dear llvm community
i have followed this group some months,but i have a newbie in llvm.i have a question to ask for advice.
i want add some instructions in the arm machine pass,but i don’t know how to generate the constant in arm mode.the code should be as follows
you know arm/thumb have their constan island to process the constant from IR level passed,in machine level how
LDR an constant , when i use BuildMI to LDR an basic block,it seems generate a wrong instruction,
and basic block can not contain data just instruction.thanks all the friends,best regards!
when i use BuildMI to LDR an basic block,it seems generate
a wrong instruction,
and basic block can not contain data just instruction.thanks all the
As long as you're doing this before ARMConstantIslands the actual
constant entries are stored in the MachineFunction somewhere, not in a
real basic block yet. A simple example of code materializing constants
like this is in ARMFrameLowering.cpp, starting at line 2207 in trunk
(search for tLDRpci).
There's also a more complete, but complex, example in
ARMExpandPseudoInsts.cpp (again, search tLDRpci); that one handles ARM
mode as well as Thumb, but also has extra cruft about how global
variables need to be accessed that you probably won't care about.
The key is that you need to register your new constant with the
MachineFunction to get ConstantPoolIndex for it. Then you add that
operand with BuildMI instead of an actual basic block.
One wrinkle not handled in either of those is that if you really need
a numeric value then you'll have to create your own Constant with
ConstantInt::Create(...), which needs an LLVM IR Type, which in turn
needs an LLVMContext. It's ugly, but "MF.getFunction()->getContext()"
should do the trick.