@@ -33,162 +33,167 @@ namespace llvm {
33
33
class TreePredicateFn ;
34
34
class TreePattern ;
35
35
36
- Matcher *ConvertPatternToMatcher (const PatternToMatch &Pattern,unsigned Variant,
37
- const CodeGenDAGPatterns &CGP);
38
- void OptimizeMatcher (std::unique_ptr<Matcher> &Matcher,
39
- const CodeGenDAGPatterns &CGP);
40
- void EmitMatcherTable (Matcher *Matcher, const CodeGenDAGPatterns &CGP,
41
- raw_ostream &OS);
42
-
43
-
44
- // / Matcher - Base class for all the DAG ISel Matcher representation
45
- // / nodes.
46
- class Matcher {
47
- // The next matcher node that is executed after this one. Null if this is the
48
- // last stage of a match.
49
- std::unique_ptr<Matcher> Next;
50
- size_t Size = 0 ; // Size in bytes of matcher and all its children (if any).
51
- virtual void anchor ();
52
- public:
53
- enum KindTy {
54
- // Matcher state manipulation.
55
- Scope, // Push a checking scope.
56
- RecordNode, // Record the current node.
57
- RecordChild, // Record a child of the current node.
58
- RecordMemRef, // Record the memref in the current node.
59
- CaptureGlueInput, // If the current node has an input glue, save it.
60
- MoveChild, // Move current node to specified child.
61
- MoveSibling, // Move current node to specified sibling.
62
- MoveParent, // Move current node to parent.
63
-
64
- // Predicate checking.
65
- CheckSame, // Fail if not same as prev match.
66
- CheckChildSame, // Fail if child not same as prev match.
67
- CheckPatternPredicate,
68
- CheckPredicate, // Fail if node predicate fails.
69
- CheckOpcode, // Fail if not opcode.
70
- SwitchOpcode, // Dispatch based on opcode.
71
- CheckType, // Fail if not correct type.
72
- SwitchType, // Dispatch based on type.
73
- CheckChildType, // Fail if child has wrong type.
74
- CheckInteger, // Fail if wrong val.
75
- CheckChildInteger, // Fail if child is wrong val.
76
- CheckCondCode, // Fail if not condcode.
77
- CheckChild2CondCode, // Fail if child is wrong condcode.
78
- CheckValueType,
79
- CheckComplexPat,
80
- CheckAndImm,
81
- CheckOrImm,
82
- CheckImmAllOnesV,
83
- CheckImmAllZerosV,
84
- CheckFoldableChainNode,
85
-
86
- // Node creation/emisssion.
87
- EmitInteger, // Create a TargetConstant
88
- EmitStringInteger, // Create a TargetConstant from a string.
89
- EmitRegister, // Create a register.
90
- EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
91
- EmitMergeInputChains, // Merge together a chains for an input.
92
- EmitCopyToReg, // Emit a copytoreg into a physreg.
93
- EmitNode, // Create a DAG node
94
- EmitNodeXForm, // Run a SDNodeXForm
95
- CompleteMatch, // Finish a match and update the results.
96
- MorphNodeTo, // Build a node, finish a match and update results.
97
-
98
- // Highest enum value; watch out when adding more.
99
- HighestKind = MorphNodeTo
100
- };
101
- const KindTy Kind;
36
+ Matcher *ConvertPatternToMatcher (const PatternToMatch &Pattern,
37
+ unsigned Variant,
38
+ const CodeGenDAGPatterns &CGP);
39
+ void OptimizeMatcher (std::unique_ptr<Matcher> &Matcher,
40
+ const CodeGenDAGPatterns &CGP);
41
+ void EmitMatcherTable (Matcher *Matcher, const CodeGenDAGPatterns &CGP,
42
+ raw_ostream &OS);
43
+
44
+ // / Matcher - Base class for all the DAG ISel Matcher representation
45
+ // / nodes.
46
+ class Matcher {
47
+ // The next matcher node that is executed after this one. Null if this is
48
+ // the last stage of a match.
49
+ std::unique_ptr<Matcher> Next;
50
+ size_t Size = 0 ; // Size in bytes of matcher and all its children (if any).
51
+ virtual void anchor ();
52
+
53
+ public:
54
+ enum KindTy {
55
+ // Matcher state manipulation.
56
+ Scope, // Push a checking scope.
57
+ RecordNode, // Record the current node.
58
+ RecordChild, // Record a child of the current node.
59
+ RecordMemRef, // Record the memref in the current node.
60
+ CaptureGlueInput, // If the current node has an input glue, save it.
61
+ MoveChild, // Move current node to specified child.
62
+ MoveSibling, // Move current node to specified sibling.
63
+ MoveParent, // Move current node to parent.
64
+
65
+ // Predicate checking.
66
+ CheckSame, // Fail if not same as prev match.
67
+ CheckChildSame, // Fail if child not same as prev match.
68
+ CheckPatternPredicate,
69
+ CheckPredicate, // Fail if node predicate fails.
70
+ CheckOpcode, // Fail if not opcode.
71
+ SwitchOpcode, // Dispatch based on opcode.
72
+ CheckType, // Fail if not correct type.
73
+ SwitchType, // Dispatch based on type.
74
+ CheckChildType, // Fail if child has wrong type.
75
+ CheckInteger, // Fail if wrong val.
76
+ CheckChildInteger, // Fail if child is wrong val.
77
+ CheckCondCode, // Fail if not condcode.
78
+ CheckChild2CondCode, // Fail if child is wrong condcode.
79
+ CheckValueType,
80
+ CheckComplexPat,
81
+ CheckAndImm,
82
+ CheckOrImm,
83
+ CheckImmAllOnesV,
84
+ CheckImmAllZerosV,
85
+ CheckFoldableChainNode,
86
+
87
+ // Node creation/emisssion.
88
+ EmitInteger, // Create a TargetConstant
89
+ EmitStringInteger, // Create a TargetConstant from a string.
90
+ EmitRegister, // Create a register.
91
+ EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
92
+ EmitMergeInputChains, // Merge together a chains for an input.
93
+ EmitCopyToReg, // Emit a copytoreg into a physreg.
94
+ EmitNode, // Create a DAG node
95
+ EmitNodeXForm, // Run a SDNodeXForm
96
+ CompleteMatch, // Finish a match and update the results.
97
+ MorphNodeTo, // Build a node, finish a match and update results.
98
+
99
+ // Highest enum value; watch out when adding more.
100
+ HighestKind = MorphNodeTo
101
+ };
102
+ const KindTy Kind;
103
+
104
+ protected:
105
+ Matcher (KindTy K) : Kind(K) {}
106
+
107
+ public:
108
+ virtual ~Matcher () {}
109
+
110
+ unsigned getSize () const { return Size; }
111
+ void setSize (unsigned sz) { Size = sz; }
112
+ KindTy getKind () const { return Kind; }
113
+
114
+ Matcher *getNext () { return Next.get (); }
115
+ const Matcher *getNext () const { return Next.get (); }
116
+ void setNext (Matcher *C) { Next.reset (C); }
117
+ Matcher *takeNext () { return Next.release (); }
118
+
119
+ std::unique_ptr<Matcher> &getNextPtr () { return Next; }
120
+
121
+ bool isEqual (const Matcher *M) const {
122
+ if (getKind () != M->getKind ())
123
+ return false ;
124
+ return isEqualImpl (M);
125
+ }
102
126
103
- protected:
104
- Matcher (KindTy K) : Kind(K) {}
105
- public:
106
- virtual ~Matcher () {}
107
-
108
- unsigned getSize () const { return Size; }
109
- void setSize (unsigned sz) { Size = sz; }
110
- KindTy getKind () const { return Kind; }
111
-
112
- Matcher *getNext () { return Next.get (); }
113
- const Matcher *getNext () const { return Next.get (); }
114
- void setNext (Matcher *C) { Next.reset (C); }
115
- Matcher *takeNext () { return Next.release (); }
116
-
117
- std::unique_ptr<Matcher> &getNextPtr () { return Next; }
118
-
119
- bool isEqual (const Matcher *M) const {
120
- if (getKind () != M->getKind ()) return false ;
121
- return isEqualImpl (M);
122
- }
123
-
124
- // / isSimplePredicateNode - Return true if this is a simple predicate that
125
- // / operates on the node or its children without potential side effects or a
126
- // / change of the current node.
127
- bool isSimplePredicateNode () const {
128
- switch (getKind ()) {
129
- default : return false ;
130
- case CheckSame:
131
- case CheckChildSame:
132
- case CheckPatternPredicate:
133
- case CheckPredicate:
134
- case CheckOpcode:
135
- case CheckType:
136
- case CheckChildType:
137
- case CheckInteger:
138
- case CheckChildInteger:
139
- case CheckCondCode:
140
- case CheckChild2CondCode:
141
- case CheckValueType:
142
- case CheckAndImm:
143
- case CheckOrImm:
144
- case CheckImmAllOnesV:
145
- case CheckImmAllZerosV:
146
- case CheckFoldableChainNode:
147
- return true ;
127
+ // / isSimplePredicateNode - Return true if this is a simple predicate that
128
+ // / operates on the node or its children without potential side effects or a
129
+ // / change of the current node.
130
+ bool isSimplePredicateNode () const {
131
+ switch (getKind ()) {
132
+ default :
133
+ return false ;
134
+ case CheckSame:
135
+ case CheckChildSame:
136
+ case CheckPatternPredicate:
137
+ case CheckPredicate:
138
+ case CheckOpcode:
139
+ case CheckType:
140
+ case CheckChildType:
141
+ case CheckInteger:
142
+ case CheckChildInteger:
143
+ case CheckCondCode:
144
+ case CheckChild2CondCode:
145
+ case CheckValueType:
146
+ case CheckAndImm:
147
+ case CheckOrImm:
148
+ case CheckImmAllOnesV:
149
+ case CheckImmAllZerosV:
150
+ case CheckFoldableChainNode:
151
+ return true ;
152
+ }
148
153
}
149
- }
150
154
151
- // / isSimplePredicateOrRecordNode - Return true if this is a record node or
152
- // / a simple predicate.
153
- bool isSimplePredicateOrRecordNode () const {
154
- return isSimplePredicateNode () ||
155
- getKind () == RecordNode || getKind () == RecordChild;
156
- }
157
-
158
- // / unlinkNode - Unlink the specified node from this chain. If Other == this,
159
- // / we unlink the next pointer and return it. Otherwise we unlink Other from
160
- // / the list and return this.
161
- Matcher *unlinkNode (Matcher *Other);
162
-
163
- // / canMoveBefore - Return true if this matcher is the same as Other, or if
164
- // / we can move this matcher past all of the nodes in-between Other and this
165
- // / node. Other must be equal to or before this.
166
- bool canMoveBefore (const Matcher *Other) const ;
167
-
168
- // / canMoveBeforeNode - Return true if it is safe to move the current matcher
169
- // / across the specified one.
170
- bool canMoveBeforeNode (const Matcher *Other) const ;
171
-
172
- // / isContradictory - Return true of these two matchers could never match on
173
- // / the same node.
174
- bool isContradictory (const Matcher *Other) const {
175
- // Since this predicate is reflexive, we canonicalize the ordering so that
176
- // we always match a node against nodes with kinds that are greater or equal
177
- // to them. For example, we'll pass in a CheckType node as an argument to
178
- // the CheckOpcode method, not the other way around.
179
- if (getKind () < Other->getKind ())
180
- return isContradictoryImpl (Other);
181
- return Other->isContradictoryImpl (this );
182
- }
183
-
184
- void print (raw_ostream &OS, unsigned indent = 0 ) const ;
185
- void printOne (raw_ostream &OS) const ;
186
- void dump () const ;
187
- protected:
188
- virtual void printImpl (raw_ostream &OS, unsigned indent) const = 0;
189
- virtual bool isEqualImpl (const Matcher *M) const = 0;
190
- virtual bool isContradictoryImpl (const Matcher *M) const { return false ; }
191
- };
155
+ // / isSimplePredicateOrRecordNode - Return true if this is a record node or
156
+ // / a simple predicate.
157
+ bool isSimplePredicateOrRecordNode () const {
158
+ return isSimplePredicateNode () || getKind () == RecordNode ||
159
+ getKind () == RecordChild;
160
+ }
161
+
162
+ // / unlinkNode - Unlink the specified node from this chain. If Other ==
163
+ // / this, we unlink the next pointer and return it. Otherwise we unlink
164
+ // / Other from the list and return this.
165
+ Matcher *unlinkNode (Matcher *Other);
166
+
167
+ // / canMoveBefore - Return true if this matcher is the same as Other, or if
168
+ // / we can move this matcher past all of the nodes in-between Other and this
169
+ // / node. Other must be equal to or before this.
170
+ bool canMoveBefore (const Matcher *Other) const ;
171
+
172
+ // / canMoveBeforeNode - Return true if it is safe to move the current
173
+ // / matcher across the specified one.
174
+ bool canMoveBeforeNode (const Matcher *Other) const ;
175
+
176
+ // / isContradictory - Return true of these two matchers could never match on
177
+ // / the same node.
178
+ bool isContradictory (const Matcher *Other) const {
179
+ // Since this predicate is reflexive, we canonicalize the ordering so that
180
+ // we always match a node against nodes with kinds that are greater or
181
+ // equal to them. For example, we'll pass in a CheckType node as an
182
+ // argument to the CheckOpcode method, not the other way around.
183
+ if (getKind () < Other->getKind ())
184
+ return isContradictoryImpl (Other);
185
+ return Other->isContradictoryImpl (this );
186
+ }
187
+
188
+ void print (raw_ostream &OS, unsigned indent = 0 ) const ;
189
+ void printOne (raw_ostream &OS) const ;
190
+ void dump () const ;
191
+
192
+ protected:
193
+ virtual void printImpl (raw_ostream &OS, unsigned indent) const = 0;
194
+ virtual bool isEqualImpl (const Matcher *M) const = 0;
195
+ virtual bool isContradictoryImpl (const Matcher *M) const { return false ; }
196
+ };
192
197
193
198
// / ScopeMatcher - This attempts to match each of its children to find the first
194
199
// / one that successfully matches. If one child fails, it tries the next child.
0 commit comments