[llvm] [LLVM-Tablegen] Pretty Printing Arguments in LLVM Intrinsics (PR #162629)
Dharuni R Acharya via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 4 00:09:29 PST 2025
================
@@ -805,6 +815,72 @@ AttributeSet Intrinsic::getFnAttributes(LLVMContext &C, ID id) {{
NoFunctionAttrsID);
}
+void IntrinsicEmitter::EmitIntrinsicToPrettyPrintTable(
+ const CodeGenIntrinsicTable &Ints, raw_ostream &OS) {
+ OS << R"(// Intrinsic ID to pretty print bitset.
+)"
+ R"(#ifdef GET_INTRINSIC_PRETTY_PRINT_TABLE
+static constexpr uint8_t PPTable[] = {
+ 0
+ )";
+ int CountPerLine = 0;
+ for (auto [I, Int] : enumerate(Ints)) {
+ size_t Idx = I + 1;
+
+ if (Idx % 8 == 0) {
+ OS << ", 0";
+ CountPerLine++;
+ if (CountPerLine == 8) {
+ OS << "\n ";
+ CountPerLine = 0;
+ }
+ }
+ if (!Int.PrettyPrintFunctions.empty())
+ OS << " | (1<<" << Idx % 8 << ')';
+ }
+ OS << "\n};\n\n";
+ OS << "return (PPTable[id/8] & (1 << (id%8))) != 0;\n";
+ OS << "#endif // GET_INTRINSIC_PRETTY_PRINT_TABLE\n\n";
+}
+
+void IntrinsicEmitter::EmitPrettyPrintArguments(
+ const CodeGenIntrinsicTable &Ints, raw_ostream &OS) {
+ OS << R"(
+#ifdef GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS
+
+void Intrinsic::printImmArg(ID IID, unsigned ArgIdx, raw_ostream &OS, const Constant *ImmArgVal) {
+ using namespace Intrinsic;
+ switch (IID) {
+)";
+
+ for (const auto &Int : Ints) {
+ if (Int.PrettyPrintFunctions.empty())
+ continue;
+
+ OS << " case " << Int.EnumName << ":\n";
+ OS << " switch (ArgIdx) {\n";
+ for (const auto &Info : Int.PrettyPrintFunctions) {
----------------
DharuniRAcharya wrote:
Updated in the latest revision! Thanks!
https://github.com/llvm/llvm-project/pull/162629
More information about the llvm-commits
mailing list