Skip to content

Commit 78fbca4

Browse files
authored
[NFC][InstrInfoEmitter] Include location of inst definition in comment (#156927)
Print the source location of the instruction definition in comment next to the enum value for each instruction. To make this more readable, change formatting of the instruction enums to be better aligned. Example output: ``` VLD4qWB_register_Asm_8 = 573, // (ARMInstrNEON.td:8849) VMOVD0 = 574, // (ARMInstrNEON.td:6337) VMOVDcc = 575, // (ARMInstrVFP.td:2466) VMOVHcc = 576, // (ARMInstrVFP.td:2474) VMOVQ0 = 577, // (ARMInstrNEON.td:6341) ```
1 parent 91e85cc commit 78fbca4

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

llvm/utils/TableGen/Common/CodeGenInstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ class CodeGenInstruction {
320320
return RV && isa<DagInit>(RV->getValue());
321321
}
322322

323+
StringRef getName() const { return TheDef->getName(); }
324+
323325
private:
324326
bool isOperandImpl(StringRef OpListName, unsigned i,
325327
StringRef PropertyName) const;

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "llvm/ADT/SmallVector.h"
2626
#include "llvm/ADT/StringExtras.h"
2727
#include "llvm/Support/Casting.h"
28+
#include "llvm/Support/Format.h"
29+
#include "llvm/Support/SourceMgr.h"
2830
#include "llvm/Support/raw_ostream.h"
2931
#include "llvm/TableGen/Error.h"
3032
#include "llvm/TableGen/Record.h"
@@ -1302,18 +1304,28 @@ void InstrInfoEmitter::emitEnums(
13021304

13031305
OS << "namespace llvm::" << Namespace << " {\n";
13041306

1307+
auto II = llvm::max_element(
1308+
NumberedInstructions,
1309+
[](const CodeGenInstruction *InstA, const CodeGenInstruction *InstB) {
1310+
return InstA->getName().size() < InstB->getName().size();
1311+
});
1312+
size_t MaxNameSize = (*II)->getName().size();
1313+
13051314
OS << " enum {\n";
1306-
for (const CodeGenInstruction *Inst : NumberedInstructions)
1307-
OS << " " << Inst->TheDef->getName()
1308-
<< "\t= " << Target.getInstrIntValue(Inst->TheDef) << ",\n";
1315+
for (const CodeGenInstruction *Inst : NumberedInstructions) {
1316+
OS << " " << left_justify(Inst->TheDef->getName(), MaxNameSize) << " = "
1317+
<< Target.getInstrIntValue(Inst->TheDef) << ", // "
1318+
<< SrcMgr.getFormattedLocationNoOffset(Inst->TheDef->getLoc().front())
1319+
<< '\n';
1320+
}
13091321
OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << '\n';
1310-
OS << " };\n\n";
1322+
OS << " };\n";
13111323
OS << "} // end namespace llvm::" << Namespace << '\n';
13121324
OS << "#endif // GET_INSTRINFO_ENUM\n\n";
13131325

13141326
OS << "#ifdef GET_INSTRINFO_SCHED_ENUM\n";
13151327
OS << "#undef GET_INSTRINFO_SCHED_ENUM\n";
1316-
OS << "namespace llvm::" << Namespace << "::Sched {\n\n";
1328+
OS << "namespace llvm::" << Namespace << "::Sched {\n";
13171329
OS << " enum {\n";
13181330
auto ExplictClasses = SchedModels.explicitSchedClasses();
13191331
for (const auto &[Idx, Class] : enumerate(ExplictClasses))

0 commit comments

Comments
 (0)