Commit 36f20b54 by Tianqi Chen Committed by GitHub

[PASS] Add storage alignment info to heap allocated data (#254)

parent 204e9cb4
......@@ -110,7 +110,12 @@ class PackedCallBuilder : public IRMutator {
op->buffer_var},
Call::Extern);
Stmt free_stmt = IfThenElse::make(free_op != make_zero(Int(32)), throw_last_error);
return Block::make(alloca, free_stmt);
body = Block::make(alloca, free_stmt);
body = AttrStmt::make(
op->buffer_var, attr::storage_alignment,
make_const(Int(32), runtime::kTempAllocaAlignment),
body);
return body;
}
Stmt Mutate_(const AttrStmt* op, const Stmt &s) final {
......
......@@ -17,18 +17,21 @@ namespace runtime {
struct StorageScope {
/*! \brief The rank of the storage */
int rank{0};
/*! \brief tag for special memory, if any */
std::string tag;
// comparator
inline bool operator==(const StorageScope& other) const {
return rank == other.rank;
return rank == other.rank && tag == other.tag;
}
inline bool operator!=(const StorageScope& other) const {
return !(*this == other);
}
inline std::string to_string() const {
std::string ret;
switch (rank) {
case 0: return "global";
case 1: return "shared";
case 2: return "local";
case 0: return "global" + tag;
case 1: return "shared" + tag;
case 2: return "local" + tag;
default: LOG(FATAL) << "unknown storage scope"; return "";
}
}
......@@ -39,12 +42,15 @@ struct StorageScope {
*/
static StorageScope make(const std::string& s) {
StorageScope r;
if (s == "global") {
if (s.compare(0, 6, "global") == 0) {
r.rank = 0;
} else if (s == "shared") {
r.tag = s.substr(6, std::string::npos);
} else if (s.compare(0, 6, "shared") == 0) {
r.rank = 1;
} else if (s == "local") {
r.tag = s.substr(6, std::string::npos);
} else if (s.compare(0, 5, "local") == 0) {
r.rank = 2;
r.tag = s.substr(5, std::string::npos);
} else {
LOG(FATAL) << "unknown storage scope " << s;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment