LLVM_NODISCARD AttributeList addAttributes(LLVMContext &C, unsigned Index,
const AttrBuilder &B) const;
+ /// Add a function attribute to the list. Returns a new list because
+ /// attribute lists are immutable.
+ LLVM_NODISCARD AttributeList addFnAttribute(LLVMContext &C,
+ Attribute::AttrKind Kind) const {
+ return addAttribute(C, FunctionIndex, Kind);
+ }
+
+ /// Add a function attribute to the list. Returns a new list because
+ /// attribute lists are immutable.
+ LLVM_NODISCARD AttributeList addFnAttribute(LLVMContext &C,
+ Attribute Attr) const {
+ return addAttribute(C, FunctionIndex, Attr);
+ }
+
+ /// Add a function attribute to the list. Returns a new list because
+ /// attribute lists are immutable.
+ LLVM_NODISCARD AttributeList addFnAttribute(
+ LLVMContext &C, StringRef Kind, StringRef Value = StringRef()) const {
+ return addAttribute(C, FunctionIndex, Kind, Value);
+ }
+
+ /// Add function attribute to the list. Returns a new list because
+ /// attribute lists are immutable.
+ LLVM_NODISCARD AttributeList addFnAttributes(LLVMContext &C,
+ const AttrBuilder &B) const {
+ return addAttributes(C, FunctionIndex, B);
+ }
+
+ /// Add a return value attribute to the list. Returns a new list because
+ /// attribute lists are immutable.
+ LLVM_NODISCARD AttributeList addRetAttribute(LLVMContext &C,
+ Attribute::AttrKind Kind) const {
+ return addAttribute(C, ReturnIndex, Kind);
+ }
+
/// Add an argument attribute to the list. Returns a new list because
/// attribute lists are immutable.
LLVM_NODISCARD AttributeList addParamAttribute(
setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (ID << 4));
}
- /// 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; }
-
- /// Add return value attributes to this function.
- void addRetAttr(Attribute::AttrKind Kind) {
- addAttribute(AttributeList::ReturnIndex, Kind);
- }
-
- /// Add function attributes to this function.
- void addFnAttr(Attribute::AttrKind Kind) {
- addAttribute(AttributeList::FunctionIndex, Kind);
- }
-
- /// Add function attributes to this function.
- void addFnAttr(StringRef Kind, StringRef Val = StringRef()) {
- addAttribute(AttributeList::FunctionIndex,
- Attribute::get(getContext(), Kind, Val));
- }
-
- /// Add function attributes to this function.
- void addFnAttr(Attribute Attr) {
- addAttribute(AttributeList::FunctionIndex, Attr);
- }
-
- /// Add function attributes to this function.
- void addFnAttrs(const AttrBuilder &Attrs) {
- addAttributes(AttributeList::FunctionIndex, Attrs);
- }
-
- /// removes the attributes from the list of attributes.
- void removeAttributes(unsigned i, const AttrBuilder &Attrs);
-
- /// Remove function attributes from this function.
- void removeFnAttr(Attribute::AttrKind Kind) {
- setAttributes(getAttributes().removeFnAttribute(getContext(), Kind));
- }
-
- /// Remove function attribute from this function.
- void removeFnAttr(StringRef Kind) {
- setAttributes(getAttributes().removeFnAttribute(getContext(), Kind));
- }
-
- void removeFnAttrs(const AttrBuilder &Attrs) {
- setAttributes(getAttributes().removeFnAttributes(getContext(), Attrs));
- }
-
- /// A function will have the "coroutine.presplit" attribute if it's
- /// a coroutine and has not gone through full CoroSplit pass.
- bool isPresplitCoroutine() const {
- return hasFnAttribute("coroutine.presplit");
- }
-
enum ProfileCountType { PCT_Invalid, PCT_Real, PCT_Synthetic };
/// Class to represent profile counts.
/// Get the section prefix for this function.
Optional<StringRef> getSectionPrefix() const;
- /// Return true if the function has the attribute.
- bool hasFnAttribute(Attribute::AttrKind Kind) const {
- return AttributeSets.hasFnAttr(Kind);
- }
-
- /// Return true if the function has the attribute.
- bool hasFnAttribute(StringRef Kind) const {
- return AttributeSets.hasFnAttr(Kind);
- }
-
- /// Return the attribute for the given attribute kind.
- Attribute getFnAttribute(Attribute::AttrKind Kind) const {
- return AttributeSets.getFnAttr(Kind);
- }
-
- /// Return the attribute for the given attribute kind.
- Attribute getFnAttribute(StringRef Kind) const {
- return AttributeSets.getFnAttr(Kind);
- }
-
- /// Return the stack alignment for the function.
- unsigned getFnStackAlignment() const {
- if (!hasFnAttribute(Attribute::StackAlignment))
- return 0;
- if (const auto MA =
- AttributeSets.getStackAlignment(AttributeList::FunctionIndex))
- return MA->value();
- return 0;
- }
-
- /// Return the stack alignment for the function.
- MaybeAlign getFnStackAlign() const {
- if (!hasFnAttribute(Attribute::StackAlignment))
- return None;
- return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
- }
-
/// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
/// to use during code generation.
bool hasGC() const {
void setGC(std::string Str);
void clearGC();
- /// Returns true if the function has ssp, sspstrong, or sspreq fn attrs.
- bool hasStackProtectorFnAttr() const;
+ /// Return the attribute list for this Function.
+ AttributeList getAttributes() const { return AttributeSets; }
- /// adds the attribute to the list of attributes.
- void addAttribute(unsigned i, Attribute::AttrKind Kind);
+ /// Set the attribute list for this Function.
+ void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; }
/// adds the attribute to the list of attributes.
void addAttribute(unsigned i, Attribute Attr);
+ /// adds the attribute to the list of attributes.
+ void addAttribute(unsigned i, Attribute::AttrKind Kind);
+
/// adds the attributes to the list of attributes.
void addAttributes(unsigned i, const AttrBuilder &Attrs);
+ /// Add function attributes to this function.
+ void addFnAttr(Attribute::AttrKind Kind);
+
+ /// Add function attributes to this function.
+ void addFnAttr(StringRef Kind, StringRef Val = StringRef());
+
+ /// Add function attributes to this function.
+ void addFnAttr(Attribute Attr);
+
+ /// Add function attributes to this function.
+ void addFnAttrs(const AttrBuilder &Attrs);
+
+ /// Add return value attributes to this function.
+ void addRetAttr(Attribute::AttrKind Kind);
+
/// adds the attribute to the list of attributes for the given arg.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
/// removes the attribute from the list of attributes.
void removeAttribute(unsigned i, StringRef Kind);
+ /// Remove function attributes from this function.
+ void removeFnAttr(Attribute::AttrKind Kind);
+
+ /// Remove function attribute from this function.
+ void removeFnAttr(StringRef Kind);
+
+ void removeFnAttrs(const AttrBuilder &Attrs);
+
/// removes the attribute from the return value list of attributes.
void removeRetAttr(Attribute::AttrKind Kind);
/// removes the attribute from the return value list of attributes.
void removeRetAttr(StringRef Kind);
+ /// removes the attributes from the return value list of attributes.
void removeRetAttrs(const AttrBuilder &Attrs);
/// removes the attribute from the list of attributes.
/// removes the attribute from the list of attributes.
void removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs);
- /// removes noundef and other attributes that imply undefined behavior if a
- /// `undef` or `poison` value is passed from the list of attributes.
- void removeParamUndefImplyingAttrs(unsigned ArgNo);
+ /// Return true if the function has the attribute.
+ bool hasFnAttribute(Attribute::AttrKind Kind) const;
+
+ /// Return true if the function has the attribute.
+ bool hasFnAttribute(StringRef Kind) const;
+
+ /// check if an attribute is in the list of attributes for the return value.
+ bool hasRetAttribute(Attribute::AttrKind Kind) const;
/// check if an attributes is in the list of attributes.
- bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {
- return getAttributes().hasParamAttr(ArgNo, Kind);
- }
+ bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const;
+
+ /// gets the attribute from the list of attributes.
+ Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const;
+
+ /// gets the attribute from the list of attributes.
+ Attribute getAttribute(unsigned i, StringRef Kind) const;
+
+ /// Return the attribute for the given attribute kind.
+ Attribute getFnAttribute(Attribute::AttrKind Kind) const;
+
+ /// Return the attribute for the given attribute kind.
+ Attribute getFnAttribute(StringRef Kind) const;
/// gets the specified attribute from the list of attributes.
- Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {
- return getAttributes().getParamAttr(ArgNo, Kind);
- }
+ Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const;
- /// check if an attribute is in the list of attributes for the return value.
- bool hasRetAttribute(Attribute::AttrKind Kind) const {
- return getAttributes().hasRetAttr(Kind);
- }
+ /// removes noundef and other attributes that imply undefined behavior if a
+ /// `undef` or `poison` value is passed from the list of attributes.
+ void removeParamUndefImplyingAttrs(unsigned ArgNo);
- /// gets the attribute from the list of attributes.
- Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
- return AttributeSets.getAttribute(i, Kind);
+ /// Return the stack alignment for the function.
+ unsigned getFnStackAlignment() const {
+ if (!hasFnAttribute(Attribute::StackAlignment))
+ return 0;
+ if (const auto MA =
+ AttributeSets.getStackAlignment(AttributeList::FunctionIndex))
+ return MA->value();
+ return 0;
}
- /// gets the attribute from the list of attributes.
- Attribute getAttribute(unsigned i, StringRef Kind) const {
- return AttributeSets.getAttribute(i, Kind);
+ /// Return the stack alignment for the function.
+ MaybeAlign getFnStackAlign() const {
+ if (!hasFnAttribute(Attribute::StackAlignment))
+ return None;
+ return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
}
+ /// Returns true if the function has ssp, sspstrong, or sspreq fn attrs.
+ bool hasStackProtectorFnAttr() const;
+
/// adds the dereferenceable attribute to the list of attributes for
/// the given arg.
void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes);
return AttributeSets.getParamDereferenceableOrNullBytes(ArgNo);
}
+ /// A function will have the "coroutine.presplit" attribute if it's
+ /// a coroutine and has not gone through full CoroSplit pass.
+ bool isPresplitCoroutine() const {
+ return hasFnAttribute("coroutine.presplit");
+ }
+
/// Determine if the function does not access memory.
bool doesNotAccessMemory() const {
return hasFnAttribute(Attribute::ReadNone);
bool returnDoesNotAlias() const {
return AttributeSets.hasRetAttr(Attribute::NoAlias);
}
- void setReturnDoesNotAlias() {
- addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
- }
+ void setReturnDoesNotAlias() { addRetAttr(Attribute::NoAlias); }
/// Do not optimize this function (-O0).
bool hasOptNone() const { return hasFnAttribute(Attribute::OptimizeNone); }
clearMetadata();
}
-void Function::addAttribute(unsigned i, Attribute::AttrKind Kind) {
- AttributeList PAL = getAttributes();
- PAL = PAL.addAttribute(getContext(), i, Kind);
- setAttributes(PAL);
+void Function::addAttribute(unsigned i, Attribute Attr) {
+ AttributeSets = AttributeSets.addAttribute(getContext(), i, Attr);
}
-void Function::addAttribute(unsigned i, Attribute Attr) {
- AttributeList PAL = getAttributes();
- PAL = PAL.addAttribute(getContext(), i, Attr);
- setAttributes(PAL);
+void Function::addFnAttr(Attribute::AttrKind Kind) {
+ AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind);
+}
+
+void Function::addFnAttr(StringRef Kind, StringRef Val) {
+ AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind, Val);
+}
+
+void Function::addFnAttr(Attribute Attr) {
+ AttributeSets = AttributeSets.addFnAttribute(getContext(), Attr);
+}
+
+void Function::addFnAttrs(const AttrBuilder &Attrs) {
+ AttributeSets = AttributeSets.addFnAttributes(getContext(), Attrs);
}
-void Function::addAttributes(unsigned i, const AttrBuilder &Attrs) {
- AttributeList PAL = getAttributes();
- PAL = PAL.addAttributes(getContext(), i, Attrs);
- setAttributes(PAL);
+void Function::addRetAttr(Attribute::AttrKind Kind) {
+ AttributeSets = AttributeSets.addRetAttribute(getContext(), Kind);
}
void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
- AttributeList PAL = getAttributes();
- PAL = PAL.addParamAttribute(getContext(), ArgNo, Kind);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Kind);
}
void Function::addParamAttr(unsigned ArgNo, Attribute Attr) {
- AttributeList PAL = getAttributes();
- PAL = PAL.addParamAttribute(getContext(), ArgNo, Attr);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Attr);
}
void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {
- AttributeList PAL = getAttributes();
- PAL = PAL.addParamAttributes(getContext(), ArgNo, Attrs);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.addParamAttributes(getContext(), ArgNo, Attrs);
}
void Function::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
- AttributeList PAL = getAttributes();
- PAL = PAL.removeAttribute(getContext(), i, Kind);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.removeAttribute(getContext(), i, Kind);
}
void Function::removeAttribute(unsigned i, StringRef Kind) {
- AttributeList PAL = getAttributes();
- PAL = PAL.removeAttribute(getContext(), i, Kind);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.removeAttribute(getContext(), i, Kind);
+}
+
+void Function::removeFnAttr(Attribute::AttrKind Kind) {
+ AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind);
+}
+
+void Function::removeFnAttr(StringRef Kind) {
+ AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind);
+}
+
+void Function::removeFnAttrs(const AttrBuilder &Attrs) {
+ AttributeSets = AttributeSets.removeFnAttributes(getContext(), Attrs);
}
void Function::removeRetAttr(Attribute::AttrKind Kind) {
- AttributeList PAL = getAttributes();
- PAL = PAL.removeRetAttribute(getContext(), Kind);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind);
}
void Function::removeRetAttr(StringRef Kind) {
- AttributeList PAL = getAttributes();
- PAL = PAL.removeRetAttribute(getContext(), Kind);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind);
}
void Function::removeRetAttrs(const AttrBuilder &Attrs) {
- AttributeList PAL = getAttributes();
- PAL = PAL.removeRetAttributes(getContext(), Attrs);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.removeRetAttributes(getContext(), Attrs);
}
void Function::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
- AttributeList PAL = getAttributes();
- PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind);
}
void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) {
- AttributeList PAL = getAttributes();
- PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind);
}
void Function::removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {
- AttributeList PAL = getAttributes();
- PAL = PAL.removeParamAttributes(getContext(), ArgNo, Attrs);
- setAttributes(PAL);
+ AttributeSets =
+ AttributeSets.removeParamAttributes(getContext(), ArgNo, Attrs);
}
void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) {
- AttributeList PAL = getAttributes();
- PAL = PAL.addDereferenceableParamAttr(getContext(), ArgNo, Bytes);
- setAttributes(PAL);
+ AttributeSets =
+ AttributeSets.addDereferenceableParamAttr(getContext(), ArgNo, Bytes);
+}
+
+bool Function::hasFnAttribute(Attribute::AttrKind Kind) const {
+ return AttributeSets.hasFnAttr(Kind);
+}
+
+bool Function::hasFnAttribute(StringRef Kind) const {
+ return AttributeSets.hasFnAttr(Kind);
+}
+
+bool Function::hasRetAttribute(Attribute::AttrKind Kind) const {
+ return AttributeSets.hasRetAttr(Kind);
+}
+
+bool Function::hasParamAttribute(unsigned ArgNo,
+ Attribute::AttrKind Kind) const {
+ return AttributeSets.hasParamAttr(ArgNo, Kind);
+}
+
+Attribute Function::getAttribute(unsigned i, Attribute::AttrKind Kind) const {
+ return AttributeSets.getAttribute(i, Kind);
+}
+
+Attribute Function::getAttribute(unsigned i, StringRef Kind) const {
+ return AttributeSets.getAttribute(i, Kind);
+}
+
+Attribute Function::getFnAttribute(Attribute::AttrKind Kind) const {
+ return AttributeSets.getFnAttr(Kind);
+}
+
+Attribute Function::getFnAttribute(StringRef Kind) const {
+ return AttributeSets.getFnAttr(Kind);
+}
+
+/// gets the specified attribute from the list of attributes.
+Attribute Function::getParamAttribute(unsigned ArgNo,
+ Attribute::AttrKind Kind) const {
+ return AttributeSets.getParamAttr(ArgNo, Kind);
}
void Function::addDereferenceableOrNullParamAttr(unsigned ArgNo,
uint64_t Bytes) {
- AttributeList PAL = getAttributes();
- PAL = PAL.addDereferenceableOrNullParamAttr(getContext(), ArgNo, Bytes);
- setAttributes(PAL);
+ AttributeSets = AttributeSets.addDereferenceableOrNullParamAttr(getContext(),
+ ArgNo, Bytes);
}
DenormalMode Function::getDenormalMode(const fltSemantics &FPType) const {