Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/utils/TableGen/Common/CodeGenInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ class CodeGenInstruction {
return RV && isa<DagInit>(RV->getValue());
}

StringRef getName() const { return TheDef->getName(); }

private:
bool isOperandImpl(StringRef OpListName, unsigned i,
StringRef PropertyName) const;
Expand Down
26 changes: 20 additions & 6 deletions llvm/utils/TableGen/InstrInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
Expand Down Expand Up @@ -1289,8 +1291,9 @@ void InstrInfoEmitter::emitRecord(

// emitEnums - Print out enum values for all of the instructions.
void InstrInfoEmitter::emitEnums(
raw_ostream &OS,
raw_ostream &RawOS,
ArrayRef<const CodeGenInstruction *> NumberedInstructions) {
formatted_raw_ostream OS(RawOS);
OS << "#ifdef GET_INSTRINFO_ENUM\n";
OS << "#undef GET_INSTRINFO_ENUM\n";

Expand All @@ -1302,18 +1305,29 @@ void InstrInfoEmitter::emitEnums(

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

auto II = llvm::max_element(
NumberedInstructions,
[](const CodeGenInstruction *InstA, const CodeGenInstruction *InstB) {
return InstA->getName().size() < InstB->getName().size();
});
size_t MaxNameSize = (*II)->getName().size();

OS << " enum {\n";
for (const CodeGenInstruction *Inst : NumberedInstructions)
OS << " " << Inst->TheDef->getName()
<< "\t= " << Target.getInstrIntValue(Inst->TheDef) << ",\n";
for (const CodeGenInstruction *Inst : NumberedInstructions) {
OS << " " << Inst->TheDef->getName();
OS.PadToColumn(MaxNameSize + 5);
OS << " = " << Target.getInstrIntValue(Inst->TheDef) << ", // ";
OS << SrcMgr.getFormattedLocationNoOffset(Inst->TheDef->getLoc().front());
OS << '\n';
}
OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << '\n';
OS << " };\n\n";
OS << " };\n";
OS << "} // end namespace llvm::" << Namespace << '\n';
OS << "#endif // GET_INSTRINFO_ENUM\n\n";

OS << "#ifdef GET_INSTRINFO_SCHED_ENUM\n";
OS << "#undef GET_INSTRINFO_SCHED_ENUM\n";
OS << "namespace llvm::" << Namespace << "::Sched {\n\n";
OS << "namespace llvm::" << Namespace << "::Sched {\n";
OS << " enum {\n";
auto ExplictClasses = SchedModels.explicitSchedClasses();
for (const auto &[Idx, Class] : enumerate(ExplictClasses))
Expand Down