[LLVMdev] What is the best way to lower global variables with constant initializers?

Tom Stellard tom at stellard.net
Fri Jul 11 10:43:41 PDT 2014


Hi,

I have a module with multiple global addresses and each global
address has its own constant initializer.  I am able to make it
through instruction selection and have these addresses embedded
in MachineInstr operands, but now I'm stuck at the MachineInstr ->
MCInstr lowering pass, and I'm not sure what to do.

My goal is to have LLVM automatically replace the global address operands
with an offset to the constant data that is emitted in the .rodata
section.  Is this possible, and if so how can I achieve this?

I am also trying to understand whether or not I should be loading all
these constant values into a constant pool.  It would be much easier for
me to deal with if all these constant values were stored in a single
buffer.  It seems like this is what the constant pool is for, but I
can't quite understand how to initialize it from looking at the other
targets.  Is this a valid use case for the constant pool?  If so,
how would I go about loading the values into the pool.

Thanks,
Tom




More information about the llvm-dev mailing list