lower-lever IR (A-normal form)

Hi,

i would like to ask you, if i can get a lower-level representation than the llvm IR.
For example, having the following instruction in the llvm IR,
call void @llvm.memcpy.i32(i8* %19, i8* getelementptr inbounds ([2 x [2 x [3 x i8]]]* @main.s, i32 0, i32 0, i32 0, i32 0), i32 12, i32 1)

i would like to get something like this (in A-normal form (without nested instructions):
%temp = i8* getelementptr inbounds ([2 x [2 x [3 x i8]]]* @main.s, i32 0, i32 0, i32 0, i32 0)
call void @llvm.memcpy.i32(i8* %19, %temp, i32 12, i32 1)

Thanks

Hi Eirini,

i would like to get something like this (in A-normal form (without nested
instructions):

The nested instructions come from anything LLVM can identify as a
constant (specifically, any value that's a subclass of Constant).

I'm not aware of a pass to turn them back into non-constant Values,
though one could clearly be written. It would probably count more as a
pessimisation than an optimisation though. The Constants have a
reasonable chance at resulting in no instructions at all, which I
doubt the expanded form would.

What are you trying to do where you think it would be an advantage?
Perhaps there's a better way without compromising optimisations.

Cheers.

Tim.

As Tim has pointed out, the “nested” getelementptr isn’t really a nested instruction. It is a compile-time constant. The reason why it looks like a GEP is that it is in a symbolic form. If you really want to convert these constants into instructions, take a look at the BreakConstantGEPs pass in SAFECode. It converts some (but not all) constant expressions into LLVM instructions and will alleviate the “nesting” that you see. As Tim also said, this conversion is not an optimization. You should not expect the resulting IR to compile into efficient code. – John T.

I would like to create some tables for my instructions in the IR. For example a table that has all the store instructions.
I want all the arguments to a function or instruction or constant etc to be trivial.
So to fix my previous example instead of having :

call void @llvm.memcpy.i32(i8* %19, i8* getelementptr inbounds ([2 x [2 x [3 x i8]]]* @main.s, i32 0, i32 0, i32 0, i32 0), i32 12, i32 1)
i would like to have in my IR the following :

%temp = i8* getelementptr inbounds ([2 x [2 x [3 x i8]]]* @main.s, i32 0)
%temp1 = i8* getelementptr inbounds( %temp, i32 0)
%temp2 = i8* getelementptr inbounds (%temp1, i32 0)
%temp4 = i8* getelementptr inbounds (%temp3, i32 0)

call void @llvm.memcpy.i32(i8* %19, i8* %temp4, i32 12, i32 1)

What i’m asking is, if LLVM can do this for me (for example with a certain flag while compiling the code) or i should break on my own these kind of expressions into simpler.