llvm2alive: load pointer size from DataLayout
MODIFY
ir/function.h
ir/function.h
@@ -56,6 +56,7 @@ class Function final {
std::unordered_map<std::string, BasicBlock> BBs;
std::vector<BasicBlock*> BB_order;
+ unsigned bits_pointers;
bool little_endian;
// constants used in this function
@@ -67,8 +68,10 @@ class Function final {
public:
Function() {}
- Function(Type &type, std::string &&name, bool little_endian = true)
- : type(&type), name(std::move(name)), little_endian(little_endian) {}
+ Function(Type &type, std::string &&name, unsigned bits_pointers = 64,
+ bool little_endian = true)
+ : type(&type), name(std::move(name)), bits_pointers(bits_pointers),
+ little_endian(little_endian) {}
const IR::Type& getType() const { return type ? *type : Type::voidTy; }
void setType(IR::Type &t) { type = &t; }
@@ -109,6 +112,7 @@ public:
}
bool hasReturn() const;
+ unsigned bitsPointers() const { return bits_pointers; }
bool isLittleEndian() const { return little_endian; }
void syncDataWithSrc(const Function &src);

MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -800,7 +800,8 @@ public:
if (!type)
return {};
- Function Fn(*type, f.getName().str(), DL().isLittleEndian());
+ Function Fn(*type, f.getName().str(), 8 * DL().getPointerSize(),
+ DL().isLittleEndian());
reset_state(Fn);
for (auto &arg : f.args()) {

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -639,8 +639,10 @@ static void calculateAndInitConstants(Transform &t) {
unsigned num_globals_src = globals_src.size();
unsigned num_globals = num_globals_src;
- // TODO: get this from data layout, varies among address spaces
- bits_program_pointer = 64;
+ // FIXME: varies among address spaces
+ bits_program_pointer = t.src.bitsPointers();
+ assert(bits_program_pointer > 0 && bits_program_pointer <= 64);
+ assert(bits_program_pointer == t.tgt.bitsPointers());
heap_block_alignment = 8;
for (auto GVT : globals_tgt) {

llvm2alive: load pointer size from DataLayout