【发布时间】:2016-08-14 05:47:40
【问题描述】:
我想在函数的第一个基本块的第一条指令之前插入一个加载和存储指令(用于模拟我们工作的性能开销)。 LLVM pass 的写法如下:
Value *One = llvm::ConstantInt::get(Type::getInt32Ty(Context),1);
for(Function::iterator bb = tmp->begin(); bb != tmp->end(); ++bb {
//for every instruction of the block
for (BasicBlock::iterator inst = bb->begin(); inst != bb->end(); ++inst){
if(inst == bb->begin() && bb == tmp->begin()){
BasicBlock* bp = &*bb;
Instruction* pinst = &*inst;
AllocaInst *pa = new AllocaInst(Int32Ty, "buf", pinst);
StoreInst* newstore = new StoreInst(One, pa, pinst);
LoadInst* newload = new LoadInst(pa, "loadvalue", pinst);
}
}
}
插入的加载和存储指令可以在xx.ll文件中看到:
define i32 @fun() #0 {
entry:
%buf = alloca i32
%loadvalue = load i32, i32* %buf
store i32 %loadvalue, i32* %buf
%call = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
ret i32 1
}
但是,插入的指令在目标可执行文件中消失了。
我该如何解决这个问题?
【问题讨论】:
标签: llvm