1 //===- InstrInfoEmitter.h - Generate a Instruction Set Desc. ----*- C++ -*-===//
3 // This tablegen backend is responsible for emitting a description of the target
4 // instruction set for the code generator.
6 //===----------------------------------------------------------------------===//
8 #ifndef INSTRSELECTOR_EMITTER_H
9 #define INSTRSELECTOR_EMITTER_H
11 #include "TableGenBackend.h"
12 #include "llvm/CodeGen/ValueTypes.h"
20 // Both argument and return types...
21 Val, // A non-void type
22 Arg0, // Value matches the type of Arg0
23 Ptr, // Tree node is the type of the target pointer
26 Void, // Tree node always returns void
29 ArgResultTypes ResultType;
30 std::vector<ArgResultTypes> ArgTypes;
32 NodeType(ArgResultTypes RT, std::vector<ArgResultTypes> &AT) : ResultType(RT){
36 NodeType() : ResultType(Val) {}
37 NodeType(const NodeType &N) : ResultType(N.ResultType), ArgTypes(N.ArgTypes){}
39 static ArgResultTypes Translate(Record *R);
42 class TreePatternNode {
43 /// Operator - The operation that this node represents... this is null if this
47 /// Type - The inferred value type...
50 /// Children - If this is not a leaf (Operator != 0), this is the subtrees
52 std::vector<TreePatternNode*> Children;
54 /// Value - If this node is a leaf, this indicates what the thing is.
57 TreePatternNode(Record *o, const std::vector<TreePatternNode*> &c)
58 : Operator(o), Type(MVT::Other), Children(c), Value(0) {}
59 TreePatternNode(Init *V) : Operator(0), Type(MVT::Other), Value(V) {}
61 Record *getOperator() const { return Operator; }
62 MVT::ValueType getType() const { return Type; }
63 void setType(MVT::ValueType T) { Type = T; }
65 bool isLeaf() const { return Operator == 0; }
67 const std::vector<TreePatternNode*> &getChildren() const {
68 assert(Operator != 0 && "This is a leaf node!");
71 Init *getValue() const {
72 assert(Operator == 0 && "This is not a leaf node!");
79 std::ostream &operator<<(std::ostream &OS, const TreePatternNode &N);
83 class InstrSelectorEmitter : public TableGenBackend {
84 RecordKeeper &Records;
86 std::map<Record*, NodeType> NodeTypes;
88 InstrSelectorEmitter(RecordKeeper &R) : Records(R) {}
90 // run - Output the instruction set description, returning true on failure.
91 void run(std::ostream &OS);
94 // ProcessNodeTypes - Process all of the node types in the current
95 // RecordKeeper, turning them into the more accessible NodeTypes data
97 void ProcessNodeTypes();
99 // ProcessInstructionPatterns - Read in all subclasses of Instruction, and
100 // process those with a useful Pattern field.
101 void ProcessInstructionPatterns();
103 // ParseTreePattern - Parse the specified DagInit into a TreePattern which we
106 TreePatternNode *ParseTreePattern(DagInit *DI, const std::string &RecName);
108 // InferTypes - Perform type inference on the tree, returning true if there
109 // are any remaining untyped nodes and setting MadeChange if any changes were
111 bool InferTypes(TreePatternNode *N, const std::string &RecName,
114 // ReadAndCheckPattern - Parse the specified DagInit into a pattern and then
115 // perform full type inference.
116 TreePatternNode *ReadAndCheckPattern(DagInit *DI, const std::string &RecName);