aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Attributes.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-07-07 22:41:12 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-07-07 22:43:17 +0200
commite000b848e65c3fc7d3c153d15cd20bbd92d9427c (patch)
tree8a4812a1d8184759ed2f8ca969582e00bbc50436 /llvm/lib/IR/Attributes.cpp
parentcae3b831f4304d4487dd7c767ff88face51ea0dc (diff)
downloadllvm-e000b848e65c3fc7d3c153d15cd20bbd92d9427c.zip
llvm-e000b848e65c3fc7d3c153d15cd20bbd92d9427c.tar.gz
llvm-e000b848e65c3fc7d3c153d15cd20bbd92d9427c.tar.bz2
[IR] Simplify Attribute::getAsString() (NFC)
Avoid enumerating all attributes here and instead use getNameFromAttrKind(), which is based on the tablegen data. This only leaves us with custom handling for int attributes, which don't have uniform printing.
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r--llvm/lib/IR/Attributes.cpp157
1 files changed, 4 insertions, 153 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 27b5835..9c06e19 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -366,162 +366,13 @@ std::pair<unsigned, unsigned> Attribute::getVScaleRangeArgs() const {
std::string Attribute::getAsString(bool InAttrGrp) const {
if (!pImpl) return {};
- if (hasAttribute(Attribute::SanitizeAddress))
- return "sanitize_address";
- if (hasAttribute(Attribute::SanitizeHWAddress))
- return "sanitize_hwaddress";
- if (hasAttribute(Attribute::SanitizeMemTag))
- return "sanitize_memtag";
- if (hasAttribute(Attribute::AlwaysInline))
- return "alwaysinline";
- if (hasAttribute(Attribute::ArgMemOnly))
- return "argmemonly";
- if (hasAttribute(Attribute::Builtin))
- return "builtin";
- if (hasAttribute(Attribute::Convergent))
- return "convergent";
- if (hasAttribute(Attribute::SwiftError))
- return "swifterror";
- if (hasAttribute(Attribute::SwiftSelf))
- return "swiftself";
- if (hasAttribute(Attribute::SwiftAsync))
- return "swiftasync";
- if (hasAttribute(Attribute::InaccessibleMemOnly))
- return "inaccessiblememonly";
- if (hasAttribute(Attribute::InaccessibleMemOrArgMemOnly))
- return "inaccessiblemem_or_argmemonly";
- if (hasAttribute(Attribute::InlineHint))
- return "inlinehint";
- if (hasAttribute(Attribute::InReg))
- return "inreg";
- if (hasAttribute(Attribute::JumpTable))
- return "jumptable";
- if (hasAttribute(Attribute::MinSize))
- return "minsize";
- if (hasAttribute(Attribute::Naked))
- return "naked";
- if (hasAttribute(Attribute::Nest))
- return "nest";
- if (hasAttribute(Attribute::NoAlias))
- return "noalias";
- if (hasAttribute(Attribute::NoBuiltin))
- return "nobuiltin";
- if (hasAttribute(Attribute::NoCallback))
- return "nocallback";
- if (hasAttribute(Attribute::NoCapture))
- return "nocapture";
- if (hasAttribute(Attribute::NoDuplicate))
- return "noduplicate";
- if (hasAttribute(Attribute::NoFree))
- return "nofree";
- if (hasAttribute(Attribute::NoImplicitFloat))
- return "noimplicitfloat";
- if (hasAttribute(Attribute::NoInline))
- return "noinline";
- if (hasAttribute(Attribute::NonLazyBind))
- return "nonlazybind";
- if (hasAttribute(Attribute::NoMerge))
- return "nomerge";
- if (hasAttribute(Attribute::NonNull))
- return "nonnull";
- if (hasAttribute(Attribute::NoRedZone))
- return "noredzone";
- if (hasAttribute(Attribute::NoReturn))
- return "noreturn";
- if (hasAttribute(Attribute::NoSync))
- return "nosync";
- if (hasAttribute(Attribute::NullPointerIsValid))
- return "null_pointer_is_valid";
- if (hasAttribute(Attribute::WillReturn))
- return "willreturn";
- if (hasAttribute(Attribute::NoCfCheck))
- return "nocf_check";
- if (hasAttribute(Attribute::NoRecurse))
- return "norecurse";
- if (hasAttribute(Attribute::NoProfile))
- return "noprofile";
- if (hasAttribute(Attribute::NoUnwind))
- return "nounwind";
- if (hasAttribute(Attribute::NoSanitizeCoverage))
- return "nosanitize_coverage";
- if (hasAttribute(Attribute::OptForFuzzing))
- return "optforfuzzing";
- if (hasAttribute(Attribute::OptimizeNone))
- return "optnone";
- if (hasAttribute(Attribute::OptimizeForSize))
- return "optsize";
- if (hasAttribute(Attribute::ReadNone))
- return "readnone";
- if (hasAttribute(Attribute::ReadOnly))
- return "readonly";
- if (hasAttribute(Attribute::WriteOnly))
- return "writeonly";
- if (hasAttribute(Attribute::Returned))
- return "returned";
- if (hasAttribute(Attribute::ReturnsTwice))
- return "returns_twice";
- if (hasAttribute(Attribute::SExt))
- return "signext";
- if (hasAttribute(Attribute::SpeculativeLoadHardening))
- return "speculative_load_hardening";
- if (hasAttribute(Attribute::Speculatable))
- return "speculatable";
- if (hasAttribute(Attribute::StackProtect))
- return "ssp";
- if (hasAttribute(Attribute::StackProtectReq))
- return "sspreq";
- if (hasAttribute(Attribute::StackProtectStrong))
- return "sspstrong";
- if (hasAttribute(Attribute::SafeStack))
- return "safestack";
- if (hasAttribute(Attribute::ShadowCallStack))
- return "shadowcallstack";
- if (hasAttribute(Attribute::StrictFP))
- return "strictfp";
- if (hasAttribute(Attribute::SanitizeThread))
- return "sanitize_thread";
- if (hasAttribute(Attribute::SanitizeMemory))
- return "sanitize_memory";
- if (hasAttribute(Attribute::UWTable))
- return "uwtable";
- if (hasAttribute(Attribute::ZExt))
- return "zeroext";
- if (hasAttribute(Attribute::Cold))
- return "cold";
- if (hasAttribute(Attribute::Hot))
- return "hot";
- if (hasAttribute(Attribute::ImmArg))
- return "immarg";
- if (hasAttribute(Attribute::NoUndef))
- return "noundef";
- if (hasAttribute(Attribute::MustProgress))
- return "mustprogress";
+ if (isEnumAttribute())
+ return getNameFromAttrKind(getKindAsEnum()).str();
if (isTypeAttribute()) {
- std::string Result;
- raw_string_ostream OS(Result);
-
- switch (getKindAsEnum()) {
- case Attribute::ByVal:
- Result += "byval";
- break;
- case Attribute::StructRet:
- Result += "sret";
- break;
- case Attribute::ByRef:
- Result += "byref";
- break;
- case Attribute::Preallocated:
- Result += "preallocated";
- break;
- case Attribute::InAlloca:
- Result += "inalloca";
- break;
- default:
- llvm_unreachable("unhandled type attribute");
- }
-
+ std::string Result = getNameFromAttrKind(getKindAsEnum()).str();
Result += '(';
+ raw_string_ostream OS(Result);
getValueAsType()->print(OS, false, true);
OS.flush();
Result += ')';