Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LLVM][TableGen] Change DisassemblerEmitter to use const RecordKeeper #109177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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 @@ -181,7 +181,7 @@ class DecoderEmitter {
CodeGenTarget Target;

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

} // end anonymous namespace
Expand Down Expand Up @@ -2651,11 +2651,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
Loading