Skip to content

Commit

Permalink
[LLVM][TableGen] Change DisassemblerEmitter to use const RecordKeeper (
Browse files Browse the repository at this point in the history
…#109177)

Change DisassemblerEmitter to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
  • Loading branch information
jurahul committed Sep 20, 2024
1 parent 8a36eb8 commit b594b93
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
12 changes: 4 additions & 8 deletions llvm/utils/TableGen/DecoderEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class DecoderEmitter {
std::vector<EncodingAndInst> NumberedEncodings;

public:
DecoderEmitter(const RecordKeeper &R, const std::string &PredicateNamespace)
DecoderEmitter(const RecordKeeper &R, StringRef PredicateNamespace)
: RK(R), Target(R), PredicateNamespace(PredicateNamespace) {}

// Emit the decoder state machine table.
Expand All @@ -180,7 +180,7 @@ class DecoderEmitter {
CodeGenTarget Target;

public:
const std::string &PredicateNamespace;
StringRef PredicateNamespace;
};

} // end anonymous namespace
Expand Down Expand Up @@ -2645,11 +2645,7 @@ namespace llvm {
OS << "\n} // end namespace llvm\n";
}

namespace llvm {

void EmitDecoder(RecordKeeper &RK, raw_ostream &OS,
const std::string &PredicateNamespace) {
void llvm::EmitDecoder(const RecordKeeper &RK, raw_ostream &OS,
StringRef PredicateNamespace) {
DecoderEmitter(RK, PredicateNamespace).run(OS);
}

} // end namespace llvm
14 changes: 6 additions & 8 deletions llvm/utils/TableGen/DisassemblerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,17 @@ using namespace llvm::X86Disassembler;
/// X86RecognizableInstr.cpp contains the implementation for a single
/// instruction.

static void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) {
CodeGenTarget Target(Records);
static void EmitDisassembler(const RecordKeeper &Records, raw_ostream &OS) {
const CodeGenTarget Target(Records);
emitSourceFileHeader(" * " + Target.getName().str() + " Disassembler", OS);

// X86 uses a custom disassembler.
if (Target.getName() == "X86") {
DisassemblerTables Tables;

ArrayRef<const CodeGenInstruction *> numberedInstructions =
Target.getInstructionsByEnumValue();

for (unsigned i = 0, e = numberedInstructions.size(); i != e; ++i)
RecognizableInstr::processInstr(Tables, *numberedInstructions[i], i);
for (const auto &[Idx, NumberedInst] :
enumerate(Target.getInstructionsByEnumValue()))
RecognizableInstr::processInstr(Tables, *NumberedInst, Idx);

if (Tables.hasConflicts()) {
PrintError(Target.getTargetRecord()->getLoc(), "Primary decode conflict");
Expand All @@ -126,7 +124,7 @@ static void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) {
return;
}

std::string PredicateNamespace = std::string(Target.getName());
StringRef PredicateNamespace = Target.getName();
if (PredicateNamespace == "Thumb")
PredicateNamespace = "ARM";
EmitDecoder(Records, OS, PredicateNamespace);
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/TableGenBackends.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class RecordKeeper;
void EmitMapTable(const RecordKeeper &RK, raw_ostream &OS);

// Defined in DecoderEmitter.cpp
void EmitDecoder(RecordKeeper &RK, raw_ostream &OS,
const std::string &PredicateNamespace);
void EmitDecoder(const RecordKeeper &RK, raw_ostream &OS,
StringRef PredicateNamespace);

} // namespace llvm

Expand Down

0 comments on commit b594b93

Please sign in to comment.