aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/DecoderEmitter.cpp
diff options
context:
space:
mode:
authorRahul Joshi <rjoshi@nvidia.com>2024-09-19 04:49:12 -0700
committerGitHub <noreply@github.com>2024-09-19 04:49:12 -0700
commit3e24dd42dded01a431070c3dda486eed2640b0c7 (patch)
tree5f341f75f7a1c911819e1d98a4709c1df4d180a4 /llvm/utils/TableGen/DecoderEmitter.cpp
parent486f790d294d1bc3bdaeb4377889c4b03f0b1bca (diff)
downloadllvm-3e24dd42dded01a431070c3dda486eed2640b0c7.zip
llvm-3e24dd42dded01a431070c3dda486eed2640b0c7.tar.gz
llvm-3e24dd42dded01a431070c3dda486eed2640b0c7.tar.bz2
[NFC] Rename variables to conform to LLVM coding standards (#109166)
Rename `indent` to `Indent` and `o` to `OS`. Rename `Indentation` to `Indent`. Remove unused argument from `emitPredicateMatch`. Change `Indent` argument to `emitBinaryParser` to by value.
Diffstat (limited to 'llvm/utils/TableGen/DecoderEmitter.cpp')
-rw-r--r--llvm/utils/TableGen/DecoderEmitter.cpp196
1 files changed, 95 insertions, 101 deletions
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index edecb90..f3a4a77 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -163,16 +163,15 @@ public:
: RK(R), Target(R), PredicateNamespace(PredicateNamespace) {}
// Emit the decoder state machine table.
- void emitTable(formatted_raw_ostream &o, DecoderTable &Table,
- unsigned Indentation, unsigned BitWidth, StringRef Namespace,
+ void emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
+ unsigned Indent, unsigned BitWidth, StringRef Namespace,
const EncodingIDsVec &EncodingIDs) const;
void emitInstrLenTable(formatted_raw_ostream &OS,
std::vector<unsigned> &InstrLen) const;
void emitPredicateFunction(formatted_raw_ostream &OS,
- PredicateSet &Predicates,
- unsigned Indentation) const;
+ PredicateSet &Predicates, unsigned Indent) const;
void emitDecoderFunction(formatted_raw_ostream &OS, DecoderSet &Decoders,
- unsigned Indentation) const;
+ unsigned Indent) const;
// run - Output the code emitter
void run(raw_ostream &o);
@@ -217,17 +216,17 @@ static bit_value_t bitFromBits(const BitsInit &bits, unsigned index) {
}
// Prints the bit value for each position.
-static void dumpBits(raw_ostream &o, const BitsInit &bits) {
+static void dumpBits(raw_ostream &OS, const BitsInit &bits) {
for (unsigned index = bits.getNumBits(); index > 0; --index) {
switch (bitFromBits(bits, index - 1)) {
case BIT_TRUE:
- o << "1";
+ OS << "1";
break;
case BIT_FALSE:
- o << "0";
+ OS << "0";
break;
case BIT_UNSET:
- o << "_";
+ OS << "_";
break;
default:
llvm_unreachable("unexpected return value from bitFromBits");
@@ -497,12 +496,12 @@ protected:
/// dumpFilterArray - dumpFilterArray prints out debugging info for the given
/// filter array as a series of chars.
- void dumpFilterArray(raw_ostream &o,
+ void dumpFilterArray(raw_ostream &OS,
const std::vector<bit_value_t> &filter) const;
/// dumpStack - dumpStack traverses the filter chooser chain and calls
/// dumpFilterArray on each filter chooser up to the top level one.
- void dumpStack(raw_ostream &o, const char *prefix) const;
+ void dumpStack(raw_ostream &OS, const char *prefix) const;
Filter &bestFilter() {
assert(BestIndex != -1 && "BestIndex not set");
@@ -524,8 +523,7 @@ protected:
// Emits code to check the Predicates member of an instruction are true.
// Returns true if predicate matches were emitted, false otherwise.
- bool emitPredicateMatch(raw_ostream &o, unsigned &Indentation,
- unsigned Opc) const;
+ bool emitPredicateMatch(raw_ostream &OS, unsigned Opc) const;
bool emitPredicateMatchAux(const Init &Val, bool ParenIfBinOp,
raw_ostream &OS) const;
@@ -543,11 +541,11 @@ protected:
void emitSingletonTableEntry(DecoderTableInfo &TableInfo,
const Filter &Best) const;
- void emitBinaryParser(raw_ostream &o, unsigned &Indentation,
+ void emitBinaryParser(raw_ostream &OS, unsigned Indent,
const OperandInfo &OpInfo,
bool &OpHasCompleteDecoder) const;
- void emitDecoder(raw_ostream &OS, unsigned Indentation, unsigned Opc,
+ void emitDecoder(raw_ostream &OS, unsigned Indent, unsigned Opc,
bool &HasCompleteDecoder) const;
unsigned getDecoderIndex(DecoderSet &Decoders, unsigned Opc,
bool &HasCompleteDecoder) const;
@@ -793,7 +791,7 @@ unsigned Filter::usefulness() const {
// Emit the decoder state machine table.
void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
- unsigned Indentation, unsigned BitWidth,
+ unsigned Indent, unsigned BitWidth,
StringRef Namespace,
const EncodingIDsVec &EncodingIDs) const {
// We'll need to be able to map from a decoded opcode into the corresponding
@@ -804,10 +802,10 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
for (const auto &EI : EncodingIDs)
OpcodeToEncodingID[EI.Opcode] = EI.EncodingID;
- OS.indent(Indentation) << "static const uint8_t DecoderTable" << Namespace
- << BitWidth << "[] = {\n";
+ OS.indent(Indent) << "static const uint8_t DecoderTable" << Namespace
+ << BitWidth << "[] = {\n";
- Indentation += 2;
+ Indent += 2;
// Emit ULEB128 encoded value to OS, returning the number of bytes emitted.
auto emitULEB128 = [](DecoderTable::const_iterator I,
@@ -852,7 +850,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
PrintFatalError("invalid decode table opcode");
case MCD::OPC_ExtractField: {
++I;
- OS.indent(Indentation) << "MCD::OPC_ExtractField, ";
+ OS.indent(Indent) << "MCD::OPC_ExtractField, ";
// ULEB128 encoded start value.
const char *ErrMsg = nullptr;
@@ -870,7 +868,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_FilterValue: {
++I;
- OS.indent(Indentation) << "MCD::OPC_FilterValue, ";
+ OS.indent(Indent) << "MCD::OPC_FilterValue, ";
// The filter value is ULEB128 encoded.
I += emitULEB128(I, OS);
@@ -882,7 +880,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_CheckField: {
++I;
- OS.indent(Indentation) << "MCD::OPC_CheckField, ";
+ OS.indent(Indent) << "MCD::OPC_CheckField, ";
// ULEB128 encoded start value.
I += emitULEB128(I, OS);
// 8-bit length.
@@ -899,7 +897,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_CheckPredicate: {
++I;
- OS.indent(Indentation) << "MCD::OPC_CheckPredicate, ";
+ OS.indent(Indent) << "MCD::OPC_CheckPredicate, ";
I += emitULEB128(I, OS);
// 24-bit numtoskip value.
@@ -918,8 +916,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
Table.data() + Table.size(), &ErrMsg);
assert(ErrMsg == nullptr && "ULEB128 value too large!");
- OS.indent(Indentation)
- << "MCD::OPC_" << (IsTry ? "Try" : "") << "Decode, ";
+ OS.indent(Indent) << "MCD::OPC_" << (IsTry ? "Try" : "") << "Decode, ";
I += emitULEB128(I, OS);
// Decoder index.
@@ -946,7 +943,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_SoftFail: {
++I;
- OS.indent(Indentation) << "MCD::OPC_SoftFail";
+ OS.indent(Indent) << "MCD::OPC_SoftFail";
// Positive mask
uint64_t Value = 0;
unsigned Shift = 0;
@@ -978,16 +975,16 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
}
case MCD::OPC_Fail: {
++I;
- OS.indent(Indentation) << "MCD::OPC_Fail,\n";
+ OS.indent(Indent) << "MCD::OPC_Fail,\n";
break;
}
}
}
- OS.indent(Indentation) << "0\n";
+ OS.indent(Indent) << "0\n";
- Indentation -= 2;
+ Indent -= 2;
- OS.indent(Indentation) << "};\n\n";
+ OS.indent(Indent) << "};\n\n";
}
void DecoderEmitter::emitInstrLenTable(formatted_raw_ostream &OS,
@@ -1001,61 +998,60 @@ void DecoderEmitter::emitInstrLenTable(formatted_raw_ostream &OS,
void DecoderEmitter::emitPredicateFunction(formatted_raw_ostream &OS,
PredicateSet &Predicates,
- unsigned Indentation) const {
+ unsigned Indent) const {
// The predicate function is just a big switch statement based on the
// input predicate index.
- OS.indent(Indentation) << "static bool checkDecoderPredicate(unsigned Idx, "
- << "const FeatureBitset &Bits) {\n";
- Indentation += 2;
+ OS.indent(Indent) << "static bool checkDecoderPredicate(unsigned Idx, "
+ << "const FeatureBitset &Bits) {\n";
+ Indent += 2;
if (!Predicates.empty()) {
- OS.indent(Indentation) << "switch (Idx) {\n";
- OS.indent(Indentation)
- << "default: llvm_unreachable(\"Invalid index!\");\n";
+ OS.indent(Indent) << "switch (Idx) {\n";
+ OS.indent(Indent) << "default: llvm_unreachable(\"Invalid index!\");\n";
unsigned Index = 0;
for (const auto &Predicate : Predicates) {
- OS.indent(Indentation) << "case " << Index++ << ":\n";
- OS.indent(Indentation + 2) << "return (" << Predicate << ");\n";
+ OS.indent(Indent) << "case " << Index++ << ":\n";
+ OS.indent(Indent + 2) << "return (" << Predicate << ");\n";
}
- OS.indent(Indentation) << "}\n";
+ OS.indent(Indent) << "}\n";
} else {
// No case statement to emit
- OS.indent(Indentation) << "llvm_unreachable(\"Invalid index!\");\n";
+ OS.indent(Indent) << "llvm_unreachable(\"Invalid index!\");\n";
}
- Indentation -= 2;
- OS.indent(Indentation) << "}\n\n";
+ Indent -= 2;
+ OS.indent(Indent) << "}\n\n";
}
void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
DecoderSet &Decoders,
- unsigned Indentation) const {
+ unsigned Indent) const {
// The decoder function is just a big switch statement based on the
// input decoder index.
- OS.indent(Indentation) << "template <typename InsnType>\n";
- OS.indent(Indentation) << "static DecodeStatus decodeToMCInst(DecodeStatus S,"
- << " unsigned Idx, InsnType insn, MCInst &MI,\n";
- OS.indent(Indentation)
+ OS.indent(Indent) << "template <typename InsnType>\n";
+ OS.indent(Indent) << "static DecodeStatus decodeToMCInst(DecodeStatus S,"
+ << " unsigned Idx, InsnType insn, MCInst &MI,\n";
+ OS.indent(Indent)
<< " uint64_t "
<< "Address, const MCDisassembler *Decoder, bool &DecodeComplete) {\n";
- Indentation += 2;
- OS.indent(Indentation) << "DecodeComplete = true;\n";
+ Indent += 2;
+ OS.indent(Indent) << "DecodeComplete = true;\n";
// TODO: When InsnType is large, using uint64_t limits all fields to 64 bits
// It would be better for emitBinaryParser to use a 64-bit tmp whenever
// possible but fall back to an InsnType-sized tmp for truly large fields.
- OS.indent(Indentation) << "using TmpType = "
- "std::conditional_t<std::is_integral<InsnType>::"
- "value, InsnType, uint64_t>;\n";
- OS.indent(Indentation) << "TmpType tmp;\n";
- OS.indent(Indentation) << "switch (Idx) {\n";
- OS.indent(Indentation) << "default: llvm_unreachable(\"Invalid index!\");\n";
+ OS.indent(Indent) << "using TmpType = "
+ "std::conditional_t<std::is_integral<InsnType>::"
+ "value, InsnType, uint64_t>;\n";
+ OS.indent(Indent) << "TmpType tmp;\n";
+ OS.indent(Indent) << "switch (Idx) {\n";
+ OS.indent(Indent) << "default: llvm_unreachable(\"Invalid index!\");\n";
unsigned Index = 0;
for (const auto &Decoder : Decoders) {
- OS.indent(Indentation) << "case " << Index++ << ":\n";
+ OS.indent(Indent) << "case " << Index++ << ":\n";
OS << Decoder;
- OS.indent(Indentation + 2) << "return S;\n";
+ OS.indent(Indent + 2) << "return S;\n";
}
- OS.indent(Indentation) << "}\n";
- Indentation -= 2;
- OS.indent(Indentation) << "}\n";
+ OS.indent(Indent) << "}\n";
+ Indent -= 2;
+ OS.indent(Indent) << "}\n";
}
// Populates the field of the insn given the start position and the number of
@@ -1083,20 +1079,20 @@ std::pair<bool, uint64_t> FilterChooser::fieldFromInsn(const insn_t &Insn,
/// dumpFilterArray - dumpFilterArray prints out debugging info for the given
/// filter array as a series of chars.
void FilterChooser::dumpFilterArray(
- raw_ostream &o, const std::vector<bit_value_t> &filter) const {
+ raw_ostream &OS, const std::vector<bit_value_t> &filter) const {
for (unsigned bitIndex = BitWidth; bitIndex > 0; bitIndex--) {
switch (filter[bitIndex - 1]) {
case BIT_UNFILTERED:
- o << ".";
+ OS << ".";
break;
case BIT_UNSET:
- o << "_";
+ OS << "_";
break;
case BIT_TRUE:
- o << "1";
+ OS << "1";
break;
case BIT_FALSE:
- o << "0";
+ OS << "0";
break;
}
}
@@ -1104,13 +1100,13 @@ void FilterChooser::dumpFilterArray(
/// dumpStack - dumpStack traverses the filter chooser chain and calls
/// dumpFilterArray on each filter chooser up to the top level one.
-void FilterChooser::dumpStack(raw_ostream &o, const char *prefix) const {
+void FilterChooser::dumpStack(raw_ostream &OS, const char *prefix) const {
const FilterChooser *current = this;
while (current) {
- o << prefix;
- dumpFilterArray(o, current->FilterBitValues);
- o << '\n';
+ OS << prefix;
+ dumpFilterArray(OS, current->FilterBitValues);
+ OS << '\n';
current = current->Parent;
}
}
@@ -1176,7 +1172,7 @@ unsigned FilterChooser::getIslands(std::vector<unsigned> &StartBits,
return Num;
}
-void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation,
+void FilterChooser::emitBinaryParser(raw_ostream &OS, unsigned Indent,
const OperandInfo &OpInfo,
bool &OpHasCompleteDecoder) const {
const std::string &Decoder = OpInfo.Decoder;
@@ -1184,56 +1180,56 @@ void FilterChooser::emitBinaryParser(raw_ostream &o, unsigned &Indentation,
bool UseInsertBits = OpInfo.numFields() != 1 || OpInfo.InitValue != 0;
if (UseInsertBits) {
- o.indent(Indentation) << "tmp = 0x";
- o.write_hex(OpInfo.InitValue);
- o << ";\n";
+ OS.indent(Indent) << "tmp = 0x";
+ OS.write_hex(OpInfo.InitValue);
+ OS << ";\n";
}
for (const EncodingField &EF : OpInfo) {
- o.indent(Indentation);
+ OS.indent(Indent);
if (UseInsertBits)
- o << "insertBits(tmp, ";
+ OS << "insertBits(tmp, ";
else
- o << "tmp = ";
- o << "fieldFromInstruction(insn, " << EF.Base << ", " << EF.Width << ')';
+ OS << "tmp = ";
+ OS << "fieldFromInstruction(insn, " << EF.Base << ", " << EF.Width << ')';
if (UseInsertBits)
- o << ", " << EF.Offset << ", " << EF.Width << ')';
+ OS << ", " << EF.Offset << ", " << EF.Width << ')';
else if (EF.Offset != 0)
- o << " << " << EF.Offset;
- o << ";\n";
+ OS << " << " << EF.Offset;
+ OS << ";\n";
}
if (Decoder != "") {
OpHasCompleteDecoder = OpInfo.HasCompleteDecoder;
- o.indent(Indentation) << "if (!Check(S, " << Decoder
- << "(MI, tmp, Address, Decoder))) { "
- << (OpHasCompleteDecoder ? ""
- : "DecodeComplete = false; ")
- << "return MCDisassembler::Fail; }\n";
+ OS.indent(Indent) << "if (!Check(S, " << Decoder
+ << "(MI, tmp, Address, Decoder))) { "
+ << (OpHasCompleteDecoder ? ""
+ : "DecodeComplete = false; ")
+ << "return MCDisassembler::Fail; }\n";
} else {
OpHasCompleteDecoder = true;
- o.indent(Indentation) << "MI.addOperand(MCOperand::createImm(tmp));\n";
+ OS.indent(Indent) << "MI.addOperand(MCOperand::createImm(tmp));\n";
}
}
-void FilterChooser::emitDecoder(raw_ostream &OS, unsigned Indentation,
- unsigned Opc, bool &HasCompleteDecoder) const {
+void FilterChooser::emitDecoder(raw_ostream &OS, unsigned Indent, unsigned Opc,
+ bool &HasCompleteDecoder) const {
HasCompleteDecoder = true;
for (const auto &Op : Operands.find(Opc)->second) {
// If a custom instruction decoder was specified, use that.
if (Op.numFields() == 0 && !Op.Decoder.empty()) {
HasCompleteDecoder = Op.HasCompleteDecoder;
- OS.indent(Indentation)
- << "if (!Check(S, " << Op.Decoder
- << "(MI, insn, Address, Decoder))) { "
- << (HasCompleteDecoder ? "" : "DecodeComplete = false; ")
- << "return MCDisassembler::Fail; }\n";
+ OS.indent(Indent) << "if (!Check(S, " << Op.Decoder
+ << "(MI, insn, Address, Decoder))) { "
+ << (HasCompleteDecoder ? ""
+ : "DecodeComplete = false; ")
+ << "return MCDisassembler::Fail; }\n";
break;
}
bool OpHasCompleteDecoder;
- emitBinaryParser(OS, Indentation, Op, OpHasCompleteDecoder);
+ emitBinaryParser(OS, Indent, Op, OpHasCompleteDecoder);
if (!OpHasCompleteDecoder)
HasCompleteDecoder = false;
}
@@ -1296,8 +1292,7 @@ bool FilterChooser::emitPredicateMatchAux(const Init &Val, bool ParenIfBinOp,
return true;
}
-bool FilterChooser::emitPredicateMatch(raw_ostream &o, unsigned &Indentation,
- unsigned Opc) const {
+bool FilterChooser::emitPredicateMatch(raw_ostream &OS, unsigned Opc) const {
ListInit *Predicates =
AllInstructions[Opc].EncodingDef->getValueAsListInit("Predicates");
bool IsFirstEmission = true;
@@ -1310,9 +1305,9 @@ bool FilterChooser::emitPredicateMatch(raw_ostream &o, unsigned &Indentation,
continue;
if (!IsFirstEmission)
- o << " && ";
+ OS << " && ";
if (emitPredicateMatchAux(*Pred->getValueAsDag("AssemblerCondDag"),
- Predicates->size() > 1, o))
+ Predicates->size() > 1, OS))
PrintFatalError(Pred->getLoc(), "Invalid AssemblerCondDag!");
IsFirstEmission = false;
}
@@ -1358,8 +1353,7 @@ void FilterChooser::emitPredicateTableEntry(DecoderTableInfo &TableInfo,
// FIXME: emitPredicateMatch() functions can take a buffer directly rather
// than a stream.
raw_svector_ostream PS(Predicate);
- unsigned I = 0;
- emitPredicateMatch(PS, I, Opc);
+ emitPredicateMatch(PS, Opc);
// Figure out the index into the predicate table for the predicate just
// computed.