diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -56,8 +56,21 @@ class BranchProbabilityInfo; class BlockFrequencyInfo; +/// Helper class that forces all accesses to the function parameter attributes +/// go through a set/get interface. +class FnAttributeList { + /// Parameter attributes. + AttributeList Attrs; + +public: + void setAttributes(AttributeList NewAttrs); + const AttributeList &getAttributes() const { return Attrs; } +}; + class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject, - public ilist_node { + public ilist_node, + public FnAttributeList { + friend class AttributeListSetGet; public: using BasicBlockListType = SymbolTableList; @@ -75,7 +88,6 @@ size_t NumArgs; std::unique_ptr SymTab; ///< Symbol table of args/instructions - AttributeList AttributeSets; ///< Parameter attributes /* * Value::SubclassData @@ -309,12 +321,6 @@ void setGC(std::string Str); void clearGC(); - /// Return the attribute list for this Function. - AttributeList getAttributes() const { return AttributeSets; } - - /// Set the attribute list for this Function. - void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; } - // TODO: remove non-AtIndex versions of these methods. /// adds the attribute to the list of attributes. void addAttributeAtIndex(unsigned i, Attribute Attr); @@ -423,7 +429,7 @@ /// Return the stack alignment for the function. MaybeAlign getFnStackAlign() const { - return AttributeSets.getFnStackAlignment(); + return getAttributes().getFnStackAlignment(); } /// Returns true if the function has ssp, sspstrong, or sspreq fn attrs. @@ -438,49 +444,49 @@ void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes); MaybeAlign getParamAlign(unsigned ArgNo) const { - return AttributeSets.getParamAlignment(ArgNo); + return getAttributes().getParamAlignment(ArgNo); } MaybeAlign getParamStackAlign(unsigned ArgNo) const { - return AttributeSets.getParamStackAlignment(ArgNo); + return getAttributes().getParamStackAlignment(ArgNo); } /// Extract the byval type for a parameter. Type *getParamByValType(unsigned ArgNo) const { - return AttributeSets.getParamByValType(ArgNo); + return getAttributes().getParamByValType(ArgNo); } /// Extract the sret type for a parameter. Type *getParamStructRetType(unsigned ArgNo) const { - return AttributeSets.getParamStructRetType(ArgNo); + return getAttributes().getParamStructRetType(ArgNo); } /// Extract the inalloca type for a parameter. Type *getParamInAllocaType(unsigned ArgNo) const { - return AttributeSets.getParamInAllocaType(ArgNo); + return getAttributes().getParamInAllocaType(ArgNo); } /// Extract the byref type for a parameter. Type *getParamByRefType(unsigned ArgNo) const { - return AttributeSets.getParamByRefType(ArgNo); + return getAttributes().getParamByRefType(ArgNo); } /// Extract the preallocated type for a parameter. Type *getParamPreallocatedType(unsigned ArgNo) const { - return AttributeSets.getParamPreallocatedType(ArgNo); + return getAttributes().getParamPreallocatedType(ArgNo); } /// Extract the number of dereferenceable bytes for a parameter. /// @param ArgNo Index of an argument, with 0 being the first function arg. uint64_t getParamDereferenceableBytes(unsigned ArgNo) const { - return AttributeSets.getParamDereferenceableBytes(ArgNo); + return getAttributes().getParamDereferenceableBytes(ArgNo); } /// Extract the number of dereferenceable_or_null bytes for a /// parameter. /// @param ArgNo AttributeList ArgNo, referring to an argument. uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const { - return AttributeSets.getParamDereferenceableOrNullBytes(ArgNo); + return getAttributes().getParamDereferenceableOrNullBytes(ArgNo); } /// Determine if the function is presplit coroutine. @@ -604,7 +610,7 @@ /// Get what kind of unwind table entry to generate for this function. UWTableKind getUWTableKind() const { - return AttributeSets.getUWTableKind(); + return getAttributes().getUWTableKind(); } /// True if the ABI mandates (or the user requested) that this @@ -623,14 +629,14 @@ /// Determine if the function returns a structure through first /// or second pointer argument. bool hasStructRetAttr() const { - return AttributeSets.hasParamAttr(0, Attribute::StructRet) || - AttributeSets.hasParamAttr(1, Attribute::StructRet); + return getAttributes().hasParamAttr(0, Attribute::StructRet) || + getAttributes().hasParamAttr(1, Attribute::StructRet); } /// Determine if the parameter or return value is marked with NoAlias /// attribute. bool returnDoesNotAlias() const { - return AttributeSets.hasRetAttr(Attribute::NoAlias); + return getAttributes().hasRetAttr(Attribute::NoAlias); } void setReturnDoesNotAlias() { addRetAttr(Attribute::NoAlias); } diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -308,6 +308,10 @@ return getParent()->getParamAttribute(getArgNo(), Kind); } +void FnAttributeList::setAttributes(AttributeList NewAttrs) { + Attrs = NewAttrs; +} + //===----------------------------------------------------------------------===// // Helper Methods in Function //===----------------------------------------------------------------------===// @@ -544,131 +548,133 @@ } void Function::addAttributeAtIndex(unsigned i, Attribute Attr) { - AttributeSets = AttributeSets.addAttributeAtIndex(getContext(), i, Attr); + setAttributes(getAttributes().addAttributeAtIndex(getContext(), i, Attr)); } void Function::addFnAttr(Attribute::AttrKind Kind) { - AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind); + setAttributes(getAttributes().addFnAttribute(getContext(), Kind)); } void Function::addFnAttr(StringRef Kind, StringRef Val) { - AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind, Val); + setAttributes(getAttributes().addFnAttribute(getContext(), Kind, Val)); } void Function::addFnAttr(Attribute Attr) { - AttributeSets = AttributeSets.addFnAttribute(getContext(), Attr); + setAttributes(getAttributes().addFnAttribute(getContext(), Attr)); } void Function::addFnAttrs(const AttrBuilder &Attrs) { - AttributeSets = AttributeSets.addFnAttributes(getContext(), Attrs); + setAttributes(getAttributes().addFnAttributes(getContext(), Attrs)); } void Function::addRetAttr(Attribute::AttrKind Kind) { - AttributeSets = AttributeSets.addRetAttribute(getContext(), Kind); + setAttributes(getAttributes().addRetAttribute(getContext(), Kind)); } void Function::addRetAttr(Attribute Attr) { - AttributeSets = AttributeSets.addRetAttribute(getContext(), Attr); + setAttributes(getAttributes().addRetAttribute(getContext(), Attr)); } void Function::addRetAttrs(const AttrBuilder &Attrs) { - AttributeSets = AttributeSets.addRetAttributes(getContext(), Attrs); + setAttributes(getAttributes().addRetAttributes(getContext(), Attrs)); } void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { - AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Kind); + setAttributes(getAttributes().addParamAttribute(getContext(), ArgNo, Kind)); } void Function::addParamAttr(unsigned ArgNo, Attribute Attr) { - AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Attr); + setAttributes(getAttributes().addParamAttribute(getContext(), ArgNo, Attr)); } void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) { - AttributeSets = AttributeSets.addParamAttributes(getContext(), ArgNo, Attrs); + setAttributes(getAttributes().addParamAttributes(getContext(), ArgNo, Attrs)); } void Function::removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) { - AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind); + setAttributes(getAttributes().removeAttributeAtIndex(getContext(), i, Kind)); } void Function::removeAttributeAtIndex(unsigned i, StringRef Kind) { - AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind); + setAttributes(getAttributes().removeAttributeAtIndex(getContext(), i, Kind)); } void Function::removeFnAttr(Attribute::AttrKind Kind) { - AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind); + setAttributes(getAttributes().removeFnAttribute(getContext(), Kind)); } void Function::removeFnAttr(StringRef Kind) { - AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind); + setAttributes(getAttributes().removeFnAttribute(getContext(), Kind)); } void Function::removeFnAttrs(const AttributeMask &AM) { - AttributeSets = AttributeSets.removeFnAttributes(getContext(), AM); + setAttributes(getAttributes().removeFnAttributes(getContext(), AM)); } void Function::removeRetAttr(Attribute::AttrKind Kind) { - AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind); + setAttributes(getAttributes().removeRetAttribute(getContext(), Kind)); } void Function::removeRetAttr(StringRef Kind) { - AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind); + setAttributes(getAttributes().removeRetAttribute(getContext(), Kind)); } void Function::removeRetAttrs(const AttributeMask &Attrs) { - AttributeSets = AttributeSets.removeRetAttributes(getContext(), Attrs); + setAttributes(getAttributes().removeRetAttributes(getContext(), Attrs)); } void Function::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { - AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind); + setAttributes( + getAttributes().removeParamAttribute(getContext(), ArgNo, Kind)); } void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) { - AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind); + setAttributes( + getAttributes().removeParamAttribute(getContext(), ArgNo, Kind)); } void Function::removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs) { - AttributeSets = - AttributeSets.removeParamAttributes(getContext(), ArgNo, Attrs); + setAttributes( + getAttributes().removeParamAttributes(getContext(), ArgNo, Attrs)); } void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) { - AttributeSets = - AttributeSets.addDereferenceableParamAttr(getContext(), ArgNo, Bytes); + setAttributes( + getAttributes().addDereferenceableParamAttr(getContext(), ArgNo, Bytes)); } bool Function::hasFnAttribute(Attribute::AttrKind Kind) const { - return AttributeSets.hasFnAttr(Kind); + return getAttributes().hasFnAttr(Kind); } bool Function::hasFnAttribute(StringRef Kind) const { - return AttributeSets.hasFnAttr(Kind); + return getAttributes().hasFnAttr(Kind); } bool Function::hasRetAttribute(Attribute::AttrKind Kind) const { - return AttributeSets.hasRetAttr(Kind); + return getAttributes().hasRetAttr(Kind); } bool Function::hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const { - return AttributeSets.hasParamAttr(ArgNo, Kind); + return getAttributes().hasParamAttr(ArgNo, Kind); } Attribute Function::getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const { - return AttributeSets.getAttributeAtIndex(i, Kind); + return getAttributes().getAttributeAtIndex(i, Kind); } Attribute Function::getAttributeAtIndex(unsigned i, StringRef Kind) const { - return AttributeSets.getAttributeAtIndex(i, Kind); + return getAttributes().getAttributeAtIndex(i, Kind); } Attribute Function::getFnAttribute(Attribute::AttrKind Kind) const { - return AttributeSets.getFnAttr(Kind); + return getAttributes().getFnAttr(Kind); } Attribute Function::getFnAttribute(StringRef Kind) const { - return AttributeSets.getFnAttr(Kind); + return getAttributes().getFnAttr(Kind); } uint64_t Function::getFnAttributeAsParsedInteger(StringRef Name, @@ -687,13 +693,13 @@ /// gets the specified attribute from the list of attributes. Attribute Function::getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const { - return AttributeSets.getParamAttr(ArgNo, Kind); + return getAttributes().getParamAttr(ArgNo, Kind); } void Function::addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes) { - AttributeSets = AttributeSets.addDereferenceableOrNullParamAttr(getContext(), - ArgNo, Bytes); + setAttributes(getAttributes().addDereferenceableOrNullParamAttr( + getContext(), ArgNo, Bytes)); } DenormalMode Function::getDenormalMode(const fltSemantics &FPType) const {