Add predicates for queries on whether an attribute exists.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164264 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2012-09-19 23:35:21 +00:00
parent 3e9b6db60f
commit e853d2e250
2 changed files with 87 additions and 7 deletions

View File

@ -106,6 +106,87 @@ public:
Attributes() : Bits(0) { }
explicit Attributes(uint64_t Val) : Bits(Val) { }
/*implicit*/ Attributes(Attribute::AttrConst Val) : Bits(Val.v) { }
// Attribute query methods.
// FIXME: StackAlignment & Alignment attributes have no predicate methods.
bool hasAttributes() const { return Bits != 0; }
bool hasZExtAttr() const {
return Bits & Attribute::ZExt_i;
}
bool hasSExtAttr() const {
return Bits & Attribute::SExt_i;
}
bool hasNoReturnAttr() const {
return Bits & Attribute::NoReturn_i;
}
bool hasInRegAttr() const {
return Bits & Attribute::InReg_i;
}
bool hasStructRetAttr() const {
return Bits & Attribute::StructRet_i;
}
bool hasNoUnwindAttr() const {
return Bits & Attribute::NoUnwind_i;
}
bool hasNoAliasAttr() const {
return Bits & Attribute::NoAlias_i;
}
bool hasByValAttr() const {
return Bits & Attribute::ByVal_i;
}
bool hasNestAttr() const {
return Bits & Attribute::Nest_i;
}
bool hasReadNoneAttr() const {
return Bits & Attribute::ReadNone_i;
}
bool hasReadOnlyAttr() const {
return Bits & Attribute::ReadOnly_i;
}
bool hasNoInlineAttr() const {
return Bits & Attribute::NoInline_i;
}
bool hasAlwaysInlineAttr() const {
return Bits & Attribute::AlwaysInline_i;
}
bool hasOptimizeForSizeAttr() const {
return Bits & Attribute::OptimizeForSize_i;
}
bool hasStackProtectAttr() const {
return Bits & Attribute::StackProtect_i;
}
bool hasStackProtectReqAttr() const {
return Bits & Attribute::StackProtectReq_i;
}
bool hasNoCaptureAttr() const {
return Bits & Attribute::NoCapture_i;
}
bool hasNoRedZoneAttr() const {
return Bits & Attribute::NoRedZone_i;
}
bool hasNoImplicitFloatAttr() const {
return Bits & Attribute::NoImplicitFloat_i;
}
bool hasNakedAttr() const {
return Bits & Attribute::Naked_i;
}
bool hasInlineHintAttr() const {
return Bits & Attribute::InlineHint_i;
}
bool hasReturnsTwiceAttr() const {
return Bits & Attribute::ReturnsTwice_i;
}
bool hasUWTableAttr() const {
return Bits & Attribute::UWTable_i;
}
bool hasNonLazyBindAttr() const {
return Bits & Attribute::NonLazyBind_i;
}
bool hasAddressSafetyAttr() const {
return Bits & Attribute::AddressSafety_i;
}
// This is a "safe bool() operator".
operator const void *() const { return Bits ? this : 0; }
bool isEmptyOrSingleton() const { return (Bits & (Bits - 1)) == 0; }

View File

@ -996,9 +996,9 @@ void llvm::GetReturnInfo(Type* ReturnType, Attributes attr,
EVT VT = ValueVTs[j];
ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
if (attr & Attribute::SExt)
if (attr.hasSExtAttr())
ExtendKind = ISD::SIGN_EXTEND;
else if (attr & Attribute::ZExt)
else if (attr.hasZExtAttr())
ExtendKind = ISD::ZERO_EXTEND;
// FIXME: C calling convention requires the return type to be promoted to
@ -1016,18 +1016,17 @@ void llvm::GetReturnInfo(Type* ReturnType, Attributes attr,
// 'inreg' on function refers to return value
ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
if (attr & Attribute::InReg)
if (attr.hasInRegAttr())
Flags.setInReg();
// Propagate extension type if any
if (attr & Attribute::SExt)
if (attr.hasSExtAttr())
Flags.setSExt();
else if (attr & Attribute::ZExt)
else if (attr.hasZExtAttr())
Flags.setZExt();
for (unsigned i = 0; i < NumParts; ++i) {
for (unsigned i = 0; i < NumParts; ++i)
Outs.push_back(ISD::OutputArg(Flags, PartVT, /*isFixed=*/true));
}
}
}