[llvm] 0c2a3d6 - [TableGen][NFC] Format parts of DAGISelMatcher.h/DAGISelMatcherGen.cpp

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 12 02:12:29 PST 2023


Author: wangpc
Date: 2023-12-12T18:11:38+08:00
New Revision: 0c2a3d6033829f0fa22ace8669e4561e7dce2722

URL: https://github.com/llvm/llvm-project/commit/0c2a3d6033829f0fa22ace8669e4561e7dce2722
DIFF: https://github.com/llvm/llvm-project/commit/0c2a3d6033829f0fa22ace8669e4561e7dce2722.diff

LOG: [TableGen][NFC] Format parts of DAGISelMatcher.h/DAGISelMatcherGen.cpp

To reduce the diff in #73310

Added: 
    

Modified: 
    llvm/utils/TableGen/DAGISelMatcher.h
    llvm/utils/TableGen/DAGISelMatcherGen.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/DAGISelMatcher.h b/llvm/utils/TableGen/DAGISelMatcher.h
index e69f8fa9c5d30..0e8a948ec8a95 100644
--- a/llvm/utils/TableGen/DAGISelMatcher.h
+++ b/llvm/utils/TableGen/DAGISelMatcher.h
@@ -33,162 +33,167 @@ namespace llvm {
   class TreePredicateFn;
   class TreePattern;
 
-Matcher *ConvertPatternToMatcher(const PatternToMatch &Pattern,unsigned Variant,
-                                 const CodeGenDAGPatterns &CGP);
-void OptimizeMatcher(std::unique_ptr<Matcher> &Matcher,
-                     const CodeGenDAGPatterns &CGP);
-void EmitMatcherTable(Matcher *Matcher, const CodeGenDAGPatterns &CGP,
-                      raw_ostream &OS);
-
-
-/// Matcher - Base class for all the DAG ISel Matcher representation
-/// nodes.
-class Matcher {
-  // The next matcher node that is executed after this one.  Null if this is the
-  // last stage of a match.
-  std::unique_ptr<Matcher> Next;
-  size_t Size = 0; // Size in bytes of matcher and all its children (if any).
-  virtual void anchor();
-public:
-  enum KindTy {
-    // Matcher state manipulation.
-    Scope,            // Push a checking scope.
-    RecordNode,       // Record the current node.
-    RecordChild,      // Record a child of the current node.
-    RecordMemRef,     // Record the memref in the current node.
-    CaptureGlueInput, // If the current node has an input glue, save it.
-    MoveChild,        // Move current node to specified child.
-    MoveSibling,      // Move current node to specified sibling.
-    MoveParent,       // Move current node to parent.
-
-    // Predicate checking.
-    CheckSame,      // Fail if not same as prev match.
-    CheckChildSame, // Fail if child not same as prev match.
-    CheckPatternPredicate,
-    CheckPredicate,      // Fail if node predicate fails.
-    CheckOpcode,         // Fail if not opcode.
-    SwitchOpcode,        // Dispatch based on opcode.
-    CheckType,           // Fail if not correct type.
-    SwitchType,          // Dispatch based on type.
-    CheckChildType,      // Fail if child has wrong type.
-    CheckInteger,        // Fail if wrong val.
-    CheckChildInteger,   // Fail if child is wrong val.
-    CheckCondCode,       // Fail if not condcode.
-    CheckChild2CondCode, // Fail if child is wrong condcode.
-    CheckValueType,
-    CheckComplexPat,
-    CheckAndImm,
-    CheckOrImm,
-    CheckImmAllOnesV,
-    CheckImmAllZerosV,
-    CheckFoldableChainNode,
-
-    // Node creation/emisssion.
-    EmitInteger,          // Create a TargetConstant
-    EmitStringInteger,    // Create a TargetConstant from a string.
-    EmitRegister,         // Create a register.
-    EmitConvertToTarget,  // Convert a imm/fpimm to target imm/fpimm
-    EmitMergeInputChains, // Merge together a chains for an input.
-    EmitCopyToReg,        // Emit a copytoreg into a physreg.
-    EmitNode,             // Create a DAG node
-    EmitNodeXForm,        // Run a SDNodeXForm
-    CompleteMatch,        // Finish a match and update the results.
-    MorphNodeTo,          // Build a node, finish a match and update results.
-
-    // Highest enum value; watch out when adding more.
-    HighestKind = MorphNodeTo
-  };
-  const KindTy Kind;
+  Matcher *ConvertPatternToMatcher(const PatternToMatch &Pattern,
+                                   unsigned Variant,
+                                   const CodeGenDAGPatterns &CGP);
+  void OptimizeMatcher(std::unique_ptr<Matcher> &Matcher,
+                       const CodeGenDAGPatterns &CGP);
+  void EmitMatcherTable(Matcher *Matcher, const CodeGenDAGPatterns &CGP,
+                        raw_ostream &OS);
+
+  /// Matcher - Base class for all the DAG ISel Matcher representation
+  /// nodes.
+  class Matcher {
+    // The next matcher node that is executed after this one.  Null if this is
+    // the last stage of a match.
+    std::unique_ptr<Matcher> Next;
+    size_t Size = 0; // Size in bytes of matcher and all its children (if any).
+    virtual void anchor();
+
+  public:
+    enum KindTy {
+      // Matcher state manipulation.
+      Scope,            // Push a checking scope.
+      RecordNode,       // Record the current node.
+      RecordChild,      // Record a child of the current node.
+      RecordMemRef,     // Record the memref in the current node.
+      CaptureGlueInput, // If the current node has an input glue, save it.
+      MoveChild,        // Move current node to specified child.
+      MoveSibling,      // Move current node to specified sibling.
+      MoveParent,       // Move current node to parent.
+
+      // Predicate checking.
+      CheckSame,      // Fail if not same as prev match.
+      CheckChildSame, // Fail if child not same as prev match.
+      CheckPatternPredicate,
+      CheckPredicate,      // Fail if node predicate fails.
+      CheckOpcode,         // Fail if not opcode.
+      SwitchOpcode,        // Dispatch based on opcode.
+      CheckType,           // Fail if not correct type.
+      SwitchType,          // Dispatch based on type.
+      CheckChildType,      // Fail if child has wrong type.
+      CheckInteger,        // Fail if wrong val.
+      CheckChildInteger,   // Fail if child is wrong val.
+      CheckCondCode,       // Fail if not condcode.
+      CheckChild2CondCode, // Fail if child is wrong condcode.
+      CheckValueType,
+      CheckComplexPat,
+      CheckAndImm,
+      CheckOrImm,
+      CheckImmAllOnesV,
+      CheckImmAllZerosV,
+      CheckFoldableChainNode,
+
+      // Node creation/emisssion.
+      EmitInteger,          // Create a TargetConstant
+      EmitStringInteger,    // Create a TargetConstant from a string.
+      EmitRegister,         // Create a register.
+      EmitConvertToTarget,  // Convert a imm/fpimm to target imm/fpimm
+      EmitMergeInputChains, // Merge together a chains for an input.
+      EmitCopyToReg,        // Emit a copytoreg into a physreg.
+      EmitNode,             // Create a DAG node
+      EmitNodeXForm,        // Run a SDNodeXForm
+      CompleteMatch,        // Finish a match and update the results.
+      MorphNodeTo,          // Build a node, finish a match and update results.
+
+      // Highest enum value; watch out when adding more.
+      HighestKind = MorphNodeTo
+    };
+    const KindTy Kind;
+
+  protected:
+    Matcher(KindTy K) : Kind(K) {}
+
+  public:
+    virtual ~Matcher() {}
+
+    unsigned getSize() const { return Size; }
+    void setSize(unsigned sz) { Size = sz; }
+    KindTy getKind() const { return Kind; }
+
+    Matcher *getNext() { return Next.get(); }
+    const Matcher *getNext() const { return Next.get(); }
+    void setNext(Matcher *C) { Next.reset(C); }
+    Matcher *takeNext() { return Next.release(); }
+
+    std::unique_ptr<Matcher> &getNextPtr() { return Next; }
+
+    bool isEqual(const Matcher *M) const {
+      if (getKind() != M->getKind())
+        return false;
+      return isEqualImpl(M);
+    }
 
-protected:
-  Matcher(KindTy K) : Kind(K) {}
-public:
-  virtual ~Matcher() {}
-
-  unsigned getSize() const { return Size; }
-  void setSize(unsigned sz) { Size = sz; }
-  KindTy getKind() const { return Kind; }
-
-  Matcher *getNext() { return Next.get(); }
-  const Matcher *getNext() const { return Next.get(); }
-  void setNext(Matcher *C) { Next.reset(C); }
-  Matcher *takeNext() { return Next.release(); }
-
-  std::unique_ptr<Matcher> &getNextPtr() { return Next; }
-
-  bool isEqual(const Matcher *M) const {
-    if (getKind() != M->getKind()) return false;
-    return isEqualImpl(M);
-  }
-
-  /// isSimplePredicateNode - Return true if this is a simple predicate that
-  /// operates on the node or its children without potential side effects or a
-  /// change of the current node.
-  bool isSimplePredicateNode() const {
-    switch (getKind()) {
-    default: return false;
-    case CheckSame:
-    case CheckChildSame:
-    case CheckPatternPredicate:
-    case CheckPredicate:
-    case CheckOpcode:
-    case CheckType:
-    case CheckChildType:
-    case CheckInteger:
-    case CheckChildInteger:
-    case CheckCondCode:
-    case CheckChild2CondCode:
-    case CheckValueType:
-    case CheckAndImm:
-    case CheckOrImm:
-    case CheckImmAllOnesV:
-    case CheckImmAllZerosV:
-    case CheckFoldableChainNode:
-      return true;
+    /// isSimplePredicateNode - Return true if this is a simple predicate that
+    /// operates on the node or its children without potential side effects or a
+    /// change of the current node.
+    bool isSimplePredicateNode() const {
+      switch (getKind()) {
+      default:
+        return false;
+      case CheckSame:
+      case CheckChildSame:
+      case CheckPatternPredicate:
+      case CheckPredicate:
+      case CheckOpcode:
+      case CheckType:
+      case CheckChildType:
+      case CheckInteger:
+      case CheckChildInteger:
+      case CheckCondCode:
+      case CheckChild2CondCode:
+      case CheckValueType:
+      case CheckAndImm:
+      case CheckOrImm:
+      case CheckImmAllOnesV:
+      case CheckImmAllZerosV:
+      case CheckFoldableChainNode:
+        return true;
+      }
     }
-  }
 
-  /// isSimplePredicateOrRecordNode - Return true if this is a record node or
-  /// a simple predicate.
-  bool isSimplePredicateOrRecordNode() const {
-    return isSimplePredicateNode() ||
-           getKind() == RecordNode || getKind() == RecordChild;
-  }
-
-  /// unlinkNode - Unlink the specified node from this chain.  If Other == this,
-  /// we unlink the next pointer and return it.  Otherwise we unlink Other from
-  /// the list and return this.
-  Matcher *unlinkNode(Matcher *Other);
-
-  /// canMoveBefore - Return true if this matcher is the same as Other, or if
-  /// we can move this matcher past all of the nodes in-between Other and this
-  /// node.  Other must be equal to or before this.
-  bool canMoveBefore(const Matcher *Other) const;
-
-  /// canMoveBeforeNode - Return true if it is safe to move the current matcher
-  /// across the specified one.
-  bool canMoveBeforeNode(const Matcher *Other) const;
-
-  /// isContradictory - Return true of these two matchers could never match on
-  /// the same node.
-  bool isContradictory(const Matcher *Other) const {
-    // Since this predicate is reflexive, we canonicalize the ordering so that
-    // we always match a node against nodes with kinds that are greater or equal
-    // to them.  For example, we'll pass in a CheckType node as an argument to
-    // the CheckOpcode method, not the other way around.
-    if (getKind() < Other->getKind())
-      return isContradictoryImpl(Other);
-    return Other->isContradictoryImpl(this);
-  }
-
-  void print(raw_ostream &OS, unsigned indent = 0) const;
-  void printOne(raw_ostream &OS) const;
-  void dump() const;
-protected:
-  virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
-  virtual bool isEqualImpl(const Matcher *M) const = 0;
-  virtual bool isContradictoryImpl(const Matcher *M) const { return false; }
-};
+    /// isSimplePredicateOrRecordNode - Return true if this is a record node or
+    /// a simple predicate.
+    bool isSimplePredicateOrRecordNode() const {
+      return isSimplePredicateNode() || getKind() == RecordNode ||
+             getKind() == RecordChild;
+    }
+
+    /// unlinkNode - Unlink the specified node from this chain.  If Other ==
+    /// this, we unlink the next pointer and return it.  Otherwise we unlink
+    /// Other from the list and return this.
+    Matcher *unlinkNode(Matcher *Other);
+
+    /// canMoveBefore - Return true if this matcher is the same as Other, or if
+    /// we can move this matcher past all of the nodes in-between Other and this
+    /// node.  Other must be equal to or before this.
+    bool canMoveBefore(const Matcher *Other) const;
+
+    /// canMoveBeforeNode - Return true if it is safe to move the current
+    /// matcher across the specified one.
+    bool canMoveBeforeNode(const Matcher *Other) const;
+
+    /// isContradictory - Return true of these two matchers could never match on
+    /// the same node.
+    bool isContradictory(const Matcher *Other) const {
+      // Since this predicate is reflexive, we canonicalize the ordering so that
+      // we always match a node against nodes with kinds that are greater or
+      // equal to them.  For example, we'll pass in a CheckType node as an
+      // argument to the CheckOpcode method, not the other way around.
+      if (getKind() < Other->getKind())
+        return isContradictoryImpl(Other);
+      return Other->isContradictoryImpl(this);
+    }
+
+    void print(raw_ostream &OS, unsigned indent = 0) const;
+    void printOne(raw_ostream &OS) const;
+    void dump() const;
+
+  protected:
+    virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
+    virtual bool isEqualImpl(const Matcher *M) const = 0;
+    virtual bool isContradictoryImpl(const Matcher *M) const { return false; }
+  };
 
 /// ScopeMatcher - This attempts to match each of its children to find the first
 /// one that successfully matches.  If one child fails, it tries the next child.

diff  --git a/llvm/utils/TableGen/DAGISelMatcherGen.cpp b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
index d08f57b84b95f..fcc5e4d061c86 100644
--- a/llvm/utils/TableGen/DAGISelMatcherGen.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
@@ -147,25 +147,26 @@ namespace {
 
 MatcherGen::MatcherGen(const PatternToMatch &pattern,
                        const CodeGenDAGPatterns &cgp)
-: Pattern(pattern), CGP(cgp), NextRecordedOperandNo(0),
-  TheMatcher(nullptr), CurPredicate(nullptr) {
-  // We need to produce the matcher tree for the patterns source pattern.  To do
-  // this we need to match the structure as well as the types.  To do the type
-  // matching, we want to figure out the fewest number of type checks we need to
-  // emit.  For example, if there is only one integer type supported by a
-  // target, there should be no type comparisons at all for integer patterns!
-  //
-  // To figure out the fewest number of type checks needed, clone the pattern,
-  // remove the types, then perform type inference on the pattern as a whole.
-  // If there are unresolved types, emit an explicit check for those types,
-  // apply the type to the tree, then rerun type inference.  Iterate until all
-  // types are resolved.
-  //
-  PatWithNoTypes = Pattern.getSrcPattern()->clone();
-  PatWithNoTypes->RemoveAllTypes();
+    : Pattern(pattern), CGP(cgp), NextRecordedOperandNo(0), TheMatcher(nullptr),
+      CurPredicate(nullptr) {
+    // We need to produce the matcher tree for the patterns source pattern.  To
+    // do this we need to match the structure as well as the types.  To do the
+    // type matching, we want to figure out the fewest number of type checks we
+    // need to emit.  For example, if there is only one integer type supported
+    // by a target, there should be no type comparisons at all for integer
+    // patterns!
+    //
+    // To figure out the fewest number of type checks needed, clone the pattern,
+    // remove the types, then perform type inference on the pattern as a whole.
+    // If there are unresolved types, emit an explicit check for those types,
+    // apply the type to the tree, then rerun type inference.  Iterate until all
+    // types are resolved.
+    //
+    PatWithNoTypes = Pattern.getSrcPattern()->clone();
+    PatWithNoTypes->RemoveAllTypes();
 
-  // If there are types that are manifestly known, infer them.
-  InferPossibleTypes();
+    // If there are types that are manifestly known, infer them.
+    InferPossibleTypes();
 }
 
 /// InferPossibleTypes - As we emit the pattern, we end up generating type


        


More information about the llvm-commits mailing list