llvm-mc/AsmParser: Define match classes in the .td file.
[oota-llvm.git] / lib / Target / X86 / X86FastISel.cpp
index bbf773871b0c55598e78b9791be342529f5fb9f2..a4bb1be799e2b93284696792a7ef22ab5743a823 100644 (file)
@@ -29,6 +29,7 @@
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/Support/CallSite.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Target/TargetOptions.h"
 using namespace llvm;
@@ -424,8 +425,7 @@ bool X86FastISel::X86SelectAddress(Value *V, X86AddressMode &AM) {
   // Handle constant address.
   if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
     // Can't handle alternate code models yet.
-    if (TM.getCodeModel() != CodeModel::Default &&
-        TM.getCodeModel() != CodeModel::Small)
+    if (TM.getCodeModel() != CodeModel::Small)
       return false;
 
     // RIP-relative addresses can't have additional register operands.
@@ -441,32 +441,30 @@ bool X86FastISel::X86SelectAddress(Value *V, X86AddressMode &AM) {
     // Okay, we've committed to selecting this global. Set up the basic address.
     AM.GV = GV;
     
-    if (TM.getRelocationModel() == Reloc::PIC_ &&
-        !Subtarget->is64Bit()) {
+    // Allow the subtarget to classify the global.
+    unsigned char GVFlags = Subtarget->ClassifyGlobalReference(GV, TM);
+
+    // If this reference is relative to the pic base, set it now.
+    if (isGlobalRelativeToPICBase(GVFlags)) {
       // 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
+    
+    // Unless the ABI requires an extra load, return a direct reference to
     // the global.
-    if (!Subtarget->GVRequiresExtraLoad(GV, TM, false)) {
+    if (!isGlobalStubReference(GVFlags)) {
       if (Subtarget->isPICStyleRIPRel()) {
         // Use rip-relative addressing if we can.  Above we verified that the
         // 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;
       }
-      
+      AM.GVOpFlags = GVFlags;
       return true;
     }
     
-    // Check to see if we've already materialized this stub loaded value into a
-    // register in this block.  If so, just reuse it.
+    // Ok, we need to do a load from a stub.  If we've already loaded from this
+    // stub, reuse the loaded pointer, otherwise emit the load now.
     DenseMap<const Value*, unsigned>::iterator I = LocalValueMap.find(V);
     unsigned LoadReg;
     if (I != LocalValueMap.end() && I->second != 0) {
@@ -478,39 +476,17 @@ bool X86FastISel::X86SelectAddress(Value *V, X86AddressMode &AM) {
       X86AddressMode StubAM;
       StubAM.Base.Reg = AM.Base.Reg;
       StubAM.GV = GV;
-      
+      StubAM.GVOpFlags = GVFlags;
+
       if (TLI.getPointerTy() == MVT::i64) {
         Opc = X86::MOV64rm;
         RC  = X86::GR64RegisterClass;
         
-        if (Subtarget->isPICStyleRIPRel()) {
-          StubAM.GVOpFlags = X86II::MO_GOTPCREL;
+        if (Subtarget->isPICStyleRIPRel())
           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);
@@ -578,8 +554,7 @@ bool X86FastISel::X86SelectCallAddress(Value *V, X86AddressMode &AM) {
   // Handle constant address.
   if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
     // Can't handle alternate code models yet.
-    if (TM.getCodeModel() != CodeModel::Default &&
-        TM.getCodeModel() != CodeModel::Small)
+    if (TM.getCodeModel() != CodeModel::Small)
       return false;
 
     // RIP-relative addresses can't have additional register operands.
@@ -587,7 +562,7 @@ bool X86FastISel::X86SelectCallAddress(Value *V, X86AddressMode &AM) {
         (AM.Base.Reg != 0 || AM.IndexReg != 0))
       return false;
 
-    // Can't handle TLS yet.
+    // Can't handle TLS or DLLImport.
     if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
       if (GVar->isThreadLocal() || GVar->hasDLLImportLinkage())
         return false;
@@ -597,14 +572,12 @@ bool X86FastISel::X86SelectCallAddress(Value *V, X86AddressMode &AM) {
     
     // No ABI requires an extra load for anything other than DLLImport, which
     // we rejected above. Return a direct reference to the global.
-    assert(!Subtarget->PCRelGVRequiresExtraLoad(GV, TM));
     if (Subtarget->isPICStyleRIPRel()) {
       // Use rip-relative addressing if we can.  Above we verified that the
       // 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_) {
+    } else if (Subtarget->isPICStyleStubPIC()) {
       AM.GVOpFlags = X86II::MO_PIC_BASE_OFFSET;
     } else if (Subtarget->isPICStyleGOT()) {
       AM.GVOpFlags = X86II::MO_GOTOFF;
@@ -1346,7 +1319,7 @@ bool X86FastISel::X86SelectCall(Instruction *I) {
   
     // Promote the value if needed.
     switch (VA.getLocInfo()) {
-    default: assert(0 && "Unknown loc info!");
+    default: llvm_unreachable("Unknown loc info!");
     case CCValAssign::Full: break;
     case CCValAssign::SExt: {
       bool Emitted = X86FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(),
@@ -1378,6 +1351,14 @@ bool X86FastISel::X86SelectCall(Instruction *I) {
       ArgVT = VA.getLocVT();
       break;
     }
+    case CCValAssign::BCvt: {
+      unsigned BC = FastEmit_r(ArgVT.getSimpleVT(), VA.getLocVT().getSimpleVT(),
+                               ISD::BIT_CONVERT, Arg);
+      assert(BC != 0 && "Failed to emit a bitcast!");
+      Arg = BC;
+      ArgVT = VA.getLocVT();
+      break;
+    }
     }
     
     if (VA.isRegLoc()) {
@@ -1438,7 +1419,7 @@ bool X86FastISel::X86SelectCall(Instruction *I) {
         TM.getRelocationModel() == Reloc::PIC_ &&
         GV->hasDefaultVisibility() && !GV->hasLocalLinkage()) {
       OpFlags = X86II::MO_PLT;
-    } else if (Subtarget->isPICStyleStub() &&
+    } else if (Subtarget->isPICStyleStubAny() &&
                (GV->isDeclaration() || GV->isWeakForLinker()) &&
                Subtarget->getDarwinVers() < 9) {
       // PC-relative references to external symbols should go through $stub,
@@ -1646,8 +1627,7 @@ unsigned X86FastISel::TargetMaterializeConstant(Constant *C) {
   // x86-32 PIC requires a PIC base register for constant pools.
   unsigned PICBase = 0;
   unsigned char OpFlag = 0;
-  if (Subtarget->isPICStyleStub() &&
-      TM.getRelocationModel() == Reloc::PIC_) { // Not dynamic-no-pic
+  if (Subtarget->isPICStyleStubPIC()) { // Not dynamic-no-pic
     OpFlag = X86II::MO_PIC_BASE_OFFSET;
     PICBase = getInstrInfo()->getGlobalBaseReg(&MF);
   } else if (Subtarget->isPICStyleGOT()) {