Chris Lattner | 947ecac | 2004-10-16 16:37:42 +0000 | [diff] [blame] | 1 | //===- SparcV9InstrForest.h - SparcV9 BURG Instruction Selector Trees -----===// |
Brian Gaeke | 16f092f | 2004-08-04 07:29:16 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // A forest of BURG instruction trees (class InstrForest) which represents |
| 11 | // a function to the BURG-based instruction selector, and a bunch of constants |
| 12 | // and declarations used by the generated BURG code. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SPARCV9INSTRFOREST_H |
| 17 | #define SPARCV9INSTRFOREST_H |
| 18 | |
| 19 | #include "llvm/Instruction.h" |
| 20 | using namespace llvm; |
| 21 | |
| 22 | /// OpLabel values for special-case nodes created for instruction selection. |
| 23 | /// All op-labels not defined here are identical to the instruction |
| 24 | /// opcode returned by Instruction::getOpcode(). |
| 25 | /// |
| 26 | static const int |
| 27 | InvalidOp = -1, |
| 28 | VRegListOp = 97, |
| 29 | VRegNodeOp = 98, |
| 30 | ConstantNodeOp = 99, |
| 31 | LabelNodeOp = 100, |
| 32 | RetValueOp = 100 + Instruction::Ret, // 101 |
| 33 | BrCondOp = 100 + Instruction::Br, // 102 |
| 34 | BAndOp = 100 + Instruction::And, // 111 |
| 35 | BOrOp = 100 + Instruction::Or, // 112 |
| 36 | BXorOp = 100 + Instruction::Xor, // 113 |
| 37 | BNotOp = 200 + Instruction::Xor, // 213 |
| 38 | NotOp = 300 + Instruction::Xor, // 313 |
| 39 | SetCCOp = 100 + Instruction::SetEQ, // 114 |
| 40 | AllocaN = 100 + Instruction::Alloca, // 122 |
| 41 | LoadIdx = 100 + Instruction::Load, // 123 |
| 42 | GetElemPtrIdx = 100 + Instruction::GetElementPtr, // 125 |
| 43 | ToBoolTy = 100 + Instruction::Cast; // 127 |
| 44 | static const int |
| 45 | ToUByteTy = ToBoolTy + 1, |
| 46 | ToSByteTy = ToBoolTy + 2, |
| 47 | ToUShortTy = ToBoolTy + 3, |
| 48 | ToShortTy = ToBoolTy + 4, |
| 49 | ToUIntTy = ToBoolTy + 5, |
| 50 | ToIntTy = ToBoolTy + 6, |
| 51 | ToULongTy = ToBoolTy + 7, |
| 52 | ToLongTy = ToBoolTy + 8, |
| 53 | ToFloatTy = ToBoolTy + 9, |
| 54 | ToDoubleTy = ToBoolTy + 10, |
| 55 | ToArrayTy = ToBoolTy + 11, |
| 56 | ToPointerTy = ToBoolTy + 12; |
| 57 | |
| 58 | /// Data types needed by BURG |
| 59 | /// |
| 60 | typedef int OpLabel; |
| 61 | typedef int StateLabel; |
| 62 | |
| 63 | /// Declarations of data and functions created by BURG |
| 64 | /// |
| 65 | namespace llvm { |
| 66 | class InstrTreeNode; |
| 67 | }; |
| 68 | extern short* burm_nts[]; |
| 69 | extern StateLabel burm_label (InstrTreeNode* p); |
| 70 | extern StateLabel burm_state (OpLabel op, StateLabel leftState, |
| 71 | StateLabel rightState); |
| 72 | extern StateLabel burm_rule (StateLabel state, int goalNT); |
| 73 | extern InstrTreeNode** burm_kids (InstrTreeNode* p, int eruleno, |
| 74 | InstrTreeNode* kids[]); |
| 75 | extern void printcover (InstrTreeNode*, int, int); |
| 76 | extern void printtree (InstrTreeNode*); |
| 77 | extern int treecost (InstrTreeNode*, int, int); |
| 78 | extern void printMatches (InstrTreeNode*); |
| 79 | |
| 80 | namespace llvm { |
| 81 | |
| 82 | /// InstrTreeNode - A single tree node in the instruction tree used for |
| 83 | /// instruction selection via BURG. |
| 84 | /// |
| 85 | class InstrTreeNode { |
| 86 | InstrTreeNode(const InstrTreeNode &); // DO NOT IMPLEMENT |
| 87 | void operator=(const InstrTreeNode &); // DO NOT IMPLEMENT |
| 88 | public: |
| 89 | enum InstrTreeNodeType { NTInstructionNode, |
| 90 | NTVRegListNode, |
| 91 | NTVRegNode, |
| 92 | NTConstNode, |
| 93 | NTLabelNode }; |
| 94 | InstrTreeNode* LeftChild; |
| 95 | InstrTreeNode* RightChild; |
| 96 | InstrTreeNode* Parent; |
| 97 | OpLabel opLabel; |
| 98 | StateLabel state; |
| 99 | |
| 100 | protected: |
| 101 | InstrTreeNodeType treeNodeType; |
| 102 | Value* val; |
| 103 | |
| 104 | public: |
| 105 | InstrTreeNode(InstrTreeNodeType nodeType, Value* _val) |
| 106 | : treeNodeType(nodeType), val(_val) { |
| 107 | LeftChild = RightChild = Parent = 0; |
| 108 | opLabel = InvalidOp; |
| 109 | } |
| 110 | virtual ~InstrTreeNode() { |
| 111 | delete LeftChild; |
| 112 | delete RightChild; |
| 113 | } |
| 114 | InstrTreeNodeType getNodeType () const { return treeNodeType; } |
| 115 | Value* getValue () const { return val; } |
| 116 | inline OpLabel getOpLabel () const { return opLabel; } |
| 117 | inline InstrTreeNode *leftChild () const { return LeftChild; } |
| 118 | inline InstrTreeNode *parent () const { return Parent; } |
| 119 | |
| 120 | // If right child is a list node, recursively get its *left* child |
| 121 | inline InstrTreeNode* rightChild() const { |
| 122 | return (!RightChild ? 0 : |
| 123 | (RightChild->getOpLabel() == VRegListOp |
| 124 | ? RightChild->LeftChild : RightChild)); |
| 125 | } |
| 126 | void dump(int dumpChildren, int indent) const; |
| 127 | protected: |
| 128 | virtual void dumpNode(int indent) const = 0; |
| 129 | friend class InstrForest; |
| 130 | }; |
| 131 | |
| 132 | } // end namespace llvm. |
| 133 | |
| 134 | #endif |