Changes in directory llvm/lib/Target/X86:
README.txt updated: 1.150 -> 1.151 X86ATTAsmPrinter.cpp updated: 1.83 -> 1.84 X86AsmPrinter.cpp updated: 1.224 -> 1.225 X86AsmPrinter.h updated: 1.41 -> 1.42 X86ISelDAGToDAG.cpp updated: 1.141 -> 1.142 X86ISelLowering.cpp updated: 1.313 -> 1.314 X86RegisterInfo.cpp updated: 1.188 -> 1.189 X86Subtarget.cpp updated: 1.47 -> 1.48 X86Subtarget.h updated: 1.25 -> 1.26 X86TargetMachine.cpp updated: 1.134 -> 1.135 --- Log message: * PIC codegen for X86/Linux has been implemented * PIC-aware internal structures in X86 Codegen have been refactored * Visibility (default/weak) has been added * Docs fixes (external weak linkage, visibility, formatting) --- Diffs of the changes: (+201 -97) README.txt | 4 - X86ATTAsmPrinter.cpp | 109 +++++++++++++++++++++++++++++++++++++++------------ X86AsmPrinter.cpp | 13 ++---- X86AsmPrinter.h | 11 ----- X86ISelDAGToDAG.cpp | 17 +++++++ X86ISelLowering.cpp | 79 +++++++++++++++++++----------------- X86RegisterInfo.cpp | 4 + X86Subtarget.cpp | 15 +++---- X86Subtarget.h | 25 +++++++++-- X86TargetMachine.cpp | 21 +++++++++ 10 files changed, 201 insertions(+), 97 deletions(-) Index: llvm/lib/Target/X86/README.txt diff -u llvm/lib/Target/X86/README.txt:1.150 llvm/lib/Target/X86/README.txt:1.151 --- llvm/lib/Target/X86/README.txt:1.150 Fri Jan 5 19:30:45 2007 +++ llvm/lib/Target/X86/README.txt Fri Jan 12 13:20:47 2007 @@ -534,10 +534,6 @@ //===---------------------------------------------------------------------===// -We should handle __attribute__ ((__visibility__ ("hidden"))). - -//===---------------------------------------------------------------------===// - int %foo(int* %a, int %t) { entry: br label %cond_true Index: llvm/lib/Target/X86/X86ATTAsmPrinter.cpp diff -u llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.83 llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.84 --- llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.83 Sat Jan 6 18:41:20 2007 +++ llvm/lib/Target/X86/X86ATTAsmPrinter.cpp Fri Jan 12 13:20:47 2007 @@ -19,6 +19,7 @@ #include "X86MachineFunctionInfo.h" #include "X86TargetMachine.h" #include "X86TargetAsmInfo.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/CallingConv.h" #include "llvm/Module.h" #include "llvm/Support/Mangler.h" @@ -29,6 +30,21 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed"); +static std::string computePICLabel(unsigned fnNumber, + const X86Subtarget* Subtarget) +{ + std::string label; + + if (Subtarget->isTargetDarwin()) { + label = "\"L" + utostr_32(fnNumber) + "$pb\""; + } else if (Subtarget->isTargetELF()) { + label = ".Lllvm$" + utostr_32(fnNumber) + "$piclabel"; + } else + assert(0 && "Don't know how to print PIC label!\n"); + + return label; +} + /// getSectionForFunction - Return the section that we should emit the /// specified function body into. std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const { @@ -109,12 +125,15 @@ } break; } + if (F->hasHiddenVisibility()) + O << "\t.hidden " << CurrentFnName << "\n"; + O << CurrentFnName << ":\n"; // Add some workaround for linkonce linkage on Cygwin\MinGW if (Subtarget->isTargetCygMing() && (F->getLinkage() == Function::LinkOnceLinkage || F->getLinkage() == Function::WeakLinkage)) - O << "_llvm$workaround$fake$stub_" << CurrentFnName << ":\n"; + O << "Lllvm$workaround$fake$stub$" << CurrentFnName << ":\n"; if (Subtarget->isTargetDarwin() || Subtarget->isTargetELF() || @@ -193,9 +212,14 @@ if (!isMemOp) O << '$'; O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << "_" << MO.getJumpTableIndex(); - if (X86PICStyle == PICStyle::Stub && - TM.getRelocationModel() == Reloc::PIC_) - O << "-\"L" << getFunctionNumber() << "$pb\""; + + if (TM.getRelocationModel() == Reloc::PIC_) { + if (Subtarget->isPICStyleStub()) + O << "-\"L" << getFunctionNumber() << "$pb\""; + else if (Subtarget->isPICStyleGOT()) + O << "@GOTOFF"; + } + if (isMemOp && Subtarget->is64Bit() && !NotRIPRel) O << "(%rip)"; return; @@ -205,9 +229,14 @@ if (!isMemOp) O << '$'; O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_" << MO.getConstantPoolIndex(); - if (X86PICStyle == PICStyle::Stub && - TM.getRelocationModel() == Reloc::PIC_) - O << "-\"L" << getFunctionNumber() << "$pb\""; + + if (TM.getRelocationModel() == Reloc::PIC_) { + if (Subtarget->isPICStyleStub()) + O << "-\"L" << getFunctionNumber() << "$pb\""; + if (Subtarget->isPICStyleGOT()) + O << "@GOTOFF"; + } + int Offset = MO.getOffset(); if (Offset > 0) O << "+" << Offset; @@ -228,11 +257,11 @@ bool isExt = (GV->isExternal() || GV->hasWeakLinkage() || GV->hasLinkOnceLinkage()); + bool isHidden = GV->hasHiddenVisibility(); X86SharedAsmPrinter::decorateName(Name, GV); - if (X86PICStyle == PICStyle::Stub && - TM.getRelocationModel() != Reloc::Static) { + if (Subtarget->isPICStyleStub()) { // Link-once, External, or Weakly-linked global variables need // non-lazily-resolved stubs if (isExt) { @@ -258,6 +287,12 @@ O << "__imp_"; } O << Name; + + if (Subtarget->isPICStyleGOT() && isCallOp && isa<Function>(GV)) { + // Assemble call via PLT for non-local symbols + if (!isHidden || isExt) + O << "@PLT"; + } } if (GV->hasExternalWeakLinkage()) @@ -269,31 +304,55 @@ else if (Offset < 0) O << Offset; - if (isMemOp && Subtarget->is64Bit()) { - if (isExt && TM.getRelocationModel() != Reloc::Static) - O << "@GOTPCREL(%rip)"; - else if (!NotRIPRel) - // Use rip when possible to reduce code size, except when index or - // base register are also part of the address. e.g. - // foo(%rip)(%rcx,%rax,4) is not legal - O << "(%rip)"; + if (isMemOp) { + if (isExt) { + if (Subtarget->isPICStyleGOT()) { + O << "@GOT"; + } else if (Subtarget->isPICStyleRIPRel()) { + O << "@GOTPCREL(%rip)"; + } if (Subtarget->is64Bit() && !NotRIPRel) + // Use rip when possible to reduce code size, except when + // index or base register are also part of the address. e.g. + // foo(%rip)(%rcx,%rax,4) is not legal + O << "(%rip)"; + } else { + if (Subtarget->is64Bit() && !NotRIPRel) + O << "(%rip)"; + else if (Subtarget->isPICStyleGOT()) + O << "@GOTOFF"; + } } return; } case MachineOperand::MO_ExternalSymbol: { bool isCallOp = Modifier && !strcmp(Modifier, "call"); - if (isCallOp && - X86PICStyle == PICStyle::Stub && - TM.getRelocationModel() != Reloc::Static) { - std::string Name(TAI->getGlobalPrefix()); - Name += MO.getSymbolName(); + std::string Name(TAI->getGlobalPrefix()); + Name += MO.getSymbolName(); + if (isCallOp && Subtarget->isPICStyleStub()) { FnStubs.insert(Name); O << "L" << Name << "$stub"; return; } if (!isCallOp) O << '$'; - O << TAI->getGlobalPrefix() << MO.getSymbolName(); + O << Name; + + if (Subtarget->isPICStyleGOT()) { + std::string GOTName(TAI->getGlobalPrefix()); + GOTName+="_GLOBAL_OFFSET_TABLE_"; + if (Name == GOTName) + // Really hack! Emit extra offset to PC during printing GOT offset to + // compensate size of popl instruction. The resulting code should look + // like: + // call .piclabel + // piclabel: + // popl %some_register + // addl $_GLOBAL_ADDRESS_TABLE_ + [.-piclabel], %some_register + O << " + [.-" << computePICLabel(getFunctionNumber(), Subtarget) << "]"; + } + + if (isCallOp && Subtarget->isPICStyleGOT()) + O << "@PLT"; if (!isCallOp && Subtarget->is64Bit()) O << "(%rip)"; @@ -366,8 +425,8 @@ } void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) { - O << "\"L" << getFunctionNumber() << "$pb\"\n"; - O << "\"L" << getFunctionNumber() << "$pb\":"; + std::string label = computePICLabel(getFunctionNumber(), Subtarget); + O << label << "\n" << label << ":"; } Index: llvm/lib/Target/X86/X86AsmPrinter.cpp diff -u llvm/lib/Target/X86/X86AsmPrinter.cpp:1.224 llvm/lib/Target/X86/X86AsmPrinter.cpp:1.225 --- llvm/lib/Target/X86/X86AsmPrinter.cpp:1.224 Wed Jan 3 05:43:14 2007 +++ llvm/lib/Target/X86/X86AsmPrinter.cpp Fri Jan 12 13:20:47 2007 @@ -105,13 +105,9 @@ /// doInitialization bool X86SharedAsmPrinter::doInitialization(Module &M) { - if (Subtarget->isTargetDarwin()) { - if (!Subtarget->is64Bit()) - X86PICStyle = PICStyle::Stub; - - // Emit initial debug information. - DW.BeginModule(&M); - } else if (Subtarget->isTargetELF() || Subtarget->isTargetCygMing()) { + if (Subtarget->isTargetELF() || + Subtarget->isTargetCygMing() || + Subtarget->isTargetDarwin()) { // Emit initial debug information. DW.BeginModule(&M); } @@ -241,7 +237,6 @@ << "\n"; if (TAI->hasDotTypeDotSizeDirective()) O << "\t.size " << name << ", " << Size << "\n"; - // If the initializer is a extern weak symbol, remember to emit the weak // reference! if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) @@ -251,6 +246,8 @@ EmitGlobalConstant(C); O << '\n'; } + if (I->hasHiddenVisibility()) + O << "\t.hidden " << name << "\n"; } // Output linker support code for dllexported globals Index: llvm/lib/Target/X86/X86AsmPrinter.h diff -u llvm/lib/Target/X86/X86AsmPrinter.h:1.41 llvm/lib/Target/X86/X86AsmPrinter.h:1.42 --- llvm/lib/Target/X86/X86AsmPrinter.h:1.41 Wed Jan 3 05:43:14 2007 +++ llvm/lib/Target/X86/X86AsmPrinter.h Fri Jan 12 13:20:47 2007 @@ -28,19 +28,12 @@ namespace llvm { -// FIXME: Move this to CodeGen/AsmPrinter.h -namespace PICStyle { - enum X86AsmPICStyle { - Stub, GOT - }; -} - struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter { DwarfWriter DW; X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM, const TargetAsmInfo *T) - : AsmPrinter(O, TM, T), DW(O, this, T), X86PICStyle(PICStyle::GOT) { + : AsmPrinter(O, TM, T), DW(O, this, T) { Subtarget = &TM.getSubtarget<X86Subtarget>(); } @@ -73,8 +66,6 @@ MachineFunctionPass::getAnalysisUsage(AU); } - PICStyle::X86AsmPICStyle X86PICStyle; - const X86Subtarget *Subtarget; // Necessary for Darwin to print out the apprioriate types of linker stubs Index: llvm/lib/Target/X86/X86ISelDAGToDAG.cpp diff -u llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:1.141 llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:1.142 --- llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:1.141 Wed Jan 3 05:43:14 2007 +++ llvm/lib/Target/X86/X86ISelDAGToDAG.cpp Fri Jan 12 13:20:47 2007 @@ -938,10 +938,23 @@ MachineBasicBlock &FirstMBB = BB->getParent()->front(); MachineBasicBlock::iterator MBBI = FirstMBB.begin(); SSARegMap *RegMap = BB->getParent()->getSSARegMap(); - GlobalBaseReg = RegMap->createVirtualRegister(X86::GR32RegisterClass); + unsigned PC = RegMap->createVirtualRegister(X86::GR32RegisterClass); + const TargetInstrInfo *TII = TM.getInstrInfo(); BuildMI(FirstMBB, MBBI, TII->get(X86::MovePCtoStack)); - BuildMI(FirstMBB, MBBI, TII->get(X86::POP32r), GlobalBaseReg); + BuildMI(FirstMBB, MBBI, TII->get(X86::POP32r), PC); + + // If we're using vanilla 'GOT' PIC style, we should use relative addressing + // not to pc, but to _GLOBAL_ADDRESS_TABLE_ external + if (Subtarget->isPICStyleGOT()) { + GlobalBaseReg = RegMap->createVirtualRegister(X86::GR32RegisterClass); + BuildMI(FirstMBB, MBBI, TII->get(X86::ADD32ri), GlobalBaseReg). + addReg(PC). + addExternalSymbol("_GLOBAL_OFFSET_TABLE_"); + } else { + GlobalBaseReg = PC; + } + } return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).Val; } Index: llvm/lib/Target/X86/X86ISelLowering.cpp diff -u llvm/lib/Target/X86/X86ISelLowering.cpp:1.313 llvm/lib/Target/X86/X86ISelLowering.cpp:1.314 --- llvm/lib/Target/X86/X86ISelLowering.cpp:1.313 Fri Jan 5 15:37:56 2007 +++ llvm/lib/Target/X86/X86ISelLowering.cpp Fri Jan 12 13:20:47 2007 @@ -664,6 +664,13 @@ InFlag = Chain.getValue(1); } + if (Subtarget->isPICStyleGOT()) { + Chain = DAG.getCopyToReg(Chain, X86::EBX, + DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), + InFlag); + InFlag = Chain.getValue(1); + } + // If the callee is a GlobalAddress node (quite common, every direct call is) // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { @@ -687,7 +694,7 @@ for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) Ops.push_back(DAG.getRegister(RegsToPass[i].first, RegsToPass[i].second.getValueType())); - + if (InFlag.Val) Ops.push_back(InFlag); @@ -3856,12 +3863,12 @@ getPointerTy(), CP->getAlignment()); Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result); - if (Subtarget->isTargetDarwin()) { - // With PIC, the address is actually $g + Offset. - if (!Subtarget->is64Bit() && - getTargetMachine().getRelocationModel() == Reloc::PIC_) - Result = DAG.getNode(ISD::ADD, getPointerTy(), - DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result); + // With PIC, the address is actually $g + Offset. + if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && + !Subtarget->isPICStyleRIPRel()) { + Result = DAG.getNode(ISD::ADD, getPointerTy(), + DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), + Result); } return Result; @@ -3872,19 +3879,19 @@ GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); SDOperand Result = DAG.getTargetGlobalAddress(GV, getPointerTy()); Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result); - if (Subtarget->isTargetDarwin()) { - // With PIC, the address is actually $g + Offset. - if (!Subtarget->is64Bit() && - getTargetMachine().getRelocationModel() == Reloc::PIC_) - Result = DAG.getNode(ISD::ADD, getPointerTy(), - DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), - Result); + // With PIC, the address is actually $g + Offset. + if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && + !Subtarget->isPICStyleRIPRel()) { + Result = DAG.getNode(ISD::ADD, getPointerTy(), + DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), + Result); } // For Darwin & Mingw32, external and weak symbols are indirect, so we want to // load the value at address GV, not the value of GV itself. This means that // the GlobalAddress must be in the base or index register of the address, not // the GV offset field. Platform check is inside GVRequiresExtraLoad() call + // The same applies for external symbols during PIC codegen if (Subtarget->GVRequiresExtraLoad(GV, getTargetMachine(), false)) Result = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), Result, NULL, 0); @@ -3896,13 +3903,27 @@ const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol(); SDOperand Result = DAG.getTargetExternalSymbol(Sym, getPointerTy()); Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result); - if (Subtarget->isTargetDarwin()) { - // With PIC, the address is actually $g + Offset. - if (!Subtarget->is64Bit() && - getTargetMachine().getRelocationModel() == Reloc::PIC_) - Result = DAG.getNode(ISD::ADD, getPointerTy(), - DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), - Result); + // With PIC, the address is actually $g + Offset. + if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && + !Subtarget->isPICStyleRIPRel()) { + Result = DAG.getNode(ISD::ADD, getPointerTy(), + DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), + Result); + } + + return Result; +} + +SDOperand X86TargetLowering::LowerJumpTable(SDOperand Op, SelectionDAG &DAG) { + JumpTableSDNode *JT = cast<JumpTableSDNode>(Op); + SDOperand Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy()); + Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result); + // With PIC, the address is actually $g + Offset. + if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && + !Subtarget->isPICStyleRIPRel()) { + Result = DAG.getNode(ISD::ADD, getPointerTy(), + DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), + Result); } return Result; @@ -4334,22 +4355,6 @@ Cond, Op.getOperand(2), CC, Cond.getValue(1)); } -SDOperand X86TargetLowering::LowerJumpTable(SDOperand Op, SelectionDAG &DAG) { - JumpTableSDNode *JT = cast<JumpTableSDNode>(Op); - SDOperand Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy()); - Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result); - if (Subtarget->isTargetDarwin()) { - // With PIC, the address is actually $g + Offset. - if (!Subtarget->is64Bit() && - getTargetMachine().getRelocationModel() == Reloc::PIC_) - Result = DAG.getNode(ISD::ADD, getPointerTy(), - DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), - Result); - } - - return Result; -} - SDOperand X86TargetLowering::LowerCALL(SDOperand Op, SelectionDAG &DAG) { unsigned CallingConv= cast<ConstantSDNode>(Op.getOperand(1))->getValue(); Index: llvm/lib/Target/X86/X86RegisterInfo.cpp diff -u llvm/lib/Target/X86/X86RegisterInfo.cpp:1.188 llvm/lib/Target/X86/X86RegisterInfo.cpp:1.189 --- llvm/lib/Target/X86/X86RegisterInfo.cpp:1.188 Wed Jan 3 05:43:14 2007 +++ llvm/lib/Target/X86/X86RegisterInfo.cpp Fri Jan 12 13:20:47 2007 @@ -178,6 +178,8 @@ MIB = MIB.addGlobalAddress(MO.getGlobal(), MO.getOffset()); else if (MO.isJumpTableIndex()) MIB = MIB.addJumpTableIndex(MO.getJumpTableIndex()); + else if (MO.isExternalSymbol()) + MIB = MIB.addExternalSymbol(MO.getSymbolName()); else assert(0 && "Unknown operand type!"); } @@ -202,6 +204,8 @@ MIB = MIB.addGlobalAddress(MO.getGlobal(), MO.getOffset()); else if (MO.isJumpTableIndex()) MIB = MIB.addJumpTableIndex(MO.getJumpTableIndex()); + else if (MO.isExternalSymbol()) + MIB = MIB.addExternalSymbol(MO.getSymbolName()); else assert(0 && "Unknown operand for FuseInst!"); } Index: llvm/lib/Target/X86/X86Subtarget.cpp diff -u llvm/lib/Target/X86/X86Subtarget.cpp:1.47 llvm/lib/Target/X86/X86Subtarget.cpp:1.48 --- llvm/lib/Target/X86/X86Subtarget.cpp:1.47 Wed Jan 3 05:43:14 2007 +++ llvm/lib/Target/X86/X86Subtarget.cpp Fri Jan 12 13:20:47 2007 @@ -19,11 +19,11 @@ using namespace llvm; cl::opt<X86Subtarget::AsmWriterFlavorTy> -AsmWriterFlavor("x86-asm-syntax", cl::init(X86Subtarget::unset), +AsmWriterFlavor("x86-asm-syntax", cl::init(X86Subtarget::Unset), cl::desc("Choose style of code to emit from X86 backend:"), cl::values( - clEnumValN(X86Subtarget::att, "att", " Emit AT&T-style assembly"), - clEnumValN(X86Subtarget::intel, "intel", " Emit Intel-style assembly"), + clEnumValN(X86Subtarget::ATT, "att", " Emit AT&T-style assembly"), + clEnumValN(X86Subtarget::Intel, "intel", " Emit Intel-style assembly"), clEnumValEnd)); @@ -36,7 +36,7 @@ bool isDirectCall) const { if (TM.getRelocationModel() != Reloc::Static) - if (isTargetDarwin()) { + if (isTargetDarwin() || isPICStyleGOT()) { return (!isDirectCall && (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() || (GV->isExternal() && !GV->hasNotBeenReadFromBytecode()))); @@ -212,6 +212,7 @@ X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit) : AsmFlavor(AsmWriterFlavor) + , PICStyle(PICStyle::None) , X86SSELevel(NoMMXSSE) , HasX86_64(false) , stackAlignment(8) @@ -270,11 +271,11 @@ // If the asm syntax hasn't been overridden on the command line, use whatever // the target wants. - if (AsmFlavor == X86Subtarget::unset) { + if (AsmFlavor == X86Subtarget::Unset) { if (TargetType == isWindows) { - AsmFlavor = X86Subtarget::intel; + AsmFlavor = X86Subtarget::Intel; } else { - AsmFlavor = X86Subtarget::att; + AsmFlavor = X86Subtarget::ATT; } } Index: llvm/lib/Target/X86/X86Subtarget.h diff -u llvm/lib/Target/X86/X86Subtarget.h:1.25 llvm/lib/Target/X86/X86Subtarget.h:1.26 --- llvm/lib/Target/X86/X86Subtarget.h:1.25 Wed Jan 3 05:43:14 2007 +++ llvm/lib/Target/X86/X86Subtarget.h Fri Jan 12 13:20:47 2007 @@ -22,13 +22,18 @@ class Module; class GlobalValue; class TargetMachine; + +namespace PICStyle { +enum Style { + Stub, GOT, RIPRel, WinPIC, None +}; +} class X86Subtarget : public TargetSubtarget { public: enum AsmWriterFlavorTy { - att, intel, unset + ATT, Intel, Unset }; - protected: enum X86SSEEnum { NoMMXSSE, MMX, SSE1, SSE2, SSE3 @@ -41,6 +46,9 @@ /// AsmFlavor - Which x86 asm dialect to use. AsmWriterFlavorTy AsmFlavor; + /// PICStyle - Which PIC style to use + PICStyle::Style PICStyle; + /// X86SSELevel - MMX, SSE1, SSE2, SSE3, or none supported. X86SSEEnum X86SSELevel; @@ -93,6 +101,9 @@ bool is64Bit() const { return Is64Bit; } + PICStyle::Style getPICStyle() const { return PICStyle; } + void setPICStyle(PICStyle::Style Style) { PICStyle = Style; } + bool hasMMX() const { return X86SSELevel >= MMX; } bool hasSSE1() const { return X86SSELevel >= SSE1; } bool hasSSE2() const { return X86SSELevel >= SSE2; } @@ -100,8 +111,8 @@ bool has3DNow() const { return X863DNowLevel >= ThreeDNow; } bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; } - bool isFlavorAtt() const { return AsmFlavor == att; } - bool isFlavorIntel() const { return AsmFlavor == intel; } + bool isFlavorAtt() const { return AsmFlavor == ATT; } + bool isFlavorIntel() const { return AsmFlavor == Intel; } bool isTargetDarwin() const { return TargetType == isDarwin; } bool isTargetELF() const { return TargetType == isELF; } @@ -111,6 +122,12 @@ TargetType == isCygwin); } bool isTargetCygwin() const { return TargetType == isCygwin; } + bool isPICStyleSet() const { return PICStyle != PICStyle::None; } + bool isPICStyleGOT() const { return PICStyle == PICStyle::GOT; } + bool isPICStyleStub() const { return PICStyle == PICStyle::Stub; } + bool isPICStyleRIPRel() const { return PICStyle == PICStyle::RIPRel; } + bool isPICStyleWinPIC() const { return PICStyle == PICStyle:: WinPIC; } + /// True if accessing the GV requires an extra load. For Windows, dllimported /// symbols are indirect, loading the value at address GV rather then the /// value of GV itself. This means that the GlobalAddress must be in the base Index: llvm/lib/Target/X86/X86TargetMachine.cpp diff -u llvm/lib/Target/X86/X86TargetMachine.cpp:1.134 llvm/lib/Target/X86/X86TargetMachine.cpp:1.135 --- llvm/lib/Target/X86/X86TargetMachine.cpp:1.134 Wed Jan 3 05:43:14 2007 +++ llvm/lib/Target/X86/X86TargetMachine.cpp Fri Jan 12 13:20:47 2007 @@ -127,6 +127,25 @@ if (getCodeModel() == CodeModel::Default) setCodeModel(CodeModel::Small); } + + if (getRelocationModel() == Reloc::PIC_) { + if (Subtarget.isTargetDarwin()) { + if (Subtarget.is64Bit()) + Subtarget.setPICStyle(PICStyle::RIPRel); + else + Subtarget.setPICStyle(PICStyle::Stub); + } else if (Subtarget.isTargetELF()) + Subtarget.setPICStyle(PICStyle::GOT); + else + assert(0 && "Don't know how to generate PIC code for this target!"); + } else if (getRelocationModel() == Reloc::DynamicNoPIC) { + if (Subtarget.isTargetDarwin()) + Subtarget.setPICStyle(PICStyle::Stub); + else if (Subtarget.isTargetCygMing()) + Subtarget.setPICStyle(PICStyle::WinPIC); + else + assert(0 && "Don't know how to generate PIC code for this target!"); + } } //===----------------------------------------------------------------------===// @@ -163,6 +182,8 @@ MachineCodeEmitter &MCE) { // FIXME: Move this to TargetJITInfo! setRelocationModel(Reloc::Static); + Subtarget.setPICStyle(PICStyle::None); + // JIT cannot ensure globals are placed in the lower 4G of address. if (Subtarget.is64Bit()) setCodeModel(CodeModel::Large); _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits