[llvm] b594b93 - [LLVM][TableGen] Change DisassemblerEmitter to use const RecordKeeper (#109177)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 04:22:41 PDT 2024
Author: Rahul Joshi
Date: 2024-09-20T04:22:37-07:00
New Revision: b594b93024bbe24bddbcc0e54cb5551e0df642cf
URL: https://github.com/llvm/llvm-project/commit/b594b93024bbe24bddbcc0e54cb5551e0df642cf
DIFF: https://github.com/llvm/llvm-project/commit/b594b93024bbe24bddbcc0e54cb5551e0df642cf.diff
LOG: [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
Added:
Modified:
llvm/utils/TableGen/DecoderEmitter.cpp
llvm/utils/TableGen/DisassemblerEmitter.cpp
llvm/utils/TableGen/TableGenBackends.h
Removed:
################################################################################
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<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.
@@ -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<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");
@@ -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
More information about the llvm-commits
mailing list