• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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(Isolate* isolate, JSHeapBroker* js_heap_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_SPECULATIVE_NUMBER_UNOP_LIST(DECLARE_METHOD)
47   DECLARE_METHOD(ConvertReceiver)
48 #undef DECLARE_METHOD
49 
50 // Number binary operators.
51 #define DECLARE_METHOD(Name) Type Name(Type lhs, Type rhs);
52   SIMPLIFIED_NUMBER_BINOP_LIST(DECLARE_METHOD)
53   SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(DECLARE_METHOD)
54 #undef DECLARE_METHOD
55 
56   // Comparison operators.
57   Type SameValue(Type lhs, Type rhs);
58   Type StrictEqual(Type lhs, Type rhs);
59 
60   // Check operators.
61   Type CheckFloat64Hole(Type type);
62   Type CheckNumber(Type type);
63   Type ConvertTaggedHoleToUndefined(Type type);
64 
65   Type TypeTypeGuard(const Operator* sigma_op, Type input);
66 
67   enum ComparisonOutcomeFlags {
68     kComparisonTrue = 1,
69     kComparisonFalse = 2,
70     kComparisonUndefined = 4
71   };
72 
singleton_false()73   Type singleton_false() const { return singleton_false_; }
singleton_true()74   Type singleton_true() const { return singleton_true_; }
singleton_the_hole()75   Type singleton_the_hole() const { return singleton_the_hole_; }
76 
77  private:
78   typedef base::Flags<ComparisonOutcomeFlags> ComparisonOutcome;
79 
80   Type ToNumberOrNumeric(Object::Conversion mode, Type type);
81   base::Optional<Type> ToNumberCommon(Type type);
82 
83   ComparisonOutcome Invert(ComparisonOutcome);
84   Type Invert(Type);
85   Type FalsifyUndefined(ComparisonOutcome);
86 
87   Type Rangify(Type);
88   Type AddRanger(double lhs_min, double lhs_max, double rhs_min,
89                  double rhs_max);
90   Type SubtractRanger(double lhs_min, double lhs_max, double rhs_min,
91                       double rhs_max);
92   Type MultiplyRanger(Type lhs, Type rhs);
93 
zone()94   Zone* zone() const { return zone_; }
95 
96   Zone* const zone_;
97   TypeCache const& cache_;
98 
99   Type infinity_;
100   Type minus_infinity_;
101   Type singleton_NaN_string_;
102   Type singleton_zero_string_;
103   Type singleton_false_;
104   Type singleton_true_;
105   Type singleton_the_hole_;
106   Type signed32ish_;
107   Type unsigned32ish_;
108   Type singleton_empty_string_;
109   Type truish_;
110   Type falsish_;
111 };
112 
113 }  // namespace compiler
114 }  // namespace internal
115 }  // namespace v8
116 
117 #endif  // V8_COMPILER_OPERATION_TYPER_H_
118