Rafael EspĂndola
2006-Jul-31 20:26 UTC
[LLVMdev] creating a constant with the address of another constant
In ARM, the conventional way of setting a register to a 32 bit constant is to use a load: --------------------------------- str: .asciz "Hello World" .text main: ... ldr r0, .L3 .... .L3: .word str ----------------------------------- To implement this, LowerGlobalAddress must add an element to the constant pool (.L3 in the example). How can I implement this? Thanks, Rafael
Chris Lattner
2006-Aug-01 03:22 UTC
[LLVMdev] creating a constant with the address of another constant
On Mon, 31 Jul 2006, [UTF-8] Rafael Esp?ndola wrote:> In ARM, the conventional way of setting a register to a 32 bit > constant is to use a load: > --------------------------------- > str: > .asciz "Hello World" > > .text > main: > ... > ldr r0, .L3 > .... > .L3: > .word str > ----------------------------------- > > To implement this, LowerGlobalAddress must add an element to the > constant pool (.L3 in the example). How can I implement this?The traditional way you do this is with the MachineConstantPool class (reachable from the current MachineFunction). You can add it to the constant pool two ways. If you aren't in the lowering phase, you can directly manipulate the constant pool. To plop the address of the global into the constant pool, you'd do this, for example: MachineConstantPool &MCP = .. GlobalValue *GV = ... unsigned CPI = MCP.getConstantPoolIndex(GV, /*alignment*/4); If you *are* in the context of lowering (which is more likely), you can put it into the constantpool and create a SDNode by using: SDOperand CPAddr = DAG.getConstantPool(GV, /*pointer type*/ MVT::i32, /*alignment*/ 4); If it helps, there are examples around that use it, e.g. X86TargetLowering::LowerFABS. -Chris -- http://nondot.org/sabre/ http://llvm.org/
Apparently Analagous Threads
- [LLVMdev] jump table x constant pool
- [LLVMdev] Being able to know the jitted code-size before emitting
- [LLVMdev] Being able to know the jitted code-size before emitting
- [LLVMdev] Being able to know the jitted code-size before emitting
- [LLVMdev] Being able to know the jitted code-size before emitting