[llvm] [NFC][TableGen] Print topmost def location for Intrinsics/Insts (PR #160796)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 26 06:58:38 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
When printing location for an intrinsic or an instruction in the generated file, print the location of the topmost/outermost defm. The intent of this location is to easily trace the origin of that particular record, and currently we print the location of the innermost def for records defined using defm/multiclasses, which is not that useful. Printing the location of the topmost defm can allow someone to drill down the defm hierarchy.
---
Full diff: https://github.com/llvm/llvm-project/pull/160796.diff
3 Files Affected:
- (modified) llvm/include/llvm/TableGen/Record.h (+6)
- (modified) llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp (+1-1)
- (modified) llvm/utils/TableGen/InstrInfoEmitter.cpp (+1-1)
``````````diff
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index d4fa1e5d65749b..18aa313a88500f 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -1720,6 +1720,12 @@ class Record {
ArrayRef<SMLoc> getLoc() const { return Locs; }
void appendLoc(SMLoc Loc) { Locs.push_back(Loc); }
+ // Returns the location of the "top" def or defm that instantiated this
+ // concrete record. For a record defined using `def`, this is the location of
+ // the def. For a record defined using `defm`, this is the location of the
+ // topmost/outermost defm that lead to the instantiation of this record.
+ SMLoc getTopDefLoc() const { return Locs.back(); }
+
ArrayRef<SMLoc> getForwardDeclarationLocs() const {
return ForwardDeclarationLocs;
}
diff --git a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
index 559868dd54efe8..1ae035434d9e54 100644
--- a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
@@ -170,7 +170,7 @@ void IntrinsicEmitter::EmitEnumInfo(const CodeGenIntrinsicTable &Ints,
OS.indent(40 - Int.EnumName.size());
OS << formatv(
" // {} ({})\n", Int.Name,
- SrcMgr.getFormattedLocationNoOffset(Int.TheDef->getLoc().front()));
+ SrcMgr.getFormattedLocationNoOffset(Int.TheDef->getTopDefLoc()));
}
// Emit num_intrinsics into the target neutral enum.
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index 176e4b250b82a7..9b92aeb082dbc6 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -1389,7 +1389,7 @@ void InstrInfoEmitter::emitEnums(
for (const CodeGenInstruction *Inst : NumberedInstructions) {
OS << " " << left_justify(Inst->getName(), MaxNameSize) << " = "
<< Target.getInstrIntValue(Inst->TheDef) << ", // "
- << SrcMgr.getFormattedLocationNoOffset(Inst->TheDef->getLoc().front())
+ << SrcMgr.getFormattedLocationNoOffset(Inst->TheDef->getTopDefLoc())
<< '\n';
}
OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << '\n';
``````````
</details>
https://github.com/llvm/llvm-project/pull/160796
More information about the llvm-commits
mailing list