blob: f63e28e47cbadc403a4f409003b2cf50ff42efd0 [file] [log] [blame]
Chris Lattner4a24c642005-09-03 01:14:03 +00001//===- DAGISelEmitter.h - Generate an instruction selector ------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This tablegen backend emits a DAG instruction selector.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef DAGISEL_EMITTER_H
15#define DAGISEL_EMITTER_H
16
17#include "TableGenBackend.h"
18#include "CodeGenTarget.h"
19
20namespace llvm {
Chris Lattner54cb8fd2005-09-07 23:44:43 +000021 class Record;
Jeff Cohen8337b072005-09-10 02:00:02 +000022 struct Init;
Chris Lattnera28aec12005-09-15 22:23:50 +000023 class ListInit;
Chris Lattner54cb8fd2005-09-07 23:44:43 +000024 class DagInit;
Chris Lattner32707602005-09-08 23:22:48 +000025 class SDNodeInfo;
Chris Lattner54cb8fd2005-09-07 23:44:43 +000026 class TreePattern;
Chris Lattner32707602005-09-08 23:22:48 +000027 class TreePatternNode;
Chris Lattner54cb8fd2005-09-07 23:44:43 +000028 class DAGISelEmitter;
Evan Cheng0fc71982005-12-08 02:00:36 +000029 class ComplexPattern;
Chris Lattnerca559d02005-09-08 21:03:01 +000030
Chris Lattner3c7e18d2005-10-14 06:12:03 +000031 /// MVT::DAGISelGenValueType - These are some extended forms of MVT::ValueType
32 /// that we use as lattice values during type inferrence.
33 namespace MVT {
34 enum DAGISelGenValueType {
35 isFP = MVT::LAST_VALUETYPE,
36 isInt,
37 isUnknown
38 };
39 }
40
Chris Lattner33c92e92005-09-08 21:27:15 +000041 /// SDTypeConstraint - This is a discriminated union of constraints,
42 /// corresponding to the SDTypeConstraint tablegen class in Target.td.
43 struct SDTypeConstraint {
44 SDTypeConstraint(Record *R);
45
46 unsigned OperandNo; // The operand # this constraint applies to.
47 enum {
Chris Lattner5b21be72005-12-09 22:57:42 +000048 SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisSameAs,
49 SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp
Chris Lattner33c92e92005-09-08 21:27:15 +000050 } ConstraintType;
51
52 union { // The discriminated union.
53 struct {
54 MVT::ValueType VT;
55 } SDTCisVT_Info;
56 struct {
57 unsigned OtherOperandNum;
58 } SDTCisSameAs_Info;
59 struct {
60 unsigned OtherOperandNum;
61 } SDTCisVTSmallerThanOp_Info;
Chris Lattner03ebd802005-10-14 04:53:53 +000062 struct {
63 unsigned BigOperandNum;
64 } SDTCisOpSmallerThanOp_Info;
Chris Lattner33c92e92005-09-08 21:27:15 +000065 } x;
Chris Lattner32707602005-09-08 23:22:48 +000066
67 /// ApplyTypeConstraint - Given a node in a pattern, apply this type
68 /// constraint to the nodes operands. This returns true if it makes a
69 /// change, false otherwise. If a type contradiction is found, throw an
70 /// exception.
71 bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
72 TreePattern &TP) const;
73
74 /// getOperandNum - Return the node corresponding to operand #OpNo in tree
75 /// N, which has NumResults results.
76 TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N,
77 unsigned NumResults) const;
Chris Lattner33c92e92005-09-08 21:27:15 +000078 };
79
Chris Lattnerca559d02005-09-08 21:03:01 +000080 /// SDNodeInfo - One of these records is created for each SDNode instance in
81 /// the target .td file. This represents the various dag nodes we will be
82 /// processing.
83 class SDNodeInfo {
84 Record *Def;
85 std::string EnumName;
86 std::string SDClassName;
Chris Lattnera1a68ae2005-09-28 18:28:29 +000087 unsigned Properties;
Chris Lattner32707602005-09-08 23:22:48 +000088 unsigned NumResults;
89 int NumOperands;
Chris Lattner33c92e92005-09-08 21:27:15 +000090 std::vector<SDTypeConstraint> TypeConstraints;
Chris Lattnerca559d02005-09-08 21:03:01 +000091 public:
92 SDNodeInfo(Record *R); // Parse the specified record.
93
Chris Lattner32707602005-09-08 23:22:48 +000094 unsigned getNumResults() const { return NumResults; }
Chris Lattner33c92e92005-09-08 21:27:15 +000095 int getNumOperands() const { return NumOperands; }
Chris Lattnerca559d02005-09-08 21:03:01 +000096 Record *getRecord() const { return Def; }
97 const std::string &getEnumName() const { return EnumName; }
98 const std::string &getSDClassName() const { return SDClassName; }
Chris Lattner33c92e92005-09-08 21:27:15 +000099
Chris Lattner32707602005-09-08 23:22:48 +0000100 const std::vector<SDTypeConstraint> &getTypeConstraints() const {
Chris Lattner33c92e92005-09-08 21:27:15 +0000101 return TypeConstraints;
102 }
Chris Lattnera1a68ae2005-09-28 18:28:29 +0000103
104 // SelectionDAG node properties.
Evan Cheng1c3d19e2005-12-04 08:18:16 +0000105 enum SDNP { SDNPCommutative, SDNPAssociative, SDNPHasChain };
Chris Lattnera1a68ae2005-09-28 18:28:29 +0000106
107 /// hasProperty - Return true if this node has the specified property.
108 ///
109 bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
Chris Lattner32707602005-09-08 23:22:48 +0000110
111 /// ApplyTypeConstraints - Given a node in a pattern, apply the type
112 /// constraints for this node to the operands of the node. This returns
113 /// true if it makes a change, false otherwise. If a type contradiction is
114 /// found, throw an exception.
115 bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const {
116 bool MadeChange = false;
117 for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
118 MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP);
119 return MadeChange;
120 }
Chris Lattnerca559d02005-09-08 21:03:01 +0000121 };
Chris Lattner4a24c642005-09-03 01:14:03 +0000122
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000123 /// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped
124 /// patterns), and as such should be ref counted. We currently just leak all
125 /// TreePatternNode objects!
126 class TreePatternNode {
127 /// The inferred type for this node, or MVT::LAST_VALUETYPE if it hasn't
128 /// been determined yet.
Chris Lattner3c7e18d2005-10-14 06:12:03 +0000129 unsigned char Ty;
130
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000131 /// Operator - The Record for the operator if this is an interior node (not
132 /// a leaf).
133 Record *Operator;
134
135 /// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf.
136 ///
137 Init *Val;
138
139 /// Name - The name given to this node with the :$foo notation.
140 ///
141 std::string Name;
142
143 /// PredicateFn - The predicate function to execute on this node to check
144 /// for a match. If this string is empty, no predicate is involved.
145 std::string PredicateFn;
146
Chris Lattner24eeeb82005-09-13 21:51:00 +0000147 /// TransformFn - The transformation function to execute on this node before
148 /// it can be substituted into the resulting instruction on a pattern match.
Chris Lattnerb0276202005-09-14 22:55:26 +0000149 Record *TransformFn;
Chris Lattner24eeeb82005-09-13 21:51:00 +0000150
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000151 std::vector<TreePatternNode*> Children;
152 public:
153 TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch)
Chris Lattner3c7e18d2005-10-14 06:12:03 +0000154 : Ty(MVT::isUnknown), Operator(Op), Val(0), TransformFn(0),
Chris Lattnerb0276202005-09-14 22:55:26 +0000155 Children(Ch) {}
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000156 TreePatternNode(Init *val) // leaf ctor
Chris Lattner3c7e18d2005-10-14 06:12:03 +0000157 : Ty(MVT::isUnknown), Operator(0), Val(val), TransformFn(0) {}
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000158 ~TreePatternNode();
159
160 const std::string &getName() const { return Name; }
161 void setName(const std::string &N) { Name = N; }
162
163 bool isLeaf() const { return Val != 0; }
Chris Lattner3c7e18d2005-10-14 06:12:03 +0000164 bool hasTypeSet() const { return Ty < MVT::LAST_VALUETYPE; }
165 bool isTypeCompletelyUnknown() const {
166 return Ty == MVT::isUnknown;
167 }
168 MVT::ValueType getType() const {
169 assert(hasTypeSet() && "Doesn't have a type yet!");
170 return (MVT::ValueType)Ty;
171 }
172 unsigned char getExtType() const { return Ty; }
173 void setType(unsigned char VT) { Ty = VT; }
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000174
175 Init *getLeafValue() const { assert(isLeaf()); return Val; }
176 Record *getOperator() const { assert(!isLeaf()); return Operator; }
177
178 unsigned getNumChildren() const { return Children.size(); }
179 TreePatternNode *getChild(unsigned N) const { return Children[N]; }
180 void setChild(unsigned i, TreePatternNode *N) {
181 Children[i] = N;
182 }
183
184 const std::string &getPredicateFn() const { return PredicateFn; }
185 void setPredicateFn(const std::string &Fn) { PredicateFn = Fn; }
Chris Lattner24eeeb82005-09-13 21:51:00 +0000186
Chris Lattnerb0276202005-09-14 22:55:26 +0000187 Record *getTransformFn() const { return TransformFn; }
188 void setTransformFn(Record *Fn) { TransformFn = Fn; }
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000189
190 void print(std::ostream &OS) const;
191 void dump() const;
192
193 public: // Higher level manipulation routines.
194
195 /// clone - Return a new copy of this tree.
196 ///
197 TreePatternNode *clone() const;
198
Chris Lattnere46e17b2005-09-29 19:28:10 +0000199 /// isIsomorphicTo - Return true if this node is recursively isomorphic to
200 /// the specified node. For this comparison, all of the state of the node
201 /// is considered, except for the assigned name. Nodes with differing names
202 /// that are otherwise identical are considered isomorphic.
203 bool isIsomorphicTo(const TreePatternNode *N) const;
204
Chris Lattner32707602005-09-08 23:22:48 +0000205 /// SubstituteFormalArguments - Replace the formal arguments in this tree
206 /// with actual values specified by ArgMap.
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000207 void SubstituteFormalArguments(std::map<std::string,
208 TreePatternNode*> &ArgMap);
209
210 /// InlinePatternFragments - If this pattern refers to any pattern
211 /// fragments, inline them into place, giving us a pattern without any
212 /// PatFrag references.
213 TreePatternNode *InlinePatternFragments(TreePattern &TP);
Chris Lattner32707602005-09-08 23:22:48 +0000214
215 /// ApplyTypeConstraints - Apply all of the type constraints relevent to
216 /// this node and its children in the tree. This returns true if it makes a
217 /// change, false otherwise. If a type contradiction is found, throw an
218 /// exception.
Chris Lattner0ee7cff2005-10-14 04:11:13 +0000219 bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
Chris Lattner32707602005-09-08 23:22:48 +0000220
221 /// UpdateNodeType - Set the node type of N to VT if VT contains
222 /// information. If N already contains a conflicting type, then throw an
223 /// exception. This returns true if any information was updated.
224 ///
Chris Lattner3c7e18d2005-10-14 06:12:03 +0000225 bool UpdateNodeType(unsigned char EVT, TreePattern &TP);
Chris Lattner32707602005-09-08 23:22:48 +0000226
227 /// ContainsUnresolvedType - Return true if this tree contains any
228 /// unresolved types.
229 bool ContainsUnresolvedType() const {
Chris Lattner2ac85102005-10-19 04:12:14 +0000230 if (!hasTypeSet()) return true;
Chris Lattner32707602005-09-08 23:22:48 +0000231 for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
232 if (getChild(i)->ContainsUnresolvedType()) return true;
233 return false;
234 }
Chris Lattnere97603f2005-09-28 19:27:25 +0000235
Chris Lattner7cf2fe62005-09-28 20:58:06 +0000236 /// canPatternMatch - If it is impossible for this pattern to match on this
237 /// target, fill in Reason and return false. Otherwise, return true.
Chris Lattnere97603f2005-09-28 19:27:25 +0000238 bool canPatternMatch(std::string &Reason, DAGISelEmitter &ISE);
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000239 };
240
241
Chris Lattneree9f0c32005-09-13 21:20:49 +0000242 /// TreePattern - Represent a pattern, used for instructions, pattern
243 /// fragments, etc.
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000244 ///
245 class TreePattern {
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000246 /// Trees - The list of pattern trees which corresponds to this pattern.
247 /// Note that PatFrag's only have a single tree.
248 ///
249 std::vector<TreePatternNode*> Trees;
250
251 /// TheRecord - The actual TableGen record corresponding to this pattern.
252 ///
253 Record *TheRecord;
254
255 /// Args - This is a list of all of the arguments to this pattern (for
256 /// PatFrag patterns), which are the 'node' markers in this pattern.
257 std::vector<std::string> Args;
258
259 /// ISE - the DAG isel emitter coordinating this madness.
260 ///
261 DAGISelEmitter &ISE;
Chris Lattneredbd8712005-10-21 01:19:59 +0000262
263 /// isInputPattern - True if this is an input pattern, something to match.
264 /// False if this is an output pattern, something to emit.
265 bool isInputPattern;
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000266 public:
267
268 /// TreePattern constructor - Parse the specified DagInits into the
269 /// current record.
Chris Lattneredbd8712005-10-21 01:19:59 +0000270 TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
271 DAGISelEmitter &ise);
272 TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
273 DAGISelEmitter &ise);
274 TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
275 DAGISelEmitter &ise);
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000276
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000277 /// getTrees - Return the tree patterns which corresponds to this pattern.
278 ///
279 const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
Chris Lattner20180052005-09-09 01:11:17 +0000280 unsigned getNumTrees() const { return Trees.size(); }
281 TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
Chris Lattner37937092005-09-09 01:15:01 +0000282 TreePatternNode *getOnlyTree() const {
283 assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
284 return Trees[0];
285 }
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000286
287 /// getRecord - Return the actual TableGen record corresponding to this
288 /// pattern.
289 ///
290 Record *getRecord() const { return TheRecord; }
291
292 unsigned getNumArgs() const { return Args.size(); }
293 const std::string &getArgName(unsigned i) const {
294 assert(i < Args.size() && "Argument reference out of range!");
295 return Args[i];
296 }
Chris Lattneree9f0c32005-09-13 21:20:49 +0000297 std::vector<std::string> &getArgList() { return Args; }
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000298
299 DAGISelEmitter &getDAGISelEmitter() const { return ISE; }
300
301 /// InlinePatternFragments - If this pattern refers to any pattern
302 /// fragments, inline them into place, giving us a pattern without any
303 /// PatFrag references.
304 void InlinePatternFragments() {
305 for (unsigned i = 0, e = Trees.size(); i != e; ++i)
306 Trees[i] = Trees[i]->InlinePatternFragments(*this);
307 }
308
Chris Lattner32707602005-09-08 23:22:48 +0000309 /// InferAllTypes - Infer/propagate as many types throughout the expression
310 /// patterns as possible. Return true if all types are infered, false
311 /// otherwise. Throw an exception if a type contradiction is found.
312 bool InferAllTypes();
313
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000314 /// error - Throw an exception, prefixing it with information about this
315 /// pattern.
316 void error(const std::string &Msg) const;
317
318 void print(std::ostream &OS) const;
319 void dump() const;
320
321 private:
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000322 TreePatternNode *ParseTreePattern(DagInit *DI);
323 };
Chris Lattnerec676432005-09-14 04:03:16 +0000324
325
326 class DAGInstruction {
327 TreePattern *Pattern;
Nate Begemanddb39542005-12-01 00:06:14 +0000328 std::vector<Record*> Results;
329 std::vector<Record*> Operands;
Evan Chengbcecf332005-12-17 01:19:28 +0000330 std::vector<Record*> ImpResults;
331 std::vector<Record*> ImpOperands;
Chris Lattnerb0276202005-09-14 22:55:26 +0000332 TreePatternNode *ResultPattern;
Chris Lattnerec676432005-09-14 04:03:16 +0000333 public:
Chris Lattnerae6d8282005-09-15 21:51:12 +0000334 DAGInstruction(TreePattern *TP,
Nate Begemanddb39542005-12-01 00:06:14 +0000335 const std::vector<Record*> &results,
Evan Chengbcecf332005-12-17 01:19:28 +0000336 const std::vector<Record*> &operands,
337 const std::vector<Record*> &impresults,
338 const std::vector<Record*> &impoperands)
Nate Begemanddb39542005-12-01 00:06:14 +0000339 : Pattern(TP), Results(results), Operands(operands),
Evan Chengbcecf332005-12-17 01:19:28 +0000340 ImpResults(impresults), ImpOperands(impoperands),
Chris Lattnera28aec12005-09-15 22:23:50 +0000341 ResultPattern(0) {}
Chris Lattnerec676432005-09-14 04:03:16 +0000342
Chris Lattnerec676432005-09-14 04:03:16 +0000343 TreePattern *getPattern() const { return Pattern; }
Nate Begemanddb39542005-12-01 00:06:14 +0000344 unsigned getNumResults() const { return Results.size(); }
345 unsigned getNumOperands() const { return Operands.size(); }
Evan Chengbcecf332005-12-17 01:19:28 +0000346 unsigned getNumImpResults() const { return ImpResults.size(); }
347 unsigned getNumImpOperands() const { return ImpOperands.size(); }
Chris Lattnerae6d8282005-09-15 21:51:12 +0000348
Chris Lattnera28aec12005-09-15 22:23:50 +0000349 void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
350
Nate Begemanddb39542005-12-01 00:06:14 +0000351 Record *getResult(unsigned RN) const {
352 assert(RN < Results.size());
353 return Results[RN];
Chris Lattnerae6d8282005-09-15 21:51:12 +0000354 }
355
Nate Begemanddb39542005-12-01 00:06:14 +0000356 Record *getOperand(unsigned ON) const {
357 assert(ON < Operands.size());
358 return Operands[ON];
Chris Lattnerae6d8282005-09-15 21:51:12 +0000359 }
Evan Chengbcecf332005-12-17 01:19:28 +0000360
361 Record *getImpResult(unsigned RN) const {
362 assert(RN < ImpResults.size());
363 return ImpResults[RN];
364 }
365
366 Record *getImpOperand(unsigned ON) const {
367 assert(ON < ImpOperands.size());
368 return ImpOperands[ON];
369 }
Chris Lattnerb0276202005-09-14 22:55:26 +0000370 TreePatternNode *getResultPattern() const { return ResultPattern; }
Chris Lattnerec676432005-09-14 04:03:16 +0000371 };
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000372
Evan Cheng58e84a62005-12-14 22:02:59 +0000373/// PatternToMatch - Used by DAGISelEmitter to keep tab of patterns processed
374/// to produce isel.
375struct PatternToMatch {
376 PatternToMatch(ListInit *preds, TreePatternNode *src, TreePatternNode *dst):
377 Predicates(preds), SrcPattern(src), DstPattern(dst) {};
378
379 ListInit *Predicates; // Top level predicate conditions to match.
380 TreePatternNode *SrcPattern; // Source pattern to match.
381 TreePatternNode *DstPattern; // Resulting pattern.
382
383 ListInit *getPredicates() const { return Predicates; }
384 TreePatternNode *getSrcPattern() const { return SrcPattern; }
385 TreePatternNode *getDstPattern() const { return DstPattern; }
386};
387
Chris Lattner4a24c642005-09-03 01:14:03 +0000388/// InstrSelectorEmitter - The top-level class which coordinates construction
389/// and emission of the instruction selector.
390///
391class DAGISelEmitter : public TableGenBackend {
Chris Lattner3f7e9142005-09-23 20:52:47 +0000392public:
Evan Cheng58e84a62005-12-14 22:02:59 +0000393 //typedef std::pair<TreePatternNode*, TreePatternNode*> PatternToMatch;
Chris Lattner3f7e9142005-09-23 20:52:47 +0000394private:
Chris Lattner4a24c642005-09-03 01:14:03 +0000395 RecordKeeper &Records;
396 CodeGenTarget Target;
397
Chris Lattnerca559d02005-09-08 21:03:01 +0000398 std::map<Record*, SDNodeInfo> SDNodes;
Chris Lattner24eeeb82005-09-13 21:51:00 +0000399 std::map<Record*, std::pair<Record*, std::string> > SDNodeXForms;
Evan Cheng0fc71982005-12-08 02:00:36 +0000400 std::map<Record*, ComplexPattern> ComplexPatterns;
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000401 std::map<Record*, TreePattern*> PatternFragments;
Chris Lattnerae5b3502005-09-15 21:57:35 +0000402 std::map<Record*, DAGInstruction> Instructions;
Chris Lattner1f39e292005-09-14 00:09:24 +0000403
404 /// PatternsToMatch - All of the things we are matching on the DAG. The first
405 /// value is the pattern to match, the second pattern is the result to
406 /// emit.
Chris Lattner81303322005-09-23 19:36:15 +0000407 std::vector<PatternToMatch> PatternsToMatch;
Chris Lattner4a24c642005-09-03 01:14:03 +0000408public:
409 DAGISelEmitter(RecordKeeper &R) : Records(R) {}
410
411 // run - Output the isel, returning true on failure.
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000412 void run(std::ostream &OS);
Chris Lattnerca559d02005-09-08 21:03:01 +0000413
Chris Lattner0ee7cff2005-10-14 04:11:13 +0000414 const CodeGenTarget &getTargetInfo() const { return Target; }
415
Chris Lattner0614b622005-11-02 06:49:14 +0000416 Record *getSDNodeNamed(const std::string &Name) const;
417
Chris Lattnerca559d02005-09-08 21:03:01 +0000418 const SDNodeInfo &getSDNodeInfo(Record *R) const {
419 assert(SDNodes.count(R) && "Unknown node!");
420 return SDNodes.find(R)->second;
421 }
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000422
Chris Lattner6de8b532005-09-13 21:59:15 +0000423 const std::pair<Record*, std::string> &getSDNodeTransform(Record *R) const {
424 assert(SDNodeXForms.count(R) && "Invalid transform!");
425 return SDNodeXForms.find(R)->second;
426 }
Evan Cheng0fc71982005-12-08 02:00:36 +0000427
428 const ComplexPattern &getComplexPattern(Record *R) const {
429 assert(ComplexPatterns.count(R) && "Unknown addressing mode!");
430 return ComplexPatterns.find(R)->second;
431 }
432
433 TreePattern *getPatternFragment(Record *R) const {
434 assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
435 return PatternFragments.find(R)->second;
436 }
Chris Lattner6de8b532005-09-13 21:59:15 +0000437
Chris Lattnerae5b3502005-09-15 21:57:35 +0000438 const DAGInstruction &getInstruction(Record *R) const {
439 assert(Instructions.count(R) && "Unknown instruction!");
440 return Instructions.find(R)->second;
441 }
442
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000443private:
Chris Lattnerca559d02005-09-08 21:03:01 +0000444 void ParseNodeInfo();
Chris Lattner24eeeb82005-09-13 21:51:00 +0000445 void ParseNodeTransforms(std::ostream &OS);
Evan Cheng0fc71982005-12-08 02:00:36 +0000446 void ParseComplexPatterns();
Chris Lattnerb39e4be2005-09-15 02:38:02 +0000447 void ParsePatternFragments(std::ostream &OS);
448 void ParseInstructions();
449 void ParsePatterns();
Chris Lattnere97603f2005-09-28 19:27:25 +0000450 void GenerateVariants();
Chris Lattnerd8a3bde2005-09-14 20:53:42 +0000451 void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
452 std::map<std::string,
453 TreePatternNode*> &InstInputs,
Evan Chengbcecf332005-12-17 01:19:28 +0000454 std::map<std::string, Record*> &InstResults,
455 std::vector<Record*> &InstImpInputs,
456 std::vector<Record*> &InstImpResults);
Chris Lattner3f7e9142005-09-23 20:52:47 +0000457 void EmitCodeForPattern(PatternToMatch &Pattern, std::ostream &OS);
Chris Lattner54cb8fd2005-09-07 23:44:43 +0000458 void EmitInstructionSelector(std::ostream &OS);
Chris Lattner4a24c642005-09-03 01:14:03 +0000459};
460
461} // End llvm namespace
462
463#endif