[llvm-commits] [llvm] r40986 - in /llvm/trunk: include/llvm/CodeGen/CallingConvLower.h include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/CallingConvLower.cpp lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp lib/Target/X86/X86ISelLowering.cpp utils/TableGen/CallingConvEmitter.cpp

Rafael Espindola rafael.espindola at gmail.com
Fri Aug 10 07:44:43 PDT 2007


Author: rafael
Date: Fri Aug 10 09:44:42 2007
New Revision: 40986

URL: http://llvm.org/viewvc/llvm-project?rev=40986&view=rev
Log:
propagate struct size and alignment of byval arguments to the DAG

Modified:
    llvm/trunk/include/llvm/CodeGen/CallingConvLower.h
    llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
    llvm/trunk/lib/CodeGen/SelectionDAG/CallingConvLower.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/utils/TableGen/CallingConvEmitter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/CallingConvLower.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/CallingConvLower.h?rev=40986&r1=40985&r2=40986&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/CallingConvLower.h (original)
+++ llvm/trunk/include/llvm/CodeGen/CallingConvLower.h Fri Aug 10 09:44:42 2007
@@ -190,6 +190,10 @@
     StackOffset += Size;
     return Result;
   }
+
+  void HandleStruct(unsigned ValNo, MVT::ValueType ValVT,
+                    MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
+                    unsigned ArgFlags);
 private:
   /// MarkAllocated - Mark a register and all of its aliases as allocated.
   void MarkAllocated(unsigned Reg);

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h?rev=40986&r1=40985&r2=40986&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h Fri Aug 10 09:44:42 2007
@@ -68,6 +68,10 @@
     ByValOffs         = 4,
     Nest              = 1<<5,  ///< Parameter is nested function static chain
     NestOffs          = 5,
+    ByValAlign        = 0xF << 6, //< The alignment of the struct
+    ByValAlignOffs    = 6,
+    ByValSize         = 0x1ffff << 10, //< The size of the struct
+    ByValSizeOffs     = 10,
     OrigAlignment     = 0x1F<<27,
     OrigAlignmentOffs = 27
   };
@@ -200,6 +204,10 @@
     /// Bit 0 - signness
     /// Bit 1 - 'inreg' attribute
     /// Bit 2 - 'sret' attribute
+    /// Bit 4 - 'byval' attribute
+    /// Bit 5 - 'nest' attribute
+    /// Bit 6-9 - alignment of byval structures
+    /// Bit 10-26 - size of byval structures
     /// Bits 31:27 - argument ABI alignment in the first argument piece and
     /// alignment '1' in other argument pieces.
     CALL,

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/CallingConvLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/CallingConvLower.cpp?rev=40986&r1=40985&r2=40986&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/CallingConvLower.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/CallingConvLower.cpp Fri Aug 10 09:44:42 2007
@@ -28,6 +28,17 @@
   UsedRegs.resize(MRI.getNumRegs());
 }
 
+void CCState::HandleStruct(unsigned ValNo, MVT::ValueType ValVT,
+                           MVT::ValueType LocVT, CCValAssign::LocInfo LocInfo,
+                           unsigned ArgFlags) {
+  unsigned Align  = 1 << ((ArgFlags & ISD::ParamFlags::ByValAlign) >>
+                          ISD::ParamFlags::ByValAlignOffs);
+  unsigned Size   = (ArgFlags & ISD::ParamFlags::ByValSize) >>
+      ISD::ParamFlags::ByValSizeOffs;
+  unsigned Offset = AllocateStack(Size, Align);
+
+  addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
+}
 
 /// MarkAllocated - Mark a register and all of its aliases as allocated.
 void CCState::MarkAllocated(unsigned Reg) {
@@ -99,4 +110,3 @@
     }
   }
 }
-

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=40986&r1=40985&r2=40986&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Fri Aug 10 09:44:42 2007
@@ -3836,8 +3836,15 @@
       Flags |= ISD::ParamFlags::InReg;
     if (Attrs && Attrs->paramHasAttr(j, ParamAttr::StructRet))
       Flags |= ISD::ParamFlags::StructReturn;
-    if (Attrs && Attrs->paramHasAttr(j, ParamAttr::ByVal))
+    if (Attrs && Attrs->paramHasAttr(j, ParamAttr::ByVal)) {
       Flags |= ISD::ParamFlags::ByVal;
+      const PointerType *Ty = cast<PointerType>(I->getType());
+      const StructType *STy = cast<StructType>(Ty->getElementType());
+      unsigned StructAlign = Log2_32(getTargetData()->getABITypeAlignment(STy));
+      unsigned StructSize  = getTargetData()->getTypeSize(STy);
+      Flags |= (StructAlign << ISD::ParamFlags::ByValAlignOffs);
+      Flags |= (StructSize  << ISD::ParamFlags::ByValSizeOffs);
+    }
     if (Attrs && Attrs->paramHasAttr(j, ParamAttr::Nest))
       Flags |= ISD::ParamFlags::Nest;
     Flags |= (OriginalAlignment << ISD::ParamFlags::OrigAlignmentOffs);

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=40986&r1=40985&r2=40986&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Aug 10 09:44:42 2007
@@ -1260,7 +1260,12 @@
       int FI = MFI->CreateFixedObject(MVT::getSizeInBits(VA.getValVT())/8,
                                       VA.getLocMemOffset());
       SDOperand FIN = DAG.getFrameIndex(FI, getPointerTy());
-      ArgValues.push_back(DAG.getLoad(VA.getValVT(), Root, FIN, NULL, 0));
+
+      unsigned Flags =  cast<ConstantSDNode>(Op.getOperand(3 + i))->getValue();
+      if (Flags & ISD::ParamFlags::ByVal)
+        ArgValues.push_back(FIN);
+      else
+        ArgValues.push_back(DAG.getLoad(VA.getValVT(), Root, FIN, NULL, 0));
     }
   }
   

Modified: llvm/trunk/utils/TableGen/CallingConvEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CallingConvEmitter.cpp?rev=40986&r1=40985&r2=40986&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/CallingConvEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/CallingConvEmitter.cpp Fri Aug 10 09:44:42 2007
@@ -130,7 +130,9 @@
         << IndentStr << "else\n"
         << IndentStr << IndentStr << "LocInfo = CCValAssign::AExt;\n";
     } else if (Action->isSubClassOf("CCStructAssign")) {
-      O << "assert(0 && \"Not Implemented\");\n";
+      O << IndentStr <<
+          "State.HandleStruct(ValNo, ValVT, LocVT, LocInfo, ArgFlags);\n";
+      O << IndentStr << "return false;\n";
     } else {
       Action->dump();
       throw "Unknown CCAction!";





More information about the llvm-commits mailing list