[llvm-dev] help create constant in arm machine level
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Thu Mar 9 09:30:05 PST 2017
Hi,
On 8 March 2017 at 22:46, 冷雨 via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 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!
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.
Cheers.
Tim.
More information about the llvm-dev
mailing list