LLVM程序分析日记之插桩BranchInst
作者:互联网
1. splitblockandinsertifthenelse()
一个代码例子:StackOverflow
2. SplitBlockAndInsertIfThen()
或者仅仅想插桩if then
的逻辑,就可以用SplitBlockAndInsertIfThen()
,其使用相对简单些,一个例子如下:
Value* val_c = NULL;
IRBuilder<> IRB(InsertPoint);
Value* cmp = IRB.CreateICmpEQ(val_a, val_b);
BranchInst *BI = cast<BranchInst>(
SplitBlockAndInsertIfThen(cmp, InsertPoint, false, CallWeights));
/* Instrument at new basic block */
IRBuilder<> ThenB(BI);
val_c = ThenB.CreateAdd(val_a, val_b);
val_c = IRB.CreateSub(val_a, val_b);
上述插桩后的代码实现下面的效果:
...
if (val_a == val_b) {
val_c = val_a + val_b;
}
val_c = val_a - val_b;
3. The third parameter of SplitBlockAndInsertIfThen() and splitblockandinsertifthenelse()
详见 https://stackoverflow.com/questions/65308323/llvm-suitable-parameters-for-the-createbranchweights
标签:LLVM,val,BranchInst,BI,Value,SplitBlockAndInsertIfThen,IRB,日记 来源: https://www.cnblogs.com/bjchan9an/p/14142050.html