Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: src/compiler/common-operator.h

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback, rebase and "git cl format" Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/common-node-cache.h ('k') | src/compiler/control-builders.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_COMPILER_COMMON_OPERATOR_H_
6 #define V8_COMPILER_COMMON_OPERATOR_H_
7
8 #include "src/v8.h"
9
10 #include "src/assembler.h"
11 #include "src/compiler/linkage.h"
12 #include "src/compiler/opcodes.h"
13 #include "src/compiler/operator.h"
14 #include "src/unique.h"
15
16 namespace v8 {
17 namespace internal {
18
19 class OStream;
20
21 namespace compiler {
22
23 class ControlOperator : public Operator1<int> {
24 public:
25 ControlOperator(IrOpcode::Value opcode, uint16_t properties, int inputs,
26 int outputs, int controls, const char* mnemonic)
27 : Operator1(opcode, properties, inputs, outputs, mnemonic, controls) {}
28
29 virtual OStream& PrintParameter(OStream& os) const { return os; } // NOLINT
30 int ControlInputCount() const { return parameter(); }
31 };
32
33 class CallOperator : public Operator1<CallDescriptor*> {
34 public:
35 CallOperator(CallDescriptor* descriptor, const char* mnemonic)
36 : Operator1(IrOpcode::kCall, descriptor->properties(),
37 descriptor->InputCount(), descriptor->ReturnCount(), mnemonic,
38 descriptor) {}
39
40 virtual OStream& PrintParameter(OStream& os) const { // NOLINT
41 return os << "[" << *parameter() << "]";
42 }
43 };
44
45 class FrameStateDescriptor {
46 public:
47 explicit FrameStateDescriptor(BailoutId bailout_id)
48 : bailout_id_(bailout_id) {}
49
50 BailoutId bailout_id() const { return bailout_id_; }
51
52 private:
53 BailoutId bailout_id_;
54 };
55
56 // Interface for building common operators that can be used at any level of IR,
57 // including JavaScript, mid-level, and low-level.
58 // TODO(titzer): Move the mnemonics into SimpleOperator and Operator1 classes.
59 class CommonOperatorBuilder {
60 public:
61 explicit CommonOperatorBuilder(Zone* zone) : zone_(zone) {}
62
63 #define CONTROL_OP(name, inputs, controls) \
64 return new (zone_) ControlOperator(IrOpcode::k##name, Operator::kFoldable, \
65 inputs, 0, controls, #name);
66
67 Operator* Start() { CONTROL_OP(Start, 0, 0); }
68 Operator* Dead() { CONTROL_OP(Dead, 0, 0); }
69 Operator* End() { CONTROL_OP(End, 0, 1); }
70 Operator* Branch() { CONTROL_OP(Branch, 1, 1); }
71 Operator* IfTrue() { CONTROL_OP(IfTrue, 0, 1); }
72 Operator* IfFalse() { CONTROL_OP(IfFalse, 0, 1); }
73 Operator* Throw() { CONTROL_OP(Throw, 1, 1); }
74 Operator* LazyDeoptimization() { CONTROL_OP(LazyDeoptimization, 0, 1); }
75 Operator* Continuation() { CONTROL_OP(Continuation, 0, 1); }
76
77 Operator* Deoptimize() {
78 return new (zone_)
79 ControlOperator(IrOpcode::kDeoptimize, 0, 1, 0, 1, "Deoptimize");
80 }
81
82 Operator* Return() {
83 return new (zone_) ControlOperator(IrOpcode::kReturn, 0, 1, 0, 1, "Return");
84 }
85
86 Operator* Merge(int controls) {
87 return new (zone_) ControlOperator(IrOpcode::kMerge, Operator::kFoldable, 0,
88 0, controls, "Merge");
89 }
90
91 Operator* Loop(int controls) {
92 return new (zone_) ControlOperator(IrOpcode::kLoop, Operator::kFoldable, 0,
93 0, controls, "Loop");
94 }
95
96 Operator* Parameter(int index) {
97 return new (zone_) Operator1<int>(IrOpcode::kParameter, Operator::kPure, 0,
98 1, "Parameter", index);
99 }
100 Operator* Int32Constant(int32_t value) {
101 return new (zone_) Operator1<int>(IrOpcode::kInt32Constant, Operator::kPure,
102 0, 1, "Int32Constant", value);
103 }
104 Operator* Int64Constant(int64_t value) {
105 return new (zone_)
106 Operator1<int64_t>(IrOpcode::kInt64Constant, Operator::kPure, 0, 1,
107 "Int64Constant", value);
108 }
109 Operator* Float64Constant(double value) {
110 return new (zone_)
111 Operator1<double>(IrOpcode::kFloat64Constant, Operator::kPure, 0, 1,
112 "Float64Constant", value);
113 }
114 Operator* ExternalConstant(ExternalReference value) {
115 return new (zone_) Operator1<ExternalReference>(IrOpcode::kExternalConstant,
116 Operator::kPure, 0, 1,
117 "ExternalConstant", value);
118 }
119 Operator* NumberConstant(double value) {
120 return new (zone_)
121 Operator1<double>(IrOpcode::kNumberConstant, Operator::kPure, 0, 1,
122 "NumberConstant", value);
123 }
124 Operator* HeapConstant(PrintableUnique<Object> value) {
125 return new (zone_) Operator1<PrintableUnique<Object> >(
126 IrOpcode::kHeapConstant, Operator::kPure, 0, 1, "HeapConstant", value);
127 }
128 Operator* Phi(int arguments) {
129 ASSERT(arguments > 0); // Disallow empty phis.
130 return new (zone_) Operator1<int>(IrOpcode::kPhi, Operator::kPure,
131 arguments, 1, "Phi", arguments);
132 }
133 Operator* EffectPhi(int arguments) {
134 ASSERT(arguments > 0); // Disallow empty phis.
135 return new (zone_) Operator1<int>(IrOpcode::kEffectPhi, Operator::kPure, 0,
136 0, "EffectPhi", arguments);
137 }
138 Operator* FrameState(const FrameStateDescriptor& descriptor) {
139 return new (zone_) Operator1<FrameStateDescriptor>(
140 IrOpcode::kFrameState, Operator::kPure, 0, 1, "FrameState", descriptor);
141 }
142 Operator* Call(CallDescriptor* descriptor) {
143 return new (zone_) CallOperator(descriptor, "Call");
144 }
145 Operator* Projection(int index) {
146 return new (zone_) Operator1<int>(IrOpcode::kProjection, Operator::kPure, 1,
147 1, "Projection", index);
148 }
149
150 private:
151 Zone* zone_;
152 };
153
154
155 template <typename T>
156 struct CommonOperatorTraits {
157 static inline bool Equals(T a, T b);
158 static inline bool HasValue(Operator* op);
159 static inline T ValueOf(Operator* op);
160 };
161
162 template <>
163 struct CommonOperatorTraits<int32_t> {
164 static inline bool Equals(int32_t a, int32_t b) { return a == b; }
165 static inline bool HasValue(Operator* op) {
166 return op->opcode() == IrOpcode::kInt32Constant ||
167 op->opcode() == IrOpcode::kNumberConstant;
168 }
169 static inline int32_t ValueOf(Operator* op) {
170 if (op->opcode() == IrOpcode::kNumberConstant) {
171 // TODO(titzer): cache the converted int32 value in NumberConstant.
172 return FastD2I(reinterpret_cast<Operator1<double>*>(op)->parameter());
173 }
174 CHECK_EQ(IrOpcode::kInt32Constant, op->opcode());
175 return static_cast<Operator1<int32_t>*>(op)->parameter();
176 }
177 };
178
179 template <>
180 struct CommonOperatorTraits<uint32_t> {
181 static inline bool Equals(uint32_t a, uint32_t b) { return a == b; }
182 static inline bool HasValue(Operator* op) {
183 return CommonOperatorTraits<int32_t>::HasValue(op);
184 }
185 static inline uint32_t ValueOf(Operator* op) {
186 if (op->opcode() == IrOpcode::kNumberConstant) {
187 // TODO(titzer): cache the converted uint32 value in NumberConstant.
188 return FastD2UI(reinterpret_cast<Operator1<double>*>(op)->parameter());
189 }
190 return static_cast<uint32_t>(CommonOperatorTraits<int32_t>::ValueOf(op));
191 }
192 };
193
194 template <>
195 struct CommonOperatorTraits<int64_t> {
196 static inline bool Equals(int64_t a, int64_t b) { return a == b; }
197 static inline bool HasValue(Operator* op) {
198 return op->opcode() == IrOpcode::kInt32Constant ||
199 op->opcode() == IrOpcode::kInt64Constant ||
200 op->opcode() == IrOpcode::kNumberConstant;
201 }
202 static inline int64_t ValueOf(Operator* op) {
203 if (op->opcode() == IrOpcode::kInt32Constant) {
204 return static_cast<int64_t>(CommonOperatorTraits<int32_t>::ValueOf(op));
205 }
206 CHECK_EQ(IrOpcode::kInt64Constant, op->opcode());
207 return static_cast<Operator1<int64_t>*>(op)->parameter();
208 }
209 };
210
211 template <>
212 struct CommonOperatorTraits<uint64_t> {
213 static inline bool Equals(uint64_t a, uint64_t b) { return a == b; }
214 static inline bool HasValue(Operator* op) {
215 return CommonOperatorTraits<int64_t>::HasValue(op);
216 }
217 static inline uint64_t ValueOf(Operator* op) {
218 return static_cast<uint64_t>(CommonOperatorTraits<int64_t>::ValueOf(op));
219 }
220 };
221
222 template <>
223 struct CommonOperatorTraits<double> {
224 static inline bool Equals(double a, double b) {
225 return DoubleRepresentation(a).bits == DoubleRepresentation(b).bits;
226 }
227 static inline bool HasValue(Operator* op) {
228 return op->opcode() == IrOpcode::kFloat64Constant ||
229 op->opcode() == IrOpcode::kInt32Constant ||
230 op->opcode() == IrOpcode::kNumberConstant;
231 }
232 static inline double ValueOf(Operator* op) {
233 if (op->opcode() == IrOpcode::kFloat64Constant ||
234 op->opcode() == IrOpcode::kNumberConstant) {
235 return reinterpret_cast<Operator1<double>*>(op)->parameter();
236 }
237 return static_cast<double>(CommonOperatorTraits<int32_t>::ValueOf(op));
238 }
239 };
240
241 template <>
242 struct CommonOperatorTraits<ExternalReference> {
243 static inline bool Equals(ExternalReference a, ExternalReference b) {
244 return a == b;
245 }
246 static inline bool HasValue(Operator* op) {
247 return op->opcode() == IrOpcode::kExternalConstant;
248 }
249 static inline ExternalReference ValueOf(Operator* op) {
250 CHECK_EQ(IrOpcode::kExternalConstant, op->opcode());
251 return static_cast<Operator1<ExternalReference>*>(op)->parameter();
252 }
253 };
254
255 template <typename T>
256 struct CommonOperatorTraits<PrintableUnique<T> > {
257 static inline bool HasValue(Operator* op) {
258 return op->opcode() == IrOpcode::kHeapConstant;
259 }
260 static inline PrintableUnique<T> ValueOf(Operator* op) {
261 CHECK_EQ(IrOpcode::kHeapConstant, op->opcode());
262 return static_cast<Operator1<PrintableUnique<T> >*>(op)->parameter();
263 }
264 };
265
266 template <typename T>
267 struct CommonOperatorTraits<Handle<T> > {
268 static inline bool HasValue(Operator* op) {
269 return CommonOperatorTraits<PrintableUnique<T> >::HasValue(op);
270 }
271 static inline Handle<T> ValueOf(Operator* op) {
272 return CommonOperatorTraits<PrintableUnique<T> >::ValueOf(op).handle();
273 }
274 };
275
276
277 template <typename T>
278 inline T ValueOf(Operator* op) {
279 return CommonOperatorTraits<T>::ValueOf(op);
280 }
281 }
282 }
283 } // namespace v8::internal::compiler
284
285 #endif // V8_COMPILER_COMMON_OPERATOR_H_
OLDNEW
« no previous file with comments | « src/compiler/common-node-cache.h ('k') | src/compiler/control-builders.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698