LLVM API Documentation
00001 //===- SparcV9InstrForest.h - SparcV9 BURG Instruction Selector Trees -----===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // A forest of BURG instruction trees (class InstrForest) which represents 00011 // a function to the BURG-based instruction selector, and a bunch of constants 00012 // and declarations used by the generated BURG code. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef SPARCV9INSTRFOREST_H 00017 #define SPARCV9INSTRFOREST_H 00018 00019 #include "llvm/Instruction.h" 00020 using namespace llvm; 00021 00022 /// OpLabel values for special-case nodes created for instruction selection. 00023 /// All op-labels not defined here are identical to the instruction 00024 /// opcode returned by Instruction::getOpcode(). 00025 /// 00026 static const int 00027 InvalidOp = -1, 00028 VRegListOp = 97, 00029 VRegNodeOp = 98, 00030 ConstantNodeOp = 99, 00031 LabelNodeOp = 100, 00032 RetValueOp = 100 + Instruction::Ret, // 101 00033 BrCondOp = 100 + Instruction::Br, // 102 00034 BAndOp = 100 + Instruction::And, // 111 00035 BOrOp = 100 + Instruction::Or, // 112 00036 BXorOp = 100 + Instruction::Xor, // 113 00037 BNotOp = 200 + Instruction::Xor, // 213 00038 NotOp = 300 + Instruction::Xor, // 313 00039 SetCCOp = 100 + Instruction::SetEQ, // 114 00040 AllocaN = 100 + Instruction::Alloca, // 122 00041 LoadIdx = 100 + Instruction::Load, // 123 00042 GetElemPtrIdx = 100 + Instruction::GetElementPtr, // 125 00043 ToBoolTy = 100 + Instruction::Cast; // 127 00044 static const int 00045 ToUByteTy = ToBoolTy + 1, 00046 ToSByteTy = ToBoolTy + 2, 00047 ToUShortTy = ToBoolTy + 3, 00048 ToShortTy = ToBoolTy + 4, 00049 ToUIntTy = ToBoolTy + 5, 00050 ToIntTy = ToBoolTy + 6, 00051 ToULongTy = ToBoolTy + 7, 00052 ToLongTy = ToBoolTy + 8, 00053 ToFloatTy = ToBoolTy + 9, 00054 ToDoubleTy = ToBoolTy + 10, 00055 ToArrayTy = ToBoolTy + 11, 00056 ToPointerTy = ToBoolTy + 12; 00057 00058 /// Data types needed by BURG 00059 /// 00060 typedef int OpLabel; 00061 typedef int StateLabel; 00062 00063 /// Declarations of data and functions created by BURG 00064 /// 00065 namespace llvm { 00066 class InstrTreeNode; 00067 }; 00068 extern short* burm_nts[]; 00069 extern StateLabel burm_label (InstrTreeNode* p); 00070 extern StateLabel burm_state (OpLabel op, StateLabel leftState, 00071 StateLabel rightState); 00072 extern StateLabel burm_rule (StateLabel state, int goalNT); 00073 extern InstrTreeNode** burm_kids (InstrTreeNode* p, int eruleno, 00074 InstrTreeNode* kids[]); 00075 extern void printcover (InstrTreeNode*, int, int); 00076 extern void printtree (InstrTreeNode*); 00077 extern int treecost (InstrTreeNode*, int, int); 00078 extern void printMatches (InstrTreeNode*); 00079 00080 namespace llvm { 00081 00082 /// InstrTreeNode - A single tree node in the instruction tree used for 00083 /// instruction selection via BURG. 00084 /// 00085 class InstrTreeNode { 00086 InstrTreeNode(const InstrTreeNode &); // DO NOT IMPLEMENT 00087 void operator=(const InstrTreeNode &); // DO NOT IMPLEMENT 00088 public: 00089 enum InstrTreeNodeType { NTInstructionNode, 00090 NTVRegListNode, 00091 NTVRegNode, 00092 NTConstNode, 00093 NTLabelNode }; 00094 InstrTreeNode* LeftChild; 00095 InstrTreeNode* RightChild; 00096 InstrTreeNode* Parent; 00097 OpLabel opLabel; 00098 StateLabel state; 00099 00100 protected: 00101 InstrTreeNodeType treeNodeType; 00102 Value* val; 00103 00104 public: 00105 InstrTreeNode(InstrTreeNodeType nodeType, Value* _val) 00106 : treeNodeType(nodeType), val(_val) { 00107 LeftChild = RightChild = Parent = 0; 00108 opLabel = InvalidOp; 00109 } 00110 virtual ~InstrTreeNode() { 00111 delete LeftChild; 00112 delete RightChild; 00113 } 00114 InstrTreeNodeType getNodeType () const { return treeNodeType; } 00115 Value* getValue () const { return val; } 00116 inline OpLabel getOpLabel () const { return opLabel; } 00117 inline InstrTreeNode *leftChild () const { return LeftChild; } 00118 inline InstrTreeNode *parent () const { return Parent; } 00119 00120 // If right child is a list node, recursively get its *left* child 00121 inline InstrTreeNode* rightChild() const { 00122 return (!RightChild ? 0 : 00123 (RightChild->getOpLabel() == VRegListOp 00124 ? RightChild->LeftChild : RightChild)); 00125 } 00126 void dump(int dumpChildren, int indent) const; 00127 protected: 00128 virtual void dumpNode(int indent) const = 0; 00129 friend class InstrForest; 00130 }; 00131 00132 } // end namespace llvm. 00133 00134 #endif