move reasoning about darwin $non_lazy_ptr stubs from asmprinter into

isel.

llvm-svn: 75117
This commit is contained in:
Chris Lattner 2009-07-09 06:59:17 +00:00
parent 7452c968e4
commit 72e3deca47
4 changed files with 98 additions and 40 deletions

View File

@ -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()) {
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");
//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 {
} 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");
//assert(MO.getTargetFlags() == 0 || MO_PIC_BASE_OFFSET);
}
} 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;

View File

@ -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,22 +480,39 @@ 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) {
if (TLI.getPointerTy() == MVT::i64) {
Opc = X86::MOV64rm;
RC = X86::GR64RegisterClass;
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 {
Opc = X86::MOV64rm;
RC = X86::GR64RegisterClass;
if (TM.getRelocationModel() != Reloc::Static) {
StubAM.GVOpFlags = X86II::MO_GOTPCREL;
StubAM.Base.Reg = X86::RIP;
// Hidden $non_lazy_ptr reference.
StubAM.GVOpFlags = IsPIC ? X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
X86II::MO_DARWIN_HIDDEN_NONLAZY;
}
}
}

View File

@ -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);

View File

@ -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