diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2007-11-14 09:18:41 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2007-11-14 09:18:41 +0000 |
commit | 2c6387803e61c49f38424fcd4141204f4c49a515 (patch) | |
tree | 6b8eb8103e4e4183912daea1f21049073f4d963b /llvm/lib/CodeGen/AsmPrinter.cpp | |
parent | e2287ed552af78306390b33f18634834ba56cd45 (diff) | |
download | bcm5719-llvm-2c6387803e61c49f38424fcd4141204f4c49a515.tar.gz bcm5719-llvm-2c6387803e61c49f38424fcd4141204f4c49a515.zip |
Fix PIC jump table codegen on x86-32/linux. In fact, such thing should be applied
to all targets uses GOT-relative offsets for PIC (Alpha?)
llvm-svn: 44108
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter.cpp | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter.cpp index ed51e10d220..ce89337f36f 100644 --- a/llvm/lib/CodeGen/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter.cpp @@ -245,17 +245,9 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI, MachineFunction &MF) { const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); if (JT.empty()) return; + bool IsPic = TM.getRelocationModel() == Reloc::PIC_; - // Use JumpTableDirective otherwise honor the entry size from the jump table - // info. - const char *JTEntryDirective = TAI->getJumpTableDirective(); - bool HadJTEntryDirective = JTEntryDirective != NULL; - if (!HadJTEntryDirective) { - JTEntryDirective = MJTI->getEntrySize() == 4 ? - TAI->getData32bitsDirective() : TAI->getData64bitsDirective(); - } - // Pick the directive to use to print the jump table entries, and switch to // the appropriate section. TargetLowering *LoweringInfo = TM.getTargetLowering(); @@ -300,30 +292,51 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI, << '_' << i << ":\n"; for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) { - O << JTEntryDirective << ' '; - // 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 << TAI->getPrivateGlobalPrefix() << getFunctionNumber() - << '_' << i << "_set_" << JTBBs[ii]->getNumber(); - } else if (IsPic) { - printBasicBlockLabel(JTBBs[ii], false, false); - // If the arch uses custom Jump Table directives, don't calc relative to - // JT - if (!HadJTEntryDirective) - O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" - << getFunctionNumber() << '_' << i; - } else { - printBasicBlockLabel(JTBBs[ii], false, false); - } + printPICJumpTableEntry(MJTI, JTBBs[ii], i); O << '\n'; } } } +void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI, + const MachineBasicBlock *MBB, + unsigned uid) const { + bool IsPic = TM.getRelocationModel() == Reloc::PIC_; + + // Use JumpTableDirective otherwise honor the entry size from the jump table + // info. + const char *JTEntryDirective = TAI->getJumpTableDirective(); + bool HadJTEntryDirective = JTEntryDirective != NULL; + if (!HadJTEntryDirective) { + JTEntryDirective = MJTI->getEntrySize() == 4 ? + TAI->getData32bitsDirective() : TAI->getData64bitsDirective(); + } + + O << JTEntryDirective << ' '; + + // 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 (IsPic) { + if (TAI->getSetDirective()) { + O << TAI->getPrivateGlobalPrefix() << getFunctionNumber() + << '_' << uid << "_set_" << MBB->getNumber(); + } else { + printBasicBlockLabel(MBB, false, false); + // If the arch uses custom Jump Table directives, don't calc relative to + // JT + if (!HadJTEntryDirective) + O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" + << getFunctionNumber() << '_' << uid; + } + } else { + printBasicBlockLabel(MBB, false, false); + } +} + + /// 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. |