operation-typer.h 3.26 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_OPERATION_TYPER_H_
#define V8_COMPILER_OPERATION_TYPER_H_

#include "src/base/flags.h"
#include "src/compiler/opcodes.h"
10
#include "src/compiler/types.h"
11
#include "src/objects/objects.h"
12 13 14 15

namespace v8 {
namespace internal {

16
// Forward declarations.
17 18 19 20 21 22
class Isolate;
class RangeType;
class Zone;

namespace compiler {

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 36
  Type ToPrimitive(Type type);
  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 68 69
  Type CheckFloat64Hole(Type type);
  Type CheckNumber(Type type);
  Type ConvertTaggedHoleToUndefined(Type type);
70

71
  Type TypeTypeGuard(const Operator* sigma_op, Type input);
72

73 74 75 76 77 78
  enum ComparisonOutcomeFlags {
    kComparisonTrue = 1,
    kComparisonFalse = 2,
    kComparisonUndefined = 4
  };

79 80 81
  Type singleton_false() const { return singleton_false_; }
  Type singleton_true() const { return singleton_true_; }
  Type singleton_the_hole() const { return singleton_the_hole_; }
82 83

 private:
84
  using ComparisonOutcome = base::Flags<ComparisonOutcomeFlags>;
85 86

  ComparisonOutcome Invert(ComparisonOutcome);
87 88
  Type Invert(Type);
  Type FalsifyUndefined(ComparisonOutcome);
89

90 91 92 93 94
  Type Rangify(Type);
  Type AddRanger(double lhs_min, double lhs_max, double rhs_min,
                 double rhs_max);
  Type SubtractRanger(double lhs_min, double lhs_max, double rhs_min,
                      double rhs_max);
95 96
  Type MultiplyRanger(double lhs_min, double lhs_max, double rhs_min,
                      double rhs_max);
97

98
  Zone* zone() const { return zone_; }
99

100
  Zone* const zone_;
101
  TypeCache const* cache_;
102

103 104 105 106 107 108 109 110 111
  Type infinity_;
  Type minus_infinity_;
  Type singleton_NaN_string_;
  Type singleton_zero_string_;
  Type singleton_false_;
  Type singleton_true_;
  Type singleton_the_hole_;
  Type signed32ish_;
  Type unsigned32ish_;
112 113 114
  Type singleton_empty_string_;
  Type truish_;
  Type falsish_;
115 116 117 118 119 120 121
};

}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_OPERATION_TYPER_H_