在LLVM IR序列
int a = 5;
int b = a;
不使用任何優化,翻譯爲
%a = alloca i32, align 4
%b = alloca i32, align 4
store i32 5, i32* %a, align 4
%0 = load i32* %a, align 4
store i32 %0, i32* %b, align 4
這對應於兩個AllocaInst
S,2個StoreInst
S和LoadInst
如下
警告:未經測試/未編譯的僞代碼
ConstantInt* const_int_5 = ConstantInt::get(llvmContext, APInt(32, StringRef("5"), 10));
AllocaInst* a_alloc = new AllocaInst(IntegerType::get(llvmContext, 32), "a");
AllocaInst* b_alloc = new AllocaInst(IntegerType::get(llvmContext, 32), "b");
StoreInst* store_5 = new StoreInst(const_int_5, a_alloc, false);
LoadInst* load_from_a = new LoadInst(a_alloc, "", false);
StoreInst* store_b = new StoreInst(load_from_a, b_alloc, false);
你可能會感到困惑,因爲指令處於LLVM API歸功於精心設計的繼承層次的價值。
對不起,我想你誤解了我的意思。我可以用'llc -march'得到類似的答案。我應該如何將IR問題轉換爲IR問題?由於在IR代碼中存在alloca和store inst,我應該怎麼做才能獲得「a_alloca」? – winter333 2014-10-13 01:31:26
我不明白你的句子的英文。你想將「a」變量的名稱改爲「a_alloca」嗎?如果是這樣,請修改'AllocaInst'構造函數的'const Twine&Name ='「'參數 – 2014-10-13 07:21:59