diff options
author | Chris Lattner <sabre@nondot.org> | 2009-07-09 06:59:17 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-07-09 06:59:17 +0000 |
commit | 75cdf27f48f0b81f778b6aa50efcefa0497a9dae (patch) | |
tree | bddfdf6e6ab100c828b6d3443701b271cc346175 /lib/Target/X86 | |
parent | 910139f9ca53fc20a680d51ae61bb1e072095141 (diff) |
move reasoning about darwin $non_lazy_ptr stubs from asmprinter into
isel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75117 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86')
-rw-r--r-- | lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp | 40 | ||||
-rw-r--r-- | lib/Target/X86/X86FastISel.cpp | 46 | ||||
-rw-r--r-- | lib/Target/X86/X86ISelLowering.cpp | 32 | ||||
-rw-r--r-- | lib/Target/X86/X86InstrInfo.h | 20 |
4 files changed, 98 insertions, 40 deletions
diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index b97462918d..44d1e25461 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -429,28 +429,16 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, } // Handle dllimport linkage. - if (MO.getTargetFlags() == X86II::MO_DLLIMPORT) - O << "__imp_"; - - if (Subtarget->isPICStyleStub()) { - // DARWIN/X86-32 in != static mode. - - // Link-once, declaration, or Weakly-linked global variables need - // non-lazily-resolved stubs - if (!GV->isDeclaration() && !GV->isWeakForLinker()) { - O << Name; - } else if (!GV->hasHiddenVisibility()) { - GVStubs.insert(Name); - printSuffixedName(Name, "$non_lazy_ptr"); - //assert(MO.getTargetFlags() == 0 || MO_PIC_BASE_OFFSET); - } else if (!GV->isDeclaration() && !GV->hasCommonLinkage()) - // Definition is not definitely in the current translation unit. - O << Name; - else { - HiddenGVStubs.insert(Name); - printSuffixedName(Name, "$non_lazy_ptr"); - //assert(MO.getTargetFlags() == 0 || MO_PIC_BASE_OFFSET); - } + if (MO.getTargetFlags() == X86II::MO_DLLIMPORT) { + O << "__imp_" << Name; + } else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY || + MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) { + GVStubs.insert(Name); + printSuffixedName(Name, "$non_lazy_ptr"); + } else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY || + MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){ + HiddenGVStubs.insert(Name); + printSuffixedName(Name, "$non_lazy_ptr"); } else { O << Name; } @@ -478,7 +466,11 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, default: assert(0 && "Unknown target flag on GV operand"); case X86II::MO_NO_FLAG: // No flag. - case X86II::MO_DLLIMPORT: // Prefix, not a suffix. + break; + case X86II::MO_DARWIN_NONLAZY: + case X86II::MO_DARWIN_HIDDEN_NONLAZY: + case X86II::MO_DLLIMPORT: + // These affect the name of the symbol, not any suffix. break; case X86II::MO_GOT_ABSOLUTE_ADDRESS: O << " + [.-"; @@ -486,6 +478,8 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, O << ']'; break; case X86II::MO_PIC_BASE_OFFSET: + case X86II::MO_DARWIN_NONLAZY_PIC_BASE: + case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: O << '-'; PrintPICBaseSymbol(); break; diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index 492ba523aa..2ed68c14a0 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -445,8 +445,10 @@ bool X86FastISel::X86SelectAddress(Value *V, X86AddressMode &AM, bool isCall) { if (!isCall && TM.getRelocationModel() == Reloc::PIC_ && - !Subtarget->is64Bit()) + !Subtarget->is64Bit()) { + // FIXME: How do we know Base.Reg is free?? AM.Base.Reg = getInstrInfo()->getGlobalBaseReg(&MF); + } // If the ABI doesn't require an extra load, return a direct reference to // the global. @@ -456,6 +458,11 @@ bool X86FastISel::X86SelectAddress(Value *V, X86AddressMode &AM, bool isCall) { // base and index registers are unused. assert(AM.Base.Reg == 0 && AM.IndexReg == 0); AM.Base.Reg = X86::RIP; + } else if (Subtarget->isPICStyleStub() && + TM.getRelocationModel() == Reloc::PIC_) { + AM.GVOpFlags = X86II::MO_PIC_BASE_OFFSET; + } else if (Subtarget->isPICStyleGOT()) { + AM.GVOpFlags = X86II::MO_GOTOFF; } return true; @@ -473,23 +480,40 @@ bool X86FastISel::X86SelectAddress(Value *V, X86AddressMode &AM, bool isCall) { const TargetRegisterClass *RC = NULL; X86AddressMode StubAM; StubAM.Base.Reg = AM.Base.Reg; - StubAM.GV = AM.GV; + StubAM.GV = GV; - if (TLI.getPointerTy() == MVT::i32) { - Opc = X86::MOV32rm; - RC = X86::GR32RegisterClass; - - if (Subtarget->isPICStyleGOT()) - StubAM.GVOpFlags = X86II::MO_GOT; - - } else { + if (TLI.getPointerTy() == MVT::i64) { Opc = X86::MOV64rm; RC = X86::GR64RegisterClass; - if (TM.getRelocationModel() != Reloc::Static) { + if (Subtarget->isPICStyleRIPRel()) { StubAM.GVOpFlags = X86II::MO_GOTPCREL; StubAM.Base.Reg = X86::RIP; } + + } else { + Opc = X86::MOV32rm; + RC = X86::GR32RegisterClass; + + if (Subtarget->isPICStyleGOT()) + StubAM.GVOpFlags = X86II::MO_GOT; + else if (Subtarget->isPICStyleStub()) { + // In darwin, we have multiple different stub types, and we have both + // PIC and -mdynamic-no-pic. Determine whether we have a stub + // reference and/or whether the reference is relative to the PIC base + // or not. + bool IsPIC = TM.getRelocationModel() == Reloc::PIC_; + + if (!GV->hasHiddenVisibility()) { + // Non-hidden $non_lazy_ptr reference. + StubAM.GVOpFlags = IsPIC ? X86II::MO_DARWIN_NONLAZY_PIC_BASE : + X86II::MO_DARWIN_NONLAZY; + } else { + // Hidden $non_lazy_ptr reference. + StubAM.GVOpFlags = IsPIC ? X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: + X86II::MO_DARWIN_HIDDEN_NONLAZY; + } + } } LoadReg = createResultReg(RC); diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 31b18b7e6b..bb5829ac61 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -4551,14 +4551,14 @@ SDValue X86TargetLowering::LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl, int64_t Offset, SelectionDAG &DAG) const { - bool IsPic = getTargetMachine().getRelocationModel() == Reloc::PIC_; + bool IsPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_; bool ExtraLoadRequired = Subtarget->GVRequiresExtraLoad(GV, getTargetMachine(), false); // Create the TargetGlobalAddress node, folding in the constant // offset if it is legal. SDValue Result; - if (!IsPic && !ExtraLoadRequired && isInt32(Offset)) { + if (!IsPIC && !ExtraLoadRequired && isInt32(Offset)) { // A direct static reference to a global. Result = DAG.getTargetGlobalAddress(GV, getPointerTy(), Offset); Offset = 0; @@ -4575,9 +4575,29 @@ X86TargetLowering::LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl, OpFlags = X86II::MO_GOT; else OpFlags = X86II::MO_GOTOFF; - } else if (Subtarget->isPICStyleStub() && - getTargetMachine().getRelocationModel() == Reloc::PIC_) { - OpFlags = X86II::MO_PIC_BASE_OFFSET; + } else if (Subtarget->isPICStyleStub()) { + // In darwin, we have multiple different stub types, and we have both PIC + // and -mdynamic-no-pic. Determine whether we have a stub reference + // and/or whether the reference is relative to the PIC base or not. + + // Link-once, declaration, or Weakly-linked global variables need + // non-lazily-resolved stubs. + if (!GV->isDeclaration() && !GV->isWeakForLinker()) { + // Not a stub reference. + OpFlags = IsPIC ? X86II::MO_PIC_BASE_OFFSET : 0; + } else if (!GV->hasHiddenVisibility()) { + // Non-hidden $non_lazy_ptr reference. + OpFlags = IsPIC ? X86II::MO_DARWIN_NONLAZY_PIC_BASE : + X86II::MO_DARWIN_NONLAZY; + } else if (!GV->isDeclaration() && !GV->hasCommonLinkage()) + // Definition is definitely in the current linkage unit. + // Not a stub reference. + OpFlags = IsPIC ? X86II::MO_PIC_BASE_OFFSET : 0; + else { + // Hidden $non_lazy_ptr reference. + OpFlags = IsPIC ? X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE : + X86II::MO_DARWIN_HIDDEN_NONLAZY; + } } Result = DAG.getTargetGlobalAddress(GV, getPointerTy(), 0, OpFlags); @@ -4590,7 +4610,7 @@ X86TargetLowering::LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl, Result = DAG.getNode(X86ISD::Wrapper, dl, getPointerTy(), Result); // With PIC, the address is actually $g + Offset. - if (IsPic && !Subtarget->is64Bit()) { + if (IsPIC && !Subtarget->is64Bit()) { Result = DAG.getNode(ISD::ADD, dl, getPointerTy(), DAG.getNode(X86ISD::GlobalBaseReg, dl, getPointerTy()), Result); diff --git a/lib/Target/X86/X86InstrInfo.h b/lib/Target/X86/X86InstrInfo.h index 2336d5698b..83f3f09797 100644 --- a/lib/Target/X86/X86InstrInfo.h +++ b/lib/Target/X86/X86InstrInfo.h @@ -159,6 +159,26 @@ namespace X86II { /// and jumps to external functions on Tiger and before. MO_DARWIN_STUB = 13, + /// MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the + /// reference is actually to the "FOO$non_lazy_ptr" symbol, which is a + /// non-PIC-base-relative reference to a non-hidden dyld lazy pointer stub. + MO_DARWIN_NONLAZY = 14, + + /// MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates + /// that the reference is actually to "FOO$non_lazy_ptr - PICBASE", which is + /// a PIC-base-relative reference to a non-hidden dyld lazy pointer stub. + MO_DARWIN_NONLAZY_PIC_BASE = 15, + + /// MO_DARWIN_HIDDEN_NONLAZY - On a symbol operand "FOO", this indicates + /// that the reference is actually to the "FOO$non_lazy_ptr" symbol, which + /// is a non-PIC-base-relative reference to a hidden dyld lazy pointer stub. + MO_DARWIN_HIDDEN_NONLAZY = 16, + + /// MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this + /// indicates that the reference is actually to "FOO$non_lazy_ptr -PICBASE", + /// which is a PIC-base-relative reference to a hidden dyld lazy pointer + /// stub. + MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE = 17, //===------------------------------------------------------------------===// // Instruction encodings. These are the standard/most common forms for X86 |