Kaarthik Alagapan via llvm-dev
2019-Aug-03 21:57 UTC
[llvm-dev] Manually insert an instruction in SelectionDAG
Hello, I am trying to insert a .byte/.word in the beginning of a specific LLVM IR instruction when it prints out in assembly (the inserted ‘instruction' only appears in assembly, not in LLVM IR), and I am guessing the best way to do that is to insert it in SelectionDAG as it strips down some LLVM IR instructions when it’s lowered. Can I get some guidance on what function I should use to insert a .byte/.word in SelectionDAG so it’s printed out in assembly? Thank you, Kaarthik A. Alagappan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190803/0c70f9fe/attachment.html>
Tim Northover via llvm-dev
2019-Aug-04 06:18 UTC
[llvm-dev] Manually insert an instruction in SelectionDAG
Hi Kaarthik, On Sat, 3 Aug 2019 at 22:57, Kaarthik Alagapan via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Can I get some guidance on what function I should use to insert a .byte/.word in SelectionDAG so it’s printed out in assembly?This kind of problem is often solved by selecting the original IR instruction to a target-specific pseudo-instruction (one with "isCodeGenOnly = 1" in TableGen) and then expanding it to the real instruction sequence later. In most cases that would be a special XYZExpandPseudoInsts.cpp pass that runs very late and looks through a function replacing any MachineInstrs with the correct sequence. But in your case .byte and .word aren't even instructions so you probably want to do it during conversion to MCInsts in XYZAsmPrinter.cpp (or possibly XYZMCInstLower.cpp, different targets handle that step slightly differently). There you can detect your special pseudo and call EmitIntValue or something to get your directives. Cheers. Tim.
Kaarthik Alagapan via llvm-dev
2019-Aug-05 14:18 UTC
[llvm-dev] Manually insert an instruction in SelectionDAG
I’ll look into that file, thank you for the clarification! Kaarthik A. On Aug 4, 2019, 2:19 AM -0400, Tim Northover <t.p.northover at gmail.com>, wrote: Hi Kaarthik, On Sat, 3 Aug 2019 at 22:57, Kaarthik Alagapan via llvm-dev <llvm-dev at lists.llvm.org> wrote: Can I get some guidance on what function I should use to insert a .byte/.word in SelectionDAG so it’s printed out in assembly? This kind of problem is often solved by selecting the original IR instruction to a target-specific pseudo-instruction (one with "isCodeGenOnly = 1" in TableGen) and then expanding it to the real instruction sequence later. In most cases that would be a special XYZExpandPseudoInsts.cpp pass that runs very late and looks through a function replacing any MachineInstrs with the correct sequence. But in your case .byte and .word aren't even instructions so you probably want to do it during conversion to MCInsts in XYZAsmPrinter.cpp (or possibly XYZMCInstLower.cpp, different targets handle that step slightly differently). There you can detect your special pseudo and call EmitIntValue or something to get your directives. Cheers. Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190805/02d99f31/attachment.html>
Kaarthik Alagapan via llvm-dev
2019-Aug-06 04:32 UTC
[llvm-dev] Manually insert an instruction in SelectionDAG
Hi Tim, I was looking into what you said but then realized that I am working with jump and branch instructions (not pseudo instructions), which I believe are all translated to jumps by the AsmPrinter and InstLower phase, so I tried to see where I can detect any type of jumps so I call EmitIntValue but wasn’t able to find any other than TAILJMP*. Any tips on where I can find jumps being detected for their code emission? Kaarthik A. On Aug 4, 2019, 2:19 AM -0400, Tim Northover <t.p.northover at gmail.com>, wrote: Hi Kaarthik, On Sat, 3 Aug 2019 at 22:57, Kaarthik Alagapan via llvm-dev <llvm-dev at lists.llvm.org> wrote: Can I get some guidance on what function I should use to insert a .byte/.word in SelectionDAG so it’s printed out in assembly? This kind of problem is often solved by selecting the original IR instruction to a target-specific pseudo-instruction (one with "isCodeGenOnly = 1" in TableGen) and then expanding it to the real instruction sequence later. In most cases that would be a special XYZExpandPseudoInsts.cpp pass that runs very late and looks through a function replacing any MachineInstrs with the correct sequence. But in your case .byte and .word aren't even instructions so you probably want to do it during conversion to MCInsts in XYZAsmPrinter.cpp (or possibly XYZMCInstLower.cpp, different targets handle that step slightly differently). There you can detect your special pseudo and call EmitIntValue or something to get your directives. Cheers. Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190806/a67e35e0/attachment-0001.html>
Maybe Matching Threads
- What can cause llc to throw an error for instruction numbering?
- Inserting instructions when encountered a specific label
- What can cause llc to throw an error for instruction numbering?
- Inserting instructions when encountered a specific label
- Why is there no EmitInt64 in AsmPrinter?