OLD | NEW |
(Empty) | |
| 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 #include "src/compiler/js-graph.h" |
| 6 #include "src/compiler/node-properties-inl.h" |
| 7 #include "src/compiler/typer.h" |
| 8 |
| 9 namespace v8 { |
| 10 namespace internal { |
| 11 namespace compiler { |
| 12 |
| 13 Node* JSGraph::ImmovableHeapConstant(Handle<Object> object) { |
| 14 PrintableUnique<Object> unique = |
| 15 PrintableUnique<Object>::CreateImmovable(zone(), object); |
| 16 return NewNode(common()->HeapConstant(unique)); |
| 17 } |
| 18 |
| 19 |
| 20 Node* JSGraph::NewNode(Operator* op) { |
| 21 Node* node = graph()->NewNode(op); |
| 22 typer_->Init(node); |
| 23 return node; |
| 24 } |
| 25 |
| 26 |
| 27 Node* JSGraph::UndefinedConstant() { |
| 28 if (!undefined_constant_.is_set()) { |
| 29 undefined_constant_.set( |
| 30 ImmovableHeapConstant(factory()->undefined_value())); |
| 31 } |
| 32 return undefined_constant_.get(); |
| 33 } |
| 34 |
| 35 |
| 36 Node* JSGraph::TheHoleConstant() { |
| 37 if (!the_hole_constant_.is_set()) { |
| 38 the_hole_constant_.set(ImmovableHeapConstant(factory()->the_hole_value())); |
| 39 } |
| 40 return the_hole_constant_.get(); |
| 41 } |
| 42 |
| 43 |
| 44 Node* JSGraph::TrueConstant() { |
| 45 if (!true_constant_.is_set()) { |
| 46 true_constant_.set(ImmovableHeapConstant(factory()->true_value())); |
| 47 } |
| 48 return true_constant_.get(); |
| 49 } |
| 50 |
| 51 |
| 52 Node* JSGraph::FalseConstant() { |
| 53 if (!false_constant_.is_set()) { |
| 54 false_constant_.set(ImmovableHeapConstant(factory()->false_value())); |
| 55 } |
| 56 return false_constant_.get(); |
| 57 } |
| 58 |
| 59 |
| 60 Node* JSGraph::NullConstant() { |
| 61 if (!null_constant_.is_set()) { |
| 62 null_constant_.set(ImmovableHeapConstant(factory()->null_value())); |
| 63 } |
| 64 return null_constant_.get(); |
| 65 } |
| 66 |
| 67 |
| 68 Node* JSGraph::ZeroConstant() { |
| 69 if (!zero_constant_.is_set()) zero_constant_.set(NumberConstant(0.0)); |
| 70 return zero_constant_.get(); |
| 71 } |
| 72 |
| 73 |
| 74 Node* JSGraph::OneConstant() { |
| 75 if (!one_constant_.is_set()) one_constant_.set(NumberConstant(1.0)); |
| 76 return one_constant_.get(); |
| 77 } |
| 78 |
| 79 |
| 80 Node* JSGraph::NaNConstant() { |
| 81 if (!nan_constant_.is_set()) { |
| 82 nan_constant_.set(NumberConstant(base::OS::nan_value())); |
| 83 } |
| 84 return nan_constant_.get(); |
| 85 } |
| 86 |
| 87 |
| 88 Node* JSGraph::HeapConstant(PrintableUnique<Object> value) { |
| 89 // TODO(turbofan): canonicalize heap constants using Unique<T> |
| 90 return NewNode(common()->HeapConstant(value)); |
| 91 } |
| 92 |
| 93 |
| 94 Node* JSGraph::HeapConstant(Handle<Object> value) { |
| 95 // TODO(titzer): We could also match against the addresses of immortable |
| 96 // immovables here, even without access to the heap, thus always |
| 97 // canonicalizing references to them. |
| 98 return HeapConstant( |
| 99 PrintableUnique<Object>::CreateUninitialized(zone(), value)); |
| 100 } |
| 101 |
| 102 |
| 103 Node* JSGraph::Constant(Handle<Object> value) { |
| 104 // Dereference the handle to determine if a number constant or other |
| 105 // canonicalized node can be used. |
| 106 if (value->IsNumber()) { |
| 107 return Constant(value->Number()); |
| 108 } else if (value->IsUndefined()) { |
| 109 return UndefinedConstant(); |
| 110 } else if (value->IsTrue()) { |
| 111 return TrueConstant(); |
| 112 } else if (value->IsFalse()) { |
| 113 return FalseConstant(); |
| 114 } else if (value->IsNull()) { |
| 115 return NullConstant(); |
| 116 } else if (value->IsTheHole()) { |
| 117 return TheHoleConstant(); |
| 118 } else { |
| 119 return HeapConstant(value); |
| 120 } |
| 121 } |
| 122 |
| 123 |
| 124 Node* JSGraph::Constant(double value) { |
| 125 if (BitCast<int64_t>(value) == BitCast<int64_t>(0.0)) return ZeroConstant(); |
| 126 if (BitCast<int64_t>(value) == BitCast<int64_t>(1.0)) return OneConstant(); |
| 127 return NumberConstant(value); |
| 128 } |
| 129 |
| 130 |
| 131 Node* JSGraph::Constant(int32_t value) { |
| 132 if (value == 0) return ZeroConstant(); |
| 133 if (value == 1) return OneConstant(); |
| 134 return NumberConstant(value); |
| 135 } |
| 136 |
| 137 |
| 138 Node* JSGraph::Int32Constant(int32_t value) { |
| 139 Node** loc = cache_.FindInt32Constant(value); |
| 140 if (*loc == NULL) { |
| 141 *loc = NewNode(common()->Int32Constant(value)); |
| 142 } |
| 143 return *loc; |
| 144 } |
| 145 |
| 146 |
| 147 Node* JSGraph::NumberConstant(double value) { |
| 148 Node** loc = cache_.FindNumberConstant(value); |
| 149 if (*loc == NULL) { |
| 150 *loc = NewNode(common()->NumberConstant(value)); |
| 151 } |
| 152 return *loc; |
| 153 } |
| 154 |
| 155 |
| 156 Node* JSGraph::Float64Constant(double value) { |
| 157 Node** loc = cache_.FindFloat64Constant(value); |
| 158 if (*loc == NULL) { |
| 159 *loc = NewNode(common()->Float64Constant(value)); |
| 160 } |
| 161 return *loc; |
| 162 } |
| 163 |
| 164 |
| 165 Node* JSGraph::ExternalConstant(ExternalReference reference) { |
| 166 Node** loc = cache_.FindExternalConstant(reference); |
| 167 if (*loc == NULL) { |
| 168 *loc = NewNode(common()->ExternalConstant(reference)); |
| 169 } |
| 170 return *loc; |
| 171 } |
| 172 } // namespace compiler |
| 173 } // namespace internal |
| 174 } // namespace v8 |
OLD | NEW |