aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/SparcV9/SparcV9InstrForest.h
blob: 2c70a29a39e7eccb57a4aaf1e969e2edb1373716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//===- SparcV9InstrForest.h - SparcV9 BURG Instruction Selector Trees -----===//
// 
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
// 
//===----------------------------------------------------------------------===//
//
// A forest of BURG instruction trees (class InstrForest) which represents
// a function to the BURG-based instruction selector, and a bunch of constants
// and declarations used by the generated BURG code.
//	
//===----------------------------------------------------------------------===//

#ifndef SPARCV9INSTRFOREST_H
#define SPARCV9INSTRFOREST_H

#include "llvm/Instruction.h"
using namespace llvm;

/// OpLabel values for special-case nodes created for instruction selection.
/// All op-labels not defined here are identical to the instruction
/// opcode returned by Instruction::getOpcode().
///
static const int
 InvalidOp	= -1,
 VRegListOp     = 97,
 VRegNodeOp	= 98,
 ConstantNodeOp = 99,
 LabelNodeOp	= 100,
 RetValueOp	= 100 + Instruction::Ret,               // 101
 BrCondOp	= 100 + Instruction::Br,                // 102
 BAndOp         = 100 + Instruction::And,               // 111
 BOrOp          = 100 + Instruction::Or,                // 112
 BXorOp         = 100 + Instruction::Xor,               // 113
 BNotOp         = 200 + Instruction::Xor,               // 213
  NotOp         = 300 + Instruction::Xor,               // 313
 SetCCOp	= 100 + Instruction::SetEQ,             // 114
 AllocaN	= 100 + Instruction::Alloca,		// 122
 LoadIdx	= 100 + Instruction::Load,		// 123
 GetElemPtrIdx  = 100 + Instruction::GetElementPtr,	// 125
 ToBoolTy	= 100 + Instruction::Cast;		// 127
static const int
 ToUByteTy	= ToBoolTy +  1,
 ToSByteTy	= ToBoolTy +  2,
 ToUShortTy	= ToBoolTy +  3,
 ToShortTy	= ToBoolTy +  4,
 ToUIntTy	= ToBoolTy +  5,
 ToIntTy	= ToBoolTy +  6,
 ToULongTy	= ToBoolTy +  7,
 ToLongTy	= ToBoolTy +  8,
 ToFloatTy	= ToBoolTy +  9,
 ToDoubleTy	= ToBoolTy + 10,
 ToArrayTy	= ToBoolTy + 11,
 ToPointerTy	= ToBoolTy + 12;

/// Data types needed by BURG
///
typedef int OpLabel;
typedef int StateLabel;

/// Declarations of data and functions created by BURG
///
namespace llvm { 
  class InstrTreeNode;
};
extern short*		burm_nts[];
extern StateLabel	burm_label	(InstrTreeNode* p);
extern StateLabel	burm_state	(OpLabel op, StateLabel leftState,
					 StateLabel rightState);
extern StateLabel	burm_rule	(StateLabel state, int goalNT);
extern InstrTreeNode**  burm_kids	(InstrTreeNode* p, int eruleno,
					 InstrTreeNode* kids[]);
extern void		printcover	(InstrTreeNode*, int, int);
extern void		printtree	(InstrTreeNode*);
extern int		treecost	(InstrTreeNode*, int, int);
extern void		printMatches	(InstrTreeNode*);

namespace llvm {

/// InstrTreeNode - A single tree node in the instruction tree used for
/// instruction selection via BURG.
///
class InstrTreeNode {
  InstrTreeNode(const InstrTreeNode &);   // DO NOT IMPLEMENT
  void operator=(const InstrTreeNode &);  // DO NOT IMPLEMENT
public:
  enum InstrTreeNodeType { NTInstructionNode,
			   NTVRegListNode,
			   NTVRegNode,
			   NTConstNode,
			   NTLabelNode };
  InstrTreeNode* LeftChild;
  InstrTreeNode* RightChild;
  InstrTreeNode* Parent;
  OpLabel        opLabel;
  StateLabel     state;

protected:
  InstrTreeNodeType treeNodeType;
  Value*	   val;
  
public:
  InstrTreeNode(InstrTreeNodeType nodeType, Value* _val)
    : treeNodeType(nodeType), val(_val) {
    LeftChild = RightChild = Parent = 0;
    opLabel   = InvalidOp;
  }
  virtual ~InstrTreeNode() {
    delete LeftChild;
    delete RightChild;
  }
  InstrTreeNodeType	getNodeType	() const { return treeNodeType; }
  Value*		getValue	() const { return val; }
  inline OpLabel	getOpLabel	() const { return opLabel; }
  inline InstrTreeNode *leftChild       () const { return LeftChild; }
  inline InstrTreeNode *parent          () const { return Parent; }
  
  // If right child is a list node, recursively get its *left* child
  inline InstrTreeNode* rightChild() const {
    return (!RightChild ? 0 : 
	    (RightChild->getOpLabel() == VRegListOp
	     ? RightChild->LeftChild : RightChild));
  }
  void dump(int dumpChildren, int indent) const;
protected:
  virtual void dumpNode(int indent) const = 0;
  friend class InstrForest;
};

} // end namespace llvm.

#endif