llvm.org GIT mirror llvm / 0475ab5
Combine MovePCtoStack + POP32r into one instruction MOVPC32r so it can be moved if needed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45605 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 12 years ago
5 changed file(s) with 49 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
3131
3232 STATISTIC(EmittedInsts, "Number of machine instrs printed");
3333
34 static std::string computePICLabel(unsigned FnNum,
35 const TargetAsmInfo *TAI,
36 const X86Subtarget* Subtarget) {
34 static std::string getPICLabelString(unsigned FnNum,
35 const TargetAsmInfo *TAI,
36 const X86Subtarget* Subtarget) {
3737 std::string label;
3838 if (Subtarget->isTargetDarwin())
3939 label = "\"L" + utostr_32(FnNum) + "$pb\"";
4040 else if (Subtarget->isTargetELF())
41 label = ".Lllvm$" + utostr_32(FnNum) + "$piclabel";
41 label = ".Lllvm$" + utostr_32(FnNum) + "." + "$piclabel";
4242 else
4343 assert(0 && "Don't know how to print PIC label!\n");
4444
317317 }
318318
319319 if (!isCallOp && TM.getRelocationModel() == Reloc::PIC_)
320 O << "-\"" << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
321 << "$pb\"";
320 O << '-' << getPICLabelString(getFunctionNumber(), TAI, Subtarget);
322321 } else {
323322 if (GV->hasDLLImportLinkage()) {
324323 O << "__imp_";
419418 // popl %some_register
420419 // addl $_GLOBAL_ADDRESS_TABLE_ + [.-piclabel], %some_register
421420 O << " + [.-"
422 << computePICLabel(getFunctionNumber(), TAI, Subtarget) << "]";
421 << getPICLabelString(getFunctionNumber(), TAI, Subtarget) << "]";
423422
424423 if (isCallOp)
425424 O << "@PLT";
514513 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
515514 << '_' << uid << '\n';
516515 else
517 O << '-' << computePICLabel(getFunctionNumber(), TAI, Subtarget) << '\n';
516 O << '-' << getPICLabelString(getFunctionNumber(), TAI, Subtarget) << '\n';
518517 }
519518
520519 void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
521 std::string label = computePICLabel(getFunctionNumber(), TAI, Subtarget);
520 std::string label = getPICLabelString(getFunctionNumber(), TAI, Subtarget);
522521 O << label << "\n" << label << ":";
523522 }
524523
5757 return "X86 Machine Code Emitter";
5858 }
5959
60 void emitInstruction(const MachineInstr &MI);
60 void emitInstruction(const MachineInstr &MI,
61 const TargetInstrDescriptor *Desc);
6162
6263 private:
6364 void emitPCRelativeBlockAddress(MachineBasicBlock *MBB);
111112 MBB != E; ++MBB) {
112113 MCE.StartMachineBasicBlock(MBB);
113114 for (MachineBasicBlock::const_iterator I = MBB->begin(), E = MBB->end();
114 I != E; ++I)
115 emitInstruction(*I);
115 I != E; ++I) {
116 const TargetInstrDescriptor *Desc = I->getInstrDescriptor();
117 emitInstruction(*I, Desc);
118 // MOVPC32r is basically a call plus a pop instruction.
119 if (Desc->Opcode == X86::MOVPC32r)
120 emitInstruction(*I, &II->get(X86::POP32r));
121 NumEmitted++; // Keep track of the # of mi's emitted
122 }
116123 }
117124 } while (MCE.finishFunction(MF));
118125
518525 return REX;
519526 }
520527
521 void Emitter::emitInstruction(const MachineInstr &MI) {
522 NumEmitted++; // Keep track of the # of mi's emitted
523
524 const TargetInstrDescriptor *Desc = MI.getInstrDescriptor();
528 void Emitter::emitInstruction(const MachineInstr &MI,
529 const TargetInstrDescriptor *Desc) {
525530 unsigned Opcode = Desc->Opcode;
526531
527532 // Emit the repeat opcode prefix as needed.
586591 switch (Desc->TSFlags & X86II::FormMask) {
587592 default: assert(0 && "Unknown FormMask value in X86 MachineCodeEmitter!");
588593 case X86II::Pseudo:
594 // Remember the current PC offset, this is the PIC relocation
595 // base address.
596 switch (Opcode) {
589597 #ifndef NDEBUG
590 switch (Opcode) {
591598 default:
592599 assert(0 && "psuedo instructions should be removed before code emission");
593600 case TargetInstrInfo::INLINEASM:
606613 case X86::IMPLICIT_DEF_VR128:
607614 case X86::FP_REG_KILL:
608615 break;
609 }
610616 #endif
617 case X86::MOVPC32r:
618 // This emits the "call" portion of this pseudo instruction.
619 MCE.emitByte(BaseOpcode);
620 emitConstant(0, sizeOfImm(Desc));
621 PICBase = MCE.getCurrentPCOffset();
622 break;
623 }
611624 CurOp = NumOps;
612625 break;
613626
614627 case X86II::RawFrm:
615628 MCE.emitByte(BaseOpcode);
629
616630 if (CurOp != NumOps) {
617631 const MachineOperand &MO = MI.getOperand(CurOp++);
618632 if (MO.isMachineBasicBlock()) {
630644 assert(0 && "Unknown RawFrm operand!");
631645 }
632646 }
633
634 // Remember the current PC offset, this is the PIC relocation
635 // base address.
636 if (Opcode == X86::MovePCtoStack)
637 PICBase = MCE.getCurrentPCOffset();
638647 break;
639648
640649 case X86II::AddRegFrm:
1515 #include "X86.h"
1616 #include "X86InstrBuilder.h"
1717 #include "X86ISelLowering.h"
18 #include "X86MachineFunctionInfo.h"
1819 #include "X86RegisterInfo.h"
1920 #include "X86Subtarget.h"
2021 #include "X86TargetMachine.h"
987988 assert(!Subtarget->is64Bit() && "X86-64 PIC uses RIP relative addressing");
988989 if (!GlobalBaseReg) {
989990 // Insert the set of GlobalBaseReg into the first MBB of the function
990 MachineBasicBlock &FirstMBB = BB->getParent()->front();
991 MachineFunction *MF = BB->getParent();
992 MachineBasicBlock &FirstMBB = MF->front();
991993 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
992 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo();
994 MachineRegisterInfo &RegInfo = MF->getRegInfo();
993995 unsigned PC = RegInfo.createVirtualRegister(X86::GR32RegisterClass);
994996
995997 const TargetInstrInfo *TII = TM.getInstrInfo();
996998 // Operand of MovePCtoStack is completely ignored by asm printer. It's
997999 // only used in JIT code emission as displacement to pc.
998 BuildMI(FirstMBB, MBBI, TII->get(X86::MovePCtoStack)).addImm(0);
999 BuildMI(FirstMBB, MBBI, TII->get(X86::POP32r), PC);
1000 BuildMI(FirstMBB, MBBI, TII->get(X86::MOVPC32r), PC).addImm(0);
10001001
10011002 // If we're using vanilla 'GOT' PIC style, we should use relative addressing
10021003 // not to pc, but to _GLOBAL_ADDRESS_TABLE_ external
10031004 if (TM.getRelocationModel() == Reloc::PIC_ &&
10041005 Subtarget->isPICStyleGOT()) {
10051006 GlobalBaseReg = RegInfo.createVirtualRegister(X86::GR32RegisterClass);
1006 BuildMI(FirstMBB, MBBI, TII->get(X86::ADD32ri), GlobalBaseReg).
1007 addReg(PC).
1008 addExternalSymbol("_GLOBAL_OFFSET_TABLE_");
1007 BuildMI(FirstMBB, MBBI, TII->get(X86::ADD32ri), GlobalBaseReg)
1008 .addReg(PC).addExternalSymbol("_GLOBAL_OFFSET_TABLE_");
10091009 } else {
10101010 GlobalBaseReg = PC;
10111011 }
280280 // Nop
281281 def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", []>;
282282
283 // PIC base
284 def MOVPC32r : Ii32<0xE8, Pseudo, (outs GR32:$reg), (ins piclabel:$label),
285 "call\t$label\n\tpop{l}\t$reg", []>;
283286
284287 //===----------------------------------------------------------------------===//
285288 // Control Flow Instructions...
406409 def POPFD : I<0x9D, RawFrm, (outs), (ins), "popf", []>;
407410 let Defs = [ESP], Uses = [ESP, EFLAGS] in
408411 def PUSHFD : I<0x9C, RawFrm, (outs), (ins), "pushf", []>;
409
410 def MovePCtoStack : Ii32<0xE8, RawFrm, (outs), (ins piclabel:$label),
411 "call\t$label", []>;
412412
413413 let isTwoAddress = 1 in // GR32 = bswap GR32
414414 def BSWAP32r : I<0xC8, AddRegFrm,
3636 /// stack frame in bytes.
3737 unsigned CalleeSavedFrameSize;
3838
39 /// BytesToPopOnReturn - amount of bytes function pops on return.
39 /// BytesToPopOnReturn - Number of bytes function pops on return.
4040 /// Used on windows platform for stdcall & fastcall name decoration
4141 unsigned BytesToPopOnReturn;
4242
43 /// If the function requires additional name decoration, DecorationStyle holds
44 /// the right way to do so.
43 /// DecorationStyle - If the function requires additional name decoration,
44 /// DecorationStyle holds the right way to do so.
4545 NameDecorationStyle DecorationStyle;
4646
47 // FrameIndex for return slot.
47 /// ReturnAddrIndex - FrameIndex for return slot.
4848 int ReturnAddrIndex;
4949
50 // Delta the ReturnAddr stack slot is moved
51 // Used for creating an area before the register spill area on the stack
52 // the returnaddr can be savely move to this area
50 /// TailCallReturnAddrDelta - Delta the ReturnAddr stack slot is moved
51 /// Used for creating an area before the register spill area on the stack
52 /// the returnaddr can be savely move to this area
5353 int TailCallReturnAddrDelta;
5454
5555 public:
5858 BytesToPopOnReturn(0),
5959 DecorationStyle(None),
6060 ReturnAddrIndex(0),
61 TailCallReturnAddrDelta(0){}
61 TailCallReturnAddrDelta(0) {}
6262
6363 X86MachineFunctionInfo(MachineFunction &MF) : ForceFramePointer(false),
6464 CalleeSavedFrameSize(0),