diff options
author | Nate Begeman <natebegeman@mac.com> | 2006-08-12 21:29:52 +0000 |
---|---|---|
committer | Nate Begeman <natebegeman@mac.com> | 2006-08-12 21:29:52 +0000 |
commit | 52a51e38dc312aa262b0d771419afe1785f3cb22 (patch) | |
tree | 2e3c7c10a0434eaf7880b1ebaa3510f541a243a8 /lib | |
parent | f6e190fae02174d465ae1f9000192269a5978c73 (diff) | |
download | external_llvm-52a51e38dc312aa262b0d771419afe1785f3cb22.zip external_llvm-52a51e38dc312aa262b0d771419afe1785f3cb22.tar.gz external_llvm-52a51e38dc312aa262b0d771419afe1785f3cb22.tar.bz2 |
Emit .set directives for jump table entries when possible, which reduces
the number of relocations in object files, shrinkifying them.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29650 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/AsmPrinter.cpp | 42 | ||||
-rw-r--r-- | lib/Target/PowerPC/PPCAsmPrinter.cpp | 1 | ||||
-rw-r--r-- | lib/Target/X86/X86AsmPrinter.cpp | 1 |
3 files changed, 41 insertions, 3 deletions
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index ca9b50b..266f82a 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -59,6 +59,7 @@ AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm) FourByteConstantSection(0), EightByteConstantSection(0), SixteenByteConstantSection(0), + SetDirective(0), LCOMMDirective(0), COMMDirective("\t.comm\t"), COMMDirectiveTakesAlignment(true), @@ -228,15 +229,36 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) { EmitAlignment(Log2_32(TD->getPointerAlignment())); for (unsigned i = 0, e = JT.size(); i != e; ++i) { + const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs; + + // For PIC codegen, if possible we want to use the SetDirective to reduce + // the number of relocations the assembler will generate for the jump table. + // Set directives are all printed before the jump table itself. + std::set<MachineBasicBlock*> EmittedSets; + if (SetDirective && TM.getRelocationModel() == Reloc::PIC_) + for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) + if (EmittedSets.insert(JTBBs[ii]).second) + printSetLabel(i, JTBBs[ii]); + 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 << JTEntryDirective << ' '; - printBasicBlockLabel(JTBBs[ii], false, false); - if (TM.getRelocationModel() == Reloc::PIC_) { + // If we have emitted set directives for the jump table entries, print + // them rather than the entries themselves. If we're emitting PIC, then + // emit the table entries as differences between two text section labels. + // If we're emitting non-PIC code, then emit the entries as direct + // references to the target basic blocks. + if (!EmittedSets.empty()) { + O << PrivateGlobalPrefix << getFunctionNumber() << '_' << i << "_set_" + << JTBBs[ii]->getNumber(); + } else if (TM.getRelocationModel() == Reloc::PIC_) { + printBasicBlockLabel(JTBBs[ii], false, false); O << '-' << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << '_' << i; + } else { + printBasicBlockLabel(JTBBs[ii], false, false); } O << '\n'; } @@ -818,3 +840,17 @@ void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB, if (printComment) O << '\t' << CommentString << MBB->getBasicBlock()->getName(); } + +/// printSetLabel - This method prints a set label for the specified +/// MachineBasicBlock +void AsmPrinter::printSetLabel(unsigned uid, + const MachineBasicBlock *MBB) const { + if (!SetDirective) + return; + + O << SetDirective << ' ' << PrivateGlobalPrefix << getFunctionNumber() + << '_' << uid << "_set_" << MBB->getNumber() << ','; + printBasicBlockLabel(MBB, false, false); + O << '-' << PrivateGlobalPrefix << "JTI" << getFunctionNumber() + << '_' << uid << '\n'; +} diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp index bf9c608..5850682 100644 --- a/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -276,6 +276,7 @@ namespace { GlobalPrefix = "_"; PrivateGlobalPrefix = "L"; // Marker for constant pool idxs ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. + SetDirective = "\t.set"; if (isPPC64) Data64bitsDirective = ".quad\t"; // we can't emit a 64-bit unit else diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 4981964..9e862e8 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -72,6 +72,7 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) { StaticDtorsSection = ".mod_term_func"; InlineAsmStart = "# InlineAsm Start"; InlineAsmEnd = "# InlineAsm End"; + SetDirective = "\t.set"; break; case X86Subtarget::isCygwin: GlobalPrefix = "_"; |