OLD | NEW |
---|---|
(Empty) | |
1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// | |
2 // | |
3 // The Subzero Code Generator | |
4 // | |
5 // This file is distributed under the University of Illinois Open Source | |
6 // License. See LICENSE.TXT for details. | |
7 // | |
8 //===----------------------------------------------------------------------===// | |
9 // | |
10 // This file declares the IceOperand class and its target-independent | |
11 // subclasses. The main classes are IceVariable, which represents an | |
12 // LLVM variable that is either register- or stack-allocated, and the | |
JF
2014/04/16 01:27:32
Do variables even have a concept of stack at the I
Jim Stichnoth
2014/04/21 20:26:40
I guess you'd say they are SSA values that are ult
| |
13 // IceConstant hierarchy, which represents integer, floating-point, | |
14 // and/or symbolic constants. | |
15 // | |
16 //===----------------------------------------------------------------------===// | |
17 | |
18 #ifndef SUBZERO_SRC_ICEOPERAND_H | |
19 #define SUBZERO_SRC_ICEOPERAND_H | |
20 | |
21 #include "IceDefs.h" | |
22 #include "IceTypes.h" | |
23 | |
24 class IceOperand { | |
25 public: | |
26 enum OperandKind { | |
27 Constant, | |
JF
2014/04/16 01:27:32
What's constant but not Int/FP/Reloc?
Jim Stichnoth
2014/04/21 20:26:40
Constant is the abstract superclass of all the con
| |
28 ConstantInteger, | |
29 ConstantFloat, | |
30 ConstantDouble, | |
31 ConstantRelocatable, | |
32 Constant_Num, | |
33 Variable, | |
34 // Target-specific operand classes use Target as the starting | |
35 // point for their Kind enum space. | |
36 Target | |
37 }; | |
38 OperandKind getKind() const { return Kind; } | |
39 IceType getType() const { return Type; } | |
40 | |
41 // Every IceOperand keeps an array of the IceVariables referenced in | |
42 // the operand. This is so that the liveness operations can get | |
43 // quick access to the variables of interest, without having to dig | |
44 // so far into the operand. | |
45 uint32_t getNumVars() const { return NumVars; } | |
46 IceVariable *getVar(uint32_t I) const { | |
47 assert(I < getNumVars()); | |
48 return Vars[I]; | |
49 } | |
50 virtual void setUse(const IceInst *Inst, const IceCfgNode *Node) {} | |
JF
2014/04/16 01:27:32
Make this pure virtual, error out for constant and
Jim Stichnoth
2014/04/21 20:26:40
Better yet, take this method out of IceOperand and
| |
51 virtual void dump(const IceCfg *Cfg) const = 0; | |
52 | |
53 virtual ~IceOperand() {} | |
JF
2014/04/16 01:27:32
Ditto on private virtual dtors in derived classes.
Jim Stichnoth
2014/04/21 20:26:40
Done, though I needed to make ~IceConstant() prote
| |
54 | |
55 protected: | |
56 IceOperand(OperandKind Kind, IceType Type) : Type(Type), Kind(Kind) {} | |
JF
2014/04/16 01:27:32
You should initialize NumVars(0), Vars(NULL) to be
Jim Stichnoth
2014/04/21 20:26:40
Done.
| |
57 const IceType Type; | |
58 const OperandKind Kind; | |
59 // Vars and NumVars are initialized by the derived class. | |
60 uint32_t NumVars; | |
61 IceVariable **Vars; | |
62 | |
63 private: | |
64 IceOperand(const IceOperand &) LLVM_DELETED_FUNCTION; | |
65 IceOperand &operator=(const IceOperand &) LLVM_DELETED_FUNCTION; | |
66 }; | |
67 | |
68 // IceConstant is the abstract base class for constants. All | |
69 // constants are allocated from a global arena and are pooled. | |
70 class IceConstant : public IceOperand { | |
71 public: | |
72 virtual void dump(const IceCfg *Cfg) const = 0; | |
73 | |
74 static bool classof(const IceOperand *Operand) { | |
75 OperandKind Kind = Operand->getKind(); | |
76 return Kind >= Constant && Kind <= Constant_Num; | |
77 } | |
78 | |
79 protected: | |
80 IceConstant(OperandKind Kind, IceType Type) : IceOperand(Kind, Type) { | |
81 Vars = NULL; | |
82 NumVars = 0; | |
83 } | |
84 | |
85 private: | |
86 IceConstant(const IceConstant &) LLVM_DELETED_FUNCTION; | |
87 IceConstant &operator=(const IceConstant &) LLVM_DELETED_FUNCTION; | |
88 }; | |
89 | |
90 // IceConstantPrimitive<> wraps a primitive type. | |
91 template <typename T, IceOperand::OperandKind K> | |
92 class IceConstantPrimitive : public IceConstant { | |
93 public: | |
94 static IceConstantPrimitive *create(IceGlobalContext *Ctx, IceType Type, | |
95 T Value) { | |
96 return new (Ctx->allocate<IceConstantPrimitive>()) | |
97 IceConstantPrimitive(Type, Value); | |
98 } | |
99 T getValue() const { return Value; } | |
100 virtual void dump(const IceCfg *Cfg) const { | |
101 IceOstream &Str = Cfg->getContext()->StrDump; | |
102 Str << getValue(); | |
103 } | |
104 | |
105 static bool classof(const IceOperand *Operand) { | |
106 return Operand->getKind() == K; | |
107 } | |
108 | |
109 private: | |
110 IceConstantPrimitive(IceType Type, T Value) | |
111 : IceConstant(K, Type), Value(Value) {} | |
112 IceConstantPrimitive(const IceConstantPrimitive &) LLVM_DELETED_FUNCTION; | |
113 IceConstantPrimitive & | |
114 operator=(const IceConstantPrimitive &) LLVM_DELETED_FUNCTION; | |
115 const T Value; | |
116 }; | |
117 | |
118 typedef IceConstantPrimitive<uint64_t, IceOperand::ConstantInteger> | |
119 IceConstantInteger; | |
120 typedef IceConstantPrimitive<float, IceOperand::ConstantFloat> IceConstantFloat; | |
121 typedef IceConstantPrimitive<double, IceOperand::ConstantDouble> | |
122 IceConstantDouble; | |
123 | |
124 // IceConstantRelocatable represents a symbolic constant combined with | |
125 // a fixed offset. | |
126 class IceConstantRelocatable : public IceConstant { | |
127 public: | |
128 static IceConstantRelocatable *create(IceGlobalContext *Ctx, uint32_t CPIndex, | |
129 IceType Type, const void *Handle, | |
130 int64_t Offset, | |
131 const IceString &Name = "") { | |
132 return new (Ctx->allocate<IceConstantRelocatable>()) | |
133 IceConstantRelocatable(Type, Handle, Offset, Name, CPIndex); | |
134 } | |
135 uint32_t getCPIndex() const { return CPIndex; } | |
136 const void *getHandle() const { return Handle; } | |
137 int64_t getOffset() const { return Offset; } | |
138 IceString getName() const { return Name; } | |
139 void setSuppressMangling(bool Value) { SuppressMangling = Value; } | |
140 bool getSuppressMangling() const { return SuppressMangling; } | |
141 virtual void dump(const IceCfg *Cfg) const; | |
142 | |
143 static bool classof(const IceOperand *Operand) { | |
144 OperandKind Kind = Operand->getKind(); | |
145 return Kind == ConstantRelocatable; | |
146 } | |
147 | |
148 private: | |
149 IceConstantRelocatable(IceType Type, const void *Handle, int64_t Offset, | |
150 const IceString &Name, uint32_t CPIndex) | |
151 : IceConstant(ConstantRelocatable, Type), CPIndex(CPIndex), | |
152 Handle(Handle), Offset(Offset), Name(Name), SuppressMangling(false) {} | |
153 IceConstantRelocatable(const IceConstantRelocatable &) LLVM_DELETED_FUNCTION; | |
154 IceConstantRelocatable & | |
155 operator=(const IceConstantRelocatable &) LLVM_DELETED_FUNCTION; | |
156 const uint32_t CPIndex; // index into ICE constant pool | |
157 const void *const Handle; // opaque handle e.g. to LLVM | |
158 const int64_t Offset; // fixed offset to add | |
159 const IceString Name; // optional for debug/dump | |
160 bool SuppressMangling; | |
161 }; | |
162 | |
163 // IceVariable represents an operand that is register-allocated or | |
164 // stack-allocated. If it is register-allocated, it will ultimately | |
165 // have a non-negative RegNum field. | |
166 class IceVariable : public IceOperand { | |
167 public: | |
168 static IceVariable *create(IceCfg *Cfg, IceType Type, const IceCfgNode *Node, | |
169 uint32_t Index, const IceString &Name) { | |
170 return new (Cfg->allocate<IceVariable>()) | |
171 IceVariable(Type, Node, Index, Name); | |
172 } | |
173 | |
174 uint32_t getIndex() const { return Number; } | |
175 IceString getName() const; | |
176 | |
177 IceInst *getDefinition() const { return DefInst; } | |
178 void setDefinition(IceInst *Inst, const IceCfgNode *Node); | |
179 void replaceDefinition(IceInst *Inst, const IceCfgNode *Node); | |
180 | |
181 const IceCfgNode *getLocalUseNode() const { return DefNode; } | |
182 bool isMultiblockLife() const { return (DefNode == NULL); } | |
183 void setUse(const IceInst *Inst, const IceCfgNode *Node); | |
184 | |
185 bool getIsArg() const { return IsArgument; } | |
186 void setIsArg(IceCfg *Cfg); | |
187 | |
188 virtual void dump(const IceCfg *Cfg) const; | |
189 | |
190 static bool classof(const IceOperand *Operand) { | |
191 return Operand->getKind() == Variable; | |
192 } | |
193 | |
194 private: | |
195 IceVariable(IceType Type, const IceCfgNode *Node, uint32_t Index, | |
196 const IceString &Name) | |
197 : IceOperand(Variable, Type), Number(Index), Name(Name), DefInst(NULL), | |
198 DefNode(Node), IsArgument(false) { | |
199 Vars = VarsReal; | |
200 Vars[0] = this; | |
201 NumVars = 1; | |
202 } | |
203 IceVariable(const IceVariable &) LLVM_DELETED_FUNCTION; | |
204 IceVariable &operator=(const IceVariable &) LLVM_DELETED_FUNCTION; | |
205 // Number is unique across all variables, and is used as a | |
206 // (bit)vector index for liveness analysis. | |
207 const uint32_t Number; | |
208 // Name is optional. | |
209 const IceString Name; | |
210 // DefInst is the instruction that produces this variable as its | |
211 // dest. | |
212 IceInst *DefInst; | |
213 // DefNode is the node where this variable was produced, and is | |
214 // reset to NULL if it is used outside that node. This is used for | |
215 // detecting isMultiblockLife(). | |
216 const IceCfgNode *DefNode; | |
217 bool IsArgument; | |
218 // VarsReal (and IceOperand::Vars) are set up such that Vars[0] == | |
219 // this. | |
220 IceVariable *VarsReal[1]; | |
221 }; | |
222 | |
223 #endif // SUBZERO_SRC_ICEOPERAND_H | |
OLD | NEW |