[llvm-dev] Create an Add Instruction in LLVM IR

mayuyu.io via llvm-dev llvm-dev at lists.llvm.org
Mon Aug 6 20:05:12 PDT 2018


By default IRBuilder uses ConstantFolder to fold your constant add instruction. In order to disable this, use IRBuilder<NoFolder> 

Zhang

> 在 2018年8月7日,10:16,Ahmad Nouralizadeh via llvm-dev <llvm-dev at lists.llvm.org> 写道:
> 
> I want to create an add instruction that takes two constant operands at the LLVM IR level. I use the IRBuilder class, but nothing happens. Here is part of the runOnFunction() method of my function pass:
> ...
> LLVMContext &Context = F.getContext();
> IRBuilder<> builder(&Instruction);
> Value *Lef = ConstantInt::get(Type::getInt32Ty(Context), 4);
> Value *Rig = ConstantInt::get(Type::getInt32Ty(Context), 5);
> Value *Result = builder.CreateAdd(Lef, Rig);
> ...
> It seems that the problem is with the ConstantInt::get() function. Any idea?
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



More information about the llvm-dev mailing list