blob: 2c70a29a39e7eccb57a4aaf1e969e2edb1373716 [file] [log] [blame]
Chris Lattner947ecac2004-10-16 16:37:42 +00001//===- SparcV9InstrForest.h - SparcV9 BURG Instruction Selector Trees -----===//
Brian Gaeke16f092f2004-08-04 07:29:16 +00002//
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"
20using 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///
26static 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
44static 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///
60typedef int OpLabel;
61typedef int StateLabel;
62
63/// Declarations of data and functions created by BURG
64///
65namespace llvm {
66 class InstrTreeNode;
67};
68extern short* burm_nts[];
69extern StateLabel burm_label (InstrTreeNode* p);
70extern StateLabel burm_state (OpLabel op, StateLabel leftState,
71 StateLabel rightState);
72extern StateLabel burm_rule (StateLabel state, int goalNT);
73extern InstrTreeNode** burm_kids (InstrTreeNode* p, int eruleno,
74 InstrTreeNode* kids[]);
75extern void printcover (InstrTreeNode*, int, int);
76extern void printtree (InstrTreeNode*);
77extern int treecost (InstrTreeNode*, int, int);
78extern void printMatches (InstrTreeNode*);
79
80namespace llvm {
81
82/// InstrTreeNode - A single tree node in the instruction tree used for
83/// instruction selection via BURG.
84///
85class InstrTreeNode {
86 InstrTreeNode(const InstrTreeNode &); // DO NOT IMPLEMENT
87 void operator=(const InstrTreeNode &); // DO NOT IMPLEMENT
88public:
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
100protected:
101 InstrTreeNodeType treeNodeType;
102 Value* val;
103
104public:
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;
127protected:
128 virtual void dumpNode(int indent) const = 0;
129 friend class InstrForest;
130};
131
132} // end namespace llvm.
133
134#endif