From b594b93024bbe24bddbcc0e54cb5551e0df642cf Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Fri, 20 Sep 2024 04:22:37 -0700 Subject: [PATCH] [LLVM][TableGen] Change DisassemblerEmitter to use const RecordKeeper (#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 --- llvm/utils/TableGen/DecoderEmitter.cpp | 12 ++++-------- llvm/utils/TableGen/DisassemblerEmitter.cpp | 14 ++++++-------- llvm/utils/TableGen/TableGenBackends.h | 4 ++-- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp index f3a4a77cc9b7f6..eaaa1edb52badf 100644 --- a/llvm/utils/TableGen/DecoderEmitter.cpp +++ b/llvm/utils/TableGen/DecoderEmitter.cpp @@ -159,7 +159,7 @@ class DecoderEmitter { std::vector 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. @@ -180,7 +180,7 @@ class DecoderEmitter { CodeGenTarget Target; public: - const std::string &PredicateNamespace; + StringRef PredicateNamespace; }; } // end anonymous namespace @@ -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 diff --git a/llvm/utils/TableGen/DisassemblerEmitter.cpp b/llvm/utils/TableGen/DisassemblerEmitter.cpp index f2c25d38ad2a7d..eb15392272a3f3 100644 --- a/llvm/utils/TableGen/DisassemblerEmitter.cpp +++ b/llvm/utils/TableGen/DisassemblerEmitter.cpp @@ -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 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"); @@ -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); diff --git a/llvm/utils/TableGen/TableGenBackends.h b/llvm/utils/TableGen/TableGenBackends.h index fc3b87370766a3..d1cbc5d1605d8c 100644 --- a/llvm/utils/TableGen/TableGenBackends.h +++ b/llvm/utils/TableGen/TableGenBackends.h @@ -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