diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index cb2721aba4f25..1c3a3280bbb4f 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -1720,6 +1720,12 @@ class Record { ArrayRef 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 getForwardDeclarationLocs() const { return ForwardDeclarationLocs; } diff --git a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp index 559868dd54efe..1ae035434d9e5 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 176e4b250b82a..9b92aeb082dbc 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';