Skip to content

Conversation

@jurahul
Copy link
Contributor

@jurahul jurahul commented Sep 4, 2025

Include the source location of the intrinsic record definition in a comment next to the enum definition for that intrinsic. This will help quickly locate the definition of a given intrinsic when it's not obvious from a simple search (for example, intrinsics defined by stitching components of names).

@jurahul
Copy link
Contributor Author

jurahul commented Sep 4, 2025

Example output:

enum ARMIntrinsics : unsigned {
// Enum values for intrinsics.
    arm_cde_cx1 = 3606,                               // llvm.arm.cde.cx1 (IntrinsicsARM.td:1387)
    arm_cde_cx1a,                              // llvm.arm.cde.cx1a (IntrinsicsARM.td:1391)
    arm_cde_cx1d,                              // llvm.arm.cde.cx1d (IntrinsicsARM.td:1397)
    arm_cde_cx1da,                             // llvm.arm.cde.cx1da (IntrinsicsARM.td:1401)
    arm_cde_cx2,                               // llvm.arm.cde.cx2 (IntrinsicsARM.td:1387)

@jurahul jurahul changed the title [NFC][IntrinsicEmitter] Include source location in comment [NFC][IntrinsicEmitter] Include source location with enum definition Sep 4, 2025
@jurahul jurahul marked this pull request as ready for review September 4, 2025 05:15
@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2025

@llvm/pr-subscribers-tablegen

Author: Rahul Joshi (jurahul)

Changes

Include the source location of the intrinsic record definition in a comment next to the enum definition for that intrinsic. This will help quickly locate the definition of a given intrinsic when it's not obvious from a simple search (for example, intrinsics defined by stitching components of names).


Full diff: https://github.com/llvm/llvm-project/pull/156800.diff

1 Files Affected:

  • (modified) llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp (+5-2)
diff --git a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
index 04707084a4166..09d29b8522f54 100644
--- a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/ModRef.h"
+#include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
@@ -154,7 +155,7 @@ void IntrinsicEmitter::EmitEnumInfo(const CodeGenIntrinsicTable &Ints,
 
   OS << "// Enum values for intrinsics.\n";
   bool First = true;
-  for (const auto &Int : Ints[*Set]) {
+  for (const CodeGenIntrinsic &Int : Ints[*Set]) {
     OS << "    " << Int.EnumName;
 
     // Assign a value to the first intrinsic in this target set so that all
@@ -167,7 +168,9 @@ void IntrinsicEmitter::EmitEnumInfo(const CodeGenIntrinsicTable &Ints,
     OS << ", ";
     if (Int.EnumName.size() < 40)
       OS.indent(40 - Int.EnumName.size());
-    OS << formatv(" // {}\n", Int.Name);
+    OS << formatv(
+        " // {} ({})\n", Int.Name,
+        SrcMgr.getFormattedLocationNoOffset(Int.TheDef->getLoc().front()));
   }
 
   // Emit num_intrinsics into the target neutral enum.

@jurahul jurahul requested review from arsenm and nikic September 4, 2025 05:16
@jurahul jurahul merged commit bcb1a89 into llvm:main Sep 4, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants