[llvm] [NFC][TableGen] Refactor IntrinsicEmitter code (PR #106479)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 01:54:34 PDT 2024
================
@@ -419,118 +422,127 @@ void IntrinsicEmitter::EmitAttributes(const CodeGenIntrinsicTable &Ints,
continue;
assert(is_sorted(Attrs) && "Argument attributes are not sorted");
-
- OS << " case " << ID << ":\n";
- OS << " return AttributeSet::get(C, {\n";
- for (const CodeGenIntrinsic::ArgAttribute &Attr : Attrs) {
- switch (Attr.Kind) {
+ auto getAttrEnumName =
+ [](CodeGenIntrinsic::ArgAttrKind Kind) -> StringRef {
+ switch (Kind) {
case CodeGenIntrinsic::NoCapture:
- OS << " Attribute::get(C, Attribute::NoCapture),\n";
- break;
+ return "NoCapture";
case CodeGenIntrinsic::NoAlias:
- OS << " Attribute::get(C, Attribute::NoAlias),\n";
- break;
+ return "NoAlias";
case CodeGenIntrinsic::NoUndef:
- OS << " Attribute::get(C, Attribute::NoUndef),\n";
- break;
+ return "NoUndef";
case CodeGenIntrinsic::NonNull:
- OS << " Attribute::get(C, Attribute::NonNull),\n";
- break;
+ return "NonNull";
case CodeGenIntrinsic::Returned:
- OS << " Attribute::get(C, Attribute::Returned),\n";
- break;
+ return "Returned";
case CodeGenIntrinsic::ReadOnly:
- OS << " Attribute::get(C, Attribute::ReadOnly),\n";
- break;
+ return "ReadOnly";
case CodeGenIntrinsic::WriteOnly:
- OS << " Attribute::get(C, Attribute::WriteOnly),\n";
- break;
+ return "WriteOnly";
case CodeGenIntrinsic::ReadNone:
- OS << " Attribute::get(C, Attribute::ReadNone),\n";
- break;
+ return "ReadNone";
case CodeGenIntrinsic::ImmArg:
- OS << " Attribute::get(C, Attribute::ImmArg),\n";
- break;
+ return "ImmArg";
case CodeGenIntrinsic::Alignment:
- OS << " Attribute::get(C, Attribute::Alignment, " << Attr.Value
- << "),\n";
- break;
+ return "Alignment";
case CodeGenIntrinsic::Dereferenceable:
- OS << " Attribute::get(C, Attribute::Dereferenceable, "
- << Attr.Value << "),\n";
- break;
+ return "Dereferenceable";
}
+ };
+
+ OS << formatv(R"(
+ case {0}:
+ return AttributeSet::get(C, {{
+)",
+ ID);
+ for (const CodeGenIntrinsic::ArgAttribute &Attr : Attrs) {
+ StringRef AttrName = getAttrEnumName(Attr.Kind);
+ if (Attr.Kind == CodeGenIntrinsic::Alignment ||
+ Attr.Kind == CodeGenIntrinsic::Dereferenceable)
+ OS << formatv(" Attribute::get(C, Attribute::{0}, {1}),\n",
+ AttrName, Attr.Value);
+ else
+ OS << formatv(" Attribute::get(C, Attribute::{0}),\n", AttrName);
}
- OS << " });\n";
+ OS << " });";
}
}
- OS << " }\n";
- OS << "}\n\n";
+ OS << R"(
+ }
+} // getIntrinsicArgAttributeSet
+
+static AttributeSet getIntrinsicFnAttributeSet(LLVMContext &C, unsigned ID) {
----------------
s-barannikov wrote:
(nit) Unglued literal looked better to me
https://github.com/llvm/llvm-project/pull/106479
More information about the llvm-commits
mailing list