如何确定特定加载/存储在LLVM IR中访问的内存大小?

时间:2017-02-23 21:45:38

标签: llvm llvm-ir llvm-c++-api

我想知道加载/存储是否访问LLVM IR中的字节,半字,字或双字。

getAlignment()llvm::LoadInst课程中有一个llvm:StoreInst功能。它的描述说它返回正在执行的访问的对齐方式。我不确定这是否给出了内存对齐或没有它访问的字节数?

1 个答案:

答案 0 :(得分:4)

DataLayout* dataLayout = new DataLayout(&module);
Value* memoryPointer = loadInstruction->getPointerOperand();
PointerType* pointerType = cast<PointerType>(memoryPointer->getType());                         
uint64_t storeSize = dataLayout->getTypeStoreSize(pointerType->getPointerElementType());

我有这个代码在llvm-3.7上工作。 storeSize将是操作数的大小(以字节为单位)。这里module是您在模块传递中作为参数获得的模块指针。函数getPointerOperand适用于加载和存储指令。以下是函数getTypeStoreSize的{​​{3}}。还有其他功能,例如getTypeStoreSizeInBitsgetTypeAllocSize等,您可以根据需要使用这些功能。

相关问题