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

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

Issue 552653003: [turbofan] Fix the node matchers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address nit. Created 6 years, 3 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_COMPILER_COMMON_OPERATOR_H_ 5 #ifndef V8_COMPILER_COMMON_OPERATOR_H_
6 #define V8_COMPILER_COMMON_OPERATOR_H_ 6 #define V8_COMPILER_COMMON_OPERATOR_H_
7 7
8 #include "src/assembler.h" 8 #include "src/assembler.h"
9 #include "src/compiler/linkage.h" 9 #include "src/compiler/linkage.h"
10 #include "src/compiler/machine-type.h" 10 #include "src/compiler/machine-type.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 180 }
181 Operator* Projection(size_t index) { 181 Operator* Projection(size_t index) {
182 return new (zone_) Operator1<size_t>(IrOpcode::kProjection, Operator::kPure, 182 return new (zone_) Operator1<size_t>(IrOpcode::kProjection, Operator::kPure,
183 1, 1, "Projection", index); 183 1, 1, "Projection", index);
184 } 184 }
185 185
186 private: 186 private:
187 Zone* zone_; 187 Zone* zone_;
188 }; 188 };
189 189
190
191 template <typename T>
192 struct CommonOperatorTraits {
193 static inline bool Equals(T a, T b);
194 static inline bool HasValue(const Operator* op);
195 static inline T ValueOf(const Operator* op);
196 };
197
198 template <>
199 struct CommonOperatorTraits<int32_t> {
200 static inline bool Equals(int32_t a, int32_t b) { return a == b; }
201 static inline bool HasValue(const Operator* op) {
202 return op->opcode() == IrOpcode::kInt32Constant ||
203 op->opcode() == IrOpcode::kNumberConstant;
204 }
205 static inline int32_t ValueOf(const Operator* op) {
206 if (op->opcode() == IrOpcode::kNumberConstant) {
207 // TODO(titzer): cache the converted int32 value in NumberConstant.
208 return FastD2I(OpParameter<double>(op));
209 }
210 CHECK_EQ(IrOpcode::kInt32Constant, op->opcode());
211 return OpParameter<int32_t>(op);
212 }
213 };
214
215 template <>
216 struct CommonOperatorTraits<uint32_t> {
217 static inline bool Equals(uint32_t a, uint32_t b) { return a == b; }
218 static inline bool HasValue(const Operator* op) {
219 return CommonOperatorTraits<int32_t>::HasValue(op);
220 }
221 static inline uint32_t ValueOf(const Operator* op) {
222 if (op->opcode() == IrOpcode::kNumberConstant) {
223 // TODO(titzer): cache the converted uint32 value in NumberConstant.
224 return FastD2UI(OpParameter<double>(op));
225 }
226 return static_cast<uint32_t>(CommonOperatorTraits<int32_t>::ValueOf(op));
227 }
228 };
229
230 template <>
231 struct CommonOperatorTraits<int64_t> {
232 static inline bool Equals(int64_t a, int64_t b) { return a == b; }
233 static inline bool HasValue(const Operator* op) {
234 return op->opcode() == IrOpcode::kInt32Constant ||
235 op->opcode() == IrOpcode::kInt64Constant ||
236 op->opcode() == IrOpcode::kNumberConstant;
237 }
238 static inline int64_t ValueOf(const Operator* op) {
239 if (op->opcode() == IrOpcode::kInt32Constant) {
240 return static_cast<int64_t>(CommonOperatorTraits<int32_t>::ValueOf(op));
241 }
242 CHECK_EQ(IrOpcode::kInt64Constant, op->opcode());
243 return OpParameter<int64_t>(op);
244 }
245 };
246
247 template <>
248 struct CommonOperatorTraits<uint64_t> {
249 static inline bool Equals(uint64_t a, uint64_t b) { return a == b; }
250 static inline bool HasValue(const Operator* op) {
251 return CommonOperatorTraits<int64_t>::HasValue(op);
252 }
253 static inline uint64_t ValueOf(const Operator* op) {
254 return static_cast<uint64_t>(CommonOperatorTraits<int64_t>::ValueOf(op));
255 }
256 };
257
258 template <>
259 struct CommonOperatorTraits<double> {
260 static inline bool Equals(double a, double b) {
261 return DoubleRepresentation(a).bits == DoubleRepresentation(b).bits;
262 }
263 static inline bool HasValue(const Operator* op) {
264 return op->opcode() == IrOpcode::kFloat64Constant ||
265 op->opcode() == IrOpcode::kInt32Constant ||
266 op->opcode() == IrOpcode::kNumberConstant;
267 }
268 static inline double ValueOf(const Operator* op) {
269 if (op->opcode() == IrOpcode::kFloat64Constant ||
270 op->opcode() == IrOpcode::kNumberConstant) {
271 return OpParameter<double>(op);
272 }
273 return static_cast<double>(CommonOperatorTraits<int32_t>::ValueOf(op));
274 }
275 };
276
277 template <>
278 struct CommonOperatorTraits<ExternalReference> {
279 static inline bool Equals(ExternalReference a, ExternalReference b) {
280 return a == b;
281 }
282 static inline bool HasValue(const Operator* op) {
283 return op->opcode() == IrOpcode::kExternalConstant;
284 }
285 static inline ExternalReference ValueOf(const Operator* op) {
286 CHECK_EQ(IrOpcode::kExternalConstant, op->opcode());
287 return OpParameter<ExternalReference>(op);
288 }
289 };
290
291 template <typename T>
292 struct CommonOperatorTraits<Unique<T> > {
293 static inline bool HasValue(const Operator* op) {
294 return op->opcode() == IrOpcode::kHeapConstant;
295 }
296 static inline Unique<T> ValueOf(const Operator* op) {
297 CHECK_EQ(IrOpcode::kHeapConstant, op->opcode());
298 return OpParameter<Unique<T> >(op);
299 }
300 };
301
302 template <typename T>
303 struct CommonOperatorTraits<Handle<T> > {
304 static inline bool HasValue(const Operator* op) {
305 return CommonOperatorTraits<Unique<T> >::HasValue(op);
306 }
307 static inline Handle<T> ValueOf(const Operator* op) {
308 return CommonOperatorTraits<Unique<T> >::ValueOf(op).handle();
309 }
310 };
311
312
313 template <typename T>
314 inline T ValueOf(const Operator* op) {
315 return CommonOperatorTraits<T>::ValueOf(op);
316 }
317
318 } // namespace compiler 190 } // namespace compiler
319 } // namespace internal 191 } // namespace internal
320 } // namespace v8 192 } // namespace v8
321 193
322 #endif // V8_COMPILER_COMMON_OPERATOR_H_ 194 #endif // V8_COMPILER_COMMON_OPERATOR_H_
OLDNEW
« no previous file with comments | « src/compiler/arm64/instruction-selector-arm64-unittest.cc ('k') | src/compiler/ia32/instruction-selector-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698