blob: 37bfe022b4d13d27da745ca7dac9c44ddca54578 [file] [log] [blame]
Chris Lattnerab3242f2008-01-06 01:10:31 +00001//===- CodeGenDAGPatterns.h - Read DAG patterns from .td file ---*- C++ -*-===//
Chris Lattner8cab0212008-01-05 22:25:12 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Chris Lattnerab3242f2008-01-06 01:10:31 +000010// This file declares the CodeGenDAGPatterns class, which is used to read and
Chris Lattner8cab0212008-01-05 22:25:12 +000011// represent the patterns present in a .td file for instructions.
12//
13//===----------------------------------------------------------------------===//
14
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H
16#define LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H
Chris Lattner8cab0212008-01-05 22:25:12 +000017
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +000018#include "CodeGenHwModes.h"
Chris Lattner8cab0212008-01-05 22:25:12 +000019#include "CodeGenIntrinsics.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000020#include "CodeGenTarget.h"
Chris Lattnercabe0372010-03-15 06:00:16 +000021#include "llvm/ADT/SmallVector.h"
22#include "llvm/ADT/StringMap.h"
Zachary Turner249dc142017-09-20 18:01:40 +000023#include "llvm/ADT/StringSet.h"
Craig Topperc4965bc2012-02-05 07:21:30 +000024#include "llvm/Support/ErrorHandling.h"
Krzysztof Parzyszekaffd2012017-09-19 18:42:34 +000025#include "llvm/Support/MathExtras.h"
Chris Lattner1802b172010-03-19 01:07:44 +000026#include <algorithm>
Krzysztof Parzyszekaffd2012017-09-19 18:42:34 +000027#include <array>
Chris Lattner1802b172010-03-19 01:07:44 +000028#include <map>
Chandler Carruth91d19d82012-12-04 10:37:14 +000029#include <set>
30#include <vector>
Chris Lattner8cab0212008-01-05 22:25:12 +000031
32namespace llvm {
Chris Lattner8cab0212008-01-05 22:25:12 +000033
Krzysztof Parzyszekaffd2012017-09-19 18:42:34 +000034class Record;
35class Init;
36class ListInit;
37class DagInit;
38class SDNodeInfo;
39class TreePattern;
40class TreePatternNode;
41class CodeGenDAGPatterns;
42class ComplexPattern;
43
44/// This represents a set of MVTs. Since the underlying type for the MVT
45/// is uint8_t, there are at most 256 values. To reduce the number of memory
46/// allocations and deallocations, represent the set as a sequence of bits.
47/// To reduce the allocations even further, make MachineValueTypeSet own
48/// the storage and use std::array as the bit container.
49struct MachineValueTypeSet {
50 static_assert(std::is_same<std::underlying_type<MVT::SimpleValueType>::type,
51 uint8_t>::value,
52 "Change uint8_t here to the SimpleValueType's type");
53 static unsigned constexpr Capacity = std::numeric_limits<uint8_t>::max()+1;
54 using WordType = uint64_t;
Craig Topperd022d252017-09-21 04:55:04 +000055 static unsigned constexpr WordWidth = CHAR_BIT*sizeof(WordType);
Krzysztof Parzyszekaffd2012017-09-19 18:42:34 +000056 static unsigned constexpr NumWords = Capacity/WordWidth;
57 static_assert(NumWords*WordWidth == Capacity,
58 "Capacity should be a multiple of WordWidth");
59
60 LLVM_ATTRIBUTE_ALWAYS_INLINE
61 MachineValueTypeSet() {
62 clear();
63 }
64
65 LLVM_ATTRIBUTE_ALWAYS_INLINE
66 unsigned size() const {
67 unsigned Count = 0;
68 for (WordType W : Words)
69 Count += countPopulation(W);
70 return Count;
71 }
72 LLVM_ATTRIBUTE_ALWAYS_INLINE
73 void clear() {
74 std::memset(Words.data(), 0, NumWords*sizeof(WordType));
75 }
76 LLVM_ATTRIBUTE_ALWAYS_INLINE
77 bool empty() const {
78 for (WordType W : Words)
79 if (W != 0)
80 return false;
81 return true;
82 }
83 LLVM_ATTRIBUTE_ALWAYS_INLINE
84 unsigned count(MVT T) const {
85 return (Words[T.SimpleTy / WordWidth] >> (T.SimpleTy % WordWidth)) & 1;
86 }
87 std::pair<MachineValueTypeSet&,bool> insert(MVT T) {
88 bool V = count(T.SimpleTy);
89 Words[T.SimpleTy / WordWidth] |= WordType(1) << (T.SimpleTy % WordWidth);
90 return {*this, V};
91 }
92 MachineValueTypeSet &insert(const MachineValueTypeSet &S) {
93 for (unsigned i = 0; i != NumWords; ++i)
94 Words[i] |= S.Words[i];
95 return *this;
96 }
97 LLVM_ATTRIBUTE_ALWAYS_INLINE
98 void erase(MVT T) {
99 Words[T.SimpleTy / WordWidth] &= ~(WordType(1) << (T.SimpleTy % WordWidth));
100 }
101
102 struct const_iterator {
103 // Some implementations of the C++ library require these traits to be
104 // defined.
105 using iterator_category = std::forward_iterator_tag;
106 using value_type = MVT;
107 using difference_type = ptrdiff_t;
108 using pointer = const MVT*;
109 using reference = const MVT&;
110
111 LLVM_ATTRIBUTE_ALWAYS_INLINE
112 MVT operator*() const {
113 assert(Pos != Capacity);
114 return MVT::SimpleValueType(Pos);
115 }
116 LLVM_ATTRIBUTE_ALWAYS_INLINE
117 const_iterator(const MachineValueTypeSet *S, bool End) : Set(S) {
118 Pos = End ? Capacity : find_from_pos(0);
119 }
120 LLVM_ATTRIBUTE_ALWAYS_INLINE
121 const_iterator &operator++() {
122 assert(Pos != Capacity);
123 Pos = find_from_pos(Pos+1);
124 return *this;
125 }
126
127 LLVM_ATTRIBUTE_ALWAYS_INLINE
128 bool operator==(const const_iterator &It) const {
129 return Set == It.Set && Pos == It.Pos;
130 }
131 LLVM_ATTRIBUTE_ALWAYS_INLINE
132 bool operator!=(const const_iterator &It) const {
133 return !operator==(It);
134 }
135
136 private:
137 unsigned find_from_pos(unsigned P) const {
138 unsigned SkipWords = P / WordWidth;
139 unsigned SkipBits = P % WordWidth;
140 unsigned Count = SkipWords * WordWidth;
141
142 // If P is in the middle of a word, process it manually here, because
143 // the trailing bits need to be masked off to use findFirstSet.
144 if (SkipBits != 0) {
145 WordType W = Set->Words[SkipWords];
146 W &= maskLeadingOnes<WordType>(WordWidth-SkipBits);
147 if (W != 0)
148 return Count + findFirstSet(W);
149 Count += WordWidth;
150 SkipWords++;
151 }
152
153 for (unsigned i = SkipWords; i != NumWords; ++i) {
154 WordType W = Set->Words[i];
155 if (W != 0)
156 return Count + findFirstSet(W);
157 Count += WordWidth;
158 }
159 return Capacity;
160 }
161
162 const MachineValueTypeSet *Set;
163 unsigned Pos;
164 };
165
166 LLVM_ATTRIBUTE_ALWAYS_INLINE
167 const_iterator begin() const { return const_iterator(this, false); }
168 LLVM_ATTRIBUTE_ALWAYS_INLINE
169 const_iterator end() const { return const_iterator(this, true); }
170
171 LLVM_ATTRIBUTE_ALWAYS_INLINE
172 bool operator==(const MachineValueTypeSet &S) const {
173 return Words == S.Words;
174 }
175 LLVM_ATTRIBUTE_ALWAYS_INLINE
176 bool operator!=(const MachineValueTypeSet &S) const {
177 return !operator==(S);
178 }
179
180private:
181 friend struct const_iterator;
182 std::array<WordType,NumWords> Words;
183};
184
185struct TypeSetByHwMode : public InfoByHwMode<MachineValueTypeSet> {
186 using SetType = MachineValueTypeSet;
Jim Grosbach50986b52010-12-24 05:06:32 +0000187
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000188 TypeSetByHwMode() = default;
189 TypeSetByHwMode(const TypeSetByHwMode &VTS) = default;
190 TypeSetByHwMode(MVT::SimpleValueType VT)
191 : TypeSetByHwMode(ValueTypeByHwMode(VT)) {}
192 TypeSetByHwMode(ValueTypeByHwMode VT)
193 : TypeSetByHwMode(ArrayRef<ValueTypeByHwMode>(&VT, 1)) {}
194 TypeSetByHwMode(ArrayRef<ValueTypeByHwMode> VTList);
Jim Grosbach50986b52010-12-24 05:06:32 +0000195
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000196 SetType &getOrCreate(unsigned Mode) {
197 if (hasMode(Mode))
198 return get(Mode);
199 return Map.insert({Mode,SetType()}).first->second;
200 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000201
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000202 bool isValueTypeByHwMode(bool AllowEmpty) const;
203 ValueTypeByHwMode getValueTypeByHwMode() const;
Krzysztof Parzyszekaffd2012017-09-19 18:42:34 +0000204
205 LLVM_ATTRIBUTE_ALWAYS_INLINE
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000206 bool isMachineValueType() const {
207 return isDefaultOnly() && Map.begin()->second.size() == 1;
208 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000209
Krzysztof Parzyszekaffd2012017-09-19 18:42:34 +0000210 LLVM_ATTRIBUTE_ALWAYS_INLINE
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000211 MVT getMachineValueType() const {
212 assert(isMachineValueType());
213 return *Map.begin()->second.begin();
214 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000215
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000216 bool isPossible() const;
Krzysztof Parzyszekaffd2012017-09-19 18:42:34 +0000217
218 LLVM_ATTRIBUTE_ALWAYS_INLINE
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000219 bool isDefaultOnly() const {
Krzysztof Parzyszekaffd2012017-09-19 18:42:34 +0000220 return Map.size() == 1 && Map.begin()->first == DefaultMode;
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000221 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000222
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000223 bool insert(const ValueTypeByHwMode &VVT);
224 bool constrain(const TypeSetByHwMode &VTS);
225 template <typename Predicate> bool constrain(Predicate P);
Zachary Turner249dc142017-09-20 18:01:40 +0000226 template <typename Predicate>
227 bool assign_if(const TypeSetByHwMode &VTS, Predicate P);
Jim Grosbach50986b52010-12-24 05:06:32 +0000228
Zachary Turner249dc142017-09-20 18:01:40 +0000229 void writeToStream(raw_ostream &OS) const;
230 static void writeToStream(const SetType &S, raw_ostream &OS);
Jim Grosbach50986b52010-12-24 05:06:32 +0000231
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000232 bool operator==(const TypeSetByHwMode &VTS) const;
233 bool operator!=(const TypeSetByHwMode &VTS) const { return !(*this == VTS); }
Jim Grosbach50986b52010-12-24 05:06:32 +0000234
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000235 void dump() const;
236 void validate() const;
Craig Topper74169dc2014-01-28 04:49:01 +0000237
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000238private:
239 /// Intersect two sets. Return true if anything has changed.
240 bool intersect(SetType &Out, const SetType &In);
241};
Jim Grosbach50986b52010-12-24 05:06:32 +0000242
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000243struct TypeInfer {
244 TypeInfer(TreePattern &T) : TP(T), ForceMode(0) {}
Jim Grosbach50986b52010-12-24 05:06:32 +0000245
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000246 bool isConcrete(const TypeSetByHwMode &VTS, bool AllowEmpty) const {
247 return VTS.isValueTypeByHwMode(AllowEmpty);
248 }
249 ValueTypeByHwMode getConcrete(const TypeSetByHwMode &VTS,
250 bool AllowEmpty) const {
251 assert(VTS.isValueTypeByHwMode(AllowEmpty));
252 return VTS.getValueTypeByHwMode();
253 }
Duncan Sands13237ac2008-06-06 12:08:01 +0000254
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000255 /// The protocol in the following functions (Merge*, force*, Enforce*,
256 /// expand*) is to return "true" if a change has been made, "false"
257 /// otherwise.
Chris Lattner8cab0212008-01-05 22:25:12 +0000258
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000259 bool MergeInTypeInfo(TypeSetByHwMode &Out, const TypeSetByHwMode &In);
260 bool MergeInTypeInfo(TypeSetByHwMode &Out, MVT::SimpleValueType InVT) {
261 return MergeInTypeInfo(Out, TypeSetByHwMode(InVT));
262 }
263 bool MergeInTypeInfo(TypeSetByHwMode &Out, ValueTypeByHwMode InVT) {
264 return MergeInTypeInfo(Out, TypeSetByHwMode(InVT));
265 }
Bob Wilsonf7e587f2009-08-12 22:30:59 +0000266
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000267 /// Reduce the set \p Out to have at most one element for each mode.
268 bool forceArbitrary(TypeSetByHwMode &Out);
Chris Lattnercabe0372010-03-15 06:00:16 +0000269
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000270 /// The following four functions ensure that upon return the set \p Out
271 /// will only contain types of the specified kind: integer, floating-point,
272 /// scalar, or vector.
273 /// If \p Out is empty, all legal types of the specified kind will be added
274 /// to it. Otherwise, all types that are not of the specified kind will be
275 /// removed from \p Out.
276 bool EnforceInteger(TypeSetByHwMode &Out);
277 bool EnforceFloatingPoint(TypeSetByHwMode &Out);
278 bool EnforceScalar(TypeSetByHwMode &Out);
279 bool EnforceVector(TypeSetByHwMode &Out);
Chris Lattnercabe0372010-03-15 06:00:16 +0000280
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000281 /// If \p Out is empty, fill it with all legal types. Otherwise, leave it
282 /// unchanged.
283 bool EnforceAny(TypeSetByHwMode &Out);
284 /// Make sure that for each type in \p Small, there exists a larger type
285 /// in \p Big.
286 bool EnforceSmallerThan(TypeSetByHwMode &Small, TypeSetByHwMode &Big);
287 /// 1. Ensure that for each type T in \p Vec, T is a vector type, and that
288 /// for each type U in \p Elem, U is a scalar type.
289 /// 2. Ensure that for each (scalar) type U in \p Elem, there exists a
290 /// (vector) type T in \p Vec, such that U is the element type of T.
291 bool EnforceVectorEltTypeIs(TypeSetByHwMode &Vec, TypeSetByHwMode &Elem);
292 bool EnforceVectorEltTypeIs(TypeSetByHwMode &Vec,
293 const ValueTypeByHwMode &VVT);
294 /// Ensure that for each type T in \p Sub, T is a vector type, and there
295 /// exists a type U in \p Vec such that U is a vector type with the same
296 /// element type as T and at least as many elements as T.
297 bool EnforceVectorSubVectorTypeIs(TypeSetByHwMode &Vec,
298 TypeSetByHwMode &Sub);
299 /// 1. Ensure that \p V has a scalar type iff \p W has a scalar type.
300 /// 2. Ensure that for each vector type T in \p V, there exists a vector
301 /// type U in \p W, such that T and U have the same number of elements.
302 /// 3. Ensure that for each vector type U in \p W, there exists a vector
303 /// type T in \p V, such that T and U have the same number of elements
304 /// (reverse of 2).
305 bool EnforceSameNumElts(TypeSetByHwMode &V, TypeSetByHwMode &W);
306 /// 1. Ensure that for each type T in \p A, there exists a type U in \p B,
307 /// such that T and U have equal size in bits.
308 /// 2. Ensure that for each type U in \p B, there exists a type T in \p A
309 /// such that T and U have equal size in bits (reverse of 1).
310 bool EnforceSameSize(TypeSetByHwMode &A, TypeSetByHwMode &B);
Chris Lattnercabe0372010-03-15 06:00:16 +0000311
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000312 /// For each overloaded type (i.e. of form *Any), replace it with the
313 /// corresponding subset of legal, specific types.
314 void expandOverloads(TypeSetByHwMode &VTS);
315 void expandOverloads(TypeSetByHwMode::SetType &Out,
316 const TypeSetByHwMode::SetType &Legal);
Jim Grosbach50986b52010-12-24 05:06:32 +0000317
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000318 struct ValidateOnExit {
319 ValidateOnExit(TypeSetByHwMode &T) : VTS(T) {}
320 ~ValidateOnExit() { VTS.validate(); }
321 TypeSetByHwMode &VTS;
Chris Lattnercabe0372010-03-15 06:00:16 +0000322 };
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000323
324 TreePattern &TP;
325 unsigned ForceMode; // Mode to use when set.
326 bool CodeGen = false; // Set during generation of matcher code.
327
328private:
329 TypeSetByHwMode getLegalTypes();
Krzysztof Parzyszekaffd2012017-09-19 18:42:34 +0000330
331 /// Cached legal types.
332 bool LegalTypesCached = false;
333 TypeSetByHwMode::SetType LegalCache = {};
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000334};
Chris Lattner8cab0212008-01-05 22:25:12 +0000335
Scott Michel94420742008-03-05 17:49:05 +0000336/// Set type used to track multiply used variables in patterns
Zachary Turner249dc142017-09-20 18:01:40 +0000337typedef StringSet<> MultipleUseVarSet;
Scott Michel94420742008-03-05 17:49:05 +0000338
Chris Lattner8cab0212008-01-05 22:25:12 +0000339/// SDTypeConstraint - This is a discriminated union of constraints,
340/// corresponding to the SDTypeConstraint tablegen class in Target.td.
341struct SDTypeConstraint {
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000342 SDTypeConstraint(Record *R, const CodeGenHwModes &CGH);
Jim Grosbach50986b52010-12-24 05:06:32 +0000343
Chris Lattner8cab0212008-01-05 22:25:12 +0000344 unsigned OperandNo; // The operand # this constraint applies to.
Jim Grosbach50986b52010-12-24 05:06:32 +0000345 enum {
346 SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisVec, SDTCisSameAs,
David Greene127fd1d2011-01-24 20:53:18 +0000347 SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisEltOfVec,
Craig Topper9a44b3f2015-11-26 07:02:18 +0000348 SDTCisSubVecOfVec, SDTCVecEltisVT, SDTCisSameNumEltsAs, SDTCisSameSizeAs
Chris Lattner8cab0212008-01-05 22:25:12 +0000349 } ConstraintType;
Jim Grosbach50986b52010-12-24 05:06:32 +0000350
Chris Lattner8cab0212008-01-05 22:25:12 +0000351 union { // The discriminated union.
352 struct {
Chris Lattner8cab0212008-01-05 22:25:12 +0000353 unsigned OtherOperandNum;
354 } SDTCisSameAs_Info;
355 struct {
356 unsigned OtherOperandNum;
357 } SDTCisVTSmallerThanOp_Info;
358 struct {
359 unsigned BigOperandNum;
360 } SDTCisOpSmallerThanOp_Info;
361 struct {
362 unsigned OtherOperandNum;
Nate Begeman17bedbc2008-02-09 01:37:05 +0000363 } SDTCisEltOfVec_Info;
David Greene127fd1d2011-01-24 20:53:18 +0000364 struct {
365 unsigned OtherOperandNum;
366 } SDTCisSubVecOfVec_Info;
Craig Topper0be34582015-03-05 07:11:34 +0000367 struct {
Craig Topper0be34582015-03-05 07:11:34 +0000368 unsigned OtherOperandNum;
369 } SDTCisSameNumEltsAs_Info;
Craig Topper9a44b3f2015-11-26 07:02:18 +0000370 struct {
371 unsigned OtherOperandNum;
372 } SDTCisSameSizeAs_Info;
Chris Lattner8cab0212008-01-05 22:25:12 +0000373 } x;
374
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000375 // The VT for SDTCisVT and SDTCVecEltisVT.
376 // Must not be in the union because it has a non-trivial destructor.
377 ValueTypeByHwMode VVT;
378
Chris Lattner8cab0212008-01-05 22:25:12 +0000379 /// ApplyTypeConstraint - Given a node in a pattern, apply this type
380 /// constraint to the nodes operands. This returns true if it makes a
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000381 /// change, false otherwise. If a type contradiction is found, an error
382 /// is flagged.
Chris Lattner8cab0212008-01-05 22:25:12 +0000383 bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
384 TreePattern &TP) const;
Chris Lattner8cab0212008-01-05 22:25:12 +0000385};
386
387/// SDNodeInfo - One of these records is created for each SDNode instance in
388/// the target .td file. This represents the various dag nodes we will be
389/// processing.
390class SDNodeInfo {
391 Record *Def;
Craig Topperbcd3c372017-05-31 21:12:46 +0000392 StringRef EnumName;
393 StringRef SDClassName;
Chris Lattner8cab0212008-01-05 22:25:12 +0000394 unsigned Properties;
395 unsigned NumResults;
396 int NumOperands;
397 std::vector<SDTypeConstraint> TypeConstraints;
398public:
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000399 // Parse the specified record.
400 SDNodeInfo(Record *R, const CodeGenHwModes &CGH);
Jim Grosbach50986b52010-12-24 05:06:32 +0000401
Chris Lattner8cab0212008-01-05 22:25:12 +0000402 unsigned getNumResults() const { return NumResults; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000403
Chris Lattner135091b2010-03-28 08:48:47 +0000404 /// getNumOperands - This is the number of operands required or -1 if
405 /// variadic.
Chris Lattner8cab0212008-01-05 22:25:12 +0000406 int getNumOperands() const { return NumOperands; }
407 Record *getRecord() const { return Def; }
Craig Topperbcd3c372017-05-31 21:12:46 +0000408 StringRef getEnumName() const { return EnumName; }
409 StringRef getSDClassName() const { return SDClassName; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000410
Chris Lattner8cab0212008-01-05 22:25:12 +0000411 const std::vector<SDTypeConstraint> &getTypeConstraints() const {
412 return TypeConstraints;
413 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000414
Chris Lattner99e53b32010-02-28 00:22:30 +0000415 /// getKnownType - If the type constraints on this node imply a fixed type
416 /// (e.g. all stores return void, etc), then return it as an
Chris Lattnerda5b4ad2010-03-19 01:14:27 +0000417 /// MVT::SimpleValueType. Otherwise, return MVT::Other.
Chris Lattner6c2d1782010-03-24 00:41:19 +0000418 MVT::SimpleValueType getKnownType(unsigned ResNo) const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000419
Chris Lattner8cab0212008-01-05 22:25:12 +0000420 /// hasProperty - Return true if this node has the specified property.
421 ///
422 bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
423
424 /// ApplyTypeConstraints - Given a node in a pattern, apply the type
425 /// constraints for this node to the operands of the node. This returns
426 /// true if it makes a change, false otherwise. If a type contradiction is
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000427 /// found, an error is flagged.
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000428 bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const;
Chris Lattner8cab0212008-01-05 22:25:12 +0000429};
Chris Lattner514e2922011-04-17 21:38:24 +0000430
431/// TreePredicateFn - This is an abstraction that represents the predicates on
432/// a PatFrag node. This is a simple one-word wrapper around a pointer to
433/// provide nice accessors.
434class TreePredicateFn {
435 /// PatFragRec - This is the TreePattern for the PatFrag that we
436 /// originally came from.
437 TreePattern *PatFragRec;
438public:
439 /// TreePredicateFn constructor. Here 'N' is a subclass of PatFrag.
Chris Lattner2ff8c1a2011-04-17 22:05:17 +0000440 TreePredicateFn(TreePattern *N);
Chris Lattner514e2922011-04-17 21:38:24 +0000441
442
443 TreePattern *getOrigPatFragRecord() const { return PatFragRec; }
444
445 /// isAlwaysTrue - Return true if this is a noop predicate.
446 bool isAlwaysTrue() const;
447
Chris Lattner07add492011-04-18 06:22:33 +0000448 bool isImmediatePattern() const { return !getImmCode().empty(); }
449
450 /// getImmediatePredicateCode - Return the code that evaluates this pattern if
451 /// this is an immediate predicate. It is an error to call this on a
452 /// non-immediate pattern.
453 std::string getImmediatePredicateCode() const {
454 std::string Result = getImmCode();
455 assert(!Result.empty() && "Isn't an immediate pattern!");
456 return Result;
457 }
458
Chris Lattner514e2922011-04-17 21:38:24 +0000459
460 bool operator==(const TreePredicateFn &RHS) const {
461 return PatFragRec == RHS.PatFragRec;
462 }
463
464 bool operator!=(const TreePredicateFn &RHS) const { return !(*this == RHS); }
465
466 /// Return the name to use in the generated code to reference this, this is
467 /// "Predicate_foo" if from a pattern fragment "foo".
468 std::string getFnName() const;
469
470 /// getCodeToRunOnSDNode - Return the code for the function body that
471 /// evaluates this predicate. The argument is expected to be in "Node",
472 /// not N. This handles casting and conversion to a concrete node type as
473 /// appropriate.
474 std::string getCodeToRunOnSDNode() const;
475
476private:
477 std::string getPredCode() const;
Chris Lattner2ff8c1a2011-04-17 22:05:17 +0000478 std::string getImmCode() const;
Chris Lattner514e2922011-04-17 21:38:24 +0000479};
David Blaikiecf195302014-11-17 22:55:41 +0000480
Chris Lattner8cab0212008-01-05 22:25:12 +0000481
482/// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped
483/// patterns), and as such should be ref counted. We currently just leak all
484/// TreePatternNode objects!
485class TreePatternNode {
Chris Lattnerf1447252010-03-19 21:37:09 +0000486 /// The type of each node result. Before and during type inference, each
487 /// result may be a set of possible types. After (successful) type inference,
488 /// each is a single concrete type.
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000489 std::vector<TypeSetByHwMode> Types;
Jim Grosbach50986b52010-12-24 05:06:32 +0000490
Chris Lattner8cab0212008-01-05 22:25:12 +0000491 /// Operator - The Record for the operator if this is an interior node (not
492 /// a leaf).
493 Record *Operator;
Jim Grosbach50986b52010-12-24 05:06:32 +0000494
Chris Lattner8cab0212008-01-05 22:25:12 +0000495 /// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf.
496 ///
David Greeneaf8ee2c2011-07-29 22:43:06 +0000497 Init *Val;
Jim Grosbach50986b52010-12-24 05:06:32 +0000498
Chris Lattner8cab0212008-01-05 22:25:12 +0000499 /// Name - The name given to this node with the :$foo notation.
500 ///
501 std::string Name;
Jim Grosbach50986b52010-12-24 05:06:32 +0000502
Dan Gohman6e979022008-10-15 06:17:21 +0000503 /// PredicateFns - The predicate functions to execute on this node to check
504 /// for a match. If this list is empty, no predicate is involved.
Chris Lattner514e2922011-04-17 21:38:24 +0000505 std::vector<TreePredicateFn> PredicateFns;
Jim Grosbach50986b52010-12-24 05:06:32 +0000506
Chris Lattner8cab0212008-01-05 22:25:12 +0000507 /// TransformFn - The transformation function to execute on this node before
508 /// it can be substituted into the resulting instruction on a pattern match.
509 Record *TransformFn;
Jim Grosbach50986b52010-12-24 05:06:32 +0000510
Chris Lattner8cab0212008-01-05 22:25:12 +0000511 std::vector<TreePatternNode*> Children;
512public:
Chris Lattnerf1447252010-03-19 21:37:09 +0000513 TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch,
Jim Grosbach50986b52010-12-24 05:06:32 +0000514 unsigned NumResults)
Craig Topperada08572014-04-16 04:21:27 +0000515 : Operator(Op), Val(nullptr), TransformFn(nullptr), Children(Ch) {
Chris Lattnerf1447252010-03-19 21:37:09 +0000516 Types.resize(NumResults);
517 }
David Greeneaf8ee2c2011-07-29 22:43:06 +0000518 TreePatternNode(Init *val, unsigned NumResults) // leaf ctor
Craig Topperada08572014-04-16 04:21:27 +0000519 : Operator(nullptr), Val(val), TransformFn(nullptr) {
Chris Lattnerf1447252010-03-19 21:37:09 +0000520 Types.resize(NumResults);
Chris Lattner8cab0212008-01-05 22:25:12 +0000521 }
522 ~TreePatternNode();
Jim Grosbach50986b52010-12-24 05:06:32 +0000523
Jakob Stoklund Olesenb5b91102013-03-23 18:08:44 +0000524 bool hasName() const { return !Name.empty(); }
Chris Lattner8cab0212008-01-05 22:25:12 +0000525 const std::string &getName() const { return Name; }
Chris Lattneradf7ecf2010-03-28 06:50:34 +0000526 void setName(StringRef N) { Name.assign(N.begin(), N.end()); }
Jim Grosbach50986b52010-12-24 05:06:32 +0000527
Craig Topperada08572014-04-16 04:21:27 +0000528 bool isLeaf() const { return Val != nullptr; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000529
Chris Lattnercabe0372010-03-15 06:00:16 +0000530 // Type accessors.
Chris Lattnerf1447252010-03-19 21:37:09 +0000531 unsigned getNumTypes() const { return Types.size(); }
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000532 ValueTypeByHwMode getType(unsigned ResNo) const {
533 return Types[ResNo].getValueTypeByHwMode();
Chris Lattnerf1447252010-03-19 21:37:09 +0000534 }
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000535 const std::vector<TypeSetByHwMode> &getExtTypes() const { return Types; }
536 const TypeSetByHwMode &getExtType(unsigned ResNo) const {
537 return Types[ResNo];
538 }
539 TypeSetByHwMode &getExtType(unsigned ResNo) { return Types[ResNo]; }
540 void setType(unsigned ResNo, const TypeSetByHwMode &T) { Types[ResNo] = T; }
541 MVT::SimpleValueType getSimpleType(unsigned ResNo) const {
542 return Types[ResNo].getMachineValueType().SimpleTy;
543 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000544
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000545 bool hasConcreteType(unsigned ResNo) const {
546 return Types[ResNo].isValueTypeByHwMode(false);
Chris Lattnerf1447252010-03-19 21:37:09 +0000547 }
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000548 bool isTypeCompletelyUnknown(unsigned ResNo, TreePattern &TP) const {
549 return Types[ResNo].empty();
Chris Lattnerf1447252010-03-19 21:37:09 +0000550 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000551
David Greeneaf8ee2c2011-07-29 22:43:06 +0000552 Init *getLeafValue() const { assert(isLeaf()); return Val; }
Chris Lattner8cab0212008-01-05 22:25:12 +0000553 Record *getOperator() const { assert(!isLeaf()); return Operator; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000554
Chris Lattner8cab0212008-01-05 22:25:12 +0000555 unsigned getNumChildren() const { return Children.size(); }
556 TreePatternNode *getChild(unsigned N) const { return Children[N]; }
557 void setChild(unsigned i, TreePatternNode *N) {
558 Children[i] = N;
559 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000560
Chris Lattneraa7d3e02010-02-16 06:10:58 +0000561 /// hasChild - Return true if N is any of our children.
562 bool hasChild(const TreePatternNode *N) const {
563 for (unsigned i = 0, e = Children.size(); i != e; ++i)
564 if (Children[i] == N) return true;
565 return false;
566 }
Chris Lattner89c65662008-01-06 05:36:50 +0000567
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000568 bool hasProperTypeByHwMode() const;
569 bool hasPossibleType() const;
570 bool setDefaultMode(unsigned Mode);
571
Chris Lattner514e2922011-04-17 21:38:24 +0000572 bool hasAnyPredicate() const { return !PredicateFns.empty(); }
573
574 const std::vector<TreePredicateFn> &getPredicateFns() const {
575 return PredicateFns;
576 }
Dan Gohman6e979022008-10-15 06:17:21 +0000577 void clearPredicateFns() { PredicateFns.clear(); }
Chris Lattner514e2922011-04-17 21:38:24 +0000578 void setPredicateFns(const std::vector<TreePredicateFn> &Fns) {
Dan Gohman6e979022008-10-15 06:17:21 +0000579 assert(PredicateFns.empty() && "Overwriting non-empty predicate list!");
580 PredicateFns = Fns;
581 }
Chris Lattner514e2922011-04-17 21:38:24 +0000582 void addPredicateFn(const TreePredicateFn &Fn) {
583 assert(!Fn.isAlwaysTrue() && "Empty predicate string!");
David Majnemer0d955d02016-08-11 22:21:41 +0000584 if (!is_contained(PredicateFns, Fn))
Dan Gohman6e979022008-10-15 06:17:21 +0000585 PredicateFns.push_back(Fn);
586 }
Chris Lattner8cab0212008-01-05 22:25:12 +0000587
588 Record *getTransformFn() const { return TransformFn; }
589 void setTransformFn(Record *Fn) { TransformFn = Fn; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000590
Chris Lattner89c65662008-01-06 05:36:50 +0000591 /// getIntrinsicInfo - If this node corresponds to an intrinsic, return the
592 /// CodeGenIntrinsic information for it, otherwise return a null pointer.
593 const CodeGenIntrinsic *getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const;
Evan Cheng49bad4c2008-06-16 20:29:38 +0000594
Chris Lattner53c39ba2010-02-14 22:22:58 +0000595 /// getComplexPatternInfo - If this node corresponds to a ComplexPattern,
596 /// return the ComplexPattern information, otherwise return null.
597 const ComplexPattern *
598 getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const;
599
Tim Northoverc807a172014-05-20 11:52:46 +0000600 /// Returns the number of MachineInstr operands that would be produced by this
601 /// node if it mapped directly to an output Instruction's
602 /// operand. ComplexPattern specifies this explicitly; MIOperandInfo gives it
603 /// for Operands; otherwise 1.
604 unsigned getNumMIResults(const CodeGenDAGPatterns &CGP) const;
605
Chris Lattner53c39ba2010-02-14 22:22:58 +0000606 /// NodeHasProperty - Return true if this node has the specified property.
Chris Lattner450d5042010-02-14 22:33:49 +0000607 bool NodeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000608
Chris Lattner53c39ba2010-02-14 22:22:58 +0000609 /// TreeHasProperty - Return true if any node in this tree has the specified
610 /// property.
Chris Lattner450d5042010-02-14 22:33:49 +0000611 bool TreeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000612
Evan Cheng49bad4c2008-06-16 20:29:38 +0000613 /// isCommutativeIntrinsic - Return true if the node is an intrinsic which is
614 /// marked isCommutative.
615 bool isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000616
Daniel Dunbar38a22bf2009-07-03 00:10:29 +0000617 void print(raw_ostream &OS) const;
Chris Lattner8cab0212008-01-05 22:25:12 +0000618 void dump() const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000619
Chris Lattner8cab0212008-01-05 22:25:12 +0000620public: // Higher level manipulation routines.
621
622 /// clone - Return a new copy of this tree.
623 ///
624 TreePatternNode *clone() const;
Chris Lattner53c39ba2010-02-14 22:22:58 +0000625
626 /// RemoveAllTypes - Recursively strip all the types of this tree.
627 void RemoveAllTypes();
Jim Grosbach50986b52010-12-24 05:06:32 +0000628
Chris Lattner8cab0212008-01-05 22:25:12 +0000629 /// isIsomorphicTo - Return true if this node is recursively isomorphic to
630 /// the specified node. For this comparison, all of the state of the node
631 /// is considered, except for the assigned name. Nodes with differing names
632 /// that are otherwise identical are considered isomorphic.
Scott Michel94420742008-03-05 17:49:05 +0000633 bool isIsomorphicTo(const TreePatternNode *N,
634 const MultipleUseVarSet &DepVars) const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000635
Chris Lattner8cab0212008-01-05 22:25:12 +0000636 /// SubstituteFormalArguments - Replace the formal arguments in this tree
637 /// with actual values specified by ArgMap.
638 void SubstituteFormalArguments(std::map<std::string,
639 TreePatternNode*> &ArgMap);
640
641 /// InlinePatternFragments - If this pattern refers to any pattern
642 /// fragments, inline them into place, giving us a pattern without any
643 /// PatFrag references.
644 TreePatternNode *InlinePatternFragments(TreePattern &TP);
Jim Grosbach50986b52010-12-24 05:06:32 +0000645
Bob Wilson1b97f3f2009-01-05 17:23:09 +0000646 /// ApplyTypeConstraints - Apply all of the type constraints relevant to
Chris Lattner8cab0212008-01-05 22:25:12 +0000647 /// this node and its children in the tree. This returns true if it makes a
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000648 /// change, false otherwise. If a type contradiction is found, flag an error.
Chris Lattner8cab0212008-01-05 22:25:12 +0000649 bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
Jim Grosbach50986b52010-12-24 05:06:32 +0000650
Chris Lattner8cab0212008-01-05 22:25:12 +0000651 /// UpdateNodeType - Set the node type of N to VT if VT contains
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000652 /// information. If N already contains a conflicting type, then flag an
653 /// error. This returns true if any information was updated.
Chris Lattner8cab0212008-01-05 22:25:12 +0000654 ///
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000655 bool UpdateNodeType(unsigned ResNo, const TypeSetByHwMode &InTy,
656 TreePattern &TP);
Chris Lattnerf1447252010-03-19 21:37:09 +0000657 bool UpdateNodeType(unsigned ResNo, MVT::SimpleValueType InTy,
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000658 TreePattern &TP);
659 bool UpdateNodeType(unsigned ResNo, ValueTypeByHwMode InTy,
660 TreePattern &TP);
Jim Grosbach50986b52010-12-24 05:06:32 +0000661
Jakob Stoklund Olesen57a86502013-03-18 04:08:07 +0000662 // Update node type with types inferred from an instruction operand or result
663 // def from the ins/outs lists.
664 // Return true if the type changed.
665 bool UpdateNodeTypeFromInst(unsigned ResNo, Record *Operand, TreePattern &TP);
666
Chris Lattner8cab0212008-01-05 22:25:12 +0000667 /// ContainsUnresolvedType - Return true if this tree contains any
668 /// unresolved types.
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000669 bool ContainsUnresolvedType(TreePattern &TP) const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000670
Chris Lattner8cab0212008-01-05 22:25:12 +0000671 /// canPatternMatch - If it is impossible for this pattern to match on this
672 /// target, fill in Reason and return false. Otherwise, return true.
Dan Gohmanfc4ad7de2008-04-03 00:02:49 +0000673 bool canPatternMatch(std::string &Reason, const CodeGenDAGPatterns &CDP);
Chris Lattner8cab0212008-01-05 22:25:12 +0000674};
675
Chris Lattnerdd2ec582010-02-14 21:10:33 +0000676inline raw_ostream &operator<<(raw_ostream &OS, const TreePatternNode &TPN) {
677 TPN.print(OS);
678 return OS;
679}
Jim Grosbach50986b52010-12-24 05:06:32 +0000680
Chris Lattner8cab0212008-01-05 22:25:12 +0000681
682/// TreePattern - Represent a pattern, used for instructions, pattern
683/// fragments, etc.
684///
685class TreePattern {
686 /// Trees - The list of pattern trees which corresponds to this pattern.
687 /// Note that PatFrag's only have a single tree.
688 ///
David Blaikiecf195302014-11-17 22:55:41 +0000689 std::vector<TreePatternNode*> Trees;
Jim Grosbach50986b52010-12-24 05:06:32 +0000690
Chris Lattnercabe0372010-03-15 06:00:16 +0000691 /// NamedNodes - This is all of the nodes that have names in the trees in this
692 /// pattern.
693 StringMap<SmallVector<TreePatternNode*,1> > NamedNodes;
Jim Grosbach50986b52010-12-24 05:06:32 +0000694
Chris Lattner8cab0212008-01-05 22:25:12 +0000695 /// TheRecord - The actual TableGen record corresponding to this pattern.
696 ///
697 Record *TheRecord;
Jim Grosbach50986b52010-12-24 05:06:32 +0000698
Chris Lattner8cab0212008-01-05 22:25:12 +0000699 /// Args - This is a list of all of the arguments to this pattern (for
700 /// PatFrag patterns), which are the 'node' markers in this pattern.
701 std::vector<std::string> Args;
Jim Grosbach50986b52010-12-24 05:06:32 +0000702
Chris Lattner8cab0212008-01-05 22:25:12 +0000703 /// CDP - the top-level object coordinating this madness.
704 ///
Chris Lattnerab3242f2008-01-06 01:10:31 +0000705 CodeGenDAGPatterns &CDP;
Chris Lattner8cab0212008-01-05 22:25:12 +0000706
707 /// isInputPattern - True if this is an input pattern, something to match.
708 /// False if this is an output pattern, something to emit.
709 bool isInputPattern;
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000710
711 /// hasError - True if the currently processed nodes have unresolvable types
712 /// or other non-fatal errors
713 bool HasError;
Tim Northoverc807a172014-05-20 11:52:46 +0000714
715 /// It's important that the usage of operands in ComplexPatterns is
716 /// consistent: each named operand can be defined by at most one
717 /// ComplexPattern. This records the ComplexPattern instance and the operand
718 /// number for each operand encountered in a ComplexPattern to aid in that
719 /// check.
720 StringMap<std::pair<Record *, unsigned>> ComplexPatternOperands;
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000721
722 TypeInfer Infer;
723
Chris Lattner8cab0212008-01-05 22:25:12 +0000724public:
Jim Grosbach50986b52010-12-24 05:06:32 +0000725
Chris Lattner8cab0212008-01-05 22:25:12 +0000726 /// TreePattern constructor - Parse the specified DagInits into the
727 /// current record.
David Greeneaf8ee2c2011-07-29 22:43:06 +0000728 TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
Chris Lattnerab3242f2008-01-06 01:10:31 +0000729 CodeGenDAGPatterns &ise);
David Greeneaf8ee2c2011-07-29 22:43:06 +0000730 TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
Chris Lattnerab3242f2008-01-06 01:10:31 +0000731 CodeGenDAGPatterns &ise);
David Blaikiecf195302014-11-17 22:55:41 +0000732 TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
733 CodeGenDAGPatterns &ise);
Jim Grosbach50986b52010-12-24 05:06:32 +0000734
Chris Lattner8cab0212008-01-05 22:25:12 +0000735 /// getTrees - Return the tree patterns which corresponds to this pattern.
736 ///
David Blaikiecf195302014-11-17 22:55:41 +0000737 const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
Chris Lattner8cab0212008-01-05 22:25:12 +0000738 unsigned getNumTrees() const { return Trees.size(); }
David Blaikiecf195302014-11-17 22:55:41 +0000739 TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
740 TreePatternNode *getOnlyTree() const {
Chris Lattner8cab0212008-01-05 22:25:12 +0000741 assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
742 return Trees[0];
743 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000744
Chris Lattnercabe0372010-03-15 06:00:16 +0000745 const StringMap<SmallVector<TreePatternNode*,1> > &getNamedNodesMap() {
746 if (NamedNodes.empty())
747 ComputeNamedNodes();
748 return NamedNodes;
749 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000750
Chris Lattner8cab0212008-01-05 22:25:12 +0000751 /// getRecord - Return the actual TableGen record corresponding to this
752 /// pattern.
753 ///
754 Record *getRecord() const { return TheRecord; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000755
Chris Lattner8cab0212008-01-05 22:25:12 +0000756 unsigned getNumArgs() const { return Args.size(); }
757 const std::string &getArgName(unsigned i) const {
758 assert(i < Args.size() && "Argument reference out of range!");
759 return Args[i];
760 }
761 std::vector<std::string> &getArgList() { return Args; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000762
Chris Lattnerab3242f2008-01-06 01:10:31 +0000763 CodeGenDAGPatterns &getDAGPatterns() const { return CDP; }
Chris Lattner8cab0212008-01-05 22:25:12 +0000764
765 /// InlinePatternFragments - If this pattern refers to any pattern
766 /// fragments, inline them into place, giving us a pattern without any
767 /// PatFrag references.
768 void InlinePatternFragments() {
769 for (unsigned i = 0, e = Trees.size(); i != e; ++i)
David Blaikiecf195302014-11-17 22:55:41 +0000770 Trees[i] = Trees[i]->InlinePatternFragments(*this);
Chris Lattner8cab0212008-01-05 22:25:12 +0000771 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000772
Chris Lattner8cab0212008-01-05 22:25:12 +0000773 /// InferAllTypes - Infer/propagate as many types throughout the expression
Jim Grosbach975c1cb2009-03-26 16:17:51 +0000774 /// patterns as possible. Return true if all types are inferred, false
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000775 /// otherwise. Bail out if a type contradiction is found.
Chris Lattnercabe0372010-03-15 06:00:16 +0000776 bool InferAllTypes(const StringMap<SmallVector<TreePatternNode*,1> >
Craig Topperada08572014-04-16 04:21:27 +0000777 *NamedTypes=nullptr);
Jim Grosbach50986b52010-12-24 05:06:32 +0000778
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000779 /// error - If this is the first error in the current resolution step,
780 /// print it and set the error flag. Otherwise, continue silently.
Matt Arsenaultea8df3a2014-11-11 23:48:11 +0000781 void error(const Twine &Msg);
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000782 bool hasError() const {
783 return HasError;
784 }
785 void resetError() {
786 HasError = false;
787 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000788
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000789 TypeInfer &getInfer() { return Infer; }
790
Daniel Dunbar38a22bf2009-07-03 00:10:29 +0000791 void print(raw_ostream &OS) const;
Chris Lattner8cab0212008-01-05 22:25:12 +0000792 void dump() const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000793
Chris Lattner8cab0212008-01-05 22:25:12 +0000794private:
David Blaikiecf195302014-11-17 22:55:41 +0000795 TreePatternNode *ParseTreePattern(Init *DI, StringRef OpName);
Chris Lattnercabe0372010-03-15 06:00:16 +0000796 void ComputeNamedNodes();
797 void ComputeNamedNodes(TreePatternNode *N);
Chris Lattner8cab0212008-01-05 22:25:12 +0000798};
799
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000800
801inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
802 const TypeSetByHwMode &InTy,
803 TreePattern &TP) {
804 TypeSetByHwMode VTS(InTy);
805 TP.getInfer().expandOverloads(VTS);
806 return TP.getInfer().MergeInTypeInfo(Types[ResNo], VTS);
807}
808
809inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
810 MVT::SimpleValueType InTy,
811 TreePattern &TP) {
812 TypeSetByHwMode VTS(InTy);
813 TP.getInfer().expandOverloads(VTS);
814 return TP.getInfer().MergeInTypeInfo(Types[ResNo], VTS);
815}
816
817inline bool TreePatternNode::UpdateNodeType(unsigned ResNo,
818 ValueTypeByHwMode InTy,
819 TreePattern &TP) {
820 TypeSetByHwMode VTS(InTy);
821 TP.getInfer().expandOverloads(VTS);
822 return TP.getInfer().MergeInTypeInfo(Types[ResNo], VTS);
823}
824
825
Tom Stellardb7246a72012-09-06 14:15:52 +0000826/// DAGDefaultOperand - One of these is created for each OperandWithDefaultOps
827/// that has a set ExecuteAlways / DefaultOps field.
Chris Lattner8cab0212008-01-05 22:25:12 +0000828struct DAGDefaultOperand {
829 std::vector<TreePatternNode*> DefaultOps;
830};
831
832class DAGInstruction {
833 TreePattern *Pattern;
834 std::vector<Record*> Results;
835 std::vector<Record*> Operands;
836 std::vector<Record*> ImpResults;
David Blaikiecf195302014-11-17 22:55:41 +0000837 TreePatternNode *ResultPattern;
Chris Lattner8cab0212008-01-05 22:25:12 +0000838public:
839 DAGInstruction(TreePattern *TP,
840 const std::vector<Record*> &results,
841 const std::vector<Record*> &operands,
Chris Lattner9dc68d32010-04-20 06:28:43 +0000842 const std::vector<Record*> &impresults)
Jim Grosbach50986b52010-12-24 05:06:32 +0000843 : Pattern(TP), Results(results), Operands(operands),
David Blaikiecf195302014-11-17 22:55:41 +0000844 ImpResults(impresults), ResultPattern(nullptr) {}
Chris Lattner8cab0212008-01-05 22:25:12 +0000845
Joerg Sonnenberger635debe2012-10-25 20:33:17 +0000846 TreePattern *getPattern() const { return Pattern; }
Chris Lattner8cab0212008-01-05 22:25:12 +0000847 unsigned getNumResults() const { return Results.size(); }
848 unsigned getNumOperands() const { return Operands.size(); }
849 unsigned getNumImpResults() const { return ImpResults.size(); }
Chris Lattner8cab0212008-01-05 22:25:12 +0000850 const std::vector<Record*>& getImpResults() const { return ImpResults; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000851
David Blaikiecf195302014-11-17 22:55:41 +0000852 void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000853
Chris Lattner8cab0212008-01-05 22:25:12 +0000854 Record *getResult(unsigned RN) const {
855 assert(RN < Results.size());
856 return Results[RN];
857 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000858
Chris Lattner8cab0212008-01-05 22:25:12 +0000859 Record *getOperand(unsigned ON) const {
860 assert(ON < Operands.size());
861 return Operands[ON];
862 }
863
864 Record *getImpResult(unsigned RN) const {
865 assert(RN < ImpResults.size());
866 return ImpResults[RN];
867 }
Jim Grosbach50986b52010-12-24 05:06:32 +0000868
David Blaikiecf195302014-11-17 22:55:41 +0000869 TreePatternNode *getResultPattern() const { return ResultPattern; }
Chris Lattner8cab0212008-01-05 22:25:12 +0000870};
Jim Grosbach50986b52010-12-24 05:06:32 +0000871
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000872/// This class represents a condition that has to be satisfied for a pattern
873/// to be tried. It is a generalization of a class "Pattern" from Target.td:
874/// in addition to the Target.td's predicates, this class can also represent
875/// conditions associated with HW modes. Both types will eventually become
876/// strings containing C++ code to be executed, the difference is in how
877/// these strings are generated.
878class Predicate {
879public:
880 Predicate(Record *R, bool C = true) : Def(R), IfCond(C), IsHwMode(false) {
881 assert(R->isSubClassOf("Predicate") &&
882 "Predicate objects should only be created for records derived"
883 "from Predicate class");
884 }
885 Predicate(StringRef FS, bool C = true) : Def(nullptr), Features(FS.str()),
886 IfCond(C), IsHwMode(true) {}
887
888 /// Return a string which contains the C++ condition code that will serve
889 /// as a predicate during instruction selection.
890 std::string getCondString() const {
891 // The string will excute in a subclass of SelectionDAGISel.
892 // Cast to std::string explicitly to avoid ambiguity with StringRef.
893 std::string C = IsHwMode
894 ? std::string("MF->getSubtarget().checkFeatures(\"" + Features + "\")")
895 : std::string(Def->getValueAsString("CondString"));
896 return IfCond ? C : "!("+C+')';
897 }
898 bool operator==(const Predicate &P) const {
899 return IfCond == P.IfCond && IsHwMode == P.IsHwMode && Def == P.Def;
900 }
901 bool operator<(const Predicate &P) const {
902 if (IsHwMode != P.IsHwMode)
903 return IsHwMode < P.IsHwMode;
904 assert(!Def == !P.Def && "Inconsistency between Def and IsHwMode");
905 if (IfCond != P.IfCond)
906 return IfCond < P.IfCond;
907 if (Def)
908 return LessRecord()(Def, P.Def);
909 return Features < P.Features;
910 }
911 Record *Def; ///< Predicate definition from .td file, null for
912 ///< HW modes.
913 std::string Features; ///< Feature string for HW mode.
914 bool IfCond; ///< The boolean value that the condition has to
915 ///< evaluate to for this predicate to be true.
916 bool IsHwMode; ///< Does this predicate correspond to a HW mode?
917};
918
Chris Lattnerab3242f2008-01-06 01:10:31 +0000919/// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns
Chris Lattner8cab0212008-01-05 22:25:12 +0000920/// processed to produce isel.
Chris Lattner7ed81692010-02-18 06:47:49 +0000921class PatternToMatch {
922public:
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000923 PatternToMatch(Record *srcrecord, const std::vector<Predicate> &preds,
924 TreePatternNode *src, TreePatternNode *dst,
925 const std::vector<Record*> &dstregs,
926 int complexity, unsigned uid, unsigned setmode = 0)
927 : SrcRecord(srcrecord), SrcPattern(src), DstPattern(dst),
928 Predicates(preds), Dstregs(std::move(dstregs)),
929 AddedComplexity(complexity), ID(uid), ForceMode(setmode) {}
930
931 PatternToMatch(Record *srcrecord, std::vector<Predicate> &&preds,
932 TreePatternNode *src, TreePatternNode *dst,
933 std::vector<Record*> &&dstregs,
934 int complexity, unsigned uid, unsigned setmode = 0)
935 : SrcRecord(srcrecord), SrcPattern(src), DstPattern(dst),
936 Predicates(preds), Dstregs(std::move(dstregs)),
937 AddedComplexity(complexity), ID(uid), ForceMode(setmode) {}
Chris Lattner8cab0212008-01-05 22:25:12 +0000938
Jim Grosbachfb116ae2010-12-07 23:05:49 +0000939 Record *SrcRecord; // Originating Record for the pattern.
Chris Lattner8cab0212008-01-05 22:25:12 +0000940 TreePatternNode *SrcPattern; // Source pattern to match.
941 TreePatternNode *DstPattern; // Resulting pattern.
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000942 std::vector<Predicate> Predicates; // Top level predicate conditions
943 // to match.
Chris Lattner8cab0212008-01-05 22:25:12 +0000944 std::vector<Record*> Dstregs; // Physical register defs being matched.
Tom Stellard6655dd62014-08-01 00:32:36 +0000945 int AddedComplexity; // Add to matching pattern complexity.
Chris Lattnerd39f75b2010-03-01 22:09:11 +0000946 unsigned ID; // Unique ID for the record.
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000947 unsigned ForceMode; // Force this mode in type inference when set.
Chris Lattner8cab0212008-01-05 22:25:12 +0000948
Jim Grosbachfb116ae2010-12-07 23:05:49 +0000949 Record *getSrcRecord() const { return SrcRecord; }
Chris Lattner8cab0212008-01-05 22:25:12 +0000950 TreePatternNode *getSrcPattern() const { return SrcPattern; }
951 TreePatternNode *getDstPattern() const { return DstPattern; }
952 const std::vector<Record*> &getDstRegs() const { return Dstregs; }
Tom Stellard6655dd62014-08-01 00:32:36 +0000953 int getAddedComplexity() const { return AddedComplexity; }
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000954 const std::vector<Predicate> &getPredicates() const { return Predicates; }
Dan Gohman49e19e92008-08-22 00:20:26 +0000955
956 std::string getPredicateCheck() const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000957
Chris Lattner05925fe2010-03-29 01:40:38 +0000958 /// Compute the complexity metric for the input pattern. This roughly
959 /// corresponds to the number of nodes that are covered.
Tom Stellard6655dd62014-08-01 00:32:36 +0000960 int getPatternComplexity(const CodeGenDAGPatterns &CGP) const;
Chris Lattner8cab0212008-01-05 22:25:12 +0000961};
962
Chris Lattnerab3242f2008-01-06 01:10:31 +0000963class CodeGenDAGPatterns {
Chris Lattner8cab0212008-01-05 22:25:12 +0000964 RecordKeeper &Records;
965 CodeGenTarget Target;
Justin Bogner92a8c612016-07-15 16:31:37 +0000966 CodeGenIntrinsicTable Intrinsics;
967 CodeGenIntrinsicTable TgtIntrinsics;
Jim Grosbach50986b52010-12-24 05:06:32 +0000968
Sean Silvaa4e2c5f2012-09-19 01:47:00 +0000969 std::map<Record*, SDNodeInfo, LessRecordByID> SDNodes;
Krzysztof Parzyszek426bf362017-09-12 15:31:26 +0000970 std::map<Record*, std::pair<Record*, std::string>, LessRecordByID>
971 SDNodeXForms;
Sean Silvaa4e2c5f2012-09-19 01:47:00 +0000972 std::map<Record*, ComplexPattern, LessRecordByID> ComplexPatterns;
David Blaikie3c6ca232014-11-13 21:40:02 +0000973 std::map<Record *, std::unique_ptr<TreePattern>, LessRecordByID>
974 PatternFragments;
Sean Silvaa4e2c5f2012-09-19 01:47:00 +0000975 std::map<Record*, DAGDefaultOperand, LessRecordByID> DefaultOperands;
976 std::map<Record*, DAGInstruction, LessRecordByID> Instructions;
Jim Grosbach50986b52010-12-24 05:06:32 +0000977
Chris Lattner8cab0212008-01-05 22:25:12 +0000978 // Specific SDNode definitions:
979 Record *intrinsic_void_sdnode;
980 Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode;
Jim Grosbach50986b52010-12-24 05:06:32 +0000981
Chris Lattner8cab0212008-01-05 22:25:12 +0000982 /// PatternsToMatch - All of the things we are matching on the DAG. The first
983 /// value is the pattern to match, the second pattern is the result to
984 /// emit.
985 std::vector<PatternToMatch> PatternsToMatch;
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000986
987 TypeSetByHwMode LegalVTS;
988
Chris Lattner8cab0212008-01-05 22:25:12 +0000989public:
Jim Grosbach50986b52010-12-24 05:06:32 +0000990 CodeGenDAGPatterns(RecordKeeper &R);
Jim Grosbach50986b52010-12-24 05:06:32 +0000991
Dan Gohmanfc4ad7de2008-04-03 00:02:49 +0000992 CodeGenTarget &getTargetInfo() { return Target; }
Chris Lattner8cab0212008-01-05 22:25:12 +0000993 const CodeGenTarget &getTargetInfo() const { return Target; }
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +0000994 const TypeSetByHwMode &getLegalTypes() const { return LegalVTS; }
Jim Grosbach50986b52010-12-24 05:06:32 +0000995
Chris Lattner8cab0212008-01-05 22:25:12 +0000996 Record *getSDNodeNamed(const std::string &Name) const;
Jim Grosbach50986b52010-12-24 05:06:32 +0000997
Chris Lattner8cab0212008-01-05 22:25:12 +0000998 const SDNodeInfo &getSDNodeInfo(Record *R) const {
999 assert(SDNodes.count(R) && "Unknown node!");
1000 return SDNodes.find(R)->second;
1001 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001002
Chris Lattnercc43e792008-01-05 22:54:53 +00001003 // Node transformation lookups.
1004 typedef std::pair<Record*, std::string> NodeXForm;
1005 const NodeXForm &getSDNodeTransform(Record *R) const {
Chris Lattner8cab0212008-01-05 22:25:12 +00001006 assert(SDNodeXForms.count(R) && "Invalid transform!");
1007 return SDNodeXForms.find(R)->second;
1008 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001009
Sean Silvaa4e2c5f2012-09-19 01:47:00 +00001010 typedef std::map<Record*, NodeXForm, LessRecordByID>::const_iterator
Benjamin Kramerc2dbd5d2009-08-23 10:39:21 +00001011 nx_iterator;
Chris Lattnercc43e792008-01-05 22:54:53 +00001012 nx_iterator nx_begin() const { return SDNodeXForms.begin(); }
1013 nx_iterator nx_end() const { return SDNodeXForms.end(); }
1014
Jim Grosbach50986b52010-12-24 05:06:32 +00001015
Chris Lattner8cab0212008-01-05 22:25:12 +00001016 const ComplexPattern &getComplexPattern(Record *R) const {
1017 assert(ComplexPatterns.count(R) && "Unknown addressing mode!");
1018 return ComplexPatterns.find(R)->second;
1019 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001020
Chris Lattner8cab0212008-01-05 22:25:12 +00001021 const CodeGenIntrinsic &getIntrinsic(Record *R) const {
1022 for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
1023 if (Intrinsics[i].TheDef == R) return Intrinsics[i];
Dale Johannesenb842d522009-02-05 01:49:45 +00001024 for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
1025 if (TgtIntrinsics[i].TheDef == R) return TgtIntrinsics[i];
Craig Topperc4965bc2012-02-05 07:21:30 +00001026 llvm_unreachable("Unknown intrinsic!");
Chris Lattner8cab0212008-01-05 22:25:12 +00001027 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001028
Chris Lattner8cab0212008-01-05 22:25:12 +00001029 const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const {
Dale Johannesenb842d522009-02-05 01:49:45 +00001030 if (IID-1 < Intrinsics.size())
1031 return Intrinsics[IID-1];
1032 if (IID-Intrinsics.size()-1 < TgtIntrinsics.size())
1033 return TgtIntrinsics[IID-Intrinsics.size()-1];
Craig Topperc4965bc2012-02-05 07:21:30 +00001034 llvm_unreachable("Bad intrinsic ID!");
Chris Lattner8cab0212008-01-05 22:25:12 +00001035 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001036
Chris Lattner8cab0212008-01-05 22:25:12 +00001037 unsigned getIntrinsicID(Record *R) const {
1038 for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
1039 if (Intrinsics[i].TheDef == R) return i;
Dale Johannesenb842d522009-02-05 01:49:45 +00001040 for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
1041 if (TgtIntrinsics[i].TheDef == R) return i + Intrinsics.size();
Craig Topperc4965bc2012-02-05 07:21:30 +00001042 llvm_unreachable("Unknown intrinsic!");
Chris Lattner8cab0212008-01-05 22:25:12 +00001043 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001044
Chris Lattner7ed81692010-02-18 06:47:49 +00001045 const DAGDefaultOperand &getDefaultOperand(Record *R) const {
Chris Lattner8cab0212008-01-05 22:25:12 +00001046 assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!");
1047 return DefaultOperands.find(R)->second;
1048 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001049
Chris Lattner8cab0212008-01-05 22:25:12 +00001050 // Pattern Fragment information.
1051 TreePattern *getPatternFragment(Record *R) const {
1052 assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
David Blaikie3c6ca232014-11-13 21:40:02 +00001053 return PatternFragments.find(R)->second.get();
Chris Lattner8cab0212008-01-05 22:25:12 +00001054 }
Chris Lattnerf1447252010-03-19 21:37:09 +00001055 TreePattern *getPatternFragmentIfRead(Record *R) const {
David Blaikie3c6ca232014-11-13 21:40:02 +00001056 if (!PatternFragments.count(R))
1057 return nullptr;
1058 return PatternFragments.find(R)->second.get();
Chris Lattnerf1447252010-03-19 21:37:09 +00001059 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001060
David Blaikiefcacc742014-11-13 21:56:57 +00001061 typedef std::map<Record *, std::unique_ptr<TreePattern>,
1062 LessRecordByID>::const_iterator pf_iterator;
Chris Lattner8cab0212008-01-05 22:25:12 +00001063 pf_iterator pf_begin() const { return PatternFragments.begin(); }
1064 pf_iterator pf_end() const { return PatternFragments.end(); }
Ahmed Bougacha36f70352016-12-21 23:26:20 +00001065 iterator_range<pf_iterator> ptfs() const { return PatternFragments; }
Chris Lattner8cab0212008-01-05 22:25:12 +00001066
1067 // Patterns to match information.
Chris Lattner9abe77b2008-01-05 22:30:17 +00001068 typedef std::vector<PatternToMatch>::const_iterator ptm_iterator;
1069 ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
1070 ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
Ahmed Bougacha36f70352016-12-21 23:26:20 +00001071 iterator_range<ptm_iterator> ptms() const { return PatternsToMatch; }
Jim Grosbach50986b52010-12-24 05:06:32 +00001072
Ahmed Bougacha14107512013-10-28 18:07:21 +00001073 /// Parse the Pattern for an instruction, and insert the result in DAGInsts.
1074 typedef std::map<Record*, DAGInstruction, LessRecordByID> DAGInstMap;
1075 const DAGInstruction &parseInstructionPattern(
1076 CodeGenInstruction &CGI, ListInit *Pattern,
1077 DAGInstMap &DAGInsts);
Jim Grosbach50986b52010-12-24 05:06:32 +00001078
Chris Lattner8cab0212008-01-05 22:25:12 +00001079 const DAGInstruction &getInstruction(Record *R) const {
1080 assert(Instructions.count(R) && "Unknown instruction!");
1081 return Instructions.find(R)->second;
1082 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001083
Chris Lattner8cab0212008-01-05 22:25:12 +00001084 Record *get_intrinsic_void_sdnode() const {
1085 return intrinsic_void_sdnode;
1086 }
1087 Record *get_intrinsic_w_chain_sdnode() const {
1088 return intrinsic_w_chain_sdnode;
1089 }
1090 Record *get_intrinsic_wo_chain_sdnode() const {
1091 return intrinsic_wo_chain_sdnode;
1092 }
Jim Grosbach50986b52010-12-24 05:06:32 +00001093
Jakob Stoklund Olesene4197252009-10-15 18:50:03 +00001094 bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); }
1095
Chris Lattner8cab0212008-01-05 22:25:12 +00001096private:
1097 void ParseNodeInfo();
Chris Lattnercc43e792008-01-05 22:54:53 +00001098 void ParseNodeTransforms();
Chris Lattner8cab0212008-01-05 22:25:12 +00001099 void ParseComplexPatterns();
Hal Finkel2756dc12014-02-28 00:26:56 +00001100 void ParsePatternFragments(bool OutFrags = false);
Chris Lattner8cab0212008-01-05 22:25:12 +00001101 void ParseDefaultOperands();
1102 void ParseInstructions();
1103 void ParsePatterns();
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +00001104 void ExpandHwModeBasedTypes();
Dan Gohmanfc4ad7de2008-04-03 00:02:49 +00001105 void InferInstructionFlags();
Chris Lattner8cab0212008-01-05 22:25:12 +00001106 void GenerateVariants();
Jakob Stoklund Olesena9d322a2012-08-28 03:26:49 +00001107 void VerifyInstructionFlags();
Jim Grosbach50986b52010-12-24 05:06:32 +00001108
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +00001109 std::vector<Predicate> makePredList(ListInit *L);
1110
Craig Topper18e6b572017-06-25 17:33:49 +00001111 void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM);
Chris Lattner8cab0212008-01-05 22:25:12 +00001112 void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
1113 std::map<std::string,
1114 TreePatternNode*> &InstInputs,
1115 std::map<std::string,
1116 TreePatternNode*> &InstResults,
Chris Lattner8cab0212008-01-05 22:25:12 +00001117 std::vector<Record*> &InstImpResults);
1118};
Krzysztof Parzyszek779d98e2017-09-14 16:56:21 +00001119
1120
1121inline bool SDNodeInfo::ApplyTypeConstraints(TreePatternNode *N,
1122 TreePattern &TP) const {
1123 bool MadeChange = false;
1124 for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
1125 MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP);
1126 return MadeChange;
1127 }
Chris Lattner8cab0212008-01-05 22:25:12 +00001128} // end namespace llvm
1129
1130#endif