diff --git a/include/llvm/ParameterAttributes.h b/include/llvm/ParameterAttributes.h index b66f991084c..0d138fe0e2f 100644 --- a/include/llvm/ParameterAttributes.h +++ b/include/llvm/ParameterAttributes.h @@ -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 diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index 8e6a3b91c1f..3550d713525 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -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)); diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 3d37bcd5890..19f86f9b9c4 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -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(*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) diff --git a/lib/VMCore/ParameterAttributes.cpp b/lib/VMCore/ParameterAttributes.cpp index 840d54b6323..77a2a6e7fe3 100644 --- a/lib/VMCore/ParameterAttributes.cpp +++ b/lib/VMCore/ParameterAttributes.cpp @@ -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(Ty)) - Incompatible |= PointerTypeOnly; - else if (attrs & ParamAttr::ByVal) { - const PointerType *PTy = cast(Ty); + if (const PointerType *PTy = dyn_cast(Ty)) { if (!isa(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; } diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 95f871be339..0f7852d411e 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -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);