Chris Lattner | ab3242f | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 1 | //===- CodeGenDAGPatterns.h - Read DAG patterns from .td file ---*- C++ -*-===// |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 2 | // |
| 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 Lattner | ab3242f | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 10 | // This file declares the CodeGenDAGPatterns class, which is used to read and |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 11 | // represent the patterns present in a .td file for instructions. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 15 | #ifndef LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H |
| 16 | #define LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 17 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 18 | #include "CodeGenHwModes.h" |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 19 | #include "CodeGenIntrinsics.h" |
Chandler Carruth | 91d19d8 | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 20 | #include "CodeGenTarget.h" |
Chris Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
| 22 | #include "llvm/ADT/StringMap.h" |
Zachary Turner | 249dc14 | 2017-09-20 18:01:40 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringSet.h" |
Craig Topper | c4965bc | 2012-02-05 07:21:30 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ErrorHandling.h" |
Krzysztof Parzyszek | affd201 | 2017-09-19 18:42:34 +0000 | [diff] [blame] | 25 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 1802b17 | 2010-03-19 01:07:44 +0000 | [diff] [blame] | 26 | #include <algorithm> |
Krzysztof Parzyszek | affd201 | 2017-09-19 18:42:34 +0000 | [diff] [blame] | 27 | #include <array> |
Chris Lattner | 1802b17 | 2010-03-19 01:07:44 +0000 | [diff] [blame] | 28 | #include <map> |
Chandler Carruth | 91d19d8 | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 29 | #include <set> |
| 30 | #include <vector> |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 31 | |
| 32 | namespace llvm { |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 33 | |
Krzysztof Parzyszek | affd201 | 2017-09-19 18:42:34 +0000 | [diff] [blame] | 34 | class Record; |
| 35 | class Init; |
| 36 | class ListInit; |
| 37 | class DagInit; |
| 38 | class SDNodeInfo; |
| 39 | class TreePattern; |
| 40 | class TreePatternNode; |
| 41 | class CodeGenDAGPatterns; |
| 42 | class 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. |
| 49 | struct 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 Topper | d022d25 | 2017-09-21 04:55:04 +0000 | [diff] [blame^] | 55 | static unsigned constexpr WordWidth = CHAR_BIT*sizeof(WordType); |
Krzysztof Parzyszek | affd201 | 2017-09-19 18:42:34 +0000 | [diff] [blame] | 56 | 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 | |
| 180 | private: |
| 181 | friend struct const_iterator; |
| 182 | std::array<WordType,NumWords> Words; |
| 183 | }; |
| 184 | |
| 185 | struct TypeSetByHwMode : public InfoByHwMode<MachineValueTypeSet> { |
| 186 | using SetType = MachineValueTypeSet; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 187 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 188 | 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 195 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 196 | SetType &getOrCreate(unsigned Mode) { |
| 197 | if (hasMode(Mode)) |
| 198 | return get(Mode); |
| 199 | return Map.insert({Mode,SetType()}).first->second; |
| 200 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 201 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 202 | bool isValueTypeByHwMode(bool AllowEmpty) const; |
| 203 | ValueTypeByHwMode getValueTypeByHwMode() const; |
Krzysztof Parzyszek | affd201 | 2017-09-19 18:42:34 +0000 | [diff] [blame] | 204 | |
| 205 | LLVM_ATTRIBUTE_ALWAYS_INLINE |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 206 | bool isMachineValueType() const { |
| 207 | return isDefaultOnly() && Map.begin()->second.size() == 1; |
| 208 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 209 | |
Krzysztof Parzyszek | affd201 | 2017-09-19 18:42:34 +0000 | [diff] [blame] | 210 | LLVM_ATTRIBUTE_ALWAYS_INLINE |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 211 | MVT getMachineValueType() const { |
| 212 | assert(isMachineValueType()); |
| 213 | return *Map.begin()->second.begin(); |
| 214 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 215 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 216 | bool isPossible() const; |
Krzysztof Parzyszek | affd201 | 2017-09-19 18:42:34 +0000 | [diff] [blame] | 217 | |
| 218 | LLVM_ATTRIBUTE_ALWAYS_INLINE |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 219 | bool isDefaultOnly() const { |
Krzysztof Parzyszek | affd201 | 2017-09-19 18:42:34 +0000 | [diff] [blame] | 220 | return Map.size() == 1 && Map.begin()->first == DefaultMode; |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 221 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 222 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 223 | bool insert(const ValueTypeByHwMode &VVT); |
| 224 | bool constrain(const TypeSetByHwMode &VTS); |
| 225 | template <typename Predicate> bool constrain(Predicate P); |
Zachary Turner | 249dc14 | 2017-09-20 18:01:40 +0000 | [diff] [blame] | 226 | template <typename Predicate> |
| 227 | bool assign_if(const TypeSetByHwMode &VTS, Predicate P); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 228 | |
Zachary Turner | 249dc14 | 2017-09-20 18:01:40 +0000 | [diff] [blame] | 229 | void writeToStream(raw_ostream &OS) const; |
| 230 | static void writeToStream(const SetType &S, raw_ostream &OS); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 231 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 232 | bool operator==(const TypeSetByHwMode &VTS) const; |
| 233 | bool operator!=(const TypeSetByHwMode &VTS) const { return !(*this == VTS); } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 234 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 235 | void dump() const; |
| 236 | void validate() const; |
Craig Topper | 74169dc | 2014-01-28 04:49:01 +0000 | [diff] [blame] | 237 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 238 | private: |
| 239 | /// Intersect two sets. Return true if anything has changed. |
| 240 | bool intersect(SetType &Out, const SetType &In); |
| 241 | }; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 242 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 243 | struct TypeInfer { |
| 244 | TypeInfer(TreePattern &T) : TP(T), ForceMode(0) {} |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 245 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 246 | 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 Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 254 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 255 | /// 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 Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 258 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 259 | 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 Wilson | f7e587f | 2009-08-12 22:30:59 +0000 | [diff] [blame] | 266 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 267 | /// Reduce the set \p Out to have at most one element for each mode. |
| 268 | bool forceArbitrary(TypeSetByHwMode &Out); |
Chris Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 269 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 270 | /// 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 Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 280 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 281 | /// 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 Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 311 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 312 | /// 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 317 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 318 | struct ValidateOnExit { |
| 319 | ValidateOnExit(TypeSetByHwMode &T) : VTS(T) {} |
| 320 | ~ValidateOnExit() { VTS.validate(); } |
| 321 | TypeSetByHwMode &VTS; |
Chris Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 322 | }; |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 323 | |
| 324 | TreePattern &TP; |
| 325 | unsigned ForceMode; // Mode to use when set. |
| 326 | bool CodeGen = false; // Set during generation of matcher code. |
| 327 | |
| 328 | private: |
| 329 | TypeSetByHwMode getLegalTypes(); |
Krzysztof Parzyszek | affd201 | 2017-09-19 18:42:34 +0000 | [diff] [blame] | 330 | |
| 331 | /// Cached legal types. |
| 332 | bool LegalTypesCached = false; |
| 333 | TypeSetByHwMode::SetType LegalCache = {}; |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 334 | }; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 335 | |
Scott Michel | 9442074 | 2008-03-05 17:49:05 +0000 | [diff] [blame] | 336 | /// Set type used to track multiply used variables in patterns |
Zachary Turner | 249dc14 | 2017-09-20 18:01:40 +0000 | [diff] [blame] | 337 | typedef StringSet<> MultipleUseVarSet; |
Scott Michel | 9442074 | 2008-03-05 17:49:05 +0000 | [diff] [blame] | 338 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 339 | /// SDTypeConstraint - This is a discriminated union of constraints, |
| 340 | /// corresponding to the SDTypeConstraint tablegen class in Target.td. |
| 341 | struct SDTypeConstraint { |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 342 | SDTypeConstraint(Record *R, const CodeGenHwModes &CGH); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 343 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 344 | unsigned OperandNo; // The operand # this constraint applies to. |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 345 | enum { |
| 346 | SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisVec, SDTCisSameAs, |
David Greene | 127fd1d | 2011-01-24 20:53:18 +0000 | [diff] [blame] | 347 | SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisEltOfVec, |
Craig Topper | 9a44b3f | 2015-11-26 07:02:18 +0000 | [diff] [blame] | 348 | SDTCisSubVecOfVec, SDTCVecEltisVT, SDTCisSameNumEltsAs, SDTCisSameSizeAs |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 349 | } ConstraintType; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 350 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 351 | union { // The discriminated union. |
| 352 | struct { |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 353 | 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 Begeman | 17bedbc | 2008-02-09 01:37:05 +0000 | [diff] [blame] | 363 | } SDTCisEltOfVec_Info; |
David Greene | 127fd1d | 2011-01-24 20:53:18 +0000 | [diff] [blame] | 364 | struct { |
| 365 | unsigned OtherOperandNum; |
| 366 | } SDTCisSubVecOfVec_Info; |
Craig Topper | 0be3458 | 2015-03-05 07:11:34 +0000 | [diff] [blame] | 367 | struct { |
Craig Topper | 0be3458 | 2015-03-05 07:11:34 +0000 | [diff] [blame] | 368 | unsigned OtherOperandNum; |
| 369 | } SDTCisSameNumEltsAs_Info; |
Craig Topper | 9a44b3f | 2015-11-26 07:02:18 +0000 | [diff] [blame] | 370 | struct { |
| 371 | unsigned OtherOperandNum; |
| 372 | } SDTCisSameSizeAs_Info; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 373 | } x; |
| 374 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 375 | // 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 Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 379 | /// ApplyTypeConstraint - Given a node in a pattern, apply this type |
| 380 | /// constraint to the nodes operands. This returns true if it makes a |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 381 | /// change, false otherwise. If a type contradiction is found, an error |
| 382 | /// is flagged. |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 383 | bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo, |
| 384 | TreePattern &TP) const; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 385 | }; |
| 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. |
| 390 | class SDNodeInfo { |
| 391 | Record *Def; |
Craig Topper | bcd3c37 | 2017-05-31 21:12:46 +0000 | [diff] [blame] | 392 | StringRef EnumName; |
| 393 | StringRef SDClassName; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 394 | unsigned Properties; |
| 395 | unsigned NumResults; |
| 396 | int NumOperands; |
| 397 | std::vector<SDTypeConstraint> TypeConstraints; |
| 398 | public: |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 399 | // Parse the specified record. |
| 400 | SDNodeInfo(Record *R, const CodeGenHwModes &CGH); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 401 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 402 | unsigned getNumResults() const { return NumResults; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 403 | |
Chris Lattner | 135091b | 2010-03-28 08:48:47 +0000 | [diff] [blame] | 404 | /// getNumOperands - This is the number of operands required or -1 if |
| 405 | /// variadic. |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 406 | int getNumOperands() const { return NumOperands; } |
| 407 | Record *getRecord() const { return Def; } |
Craig Topper | bcd3c37 | 2017-05-31 21:12:46 +0000 | [diff] [blame] | 408 | StringRef getEnumName() const { return EnumName; } |
| 409 | StringRef getSDClassName() const { return SDClassName; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 410 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 411 | const std::vector<SDTypeConstraint> &getTypeConstraints() const { |
| 412 | return TypeConstraints; |
| 413 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 414 | |
Chris Lattner | 99e53b3 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 415 | /// 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 Lattner | da5b4ad | 2010-03-19 01:14:27 +0000 | [diff] [blame] | 417 | /// MVT::SimpleValueType. Otherwise, return MVT::Other. |
Chris Lattner | 6c2d178 | 2010-03-24 00:41:19 +0000 | [diff] [blame] | 418 | MVT::SimpleValueType getKnownType(unsigned ResNo) const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 419 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 420 | /// 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 Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 427 | /// found, an error is flagged. |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 428 | bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 429 | }; |
Chris Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 430 | |
| 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. |
| 434 | class TreePredicateFn { |
| 435 | /// PatFragRec - This is the TreePattern for the PatFrag that we |
| 436 | /// originally came from. |
| 437 | TreePattern *PatFragRec; |
| 438 | public: |
| 439 | /// TreePredicateFn constructor. Here 'N' is a subclass of PatFrag. |
Chris Lattner | 2ff8c1a | 2011-04-17 22:05:17 +0000 | [diff] [blame] | 440 | TreePredicateFn(TreePattern *N); |
Chris Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 441 | |
| 442 | |
| 443 | TreePattern *getOrigPatFragRecord() const { return PatFragRec; } |
| 444 | |
| 445 | /// isAlwaysTrue - Return true if this is a noop predicate. |
| 446 | bool isAlwaysTrue() const; |
| 447 | |
Chris Lattner | 07add49 | 2011-04-18 06:22:33 +0000 | [diff] [blame] | 448 | 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 Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 459 | |
| 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 | |
| 476 | private: |
| 477 | std::string getPredCode() const; |
Chris Lattner | 2ff8c1a | 2011-04-17 22:05:17 +0000 | [diff] [blame] | 478 | std::string getImmCode() const; |
Chris Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 479 | }; |
David Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 480 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 481 | |
| 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! |
| 485 | class TreePatternNode { |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 486 | /// 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 Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 489 | std::vector<TypeSetByHwMode> Types; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 490 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 491 | /// Operator - The Record for the operator if this is an interior node (not |
| 492 | /// a leaf). |
| 493 | Record *Operator; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 494 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 495 | /// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf. |
| 496 | /// |
David Greene | af8ee2c | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 497 | Init *Val; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 498 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 499 | /// Name - The name given to this node with the :$foo notation. |
| 500 | /// |
| 501 | std::string Name; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 502 | |
Dan Gohman | 6e97902 | 2008-10-15 06:17:21 +0000 | [diff] [blame] | 503 | /// 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 Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 505 | std::vector<TreePredicateFn> PredicateFns; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 506 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 507 | /// 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 510 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 511 | std::vector<TreePatternNode*> Children; |
| 512 | public: |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 513 | TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch, |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 514 | unsigned NumResults) |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 515 | : Operator(Op), Val(nullptr), TransformFn(nullptr), Children(Ch) { |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 516 | Types.resize(NumResults); |
| 517 | } |
David Greene | af8ee2c | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 518 | TreePatternNode(Init *val, unsigned NumResults) // leaf ctor |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 519 | : Operator(nullptr), Val(val), TransformFn(nullptr) { |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 520 | Types.resize(NumResults); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 521 | } |
| 522 | ~TreePatternNode(); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 523 | |
Jakob Stoklund Olesen | b5b9110 | 2013-03-23 18:08:44 +0000 | [diff] [blame] | 524 | bool hasName() const { return !Name.empty(); } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 525 | const std::string &getName() const { return Name; } |
Chris Lattner | adf7ecf | 2010-03-28 06:50:34 +0000 | [diff] [blame] | 526 | void setName(StringRef N) { Name.assign(N.begin(), N.end()); } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 527 | |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 528 | bool isLeaf() const { return Val != nullptr; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 529 | |
Chris Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 530 | // Type accessors. |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 531 | unsigned getNumTypes() const { return Types.size(); } |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 532 | ValueTypeByHwMode getType(unsigned ResNo) const { |
| 533 | return Types[ResNo].getValueTypeByHwMode(); |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 534 | } |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 535 | 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 544 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 545 | bool hasConcreteType(unsigned ResNo) const { |
| 546 | return Types[ResNo].isValueTypeByHwMode(false); |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 547 | } |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 548 | bool isTypeCompletelyUnknown(unsigned ResNo, TreePattern &TP) const { |
| 549 | return Types[ResNo].empty(); |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 550 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 551 | |
David Greene | af8ee2c | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 552 | Init *getLeafValue() const { assert(isLeaf()); return Val; } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 553 | Record *getOperator() const { assert(!isLeaf()); return Operator; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 554 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 555 | 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 560 | |
Chris Lattner | aa7d3e0 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 561 | /// 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 Lattner | 89c6566 | 2008-01-06 05:36:50 +0000 | [diff] [blame] | 567 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 568 | bool hasProperTypeByHwMode() const; |
| 569 | bool hasPossibleType() const; |
| 570 | bool setDefaultMode(unsigned Mode); |
| 571 | |
Chris Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 572 | bool hasAnyPredicate() const { return !PredicateFns.empty(); } |
| 573 | |
| 574 | const std::vector<TreePredicateFn> &getPredicateFns() const { |
| 575 | return PredicateFns; |
| 576 | } |
Dan Gohman | 6e97902 | 2008-10-15 06:17:21 +0000 | [diff] [blame] | 577 | void clearPredicateFns() { PredicateFns.clear(); } |
Chris Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 578 | void setPredicateFns(const std::vector<TreePredicateFn> &Fns) { |
Dan Gohman | 6e97902 | 2008-10-15 06:17:21 +0000 | [diff] [blame] | 579 | assert(PredicateFns.empty() && "Overwriting non-empty predicate list!"); |
| 580 | PredicateFns = Fns; |
| 581 | } |
Chris Lattner | 514e292 | 2011-04-17 21:38:24 +0000 | [diff] [blame] | 582 | void addPredicateFn(const TreePredicateFn &Fn) { |
| 583 | assert(!Fn.isAlwaysTrue() && "Empty predicate string!"); |
David Majnemer | 0d955d0 | 2016-08-11 22:21:41 +0000 | [diff] [blame] | 584 | if (!is_contained(PredicateFns, Fn)) |
Dan Gohman | 6e97902 | 2008-10-15 06:17:21 +0000 | [diff] [blame] | 585 | PredicateFns.push_back(Fn); |
| 586 | } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 587 | |
| 588 | Record *getTransformFn() const { return TransformFn; } |
| 589 | void setTransformFn(Record *Fn) { TransformFn = Fn; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 590 | |
Chris Lattner | 89c6566 | 2008-01-06 05:36:50 +0000 | [diff] [blame] | 591 | /// 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 Cheng | 49bad4c | 2008-06-16 20:29:38 +0000 | [diff] [blame] | 594 | |
Chris Lattner | 53c39ba | 2010-02-14 22:22:58 +0000 | [diff] [blame] | 595 | /// 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 Northover | c807a17 | 2014-05-20 11:52:46 +0000 | [diff] [blame] | 600 | /// 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 Lattner | 53c39ba | 2010-02-14 22:22:58 +0000 | [diff] [blame] | 606 | /// NodeHasProperty - Return true if this node has the specified property. |
Chris Lattner | 450d504 | 2010-02-14 22:33:49 +0000 | [diff] [blame] | 607 | bool NodeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 608 | |
Chris Lattner | 53c39ba | 2010-02-14 22:22:58 +0000 | [diff] [blame] | 609 | /// TreeHasProperty - Return true if any node in this tree has the specified |
| 610 | /// property. |
Chris Lattner | 450d504 | 2010-02-14 22:33:49 +0000 | [diff] [blame] | 611 | bool TreeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 612 | |
Evan Cheng | 49bad4c | 2008-06-16 20:29:38 +0000 | [diff] [blame] | 613 | /// isCommutativeIntrinsic - Return true if the node is an intrinsic which is |
| 614 | /// marked isCommutative. |
| 615 | bool isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 616 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 617 | void print(raw_ostream &OS) const; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 618 | void dump() const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 619 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 620 | public: // Higher level manipulation routines. |
| 621 | |
| 622 | /// clone - Return a new copy of this tree. |
| 623 | /// |
| 624 | TreePatternNode *clone() const; |
Chris Lattner | 53c39ba | 2010-02-14 22:22:58 +0000 | [diff] [blame] | 625 | |
| 626 | /// RemoveAllTypes - Recursively strip all the types of this tree. |
| 627 | void RemoveAllTypes(); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 628 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 629 | /// 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 Michel | 9442074 | 2008-03-05 17:49:05 +0000 | [diff] [blame] | 633 | bool isIsomorphicTo(const TreePatternNode *N, |
| 634 | const MultipleUseVarSet &DepVars) const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 635 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 636 | /// 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 645 | |
Bob Wilson | 1b97f3f | 2009-01-05 17:23:09 +0000 | [diff] [blame] | 646 | /// ApplyTypeConstraints - Apply all of the type constraints relevant to |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 647 | /// this node and its children in the tree. This returns true if it makes a |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 648 | /// change, false otherwise. If a type contradiction is found, flag an error. |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 649 | bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 650 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 651 | /// UpdateNodeType - Set the node type of N to VT if VT contains |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 652 | /// information. If N already contains a conflicting type, then flag an |
| 653 | /// error. This returns true if any information was updated. |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 654 | /// |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 655 | bool UpdateNodeType(unsigned ResNo, const TypeSetByHwMode &InTy, |
| 656 | TreePattern &TP); |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 657 | bool UpdateNodeType(unsigned ResNo, MVT::SimpleValueType InTy, |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 658 | TreePattern &TP); |
| 659 | bool UpdateNodeType(unsigned ResNo, ValueTypeByHwMode InTy, |
| 660 | TreePattern &TP); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 661 | |
Jakob Stoklund Olesen | 57a8650 | 2013-03-18 04:08:07 +0000 | [diff] [blame] | 662 | // 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 Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 667 | /// ContainsUnresolvedType - Return true if this tree contains any |
| 668 | /// unresolved types. |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 669 | bool ContainsUnresolvedType(TreePattern &TP) const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 670 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 671 | /// canPatternMatch - If it is impossible for this pattern to match on this |
| 672 | /// target, fill in Reason and return false. Otherwise, return true. |
Dan Gohman | fc4ad7de | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 673 | bool canPatternMatch(std::string &Reason, const CodeGenDAGPatterns &CDP); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 674 | }; |
| 675 | |
Chris Lattner | dd2ec58 | 2010-02-14 21:10:33 +0000 | [diff] [blame] | 676 | inline raw_ostream &operator<<(raw_ostream &OS, const TreePatternNode &TPN) { |
| 677 | TPN.print(OS); |
| 678 | return OS; |
| 679 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 680 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 681 | |
| 682 | /// TreePattern - Represent a pattern, used for instructions, pattern |
| 683 | /// fragments, etc. |
| 684 | /// |
| 685 | class 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 Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 689 | std::vector<TreePatternNode*> Trees; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 690 | |
Chris Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 691 | /// NamedNodes - This is all of the nodes that have names in the trees in this |
| 692 | /// pattern. |
| 693 | StringMap<SmallVector<TreePatternNode*,1> > NamedNodes; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 694 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 695 | /// TheRecord - The actual TableGen record corresponding to this pattern. |
| 696 | /// |
| 697 | Record *TheRecord; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 698 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 699 | /// 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 702 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 703 | /// CDP - the top-level object coordinating this madness. |
| 704 | /// |
Chris Lattner | ab3242f | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 705 | CodeGenDAGPatterns &CDP; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 706 | |
| 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 Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 710 | |
| 711 | /// hasError - True if the currently processed nodes have unresolvable types |
| 712 | /// or other non-fatal errors |
| 713 | bool HasError; |
Tim Northover | c807a17 | 2014-05-20 11:52:46 +0000 | [diff] [blame] | 714 | |
| 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 Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 721 | |
| 722 | TypeInfer Infer; |
| 723 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 724 | public: |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 725 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 726 | /// TreePattern constructor - Parse the specified DagInits into the |
| 727 | /// current record. |
David Greene | af8ee2c | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 728 | TreePattern(Record *TheRec, ListInit *RawPat, bool isInput, |
Chris Lattner | ab3242f | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 729 | CodeGenDAGPatterns &ise); |
David Greene | af8ee2c | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 730 | TreePattern(Record *TheRec, DagInit *Pat, bool isInput, |
Chris Lattner | ab3242f | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 731 | CodeGenDAGPatterns &ise); |
David Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 732 | TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput, |
| 733 | CodeGenDAGPatterns &ise); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 734 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 735 | /// getTrees - Return the tree patterns which corresponds to this pattern. |
| 736 | /// |
David Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 737 | const std::vector<TreePatternNode*> &getTrees() const { return Trees; } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 738 | unsigned getNumTrees() const { return Trees.size(); } |
David Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 739 | TreePatternNode *getTree(unsigned i) const { return Trees[i]; } |
| 740 | TreePatternNode *getOnlyTree() const { |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 741 | assert(Trees.size() == 1 && "Doesn't have exactly one pattern!"); |
| 742 | return Trees[0]; |
| 743 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 744 | |
Chris Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 745 | const StringMap<SmallVector<TreePatternNode*,1> > &getNamedNodesMap() { |
| 746 | if (NamedNodes.empty()) |
| 747 | ComputeNamedNodes(); |
| 748 | return NamedNodes; |
| 749 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 750 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 751 | /// getRecord - Return the actual TableGen record corresponding to this |
| 752 | /// pattern. |
| 753 | /// |
| 754 | Record *getRecord() const { return TheRecord; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 755 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 756 | 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 762 | |
Chris Lattner | ab3242f | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 763 | CodeGenDAGPatterns &getDAGPatterns() const { return CDP; } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 764 | |
| 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 Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 770 | Trees[i] = Trees[i]->InlinePatternFragments(*this); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 771 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 772 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 773 | /// InferAllTypes - Infer/propagate as many types throughout the expression |
Jim Grosbach | 975c1cb | 2009-03-26 16:17:51 +0000 | [diff] [blame] | 774 | /// patterns as possible. Return true if all types are inferred, false |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 775 | /// otherwise. Bail out if a type contradiction is found. |
Chris Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 776 | bool InferAllTypes(const StringMap<SmallVector<TreePatternNode*,1> > |
Craig Topper | ada0857 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 777 | *NamedTypes=nullptr); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 778 | |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 779 | /// error - If this is the first error in the current resolution step, |
| 780 | /// print it and set the error flag. Otherwise, continue silently. |
Matt Arsenault | ea8df3a | 2014-11-11 23:48:11 +0000 | [diff] [blame] | 781 | void error(const Twine &Msg); |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 782 | bool hasError() const { |
| 783 | return HasError; |
| 784 | } |
| 785 | void resetError() { |
| 786 | HasError = false; |
| 787 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 788 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 789 | TypeInfer &getInfer() { return Infer; } |
| 790 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 791 | void print(raw_ostream &OS) const; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 792 | void dump() const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 793 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 794 | private: |
David Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 795 | TreePatternNode *ParseTreePattern(Init *DI, StringRef OpName); |
Chris Lattner | cabe037 | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 796 | void ComputeNamedNodes(); |
| 797 | void ComputeNamedNodes(TreePatternNode *N); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 798 | }; |
| 799 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 800 | |
| 801 | inline 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 | |
| 809 | inline 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 | |
| 817 | inline 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 Stellard | b7246a7 | 2012-09-06 14:15:52 +0000 | [diff] [blame] | 826 | /// DAGDefaultOperand - One of these is created for each OperandWithDefaultOps |
| 827 | /// that has a set ExecuteAlways / DefaultOps field. |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 828 | struct DAGDefaultOperand { |
| 829 | std::vector<TreePatternNode*> DefaultOps; |
| 830 | }; |
| 831 | |
| 832 | class DAGInstruction { |
| 833 | TreePattern *Pattern; |
| 834 | std::vector<Record*> Results; |
| 835 | std::vector<Record*> Operands; |
| 836 | std::vector<Record*> ImpResults; |
David Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 837 | TreePatternNode *ResultPattern; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 838 | public: |
| 839 | DAGInstruction(TreePattern *TP, |
| 840 | const std::vector<Record*> &results, |
| 841 | const std::vector<Record*> &operands, |
Chris Lattner | 9dc68d3 | 2010-04-20 06:28:43 +0000 | [diff] [blame] | 842 | const std::vector<Record*> &impresults) |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 843 | : Pattern(TP), Results(results), Operands(operands), |
David Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 844 | ImpResults(impresults), ResultPattern(nullptr) {} |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 845 | |
Joerg Sonnenberger | 635debe | 2012-10-25 20:33:17 +0000 | [diff] [blame] | 846 | TreePattern *getPattern() const { return Pattern; } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 847 | unsigned getNumResults() const { return Results.size(); } |
| 848 | unsigned getNumOperands() const { return Operands.size(); } |
| 849 | unsigned getNumImpResults() const { return ImpResults.size(); } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 850 | const std::vector<Record*>& getImpResults() const { return ImpResults; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 851 | |
David Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 852 | void setResultPattern(TreePatternNode *R) { ResultPattern = R; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 853 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 854 | Record *getResult(unsigned RN) const { |
| 855 | assert(RN < Results.size()); |
| 856 | return Results[RN]; |
| 857 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 858 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 859 | 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 868 | |
David Blaikie | cf19530 | 2014-11-17 22:55:41 +0000 | [diff] [blame] | 869 | TreePatternNode *getResultPattern() const { return ResultPattern; } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 870 | }; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 871 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 872 | /// 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. |
| 878 | class Predicate { |
| 879 | public: |
| 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 Lattner | ab3242f | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 919 | /// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 920 | /// processed to produce isel. |
Chris Lattner | 7ed8169 | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 921 | class PatternToMatch { |
| 922 | public: |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 923 | 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 Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 938 | |
Jim Grosbach | fb116ae | 2010-12-07 23:05:49 +0000 | [diff] [blame] | 939 | Record *SrcRecord; // Originating Record for the pattern. |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 940 | TreePatternNode *SrcPattern; // Source pattern to match. |
| 941 | TreePatternNode *DstPattern; // Resulting pattern. |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 942 | std::vector<Predicate> Predicates; // Top level predicate conditions |
| 943 | // to match. |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 944 | std::vector<Record*> Dstregs; // Physical register defs being matched. |
Tom Stellard | 6655dd6 | 2014-08-01 00:32:36 +0000 | [diff] [blame] | 945 | int AddedComplexity; // Add to matching pattern complexity. |
Chris Lattner | d39f75b | 2010-03-01 22:09:11 +0000 | [diff] [blame] | 946 | unsigned ID; // Unique ID for the record. |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 947 | unsigned ForceMode; // Force this mode in type inference when set. |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 948 | |
Jim Grosbach | fb116ae | 2010-12-07 23:05:49 +0000 | [diff] [blame] | 949 | Record *getSrcRecord() const { return SrcRecord; } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 950 | TreePatternNode *getSrcPattern() const { return SrcPattern; } |
| 951 | TreePatternNode *getDstPattern() const { return DstPattern; } |
| 952 | const std::vector<Record*> &getDstRegs() const { return Dstregs; } |
Tom Stellard | 6655dd6 | 2014-08-01 00:32:36 +0000 | [diff] [blame] | 953 | int getAddedComplexity() const { return AddedComplexity; } |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 954 | const std::vector<Predicate> &getPredicates() const { return Predicates; } |
Dan Gohman | 49e19e9 | 2008-08-22 00:20:26 +0000 | [diff] [blame] | 955 | |
| 956 | std::string getPredicateCheck() const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 957 | |
Chris Lattner | 05925fe | 2010-03-29 01:40:38 +0000 | [diff] [blame] | 958 | /// Compute the complexity metric for the input pattern. This roughly |
| 959 | /// corresponds to the number of nodes that are covered. |
Tom Stellard | 6655dd6 | 2014-08-01 00:32:36 +0000 | [diff] [blame] | 960 | int getPatternComplexity(const CodeGenDAGPatterns &CGP) const; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 961 | }; |
| 962 | |
Chris Lattner | ab3242f | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 963 | class CodeGenDAGPatterns { |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 964 | RecordKeeper &Records; |
| 965 | CodeGenTarget Target; |
Justin Bogner | 92a8c61 | 2016-07-15 16:31:37 +0000 | [diff] [blame] | 966 | CodeGenIntrinsicTable Intrinsics; |
| 967 | CodeGenIntrinsicTable TgtIntrinsics; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 968 | |
Sean Silva | a4e2c5f | 2012-09-19 01:47:00 +0000 | [diff] [blame] | 969 | std::map<Record*, SDNodeInfo, LessRecordByID> SDNodes; |
Krzysztof Parzyszek | 426bf36 | 2017-09-12 15:31:26 +0000 | [diff] [blame] | 970 | std::map<Record*, std::pair<Record*, std::string>, LessRecordByID> |
| 971 | SDNodeXForms; |
Sean Silva | a4e2c5f | 2012-09-19 01:47:00 +0000 | [diff] [blame] | 972 | std::map<Record*, ComplexPattern, LessRecordByID> ComplexPatterns; |
David Blaikie | 3c6ca23 | 2014-11-13 21:40:02 +0000 | [diff] [blame] | 973 | std::map<Record *, std::unique_ptr<TreePattern>, LessRecordByID> |
| 974 | PatternFragments; |
Sean Silva | a4e2c5f | 2012-09-19 01:47:00 +0000 | [diff] [blame] | 975 | std::map<Record*, DAGDefaultOperand, LessRecordByID> DefaultOperands; |
| 976 | std::map<Record*, DAGInstruction, LessRecordByID> Instructions; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 977 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 978 | // Specific SDNode definitions: |
| 979 | Record *intrinsic_void_sdnode; |
| 980 | Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 981 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 982 | /// 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 Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 986 | |
| 987 | TypeSetByHwMode LegalVTS; |
| 988 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 989 | public: |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 990 | CodeGenDAGPatterns(RecordKeeper &R); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 991 | |
Dan Gohman | fc4ad7de | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 992 | CodeGenTarget &getTargetInfo() { return Target; } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 993 | const CodeGenTarget &getTargetInfo() const { return Target; } |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 994 | const TypeSetByHwMode &getLegalTypes() const { return LegalVTS; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 995 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 996 | Record *getSDNodeNamed(const std::string &Name) const; |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 997 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 998 | const SDNodeInfo &getSDNodeInfo(Record *R) const { |
| 999 | assert(SDNodes.count(R) && "Unknown node!"); |
| 1000 | return SDNodes.find(R)->second; |
| 1001 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1002 | |
Chris Lattner | cc43e79 | 2008-01-05 22:54:53 +0000 | [diff] [blame] | 1003 | // Node transformation lookups. |
| 1004 | typedef std::pair<Record*, std::string> NodeXForm; |
| 1005 | const NodeXForm &getSDNodeTransform(Record *R) const { |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1006 | assert(SDNodeXForms.count(R) && "Invalid transform!"); |
| 1007 | return SDNodeXForms.find(R)->second; |
| 1008 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1009 | |
Sean Silva | a4e2c5f | 2012-09-19 01:47:00 +0000 | [diff] [blame] | 1010 | typedef std::map<Record*, NodeXForm, LessRecordByID>::const_iterator |
Benjamin Kramer | c2dbd5d | 2009-08-23 10:39:21 +0000 | [diff] [blame] | 1011 | nx_iterator; |
Chris Lattner | cc43e79 | 2008-01-05 22:54:53 +0000 | [diff] [blame] | 1012 | nx_iterator nx_begin() const { return SDNodeXForms.begin(); } |
| 1013 | nx_iterator nx_end() const { return SDNodeXForms.end(); } |
| 1014 | |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1015 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1016 | const ComplexPattern &getComplexPattern(Record *R) const { |
| 1017 | assert(ComplexPatterns.count(R) && "Unknown addressing mode!"); |
| 1018 | return ComplexPatterns.find(R)->second; |
| 1019 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1020 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1021 | 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 Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 1024 | for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i) |
| 1025 | if (TgtIntrinsics[i].TheDef == R) return TgtIntrinsics[i]; |
Craig Topper | c4965bc | 2012-02-05 07:21:30 +0000 | [diff] [blame] | 1026 | llvm_unreachable("Unknown intrinsic!"); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1027 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1028 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1029 | const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const { |
Dale Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 1030 | 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 Topper | c4965bc | 2012-02-05 07:21:30 +0000 | [diff] [blame] | 1034 | llvm_unreachable("Bad intrinsic ID!"); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1035 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1036 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1037 | 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 Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 1040 | for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i) |
| 1041 | if (TgtIntrinsics[i].TheDef == R) return i + Intrinsics.size(); |
Craig Topper | c4965bc | 2012-02-05 07:21:30 +0000 | [diff] [blame] | 1042 | llvm_unreachable("Unknown intrinsic!"); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1043 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1044 | |
Chris Lattner | 7ed8169 | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 1045 | const DAGDefaultOperand &getDefaultOperand(Record *R) const { |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1046 | assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!"); |
| 1047 | return DefaultOperands.find(R)->second; |
| 1048 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1049 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1050 | // Pattern Fragment information. |
| 1051 | TreePattern *getPatternFragment(Record *R) const { |
| 1052 | assert(PatternFragments.count(R) && "Invalid pattern fragment request!"); |
David Blaikie | 3c6ca23 | 2014-11-13 21:40:02 +0000 | [diff] [blame] | 1053 | return PatternFragments.find(R)->second.get(); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1054 | } |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 1055 | TreePattern *getPatternFragmentIfRead(Record *R) const { |
David Blaikie | 3c6ca23 | 2014-11-13 21:40:02 +0000 | [diff] [blame] | 1056 | if (!PatternFragments.count(R)) |
| 1057 | return nullptr; |
| 1058 | return PatternFragments.find(R)->second.get(); |
Chris Lattner | f144725 | 2010-03-19 21:37:09 +0000 | [diff] [blame] | 1059 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1060 | |
David Blaikie | fcacc74 | 2014-11-13 21:56:57 +0000 | [diff] [blame] | 1061 | typedef std::map<Record *, std::unique_ptr<TreePattern>, |
| 1062 | LessRecordByID>::const_iterator pf_iterator; |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1063 | pf_iterator pf_begin() const { return PatternFragments.begin(); } |
| 1064 | pf_iterator pf_end() const { return PatternFragments.end(); } |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 1065 | iterator_range<pf_iterator> ptfs() const { return PatternFragments; } |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1066 | |
| 1067 | // Patterns to match information. |
Chris Lattner | 9abe77b | 2008-01-05 22:30:17 +0000 | [diff] [blame] | 1068 | 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 Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 1071 | iterator_range<ptm_iterator> ptms() const { return PatternsToMatch; } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1072 | |
Ahmed Bougacha | 1410751 | 2013-10-28 18:07:21 +0000 | [diff] [blame] | 1073 | /// 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1078 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1079 | const DAGInstruction &getInstruction(Record *R) const { |
| 1080 | assert(Instructions.count(R) && "Unknown instruction!"); |
| 1081 | return Instructions.find(R)->second; |
| 1082 | } |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1083 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1084 | 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 Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1093 | |
Jakob Stoklund Olesen | e419725 | 2009-10-15 18:50:03 +0000 | [diff] [blame] | 1094 | bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); } |
| 1095 | |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1096 | private: |
| 1097 | void ParseNodeInfo(); |
Chris Lattner | cc43e79 | 2008-01-05 22:54:53 +0000 | [diff] [blame] | 1098 | void ParseNodeTransforms(); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1099 | void ParseComplexPatterns(); |
Hal Finkel | 2756dc1 | 2014-02-28 00:26:56 +0000 | [diff] [blame] | 1100 | void ParsePatternFragments(bool OutFrags = false); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1101 | void ParseDefaultOperands(); |
| 1102 | void ParseInstructions(); |
| 1103 | void ParsePatterns(); |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 1104 | void ExpandHwModeBasedTypes(); |
Dan Gohman | fc4ad7de | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 1105 | void InferInstructionFlags(); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1106 | void GenerateVariants(); |
Jakob Stoklund Olesen | a9d322a | 2012-08-28 03:26:49 +0000 | [diff] [blame] | 1107 | void VerifyInstructionFlags(); |
Jim Grosbach | 50986b5 | 2010-12-24 05:06:32 +0000 | [diff] [blame] | 1108 | |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 1109 | std::vector<Predicate> makePredList(ListInit *L); |
| 1110 | |
Craig Topper | 18e6b57 | 2017-06-25 17:33:49 +0000 | [diff] [blame] | 1111 | void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM); |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1112 | void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat, |
| 1113 | std::map<std::string, |
| 1114 | TreePatternNode*> &InstInputs, |
| 1115 | std::map<std::string, |
| 1116 | TreePatternNode*> &InstResults, |
Chris Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1117 | std::vector<Record*> &InstImpResults); |
| 1118 | }; |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 1119 | |
| 1120 | |
| 1121 | inline 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 Lattner | 8cab021 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 1128 | } // end namespace llvm |
| 1129 | |
| 1130 | #endif |