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