Factor the addressing mode and the load/store VT out of LoadSDNode
[oota-llvm.git] / lib / CodeGen / SelectionDAG / SelectionDAGISel.cpp
index 2934345b603589440655ad9018a69e41b5dad6e0..406011ac9165d51be5f021b3a6cd0d039938016c 100644 (file)
@@ -57,7 +57,7 @@ ViewSchedDAGs("view-sched-dags", cl::Hidden,
           cl::desc("Pop up a window to show sched dags as they are processed"));
 static cl::opt<bool>
 ViewSUnitDAGs("view-sunit-dags", cl::Hidden,
-          cl::desc("Pop up a window to show SUnit dags after they are processed"));
+      cl::desc("Pop up a window to show SUnit dags after they are processed"));
 #else
 static const bool ViewISelDAGs = 0, ViewSchedDAGs = 0, ViewSUnitDAGs = 0;
 #endif
@@ -79,7 +79,8 @@ namespace {
           RegisterPassParser<RegisterScheduler> >
   ISHeuristic("pre-RA-sched",
               cl::init(&createDefaultScheduler),
-              cl::desc("Instruction schedulers available (before register allocation):"));
+              cl::desc("Instruction schedulers available (before register"
+                       " allocation):"));
 
   static RegisterScheduler
   defaultListDAGScheduler("default", "  Best scheduler for the target",
@@ -483,10 +484,6 @@ public:
                         const Value *SV, SDOperand Root,
                         bool isVolatile, unsigned Alignment);
 
-  SDOperand getIntPtrConstant(uint64_t Val) {
-    return DAG.getConstant(Val, TLI.getPointerTy());
-  }
-
   SDOperand getValue(const Value *V);
 
   void setValue(const Value *V, SDOperand NewN) {
@@ -677,12 +674,10 @@ static SDOperand getCopyFromParts(SelectionDAG &DAG,
       }
     }
   
-    if (MVT::isFloatingPoint(PartVT) &&
-        MVT::isFloatingPoint(ValueVT))
-      return DAG.getNode(ISD::FP_ROUND, ValueVT, Val);
+    if (MVT::isFloatingPoint(PartVT) && MVT::isFloatingPoint(ValueVT))
+      return DAG.getNode(ISD::FP_ROUND, ValueVT, Val, DAG.getIntPtrConstant(0));
 
-    if (MVT::getSizeInBits(PartVT) == 
-        MVT::getSizeInBits(ValueVT))
+    if (MVT::getSizeInBits(PartVT) == MVT::getSizeInBits(ValueVT))
       return DAG.getNode(ISD::BIT_CONVERT, ValueVT, Val);
 
     assert(0 && "Unknown mismatch!");
@@ -2163,7 +2158,7 @@ void SelectionDAGLowering::visitFPTrunc(User &I) {
   // FPTrunc is never a no-op cast, no need to check
   SDOperand N = getValue(I.getOperand(0));
   MVT::ValueType DestVT = TLI.getValueType(I.getType());
-  setValue(&I, DAG.getNode(ISD::FP_ROUND, DestVT, N));
+  setValue(&I, DAG.getNode(ISD::FP_ROUND, DestVT, N, DAG.getIntPtrConstant(0)));
 }
 
 void SelectionDAGLowering::visitFPExt(User &I){ 
@@ -2284,7 +2279,7 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
         // N = N + Offset
         uint64_t Offset = TD->getStructLayout(StTy)->getElementOffset(Field);
         N = DAG.getNode(ISD::ADD, N.getValueType(), N,
-                        getIntPtrConstant(Offset));
+                        DAG.getIntPtrConstant(Offset));
       }
       Ty = StTy->getElementType(Field);
     } else {
@@ -2295,7 +2290,8 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
         if (CI->getZExtValue() == 0) continue;
         uint64_t Offs = 
             TD->getABITypeSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
-        N = DAG.getNode(ISD::ADD, N.getValueType(), N, getIntPtrConstant(Offs));
+        N = DAG.getNode(ISD::ADD, N.getValueType(), N,
+                        DAG.getIntPtrConstant(Offs));
         continue;
       }
       
@@ -2320,7 +2316,7 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
         continue;
       }
       
-      SDOperand Scale = getIntPtrConstant(ElementSize);
+      SDOperand Scale = DAG.getIntPtrConstant(ElementSize);
       IdxN = DAG.getNode(ISD::MUL, N.getValueType(), IdxN, Scale);
       N = DAG.getNode(ISD::ADD, N.getValueType(), N, IdxN);
     }
@@ -2348,7 +2344,7 @@ void SelectionDAGLowering::visitAlloca(AllocaInst &I) {
     AllocSize = DAG.getNode(ISD::ZERO_EXTEND, IntPtr, AllocSize);
 
   AllocSize = DAG.getNode(ISD::MUL, IntPtr, AllocSize,
-                          getIntPtrConstant(TySize));
+                          DAG.getIntPtrConstant(TySize));
 
   // Handle alignment.  If the requested alignment is less than or equal to
   // the stack alignment, ignore it.  If the size is greater than or equal to
@@ -2361,12 +2357,12 @@ void SelectionDAGLowering::visitAlloca(AllocaInst &I) {
   // Round the size of the allocation up to the stack alignment size
   // by add SA-1 to the size.
   AllocSize = DAG.getNode(ISD::ADD, AllocSize.getValueType(), AllocSize,
-                          getIntPtrConstant(StackAlign-1));
+                          DAG.getIntPtrConstant(StackAlign-1));
   // Mask out the low bits for alignment purposes.
   AllocSize = DAG.getNode(ISD::AND, AllocSize.getValueType(), AllocSize,
-                          getIntPtrConstant(~(uint64_t)(StackAlign-1)));
+                          DAG.getIntPtrConstant(~(uint64_t)(StackAlign-1)));
 
-  SDOperand Ops[] = { getRoot(), AllocSize, getIntPtrConstant(Align) };
+  SDOperand Ops[] = { getRoot(), AllocSize, DAG.getIntPtrConstant(Align) };
   const MVT::ValueType *VTs = DAG.getNodeValueTypes(AllocSize.getValueType(),
                                                     MVT::Other);
   SDOperand DSA = DAG.getNode(ISD::DYNAMIC_STACKALLOC, VTs, 2, Ops, 3);
@@ -2932,6 +2928,11 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     setValue(&I, DAG.getNode(ISD::FLT_ROUNDS, MVT::i32));
     return 0;
   }
+
+  case Intrinsic::trap: {
+    DAG.setRoot(DAG.getNode(ISD::TRAP, MVT::Other, getRoot()));
+    return 0;
+  }
   }
 }
 
@@ -3249,27 +3250,41 @@ void AsmOperandInfo::ComputeConstraintToUse(const TargetLowering &TLI) {
   if (Codes.size() == 1) {   // Single-letter constraints ('r') are very common.
     ConstraintCode = *Current;
     ConstraintType = CurType;
-    return;
+  } else {
+    unsigned CurGenerality = getConstraintGenerality(CurType);
+
+    // If we have multiple constraints, try to pick the most general one ahead
+    // of time.  This isn't a wonderful solution, but handles common cases.
+    for (unsigned j = 1, e = Codes.size(); j != e; ++j) {
+      TargetLowering::ConstraintType ThisType = TLI.getConstraintType(Codes[j]);
+      unsigned ThisGenerality = getConstraintGenerality(ThisType);
+      if (ThisGenerality > CurGenerality) {
+        // This constraint letter is more general than the previous one,
+        // use it.
+        CurType = ThisType;
+        Current = &Codes[j];
+        CurGenerality = ThisGenerality;
+      }
+    }
+
+    ConstraintCode = *Current;
+    ConstraintType = CurType;
   }
-  
-  unsigned CurGenerality = getConstraintGenerality(CurType);
-  
-  // If we have multiple constraints, try to pick the most general one ahead
-  // of time.  This isn't a wonderful solution, but handles common cases.
-  for (unsigned j = 1, e = Codes.size(); j != e; ++j) {
-    TargetLowering::ConstraintType ThisType = TLI.getConstraintType(Codes[j]);
-    unsigned ThisGenerality = getConstraintGenerality(ThisType);
-    if (ThisGenerality > CurGenerality) {
-      // This constraint letter is more general than the previous one,
-      // use it.
-      CurType = ThisType;
-      Current = &Codes[j];
-      CurGenerality = ThisGenerality;
+
+  if (ConstraintCode == "X") {
+    if (isa<BasicBlock>(CallOperandVal) || isa<ConstantInt>(CallOperandVal))
+      return;
+    // This matches anything.  Labels and constants we handle elsewhere 
+    // ('X' is the only thing that matches labels).  Otherwise, try to 
+    // resolve it to something we know about by looking at the actual 
+    // operand type.
+    std::string s = "";
+    TLI.lowerXConstraint(ConstraintVT, s);
+    if (s!="") {
+      ConstraintCode = s;
+      ConstraintType = TLI.getConstraintType(ConstraintCode);
     }
   }
-  
-  ConstraintCode = *Current;
-  ConstraintType = CurType;
 }
 
 
@@ -3491,7 +3506,8 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) {
     if (OpInfo.CallOperandVal) {
       if (isa<BasicBlock>(OpInfo.CallOperandVal))
         OpInfo.CallOperand = 
-          DAG.getBasicBlock(FuncInfo.MBBMap[cast<BasicBlock>(OpInfo.CallOperandVal)]);
+          DAG.getBasicBlock(FuncInfo.MBBMap[cast<BasicBlock>(
+                                                 OpInfo.CallOperandVal)]);
       else {
         OpInfo.CallOperand = getValue(OpInfo.CallOperandVal);
         const Type *OpTy = OpInfo.CallOperandVal->getType();
@@ -3810,7 +3826,7 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
   // Scale the source by the type size.
   uint64_t ElementSize = TD->getABITypeSize(I.getType()->getElementType());
   Src = DAG.getNode(ISD::MUL, Src.getValueType(),
-                    Src, getIntPtrConstant(ElementSize));
+                    Src, DAG.getIntPtrConstant(ElementSize));
 
   TargetLowering::ArgListTy Args;
   TargetLowering::ArgListEntry Entry;
@@ -3917,8 +3933,7 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
       Flags |= ISD::ParamFlags::ByVal;
       const PointerType *Ty = cast<PointerType>(I->getType());
       const Type *ElementTy = Ty->getElementType();
-      unsigned FrameAlign =
-          Log2_32(getTargetData()->getCallFrameTypeAlignment(ElementTy));
+      unsigned FrameAlign = Log2_32(getByValTypeAlignment(ElementTy));
       unsigned FrameSize  = getTargetData()->getABITypeSize(ElementTy);
       Flags |= (FrameAlign << ISD::ParamFlags::ByValAlignOffs);
       Flags |= (FrameSize  << ISD::ParamFlags::ByValSizeOffs);
@@ -3989,7 +4004,7 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
         Op = DAG.getNode(ISD::TRUNCATE, VT, Op);
       } else {
         assert(MVT::isFloatingPoint(VT) && "Not int or FP?");
-        Op = DAG.getNode(ISD::FP_ROUND, VT, Op);
+        Op = DAG.getNode(ISD::FP_ROUND, VT, Op, DAG.getIntPtrConstant(1));
       }
       Ops.push_back(Op);
       break;
@@ -4047,8 +4062,7 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
       Flags |= ISD::ParamFlags::ByVal;
       const PointerType *Ty = cast<PointerType>(Args[i].Ty);
       const Type *ElementTy = Ty->getElementType();
-      unsigned FrameAlign =
-          Log2_32(getTargetData()->getCallFrameTypeAlignment(ElementTy));
+      unsigned FrameAlign = Log2_32(getByValTypeAlignment(ElementTy));
       unsigned FrameSize  = getTargetData()->getABITypeSize(ElementTy);
       Flags |= (FrameAlign << ISD::ParamFlags::ByValAlignOffs);
       Flags |= (FrameSize  << ISD::ParamFlags::ByValSizeOffs);