More constification of things. More comments added. No functionality
[oota-llvm.git] / lib / CodeGen / SelectionDAG / SelectionDAGISel.cpp
index 76e8d2824e202e0ede33033ce517649fe98961ba..1ee93d7bba103877f670d14585ea21d43b02d945 100644 (file)
@@ -608,6 +608,10 @@ public:
 
   void visitMemIntrinsic(CallInst &I, unsigned Op);
 
+  void visitGetResult(GetResultInst &I) {
+    // FIXME
+  }
+
   void visitUserOp1(Instruction &I) {
     assert(0 && "UserOp1 should not exist at instruction selection time!");
     abort();
@@ -3046,6 +3050,15 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     DAG.setRoot(DAG.getNode(ISD::TRAP, MVT::Other, getRoot()));
     return 0;
   }
+  case Intrinsic::memory_barrier: {
+    SDOperand Ops[6];
+    Ops[0] = getRoot();
+    for (int x = 1; x < 6; ++x)
+      Ops[x] = getValue(I.getOperand(x));
+
+    DAG.setRoot(DAG.getNode(ISD::MEMBARRIER, MVT::Other, &Ops[0], 6));
+    return 0;
+  }
   }
 }
 
@@ -3092,6 +3105,7 @@ void SelectionDAGLowering::LowerCallTo(CallSite CS, SDOperand Callee,
   std::pair<SDOperand,SDOperand> Result =
     TLI.LowerCallTo(getRoot(), CS.getType(),
                     CS.paramHasAttr(0, ParamAttr::SExt),
+                    CS.paramHasAttr(0, ParamAttr::ZExt),
                     FTy->isVarArg(), CS.getCallingConv(), IsTailCall,
                     Callee, Args, DAG);
   if (CS.getType() != Type::VoidTy)
@@ -3951,9 +3965,8 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
   Args.push_back(Entry);
 
   std::pair<SDOperand,SDOperand> Result =
-    TLI.LowerCallTo(getRoot(), I.getType(), false, false, CallingConv::C, true,
-                    DAG.getExternalSymbol("malloc", IntPtr),
-                    Args, DAG);
+    TLI.LowerCallTo(getRoot(), I.getType(), false, false, false, CallingConv::C,
+                    true, DAG.getExternalSymbol("malloc", IntPtr), Args, DAG);
   setValue(&I, Result.first);  // Pointers always fit in registers
   DAG.setRoot(Result.second);
 }
@@ -3966,7 +3979,8 @@ void SelectionDAGLowering::visitFree(FreeInst &I) {
   Args.push_back(Entry);
   MVT::ValueType IntPtr = TLI.getPointerTy();
   std::pair<SDOperand,SDOperand> Result =
-    TLI.LowerCallTo(getRoot(), Type::VoidTy, false, false, CallingConv::C, true,
+    TLI.LowerCallTo(getRoot(), Type::VoidTy, false, false, false,
+                    CallingConv::C, true,
                     DAG.getExternalSymbol("free", IntPtr), Args, DAG);
   DAG.setRoot(Result.second);
 }
@@ -4074,8 +4088,22 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
   
   // Create the node.
   SDNode *Result = DAG.getNode(ISD::FORMAL_ARGUMENTS,
-                               DAG.getNodeValueTypes(RetVals), RetVals.size(),
+                               DAG.getVTList(&RetVals[0], RetVals.size()),
                                &Ops[0], Ops.size()).Val;
+  
+  // Prelower FORMAL_ARGUMENTS.  This isn't required for functionality, but
+  // allows exposing the loads that may be part of the argument access to the
+  // first DAGCombiner pass.
+  SDOperand TmpRes = LowerOperation(SDOperand(Result, 0), DAG);
+  
+  // The number of results should match up, except that the lowered one may have
+  // an extra flag result.
+  assert((Result->getNumValues() == TmpRes.Val->getNumValues() ||
+          (Result->getNumValues()+1 == TmpRes.Val->getNumValues() &&
+           TmpRes.getValue(Result->getNumValues()).getValueType() == MVT::Flag))
+         && "Lowering produced unexpected number of results!");
+  Result = TmpRes.Val;
+  
   unsigned NumArgRegs = Result->getNumValues() - 1;
   DAG.setRoot(SDOperand(Result, NumArgRegs));
 
@@ -4112,9 +4140,9 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
 /// lowered by the target to something concrete.  FIXME: When all targets are
 /// migrated to using ISD::CALL, this hook should be integrated into SDISel.
 std::pair<SDOperand, SDOperand>
-TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, 
-                            bool RetTyIsSigned, bool isVarArg,
-                            unsigned CallingConv, bool isTailCall, 
+TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
+                            bool RetSExt, bool RetZExt, bool isVarArg,
+                            unsigned CallingConv, bool isTailCall,
                             SDOperand Callee,
                             ArgListTy &Args, SelectionDAG &DAG) {
   SmallVector<SDOperand, 32> Ops;
@@ -4195,13 +4223,18 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
 
   // Gather up the call result into a single value.
   if (RetTy != Type::VoidTy) {
-    ISD::NodeType AssertOp = ISD::AssertSext;
-    if (!RetTyIsSigned)
+    ISD::NodeType AssertOp = ISD::DELETED_NODE;
+
+    if (RetSExt)
+      AssertOp = ISD::AssertSext;
+    else if (RetZExt)
       AssertOp = ISD::AssertZext;
+
     SmallVector<SDOperand, 4> Results(NumRegs);
     for (unsigned i = 0; i != NumRegs; ++i)
       Results[i] = Res.getValue(i);
-    Res = getCopyFromParts(DAG, &Results[0], NumRegs, RegisterVT, VT, AssertOp);
+    Res = getCopyFromParts(DAG, &Results[0], NumRegs, RegisterVT, VT,
+                           AssertOp, true);
   }
 
   return std::make_pair(Res, Chain);