1 // Copyright 2014 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.
5 #ifndef V8_COMPILER_SIMPLIFIED_NODE_FACTORY_H_
6 #define V8_COMPILER_SIMPLIFIED_NODE_FACTORY_H_
8 #include "src/compiler/node.h"
9 #include "src/compiler/simplified-operator.h"
15 #define SIMPLIFIED() static_cast<NodeFactory*>(this)->simplified()
16 #define NEW_NODE_1(op, a) static_cast<NodeFactory*>(this)->NewNode(op, a)
17 #define NEW_NODE_2(op, a, b) static_cast<NodeFactory*>(this)->NewNode(op, a, b)
18 #define NEW_NODE_3(op, a, b, c) \
19 static_cast<NodeFactory*>(this)->NewNode(op, a, b, c)
21 template <typename NodeFactory>
22 class SimplifiedNodeFactory {
24 Node* BooleanNot(Node* a) {
25 return NEW_NODE_1(SIMPLIFIED()->BooleanNot(), a);
28 Node* NumberEqual(Node* a, Node* b) {
29 return NEW_NODE_2(SIMPLIFIED()->NumberEqual(), a, b);
31 Node* NumberNotEqual(Node* a, Node* b) {
32 return NEW_NODE_2(SIMPLIFIED()->NumberNotEqual(), a, b);
34 Node* NumberLessThan(Node* a, Node* b) {
35 return NEW_NODE_2(SIMPLIFIED()->NumberLessThan(), a, b);
37 Node* NumberLessThanOrEqual(Node* a, Node* b) {
38 return NEW_NODE_2(SIMPLIFIED()->NumberLessThanOrEqual(), a, b);
40 Node* NumberAdd(Node* a, Node* b) {
41 return NEW_NODE_2(SIMPLIFIED()->NumberAdd(), a, b);
43 Node* NumberSubtract(Node* a, Node* b) {
44 return NEW_NODE_2(SIMPLIFIED()->NumberSubtract(), a, b);
46 Node* NumberMultiply(Node* a, Node* b) {
47 return NEW_NODE_2(SIMPLIFIED()->NumberMultiply(), a, b);
49 Node* NumberDivide(Node* a, Node* b) {
50 return NEW_NODE_2(SIMPLIFIED()->NumberDivide(), a, b);
52 Node* NumberModulus(Node* a, Node* b) {
53 return NEW_NODE_2(SIMPLIFIED()->NumberModulus(), a, b);
55 Node* NumberToInt32(Node* a) {
56 return NEW_NODE_1(SIMPLIFIED()->NumberToInt32(), a);
58 Node* NumberToUint32(Node* a) {
59 return NEW_NODE_1(SIMPLIFIED()->NumberToUint32(), a);
62 Node* ReferenceEqual(Type* type, Node* a, Node* b) {
63 return NEW_NODE_2(SIMPLIFIED()->ReferenceEqual(), a, b);
66 Node* StringEqual(Node* a, Node* b) {
67 return NEW_NODE_2(SIMPLIFIED()->StringEqual(), a, b);
69 Node* StringLessThan(Node* a, Node* b) {
70 return NEW_NODE_2(SIMPLIFIED()->StringLessThan(), a, b);
72 Node* StringLessThanOrEqual(Node* a, Node* b) {
73 return NEW_NODE_2(SIMPLIFIED()->StringLessThanOrEqual(), a, b);
75 Node* StringAdd(Node* a, Node* b) {
76 return NEW_NODE_2(SIMPLIFIED()->StringAdd(), a, b);
79 Node* ChangeTaggedToInt32(Node* a) {
80 return NEW_NODE_1(SIMPLIFIED()->ChangeTaggedToInt32(), a);
82 Node* ChangeTaggedToUint32(Node* a) {
83 return NEW_NODE_1(SIMPLIFIED()->ChangeTaggedToUint32(), a);
85 Node* ChangeTaggedToFloat64(Node* a) {
86 return NEW_NODE_1(SIMPLIFIED()->ChangeTaggedToFloat64(), a);
88 Node* ChangeInt32ToTagged(Node* a) {
89 return NEW_NODE_1(SIMPLIFIED()->ChangeInt32ToTagged(), a);
91 Node* ChangeUint32ToTagged(Node* a) {
92 return NEW_NODE_1(SIMPLIFIED()->ChangeUint32ToTagged(), a);
94 Node* ChangeFloat64ToTagged(Node* a) {
95 return NEW_NODE_1(SIMPLIFIED()->ChangeFloat64ToTagged(), a);
97 Node* ChangeBoolToBit(Node* a) {
98 return NEW_NODE_1(SIMPLIFIED()->ChangeBoolToBit(), a);
100 Node* ChangeBitToBool(Node* a) {
101 return NEW_NODE_1(SIMPLIFIED()->ChangeBitToBool(), a);
104 Node* LoadField(const FieldAccess& access, Node* object) {
105 return NEW_NODE_1(SIMPLIFIED()->LoadField(access), object);
107 Node* StoreField(const FieldAccess& access, Node* object, Node* value) {
108 return NEW_NODE_2(SIMPLIFIED()->StoreField(access), object, value);
110 Node* LoadElement(const ElementAccess& access, Node* object, Node* index) {
111 return NEW_NODE_2(SIMPLIFIED()->LoadElement(access), object, index);
113 Node* StoreElement(const ElementAccess& access, Node* object, Node* index,
115 return NEW_NODE_3(SIMPLIFIED()->StoreElement(access), object, index, value);
124 } // namespace compiler
125 } // namespace internal
128 #endif // V8_COMPILER_SIMPLIFIED_NODE_FACTORY_H_