Problem with llvm-c

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

ll.c (1.37 KB)

Hi James,

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.

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 ?