Chromium Code Reviews| 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/compiler/js-graph.h" | 5 #include "src/compiler/js-graph.h" |
| 6 #include "src/compiler/node-properties-inl.h" | 6 #include "src/compiler/node-properties-inl.h" |
| 7 #include "src/compiler/typer.h" | 7 #include "src/compiler/typer.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| 11 namespace compiler { | 11 namespace compiler { |
| 12 | 12 |
| 13 Node* JSGraph::ImmovableHeapConstant(Handle<Object> object) { | 13 Node* JSGraph::ImmovableHeapConstant(Handle<Object> object) { |
| 14 PrintableUnique<Object> unique = | 14 PrintableUnique<Object> unique = |
| 15 PrintableUnique<Object>::CreateImmovable(zone(), object); | 15 PrintableUnique<Object>::CreateImmovable(zone(), object); |
| 16 return NewNode(common()->HeapConstant(unique)); | 16 return graph()->NewNode(common()->HeapConstant(unique)); |
| 17 } | 17 } |
| 18 | 18 |
| 19 | 19 |
| 20 Node* JSGraph::NewNode(Operator* op) { | 20 Node* JSGraph::CacheNode(SetOncePointer<Node>* cache, Node* node) { |
| 21 Node* node = graph()->NewNode(op); | 21 cache->set(node); |
| 22 typer_->Init(node); | 22 return node; |
| 23 } | |
| 24 | |
| 25 | |
| 26 Node* JSGraph::CachedNode(SetOncePointer<Node>* cache) { | |
| 27 Node* node = cache->get(); | |
| 28 graph()->Decorate(node); | |
| 23 return node; | 29 return node; |
| 24 } | 30 } |
| 25 | 31 |
| 26 | 32 |
| 27 Node* JSGraph::CEntryStubConstant() { | 33 Node* JSGraph::CEntryStubConstant() { |
| 28 if (!c_entry_stub_constant_.is_set()) { | 34 return c_entry_stub_constant_.is_set() |
| 29 c_entry_stub_constant_.set( | 35 ? CachedNode(&c_entry_stub_constant_) |
| 30 ImmovableHeapConstant(CEntryStub(isolate(), 1).GetCode())); | 36 : CacheNode(&c_entry_stub_constant_, |
| 31 } | 37 ImmovableHeapConstant(CEntryStub(isolate(), 1).GetCode())); |
| 32 return c_entry_stub_constant_.get(); | |
| 33 } | 38 } |
| 34 | 39 |
| 35 | 40 |
| 36 Node* JSGraph::UndefinedConstant() { | 41 Node* JSGraph::UndefinedConstant() { |
| 37 if (!undefined_constant_.is_set()) { | 42 return undefined_constant_.is_set() |
| 38 undefined_constant_.set( | 43 ? CachedNode(&undefined_constant_) |
| 39 ImmovableHeapConstant(factory()->undefined_value())); | 44 : CacheNode(&undefined_constant_, |
| 40 } | 45 ImmovableHeapConstant(factory()->undefined_value())); |
| 41 return undefined_constant_.get(); | |
| 42 } | 46 } |
| 43 | 47 |
| 44 | 48 |
| 45 Node* JSGraph::TheHoleConstant() { | 49 Node* JSGraph::TheHoleConstant() { |
| 46 if (!the_hole_constant_.is_set()) { | 50 return the_hole_constant_.is_set() |
| 47 the_hole_constant_.set(ImmovableHeapConstant(factory()->the_hole_value())); | 51 ? CachedNode(&the_hole_constant_) |
| 48 } | 52 : CacheNode(&the_hole_constant_, |
| 49 return the_hole_constant_.get(); | 53 ImmovableHeapConstant(factory()->the_hole_value())); |
| 50 } | 54 } |
| 51 | 55 |
| 52 | 56 |
| 53 Node* JSGraph::TrueConstant() { | 57 Node* JSGraph::TrueConstant() { |
| 54 if (!true_constant_.is_set()) { | 58 return true_constant_.is_set() |
| 55 true_constant_.set(ImmovableHeapConstant(factory()->true_value())); | 59 ? CachedNode(&true_constant_) |
| 56 } | 60 : CacheNode(&true_constant_, |
| 57 return true_constant_.get(); | 61 ImmovableHeapConstant(factory()->true_value())); |
| 58 } | 62 } |
| 59 | 63 |
| 60 | 64 |
| 61 Node* JSGraph::FalseConstant() { | 65 Node* JSGraph::FalseConstant() { |
| 62 if (!false_constant_.is_set()) { | 66 return false_constant_.is_set() |
| 63 false_constant_.set(ImmovableHeapConstant(factory()->false_value())); | 67 ? CachedNode(&false_constant_) |
| 64 } | 68 : CacheNode(&false_constant_, |
| 65 return false_constant_.get(); | 69 ImmovableHeapConstant(factory()->false_value())); |
| 66 } | 70 } |
| 67 | 71 |
| 68 | 72 |
| 69 Node* JSGraph::NullConstant() { | 73 Node* JSGraph::NullConstant() { |
| 70 if (!null_constant_.is_set()) { | 74 return null_constant_.is_set() |
| 71 null_constant_.set(ImmovableHeapConstant(factory()->null_value())); | 75 ? CachedNode(&null_constant_) |
| 72 } | 76 : CacheNode(&null_constant_, |
| 73 return null_constant_.get(); | 77 ImmovableHeapConstant(factory()->null_value())); |
| 74 } | 78 } |
| 75 | 79 |
| 76 | 80 |
| 77 Node* JSGraph::ZeroConstant() { | 81 Node* JSGraph::ZeroConstant() { |
| 78 if (!zero_constant_.is_set()) zero_constant_.set(NumberConstant(0.0)); | 82 return zero_constant_.is_set() |
| 79 return zero_constant_.get(); | 83 ? CachedNode(&zero_constant_) |
| 84 : CacheNode(&zero_constant_, NumberConstant(0.0)); | |
| 80 } | 85 } |
| 81 | 86 |
| 82 | 87 |
| 83 Node* JSGraph::OneConstant() { | 88 Node* JSGraph::OneConstant() { |
| 84 if (!one_constant_.is_set()) one_constant_.set(NumberConstant(1.0)); | 89 return one_constant_.is_set() |
| 85 return one_constant_.get(); | 90 ? CachedNode(&one_constant_) |
| 91 : CacheNode(&one_constant_, NumberConstant(1.0)); | |
| 86 } | 92 } |
| 87 | 93 |
| 88 | 94 |
| 89 Node* JSGraph::NaNConstant() { | 95 Node* JSGraph::NaNConstant() { |
| 90 if (!nan_constant_.is_set()) { | 96 return nan_constant_.is_set() |
| 91 nan_constant_.set(NumberConstant(base::OS::nan_value())); | 97 ? CachedNode(&nan_constant_) |
| 92 } | 98 : CacheNode(&nan_constant_, NumberConstant(base::OS::nan_value())); |
| 93 return nan_constant_.get(); | |
| 94 } | 99 } |
| 95 | 100 |
| 96 | 101 |
| 97 Node* JSGraph::HeapConstant(PrintableUnique<Object> value) { | 102 Node* JSGraph::HeapConstant(PrintableUnique<Object> value) { |
| 98 // TODO(turbofan): canonicalize heap constants using Unique<T> | 103 // TODO(turbofan): canonicalize heap constants using Unique<T> |
| 99 return NewNode(common()->HeapConstant(value)); | 104 return graph()->NewNode(common()->HeapConstant(value)); |
| 100 } | 105 } |
| 101 | 106 |
| 102 | 107 |
| 103 Node* JSGraph::HeapConstant(Handle<Object> value) { | 108 Node* JSGraph::HeapConstant(Handle<Object> value) { |
| 104 // TODO(titzer): We could also match against the addresses of immortable | 109 // TODO(titzer): We could also match against the addresses of immortable |
| 105 // immovables here, even without access to the heap, thus always | 110 // immovables here, even without access to the heap, thus always |
| 106 // canonicalizing references to them. | 111 // canonicalizing references to them. |
| 107 return HeapConstant( | 112 return HeapConstant( |
| 108 PrintableUnique<Object>::CreateUninitialized(zone(), value)); | 113 PrintableUnique<Object>::CreateUninitialized(zone(), value)); |
| 109 } | 114 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 140 Node* JSGraph::Constant(int32_t value) { | 145 Node* JSGraph::Constant(int32_t value) { |
| 141 if (value == 0) return ZeroConstant(); | 146 if (value == 0) return ZeroConstant(); |
| 142 if (value == 1) return OneConstant(); | 147 if (value == 1) return OneConstant(); |
| 143 return NumberConstant(value); | 148 return NumberConstant(value); |
| 144 } | 149 } |
| 145 | 150 |
| 146 | 151 |
| 147 Node* JSGraph::Int32Constant(int32_t value) { | 152 Node* JSGraph::Int32Constant(int32_t value) { |
| 148 Node** loc = cache_.FindInt32Constant(value); | 153 Node** loc = cache_.FindInt32Constant(value); |
| 149 if (*loc == NULL) { | 154 if (*loc == NULL) { |
| 150 *loc = NewNode(common()->Int32Constant(value)); | 155 *loc = graph()->NewNode(common()->Int32Constant(value)); |
| 156 } else { | |
| 157 graph()->Decorate(*loc); | |
|
titzer
2014/08/28 13:12:31
Why are you explicitly calling Decorate all over t
rossberg
2014/08/28 15:35:50
Because new decorators might have been added since
titzer
2014/10/01 08:30:24
This is starting to be a real pain. Now we are add
| |
| 151 } | 158 } |
| 152 return *loc; | 159 return *loc; |
| 153 } | 160 } |
| 154 | 161 |
| 155 | 162 |
| 156 Node* JSGraph::NumberConstant(double value) { | 163 Node* JSGraph::NumberConstant(double value) { |
| 157 Node** loc = cache_.FindNumberConstant(value); | 164 Node** loc = cache_.FindNumberConstant(value); |
| 158 if (*loc == NULL) { | 165 if (*loc == NULL) { |
| 159 *loc = NewNode(common()->NumberConstant(value)); | 166 *loc = graph()->NewNode(common()->NumberConstant(value)); |
| 167 } else { | |
| 168 graph()->Decorate(*loc); | |
| 160 } | 169 } |
| 161 return *loc; | 170 return *loc; |
| 162 } | 171 } |
| 163 | 172 |
| 164 | 173 |
| 165 Node* JSGraph::Float64Constant(double value) { | 174 Node* JSGraph::Float64Constant(double value) { |
| 166 Node** loc = cache_.FindFloat64Constant(value); | 175 Node** loc = cache_.FindFloat64Constant(value); |
| 167 if (*loc == NULL) { | 176 if (*loc == NULL) { |
| 168 *loc = NewNode(common()->Float64Constant(value)); | 177 *loc = graph()->NewNode(common()->Float64Constant(value)); |
| 178 } else { | |
| 179 graph()->Decorate(*loc); | |
| 169 } | 180 } |
| 170 return *loc; | 181 return *loc; |
| 171 } | 182 } |
| 172 | 183 |
| 173 | 184 |
| 174 Node* JSGraph::ExternalConstant(ExternalReference reference) { | 185 Node* JSGraph::ExternalConstant(ExternalReference reference) { |
| 175 Node** loc = cache_.FindExternalConstant(reference); | 186 Node** loc = cache_.FindExternalConstant(reference); |
| 176 if (*loc == NULL) { | 187 if (*loc == NULL) { |
| 177 *loc = NewNode(common()->ExternalConstant(reference)); | 188 *loc = graph()->NewNode(common()->ExternalConstant(reference)); |
| 178 } | 189 } |
| 179 return *loc; | 190 return *loc; |
| 180 } | 191 } |
| 181 } // namespace compiler | 192 } // namespace compiler |
| 182 } // namespace internal | 193 } // namespace internal |
| 183 } // namespace v8 | 194 } // namespace v8 |
| OLD | NEW |