Small cleanup for handling of type/parameter attribute
authorDuncan Sands <baldrick@free.fr>
Mon, 7 Jan 2008 17:16:06 +0000 (17:16 +0000)
committerDuncan Sands <baldrick@free.fr>
Mon, 7 Jan 2008 17:16:06 +0000 (17:16 +0000)
incompatibility.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45704 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ParameterAttributes.h
lib/Transforms/IPO/DeadArgumentElimination.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/VMCore/ParameterAttributes.cpp
lib/VMCore/Verifier.cpp

index b66f991084c3e851a386c770b2ef54ccf546d8c6..0d138fe0e2f7f2747a883d05cedb7874a65d660b 100644 (file)
@@ -52,12 +52,6 @@ const uint16_t ParameterOnly = ByVal | InReg | Nest | StructRet;
 /// @brief Attributes that only apply to function return values.
 const uint16_t ReturnOnly = NoReturn | NoUnwind | ReadNone | ReadOnly;
 
-/// @brief Attributes that only apply to integers.
-const uint16_t IntegerTypeOnly = SExt | ZExt;
-
-/// @brief Attributes that only apply to pointers.
-const uint16_t PointerTypeOnly = ByVal | Nest | NoAlias | StructRet;
-
 /// @brief Attributes that are mutually incompatible.
 const uint16_t MutuallyIncompatible[3] = {
   ByVal | InReg | Nest  | StructRet,
@@ -65,8 +59,8 @@ const uint16_t MutuallyIncompatible[3] = {
   ReadNone | ReadOnly
 };
 
-/// @brief Which of the given attributes do not apply to the type.
-uint16_t incompatibleWithType (const Type *Ty, uint16_t attrs);
+/// @brief Which attributes cannot be applied to a type.
+uint16_t typeIncompatible (const Type *Ty);
 
 } // end namespace ParamAttr
 
index 8e6a3b91c1f4d2a440a88e99213cde3da76b540b..3550d7135250fa5701ca9f4518aebec515ce3c59 100644 (file)
@@ -505,7 +505,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
   const Type *RetTy = FTy->getReturnType();
   if (DeadRetVal.count(F)) {
     RetTy = Type::VoidTy;
-    RAttrs &= ~ParamAttr::incompatibleWithType(RetTy, RAttrs);
+    RAttrs &= ~ParamAttr::typeIncompatible(RetTy);
     DeadRetVal.erase(F);
   }
 
@@ -561,7 +561,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
     // The call return attributes.
     uint16_t RAttrs = PAL ? PAL->getParamAttrs(0) : 0;
     // Adjust in case the function was changed to return void.
-    RAttrs &= ~ParamAttr::incompatibleWithType(NF->getReturnType(), RAttrs);
+    RAttrs &= ~ParamAttr::typeIncompatible(NF->getReturnType());
     if (RAttrs)
       ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, RAttrs));
 
index 3d37bcd5890d54f9634ce5b362904e1b4cedb885..19f86f9b9c45972c8b4de1a63fe7d79fa8ed44f8 100644 (file)
@@ -8097,10 +8097,11 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
         FT->getReturnType() != Type::VoidTy)
       return false;   // Cannot transform this return value.
 
-    if (!Caller->use_empty() && CallerPAL &&
-        ParamAttr::incompatibleWithType(FT->getReturnType(),
-                                        CallerPAL->getParamAttrs(0)))
-      return false;   // Attribute not compatible with transformed value.
+    if (CallerPAL && !Caller->use_empty()) {
+      uint16_t RAttrs = CallerPAL->getParamAttrs(0);
+      if (RAttrs & ParamAttr::typeIncompatible(FT->getReturnType()))
+        return false;   // Attribute not compatible with transformed value.
+    }
 
     // If the callsite is an invoke instruction, and the return value is used by
     // a PHI node in a successor, we cannot change the return type of the call
@@ -8127,9 +8128,11 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
     if (!CastInst::isCastable(ActTy, ParamTy))
       return false;   // Cannot transform this parameter value.
 
-    if (CallerPAL &&
-        ParamAttr::incompatibleWithType(ParamTy, CallerPAL->getParamAttrs(i+1)))
-      return false;   // Attribute not compatible with transformed value.
+    if (CallerPAL) {
+      uint16_t PAttrs = CallerPAL->getParamAttrs(i + 1);
+      if (PAttrs & ParamAttr::typeIncompatible(ParamTy))
+        return false;   // Attribute not compatible with transformed value.
+    }
 
     ConstantInt *c = dyn_cast<ConstantInt>(*AI);
     // Some conversions are safe even if we do not have a body.
@@ -8168,7 +8171,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
 
   // If the return value is not being used, the type may not be compatible
   // with the existing attributes.  Wipe out any problematic attributes.
-  RAttrs &= ~ParamAttr::incompatibleWithType(FT->getReturnType(), RAttrs);
+  RAttrs &= ~ParamAttr::typeIncompatible(FT->getReturnType());
 
   // Add the new return attributes.
   if (RAttrs)
index 840d54b6323fc017b7e1cc4c71d2c4a969a53465..77a2a6e7fe3317ff91faa08e141d210a2df8a6ca 100644 (file)
@@ -186,19 +186,21 @@ ParamAttrsList::excludeAttrs(const ParamAttrsList *PAL,
   return getModified(PAL, modVec);
 }
 
-uint16_t ParamAttr::incompatibleWithType (const Type *Ty, uint16_t attrs) {
+uint16_t ParamAttr::typeIncompatible (const Type *Ty) {
   uint16_t Incompatible = None;
 
   if (!Ty->isInteger())
-    Incompatible |= IntegerTypeOnly;
+    // Attributes that only apply to integers.
+    Incompatible |= SExt | ZExt;
 
-  if (!isa<PointerType>(Ty))
-    Incompatible |= PointerTypeOnly;
-  else if (attrs & ParamAttr::ByVal) {
-    const PointerType *PTy = cast<PointerType>(Ty);
+  if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
     if (!isa<StructType>(PTy->getElementType()))
+      // Attributes that only apply to pointers to structs.
       Incompatible |= ParamAttr::ByVal;
+  } else {
+    // Attributes that only apply to pointers.
+    Incompatible |= ByVal | Nest | NoAlias | StructRet;
   }
 
-  return attrs & Incompatible;
+  return Incompatible;
 }
index 95f871be339d867a0164e050787ee078c3ee71a3..0f7852d411e923e9fabfb0eefa812a2f66a8e4c5 100644 (file)
@@ -418,10 +418,10 @@ void Verifier::VerifyParamAttrs(const FunctionType *FT,
               Attrs->getParamAttrsText(MutI) + "are incompatible!", V);
     }
 
-    uint16_t IType = ParamAttr::incompatibleWithType(FT->getParamType(Idx-1),
-                                                     Attr);
-    Assert1(!IType, "Wrong type for attribute " +
-            Attrs->getParamAttrsText(IType), V);
+    uint16_t TypeI =
+      Attr & ParamAttr::typeIncompatible(FT->getParamType(Idx-1));
+    Assert1(!TypeI, "Wrong type for attribute " +
+            Attrs->getParamAttrsText(TypeI), V);
 
     if (Attr & ParamAttr::Nest) {
       Assert1(!SawNest, "More than one parameter has attribute nest!", V);