llvm.org GIT mirror llvm / 589c6f6
Move getJTISymbol from MachineJumpTableInfo to MachineFunction, which is more convenient, and change getPICJumpTableRelocBaseExpr to take a MachineFunction to match. Next, move the X86 code that create a PICBase symbol to X86TargetLowering::getPICBaseSymbol from X86MCInstLower::GetPICBaseSymbol, which was an asmprinter specific library. This eliminates a 'gross hack', and allows us to implement X86ISelLowering::getPICJumpTableRelocBaseExpr which now calls it. This in turn allows us to eliminate the X86AsmPrinter::printPICJumpTableSetLabel method, which was the only overload of printPICJumpTableSetLabel. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94526 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
11 changed file(s) with 78 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
376376 MachineInstr::mmo_iterator End);
377377
378378 //===--------------------------------------------------------------------===//
379 // Label Manipulation.
380 //
381
382 /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
383 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
384 /// normal 'L' label is returned.
385 MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
386 bool isLinkerPrivate = false) const;
387
388
389 //===--------------------------------------------------------------------===//
379390 // Debug location.
380391 //
381392
9090 return JumpTables;
9191 }
9292
93 /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
94 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
95 /// normal 'L' label is returned.
96 MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
97 bool isLinkerPrivate = false) const;
98
9993 /// RemoveJumpTable - Mark the specific index as being dead. This will
10094 /// prevent it from being emitted.
10195 void RemoveJumpTable(unsigned Idx) {
775775 /// given PIC jumptable, the same as getPICJumpTableRelocBase, but as an
776776 /// MCExpr.
777777 virtual const MCExpr *
778 getPICJumpTableRelocBaseExpr(const MachineJumpTableInfo *MJTI,
778 getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
779779 unsigned JTI, MCContext &Ctx) const;
780780
781781 /// isOffsetFoldingLegal - Return true if folding a constant offset
13901390
13911391 /// GetJTISymbol - Return the symbol for the specified jump table entry.
13921392 MCSymbol *AsmPrinter::GetJTISymbol(unsigned JTID, bool isLinkerPrivate) const {
1393 return MF->getJumpTableInfo()->getJTISymbol(JTID, OutContext,isLinkerPrivate);
1393 return MF->getJTISymbol(JTID, OutContext, isLinkerPrivate);
13941394 }
13951395
13961396 /// GetJTSetSymbol - Return the symbol for the specified jump table .set
15451545 /// specified MachineBasicBlock for a jumptable entry.
15461546 void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
15471547 const MachineBasicBlock *MBB) const {
1548 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
15491548 const TargetLowering *TLI = TM.getTargetLowering();
15501549 O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
15511550 << *GetJTSetSymbol(uid, MBB->getNumber()) << ','
15521551 << *MBB->getSymbol(OutContext) << '-'
1553 << *TLI->getPICJumpTableRelocBaseExpr(MJTI,uid,OutContext)
1552 << *TLI->getPICJumpTableRelocBaseExpr(MF, uid, OutContext)
15541553 << '\n';
15551554 }
15561555
444444 return DILocation(DebugLocInfo.DebugLocations[Idx]);
445445 }
446446
447
448 /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
449 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
450 /// normal 'L' label is returned.
451 MCSymbol *MachineFunction::getJTISymbol(unsigned JTI, MCContext &Ctx,
452 bool isLinkerPrivate) const {
453 assert(JumpTableInfo && "No jump tables");
454
455 const std::vector &JTs =JumpTableInfo->getJumpTables();
456 assert(JTI < JTs.size() && "Invalid JTI!");
457 const MCAsmInfo &MAI = *getTarget().getMCAsmInfo();
458
459 const char *Prefix = isLinkerPrivate ? MAI.getLinkerPrivateGlobalPrefix() :
460 MAI.getPrivateGlobalPrefix();
461 SmallString<60> Name;
462 raw_svector_ostream(Name)
463 << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
464 return Ctx.GetOrCreateSymbol(Name.str());
465 }
466
467
447468 //===----------------------------------------------------------------------===//
448469 // MachineFrameInfo implementation
449470 //===----------------------------------------------------------------------===//
580601 return JumpTables.size()-1;
581602 }
582603
583 /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
584 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
585 /// normal 'L' label is returned.
586 MCSymbol *MachineJumpTableInfo::getJTISymbol(unsigned JTI, MCContext &Ctx,
587 bool isLinkerPrivate) const {
588 assert(JTI < JumpTables.size() && !JumpTables[JTI].MBBs.empty() &&
589 "Invalid JTI!");
590 const MachineFunction *MF = JumpTables[JTI].MBBs[0]->getParent();
591 const MCAsmInfo &MAI = *MF->getTarget().getMCAsmInfo();
592
593 const char *Prefix = isLinkerPrivate ? MAI.getLinkerPrivateGlobalPrefix() :
594 MAI.getPrivateGlobalPrefix();
595 SmallString<60> Name;
596 raw_svector_ostream(Name)
597 << Prefix << "JTI" << MF->getFunctionNumber() << '_' << JTI;
598 return Ctx.GetOrCreateSymbol(Name.str());
599 }
600
601604
602605 /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
603606 /// the jump tables to branch to New instead.
2222 #include "llvm/DerivedTypes.h"
2323 #include "llvm/CodeGen/MachineFrameInfo.h"
2424 #include "llvm/CodeGen/MachineJumpTableInfo.h"
25 #include "llvm/CodeGen/MachineFunction.h"
2526 #include "llvm/CodeGen/SelectionDAG.h"
2627 #include "llvm/ADT/STLExtras.h"
2728 #include "llvm/Support/ErrorHandling.h"
822823 /// given PIC jumptable, the same as getPICJumpTableRelocBase, but as an
823824 /// MCExpr.
824825 const MCExpr *
825 TargetLowering::getPICJumpTableRelocBaseExpr(const MachineJumpTableInfo *MJTI,
826 unsigned JTI,
827 MCContext &Ctx) const {
826 TargetLowering::getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
827 unsigned JTI,MCContext &Ctx) const{
828828 // The normal PIC reloc base is the label at the start of the jump table.
829 return MCSymbolRefExpr::Create(MJTI->getJTISymbol(JTI, Ctx), Ctx);
829 return MCSymbolRefExpr::Create(MF->getJTISymbol(JTI, Ctx), Ctx);
830830 }
831831
832832 bool
5757 }
5858
5959 void X86AsmPrinter::PrintPICBaseSymbol() const {
60 // FIXME: Gross const cast hack.
61 X86AsmPrinter *AP = const_cast(this);
62 O << *X86MCInstLower(OutContext, 0, *AP).GetPICBaseSymbol();
60 const TargetLowering *TLI = TM.getTargetLowering();
61 O << *static_cast(TLI)->getPICBaseSymbol(MF,
62 OutContext);
6363 }
6464
6565 void X86AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
452452 printLeaMemReference(MI, Op, Modifier);
453453 }
454454
455 void X86AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
456 const MachineBasicBlock *MBB) const {
457 O << MAI->getSetDirective() << ' ' << *GetJTSetSymbol(uid, MBB->getNumber())
458 << ',' << *MBB->getSymbol(OutContext);
459
460 if (Subtarget->isPICStyleRIPRel())
461 O << '-' << *GetJTISymbol(uid) << '\n';
462 else {
463 O << '-';
464 PrintPICBaseSymbol();
465 O << '\n';
466 }
467 }
468
469
470455 void X86AsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
471456 PrintPICBaseSymbol();
472457 O << '\n';
123123 const char *Modifier=NULL);
124124 void printLeaMemReference(const MachineInstr *MI, unsigned Op,
125125 const char *Modifier=NULL);
126 void printPICJumpTableSetLabel(unsigned uid,
127 const MachineBasicBlock *MBB) const;
128126
129127 void printPICLabel(const MachineInstr *MI, unsigned Op);
130128
3838
3939
4040 MCSymbol *X86MCInstLower::GetPICBaseSymbol() const {
41 return Ctx.GetOrCreateSymbol(Twine(AsmPrinter.MAI->getPrivateGlobalPrefix())+
42 Twine(AsmPrinter.getFunctionNumber())+"$pb");
41 const TargetLowering *TLI = AsmPrinter.TM.getTargetLowering();
42 return static_cast(TLI)->
43 getPICBaseSymbol(AsmPrinter.MF, Ctx);
4344 }
4445
4546 /// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an
3232 #include "llvm/CodeGen/MachineModuleInfo.h"
3333 #include "llvm/CodeGen/MachineRegisterInfo.h"
3434 #include "llvm/CodeGen/PseudoSourceValue.h"
35 #include "llvm/MC/MCAsmInfo.h"
3536 #include "llvm/MC/MCContext.h"
3637 #include "llvm/MC/MCExpr.h"
3738 #include "llvm/MC/MCSymbol.h"
11071108 return TargetLowering::getJumpTableEncoding();
11081109 }
11091110
1111 /// getPICBaseSymbol - Return the X86-32 PIC base.
1112 MCSymbol *
1113 X86TargetLowering::getPICBaseSymbol(const MachineFunction *MF,
1114 MCContext &Ctx) const {
1115 const MCAsmInfo &MAI = *getTargetMachine().getMCAsmInfo();
1116 return Ctx.GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix())+
1117 Twine(MF->getFunctionNumber())+"$pb");
1118 }
1119
1120
11101121 const MCExpr *
11111122 X86TargetLowering::LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI,
11121123 const MachineBasicBlock *MBB,
11241135 /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC
11251136 /// jumptable.
11261137 SDValue X86TargetLowering::getPICJumpTableRelocBase(SDValue Table,
1127 SelectionDAG &DAG) const {
1138 SelectionDAG &DAG) const {
11281139 if (!Subtarget->is64Bit())
11291140 // This doesn't have DebugLoc associated with it, but is not really the
11301141 // same as a Register.
11311142 return DAG.getNode(X86ISD::GlobalBaseReg, DebugLoc::getUnknownLoc(),
11321143 getPointerTy());
11331144 return Table;
1145 }
1146
1147 /// getPICJumpTableRelocBaseExpr - This returns the relocation base for the
1148 /// given PIC jumptable, the same as getPICJumpTableRelocBase, but as an
1149 /// MCExpr.
1150 const MCExpr *X86TargetLowering::
1151 getPICJumpTableRelocBaseExpr(const MachineFunction *MF, unsigned JTI,
1152 MCContext &Ctx) const {
1153 // X86-64 uses RIP relative addressing based on the jump table label.
1154 if (Subtarget->isPICStyleRIPRel())
1155 return TargetLowering::getPICJumpTableRelocBaseExpr(MF, JTI, Ctx);
1156
1157 // Otherwise, the reference is relative to the PIC base.
1158 return MCSymbolRefExpr::Create(getPICBaseSymbol(MF, Ctx), Ctx);
11341159 }
11351160
11361161 /// getFunctionAlignment - Return the Log2 alignment of this function.
375375 public:
376376 explicit X86TargetLowering(X86TargetMachine &TM);
377377
378 /// getPICBaseSymbol - Return the X86-32 PIC base.
379 MCSymbol *getPICBaseSymbol(const MachineFunction *MF, MCContext &Ctx) const;
380
378381 virtual unsigned getJumpTableEncoding() const;
379382
380383 virtual const MCExpr *
386389 /// jumptable.
387390 virtual SDValue getPICJumpTableRelocBase(SDValue Table,
388391 SelectionDAG &DAG) const;
389
392 virtual const MCExpr *
393 getPICJumpTableRelocBaseExpr(const MachineFunction *MF,
394 unsigned JTI, MCContext &Ctx) const;
395
390396 // Return the number of bytes that a function should pop when it returns (in
391397 // addition to the space used by the return address).
392398 //