Skip to content
Merged
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
32 changes: 12 additions & 20 deletions llvm/utils/TableGen/DecoderEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class DecoderEmitter {
SmallDenseMap<unsigned, std::vector<unsigned>> EncodingIDsByHwMode;

public:
DecoderEmitter(const RecordKeeper &RK, StringRef PredicateNamespace);
explicit DecoderEmitter(const RecordKeeper &RK);

const CodeGenTarget &getTarget() const { return Target; }

Expand Down Expand Up @@ -370,9 +370,6 @@ class DecoderEmitter {
NamespacesHwModesMap &NamespacesWithHwModes);

void parseInstructionEncodings();

public:
StringRef PredicateNamespace;
};

} // end anonymous namespace
Expand Down Expand Up @@ -487,8 +484,7 @@ class FilterChooser {
/// This field allows us to ignore the extra bits.
unsigned MaxFilterWidth;

// Parent emitter
const DecoderEmitter *Emitter;
const CodeGenTarget &Target;

/// If the selected filter matches multiple encodings, then this is the
/// starting position and the width of the filtered range.
Expand Down Expand Up @@ -524,9 +520,9 @@ class FilterChooser {
/// Constructs a top-level filter chooser.
FilterChooser(ArrayRef<InstructionEncoding> Encodings,
ArrayRef<unsigned> EncodingIDs, unsigned MaxFilterWidth,
const DecoderEmitter *E)
const CodeGenTarget &Target)
: Encodings(Encodings), EncodingIDs(EncodingIDs), Parent(nullptr),
MaxFilterWidth(MaxFilterWidth), Emitter(E) {
MaxFilterWidth(MaxFilterWidth), Target(Target) {
// Sort encoding IDs once.
stable_sort(this->EncodingIDs, LessEncodingIDByWidth(Encodings));
// Filter width is the width of the smallest encoding.
Expand All @@ -542,7 +538,7 @@ class FilterChooser {
ArrayRef<unsigned> EncodingIDs, const KnownBits &FilterBits,
const FilterChooser &Parent)
: Encodings(Encodings), EncodingIDs(EncodingIDs), Parent(&Parent),
MaxFilterWidth(Parent.MaxFilterWidth), Emitter(Parent.Emitter) {
MaxFilterWidth(Parent.MaxFilterWidth), Target(Parent.Target) {
// Inferior filter choosers are created from sorted array of encoding IDs.
assert(is_sorted(EncodingIDs, LessEncodingIDByWidth(Encodings)));
assert(!FilterBits.hasConflict() && "Broken filter");
Expand Down Expand Up @@ -1155,8 +1151,7 @@ bool FilterChooser::emitPredicateMatchAux(const Init &Val, bool ParenIfBinOp,
if (const auto *D = dyn_cast<DefInit>(&Val)) {
if (!D->getDef()->isSubClassOf("SubtargetFeature"))
return true;
OS << "Bits[" << Emitter->PredicateNamespace << "::" << D->getAsString()
<< "]";
OS << "Bits[" << Target.getName() << "::" << D->getAsString() << "]";
return false;
}
if (const auto *D = dyn_cast<DagInit>(&Val)) {
Expand Down Expand Up @@ -1350,7 +1345,7 @@ void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
: MCD::OPC_TryDecode;
TableInfo.Table.insertOpcode(DecoderOp);
const Record *InstDef = Encodings[EncodingID].getInstruction()->TheDef;
TableInfo.Table.insertULEB128(Emitter->getTarget().getInstrIntValue(InstDef));
TableInfo.Table.insertULEB128(Target.getInstrIntValue(InstDef));
TableInfo.Table.insertULEB128(DIdx);

if (DecoderOp == MCD::OPC_TryDecode) {
Expand Down Expand Up @@ -2502,10 +2497,8 @@ void DecoderEmitter::parseInstructionEncodings() {
NumEncodings = NumEncodingsSupported + NumEncodingsOmitted;
}

DecoderEmitter::DecoderEmitter(const RecordKeeper &RK,
StringRef PredicateNamespace)
: RK(RK), Target(RK), CGH(Target.getHwModes()),
PredicateNamespace(PredicateNamespace) {
DecoderEmitter::DecoderEmitter(const RecordKeeper &RK)
: RK(RK), Target(RK), CGH(Target.getHwModes()) {
Target.reverseBitsForLittleEndianEncoding();
parseInstructionEncodings();
}
Expand Down Expand Up @@ -2560,7 +2553,7 @@ namespace {
auto [DecoderNamespace, HwModeID, Size] = Key;
const unsigned BitWidth = IsVarLenInst ? MaxInstLen : 8 * Size;
// Emit the decoder for this (namespace, hwmode, width) combination.
FilterChooser FC(Encodings, EncodingIDs, BitWidth, this);
FilterChooser FC(Encodings, EncodingIDs, BitWidth, Target);

// The decode table is cleared for each top level decoder function. The
// predicates and decoders themselves, however, are shared across all
Expand Down Expand Up @@ -2603,7 +2596,6 @@ namespace {
OS << "\n} // namespace\n";
}

void llvm::EmitDecoder(const RecordKeeper &RK, raw_ostream &OS,
StringRef PredicateNamespace) {
DecoderEmitter(RK, PredicateNamespace).run(OS);
void llvm::EmitDecoder(const RecordKeeper &RK, raw_ostream &OS) {
DecoderEmitter(RK).run(OS);
}
5 changes: 1 addition & 4 deletions llvm/utils/TableGen/DisassemblerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ static void emitDisassembler(const RecordKeeper &Records, raw_ostream &OS) {
return;
}

StringRef PredicateNamespace = Target.getName();
if (PredicateNamespace == "Thumb")
PredicateNamespace = "ARM";
EmitDecoder(Records, OS, PredicateNamespace);
EmitDecoder(Records, OS);
}

cl::OptionCategory DisassemblerEmitterCat("Options for -gen-disassembler");
Expand Down
3 changes: 1 addition & 2 deletions llvm/utils/TableGen/TableGenBackends.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class RecordKeeper;
void EmitMapTable(const RecordKeeper &RK, raw_ostream &OS);

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

} // namespace llvm

Expand Down
Loading