1 //===- SparcV9InstrForest.h - SparcV9 BURG Instruction Selector Trees -----===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef SPARCV9INSTRFOREST_H
17 #define SPARCV9INSTRFOREST_H
19 #include "llvm/Instruction.h"
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().
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
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;
58 /// Data types needed by BURG
61 typedef int StateLabel;
63 /// Declarations of data and functions created by BURG
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*);
82 /// InstrTreeNode - A single tree node in the instruction tree used for
83 /// instruction selection via BURG.
86 InstrTreeNode(const InstrTreeNode &); // DO NOT IMPLEMENT
87 void operator=(const InstrTreeNode &); // DO NOT IMPLEMENT
89 enum InstrTreeNodeType { NTInstructionNode,
94 InstrTreeNode* LeftChild;
95 InstrTreeNode* RightChild;
96 InstrTreeNode* Parent;
101 InstrTreeNodeType treeNodeType;
105 InstrTreeNode(InstrTreeNodeType nodeType, Value* _val)
106 : treeNodeType(nodeType), val(_val) {
107 LeftChild = RightChild = Parent = 0;
110 virtual ~InstrTreeNode() {
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; }
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));
126 void dump(int dumpChildren, int indent) const;
128 virtual void dumpNode(int indent) const = 0;
129 friend class InstrForest;
132 } // end namespace llvm.