Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 1 | //===- CodeGenDAGPatterns.h - Read DAG patterns from .td file ---*- C++ -*-===// |
Chris Lattner | 4ca8ff0 | 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 | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 10 | // This file declares the CodeGenDAGPatterns class, which is used to read and |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 11 | // represent the patterns present in a .td file for instructions. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef CODEGEN_DAGPATTERNS_H |
| 16 | #define CODEGEN_DAGPATTERNS_H |
| 17 | |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 18 | #include "CodeGenTarget.h" |
| 19 | #include "CodeGenIntrinsics.h" |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
| 21 | #include "llvm/ADT/StringMap.h" |
Chris Lattner | 95127fb | 2010-03-19 01:07:44 +0000 | [diff] [blame] | 22 | #include <set> |
| 23 | #include <algorithm> |
| 24 | #include <vector> |
| 25 | #include <map> |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 26 | |
| 27 | namespace llvm { |
| 28 | class Record; |
| 29 | struct Init; |
| 30 | class ListInit; |
| 31 | class DagInit; |
| 32 | class SDNodeInfo; |
| 33 | class TreePattern; |
| 34 | class TreePatternNode; |
Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 35 | class CodeGenDAGPatterns; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 36 | class ComplexPattern; |
| 37 | |
Owen Anderson | ac9de03 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 38 | /// EEVT::DAGISelGenValueType - These are some extended forms of |
Owen Anderson | 36e3a6e | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 39 | /// MVT::SimpleValueType that we use as lattice values during type inference. |
Bob Wilson | 502c35e | 2009-08-29 05:53:25 +0000 | [diff] [blame] | 40 | /// The existing MVT iAny, fAny and vAny types suffice to represent |
| 41 | /// arbitrary integer, floating-point, and vector types, so only an unknown |
| 42 | /// value is needed. |
Owen Anderson | ac9de03 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 43 | namespace EEVT { |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 44 | /// TypeSet - This is either empty if it's completely unknown, or holds a set |
| 45 | /// of types. It is used during type inference because register classes can |
| 46 | /// have multiple possible types and we don't know which one they get until |
| 47 | /// type inference is complete. |
| 48 | /// |
| 49 | /// TypeSet can have three states: |
| 50 | /// Vector is empty: The type is completely unknown, it can be any valid |
| 51 | /// target type. |
| 52 | /// Vector has multiple constrained types: (e.g. v4i32 + v4f32) it is one |
| 53 | /// of those types only. |
| 54 | /// Vector has one concrete type: The type is completely known. |
| 55 | /// |
| 56 | class TypeSet { |
Chris Lattner | ab6a5d3 | 2010-03-19 17:41:26 +0000 | [diff] [blame] | 57 | SmallVector<MVT::SimpleValueType, 4> TypeVec; |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 58 | public: |
| 59 | TypeSet() {} |
| 60 | TypeSet(MVT::SimpleValueType VT, TreePattern &TP); |
| 61 | TypeSet(const std::vector<MVT::SimpleValueType> &VTList); |
| 62 | |
| 63 | bool isCompletelyUnknown() const { return TypeVec.empty(); } |
| 64 | |
| 65 | bool isConcrete() const { |
| 66 | if (TypeVec.size() != 1) return false; |
| 67 | unsigned char T = TypeVec[0]; (void)T; |
| 68 | assert(T < MVT::LAST_VALUETYPE || T == MVT::iPTR || T == MVT::iPTRAny); |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | MVT::SimpleValueType getConcrete() const { |
| 73 | assert(isConcrete() && "Type isn't concrete yet"); |
| 74 | return (MVT::SimpleValueType)TypeVec[0]; |
| 75 | } |
| 76 | |
| 77 | bool isDynamicallyResolved() const { |
| 78 | return getConcrete() == MVT::iPTR || getConcrete() == MVT::iPTRAny; |
| 79 | } |
| 80 | |
| 81 | const SmallVectorImpl<MVT::SimpleValueType> &getTypeList() const { |
| 82 | assert(!TypeVec.empty() && "Not a type list!"); |
| 83 | return TypeVec; |
| 84 | } |
| 85 | |
Chris Lattner | 20e96a2 | 2010-03-18 23:15:10 +0000 | [diff] [blame] | 86 | bool isVoid() const { |
| 87 | return TypeVec.size() == 1 && TypeVec[0] == MVT::isVoid; |
| 88 | } |
| 89 | |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 90 | /// hasIntegerTypes - Return true if this TypeSet contains any integer value |
| 91 | /// types. |
| 92 | bool hasIntegerTypes() const; |
| 93 | |
| 94 | /// hasFloatingPointTypes - Return true if this TypeSet contains an fAny or |
| 95 | /// a floating point value type. |
| 96 | bool hasFloatingPointTypes() const; |
| 97 | |
| 98 | /// hasVectorTypes - Return true if this TypeSet contains a vector value |
| 99 | /// type. |
| 100 | bool hasVectorTypes() const; |
| 101 | |
| 102 | /// getName() - Return this TypeSet as a string. |
| 103 | std::string getName() const; |
| 104 | |
| 105 | /// MergeInTypeInfo - This merges in type information from the specified |
| 106 | /// argument. If 'this' changes, it returns true. If the two types are |
| 107 | /// contradictory (e.g. merge f32 into i32) then this throws an exception. |
| 108 | bool MergeInTypeInfo(const EEVT::TypeSet &InVT, TreePattern &TP); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 109 | |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 110 | bool MergeInTypeInfo(MVT::SimpleValueType InVT, TreePattern &TP) { |
| 111 | return MergeInTypeInfo(EEVT::TypeSet(InVT, TP), TP); |
| 112 | } |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 113 | |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 114 | /// Force this type list to only contain integer types. |
| 115 | bool EnforceInteger(TreePattern &TP); |
Bob Wilson | c8d7717 | 2009-08-12 22:30:59 +0000 | [diff] [blame] | 116 | |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 117 | /// Force this type list to only contain floating point types. |
| 118 | bool EnforceFloatingPoint(TreePattern &TP); |
| 119 | |
| 120 | /// EnforceScalar - Remove all vector types from this type list. |
| 121 | bool EnforceScalar(TreePattern &TP); |
| 122 | |
| 123 | /// EnforceVector - Remove all non-vector types from this type list. |
| 124 | bool EnforceVector(TreePattern &TP); |
| 125 | |
| 126 | /// EnforceSmallerThan - 'this' must be a smaller VT than Other. Update |
| 127 | /// this an other based on this information. |
| 128 | bool EnforceSmallerThan(EEVT::TypeSet &Other, TreePattern &TP); |
| 129 | |
| 130 | /// EnforceVectorEltTypeIs - 'this' is now constrainted to be a vector type |
| 131 | /// whose element is VT. |
| 132 | bool EnforceVectorEltTypeIs(MVT::SimpleValueType VT, TreePattern &TP); |
| 133 | |
| 134 | bool operator!=(const TypeSet &RHS) const { return TypeVec != RHS.TypeVec; } |
| 135 | bool operator==(const TypeSet &RHS) const { return TypeVec == RHS.TypeVec; } |
Chris Lattner | df91b1a | 2010-03-19 04:54:36 +0000 | [diff] [blame] | 136 | |
| 137 | private: |
| 138 | /// FillWithPossibleTypes - Set to all legal types and return true, only |
Chris Lattner | ab6a5d3 | 2010-03-19 17:41:26 +0000 | [diff] [blame] | 139 | /// valid on completely unknown type sets. If Pred is non-null, only MVTs |
| 140 | /// that pass the predicate are added. |
| 141 | bool FillWithPossibleTypes(TreePattern &TP, |
| 142 | bool (*Pred)(MVT::SimpleValueType) = 0, |
| 143 | const char *PredicateName = 0); |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 144 | }; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Scott Michel | b41fcac | 2008-03-05 17:49:05 +0000 | [diff] [blame] | 147 | /// Set type used to track multiply used variables in patterns |
| 148 | typedef std::set<std::string> MultipleUseVarSet; |
| 149 | |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 150 | /// SDTypeConstraint - This is a discriminated union of constraints, |
| 151 | /// corresponding to the SDTypeConstraint tablegen class in Target.td. |
| 152 | struct SDTypeConstraint { |
| 153 | SDTypeConstraint(Record *R); |
| 154 | |
| 155 | unsigned OperandNo; // The operand # this constraint applies to. |
| 156 | enum { |
Bob Wilson | c8d7717 | 2009-08-12 22:30:59 +0000 | [diff] [blame] | 157 | SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisVec, SDTCisSameAs, |
Nate Begeman | 543d214 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 158 | SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisEltOfVec |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 159 | } ConstraintType; |
| 160 | |
| 161 | union { // The discriminated union. |
| 162 | struct { |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 163 | MVT::SimpleValueType VT; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 164 | } SDTCisVT_Info; |
| 165 | struct { |
| 166 | unsigned OtherOperandNum; |
| 167 | } SDTCisSameAs_Info; |
| 168 | struct { |
| 169 | unsigned OtherOperandNum; |
| 170 | } SDTCisVTSmallerThanOp_Info; |
| 171 | struct { |
| 172 | unsigned BigOperandNum; |
| 173 | } SDTCisOpSmallerThanOp_Info; |
| 174 | struct { |
| 175 | unsigned OtherOperandNum; |
Nate Begeman | ea391a2 | 2008-02-09 01:37:05 +0000 | [diff] [blame] | 176 | } SDTCisEltOfVec_Info; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 177 | } x; |
| 178 | |
| 179 | /// ApplyTypeConstraint - Given a node in a pattern, apply this type |
| 180 | /// constraint to the nodes operands. This returns true if it makes a |
| 181 | /// change, false otherwise. If a type contradiction is found, throw an |
| 182 | /// exception. |
| 183 | bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo, |
| 184 | TreePattern &TP) const; |
| 185 | |
| 186 | /// getOperandNum - Return the node corresponding to operand #OpNo in tree |
| 187 | /// N, which has NumResults results. |
| 188 | TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N, |
| 189 | unsigned NumResults) const; |
| 190 | }; |
| 191 | |
| 192 | /// SDNodeInfo - One of these records is created for each SDNode instance in |
| 193 | /// the target .td file. This represents the various dag nodes we will be |
| 194 | /// processing. |
| 195 | class SDNodeInfo { |
| 196 | Record *Def; |
| 197 | std::string EnumName; |
| 198 | std::string SDClassName; |
| 199 | unsigned Properties; |
| 200 | unsigned NumResults; |
| 201 | int NumOperands; |
| 202 | std::vector<SDTypeConstraint> TypeConstraints; |
| 203 | public: |
| 204 | SDNodeInfo(Record *R); // Parse the specified record. |
| 205 | |
| 206 | unsigned getNumResults() const { return NumResults; } |
| 207 | int getNumOperands() const { return NumOperands; } |
| 208 | Record *getRecord() const { return Def; } |
| 209 | const std::string &getEnumName() const { return EnumName; } |
| 210 | const std::string &getSDClassName() const { return SDClassName; } |
| 211 | |
| 212 | const std::vector<SDTypeConstraint> &getTypeConstraints() const { |
| 213 | return TypeConstraints; |
| 214 | } |
| 215 | |
Chris Lattner | e55ca27 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 216 | /// getKnownType - If the type constraints on this node imply a fixed type |
| 217 | /// (e.g. all stores return void, etc), then return it as an |
Chris Lattner | 1344060 | 2010-03-19 01:14:27 +0000 | [diff] [blame] | 218 | /// MVT::SimpleValueType. Otherwise, return MVT::Other. |
| 219 | MVT::SimpleValueType getKnownType() const; |
Chris Lattner | e55ca27 | 2010-02-28 00:22:30 +0000 | [diff] [blame] | 220 | |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 221 | /// hasProperty - Return true if this node has the specified property. |
| 222 | /// |
| 223 | bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); } |
| 224 | |
| 225 | /// ApplyTypeConstraints - Given a node in a pattern, apply the type |
| 226 | /// constraints for this node to the operands of the node. This returns |
| 227 | /// true if it makes a change, false otherwise. If a type contradiction is |
| 228 | /// found, throw an exception. |
| 229 | bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const { |
| 230 | bool MadeChange = false; |
| 231 | for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i) |
| 232 | MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP); |
| 233 | return MadeChange; |
| 234 | } |
| 235 | }; |
| 236 | |
| 237 | /// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped |
| 238 | /// patterns), and as such should be ref counted. We currently just leak all |
| 239 | /// TreePatternNode objects! |
| 240 | class TreePatternNode { |
Chris Lattner | b80a4bb | 2010-03-19 21:37:09 +0000 | [diff] [blame^] | 241 | /// The type of each node result. Before and during type inference, each |
| 242 | /// result may be a set of possible types. After (successful) type inference, |
| 243 | /// each is a single concrete type. |
| 244 | SmallVector<EEVT::TypeSet, 1> Types; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 245 | |
| 246 | /// Operator - The Record for the operator if this is an interior node (not |
| 247 | /// a leaf). |
| 248 | Record *Operator; |
| 249 | |
| 250 | /// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf. |
| 251 | /// |
| 252 | Init *Val; |
| 253 | |
| 254 | /// Name - The name given to this node with the :$foo notation. |
| 255 | /// |
| 256 | std::string Name; |
| 257 | |
Dan Gohman | 5394e11 | 2008-10-15 06:17:21 +0000 | [diff] [blame] | 258 | /// PredicateFns - The predicate functions to execute on this node to check |
| 259 | /// for a match. If this list is empty, no predicate is involved. |
| 260 | std::vector<std::string> PredicateFns; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 261 | |
| 262 | /// TransformFn - The transformation function to execute on this node before |
| 263 | /// it can be substituted into the resulting instruction on a pattern match. |
| 264 | Record *TransformFn; |
| 265 | |
| 266 | std::vector<TreePatternNode*> Children; |
| 267 | public: |
Chris Lattner | b80a4bb | 2010-03-19 21:37:09 +0000 | [diff] [blame^] | 268 | TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch, |
| 269 | unsigned NumResults) |
| 270 | : Operator(Op), Val(0), TransformFn(0), Children(Ch) { |
| 271 | Types.resize(NumResults); |
| 272 | } |
| 273 | TreePatternNode(Init *val, unsigned NumResults) // leaf ctor |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 274 | : Operator(0), Val(val), TransformFn(0) { |
Chris Lattner | b80a4bb | 2010-03-19 21:37:09 +0000 | [diff] [blame^] | 275 | Types.resize(NumResults); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 276 | } |
| 277 | ~TreePatternNode(); |
| 278 | |
| 279 | const std::string &getName() const { return Name; } |
| 280 | void setName(const std::string &N) { Name = N; } |
| 281 | |
| 282 | bool isLeaf() const { return Val != 0; } |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 283 | |
| 284 | // Type accessors. |
Chris Lattner | b80a4bb | 2010-03-19 21:37:09 +0000 | [diff] [blame^] | 285 | unsigned getNumTypes() const { return Types.size(); } |
| 286 | MVT::SimpleValueType getType(unsigned ResNo) const { |
| 287 | return Types[ResNo].getConcrete(); |
| 288 | } |
| 289 | const SmallVectorImpl<EEVT::TypeSet> &getExtTypes() const { return Types; } |
| 290 | const EEVT::TypeSet &getExtType(unsigned ResNo) const { return Types[ResNo]; } |
| 291 | EEVT::TypeSet &getExtType(unsigned ResNo) { return Types[ResNo]; } |
| 292 | void setType(unsigned ResNo, const EEVT::TypeSet &T) { Types[ResNo] = T; } |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 293 | |
Chris Lattner | b80a4bb | 2010-03-19 21:37:09 +0000 | [diff] [blame^] | 294 | bool hasTypeSet(unsigned ResNo) const { |
| 295 | return Types[ResNo].isConcrete(); |
| 296 | } |
| 297 | bool isTypeCompletelyUnknown(unsigned ResNo) const { |
| 298 | return Types[ResNo].isCompletelyUnknown(); |
| 299 | } |
| 300 | bool isTypeDynamicallyResolved(unsigned ResNo) const { |
| 301 | return Types[ResNo].isDynamicallyResolved(); |
| 302 | } |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 303 | |
| 304 | Init *getLeafValue() const { assert(isLeaf()); return Val; } |
| 305 | Record *getOperator() const { assert(!isLeaf()); return Operator; } |
| 306 | |
| 307 | unsigned getNumChildren() const { return Children.size(); } |
| 308 | TreePatternNode *getChild(unsigned N) const { return Children[N]; } |
| 309 | void setChild(unsigned i, TreePatternNode *N) { |
| 310 | Children[i] = N; |
| 311 | } |
Chris Lattner | 9de3948 | 2010-02-16 06:10:58 +0000 | [diff] [blame] | 312 | |
| 313 | /// hasChild - Return true if N is any of our children. |
| 314 | bool hasChild(const TreePatternNode *N) const { |
| 315 | for (unsigned i = 0, e = Children.size(); i != e; ++i) |
| 316 | if (Children[i] == N) return true; |
| 317 | return false; |
| 318 | } |
Chris Lattner | d99f236 | 2008-01-06 05:36:50 +0000 | [diff] [blame] | 319 | |
Chris Lattner | 5c1eb0c | 2010-02-14 22:22:58 +0000 | [diff] [blame] | 320 | const std::vector<std::string> &getPredicateFns() const {return PredicateFns;} |
Dan Gohman | 5394e11 | 2008-10-15 06:17:21 +0000 | [diff] [blame] | 321 | void clearPredicateFns() { PredicateFns.clear(); } |
| 322 | void setPredicateFns(const std::vector<std::string> &Fns) { |
| 323 | assert(PredicateFns.empty() && "Overwriting non-empty predicate list!"); |
| 324 | PredicateFns = Fns; |
| 325 | } |
| 326 | void addPredicateFn(const std::string &Fn) { |
| 327 | assert(!Fn.empty() && "Empty predicate string!"); |
| 328 | if (std::find(PredicateFns.begin(), PredicateFns.end(), Fn) == |
| 329 | PredicateFns.end()) |
| 330 | PredicateFns.push_back(Fn); |
| 331 | } |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 332 | |
| 333 | Record *getTransformFn() const { return TransformFn; } |
| 334 | void setTransformFn(Record *Fn) { TransformFn = Fn; } |
| 335 | |
Chris Lattner | d99f236 | 2008-01-06 05:36:50 +0000 | [diff] [blame] | 336 | /// getIntrinsicInfo - If this node corresponds to an intrinsic, return the |
| 337 | /// CodeGenIntrinsic information for it, otherwise return a null pointer. |
| 338 | const CodeGenIntrinsic *getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const; |
Evan Cheng | bb46d26 | 2008-06-16 20:29:38 +0000 | [diff] [blame] | 339 | |
Chris Lattner | 5c1eb0c | 2010-02-14 22:22:58 +0000 | [diff] [blame] | 340 | /// getComplexPatternInfo - If this node corresponds to a ComplexPattern, |
| 341 | /// return the ComplexPattern information, otherwise return null. |
| 342 | const ComplexPattern * |
| 343 | getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const; |
| 344 | |
| 345 | /// NodeHasProperty - Return true if this node has the specified property. |
Chris Lattner | 6cb6e42 | 2010-02-14 22:33:49 +0000 | [diff] [blame] | 346 | bool NodeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const; |
Chris Lattner | 5c1eb0c | 2010-02-14 22:22:58 +0000 | [diff] [blame] | 347 | |
| 348 | /// TreeHasProperty - Return true if any node in this tree has the specified |
| 349 | /// property. |
Chris Lattner | 6cb6e42 | 2010-02-14 22:33:49 +0000 | [diff] [blame] | 350 | bool TreeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const; |
Chris Lattner | 5c1eb0c | 2010-02-14 22:22:58 +0000 | [diff] [blame] | 351 | |
Evan Cheng | bb46d26 | 2008-06-16 20:29:38 +0000 | [diff] [blame] | 352 | /// isCommutativeIntrinsic - Return true if the node is an intrinsic which is |
| 353 | /// marked isCommutative. |
| 354 | bool isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const; |
Chris Lattner | d99f236 | 2008-01-06 05:36:50 +0000 | [diff] [blame] | 355 | |
Daniel Dunbar | d428706 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 356 | void print(raw_ostream &OS) const; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 357 | void dump() const; |
| 358 | |
| 359 | public: // Higher level manipulation routines. |
| 360 | |
| 361 | /// clone - Return a new copy of this tree. |
| 362 | /// |
| 363 | TreePatternNode *clone() const; |
Chris Lattner | 5c1eb0c | 2010-02-14 22:22:58 +0000 | [diff] [blame] | 364 | |
| 365 | /// RemoveAllTypes - Recursively strip all the types of this tree. |
| 366 | void RemoveAllTypes(); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 367 | |
| 368 | /// isIsomorphicTo - Return true if this node is recursively isomorphic to |
| 369 | /// the specified node. For this comparison, all of the state of the node |
| 370 | /// is considered, except for the assigned name. Nodes with differing names |
| 371 | /// that are otherwise identical are considered isomorphic. |
Scott Michel | b41fcac | 2008-03-05 17:49:05 +0000 | [diff] [blame] | 372 | bool isIsomorphicTo(const TreePatternNode *N, |
| 373 | const MultipleUseVarSet &DepVars) const; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 374 | |
| 375 | /// SubstituteFormalArguments - Replace the formal arguments in this tree |
| 376 | /// with actual values specified by ArgMap. |
| 377 | void SubstituteFormalArguments(std::map<std::string, |
| 378 | TreePatternNode*> &ArgMap); |
| 379 | |
| 380 | /// InlinePatternFragments - If this pattern refers to any pattern |
| 381 | /// fragments, inline them into place, giving us a pattern without any |
| 382 | /// PatFrag references. |
| 383 | TreePatternNode *InlinePatternFragments(TreePattern &TP); |
| 384 | |
Bob Wilson | b72d934 | 2009-01-05 17:23:09 +0000 | [diff] [blame] | 385 | /// ApplyTypeConstraints - Apply all of the type constraints relevant to |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 386 | /// this node and its children in the tree. This returns true if it makes a |
| 387 | /// change, false otherwise. If a type contradiction is found, throw an |
| 388 | /// exception. |
| 389 | bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters); |
| 390 | |
| 391 | /// UpdateNodeType - Set the node type of N to VT if VT contains |
| 392 | /// information. If N already contains a conflicting type, then throw an |
| 393 | /// exception. This returns true if any information was updated. |
| 394 | /// |
Chris Lattner | b80a4bb | 2010-03-19 21:37:09 +0000 | [diff] [blame^] | 395 | bool UpdateNodeType(unsigned ResNo, const EEVT::TypeSet &InTy, |
| 396 | TreePattern &TP) { |
| 397 | return Types[ResNo].MergeInTypeInfo(InTy, TP); |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Chris Lattner | b80a4bb | 2010-03-19 21:37:09 +0000 | [diff] [blame^] | 400 | bool UpdateNodeType(unsigned ResNo, MVT::SimpleValueType InTy, |
| 401 | TreePattern &TP) { |
| 402 | return Types[ResNo].MergeInTypeInfo(EEVT::TypeSet(InTy, TP), TP); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /// ContainsUnresolvedType - Return true if this tree contains any |
| 406 | /// unresolved types. |
| 407 | bool ContainsUnresolvedType() const { |
Chris Lattner | b80a4bb | 2010-03-19 21:37:09 +0000 | [diff] [blame^] | 408 | for (unsigned i = 0, e = Types.size(); i != e; ++i) |
| 409 | if (!Types[i].isConcrete()) return true; |
| 410 | |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 411 | for (unsigned i = 0, e = getNumChildren(); i != e; ++i) |
| 412 | if (getChild(i)->ContainsUnresolvedType()) return true; |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | /// canPatternMatch - If it is impossible for this pattern to match on this |
| 417 | /// target, fill in Reason and return false. Otherwise, return true. |
Dan Gohman | 907df57 | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 418 | bool canPatternMatch(std::string &Reason, const CodeGenDAGPatterns &CDP); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 419 | }; |
| 420 | |
Chris Lattner | c31b02c | 2010-02-14 21:10:33 +0000 | [diff] [blame] | 421 | inline raw_ostream &operator<<(raw_ostream &OS, const TreePatternNode &TPN) { |
| 422 | TPN.print(OS); |
| 423 | return OS; |
| 424 | } |
| 425 | |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 426 | |
| 427 | /// TreePattern - Represent a pattern, used for instructions, pattern |
| 428 | /// fragments, etc. |
| 429 | /// |
| 430 | class TreePattern { |
| 431 | /// Trees - The list of pattern trees which corresponds to this pattern. |
| 432 | /// Note that PatFrag's only have a single tree. |
| 433 | /// |
| 434 | std::vector<TreePatternNode*> Trees; |
| 435 | |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 436 | /// NamedNodes - This is all of the nodes that have names in the trees in this |
| 437 | /// pattern. |
| 438 | StringMap<SmallVector<TreePatternNode*,1> > NamedNodes; |
| 439 | |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 440 | /// TheRecord - The actual TableGen record corresponding to this pattern. |
| 441 | /// |
| 442 | Record *TheRecord; |
| 443 | |
| 444 | /// Args - This is a list of all of the arguments to this pattern (for |
| 445 | /// PatFrag patterns), which are the 'node' markers in this pattern. |
| 446 | std::vector<std::string> Args; |
| 447 | |
| 448 | /// CDP - the top-level object coordinating this madness. |
| 449 | /// |
Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 450 | CodeGenDAGPatterns &CDP; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 451 | |
| 452 | /// isInputPattern - True if this is an input pattern, something to match. |
| 453 | /// False if this is an output pattern, something to emit. |
| 454 | bool isInputPattern; |
| 455 | public: |
| 456 | |
| 457 | /// TreePattern constructor - Parse the specified DagInits into the |
| 458 | /// current record. |
| 459 | TreePattern(Record *TheRec, ListInit *RawPat, bool isInput, |
Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 460 | CodeGenDAGPatterns &ise); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 461 | TreePattern(Record *TheRec, DagInit *Pat, bool isInput, |
Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 462 | CodeGenDAGPatterns &ise); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 463 | TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput, |
Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 464 | CodeGenDAGPatterns &ise); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 465 | |
| 466 | /// getTrees - Return the tree patterns which corresponds to this pattern. |
| 467 | /// |
| 468 | const std::vector<TreePatternNode*> &getTrees() const { return Trees; } |
| 469 | unsigned getNumTrees() const { return Trees.size(); } |
| 470 | TreePatternNode *getTree(unsigned i) const { return Trees[i]; } |
| 471 | TreePatternNode *getOnlyTree() const { |
| 472 | assert(Trees.size() == 1 && "Doesn't have exactly one pattern!"); |
| 473 | return Trees[0]; |
| 474 | } |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 475 | |
| 476 | const StringMap<SmallVector<TreePatternNode*,1> > &getNamedNodesMap() { |
| 477 | if (NamedNodes.empty()) |
| 478 | ComputeNamedNodes(); |
| 479 | return NamedNodes; |
| 480 | } |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 481 | |
| 482 | /// getRecord - Return the actual TableGen record corresponding to this |
| 483 | /// pattern. |
| 484 | /// |
| 485 | Record *getRecord() const { return TheRecord; } |
| 486 | |
| 487 | unsigned getNumArgs() const { return Args.size(); } |
| 488 | const std::string &getArgName(unsigned i) const { |
| 489 | assert(i < Args.size() && "Argument reference out of range!"); |
| 490 | return Args[i]; |
| 491 | } |
| 492 | std::vector<std::string> &getArgList() { return Args; } |
| 493 | |
Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 494 | CodeGenDAGPatterns &getDAGPatterns() const { return CDP; } |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 495 | |
| 496 | /// InlinePatternFragments - If this pattern refers to any pattern |
| 497 | /// fragments, inline them into place, giving us a pattern without any |
| 498 | /// PatFrag references. |
| 499 | void InlinePatternFragments() { |
| 500 | for (unsigned i = 0, e = Trees.size(); i != e; ++i) |
| 501 | Trees[i] = Trees[i]->InlinePatternFragments(*this); |
| 502 | } |
| 503 | |
| 504 | /// InferAllTypes - Infer/propagate as many types throughout the expression |
Jim Grosbach | da95ec8 | 2009-03-26 16:17:51 +0000 | [diff] [blame] | 505 | /// patterns as possible. Return true if all types are inferred, false |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 506 | /// otherwise. Throw an exception if a type contradiction is found. |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 507 | bool InferAllTypes(const StringMap<SmallVector<TreePatternNode*,1> > |
| 508 | *NamedTypes=0); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 509 | |
| 510 | /// error - Throw an exception, prefixing it with information about this |
| 511 | /// pattern. |
| 512 | void error(const std::string &Msg) const; |
| 513 | |
Daniel Dunbar | d428706 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 514 | void print(raw_ostream &OS) const; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 515 | void dump() const; |
| 516 | |
| 517 | private: |
| 518 | TreePatternNode *ParseTreePattern(DagInit *DI); |
Chris Lattner | 3f9bead | 2010-03-15 06:00:16 +0000 | [diff] [blame] | 519 | void ComputeNamedNodes(); |
| 520 | void ComputeNamedNodes(TreePatternNode *N); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 521 | }; |
| 522 | |
| 523 | /// DAGDefaultOperand - One of these is created for each PredicateOperand |
| 524 | /// or OptionalDefOperand that has a set ExecuteAlways / DefaultOps field. |
| 525 | struct DAGDefaultOperand { |
| 526 | std::vector<TreePatternNode*> DefaultOps; |
| 527 | }; |
| 528 | |
| 529 | class DAGInstruction { |
| 530 | TreePattern *Pattern; |
| 531 | std::vector<Record*> Results; |
| 532 | std::vector<Record*> Operands; |
| 533 | std::vector<Record*> ImpResults; |
| 534 | std::vector<Record*> ImpOperands; |
| 535 | TreePatternNode *ResultPattern; |
| 536 | public: |
| 537 | DAGInstruction(TreePattern *TP, |
| 538 | const std::vector<Record*> &results, |
| 539 | const std::vector<Record*> &operands, |
| 540 | const std::vector<Record*> &impresults, |
| 541 | const std::vector<Record*> &impoperands) |
| 542 | : Pattern(TP), Results(results), Operands(operands), |
| 543 | ImpResults(impresults), ImpOperands(impoperands), |
| 544 | ResultPattern(0) {} |
| 545 | |
Chris Lattner | 7c6e585 | 2008-01-06 01:52:22 +0000 | [diff] [blame] | 546 | const TreePattern *getPattern() const { return Pattern; } |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 547 | unsigned getNumResults() const { return Results.size(); } |
| 548 | unsigned getNumOperands() const { return Operands.size(); } |
| 549 | unsigned getNumImpResults() const { return ImpResults.size(); } |
| 550 | unsigned getNumImpOperands() const { return ImpOperands.size(); } |
| 551 | const std::vector<Record*>& getImpResults() const { return ImpResults; } |
| 552 | |
| 553 | void setResultPattern(TreePatternNode *R) { ResultPattern = R; } |
| 554 | |
| 555 | Record *getResult(unsigned RN) const { |
| 556 | assert(RN < Results.size()); |
| 557 | return Results[RN]; |
| 558 | } |
| 559 | |
| 560 | Record *getOperand(unsigned ON) const { |
| 561 | assert(ON < Operands.size()); |
| 562 | return Operands[ON]; |
| 563 | } |
| 564 | |
| 565 | Record *getImpResult(unsigned RN) const { |
| 566 | assert(RN < ImpResults.size()); |
| 567 | return ImpResults[RN]; |
| 568 | } |
| 569 | |
| 570 | Record *getImpOperand(unsigned ON) const { |
| 571 | assert(ON < ImpOperands.size()); |
| 572 | return ImpOperands[ON]; |
| 573 | } |
| 574 | |
| 575 | TreePatternNode *getResultPattern() const { return ResultPattern; } |
| 576 | }; |
| 577 | |
Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 578 | /// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 579 | /// processed to produce isel. |
Chris Lattner | 43c3299 | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 580 | class PatternToMatch { |
| 581 | public: |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 582 | PatternToMatch(ListInit *preds, |
| 583 | TreePatternNode *src, TreePatternNode *dst, |
| 584 | const std::vector<Record*> &dstregs, |
Chris Lattner | 14b8583 | 2010-03-01 22:09:11 +0000 | [diff] [blame] | 585 | unsigned complexity, unsigned uid) |
| 586 | : Predicates(preds), SrcPattern(src), DstPattern(dst), |
| 587 | Dstregs(dstregs), AddedComplexity(complexity), ID(uid) {} |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 588 | |
| 589 | ListInit *Predicates; // Top level predicate conditions to match. |
| 590 | TreePatternNode *SrcPattern; // Source pattern to match. |
| 591 | TreePatternNode *DstPattern; // Resulting pattern. |
| 592 | std::vector<Record*> Dstregs; // Physical register defs being matched. |
| 593 | unsigned AddedComplexity; // Add to matching pattern complexity. |
Chris Lattner | 14b8583 | 2010-03-01 22:09:11 +0000 | [diff] [blame] | 594 | unsigned ID; // Unique ID for the record. |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 595 | |
| 596 | ListInit *getPredicates() const { return Predicates; } |
| 597 | TreePatternNode *getSrcPattern() const { return SrcPattern; } |
| 598 | TreePatternNode *getDstPattern() const { return DstPattern; } |
| 599 | const std::vector<Record*> &getDstRegs() const { return Dstregs; } |
| 600 | unsigned getAddedComplexity() const { return AddedComplexity; } |
Dan Gohman | e97f1a3 | 2008-08-22 00:20:26 +0000 | [diff] [blame] | 601 | |
| 602 | std::string getPredicateCheck() const; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 603 | }; |
| 604 | |
Daniel Dunbar | 3fdb045 | 2009-08-23 09:47:37 +0000 | [diff] [blame] | 605 | // Deterministic comparison of Record*. |
| 606 | struct RecordPtrCmp { |
| 607 | bool operator()(const Record *LHS, const Record *RHS) const; |
| 608 | }; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 609 | |
Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 610 | class CodeGenDAGPatterns { |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 611 | RecordKeeper &Records; |
| 612 | CodeGenTarget Target; |
| 613 | std::vector<CodeGenIntrinsic> Intrinsics; |
Dale Johannesen | fe5921a | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 614 | std::vector<CodeGenIntrinsic> TgtIntrinsics; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 615 | |
Daniel Dunbar | 3fdb045 | 2009-08-23 09:47:37 +0000 | [diff] [blame] | 616 | std::map<Record*, SDNodeInfo, RecordPtrCmp> SDNodes; |
| 617 | std::map<Record*, std::pair<Record*, std::string>, RecordPtrCmp> SDNodeXForms; |
| 618 | std::map<Record*, ComplexPattern, RecordPtrCmp> ComplexPatterns; |
| 619 | std::map<Record*, TreePattern*, RecordPtrCmp> PatternFragments; |
| 620 | std::map<Record*, DAGDefaultOperand, RecordPtrCmp> DefaultOperands; |
| 621 | std::map<Record*, DAGInstruction, RecordPtrCmp> Instructions; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 622 | |
| 623 | // Specific SDNode definitions: |
| 624 | Record *intrinsic_void_sdnode; |
| 625 | Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode; |
| 626 | |
| 627 | /// PatternsToMatch - All of the things we are matching on the DAG. The first |
| 628 | /// value is the pattern to match, the second pattern is the result to |
| 629 | /// emit. |
| 630 | std::vector<PatternToMatch> PatternsToMatch; |
| 631 | public: |
Chris Lattner | ae50670 | 2008-01-06 01:10:31 +0000 | [diff] [blame] | 632 | CodeGenDAGPatterns(RecordKeeper &R); |
| 633 | ~CodeGenDAGPatterns(); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 634 | |
Dan Gohman | 907df57 | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 635 | CodeGenTarget &getTargetInfo() { return Target; } |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 636 | const CodeGenTarget &getTargetInfo() const { return Target; } |
| 637 | |
| 638 | Record *getSDNodeNamed(const std::string &Name) const; |
| 639 | |
| 640 | const SDNodeInfo &getSDNodeInfo(Record *R) const { |
| 641 | assert(SDNodes.count(R) && "Unknown node!"); |
| 642 | return SDNodes.find(R)->second; |
| 643 | } |
| 644 | |
Chris Lattner | 227da45 | 2008-01-05 22:54:53 +0000 | [diff] [blame] | 645 | // Node transformation lookups. |
| 646 | typedef std::pair<Record*, std::string> NodeXForm; |
| 647 | const NodeXForm &getSDNodeTransform(Record *R) const { |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 648 | assert(SDNodeXForms.count(R) && "Invalid transform!"); |
| 649 | return SDNodeXForms.find(R)->second; |
| 650 | } |
| 651 | |
Benjamin Kramer | 237602e | 2009-08-23 10:39:21 +0000 | [diff] [blame] | 652 | typedef std::map<Record*, NodeXForm, RecordPtrCmp>::const_iterator |
| 653 | nx_iterator; |
Chris Lattner | 227da45 | 2008-01-05 22:54:53 +0000 | [diff] [blame] | 654 | nx_iterator nx_begin() const { return SDNodeXForms.begin(); } |
| 655 | nx_iterator nx_end() const { return SDNodeXForms.end(); } |
| 656 | |
| 657 | |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 658 | const ComplexPattern &getComplexPattern(Record *R) const { |
| 659 | assert(ComplexPatterns.count(R) && "Unknown addressing mode!"); |
| 660 | return ComplexPatterns.find(R)->second; |
| 661 | } |
| 662 | |
| 663 | const CodeGenIntrinsic &getIntrinsic(Record *R) const { |
| 664 | for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i) |
| 665 | if (Intrinsics[i].TheDef == R) return Intrinsics[i]; |
Dale Johannesen | fe5921a | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 666 | for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i) |
| 667 | if (TgtIntrinsics[i].TheDef == R) return TgtIntrinsics[i]; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 668 | assert(0 && "Unknown intrinsic!"); |
| 669 | abort(); |
| 670 | } |
| 671 | |
| 672 | const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const { |
Dale Johannesen | fe5921a | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 673 | if (IID-1 < Intrinsics.size()) |
| 674 | return Intrinsics[IID-1]; |
| 675 | if (IID-Intrinsics.size()-1 < TgtIntrinsics.size()) |
| 676 | return TgtIntrinsics[IID-Intrinsics.size()-1]; |
| 677 | assert(0 && "Bad intrinsic ID!"); |
Evan Cheng | 2b8b012 | 2009-02-09 03:07:24 +0000 | [diff] [blame] | 678 | abort(); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | unsigned getIntrinsicID(Record *R) const { |
| 682 | for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i) |
| 683 | if (Intrinsics[i].TheDef == R) return i; |
Dale Johannesen | fe5921a | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 684 | for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i) |
| 685 | if (TgtIntrinsics[i].TheDef == R) return i + Intrinsics.size(); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 686 | assert(0 && "Unknown intrinsic!"); |
| 687 | abort(); |
| 688 | } |
| 689 | |
Chris Lattner | 43c3299 | 2010-02-18 06:47:49 +0000 | [diff] [blame] | 690 | const DAGDefaultOperand &getDefaultOperand(Record *R) const { |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 691 | assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!"); |
| 692 | return DefaultOperands.find(R)->second; |
| 693 | } |
| 694 | |
| 695 | // Pattern Fragment information. |
| 696 | TreePattern *getPatternFragment(Record *R) const { |
| 697 | assert(PatternFragments.count(R) && "Invalid pattern fragment request!"); |
| 698 | return PatternFragments.find(R)->second; |
| 699 | } |
Chris Lattner | b80a4bb | 2010-03-19 21:37:09 +0000 | [diff] [blame^] | 700 | TreePattern *getPatternFragmentIfRead(Record *R) const { |
| 701 | if (!PatternFragments.count(R)) return 0; |
| 702 | return PatternFragments.find(R)->second; |
| 703 | } |
| 704 | |
Benjamin Kramer | 237602e | 2009-08-23 10:39:21 +0000 | [diff] [blame] | 705 | typedef std::map<Record*, TreePattern*, RecordPtrCmp>::const_iterator |
| 706 | pf_iterator; |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 707 | pf_iterator pf_begin() const { return PatternFragments.begin(); } |
| 708 | pf_iterator pf_end() const { return PatternFragments.end(); } |
| 709 | |
| 710 | // Patterns to match information. |
Chris Lattner | 8191575 | 2008-01-05 22:30:17 +0000 | [diff] [blame] | 711 | typedef std::vector<PatternToMatch>::const_iterator ptm_iterator; |
| 712 | ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); } |
| 713 | ptm_iterator ptm_end() const { return PatternsToMatch.end(); } |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 714 | |
| 715 | |
| 716 | |
| 717 | const DAGInstruction &getInstruction(Record *R) const { |
| 718 | assert(Instructions.count(R) && "Unknown instruction!"); |
| 719 | return Instructions.find(R)->second; |
| 720 | } |
| 721 | |
| 722 | Record *get_intrinsic_void_sdnode() const { |
| 723 | return intrinsic_void_sdnode; |
| 724 | } |
| 725 | Record *get_intrinsic_w_chain_sdnode() const { |
| 726 | return intrinsic_w_chain_sdnode; |
| 727 | } |
| 728 | Record *get_intrinsic_wo_chain_sdnode() const { |
| 729 | return intrinsic_wo_chain_sdnode; |
| 730 | } |
| 731 | |
Jakob Stoklund Olesen | 75dbdd1 | 2009-10-15 18:50:03 +0000 | [diff] [blame] | 732 | bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); } |
| 733 | |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 734 | private: |
| 735 | void ParseNodeInfo(); |
Chris Lattner | 227da45 | 2008-01-05 22:54:53 +0000 | [diff] [blame] | 736 | void ParseNodeTransforms(); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 737 | void ParseComplexPatterns(); |
Chris Lattner | 7fdd934 | 2008-01-05 22:43:57 +0000 | [diff] [blame] | 738 | void ParsePatternFragments(); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 739 | void ParseDefaultOperands(); |
| 740 | void ParseInstructions(); |
| 741 | void ParsePatterns(); |
Dan Gohman | 907df57 | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 742 | void InferInstructionFlags(); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 743 | void GenerateVariants(); |
| 744 | |
Chris Lattner | 654e716 | 2010-02-23 06:16:51 +0000 | [diff] [blame] | 745 | void AddPatternToMatch(const TreePattern *Pattern, const PatternToMatch &PTM); |
Chris Lattner | 4ca8ff0 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 746 | void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat, |
| 747 | std::map<std::string, |
| 748 | TreePatternNode*> &InstInputs, |
| 749 | std::map<std::string, |
| 750 | TreePatternNode*> &InstResults, |
| 751 | std::vector<Record*> &InstImpInputs, |
| 752 | std::vector<Record*> &InstImpResults); |
| 753 | }; |
| 754 | } // end namespace llvm |
| 755 | |
| 756 | #endif |