[llvm] 2b01452 - [LLVM][TableGen] Use const Record pointers in PredicateExpander (#109365)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 20 04:23:55 PDT 2024


Author: Rahul Joshi
Date: 2024-09-20T04:23:52-07:00
New Revision: 2b01452c208877e20043c0a643c89bc10be5ca4d

URL: https://github.com/llvm/llvm-project/commit/2b01452c208877e20043c0a643c89bc10be5ca4d
DIFF: https://github.com/llvm/llvm-project/commit/2b01452c208877e20043c0a643c89bc10be5ca4d.diff

LOG: [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

Added: 
    

Modified: 
    llvm/utils/TableGen/Common/PredicateExpander.cpp
    llvm/utils/TableGen/Common/PredicateExpander.h

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/Common/PredicateExpander.cpp b/llvm/utils/TableGen/Common/PredicateExpander.cpp
index d0a35ff82df649..456c4cf5d92279 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 333d1c561f9701..c0cd69e3cb1f85 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 @@ class PredicateExpander {
   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 @@ class PredicateExpander {
   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 @@ class PredicateExpander {
   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);
 };


        


More information about the llvm-commits mailing list