Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 1 | //===- InstrInfoEmitter.h - Generate a Instruction Set Desc. ----*- C++ -*-===// |
| 2 | // |
| 3 | // This tablegen backend is responsible for emitting a description of the target |
| 4 | // instruction set for the code generator. |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
| 8 | #ifndef INSTRSELECTOR_EMITTER_H |
| 9 | #define INSTRSELECTOR_EMITTER_H |
| 10 | |
| 11 | #include "TableGenBackend.h" |
Chris Lattner | bc659dd | 2003-08-07 06:02:15 +0000 | [diff] [blame] | 12 | #include "CodeGenWrappers.h" |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 13 | #include <vector> |
| 14 | #include <map> |
John Criswell | 43bf32e | 2003-08-20 22:07:45 +0000 | [diff] [blame^] | 15 | #include <cassert> |
| 16 | |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 17 | class DagInit; |
| 18 | class Init; |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 19 | class InstrSelectorEmitter; |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 20 | |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 21 | /// NodeType - Represents Information parsed from the DagNode entries. |
| 22 | /// |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 23 | struct NodeType { |
| 24 | enum ArgResultTypes { |
Chris Lattner | 6b666e8 | 2003-08-12 04:56:42 +0000 | [diff] [blame] | 25 | Any, // No constraint on type |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 26 | Val, // A non-void type |
| 27 | Arg0, // Value matches the type of Arg0 |
Chris Lattner | 88118bf | 2003-08-11 20:25:52 +0000 | [diff] [blame] | 28 | Arg1, // Value matches the type of Arg1 |
Chris Lattner | 2787d1a | 2003-08-06 06:16:35 +0000 | [diff] [blame] | 29 | Ptr, // Tree node is the type of the target pointer |
Chris Lattner | c12a614 | 2003-08-12 04:28:21 +0000 | [diff] [blame] | 30 | I8, // Always bool |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 31 | Void, // Tree node always returns void |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | ArgResultTypes ResultType; |
| 35 | std::vector<ArgResultTypes> ArgTypes; |
| 36 | |
| 37 | NodeType(ArgResultTypes RT, std::vector<ArgResultTypes> &AT) : ResultType(RT){ |
| 38 | AT.swap(ArgTypes); |
| 39 | } |
| 40 | |
| 41 | NodeType() : ResultType(Val) {} |
| 42 | NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){} |
| 43 | |
| 44 | static ArgResultTypes Translate(Record *R); |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | /// TreePatternNode - Represent a node of the tree patterns. |
| 50 | /// |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 51 | class TreePatternNode { |
| 52 | /// Operator - The operation that this node represents... this is null if this |
| 53 | /// is a leaf. |
| 54 | Record *Operator; |
| 55 | |
| 56 | /// Type - The inferred value type... |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 57 | /// |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 58 | MVT::ValueType Type; |
| 59 | |
| 60 | /// Children - If this is not a leaf (Operator != 0), this is the subtrees |
| 61 | /// that we contain. |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 62 | std::vector<std::pair<TreePatternNode*, std::string> > Children; |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 63 | |
| 64 | /// Value - If this node is a leaf, this indicates what the thing is. |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 65 | /// |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 66 | Init *Value; |
| 67 | public: |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 68 | TreePatternNode(Record *o, const std::vector<std::pair<TreePatternNode*, |
| 69 | std::string> > &c) |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 70 | : Operator(o), Type(MVT::Other), Children(c), Value(0) {} |
| 71 | TreePatternNode(Init *V) : Operator(0), Type(MVT::Other), Value(V) {} |
| 72 | |
Chris Lattner | 6dafd39 | 2003-08-08 16:30:10 +0000 | [diff] [blame] | 73 | Record *getOperator() const { |
| 74 | assert(Operator && "This is a leaf node!"); |
| 75 | return Operator; |
| 76 | } |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 77 | MVT::ValueType getType() const { return Type; } |
| 78 | void setType(MVT::ValueType T) { Type = T; } |
| 79 | |
| 80 | bool isLeaf() const { return Operator == 0; } |
| 81 | |
Chris Lattner | 955c1be | 2003-08-08 22:29:23 +0000 | [diff] [blame] | 82 | unsigned getNumChildren() const { return Children.size(); } |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 83 | TreePatternNode *getChild(unsigned c) const { |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 84 | assert(Operator != 0 && "This is a leaf node!"); |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 85 | assert(c < Children.size() && "Child access out of range!"); |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 86 | return Children[c].first; |
| 87 | } |
| 88 | const std::string &getChildName(unsigned c) const { |
| 89 | assert(Operator != 0 && "This is a leaf node!"); |
| 90 | assert(c < Children.size() && "Child access out of range!"); |
| 91 | return Children[c].second; |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 94 | Init *getValue() const { |
| 95 | assert(Operator == 0 && "This is not a leaf node!"); |
| 96 | return Value; |
| 97 | } |
| 98 | |
Chris Lattner | 955c1be | 2003-08-08 22:29:23 +0000 | [diff] [blame] | 99 | /// getValueRecord - Returns the value of this tree node as a record. For now |
| 100 | /// we only allow DefInit's as our leaf values, so this is used. |
| 101 | Record *getValueRecord() const; |
| 102 | |
Chris Lattner | ef0ce6a | 2003-08-07 23:16:20 +0000 | [diff] [blame] | 103 | /// clone - Make a copy of this tree and all of its children. |
| 104 | /// |
| 105 | TreePatternNode *clone() const; |
| 106 | |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 107 | void dump() const; |
Chris Lattner | 2b8b2b4 | 2003-08-07 19:28:55 +0000 | [diff] [blame] | 108 | |
Chris Lattner | ef0ce6a | 2003-08-07 23:16:20 +0000 | [diff] [blame] | 109 | /// InstantiateNonterminals - If this pattern refers to any nonterminals which |
| 110 | /// are not themselves completely resolved, clone the nonterminal and resolve |
| 111 | /// it with the using context we provide. |
| 112 | void InstantiateNonterminals(InstrSelectorEmitter &ISE); |
Chris Lattner | 2b8b2b4 | 2003-08-07 19:28:55 +0000 | [diff] [blame] | 113 | |
Chris Lattner | 955c1be | 2003-08-08 22:29:23 +0000 | [diff] [blame] | 114 | /// UpdateNodeType - Set the node type of N to VT if VT contains information. |
| 115 | /// If N already contains a conflicting type, then throw an exception. This |
| 116 | /// returns true if any information was updated. |
| 117 | /// |
Chris Lattner | 2b8b2b4 | 2003-08-07 19:28:55 +0000 | [diff] [blame] | 118 | bool updateNodeType(MVT::ValueType VT, const std::string &RecName); |
Chris Lattner | 018c9e4 | 2003-08-07 05:40:14 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | std::ostream &operator<<(std::ostream &OS, const TreePatternNode &N); |
| 122 | |
| 123 | |
| 124 | |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 125 | /// Pattern - Represent a pattern of one form or another. Currently, three |
| 126 | /// types of patterns are possible: Instruction's, Nonterminals, and Expanders. |
| 127 | /// |
| 128 | struct Pattern { |
| 129 | enum PatternType { |
| 130 | Nonterminal, Instruction, Expander |
| 131 | }; |
| 132 | private: |
| 133 | /// PTy - The type of pattern this is. |
| 134 | /// |
| 135 | PatternType PTy; |
| 136 | |
| 137 | /// Tree - The tree pattern which corresponds to this pattern. Note that if |
| 138 | /// there was a (set) node on the outside level that it has been stripped off. |
| 139 | /// |
| 140 | TreePatternNode *Tree; |
| 141 | |
| 142 | /// Result - If this is an instruction or expander pattern, this is the |
| 143 | /// register result, specified with a (set) in the pattern. |
| 144 | /// |
Chris Lattner | abb215e | 2003-08-11 21:28:59 +0000 | [diff] [blame] | 145 | std::string ResultName; // The name of the result value... |
| 146 | TreePatternNode *ResultNode; // The leaf node for the result register... |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 147 | |
| 148 | /// TheRecord - The actual TableGen record corresponding to this pattern. |
| 149 | /// |
| 150 | Record *TheRecord; |
| 151 | |
| 152 | /// Resolved - This is true of the pattern is useful in practice. In |
| 153 | /// particular, some non-terminals will have non-resolvable types. When a |
| 154 | /// user of the non-terminal is later found, they will have inferred a type |
| 155 | /// for the result of the non-terminal, which cause a clone of an unresolved |
| 156 | /// nonterminal to be made which is "resolved". |
| 157 | /// |
| 158 | bool Resolved; |
| 159 | |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 160 | /// Args - This is a list of all of the arguments to this pattern, which are |
| 161 | /// the non-void leaf nodes in this pattern. |
| 162 | std::vector<std::pair<TreePatternNode*, std::string> > Args; |
| 163 | |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 164 | /// ISE - the instruction selector emitter coordinating this madness. |
| 165 | /// |
| 166 | InstrSelectorEmitter &ISE; |
| 167 | public: |
| 168 | |
| 169 | /// Pattern constructor - Parse the specified DagInitializer into the current |
| 170 | /// record. |
| 171 | Pattern(PatternType pty, DagInit *RawPat, Record *TheRec, |
| 172 | InstrSelectorEmitter &ise); |
| 173 | |
Chris Lattner | ef0ce6a | 2003-08-07 23:16:20 +0000 | [diff] [blame] | 174 | /// Pattern - Constructor used for cloning nonterminal patterns |
| 175 | Pattern(TreePatternNode *tree, Record *rec, bool res, |
Chris Lattner | abb215e | 2003-08-11 21:28:59 +0000 | [diff] [blame] | 176 | InstrSelectorEmitter &ise) |
| 177 | : PTy(Nonterminal), Tree(tree), ResultNode(0), TheRecord(rec), |
| 178 | Resolved(res), ISE(ise) { |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 179 | calculateArgs(Tree, ""); |
| 180 | } |
Chris Lattner | ef0ce6a | 2003-08-07 23:16:20 +0000 | [diff] [blame] | 181 | |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 182 | /// getPatternType - Return what flavor of Record this pattern originated from |
| 183 | /// |
| 184 | PatternType getPatternType() const { return PTy; } |
| 185 | |
| 186 | /// getTree - Return the tree pattern which corresponds to this pattern. |
| 187 | /// |
| 188 | TreePatternNode *getTree() const { return Tree; } |
| 189 | |
Chris Lattner | abb215e | 2003-08-11 21:28:59 +0000 | [diff] [blame] | 190 | Record *getResult() const { |
| 191 | return ResultNode ? ResultNode->getValueRecord() : 0; |
| 192 | } |
Chris Lattner | 57fb6ab | 2003-08-11 20:32:02 +0000 | [diff] [blame] | 193 | const std::string &getResultName() const { return ResultName; } |
Chris Lattner | abb215e | 2003-08-11 21:28:59 +0000 | [diff] [blame] | 194 | TreePatternNode *getResultNode() const { return ResultNode; } |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 195 | |
| 196 | /// getRecord - Return the actual TableGen record corresponding to this |
| 197 | /// pattern. |
| 198 | /// |
| 199 | Record *getRecord() const { return TheRecord; } |
| 200 | |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 201 | unsigned getNumArgs() const { return Args.size(); } |
| 202 | TreePatternNode *getArg(unsigned i) const { |
| 203 | assert(i < Args.size() && "Argument reference out of range!"); |
| 204 | return Args[i].first; |
| 205 | } |
| 206 | Record *getArgRec(unsigned i) const { |
| 207 | return getArg(i)->getValueRecord(); |
| 208 | } |
Chris Lattner | abb215e | 2003-08-11 21:28:59 +0000 | [diff] [blame] | 209 | Init *getArgVal(unsigned i) const { |
| 210 | return getArg(i)->getValue(); |
| 211 | } |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 212 | const std::string &getArgName(unsigned i) const { |
| 213 | assert(i < Args.size() && "Argument reference out of range!"); |
| 214 | return Args[i].second; |
| 215 | } |
| 216 | |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 217 | bool isResolved() const { return Resolved; } |
| 218 | |
Chris Lattner | ef0ce6a | 2003-08-07 23:16:20 +0000 | [diff] [blame] | 219 | /// InferAllTypes - Runs the type inference engine on the current pattern, |
| 220 | /// stopping when nothing can be inferred, then updating the Resolved field. |
| 221 | void InferAllTypes(); |
| 222 | |
| 223 | /// InstantiateNonterminals - If this pattern refers to any nonterminals which |
| 224 | /// are not themselves completely resolved, clone the nonterminal and resolve |
| 225 | /// it with the using context we provide. |
| 226 | void InstantiateNonterminals() { |
| 227 | Tree->InstantiateNonterminals(ISE); |
| 228 | } |
| 229 | |
| 230 | /// clone - This method is used to make an exact copy of the current pattern, |
| 231 | /// then change the "TheRecord" instance variable to the specified record. |
| 232 | /// |
| 233 | Pattern *clone(Record *R) const; |
| 234 | |
| 235 | /// error - Throw an exception, prefixing it with information about this |
| 236 | /// pattern. |
| 237 | void error(const std::string &Msg) const; |
| 238 | |
Chris Lattner | 955c1be | 2003-08-08 22:29:23 +0000 | [diff] [blame] | 239 | /// getSlotName - If this is a leaf node, return the slot name that the |
| 240 | /// operand will update. |
| 241 | std::string getSlotName() const; |
| 242 | static std::string getSlotName(Record *R); |
| 243 | |
Chris Lattner | 9552b8c | 2003-08-10 19:50:51 +0000 | [diff] [blame] | 244 | void dump() const; |
| 245 | |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 246 | private: |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 247 | void calculateArgs(TreePatternNode *N, const std::string &Name); |
Chris Lattner | 5709e51 | 2003-08-07 21:02:56 +0000 | [diff] [blame] | 248 | MVT::ValueType getIntrinsicType(Record *R) const; |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 249 | TreePatternNode *ParseTreePattern(DagInit *DI); |
| 250 | bool InferTypes(TreePatternNode *N, bool &MadeChange); |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | std::ostream &operator<<(std::ostream &OS, const Pattern &P); |
| 254 | |
| 255 | |
Chris Lattner | 6dafd39 | 2003-08-08 16:30:10 +0000 | [diff] [blame] | 256 | /// PatternOrganizer - This class represents all of the patterns which are |
| 257 | /// useful for the instruction selector, neatly catagorized in a hierarchical |
| 258 | /// structure. |
| 259 | struct PatternOrganizer { |
| 260 | /// PatternsForNode - The list of patterns which can produce a value of a |
| 261 | /// particular slot type, given a particular root node in the tree. All of |
| 262 | /// the patterns in this vector produce the same value type and have the same |
| 263 | /// root DAG node. |
| 264 | typedef std::vector<Pattern*> PatternsForNode; |
| 265 | |
| 266 | /// NodesForSlot - This map keeps track of all of the root DAG nodes which can |
| 267 | /// lead to the production of a value for this slot. All of the patterns in |
| 268 | /// this data structure produces values of the same slot. |
| 269 | typedef std::map<Record*, PatternsForNode> NodesForSlot; |
| 270 | |
| 271 | /// AllPatterns - This data structure contains all patterns in the instruction |
| 272 | /// selector. |
| 273 | std::map<std::string, NodesForSlot> AllPatterns; |
| 274 | |
| 275 | // Forwarding functions... |
| 276 | typedef std::map<std::string, NodesForSlot>::iterator iterator; |
| 277 | iterator begin() { return AllPatterns.begin(); } |
| 278 | iterator end() { return AllPatterns.end(); } |
| 279 | |
| 280 | |
| 281 | /// addPattern - Add the specified pattern to the appropriate location in the |
| 282 | /// collection. |
| 283 | void addPattern(Pattern *P); |
| 284 | }; |
| 285 | |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 286 | |
| 287 | /// InstrSelectorEmitter - The top-level class which coordinates construction |
| 288 | /// and emission of the instruction selector. |
| 289 | /// |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 290 | class InstrSelectorEmitter : public TableGenBackend { |
| 291 | RecordKeeper &Records; |
Chris Lattner | bc659dd | 2003-08-07 06:02:15 +0000 | [diff] [blame] | 292 | CodeGenTarget Target; |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 293 | |
| 294 | std::map<Record*, NodeType> NodeTypes; |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 295 | |
| 296 | /// Patterns - a list of all of the patterns defined by the target description |
| 297 | /// |
| 298 | std::map<Record*, Pattern*> Patterns; |
Chris Lattner | ef0ce6a | 2003-08-07 23:16:20 +0000 | [diff] [blame] | 299 | |
| 300 | /// InstantiatedNTs - A data structure to keep track of which nonterminals |
| 301 | /// have been instantiated already... |
| 302 | /// |
| 303 | std::map<std::pair<Pattern*,MVT::ValueType>, Record*> InstantiatedNTs; |
Chris Lattner | 6dafd39 | 2003-08-08 16:30:10 +0000 | [diff] [blame] | 304 | |
| 305 | /// ComputableValues - This map indicates which patterns can be used to |
| 306 | /// generate a value that is used by the selector. The keys of this map |
| 307 | /// implicitly define the values that are used by the selector. |
| 308 | /// |
| 309 | PatternOrganizer ComputableValues; |
| 310 | |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 311 | public: |
| 312 | InstrSelectorEmitter(RecordKeeper &R) : Records(R) {} |
| 313 | |
| 314 | // run - Output the instruction set description, returning true on failure. |
| 315 | void run(std::ostream &OS); |
| 316 | |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 317 | const CodeGenTarget &getTarget() const { return Target; } |
| 318 | std::map<Record*, NodeType> &getNodeTypes() { return NodeTypes; } |
Chris Lattner | 955c1be | 2003-08-08 22:29:23 +0000 | [diff] [blame] | 319 | const NodeType &getNodeType(Record *R) const { |
| 320 | std::map<Record*, NodeType>::const_iterator I = NodeTypes.find(R); |
| 321 | assert(I != NodeTypes.end() && "Unknown node type!"); |
| 322 | return I->second; |
| 323 | } |
Chris Lattner | f8e9683 | 2003-08-07 19:12:24 +0000 | [diff] [blame] | 324 | |
Chris Lattner | 5709e51 | 2003-08-07 21:02:56 +0000 | [diff] [blame] | 325 | /// getPattern - return the pattern corresponding to the specified record, or |
| 326 | /// null if there is none. |
| 327 | Pattern *getPattern(Record *R) const { |
| 328 | std::map<Record*, Pattern*>::const_iterator I = Patterns.find(R); |
| 329 | return I != Patterns.end() ? I->second : 0; |
| 330 | } |
| 331 | |
| 332 | /// ReadNonterminal - This method parses the specified record as a |
| 333 | /// nonterminal, but only if it hasn't been read in already. |
| 334 | Pattern *ReadNonterminal(Record *R); |
| 335 | |
Chris Lattner | ef0ce6a | 2003-08-07 23:16:20 +0000 | [diff] [blame] | 336 | /// InstantiateNonterminal - This method takes the nonterminal specified by |
| 337 | /// NT, which should not be completely resolved, clones it, applies ResultTy |
| 338 | /// to its root, then runs the type inference stuff on it. This should |
| 339 | /// produce a newly resolved nonterminal, which we make a record for and |
| 340 | /// return. To be extra fancy and efficient, this only makes one clone for |
| 341 | /// each type it is instantiated with. |
| 342 | Record *InstantiateNonterminal(Pattern *NT, MVT::ValueType ResultTy); |
| 343 | |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 344 | private: |
Chris Lattner | ee858d2 | 2003-08-07 20:42:23 +0000 | [diff] [blame] | 345 | // ReadNodeTypes - Read in all of the node types in the current RecordKeeper, |
| 346 | // turning them into the more accessible NodeTypes data structure. |
| 347 | void ReadNodeTypes(); |
Chris Lattner | 2787d1a | 2003-08-06 06:16:35 +0000 | [diff] [blame] | 348 | |
Chris Lattner | ee858d2 | 2003-08-07 20:42:23 +0000 | [diff] [blame] | 349 | // ReadNonTerminals - Read in all nonterminals and incorporate them into our |
| 350 | // pattern database. |
| 351 | void ReadNonterminals(); |
Chris Lattner | bc659dd | 2003-08-07 06:02:15 +0000 | [diff] [blame] | 352 | |
Chris Lattner | ee858d2 | 2003-08-07 20:42:23 +0000 | [diff] [blame] | 353 | // ReadInstructionPatterns - Read in all subclasses of Instruction, and |
Chris Lattner | 2787d1a | 2003-08-06 06:16:35 +0000 | [diff] [blame] | 354 | // process those with a useful Pattern field. |
Chris Lattner | ee858d2 | 2003-08-07 20:42:23 +0000 | [diff] [blame] | 355 | void ReadInstructionPatterns(); |
Chris Lattner | b356a24 | 2003-08-07 19:21:10 +0000 | [diff] [blame] | 356 | |
Chris Lattner | ee858d2 | 2003-08-07 20:42:23 +0000 | [diff] [blame] | 357 | // ReadExpanderPatterns - Read in all of the expanded patterns. |
| 358 | void ReadExpanderPatterns(); |
| 359 | |
| 360 | // InstantiateNonterminals - Instantiate any unresolved nonterminals with |
| 361 | // information from the context that they are used in. |
| 362 | void InstantiateNonterminals(); |
Chris Lattner | 6dafd39 | 2003-08-08 16:30:10 +0000 | [diff] [blame] | 363 | |
| 364 | // CalculateComputableValues - Fill in the ComputableValues map through |
| 365 | // analysis of the patterns we are playing with. |
| 366 | void CalculateComputableValues(); |
Chris Lattner | 955c1be | 2003-08-08 22:29:23 +0000 | [diff] [blame] | 367 | |
| 368 | // EmitMatchCosters - Given a list of patterns, which all have the same root |
| 369 | // pattern operator, emit an efficient decision tree to decide which one to |
| 370 | // pick. This is structured this way to avoid reevaluations of non-obvious |
| 371 | // subexpressions. |
| 372 | void EmitMatchCosters(std::ostream &OS, |
| 373 | const std::vector<std::pair<Pattern*, TreePatternNode*> > &Patterns, |
| 374 | const std::string &VarPrefix, unsigned Indent); |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 375 | |
| 376 | /// PrintExpanderOperand - Print out Arg as part of the instruction emission |
| 377 | /// process for the expander pattern P. This argument may be referencing some |
| 378 | /// values defined in P, or may just be physical register references or |
| 379 | /// something like that. If PrintArg is true, we are printing out arguments |
| 380 | /// to the BuildMI call. If it is false, we are printing the result register |
| 381 | /// name. |
| 382 | void PrintExpanderOperand(Init *Arg, const std::string &NameVar, |
Chris Lattner | abb215e | 2003-08-11 21:28:59 +0000 | [diff] [blame] | 383 | TreePatternNode *ArgDecl, Pattern *P, |
Chris Lattner | 053a205 | 2003-08-10 23:51:52 +0000 | [diff] [blame] | 384 | bool PrintArg, std::ostream &OS); |
Chris Lattner | faca5ab | 2003-08-06 05:42:05 +0000 | [diff] [blame] | 385 | }; |
| 386 | |
| 387 | #endif |