[AsmWriter] Simplify type attribute printing (NFC)
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 7 Jul 2021 20:46:57 +0000 (22:46 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 7 Jul 2021 20:47:33 +0000 (22:47 +0200)
Avoid enumerating all supported type attributes, instead fetch
their name from the attribute kind.

llvm/lib/IR/AsmWriter.cpp

index 66c93b6..ea86033 100644 (file)
@@ -4416,20 +4416,7 @@ void AssemblyWriter::writeAttribute(const Attribute &Attr, bool InAttrGroup) {
     return;
   }
 
-  if (Attr.hasAttribute(Attribute::ByVal)) {
-    Out << "byval";
-  } else if (Attr.hasAttribute(Attribute::StructRet)) {
-    Out << "sret";
-  } else if (Attr.hasAttribute(Attribute::ByRef)) {
-    Out << "byref";
-  } else if (Attr.hasAttribute(Attribute::Preallocated)) {
-    Out << "preallocated";
-  } else if (Attr.hasAttribute(Attribute::InAlloca)) {
-    Out << "inalloca";
-  } else {
-    llvm_unreachable("unexpected type attr");
-  }
-
+  Out << Attribute::getNameFromAttrKind(Attr.getKindAsEnum());
   if (Type *Ty = Attr.getValueAsType()) {
     Out << '(';
     TypePrinter.print(Ty, Out);