| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 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 #include <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/compiler/change-lowering.h" | 8 #include "src/compiler/change-lowering.h" |
| 9 #include "src/compiler/control-builders.h" | 9 #include "src/compiler/control-builders.h" |
| 10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "test/cctest/compiler/graph-builder-tester.h" | 24 #include "test/cctest/compiler/graph-builder-tester.h" |
| 25 #include "test/cctest/compiler/value-helper.h" | 25 #include "test/cctest/compiler/value-helper.h" |
| 26 | 26 |
| 27 namespace v8 { | 27 namespace v8 { |
| 28 namespace internal { | 28 namespace internal { |
| 29 namespace compiler { | 29 namespace compiler { |
| 30 | 30 |
| 31 template <typename ReturnType> | 31 template <typename ReturnType> |
| 32 class ChangesLoweringTester : public GraphBuilderTester<ReturnType> { | 32 class ChangesLoweringTester : public GraphBuilderTester<ReturnType> { |
| 33 public: | 33 public: |
| 34 explicit ChangesLoweringTester(MachineType p0 = kMachNone) | 34 explicit ChangesLoweringTester(MachineType p0 = MachineType::None()) |
| 35 : GraphBuilderTester<ReturnType>(p0), | 35 : GraphBuilderTester<ReturnType>(p0), |
| 36 javascript(this->zone()), | 36 javascript(this->zone()), |
| 37 jsgraph(this->isolate(), this->graph(), this->common(), &javascript, | 37 jsgraph(this->isolate(), this->graph(), this->common(), &javascript, |
| 38 nullptr, this->machine()), | 38 nullptr, this->machine()), |
| 39 function(Handle<JSFunction>::null()) {} | 39 function(Handle<JSFunction>::null()) {} |
| 40 | 40 |
| 41 JSOperatorBuilder javascript; | 41 JSOperatorBuilder javascript; |
| 42 JSGraph jsgraph; | 42 JSGraph jsgraph; |
| 43 Handle<JSFunction> function; | 43 Handle<JSFunction> function; |
| 44 | 44 |
| 45 Node* start() { return this->graph()->start(); } | 45 Node* start() { return this->graph()->start(); } |
| 46 | 46 |
| 47 template <typename T> | 47 template <typename T> |
| 48 T* CallWithPotentialGC() { | 48 T* CallWithPotentialGC() { |
| 49 // TODO(titzer): we wrap the code in a JSFunction here to reuse the | 49 // TODO(titzer): we wrap the code in a JSFunction here to reuse the |
| 50 // JSEntryStub; that could be done with a special prologue or other stub. | 50 // JSEntryStub; that could be done with a special prologue or other stub. |
| 51 if (function.is_null()) { | 51 if (function.is_null()) { |
| 52 function = FunctionTester::ForMachineGraph(this->graph()); | 52 function = FunctionTester::ForMachineGraph(this->graph()); |
| 53 } | 53 } |
| 54 Handle<Object>* args = NULL; | 54 Handle<Object>* args = NULL; |
| 55 MaybeHandle<Object> result = | 55 MaybeHandle<Object> result = |
| 56 Execution::Call(this->isolate(), function, factory()->undefined_value(), | 56 Execution::Call(this->isolate(), function, factory()->undefined_value(), |
| 57 0, args, false); | 57 0, args, false); |
| 58 return T::cast(*result.ToHandleChecked()); | 58 return T::cast(*result.ToHandleChecked()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void StoreFloat64(Node* node, double* ptr) { | 61 void StoreFloat64(Node* node, double* ptr) { |
| 62 Node* ptr_node = this->PointerConstant(ptr); | 62 Node* ptr_node = this->PointerConstant(ptr); |
| 63 this->Store(kMachFloat64, ptr_node, node); | 63 this->Store(MachineType::Float64(), ptr_node, node); |
| 64 } | 64 } |
| 65 | 65 |
| 66 Node* LoadInt32(int32_t* ptr) { | 66 Node* LoadInt32(int32_t* ptr) { |
| 67 Node* ptr_node = this->PointerConstant(ptr); | 67 Node* ptr_node = this->PointerConstant(ptr); |
| 68 return this->Load(kMachInt32, ptr_node); | 68 return this->Load(MachineType::Int32(), ptr_node); |
| 69 } | 69 } |
| 70 | 70 |
| 71 Node* LoadUint32(uint32_t* ptr) { | 71 Node* LoadUint32(uint32_t* ptr) { |
| 72 Node* ptr_node = this->PointerConstant(ptr); | 72 Node* ptr_node = this->PointerConstant(ptr); |
| 73 return this->Load(kMachUint32, ptr_node); | 73 return this->Load(MachineType::Uint32(), ptr_node); |
| 74 } | 74 } |
| 75 | 75 |
| 76 Node* LoadFloat64(double* ptr) { | 76 Node* LoadFloat64(double* ptr) { |
| 77 Node* ptr_node = this->PointerConstant(ptr); | 77 Node* ptr_node = this->PointerConstant(ptr); |
| 78 return this->Load(kMachFloat64, ptr_node); | 78 return this->Load(MachineType::Float64(), ptr_node); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void CheckNumber(double expected, Object* number) { | 81 void CheckNumber(double expected, Object* number) { |
| 82 CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number)); | 82 CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void BuildAndLower(const Operator* op) { | 85 void BuildAndLower(const Operator* op) { |
| 86 // We build a graph by hand here, because the raw machine assembler | 86 // We build a graph by hand here, because the raw machine assembler |
| 87 // does not add the correct control and effect nodes. | 87 // does not add the correct control and effect nodes. |
| 88 Node* p0 = this->Parameter(0); | 88 Node* p0 = this->Parameter(0); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 Verifier::Run(this->graph(), Verifier::UNTYPED); | 138 Verifier::Run(this->graph(), Verifier::UNTYPED); |
| 139 } | 139 } |
| 140 | 140 |
| 141 Factory* factory() { return this->isolate()->factory(); } | 141 Factory* factory() { return this->isolate()->factory(); } |
| 142 Heap* heap() { return this->isolate()->heap(); } | 142 Heap* heap() { return this->isolate()->heap(); } |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 | 145 |
| 146 TEST(RunChangeTaggedToInt32) { | 146 TEST(RunChangeTaggedToInt32) { |
| 147 // Build and lower a graph by hand. | 147 // Build and lower a graph by hand. |
| 148 ChangesLoweringTester<int32_t> t(kMachAnyTagged); | 148 ChangesLoweringTester<int32_t> t(MachineType::AnyTagged()); |
| 149 t.BuildAndLower(t.simplified()->ChangeTaggedToInt32()); | 149 t.BuildAndLower(t.simplified()->ChangeTaggedToInt32()); |
| 150 | 150 |
| 151 FOR_INT32_INPUTS(i) { | 151 FOR_INT32_INPUTS(i) { |
| 152 int32_t input = *i; | 152 int32_t input = *i; |
| 153 | 153 |
| 154 if (Smi::IsValid(input)) { | 154 if (Smi::IsValid(input)) { |
| 155 int32_t result = t.Call(Smi::FromInt(input)); | 155 int32_t result = t.Call(Smi::FromInt(input)); |
| 156 CHECK_EQ(input, result); | 156 CHECK_EQ(input, result); |
| 157 } | 157 } |
| 158 | 158 |
| 159 { | 159 { |
| 160 Handle<Object> number = t.factory()->NewNumber(input); | 160 Handle<Object> number = t.factory()->NewNumber(input); |
| 161 int32_t result = t.Call(*number); | 161 int32_t result = t.Call(*number); |
| 162 CHECK_EQ(input, result); | 162 CHECK_EQ(input, result); |
| 163 } | 163 } |
| 164 | 164 |
| 165 { | 165 { |
| 166 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); | 166 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); |
| 167 int32_t result = t.Call(*number); | 167 int32_t result = t.Call(*number); |
| 168 CHECK_EQ(input, result); | 168 CHECK_EQ(input, result); |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 | 173 |
| 174 TEST(RunChangeTaggedToUint32) { | 174 TEST(RunChangeTaggedToUint32) { |
| 175 // Build and lower a graph by hand. | 175 // Build and lower a graph by hand. |
| 176 ChangesLoweringTester<uint32_t> t(kMachAnyTagged); | 176 ChangesLoweringTester<uint32_t> t(MachineType::AnyTagged()); |
| 177 t.BuildAndLower(t.simplified()->ChangeTaggedToUint32()); | 177 t.BuildAndLower(t.simplified()->ChangeTaggedToUint32()); |
| 178 | 178 |
| 179 FOR_UINT32_INPUTS(i) { | 179 FOR_UINT32_INPUTS(i) { |
| 180 uint32_t input = *i; | 180 uint32_t input = *i; |
| 181 | 181 |
| 182 if (Smi::IsValid(input)) { | 182 if (Smi::IsValid(input)) { |
| 183 uint32_t result = t.Call(Smi::FromInt(input)); | 183 uint32_t result = t.Call(Smi::FromInt(input)); |
| 184 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result)); | 184 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 { | 187 { |
| 188 Handle<Object> number = t.factory()->NewNumber(input); | 188 Handle<Object> number = t.factory()->NewNumber(input); |
| 189 uint32_t result = t.Call(*number); | 189 uint32_t result = t.Call(*number); |
| 190 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result)); | 190 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 { | 193 { |
| 194 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); | 194 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); |
| 195 uint32_t result = t.Call(*number); | 195 uint32_t result = t.Call(*number); |
| 196 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result)); | 196 CHECK_EQ(static_cast<int32_t>(input), static_cast<int32_t>(result)); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 | 201 |
| 202 TEST(RunChangeTaggedToFloat64) { | 202 TEST(RunChangeTaggedToFloat64) { |
| 203 ChangesLoweringTester<int32_t> t(kMachAnyTagged); | 203 ChangesLoweringTester<int32_t> t(MachineType::AnyTagged()); |
| 204 double result; | 204 double result; |
| 205 | 205 |
| 206 t.BuildStoreAndLower( | 206 t.BuildStoreAndLower(t.simplified()->ChangeTaggedToFloat64(), |
| 207 t.simplified()->ChangeTaggedToFloat64(), | 207 t.machine()->Store(StoreRepresentation( |
| 208 t.machine()->Store(StoreRepresentation(kMachFloat64, kNoWriteBarrier)), | 208 MachineType::Float64(), kNoWriteBarrier)), |
| 209 &result); | 209 &result); |
| 210 | 210 |
| 211 { | 211 { |
| 212 FOR_INT32_INPUTS(i) { | 212 FOR_INT32_INPUTS(i) { |
| 213 int32_t input = *i; | 213 int32_t input = *i; |
| 214 | 214 |
| 215 if (Smi::IsValid(input)) { | 215 if (Smi::IsValid(input)) { |
| 216 t.Call(Smi::FromInt(input)); | 216 t.Call(Smi::FromInt(input)); |
| 217 CHECK_EQ(input, static_cast<int32_t>(result)); | 217 CHECK_EQ(input, static_cast<int32_t>(result)); |
| 218 } | 218 } |
| 219 | 219 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 244 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); | 244 Handle<HeapNumber> number = t.factory()->NewHeapNumber(input); |
| 245 t.Call(*number); | 245 t.Call(*number); |
| 246 CheckDoubleEq(input, result); | 246 CheckDoubleEq(input, result); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 | 252 |
| 253 TEST(RunChangeBoolToBit) { | 253 TEST(RunChangeBoolToBit) { |
| 254 ChangesLoweringTester<int32_t> t(kMachAnyTagged); | 254 ChangesLoweringTester<int32_t> t(MachineType::AnyTagged()); |
| 255 t.BuildAndLower(t.simplified()->ChangeBoolToBit()); | 255 t.BuildAndLower(t.simplified()->ChangeBoolToBit()); |
| 256 | 256 |
| 257 { | 257 { |
| 258 Object* true_obj = t.heap()->true_value(); | 258 Object* true_obj = t.heap()->true_value(); |
| 259 int32_t result = t.Call(true_obj); | 259 int32_t result = t.Call(true_obj); |
| 260 CHECK_EQ(1, result); | 260 CHECK_EQ(1, result); |
| 261 } | 261 } |
| 262 | 262 |
| 263 { | 263 { |
| 264 Object* false_obj = t.heap()->false_value(); | 264 Object* false_obj = t.heap()->false_value(); |
| 265 int32_t result = t.Call(false_obj); | 265 int32_t result = t.Call(false_obj); |
| 266 CHECK_EQ(0, result); | 266 CHECK_EQ(0, result); |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 | 269 |
| 270 | 270 |
| 271 TEST(RunChangeBitToBool) { | 271 TEST(RunChangeBitToBool) { |
| 272 ChangesLoweringTester<Object*> t(kMachInt32); | 272 ChangesLoweringTester<Object*> t(MachineType::Int32()); |
| 273 t.BuildAndLower(t.simplified()->ChangeBitToBool()); | 273 t.BuildAndLower(t.simplified()->ChangeBitToBool()); |
| 274 | 274 |
| 275 { | 275 { |
| 276 Object* result = t.Call(1); | 276 Object* result = t.Call(1); |
| 277 Object* true_obj = t.heap()->true_value(); | 277 Object* true_obj = t.heap()->true_value(); |
| 278 CHECK_EQ(true_obj, result); | 278 CHECK_EQ(true_obj, result); |
| 279 } | 279 } |
| 280 | 280 |
| 281 { | 281 { |
| 282 Object* result = t.Call(0); | 282 Object* result = t.Call(0); |
| 283 Object* false_obj = t.heap()->false_value(); | 283 Object* false_obj = t.heap()->false_value(); |
| 284 CHECK_EQ(false_obj, result); | 284 CHECK_EQ(false_obj, result); |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 } // namespace compiler | 288 } // namespace compiler |
| 289 } // namespace internal | 289 } // namespace internal |
| 290 } // namespace v8 | 290 } // namespace v8 |
| OLD | NEW |