diff options
Diffstat (limited to 'lib/CodeGen/AsmPrinter.cpp')
-rw-r--r-- | lib/CodeGen/AsmPrinter.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index 11c6f231b9..48d4a20a83 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -17,6 +17,7 @@ #include "llvm/Constants.h" #include "llvm/Module.h" #include "llvm/CodeGen/MachineConstantPool.h" +#include "llvm/CodeGen/MachineJumpTableInfo.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/MathExtras.h" #include "llvm/Target/TargetMachine.h" @@ -46,6 +47,7 @@ AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm) AlignmentIsInBytes(true), SwitchToSectionDirective("\t.section\t"), ConstantPoolSection("\t.section .rodata\n"), + JumpTableSection("\t.section .rodata\n"), StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"), StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"), LCOMMDirective(0), @@ -127,6 +129,33 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { } } +/// EmitJumpTableInfo - Print assembly representations of the jump tables used +/// by the current function to the current output stream. +/// +void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) { + const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); + if (JT.empty()) return; + const TargetData &TD = TM.getTargetData(); + + // FIXME: someday we need to handle PIC jump tables + assert((TM.getRelocationModel() == Reloc::Static || + TM.getRelocationModel() == Reloc::DynamicNoPIC) && + "Unhandled relocation model emitting jump table information!"); + + SwitchSection(JumpTableSection, 0); + EmitAlignment(Log2_32(TD.getPointerAlignment())); + for (unsigned i = 0, e = JT.size(); i != e; ++i) { + O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << '_' << i + << ":\n"; + const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs; + for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) { + O << Data32bitsDirective << ' '; + printBasicBlockLabel(JTBBs[ii]); + O << '\n'; + } + } +} + /// EmitSpecialLLVMGlobal - Check to see if the specified global is a /// special global used by LLVM. If so, emit it and return true, otherwise /// do nothing and return false. @@ -654,3 +683,12 @@ bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, // Target doesn't support this yet! return true; } + +/// printBasicBlockLabel - This method prints the label for the specified +/// MachineBasicBlock +void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB) const { + O << PrivateGlobalPrefix << "LBB" + << Mang->getValueName(MBB->getParent()->getFunction()) + << "_" << MBB->getNumber() << '\t' << CommentString + << MBB->getBasicBlock()->getName(); +} |