Hi, I have the following program (attached) I produces, using the llvm-c API, this: ; ModuleID = './llvm-test.bc' define i32 @test2() { EntryBlock: ret i32 3 } But, I want it to produce this: ; ModuleID = './llvm-test.bc' define i32 @test2() { EntryBlock: %1 = add i32 1, 2 ret i32 %1 } I.e. With the "add" in there. llvm appears to be doing some optimization on it, to remove the add. Is there any way to switch off the optimization by adding something to the ll.c file? I will be using the llvm-c api more fully, and I wish to make sure that the instructions I tell it to use are in the resulting .bc and .ll output. I.e. I want the .bc and .ll output to be pre-optimizations. Kind Regards James -------------- next part -------------- A non-text attachment was scrubbed... Name: ll.c Type: text/x-csrc Size: 1404 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130512/1d5436bd/attachment.c>
Hi James, On 13/05/13 00:25, James Courtier-Dutton wrote:> Hi, > > I have the following program (attached) > > I produces, using the llvm-c API, this: > ; ModuleID = './llvm-test.bc' > > define i32 @test2() { > EntryBlock: > ret i32 3 > } > > But, I want it to produce this: > ; ModuleID = './llvm-test.bc' > > define i32 @test2() { > EntryBlock: > %1 = add i32 1, 2 > ret i32 %1 > } > > I.e. With the "add" in there. > llvm appears to be doing some optimization on it, to remove the add.if you used LLVMConstAdd to create the add, then don't, use LLVMBuildAdd instead. If you were using LLVMBuildAdd, then use a builder than doesn't do automatic constant folding. Ciao, Duncan.> Is there any way to switch off the optimization by adding something to > the ll.c file? > I will be using the llvm-c api more fully, and I wish to make sure > that the instructions I tell it to use are in the resulting .bc and > .ll output. > I.e. I want the .bc and .ll output to be pre-optimizations. > > Kind Regards > > James > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On 13 May 2013 09:03, Duncan Sands <baldrick at free.fr> wrote:> Hi James, > > > On 13/05/13 00:25, James Courtier-Dutton wrote: >> >> >> I.e. With the "add" in there. >> llvm appears to be doing some optimization on it, to remove the add. > > > if you used LLVMConstAdd to create the add, then don't, use LLVMBuildAdd > instead. If you were using LLVMBuildAdd, then use a builder than doesn't > do automatic constant folding. > > Ciao, Duncan. >I have looked into this a bit further. The LLVM C++ API allows to select a builder without constant folding. The LLVM C API does not seem to have an option for a builder without constant folding. It only has: LLVMBuilderRef builder = LLVMCreateBuilderInContext(context); <- Uses a constant folding builder it appears, when it probably should not. The C API does not have a LLVMFoldingBuilderRef builder = LLVMCreateBuilderInContext(context); or LLVMBuilderRef builder = LLVMCreateFoldingBuilderInContext(context); Is this a limitation of the LLVM C API ?