Small cleanup for handling of type/parameter attribute

incompatibility.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45704 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan Sands 2008-01-07 17:16:06 +00:00
parent 30d15751c8
commit 6c3470efdc
5 changed files with 28 additions and 29 deletions

View 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

View 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));

View 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)))
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)))
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)

View 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;
}

View 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);