diff options
| author | Rahul Joshi <rjoshi@nvidia.com> | 2024-09-20 04:23:52 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-20 04:23:52 -0700 |
| commit | 2b01452c208877e20043c0a643c89bc10be5ca4d (patch) | |
| tree | 8225e274fdd65469feed30ed0fa74a84ef4f133f | |
| parent | d109636c2ee55f872e846ce11e0e1882382703c1 (diff) | |
| download | llvm-2b01452c208877e20043c0a643c89bc10be5ca4d.zip llvm-2b01452c208877e20043c0a643c89bc10be5ca4d.tar.gz llvm-2b01452c208877e20043c0a643c89bc10be5ca4d.tar.bz2 | |
[LLVM][TableGen] Use const Record pointers in PredicateExpander (#109365)
Use const Record pointers in PredicateExpander.
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
| -rw-r--r-- | llvm/utils/TableGen/Common/PredicateExpander.cpp | 23 | ||||
| -rw-r--r-- | llvm/utils/TableGen/Common/PredicateExpander.h | 13 |
2 files changed, 17 insertions, 19 deletions
diff --git a/llvm/utils/TableGen/Common/PredicateExpander.cpp b/llvm/utils/TableGen/Common/PredicateExpander.cpp index d0a35ff..456c4cf 100644 --- a/llvm/utils/TableGen/Common/PredicateExpander.cpp +++ b/llvm/utils/TableGen/Common/PredicateExpander.cpp @@ -139,7 +139,7 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS, const Record *Inst) { } void PredicateExpander::expandCheckOpcode(raw_ostream &OS, - const RecVec &Opcodes) { + ArrayRef<const Record *> Opcodes) { assert(!Opcodes.empty() && "Expected at least one opcode to check!"); bool First = true; @@ -169,16 +169,15 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS, } void PredicateExpander::expandCheckPseudo(raw_ostream &OS, - const RecVec &Opcodes) { + ArrayRef<const Record *> Opcodes) { if (shouldExpandForMC()) expandFalse(OS); else expandCheckOpcode(OS, Opcodes); } -void PredicateExpander::expandPredicateSequence(raw_ostream &OS, - const RecVec &Sequence, - bool IsCheckAll) { +void PredicateExpander::expandPredicateSequence( + raw_ostream &OS, ArrayRef<const Record *> Sequence, bool IsCheckAll) { assert(!Sequence.empty() && "Found an invalid empty predicate set!"); if (Sequence.size() == 1) return expandPredicate(OS, Sequence[0]); @@ -267,8 +266,7 @@ void PredicateExpander::expandReturnStatement(raw_ostream &OS, void PredicateExpander::expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec) { - const RecVec &Opcodes = Rec->getValueAsListOfDefs("Opcodes"); - for (const Record *Opcode : Opcodes) { + for (const Record *Opcode : Rec->getValueAsListOfDefs("Opcodes")) { OS.indent(getIndentLevel() * 2); OS << "case " << Opcode->getValueAsString("Namespace") << "::" << Opcode->getName() << ":\n"; @@ -280,9 +278,8 @@ void PredicateExpander::expandOpcodeSwitchCase(raw_ostream &OS, decreaseIndentLevel(); } -void PredicateExpander::expandOpcodeSwitchStatement(raw_ostream &OS, - const RecVec &Cases, - const Record *Default) { +void PredicateExpander::expandOpcodeSwitchStatement( + raw_ostream &OS, ArrayRef<const Record *> Cases, const Record *Default) { std::string Buffer; raw_string_ostream SS(Buffer); @@ -310,7 +307,7 @@ void PredicateExpander::expandOpcodeSwitchStatement(raw_ostream &OS, void PredicateExpander::expandStatement(raw_ostream &OS, const Record *Rec) { // Assume that padding has been added by the caller. if (Rec->isSubClassOf("MCOpcodeSwitchStatement")) { - expandOpcodeSwitchStatement(OS, Rec->getValueAsListOfDefs("Cases"), + expandOpcodeSwitchStatement(OS, Rec->getValueAsListOfConstDefs("Cases"), Rec->getValueAsDef("DefaultCase")); return; } @@ -461,13 +458,13 @@ void STIPredicateExpander::expandHeader(raw_ostream &OS, void STIPredicateExpander::expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn) { - RecVec Delegates = Fn.getDeclaration()->getValueAsListOfDefs("Delegates"); bool UpdatesOpcodeMask = Fn.getDeclaration()->getValueAsBit("UpdatesOpcodeMask"); increaseIndentLevel(); unsigned IndentLevel = getIndentLevel(); - for (const Record *Delegate : Delegates) { + for (const Record *Delegate : + Fn.getDeclaration()->getValueAsListOfDefs("Delegates")) { OS.indent(IndentLevel * 2); OS << "if (" << Delegate->getValueAsString("Name") << "(MI"; if (UpdatesOpcodeMask) diff --git a/llvm/utils/TableGen/Common/PredicateExpander.h b/llvm/utils/TableGen/Common/PredicateExpander.h index 333d1c5..c0cd69e 100644 --- a/llvm/utils/TableGen/Common/PredicateExpander.h +++ b/llvm/utils/TableGen/Common/PredicateExpander.h @@ -16,8 +16,8 @@ #ifndef LLVM_UTILS_TABLEGEN_COMMON_PREDICATEEXPANDER_H #define LLVM_UTILS_TABLEGEN_COMMON_PREDICATEEXPANDER_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" -#include <vector> namespace llvm { @@ -52,7 +52,6 @@ public: void increaseIndentLevel() { ++IndentLevel; } void decreaseIndentLevel() { --IndentLevel; } - using RecVec = std::vector<Record *>; void expandTrue(raw_ostream &OS); void expandFalse(raw_ostream &OS); void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal, @@ -73,9 +72,10 @@ public: void expandCheckNumOperands(raw_ostream &OS, int NumOps); void expandCheckOpcode(raw_ostream &OS, const Record *Inst); - void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes); - void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes); - void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence, + void expandCheckPseudo(raw_ostream &OS, ArrayRef<const Record *> Opcodes); + void expandCheckOpcode(raw_ostream &OS, ArrayRef<const Record *> Opcodes); + void expandPredicateSequence(raw_ostream &OS, + ArrayRef<const Record *> Sequence, bool IsCheckAll); void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName); void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex); @@ -91,7 +91,8 @@ public: void expandPredicate(raw_ostream &OS, const Record *Rec); void expandReturnStatement(raw_ostream &OS, const Record *Rec); void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec); - void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases, + void expandOpcodeSwitchStatement(raw_ostream &OS, + ArrayRef<const Record *> Cases, const Record *Default); void expandStatement(raw_ostream &OS, const Record *Rec); }; |
