Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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); |
| 24 | virtual ~SimplifiedGraphBuilder() {} |
| 25 | |
| 26 | Zone* zone() const { return graph()->zone(); } |
| 27 | Isolate* isolate() const { return zone()->isolate(); } |
| 28 | CommonOperatorBuilder* common() const { return common_; } |
| 29 | MachineOperatorBuilder* machine() const { return machine_; } |
| 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 | |
| 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 | } |
| 45 | Node* Int32Constant(int32_t value) { |
| 46 | return NewNode(common()->Int32Constant(value)); |
| 47 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 48 | Node* HeapConstant(Handle<HeapObject> object) { |
| 49 | Unique<HeapObject> val = Unique<HeapObject>::CreateUninitialized(object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 50 | return NewNode(common()->HeapConstant(val)); |
| 51 | } |
| 52 | |
| 53 | Node* BooleanNot(Node* a) { return NewNode(simplified()->BooleanNot(), a); } |
| 54 | |
| 55 | Node* NumberEqual(Node* a, Node* b) { |
| 56 | return NewNode(simplified()->NumberEqual(), a, b); |
| 57 | } |
| 58 | Node* NumberLessThan(Node* a, Node* b) { |
| 59 | return NewNode(simplified()->NumberLessThan(), a, b); |
| 60 | } |
| 61 | Node* NumberLessThanOrEqual(Node* a, Node* b) { |
| 62 | return NewNode(simplified()->NumberLessThanOrEqual(), a, b); |
| 63 | } |
| 64 | Node* NumberAdd(Node* a, Node* b) { |
| 65 | return NewNode(simplified()->NumberAdd(), a, b); |
| 66 | } |
| 67 | Node* NumberSubtract(Node* a, Node* b) { |
| 68 | return NewNode(simplified()->NumberSubtract(), a, b); |
| 69 | } |
| 70 | Node* NumberMultiply(Node* a, Node* b) { |
| 71 | return NewNode(simplified()->NumberMultiply(), a, b); |
| 72 | } |
| 73 | Node* NumberDivide(Node* a, Node* b) { |
| 74 | return NewNode(simplified()->NumberDivide(), a, b); |
| 75 | } |
| 76 | Node* NumberModulus(Node* a, Node* b) { |
| 77 | return NewNode(simplified()->NumberModulus(), a, b); |
| 78 | } |
| 79 | Node* NumberToInt32(Node* a) { |
| 80 | return NewNode(simplified()->NumberToInt32(), a); |
| 81 | } |
| 82 | Node* NumberToUint32(Node* a) { |
| 83 | return NewNode(simplified()->NumberToUint32(), a); |
| 84 | } |
| 85 | |
| 86 | Node* StringEqual(Node* a, Node* b) { |
| 87 | return NewNode(simplified()->StringEqual(), a, b); |
| 88 | } |
| 89 | Node* StringLessThan(Node* a, Node* b) { |
| 90 | return NewNode(simplified()->StringLessThan(), a, b); |
| 91 | } |
| 92 | Node* StringLessThanOrEqual(Node* a, Node* b) { |
| 93 | return NewNode(simplified()->StringLessThanOrEqual(), a, b); |
| 94 | } |
| 95 | Node* StringAdd(Node* a, Node* b) { |
| 96 | return NewNode(simplified()->StringAdd(), a, b); |
| 97 | } |
| 98 | |
| 99 | Node* ChangeTaggedToInt32(Node* a) { |
| 100 | return NewNode(simplified()->ChangeTaggedToInt32(), a); |
| 101 | } |
| 102 | Node* ChangeTaggedToUint32(Node* a) { |
| 103 | return NewNode(simplified()->ChangeTaggedToUint32(), a); |
| 104 | } |
| 105 | Node* ChangeTaggedToFloat64(Node* a) { |
| 106 | return NewNode(simplified()->ChangeTaggedToFloat64(), a); |
| 107 | } |
| 108 | Node* ChangeInt32ToTagged(Node* a) { |
| 109 | return NewNode(simplified()->ChangeInt32ToTagged(), a); |
| 110 | } |
| 111 | Node* ChangeUint32ToTagged(Node* a) { |
| 112 | return NewNode(simplified()->ChangeUint32ToTagged(), a); |
| 113 | } |
| 114 | Node* ChangeFloat64ToTagged(Node* a) { |
| 115 | return NewNode(simplified()->ChangeFloat64ToTagged(), a); |
| 116 | } |
| 117 | Node* ChangeBoolToBit(Node* a) { |
| 118 | return NewNode(simplified()->ChangeBoolToBit(), a); |
| 119 | } |
| 120 | Node* ChangeBitToBool(Node* a) { |
| 121 | return NewNode(simplified()->ChangeBitToBool(), a); |
| 122 | } |
| 123 | |
| 124 | Node* LoadField(const FieldAccess& access, Node* object) { |
| 125 | return NewNode(simplified()->LoadField(access), object); |
| 126 | } |
| 127 | Node* StoreField(const FieldAccess& access, Node* object, Node* value) { |
| 128 | return NewNode(simplified()->StoreField(access), object, value); |
| 129 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 130 | Node* LoadElement(const ElementAccess& access, Node* object, Node* index) { |
| 131 | return NewNode(simplified()->LoadElement(access), object, index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 132 | } |
| 133 | Node* StoreElement(const ElementAccess& access, Node* object, Node* index, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 134 | Node* value) { |
| 135 | return NewNode(simplified()->StoreElement(access), object, index, value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | protected: |
| 139 | virtual Node* MakeNode(const Operator* op, int value_input_count, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 140 | Node** value_inputs, bool incomplete) FINAL; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 141 | |
| 142 | private: |
| 143 | Node* effect_; |
| 144 | Node* return_; |
| 145 | CommonOperatorBuilder* common_; |
| 146 | MachineOperatorBuilder* machine_; |
| 147 | SimplifiedOperatorBuilder* simplified_; |
| 148 | }; |
| 149 | |
| 150 | } // namespace compiler |
| 151 | } // namespace internal |
| 152 | } // namespace v8 |
| 153 | |
| 154 | #endif // V8_CCTEST_COMPILER_SIMPLIFIED_GRAPH_BUILDER_H_ |