| 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/base/flags.h" | 5 #include "src/base/flags.h" |
| 6 #include "src/bootstrapper.h" | 6 #include "src/bootstrapper.h" |
| 7 #include "src/compiler/graph-reducer.h" | 7 #include "src/compiler/graph-reducer.h" |
| 8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
| 9 #include "src/compiler/node.h" | 9 #include "src/compiler/node.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 private: | 149 private: |
| 150 Typer* typer_; | 150 Typer* typer_; |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 | 153 |
| 154 Typer::Typer(Isolate* isolate, Graph* graph, MaybeHandle<Context> context) | 154 Typer::Typer(Isolate* isolate, Graph* graph, MaybeHandle<Context> context) |
| 155 : isolate_(isolate), | 155 : isolate_(isolate), |
| 156 graph_(graph), | 156 graph_(graph), |
| 157 context_(context), | 157 context_(context), |
| 158 decorator_(NULL), | 158 decorator_(NULL), |
| 159 cache_(new (graph->zone()) LazyTypeCache(isolate, graph->zone())), | 159 cache_(new (graph->zone()) LazyTypeCache(isolate, graph->zone())) { |
| 160 weaken_min_limits_(graph->zone()), | |
| 161 weaken_max_limits_(graph->zone()) { | |
| 162 Zone* zone = this->zone(); | 160 Zone* zone = this->zone(); |
| 163 Factory* f = isolate->factory(); | 161 Factory* f = isolate->factory(); |
| 164 | 162 |
| 165 Handle<Object> infinity = f->NewNumber(+V8_INFINITY); | 163 Handle<Object> infinity = f->NewNumber(+V8_INFINITY); |
| 166 Handle<Object> minusinfinity = f->NewNumber(-V8_INFINITY); | 164 Handle<Object> minusinfinity = f->NewNumber(-V8_INFINITY); |
| 167 | 165 |
| 168 Type* number = Type::Number(); | 166 Type* number = Type::Number(); |
| 169 Type* signed32 = Type::Signed32(); | 167 Type* signed32 = Type::Signed32(); |
| 170 Type* unsigned32 = Type::Unsigned32(); | 168 Type* unsigned32 = Type::Unsigned32(); |
| 171 Type* nan_or_minuszero = Type::Union(Type::NaN(), Type::MinusZero(), zone); | 169 Type* nan_or_minuszero = Type::Union(Type::NaN(), Type::MinusZero(), zone); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 195 integer = Type::Range(-V8_INFINITY, V8_INFINITY, zone); | 193 integer = Type::Range(-V8_INFINITY, V8_INFINITY, zone); |
| 196 weakint = Type::Union(integer, nan_or_minuszero, zone); | 194 weakint = Type::Union(integer, nan_or_minuszero, zone); |
| 197 | 195 |
| 198 number_fun0_ = Type::Function(number, zone); | 196 number_fun0_ = Type::Function(number, zone); |
| 199 number_fun1_ = Type::Function(number, number, zone); | 197 number_fun1_ = Type::Function(number, number, zone); |
| 200 number_fun2_ = Type::Function(number, number, number, zone); | 198 number_fun2_ = Type::Function(number, number, number, zone); |
| 201 | 199 |
| 202 weakint_fun1_ = Type::Function(weakint, number, zone); | 200 weakint_fun1_ = Type::Function(weakint, number, zone); |
| 203 random_fun_ = Type::Function(Type::OrderedNumber(), zone); | 201 random_fun_ = Type::Function(Type::OrderedNumber(), zone); |
| 204 | 202 |
| 205 const int limits_count = 20; | |
| 206 | |
| 207 weaken_min_limits_.reserve(limits_count + 1); | |
| 208 weaken_max_limits_.reserve(limits_count + 1); | |
| 209 | |
| 210 double limit = 1 << 30; | |
| 211 weaken_min_limits_.push_back(0); | |
| 212 weaken_max_limits_.push_back(0); | |
| 213 for (int i = 0; i < limits_count; i++) { | |
| 214 weaken_min_limits_.push_back(-limit); | |
| 215 weaken_max_limits_.push_back(limit - 1); | |
| 216 limit *= 2; | |
| 217 } | |
| 218 | |
| 219 decorator_ = new (zone) Decorator(this); | 203 decorator_ = new (zone) Decorator(this); |
| 220 graph_->AddDecorator(decorator_); | 204 graph_->AddDecorator(decorator_); |
| 221 } | 205 } |
| 222 | 206 |
| 223 | 207 |
| 224 Typer::~Typer() { | 208 Typer::~Typer() { |
| 225 graph_->RemoveDecorator(decorator_); | 209 graph_->RemoveDecorator(decorator_); |
| 226 } | 210 } |
| 227 | 211 |
| 228 | 212 |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 return Bounds::Unbounded(zone()); | 1282 return Bounds::Unbounded(zone()); |
| 1299 } | 1283 } |
| 1300 | 1284 |
| 1301 | 1285 |
| 1302 // Returns a somewhat larger range if we previously assigned | 1286 // Returns a somewhat larger range if we previously assigned |
| 1303 // a (smaller) range to this node. This is used to speed up | 1287 // a (smaller) range to this node. This is used to speed up |
| 1304 // the fixpoint calculation in case there appears to be a loop | 1288 // the fixpoint calculation in case there appears to be a loop |
| 1305 // in the graph. In the current implementation, we are | 1289 // in the graph. In the current implementation, we are |
| 1306 // increasing the limits to the closest power of two. | 1290 // increasing the limits to the closest power of two. |
| 1307 Type* Typer::Visitor::Weaken(Type* current_type, Type* previous_type) { | 1291 Type* Typer::Visitor::Weaken(Type* current_type, Type* previous_type) { |
| 1292 static const double kWeakenMinLimits[] = { |
| 1293 0.0, -1073741824.0, -2147483648.0, -4294967296.0, -8589934592.0, |
| 1294 -17179869184.0, -34359738368.0, -68719476736.0, -137438953472.0, |
| 1295 -274877906944.0, -549755813888.0, -1099511627776.0, -2199023255552.0, |
| 1296 -4398046511104.0, -8796093022208.0, -17592186044416.0, -35184372088832.0, |
| 1297 -70368744177664.0, -140737488355328.0, -281474976710656.0, |
| 1298 -562949953421312.0}; |
| 1299 static const double kWeakenMaxLimits[] = { |
| 1300 0.0, 1073741823.0, 2147483647.0, 4294967295.0, 8589934591.0, |
| 1301 17179869183.0, 34359738367.0, 68719476735.0, 137438953471.0, |
| 1302 274877906943.0, 549755813887.0, 1099511627775.0, 2199023255551.0, |
| 1303 4398046511103.0, 8796093022207.0, 17592186044415.0, 35184372088831.0, |
| 1304 70368744177663.0, 140737488355327.0, 281474976710655.0, |
| 1305 562949953421311.0}; |
| 1306 STATIC_ASSERT(arraysize(kWeakenMinLimits) == arraysize(kWeakenMaxLimits)); |
| 1307 |
| 1308 // If the types have nothing to do with integers, return the types. | 1308 // If the types have nothing to do with integers, return the types. |
| 1309 if (!current_type->Maybe(typer_->integer) || | 1309 if (!current_type->Maybe(typer_->integer) || |
| 1310 !previous_type->Maybe(typer_->integer)) { | 1310 !previous_type->Maybe(typer_->integer)) { |
| 1311 return current_type; | 1311 return current_type; |
| 1312 } | 1312 } |
| 1313 | 1313 |
| 1314 Type::RangeType* previous = | 1314 Type::RangeType* previous = |
| 1315 Type::Intersect(previous_type, typer_->integer, zone())->GetRange(); | 1315 Type::Intersect(previous_type, typer_->integer, zone())->GetRange(); |
| 1316 Type::RangeType* current = | 1316 Type::RangeType* current = |
| 1317 Type::Intersect(current_type, typer_->integer, zone())->GetRange(); | 1317 Type::Intersect(current_type, typer_->integer, zone())->GetRange(); |
| 1318 if (current == nullptr || previous == nullptr) { | 1318 if (current == nullptr || previous == nullptr) { |
| 1319 return current_type; | 1319 return current_type; |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 double current_min = current->Min(); | 1322 double current_min = current->Min(); |
| 1323 double new_min = current_min; | 1323 double new_min = current_min; |
| 1324 // Find the closest lower entry in the list of allowed | 1324 // Find the closest lower entry in the list of allowed |
| 1325 // minima (or negative infinity if there is no such entry). | 1325 // minima (or negative infinity if there is no such entry). |
| 1326 if (current_min != previous->Min()) { | 1326 if (current_min != previous->Min()) { |
| 1327 new_min = typer_->integer->AsRange()->Min(); | 1327 new_min = typer_->integer->AsRange()->Min(); |
| 1328 for (const auto val : typer_->weaken_min_limits_) { | 1328 for (double const min : kWeakenMinLimits) { |
| 1329 if (val <= current_min) { | 1329 if (min <= current_min) { |
| 1330 new_min = val; | 1330 new_min = min; |
| 1331 break; | 1331 break; |
| 1332 } | 1332 } |
| 1333 } | 1333 } |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 double current_max = current->Max(); | 1336 double current_max = current->Max(); |
| 1337 double new_max = current_max; | 1337 double new_max = current_max; |
| 1338 // Find the closest greater entry in the list of allowed | 1338 // Find the closest greater entry in the list of allowed |
| 1339 // maxima (or infinity if there is no such entry). | 1339 // maxima (or infinity if there is no such entry). |
| 1340 if (current_max != previous->Max()) { | 1340 if (current_max != previous->Max()) { |
| 1341 new_max = typer_->integer->AsRange()->Max(); | 1341 new_max = typer_->integer->AsRange()->Max(); |
| 1342 for (const auto val : typer_->weaken_max_limits_) { | 1342 for (double const max : kWeakenMaxLimits) { |
| 1343 if (val >= current_max) { | 1343 if (max >= current_max) { |
| 1344 new_max = val; | 1344 new_max = max; |
| 1345 break; | 1345 break; |
| 1346 } | 1346 } |
| 1347 } | 1347 } |
| 1348 } | 1348 } |
| 1349 | 1349 |
| 1350 return Type::Union(current_type, | 1350 return Type::Union(current_type, |
| 1351 Type::Range(new_min, new_max, typer_->zone()), | 1351 Type::Range(new_min, new_max, typer_->zone()), |
| 1352 typer_->zone()); | 1352 typer_->zone()); |
| 1353 } | 1353 } |
| 1354 | 1354 |
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2218 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 2218 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
| 2219 #undef TYPED_ARRAY_CASE | 2219 #undef TYPED_ARRAY_CASE |
| 2220 } | 2220 } |
| 2221 } | 2221 } |
| 2222 return Type::Constant(value, zone()); | 2222 return Type::Constant(value, zone()); |
| 2223 } | 2223 } |
| 2224 | 2224 |
| 2225 } // namespace compiler | 2225 } // namespace compiler |
| 2226 } // namespace internal | 2226 } // namespace internal |
| 2227 } // namespace v8 | 2227 } // namespace v8 |
| OLD | NEW |