add a couple of predicates to test for "stub style pic in PIC mode" and "stub style pic in dynamic-no-pic" mode.

llvm-svn: 75273
This commit is contained in:
Chris Lattner 2009-07-10 20:47:30 +00:00
parent 028e6158c2
commit e2f524f176
5 changed files with 40 additions and 34 deletions

View File

@ -603,15 +603,12 @@ void X86ATTAsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
O << JTEntryDirective << ' '; O << JTEntryDirective << ' ';
if (TM.getRelocationModel() == Reloc::PIC_) { if (Subtarget->isPICStyleRIPRel() || Subtarget->isPICStyleStubPIC(TM)) {
if (Subtarget->isPICStyleRIPRel() || Subtarget->isPICStyleStub()) { O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
O << TAI->getPrivateGlobalPrefix() << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber();
<< '_' << uid << "_set_" << MBB->getNumber(); } else if (Subtarget->isPICStyleGOT()) {
} else if (Subtarget->isPICStyleGOT()) { printBasicBlockLabel(MBB, false, false, false);
printBasicBlockLabel(MBB, false, false, false); O << "@GOTOFF";
O << "@GOTOFF";
} else
assert(0 && "Don't know how to print MBB label for this PIC mode");
} else } else
printBasicBlockLabel(MBB, false, false, false); printBasicBlockLabel(MBB, false, false, false);
} }

View File

@ -578,8 +578,7 @@ bool X86FastISel::X86SelectCallAddress(Value *V, X86AddressMode &AM) {
// base and index registers are unused. // base and index registers are unused.
assert(AM.Base.Reg == 0 && AM.IndexReg == 0); assert(AM.Base.Reg == 0 && AM.IndexReg == 0);
AM.Base.Reg = X86::RIP; AM.Base.Reg = X86::RIP;
} else if (Subtarget->isPICStyleStub() && } else if (Subtarget->isPICStyleStubPIC(TM)) {
TM.getRelocationModel() == Reloc::PIC_) {
AM.GVOpFlags = X86II::MO_PIC_BASE_OFFSET; AM.GVOpFlags = X86II::MO_PIC_BASE_OFFSET;
} else if (Subtarget->isPICStyleGOT()) { } else if (Subtarget->isPICStyleGOT()) {
AM.GVOpFlags = X86II::MO_GOTOFF; AM.GVOpFlags = X86II::MO_GOTOFF;
@ -1413,7 +1412,7 @@ bool X86FastISel::X86SelectCall(Instruction *I) {
TM.getRelocationModel() == Reloc::PIC_ && TM.getRelocationModel() == Reloc::PIC_ &&
GV->hasDefaultVisibility() && !GV->hasLocalLinkage()) { GV->hasDefaultVisibility() && !GV->hasLocalLinkage()) {
OpFlags = X86II::MO_PLT; OpFlags = X86II::MO_PLT;
} else if (Subtarget->isPICStyleStub() && } else if (Subtarget->isPICStyleStubAny() &&
(GV->isDeclaration() || GV->isWeakForLinker()) && (GV->isDeclaration() || GV->isWeakForLinker()) &&
Subtarget->getDarwinVers() < 9) { Subtarget->getDarwinVers() < 9) {
// PC-relative references to external symbols should go through $stub, // PC-relative references to external symbols should go through $stub,
@ -1621,8 +1620,7 @@ unsigned X86FastISel::TargetMaterializeConstant(Constant *C) {
// x86-32 PIC requires a PIC base register for constant pools. // x86-32 PIC requires a PIC base register for constant pools.
unsigned PICBase = 0; unsigned PICBase = 0;
unsigned char OpFlag = 0; unsigned char OpFlag = 0;
if (Subtarget->isPICStyleStub() && if (Subtarget->isPICStyleStubPIC(TM)) { // Not dynamic-no-pic
TM.getRelocationModel() == Reloc::PIC_) { // Not dynamic-no-pic
OpFlag = X86II::MO_PIC_BASE_OFFSET; OpFlag = X86II::MO_PIC_BASE_OFFSET;
PICBase = getInstrInfo()->getGlobalBaseReg(&MF); PICBase = getInstrInfo()->getGlobalBaseReg(&MF);
} else if (Subtarget->isPICStyleGOT()) { } else if (Subtarget->isPICStyleGOT()) {

View File

@ -1913,7 +1913,7 @@ SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
getTargetMachine().getRelocationModel() == Reloc::PIC_ && getTargetMachine().getRelocationModel() == Reloc::PIC_ &&
GV->hasDefaultVisibility() && !GV->hasLocalLinkage()) { GV->hasDefaultVisibility() && !GV->hasLocalLinkage()) {
OpFlags = X86II::MO_PLT; OpFlags = X86II::MO_PLT;
} else if (Subtarget->isPICStyleStub() && } else if (Subtarget->isPICStyleStubAny() &&
(GV->isDeclaration() || GV->isWeakForLinker()) && (GV->isDeclaration() || GV->isWeakForLinker()) &&
Subtarget->getDarwinVers() < 9) { Subtarget->getDarwinVers() < 9) {
// PC-relative references to external symbols should go through $stub, // PC-relative references to external symbols should go through $stub,
@ -1933,7 +1933,7 @@ SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
if (Subtarget->isTargetELF() && if (Subtarget->isTargetELF() &&
getTargetMachine().getRelocationModel() == Reloc::PIC_) { getTargetMachine().getRelocationModel() == Reloc::PIC_) {
OpFlags = X86II::MO_PLT; OpFlags = X86II::MO_PLT;
} else if (Subtarget->isPICStyleStub() && } else if (Subtarget->isPICStyleStubAny() &&
Subtarget->getDarwinVers() < 9) { Subtarget->getDarwinVers() < 9) {
// PC-relative references to external symbols should go through $stub, // PC-relative references to external symbols should go through $stub,
// unless we're building with the leopard linker or later, which // unless we're building with the leopard linker or later, which
@ -4454,14 +4454,12 @@ X86TargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) {
unsigned WrapperKind = X86ISD::Wrapper; unsigned WrapperKind = X86ISD::Wrapper;
if (Subtarget->is64Bit() && if (Subtarget->is64Bit() &&
getTargetMachine().getCodeModel() == CodeModel::Small) { getTargetMachine().getCodeModel() == CodeModel::Small)
WrapperKind = X86ISD::WrapperRIP; WrapperKind = X86ISD::WrapperRIP;
} else if (Subtarget->isPICStyleGOT()) { else if (Subtarget->isPICStyleGOT())
OpFlag = X86II::MO_GOTOFF; OpFlag = X86II::MO_GOTOFF;
} else if (Subtarget->isPICStyleStub() && else if (Subtarget->isPICStyleStubPIC(getTargetMachine()))
getTargetMachine().getRelocationModel() == Reloc::PIC_) {
OpFlag = X86II::MO_PIC_BASE_OFFSET; OpFlag = X86II::MO_PIC_BASE_OFFSET;
}
SDValue Result = DAG.getTargetConstantPool(CP->getConstVal(), getPointerTy(), SDValue Result = DAG.getTargetConstantPool(CP->getConstVal(), getPointerTy(),
CP->getAlignment(), CP->getAlignment(),
@ -4487,14 +4485,13 @@ SDValue X86TargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) {
unsigned char OpFlag = 0; unsigned char OpFlag = 0;
unsigned WrapperKind = X86ISD::Wrapper; unsigned WrapperKind = X86ISD::Wrapper;
if (Subtarget->is64Bit()) { if (Subtarget->is64Bit() &&
getTargetMachine().getCodeModel() == CodeModel::Small)
WrapperKind = X86ISD::WrapperRIP; WrapperKind = X86ISD::WrapperRIP;
} else if (Subtarget->isPICStyleGOT()) { else if (Subtarget->isPICStyleGOT())
OpFlag = X86II::MO_GOTOFF; OpFlag = X86II::MO_GOTOFF;
} else if (Subtarget->isPICStyleStub() && else if (Subtarget->isPICStyleStubPIC(getTargetMachine()))
getTargetMachine().getRelocationModel() == Reloc::PIC_) {
OpFlag = X86II::MO_PIC_BASE_OFFSET; OpFlag = X86II::MO_PIC_BASE_OFFSET;
}
SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy(), SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy(),
OpFlag); OpFlag);
@ -4520,14 +4517,13 @@ X86TargetLowering::LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) {
// global base reg. // global base reg.
unsigned char OpFlag = 0; unsigned char OpFlag = 0;
unsigned WrapperKind = X86ISD::Wrapper; unsigned WrapperKind = X86ISD::Wrapper;
if (Subtarget->is64Bit()) { if (Subtarget->is64Bit() &&
getTargetMachine().getCodeModel() == CodeModel::Small)
WrapperKind = X86ISD::WrapperRIP; WrapperKind = X86ISD::WrapperRIP;
} else if (Subtarget->isPICStyleGOT()) { else if (Subtarget->isPICStyleGOT())
OpFlag = X86II::MO_GOTOFF; OpFlag = X86II::MO_GOTOFF;
} else if (Subtarget->isPICStyleStub() && else if (Subtarget->isPICStyleStubPIC(getTargetMachine()))
getTargetMachine().getRelocationModel() == Reloc::PIC_) {
OpFlag = X86II::MO_PIC_BASE_OFFSET; OpFlag = X86II::MO_PIC_BASE_OFFSET;
}
SDValue Result = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlag); SDValue Result = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlag);

View File

@ -34,6 +34,17 @@ AsmWriterFlavor("x86-asm-syntax", cl::init(X86Subtarget::Unset),
clEnumValN(X86Subtarget::Intel, "intel", "Emit Intel-style assembly"), clEnumValN(X86Subtarget::Intel, "intel", "Emit Intel-style assembly"),
clEnumValEnd)); clEnumValEnd));
bool X86Subtarget::isPICStyleStubPIC(const TargetMachine &TM) const {
return PICStyle == PICStyles::Stub &&
TM.getRelocationModel() == Reloc::PIC_;
}
bool X86Subtarget::isPICStyleStubNoDynamic(const TargetMachine &TM) const {
return PICStyle == PICStyles::Stub &&
TM.getRelocationModel() == Reloc::DynamicNoPIC;
}
/// ClassifyGlobalReference - Classify a global variable reference for the /// ClassifyGlobalReference - Classify a global variable reference for the
/// current subtarget according to how we should reference it in a non-pcrel /// current subtarget according to how we should reference it in a non-pcrel
@ -76,7 +87,7 @@ ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
return X86II::MO_GOT; return X86II::MO_GOT;
} }
if (isPICStyleStub()) { if (isPICStyleStubAny()) {
// In Darwin/32, we have multiple different stub types, and we have both PIC // In Darwin/32, we have multiple different stub types, and we have both PIC
// and -mdynamic-no-pic. Determine whether we have a stub reference // and -mdynamic-no-pic. Determine whether we have a stub reference
// and/or whether the reference is relative to the PIC base or not. // and/or whether the reference is relative to the PIC base or not.

View File

@ -184,10 +184,14 @@ public:
bool isPICStyleSet() const { return PICStyle != PICStyles::None; } bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; } bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
bool isPICStyleStub() const { return PICStyle == PICStyles::Stub; }
bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; } bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
bool isPICStyleStubPIC(const TargetMachine &TM) const;
bool isPICStyleStubNoDynamic(const TargetMachine &TM) const;
bool isPICStyleStubAny() const { return PICStyle == PICStyles::Stub; }
/// getDarwinVers - Return the darwin version number, 8 = tiger, 9 = leopard. /// getDarwinVers - Return the darwin version number, 8 = Tiger, 9 = Leopard,
/// 10 = Snow Leopard, etc.
unsigned getDarwinVers() const { return DarwinVers; } unsigned getDarwinVers() const { return DarwinVers; }
/// isLinux - Return true if the target is "Linux". /// isLinux - Return true if the target is "Linux".