Chris.Dewhurst via llvm-dev
2016-Apr-20 13:22 UTC
[llvm-dev] Adding fix-up information to an instruction created with BuildMI
I'm trying to work out how to add fix-up information to an instruction that is built with BuildMI. The instruction is taking a local label (MBB), also created in the same piece code and needs to store its address. This address is fixed-up later in the compilation process. Here's the essential fragment of code. This is custom lowering of an instruction (__builtin_setjmp), so I can't rely on the features provided by DAG legalization to help with fix-ups. I need to mark these instructions as needing later fix-ups here. I can't find any equivalent piece of code. MIB = BuildMI(*thisMBB, MI, DL, TII->get(SP::SETHIi), LabelReg) .addMBB(restoreMBB); // Need some code here to mark that a Sparc HI22 fix-up is needed on this instruction MIB = BuildMI(*thisMBB, MI, DL, TII->get(SP::ADDri), LabelReg) .addMBB(restoreMBB) .addReg(LabelReg); // Need some code here to mark that a Sparc LO10 fix-up is needed on this instruction / Chris. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160420/199c71d8/attachment.html>
Tim Northover via llvm-dev
2016-Apr-20 14:17 UTC
[llvm-dev] Adding fix-up information to an instruction created with BuildMI
Hi Chris, On 20 April 2016 at 06:22, Chris.Dewhurst via llvm-dev <llvm-dev at lists.llvm.org> wrote:> MIB = BuildMI(*thisMBB, MI, DL, TII->get(SP::SETHIi), LabelReg) > .addMBB(restoreMBB); > // Need some code here to mark that a Sparc HI22 fix-up is needed on this > instructionThere's a second "TargetFlags" argument to addMBB which encodes information about the type of fixup needed. The rough sequence is: 1. You pass some "VK_*" argument there. 2. This gets attached to an MCExpr MCOperand when the MachineInstr -> MCInst lowering takes place (SparcMCInstLower.cpp, LowerSymbolOperand). 3. During MCCodeEmitter this gets converted into a fixup_* style fixup (getMachineOpValue via a call to getFixupKind) and push_backed onto a list of Fixups (separate from the instruction now). 4. Finally, this fixup either gets resolved in SparcAsmBackend (hopefully this, for an MBB) or converted to an R_SPARC_* relocation in SparcELFObjectWriter.cpp (goodness knows what would happen there, since an MBB normally gets an assembler-local symbol). So your main goal is going to be working out which kind of VK_* tag you really need (see SparcMCExpr.h for the list). It *looks* like that would be VK_Sparc_HI (& LO for your other inst), but that's just going by the names -- I actually know basically nothing about Sparc. Cheers. Tim.