| 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 "src/code-stubs.h" | 5 #include "src/code-stubs.h" |
| 6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
| 7 #include "src/compiler/node-properties.h" | 7 #include "src/compiler/node-properties.h" |
| 8 #include "src/compiler/typer.h" | 8 #include "src/compiler/typer.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 namespace compiler { | 12 namespace compiler { |
| 13 | 13 |
| 14 Node* JSGraph::ImmovableHeapConstant(Handle<HeapObject> value) { | |
| 15 // TODO(bmeurer): Flatten cons strings here before we canonicalize them? | |
| 16 return graph()->NewNode(common()->HeapConstant(value)); | |
| 17 } | |
| 18 | |
| 19 | |
| 20 #define CACHED(name, expr) \ | 14 #define CACHED(name, expr) \ |
| 21 cached_nodes_[name] ? cached_nodes_[name] : (cached_nodes_[name] = (expr)) | 15 cached_nodes_[name] ? cached_nodes_[name] : (cached_nodes_[name] = (expr)) |
| 22 | 16 |
| 23 | 17 |
| 24 Node* JSGraph::CEntryStubConstant(int result_size) { | 18 Node* JSGraph::CEntryStubConstant(int result_size) { |
| 25 if (result_size == 1) { | 19 if (result_size == 1) { |
| 26 return CACHED(kCEntryStubConstant, | 20 return CACHED(kCEntryStubConstant, |
| 27 ImmovableHeapConstant(CEntryStub(isolate(), 1).GetCode())); | 21 HeapConstant(CEntryStub(isolate(), 1).GetCode())); |
| 28 } | 22 } |
| 29 return ImmovableHeapConstant(CEntryStub(isolate(), result_size).GetCode()); | 23 return HeapConstant(CEntryStub(isolate(), result_size).GetCode()); |
| 30 } | 24 } |
| 31 | 25 |
| 32 | 26 |
| 33 Node* JSGraph::EmptyFixedArrayConstant() { | 27 Node* JSGraph::EmptyFixedArrayConstant() { |
| 34 return CACHED(kEmptyFixedArrayConstant, | 28 return CACHED(kEmptyFixedArrayConstant, |
| 35 ImmovableHeapConstant(factory()->empty_fixed_array())); | 29 HeapConstant(factory()->empty_fixed_array())); |
| 36 } | 30 } |
| 37 | 31 |
| 38 | 32 |
| 39 Node* JSGraph::UndefinedConstant() { | 33 Node* JSGraph::UndefinedConstant() { |
| 40 return CACHED(kUndefinedConstant, | 34 return CACHED(kUndefinedConstant, HeapConstant(factory()->undefined_value())); |
| 41 ImmovableHeapConstant(factory()->undefined_value())); | |
| 42 } | 35 } |
| 43 | 36 |
| 44 | 37 |
| 45 Node* JSGraph::TheHoleConstant() { | 38 Node* JSGraph::TheHoleConstant() { |
| 46 return CACHED(kTheHoleConstant, | 39 return CACHED(kTheHoleConstant, HeapConstant(factory()->the_hole_value())); |
| 47 ImmovableHeapConstant(factory()->the_hole_value())); | |
| 48 } | 40 } |
| 49 | 41 |
| 50 | 42 |
| 51 Node* JSGraph::TrueConstant() { | 43 Node* JSGraph::TrueConstant() { |
| 52 return CACHED(kTrueConstant, ImmovableHeapConstant(factory()->true_value())); | 44 return CACHED(kTrueConstant, HeapConstant(factory()->true_value())); |
| 53 } | 45 } |
| 54 | 46 |
| 55 | 47 |
| 56 Node* JSGraph::FalseConstant() { | 48 Node* JSGraph::FalseConstant() { |
| 57 return CACHED(kFalseConstant, | 49 return CACHED(kFalseConstant, HeapConstant(factory()->false_value())); |
| 58 ImmovableHeapConstant(factory()->false_value())); | |
| 59 } | 50 } |
| 60 | 51 |
| 61 | 52 |
| 62 Node* JSGraph::NullConstant() { | 53 Node* JSGraph::NullConstant() { |
| 63 return CACHED(kNullConstant, ImmovableHeapConstant(factory()->null_value())); | 54 return CACHED(kNullConstant, HeapConstant(factory()->null_value())); |
| 64 } | 55 } |
| 65 | 56 |
| 66 | 57 |
| 67 Node* JSGraph::ZeroConstant() { | 58 Node* JSGraph::ZeroConstant() { |
| 68 return CACHED(kZeroConstant, NumberConstant(0.0)); | 59 return CACHED(kZeroConstant, NumberConstant(0.0)); |
| 69 } | 60 } |
| 70 | 61 |
| 71 | 62 |
| 72 Node* JSGraph::OneConstant() { | 63 Node* JSGraph::OneConstant() { |
| 73 return CACHED(kOneConstant, NumberConstant(1.0)); | 64 return CACHED(kOneConstant, NumberConstant(1.0)); |
| 74 } | 65 } |
| 75 | 66 |
| 76 | 67 |
| 77 Node* JSGraph::NaNConstant() { | 68 Node* JSGraph::NaNConstant() { |
| 78 return CACHED(kNaNConstant, | 69 return CACHED(kNaNConstant, |
| 79 NumberConstant(std::numeric_limits<double>::quiet_NaN())); | 70 NumberConstant(std::numeric_limits<double>::quiet_NaN())); |
| 80 } | 71 } |
| 81 | 72 |
| 82 | 73 |
| 83 Node* JSGraph::HeapConstant(Handle<HeapObject> value) { | 74 Node* JSGraph::HeapConstant(Handle<HeapObject> value) { |
| 84 // TODO(turbofan): canonicalize heap constants using <magic approach>. | 75 // TODO(bmeurer): Flatten cons strings here before we canonicalize them? |
| 85 // TODO(titzer): We could also match against the addresses of immortable | 76 Node** loc = cache_.FindHeapConstant(value); |
| 86 // immovables here, even without access to the heap, thus always | 77 if (*loc == nullptr) { |
| 87 // canonicalizing references to them. | 78 *loc = graph()->NewNode(common()->HeapConstant(value)); |
| 88 return ImmovableHeapConstant(value); | 79 } |
| 80 return *loc; |
| 89 } | 81 } |
| 90 | 82 |
| 91 | 83 |
| 92 Node* JSGraph::Constant(Handle<Object> value) { | 84 Node* JSGraph::Constant(Handle<Object> value) { |
| 93 // Dereference the handle to determine if a number constant or other | 85 // Dereference the handle to determine if a number constant or other |
| 94 // canonicalized node can be used. | 86 // canonicalized node can be used. |
| 95 if (value->IsNumber()) { | 87 if (value->IsNumber()) { |
| 96 return Constant(value->Number()); | 88 return Constant(value->Number()); |
| 97 } else if (value->IsUndefined()) { | 89 } else if (value->IsUndefined()) { |
| 98 return UndefinedConstant(); | 90 return UndefinedConstant(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 for (size_t i = 0; i < arraysize(cached_nodes_); i++) { | 200 for (size_t i = 0; i < arraysize(cached_nodes_); i++) { |
| 209 if (Node* node = cached_nodes_[i]) { | 201 if (Node* node = cached_nodes_[i]) { |
| 210 if (!node->IsDead()) nodes->push_back(node); | 202 if (!node->IsDead()) nodes->push_back(node); |
| 211 } | 203 } |
| 212 } | 204 } |
| 213 } | 205 } |
| 214 | 206 |
| 215 } // namespace compiler | 207 } // namespace compiler |
| 216 } // namespace internal | 208 } // namespace internal |
| 217 } // namespace v8 | 209 } // namespace v8 |
| OLD | NEW |