[llvm-commits] [llvm] r47484 - in /llvm/trunk: include/llvm/Function.h include/llvm/Instructions.h include/llvm/ParameterAttributes.h include/llvm/Support/CallSite.h include/llvm/Target/TargetLowering.h lib/AsmParser/llvmAsmParser.y lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp lib/VMCore/Function.cpp lib/VMCore/Instructions.cpp

Dale Johannesen dalej at apple.com
Fri Feb 22 09:49:46 PST 2008


Author: johannes
Date: Fri Feb 22 11:49:45 2008
New Revision: 47484

URL: http://llvm.org/viewvc/llvm-project?rev=47484&view=rev
Log:
Pass alignment on ByVal parameters, from FE, all
the way through.  It is now used for codegen.


Modified:
    llvm/trunk/include/llvm/Function.h
    llvm/trunk/include/llvm/Instructions.h
    llvm/trunk/include/llvm/ParameterAttributes.h
    llvm/trunk/include/llvm/Support/CallSite.h
    llvm/trunk/include/llvm/Target/TargetLowering.h
    llvm/trunk/lib/AsmParser/llvmAsmParser.y
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    llvm/trunk/lib/VMCore/Function.cpp
    llvm/trunk/lib/VMCore/Instructions.cpp

Modified: llvm/trunk/include/llvm/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Function.h?rev=47484&r1=47483&r2=47484&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Function.h (original)
+++ llvm/trunk/include/llvm/Function.h Fri Feb 22 11:49:45 2008
@@ -166,6 +166,9 @@
   /// @brief Determine whether the function has the given attribute.
   bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
   
+  /// @brief Extract the alignment for a call or parameter (0=unknown).
+  uint16_t getParamAlignment(uint16_t i) const;
+
   /// @brief Determine if the function cannot return.
   bool doesNotReturn() const;
 

Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=47484&r1=47483&r2=47484&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Fri Feb 22 11:49:45 2008
@@ -941,6 +941,9 @@
   /// @brief Determine whether the call or the callee has the given attribute.
   bool paramHasAttr(uint16_t i, unsigned attr) const;
 
+  /// @brief Extract the alignment for a call or parameter (0=unknown).
+  uint16_t getParamAlignment(uint16_t i) const;
+
   /// @brief Determine if the call does not access memory.
   bool doesNotAccessMemory() const;
   
@@ -1738,6 +1741,9 @@
   /// @brief Determine whether the call or the callee has the given attribute.
   bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
 
+  /// @brief Extract the alignment for a call or parameter (0=unknown).
+  uint16_t getParamAlignment(uint16_t i) const;
+
   /// @brief Determine if the call does not access memory.
   bool doesNotAccessMemory() const;
 

Modified: llvm/trunk/include/llvm/ParameterAttributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ParameterAttributes.h?rev=47484&r1=47483&r2=47484&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ParameterAttributes.h (original)
+++ llvm/trunk/include/llvm/ParameterAttributes.h Fri Feb 22 11:49:45 2008
@@ -69,6 +69,12 @@
 /// @brief Which attributes cannot be applied to a type.
 Attributes typeIncompatible (const Type *Ty);
 
+/// This turns an int alignment (a power of 2, normally) into the
+/// form used internally in ParameterAttributes.
+ParamAttr::Attributes inline constructAlignmentFromInt(uint32_t i) {
+  return (i << 16);
+}
+
 } // end namespace ParamAttr
 
 /// @brief A more friendly way to reference the attributes.
@@ -176,6 +182,13 @@
     bool paramHasAttr(uint16_t i, ParameterAttributes attr) const {
       return getParamAttrs(i) & attr;
     }
+  
+    /// This extracts the alignment for the \p ith function parameter.
+    /// @returns 0 if unknown, else the alignment in bytes
+    /// @brief Extract the Alignment
+    uint16_t getParamAlignment(uint16_t i) const {
+      return (getParamAttrs(i) & ParamAttr::Alignment) >> 16;
+    }
 
     /// This returns whether the given attribute is set for at least one
     /// parameter or for the return value.

Modified: llvm/trunk/include/llvm/Support/CallSite.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CallSite.h?rev=47484&r1=47483&r2=47484&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/CallSite.h (original)
+++ llvm/trunk/include/llvm/Support/CallSite.h Fri Feb 22 11:49:45 2008
@@ -68,6 +68,9 @@
   /// paramHasAttr - whether the call or the callee has the given attribute.
   bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
 
+  /// @brief Extract the alignment for a call or parameter (0=unknown).
+  uint16_t getParamAlignment(uint16_t i) const;
+
   /// @brief Determine if the call does not access memory.
   bool doesNotAccessMemory() const;
 

Modified: llvm/trunk/include/llvm/Target/TargetLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLowering.h?rev=47484&r1=47483&r2=47484&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLowering.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLowering.h Fri Feb 22 11:49:45 2008
@@ -918,9 +918,10 @@
     bool isSRet;
     bool isNest;
     bool isByVal;
+    uint16_t Alignment;
 
     ArgListEntry() : isSExt(false), isZExt(false), isInReg(false),
-      isSRet(false), isNest(false), isByVal(false) { }
+      isSRet(false), isNest(false), isByVal(false), Alignment(0) { }
   };
   typedef std::vector<ArgListEntry> ArgListTy;
   virtual std::pair<SDOperand, SDOperand>

Modified: llvm/trunk/lib/AsmParser/llvmAsmParser.y
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/llvmAsmParser.y?rev=47484&r1=47483&r2=47484&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/llvmAsmParser.y (original)
+++ llvm/trunk/lib/AsmParser/llvmAsmParser.y Fri Feb 22 11:49:45 2008
@@ -1234,7 +1234,8 @@
               | NOALIAS { $$ = ParamAttr::NoAlias;   }
               | BYVAL   { $$ = ParamAttr::ByVal;     }
               | NEST    { $$ = ParamAttr::Nest;      }
-              | ALIGN EUINT64VAL { $$ = $2 << 16;    }
+              | ALIGN EUINT64VAL { $$ = 
+                          ParamAttr::constructAlignmentFromInt($2);    }
               ;
 
 OptParamAttrs : /* empty */  { $$ = ParamAttr::None; }

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

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Fri Feb 22 11:49:45 2008
@@ -3118,6 +3118,7 @@
     Entry.isSRet  = CS.paramHasAttr(attrInd, ParamAttr::StructRet);
     Entry.isNest  = CS.paramHasAttr(attrInd, ParamAttr::Nest);
     Entry.isByVal = CS.paramHasAttr(attrInd, ParamAttr::ByVal);
+    Entry.Alignment = CS.getParamAlignment(attrInd);
     Args.push_back(Entry);
   }
 
@@ -4146,6 +4147,10 @@
       const Type *ElementTy = Ty->getElementType();
       unsigned FrameAlign = Log2_32(getByValTypeAlignment(ElementTy));
       unsigned FrameSize  = getTargetData()->getABITypeSize(ElementTy);
+      // For ByVal, alignment should be passed from FE.  BE will guess if
+      // this info is not there but there are cases it cannot get right.
+      if (F.getParamAlignment(j))
+        FrameAlign = Log2_32(F.getParamAlignment(j));
       Flags |= (FrameAlign << ISD::ParamFlags::ByValAlignOffs);
       Flags |= (FrameSize  << ISD::ParamFlags::ByValSizeOffs);
     }
@@ -4255,6 +4260,10 @@
       const Type *ElementTy = Ty->getElementType();
       unsigned FrameAlign = Log2_32(getByValTypeAlignment(ElementTy));
       unsigned FrameSize  = getTargetData()->getABITypeSize(ElementTy);
+      // For ByVal, alignment should come from FE.  BE will guess if this
+      // info is not there but there are cases it cannot get right.
+      if (Args[i].Alignment)
+        FrameAlign = Log2_32(Args[i].Alignment);
       Flags |= (FrameAlign << ISD::ParamFlags::ByValAlignOffs);
       Flags |= (FrameSize  << ISD::ParamFlags::ByValSizeOffs);
     }

Modified: llvm/trunk/lib/VMCore/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Function.cpp?rev=47484&r1=47483&r2=47484&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Function.cpp (original)
+++ llvm/trunk/lib/VMCore/Function.cpp Fri Feb 22 11:49:45 2008
@@ -143,6 +143,11 @@
   return ParamAttrs && ParamAttrs->paramHasAttr(i, attr);
 }
 
+/// @brief Extract the alignment for a call or parameter (0=unknown).
+uint16_t Function::getParamAlignment(uint16_t i) const {
+  return ParamAttrs ? ParamAttrs->getParamAlignment(i) : 0;
+}
+
 /// @brief Determine if the function cannot return.
 bool Function::doesNotReturn() const {
   return paramHasAttr(0, ParamAttr::NoReturn);

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=47484&r1=47483&r2=47484&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Fri Feb 22 11:49:45 2008
@@ -61,6 +61,13 @@
   else
     return cast<InvokeInst>(I)->paramHasAttr(i, attr);
 }
+uint16_t CallSite::getParamAlignment(uint16_t i) const {
+  if (CallInst *CI = dyn_cast<CallInst>(I))
+    return CI->getParamAlignment(i);
+  else
+    return cast<InvokeInst>(I)->getParamAlignment(i);
+}
+
 bool CallSite::doesNotAccessMemory() const {
   if (CallInst *CI = dyn_cast<CallInst>(I))
     return CI->doesNotAccessMemory();
@@ -384,6 +391,14 @@
   return false;
 }
 
+uint16_t CallInst::getParamAlignment(uint16_t i) const {
+  if (ParamAttrs && ParamAttrs->getParamAlignment(i))
+    return ParamAttrs->getParamAlignment(i);
+  if (const Function *F = getCalledFunction())
+    return F->getParamAlignment(i);
+  return 0;
+}
+
 /// @brief Determine if the call does not access memory.
 bool CallInst::doesNotAccessMemory() const {
   return paramHasAttr(0, ParamAttr::ReadNone);
@@ -508,6 +523,13 @@
   return false;
 }
 
+uint16_t InvokeInst::getParamAlignment(uint16_t i) const {
+  if (ParamAttrs && ParamAttrs->getParamAlignment(i))
+    return ParamAttrs->getParamAlignment(i);
+  if (const Function *F = getCalledFunction())
+    return F->getParamAlignment(i);
+  return 0;
+}
 
 /// @brief Determine if the call does not access memory.
 bool InvokeInst::doesNotAccessMemory() const {





More information about the llvm-commits mailing list