[llvm-commits] [llvm] r41768 - in /llvm/trunk: include/llvm/Target/TargetData.h lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp lib/Target/TargetData.cpp lib/Target/X86/X86Subtarget.h test/CodeGen/X86/byval3.ll

Rafael Espindola rafael.espindola at gmail.com
Fri Sep 7 07:52:15 PDT 2007


Author: rafael
Date: Fri Sep  7 09:52:14 2007
New Revision: 41768

URL: http://llvm.org/viewvc/llvm-project?rev=41768&view=rev
Log:
Add support for having different alignment for objects on call frames.
The x86-64 ABI states that objects passed on the stack have
8 byte alignment. Implement that.

Added:
    llvm/trunk/test/CodeGen/X86/byval3.ll
Modified:
    llvm/trunk/include/llvm/Target/TargetData.h
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    llvm/trunk/lib/Target/TargetData.cpp
    llvm/trunk/lib/Target/X86/X86Subtarget.h

Modified: llvm/trunk/include/llvm/Target/TargetData.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetData.h?rev=41768&r1=41767&r2=41768&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetData.h (original)
+++ llvm/trunk/include/llvm/Target/TargetData.h Fri Sep  7 09:52:14 2007
@@ -38,7 +38,8 @@
   INTEGER_ALIGN = 'i',               ///< Integer type alignment
   VECTOR_ALIGN = 'v',                ///< Vector type alignment
   FLOAT_ALIGN = 'f',                 ///< Floating point type alignment
-  AGGREGATE_ALIGN = 'a'              ///< Aggregate alignment
+  AGGREGATE_ALIGN = 'a',             ///< Aggregate alignment
+  STACK_ALIGN = 's'                  ///< Stack objects alignment
 };
 /// Target alignment element.
 ///
@@ -166,6 +167,11 @@
   /// specified type.
   unsigned char getABITypeAlignment(const Type *Ty) const;
 
+  /// getCallFrameTypeAlignment - Return the minimum ABI-required alignment
+  /// for the specified type when it is part of a call frame.
+  unsigned char getCallFrameTypeAlignment(const Type *Ty) const;
+
+
   /// getPrefTypeAlignment - Return the preferred stack/global alignment for
   /// the specified type.
   unsigned char getPrefTypeAlignment(const Type *Ty) const;

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

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Fri Sep  7 09:52:14 2007
@@ -3870,7 +3870,8 @@
       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 StructAlign =
+          Log2_32(getTargetData()->getCallFrameTypeAlignment(STy));
       unsigned StructSize  = getTargetData()->getTypeSize(STy);
       Flags |= (StructAlign << ISD::ParamFlags::ByValAlignOffs);
       Flags |= (StructSize  << ISD::ParamFlags::ByValSizeOffs);
@@ -3999,7 +4000,8 @@
       Flags |= ISD::ParamFlags::ByVal;
       const PointerType *Ty = cast<PointerType>(Args[i].Ty);
       const StructType *STy = cast<StructType>(Ty->getElementType());
-      unsigned StructAlign = Log2_32(getTargetData()->getABITypeAlignment(STy));
+      unsigned StructAlign =
+          Log2_32(getTargetData()->getCallFrameTypeAlignment(STy));
       unsigned StructSize  = getTargetData()->getTypeSize(STy);
       Flags |= (StructAlign << ISD::ParamFlags::ByValAlignOffs);
       Flags |= (StructSize  << ISD::ParamFlags::ByValSizeOffs);

Modified: llvm/trunk/lib/Target/TargetData.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetData.cpp?rev=41768&r1=41767&r2=41768&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetData.cpp (original)
+++ llvm/trunk/lib/Target/TargetData.cpp Fri Sep  7 09:52:14 2007
@@ -182,7 +182,8 @@
   setAlignment(VECTOR_ALIGN,    8,  8, 64);  // v2i32
   setAlignment(VECTOR_ALIGN,   16, 16, 128); // v16i8, v8i16, v4i32, ...
   setAlignment(AGGREGATE_ALIGN, 0,  8,  0);  // struct, union, class, ...
-  
+  setAlignment(STACK_ALIGN,     0,  8,  0);  // objects on the stack
+
   while (!temp.empty()) {
     std::string token = getToken(temp, "-");
     std::string arg0 = getToken(token, ":");
@@ -204,10 +205,16 @@
     case 'i':
     case 'v':
     case 'f':
-    case 'a': {
-      AlignTypeEnum align_type = 
-        (*p == 'i' ? INTEGER_ALIGN : (*p == 'f' ? FLOAT_ALIGN :
-           (*p == 'v' ? VECTOR_ALIGN : AGGREGATE_ALIGN)));
+    case 'a':
+    case 's': {
+      AlignTypeEnum align_type;
+      switch(*p) {
+        case 'i': align_type = INTEGER_ALIGN; break;
+        case 'v': align_type = VECTOR_ALIGN; break;
+        case 'f': align_type = FLOAT_ALIGN; break;
+        case 'a': align_type = AGGREGATE_ALIGN; break;
+        case 's': align_type = STACK_ALIGN; break;
+      }
       uint32_t size = (uint32_t) atoi(++p);
       unsigned char abi_align = atoi(getToken(token, ":").c_str()) / 8;
       unsigned char pref_align = atoi(getToken(token, ":").c_str()) / 8;
@@ -529,6 +536,14 @@
   return getAlignment(Ty, true);
 }
 
+unsigned char TargetData::getCallFrameTypeAlignment(const Type *Ty) const {
+  for (unsigned i = 0, e = Alignments.size(); i != e; ++i)
+    if (Alignments[i].AlignType == STACK_ALIGN)
+      return Alignments[i].ABIAlign;
+
+  return getABITypeAlignment(Ty);
+}
+
 unsigned char TargetData::getPrefTypeAlignment(const Type *Ty) const {
   return getAlignment(Ty, false);
 }

Modified: llvm/trunk/lib/Target/X86/X86Subtarget.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Subtarget.h?rev=41768&r1=41767&r2=41768&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86Subtarget.h (original)
+++ llvm/trunk/lib/Target/X86/X86Subtarget.h Fri Sep  7 09:52:14 2007
@@ -146,7 +146,7 @@
   std::string getDataLayout() const {
     const char *p;
     if (is64Bit())
-      p = "e-p:64:64-f64:64:64-i64:64:64-f80:128:128";
+      p = "e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128";
     else {
       if (isTargetDarwin())
         p = "e-p:32:32-f64:32:64-i64:32:64-f80:128:128";

Added: llvm/trunk/test/CodeGen/X86/byval3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/byval3.ll?rev=41768&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/byval3.ll (added)
+++ llvm/trunk/test/CodeGen/X86/byval3.ll Fri Sep  7 09:52:14 2007
@@ -0,0 +1,25 @@
+; RUN: llvm-as < %s | llc -march=x86-64 | grep rep.movsl | count 2
+
+%struct.s = type { i32, i32, i32, i32, i32, i32 }
+
+define void @g(i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6) {
+entry:
+        %d = alloca %struct.s, align 16
+        %tmp = getelementptr %struct.s* %d, i32 0, i32 0
+        store i32 %a1, i32* %tmp, align 16
+        %tmp2 = getelementptr %struct.s* %d, i32 0, i32 1
+        store i32 %a2, i32* %tmp2, align 16
+        %tmp4 = getelementptr %struct.s* %d, i32 0, i32 2
+        store i32 %a3, i32* %tmp4, align 16
+        %tmp6 = getelementptr %struct.s* %d, i32 0, i32 3
+        store i32 %a4, i32* %tmp6, align 16
+        %tmp8 = getelementptr %struct.s* %d, i32 0, i32 4
+        store i32 %a5, i32* %tmp8, align 16
+        %tmp10 = getelementptr %struct.s* %d, i32 0, i32 5
+        store i32 %a6, i32* %tmp10, align 16
+        call void @f( %struct.s* %d byval)
+        call void @f( %struct.s* %d byval)
+        ret void
+}
+
+declare void @f(%struct.s* byval)





More information about the llvm-commits mailing list