2014-11-08 80 views
-1

任何人都可以幫助我通過LLVM傳遞將LLVM IR中的變量的值增加5。 這是我的指令現在,我想增加在LLVM IR中遞增變量

%1 = load i32* %k, align 4 
    %inc = add nsw i32 %1, 1 
store i32 %inc, i32* %k, align 4 

在地方的1%INC(加)指令如何通過5

我試圖識別負載指令由

if(LoadInst *ld=dyn_cast<LoadInst>instruction) 
更換

然後

Value *Five = ConstantInt::get(Type::getInt32Ty(context), 5); 

然後更換添加請示離子通過我的新指令

Instruction *in=BinaryOperator::Create(Instruction::Add,ld,Five,"inc",some instruction); 

我試着將ld指令轉換爲值也,但它沒有工作。

回答

1

假設I是指令迭代它會看起來像

if(I->getOpcode()== Instruction::Add) 
     I->setOperand(1,Val *) 
+0

感謝replying.But是不正確的,因爲我們需要L值。 – techcomp 2014-11-14 19:26:17

+0

I-> setOperand(operandNo,Value *)?我用了類似的東西不久前,它的工作,希望也會爲你工作 – 2014-11-14 21:55:59

+0

哦謝謝。有效!! – techcomp 2014-11-15 06:22:59