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 #include "src/compiler/types.h" 11 #include "src/objects/objects.h" 12 13 namespace v8 { 14 namespace internal { 15 16 // Forward declarations. 17 class Isolate; 18 class RangeType; 19 class Zone; 20 21 namespace compiler { 22 23 // Forward declarations. 24 class Operator; 25 class Type; 26 class TypeCache; 27 28 class V8_EXPORT_PRIVATE OperationTyper { 29 public: 30 OperationTyper(JSHeapBroker* broker, Zone* zone); 31 32 // Typing Phi. 33 Type Merge(Type left, Type right); 34 35 Type ToPrimitive(Type type); 36 Type ToNumber(Type type); 37 Type ToNumberConvertBigInt(Type type); 38 Type ToNumeric(Type type); 39 Type ToBoolean(Type type); 40 41 Type WeakenRange(Type current_range, Type previous_range); 42 43 // Unary operators. 44 #define DECLARE_METHOD(Name) Type Name(Type type); 45 SIMPLIFIED_NUMBER_UNOP_LIST(DECLARE_METHOD) 46 SIMPLIFIED_BIGINT_UNOP_LIST(DECLARE_METHOD) 47 SIMPLIFIED_SPECULATIVE_NUMBER_UNOP_LIST(DECLARE_METHOD) 48 SIMPLIFIED_SPECULATIVE_BIGINT_UNOP_LIST(DECLARE_METHOD) 49 DECLARE_METHOD(ConvertReceiver) 50 #undef DECLARE_METHOD 51 52 // Numeric binary operators. 53 #define DECLARE_METHOD(Name) Type Name(Type lhs, Type rhs); 54 SIMPLIFIED_NUMBER_BINOP_LIST(DECLARE_METHOD) 55 SIMPLIFIED_BIGINT_BINOP_LIST(DECLARE_METHOD) 56 SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(DECLARE_METHOD) 57 SIMPLIFIED_SPECULATIVE_BIGINT_BINOP_LIST(DECLARE_METHOD) 58 #undef DECLARE_METHOD 59 60 // Comparison operators. 61 Type SameValue(Type lhs, Type rhs); 62 Type SameValueNumbersOnly(Type lhs, Type rhs); 63 Type StrictEqual(Type lhs, Type rhs); 64 65 // Check operators. 66 Type CheckBounds(Type index, Type length); 67 Type CheckFloat64Hole(Type type); 68 Type CheckNumber(Type type); 69 Type ConvertTaggedHoleToUndefined(Type type); 70 71 Type TypeTypeGuard(const Operator* sigma_op, Type input); 72 73 enum ComparisonOutcomeFlags { 74 kComparisonTrue = 1, 75 kComparisonFalse = 2, 76 kComparisonUndefined = 4 77 }; 78 singleton_false()79 Type singleton_false() const { return singleton_false_; } singleton_true()80 Type singleton_true() const { return singleton_true_; } singleton_the_hole()81 Type singleton_the_hole() const { return singleton_the_hole_; } 82 83 private: 84 using ComparisonOutcome = base::Flags<ComparisonOutcomeFlags>; 85 86 ComparisonOutcome Invert(ComparisonOutcome); 87 Type Invert(Type); 88 Type FalsifyUndefined(ComparisonOutcome); 89 90 Type Rangify(Type); 91 Type AddRanger(double lhs_min, double lhs_max, double rhs_min, 92 double rhs_max); 93 Type SubtractRanger(double lhs_min, double lhs_max, double rhs_min, 94 double rhs_max); 95 Type MultiplyRanger(double lhs_min, double lhs_max, double rhs_min, 96 double rhs_max); 97 zone()98 Zone* zone() const { return zone_; } 99 100 Zone* const zone_; 101 TypeCache const* cache_; 102 103 Type infinity_; 104 Type minus_infinity_; 105 Type singleton_NaN_string_; 106 Type singleton_zero_string_; 107 Type singleton_false_; 108 Type singleton_true_; 109 Type singleton_the_hole_; 110 Type signed32ish_; 111 Type unsigned32ish_; 112 Type singleton_empty_string_; 113 Type truish_; 114 Type falsish_; 115 }; 116 117 } // namespace compiler 118 } // namespace internal 119 } // namespace v8 120 121 #endif // V8_COMPILER_OPERATION_TYPER_H_ 122