llvm.org GIT mirror llvm / 142b531
move the pic base symbol stuff up to MachineFunction since it is trivial and will be shared between ppc and x86. This substantially simplifies the X86 backend also. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119089 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
10 changed file(s) with 24 addition(s) and 46 deletion(s). Raw diff Collapse all Expand all
411411 /// normal 'L' label is returned.
412412 MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
413413 bool isLinkerPrivate = false) const;
414
415 /// getPICBaseSymbol - Return a function-local symbol to represent the PIC
416 /// base.
417 MCSymbol *getPICBaseSymbol() const;
414418 };
415419
416420 //===--------------------------------------------------------------------===//
425425 return Ctx.GetOrCreateSymbol(Name.str());
426426 }
427427
428 /// getPICBaseSymbol - Return a function-local symbol to represent the PIC
429 /// base.
430 MCSymbol *MachineFunction::getPICBaseSymbol() const {
431 const MCAsmInfo &MAI = *Target.getMCAsmInfo();
432 return Ctx.GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix())+
433 Twine(getFunctionNumber())+"$pb");
434 }
428435
429436 //===----------------------------------------------------------------------===//
430437 // MachineFrameInfo implementation
547547 }
548548 }
549549
550
551550 /// EmitInstruction -- Print out a single PowerPC MI in Darwin syntax to
552551 /// the current output stream.
553552 ///
558557 // Lower multi-instruction pseudo operations.
559558 switch (MI->getOpcode()) {
560559 default: break;
561
562560 case PPC::LDtoc: {
563561 // Transform %X3 = LDtoc , %X2
564562 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
554554 def LD : DSForm_1<58, 0, (outs G8RC:$rD), (ins memrix:$src),
555555 "ld $rD, $src", LdStLD,
556556 [(set G8RC:$rD, (load ixaddr:$src))]>, isPPC64;
557 // FIXME: This is a pseudo instruction. When the JIT switches to MC, remove its
558 // encoding information.
557559 def LDtoc: DSForm_1<58, 0, (outs G8RC:$rD), (ins tocentry:$disp, G8RC:$reg),
558560 "ld $rD, $disp($reg)", LdStLD,
559561 [(set G8RC:$rD,
562564 def LDinto_toc: DSForm_1<58, 0, (outs), (ins G8RC:$reg),
563565 "ld 2, 8($reg)", LdStLD,
564566 [(PPCload_toc G8RC:$reg)]>, isPPC64;
567
565568 let RST = 2, DS = 40, RA = 1 in
566569 def LDtoc_restore : DSForm_1<58, 0, (outs), (ins),
567570 "ld 2, 40(1)", LdStLD,
4747 // Primitive Helper Functions.
4848 //===----------------------------------------------------------------------===//
4949
50 void X86AsmPrinter::PrintPICBaseSymbol(raw_ostream &O) const {
51 const TargetLowering *TLI = TM.getTargetLowering();
52 O << *static_cast(TLI)->getPICBaseSymbol(*MF);
53 }
54
5550 /// runOnMachineFunction - Emit the function body.
5651 ///
5752 bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
183178 // These affect the name of the symbol, not any suffix.
184179 break;
185180 case X86II::MO_GOT_ABSOLUTE_ADDRESS:
186 O << " + [.-";
187 PrintPICBaseSymbol(O);
188 O << ']';
181 O << " + [.-" << *MF->getPICBaseSymbol() << ']';
189182 break;
190183 case X86II::MO_PIC_BASE_OFFSET:
191184 case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
192185 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
193 O << '-';
194 PrintPICBaseSymbol(O);
186 O << '-' << *MF->getPICBaseSymbol();
195187 break;
196188 case X86II::MO_TLSGD: O << "@TLSGD"; break;
197189 case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
204196 case X86II::MO_PLT: O << "@PLT"; break;
205197 case X86II::MO_TLVP: O << "@TLVP"; break;
206198 case X86II::MO_TLVP_PIC_BASE:
207 O << "@TLVP" << '-';
208 PrintPICBaseSymbol(O);
199 O << "@TLVP" << '-' << *MF->getPICBaseSymbol();
209200 break;
210201 }
211202 }
342333
343334 void X86AsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op,
344335 raw_ostream &O) {
345 PrintPICBaseSymbol(O);
346 O << '\n';
347 PrintPICBaseSymbol(O);
348 O << ':';
336 O << *MF->getPICBaseSymbol() << '\n';
337 O << *MF->getPICBaseSymbol() << ':';
349338 }
350339
351340 bool X86AsmPrinter::printAsmMRegister(const MachineOperand &MO, char Mode,
7474
7575 void printPICLabel(const MachineInstr *MI, unsigned Op, raw_ostream &O);
7676
77 void PrintPICBaseSymbol(raw_ostream &O) const;
78
7977 bool runOnMachineFunction(MachineFunction &F);
8078
8179 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
11011101 return TargetLowering::getJumpTableEncoding();
11021102 }
11031103
1104 /// getPICBaseSymbol - Return the X86-32 PIC base.
1105 MCSymbol *
1106 X86TargetLowering::getPICBaseSymbol(const MachineFunction &MF) const {
1107
1108 const MCAsmInfo &MAI = *getTargetMachine().getMCAsmInfo();
1109 MCContext &Ctx = MF.getContext();
1110 return Ctx.GetOrCreateSymbol(Twine(MAI.getPrivateGlobalPrefix())+
1111 Twine(MF.getFunctionNumber())+"$pb");
1112 }
1113
1114
11151104 const MCExpr *
11161105 X86TargetLowering::LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI,
11171106 const MachineBasicBlock *MBB,
11461135 return TargetLowering::getPICJumpTableRelocBaseExpr(MF, JTI, Ctx);
11471136
11481137 // Otherwise, the reference is relative to the PIC base.
1149 return MCSymbolRefExpr::Create(getPICBaseSymbol(*MF), Ctx);
1138 return MCSymbolRefExpr::Create(MF->getPICBaseSymbol(), Ctx);
11501139 }
11511140
11521141 /// getFunctionAlignment - Return the Log2 alignment of this function.
428428 class X86TargetLowering : public TargetLowering {
429429 public:
430430 explicit X86TargetLowering(X86TargetMachine &TM);
431
432 /// getPICBaseSymbol - Return the X86-32 PIC base.
433 MCSymbol *getPICBaseSymbol(const MachineFunction &MF) const;
434431
435432 virtual unsigned getJumpTableEncoding() const;
436433
3838 }
3939
4040
41 MCSymbol *X86MCInstLower::GetPICBaseSymbol() const {
42 return static_cast(TM.getTargetLowering())->
43 getPICBaseSymbol(MF);
44 }
45
4641 /// GetSymbolFromOperand - Lower an MO_GlobalAddress or MO_ExternalSymbol
4742 /// operand to an MCSymbol.
4843 MCSymbol *X86MCInstLower::
154149 Expr = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_TLVP, Ctx);
155150 // Subtract the pic base.
156151 Expr = MCBinaryExpr::CreateSub(Expr,
157 MCSymbolRefExpr::Create(GetPICBaseSymbol(),
152 MCSymbolRefExpr::Create(MF.getPICBaseSymbol(),
158153 Ctx),
159154 Ctx);
160155 break;
173168 Expr = MCSymbolRefExpr::Create(Sym, Ctx);
174169 // Subtract the pic base.
175170 Expr = MCBinaryExpr::CreateSub(Expr,
176 MCSymbolRefExpr::Create(GetPICBaseSymbol(), Ctx),
171 MCSymbolRefExpr::Create(MF.getPICBaseSymbol(), Ctx),
177172 Ctx);
178173 if (MO.isJTI() && MAI.hasSetDirective()) {
179174 // If .set directive is supported, use it to reduce the number of
575570 // popl %esi
576571
577572 // Emit the call.
578 MCSymbol *PICBase = MCInstLowering.GetPICBaseSymbol();
573 MCSymbol *PICBase = MF->getPICBaseSymbol();
579574 TmpInst.setOpcode(X86::CALLpcrel32);
580575 // FIXME: We would like an efficient form for this, so we don't have to do a
581576 // lot of extra uniquing.
613608
614609 const MCExpr *DotExpr = MCSymbolRefExpr::Create(DotSym, OutContext);
615610 const MCExpr *PICBase =
616 MCSymbolRefExpr::Create(MCInstLowering.GetPICBaseSymbol(), OutContext);
611 MCSymbolRefExpr::Create(MF->getPICBaseSymbol(), OutContext);
617612 DotExpr = MCBinaryExpr::CreateSub(DotExpr, PICBase, OutContext);
618613
619614 DotExpr = MCBinaryExpr::CreateAdd(MCSymbolRefExpr::Create(OpSym,OutContext),
3939
4040 void Lower(const MachineInstr *MI, MCInst &OutMI) const;
4141
42 MCSymbol *GetPICBaseSymbol() const;
43
4442 MCSymbol *GetSymbolFromOperand(const MachineOperand &MO) const;
4543 MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
4644