simplify sret handling
authorChris Lattner <sabre@nondot.org>
Wed, 28 Feb 2007 05:39:26 +0000 (05:39 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 28 Feb 2007 05:39:26 +0000 (05:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34728 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp

index 761801ad21d50a84374aa7efd357755a2ece7e9a..e1e9abae9b774dd5f222a0b44fdf9dc67dfbdc99 100644 (file)
@@ -819,7 +819,6 @@ SDOperand X86TargetLowering::LowerCCCCallTo(SDOperand Op, SelectionDAG &DAG,
   SmallVector<SDOperand, 8> MemOpChains;
 
   SDOperand StackPtr;
-  unsigned NumSRetBytes = 0; 
 
   // Walk the register/memloc assignments, inserting copies/loads.
   for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
@@ -850,19 +849,12 @@ SDOperand X86TargetLowering::LowerCCCCallTo(SDOperand Op, SelectionDAG &DAG,
       SDOperand PtrOff = DAG.getConstant(VA.getLocMemOffset(), getPointerTy());
       PtrOff = DAG.getNode(ISD::ADD, getPointerTy(), StackPtr, PtrOff);
       MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0));
-
-      // FIXME: What is this doing?
-      unsigned Flags =
-        cast<ConstantSDNode>(Op.getOperand(5+2*VA.getValNo()+1))->getValue();
-      if ((Flags >> 2) & 1)
-        NumSRetBytes += 4;
     }
   }
 
-  // Sanity check: we haven't seen NumSRetBytes > 4
-  assert((NumSRetBytes<=4) &&
-         "Too much space for struct-return pointer requested");
-    
+  // If the first argument is an sret pointer, remember it.
+  bool isSRet = NumOps &&(cast<ConstantSDNode>(Op.getOperand(6))->getValue()&4);
+  
   if (!MemOpChains.empty())
     Chain = DAG.getNode(ISD::TokenFactor, MVT::Other,
                         &MemOpChains[0], MemOpChains.size());
@@ -926,14 +918,14 @@ SDOperand X86TargetLowering::LowerCCCCallTo(SDOperand Op, SelectionDAG &DAG,
 
   if (CC == CallingConv::X86_StdCall) {
     if (isVarArg)
-      NumBytesForCalleeToPush = NumSRetBytes;
+      NumBytesForCalleeToPush = isSRet ? 4 : 0;
     else
       NumBytesForCalleeToPush = NumBytes;
   } else {
     // If this is is a call to a struct-return function, the callee
     // pops the hidden struct pointer, so we have to push it back.
     // This is common for Darwin/X86, Linux & Mingw32 targets.
-    NumBytesForCalleeToPush = NumSRetBytes;
+    NumBytesForCalleeToPush = isSRet ? 4 : 0;
   }
   
   NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);