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. 4 5 #ifndef V8_CCTEST_COMPILER_SIMPLIFIED_GRAPH_BUILDER_H_ 6 #define V8_CCTEST_COMPILER_SIMPLIFIED_GRAPH_BUILDER_H_ 7 8 #include "src/compiler/common-operator.h" 9 #include "src/compiler/graph-builder.h" 10 #include "src/compiler/machine-operator.h" 11 #include "src/compiler/simplified-operator.h" 12 #include "test/cctest/cctest.h" 13 #include "test/cctest/compiler/call-tester.h" 14 15 namespace v8 { 16 namespace internal { 17 namespace compiler { 18 19 class SimplifiedGraphBuilder : public GraphBuilder { 20 public: 21 SimplifiedGraphBuilder(Graph* graph, CommonOperatorBuilder* common, 22 MachineOperatorBuilder* machine, 23 SimplifiedOperatorBuilder* simplified); ~SimplifiedGraphBuilder()24 virtual ~SimplifiedGraphBuilder() {} 25 zone()26 Zone* zone() const { return graph()->zone(); } isolate()27 Isolate* isolate() const { return zone()->isolate(); } common()28 CommonOperatorBuilder* common() const { return common_; } machine()29 MachineOperatorBuilder* machine() const { return machine_; } simplified()30 SimplifiedOperatorBuilder* simplified() const { return simplified_; } 31 32 // Initialize graph and builder. 33 void Begin(int num_parameters); 34 35 void Return(Node* value); 36 37 // Close the graph. 38 void End(); 39 PointerConstant(void * value)40 Node* PointerConstant(void* value) { 41 intptr_t intptr_value = reinterpret_cast<intptr_t>(value); 42 return kPointerSize == 8 ? NewNode(common()->Int64Constant(intptr_value)) 43 : Int32Constant(static_cast<int>(intptr_value)); 44 } Int32Constant(int32_t value)45 Node* Int32Constant(int32_t value) { 46 return NewNode(common()->Int32Constant(value)); 47 } HeapConstant(Handle<Object> object)48 Node* HeapConstant(Handle<Object> object) { 49 Unique<Object> val = Unique<Object>::CreateUninitialized(object); 50 return NewNode(common()->HeapConstant(val)); 51 } 52 BooleanNot(Node * a)53 Node* BooleanNot(Node* a) { return NewNode(simplified()->BooleanNot(), a); } 54 NumberEqual(Node * a,Node * b)55 Node* NumberEqual(Node* a, Node* b) { 56 return NewNode(simplified()->NumberEqual(), a, b); 57 } NumberLessThan(Node * a,Node * b)58 Node* NumberLessThan(Node* a, Node* b) { 59 return NewNode(simplified()->NumberLessThan(), a, b); 60 } NumberLessThanOrEqual(Node * a,Node * b)61 Node* NumberLessThanOrEqual(Node* a, Node* b) { 62 return NewNode(simplified()->NumberLessThanOrEqual(), a, b); 63 } NumberAdd(Node * a,Node * b)64 Node* NumberAdd(Node* a, Node* b) { 65 return NewNode(simplified()->NumberAdd(), a, b); 66 } NumberSubtract(Node * a,Node * b)67 Node* NumberSubtract(Node* a, Node* b) { 68 return NewNode(simplified()->NumberSubtract(), a, b); 69 } NumberMultiply(Node * a,Node * b)70 Node* NumberMultiply(Node* a, Node* b) { 71 return NewNode(simplified()->NumberMultiply(), a, b); 72 } NumberDivide(Node * a,Node * b)73 Node* NumberDivide(Node* a, Node* b) { 74 return NewNode(simplified()->NumberDivide(), a, b); 75 } NumberModulus(Node * a,Node * b)76 Node* NumberModulus(Node* a, Node* b) { 77 return NewNode(simplified()->NumberModulus(), a, b); 78 } NumberToInt32(Node * a)79 Node* NumberToInt32(Node* a) { 80 return NewNode(simplified()->NumberToInt32(), a); 81 } NumberToUint32(Node * a)82 Node* NumberToUint32(Node* a) { 83 return NewNode(simplified()->NumberToUint32(), a); 84 } 85 StringEqual(Node * a,Node * b)86 Node* StringEqual(Node* a, Node* b) { 87 return NewNode(simplified()->StringEqual(), a, b); 88 } StringLessThan(Node * a,Node * b)89 Node* StringLessThan(Node* a, Node* b) { 90 return NewNode(simplified()->StringLessThan(), a, b); 91 } StringLessThanOrEqual(Node * a,Node * b)92 Node* StringLessThanOrEqual(Node* a, Node* b) { 93 return NewNode(simplified()->StringLessThanOrEqual(), a, b); 94 } StringAdd(Node * a,Node * b)95 Node* StringAdd(Node* a, Node* b) { 96 return NewNode(simplified()->StringAdd(), a, b); 97 } 98 ChangeTaggedToInt32(Node * a)99 Node* ChangeTaggedToInt32(Node* a) { 100 return NewNode(simplified()->ChangeTaggedToInt32(), a); 101 } ChangeTaggedToUint32(Node * a)102 Node* ChangeTaggedToUint32(Node* a) { 103 return NewNode(simplified()->ChangeTaggedToUint32(), a); 104 } ChangeTaggedToFloat64(Node * a)105 Node* ChangeTaggedToFloat64(Node* a) { 106 return NewNode(simplified()->ChangeTaggedToFloat64(), a); 107 } ChangeInt32ToTagged(Node * a)108 Node* ChangeInt32ToTagged(Node* a) { 109 return NewNode(simplified()->ChangeInt32ToTagged(), a); 110 } ChangeUint32ToTagged(Node * a)111 Node* ChangeUint32ToTagged(Node* a) { 112 return NewNode(simplified()->ChangeUint32ToTagged(), a); 113 } ChangeFloat64ToTagged(Node * a)114 Node* ChangeFloat64ToTagged(Node* a) { 115 return NewNode(simplified()->ChangeFloat64ToTagged(), a); 116 } ChangeBoolToBit(Node * a)117 Node* ChangeBoolToBit(Node* a) { 118 return NewNode(simplified()->ChangeBoolToBit(), a); 119 } ChangeBitToBool(Node * a)120 Node* ChangeBitToBool(Node* a) { 121 return NewNode(simplified()->ChangeBitToBool(), a); 122 } 123 LoadField(const FieldAccess & access,Node * object)124 Node* LoadField(const FieldAccess& access, Node* object) { 125 return NewNode(simplified()->LoadField(access), object); 126 } StoreField(const FieldAccess & access,Node * object,Node * value)127 Node* StoreField(const FieldAccess& access, Node* object, Node* value) { 128 return NewNode(simplified()->StoreField(access), object, value); 129 } LoadElement(const ElementAccess & access,Node * object,Node * index,Node * length)130 Node* LoadElement(const ElementAccess& access, Node* object, Node* index, 131 Node* length) { 132 return NewNode(simplified()->LoadElement(access), object, index, length); 133 } StoreElement(const ElementAccess & access,Node * object,Node * index,Node * length,Node * value)134 Node* StoreElement(const ElementAccess& access, Node* object, Node* index, 135 Node* length, Node* value) { 136 return NewNode(simplified()->StoreElement(access), object, index, length, 137 value); 138 } 139 140 protected: 141 virtual Node* MakeNode(const Operator* op, int value_input_count, 142 Node** value_inputs) FINAL; 143 144 private: 145 Node* effect_; 146 Node* return_; 147 CommonOperatorBuilder* common_; 148 MachineOperatorBuilder* machine_; 149 SimplifiedOperatorBuilder* simplified_; 150 }; 151 152 } // namespace compiler 153 } // namespace internal 154 } // namespace v8 155 156 #endif // V8_CCTEST_COMPILER_SIMPLIFIED_GRAPH_BUILDER_H_ 157