1 // Copyright 2016 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 #ifndef V8_COMPILER_OPERATION_TYPER_H_ 6 #define V8_COMPILER_OPERATION_TYPER_H_ 7 8 #include "src/base/flags.h" 9 #include "src/compiler/opcodes.h" 10 11 namespace v8 { 12 namespace internal { 13 14 // Forward declarations. 15 class Isolate; 16 class RangeType; 17 class Zone; 18 19 namespace compiler { 20 21 // Forward declarations. 22 class Operator; 23 class Type; 24 class TypeCache; 25 26 class OperationTyper { 27 public: 28 OperationTyper(Isolate* isolate, Zone* zone); 29 30 // Typing Phi. 31 Type* Merge(Type* left, Type* right); 32 33 Type* ToPrimitive(Type* type); 34 35 // Helpers for number operation typing. 36 Type* ToNumber(Type* type); 37 Type* WeakenRange(Type* current_range, Type* previous_range); 38 39 // Number unary operators. 40 #define DECLARE_METHOD(Name) Type* Name(Type* type); 41 SIMPLIFIED_NUMBER_UNOP_LIST(DECLARE_METHOD) 42 #undef DECLARE_METHOD 43 44 // Number binary operators. 45 #define DECLARE_METHOD(Name) Type* Name(Type* lhs, Type* rhs); 46 SIMPLIFIED_NUMBER_BINOP_LIST(DECLARE_METHOD) 47 SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(DECLARE_METHOD) 48 #undef DECLARE_METHOD 49 50 Type* TypeTypeGuard(const Operator* sigma_op, Type* input); 51 52 enum ComparisonOutcomeFlags { 53 kComparisonTrue = 1, 54 kComparisonFalse = 2, 55 kComparisonUndefined = 4 56 }; 57 singleton_false()58 Type* singleton_false() const { return singleton_false_; } singleton_true()59 Type* singleton_true() const { return singleton_true_; } singleton_the_hole()60 Type* singleton_the_hole() const { return singleton_the_hole_; } 61 62 private: 63 typedef base::Flags<ComparisonOutcomeFlags> ComparisonOutcome; 64 65 ComparisonOutcome Invert(ComparisonOutcome); 66 Type* Invert(Type*); 67 Type* FalsifyUndefined(ComparisonOutcome); 68 69 Type* Rangify(Type*); 70 Type* AddRanger(double lhs_min, double lhs_max, double rhs_min, 71 double rhs_max); 72 Type* SubtractRanger(double lhs_min, double lhs_max, double rhs_min, 73 double rhs_max); 74 Type* MultiplyRanger(Type* lhs, Type* rhs); 75 zone()76 Zone* zone() const { return zone_; } 77 78 Zone* const zone_; 79 TypeCache const& cache_; 80 81 Type* infinity_; 82 Type* minus_infinity_; 83 Type* singleton_false_; 84 Type* singleton_true_; 85 Type* singleton_the_hole_; 86 Type* signed32ish_; 87 Type* unsigned32ish_; 88 }; 89 90 } // namespace compiler 91 } // namespace internal 92 } // namespace v8 93 94 #endif // V8_COMPILER_OPERATION_TYPER_H_ 95