冷雨 via llvm-dev
2017-Mar-09 06:46 UTC
[llvm-dev] help create constant in arm machine level
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 LDR r0,constant0 mov r1,r2 ... constant0: dd 12345678h 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! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170309/f933af60/attachment.html>
Tim Northover via llvm-dev
2017-Mar-09 17:30 UTC
[llvm-dev] help create constant in arm machine level
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.