operation-typer.h 2.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// 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"

namespace v8 {
namespace internal {

14
// Forward declarations.
15 16 17 18 19 20
class Isolate;
class RangeType;
class Zone;

namespace compiler {

21
// Forward declarations.
22
class Operator;
23
class Type;
24
class TypeCache;
25

26 27 28 29 30 31 32 33 34 35 36 37 38
class OperationTyper {
 public:
  OperationTyper(Isolate* isolate, Zone* zone);

  // Typing Phi.
  Type* Merge(Type* left, Type* right);

  Type* ToPrimitive(Type* type);

  // Helpers for number operation typing.
  Type* ToNumber(Type* type);
  Type* WeakenRange(Type* current_range, Type* previous_range);

39 40 41 42
// Number unary operators.
#define DECLARE_METHOD(Name) Type* Name(Type* type);
  SIMPLIFIED_NUMBER_UNOP_LIST(DECLARE_METHOD)
#undef DECLARE_METHOD
43

44 45 46 47 48
// Number binary operators.
#define DECLARE_METHOD(Name) Type* Name(Type* lhs, Type* rhs);
  SIMPLIFIED_NUMBER_BINOP_LIST(DECLARE_METHOD)
  SIMPLIFIED_SPECULATIVE_NUMBER_BINOP_LIST(DECLARE_METHOD)
#undef DECLARE_METHOD
49

50 51
  Type* TypeTypeGuard(const Operator* sigma_op, Type* input);

52 53 54 55 56 57
  enum ComparisonOutcomeFlags {
    kComparisonTrue = 1,
    kComparisonFalse = 2,
    kComparisonUndefined = 4
  };

58 59 60
  Type* singleton_false() const { return singleton_false_; }
  Type* singleton_true() const { return singleton_true_; }
  Type* singleton_the_hole() const { return singleton_the_hole_; }
61 62 63 64 65 66 67 68 69

 private:
  typedef base::Flags<ComparisonOutcomeFlags> ComparisonOutcome;

  ComparisonOutcome Invert(ComparisonOutcome);
  Type* Invert(Type*);
  Type* FalsifyUndefined(ComparisonOutcome);

  Type* Rangify(Type*);
70 71
  Type* AddRanger(double lhs_min, double lhs_max, double rhs_min,
                  double rhs_max);
72 73
  Type* SubtractRanger(double lhs_min, double lhs_max, double rhs_min,
                       double rhs_max);
74
  Type* MultiplyRanger(Type* lhs, Type* rhs);
75

76
  Zone* zone() const { return zone_; }
77

78
  Zone* const zone_;
79 80
  TypeCache const& cache_;

81 82
  Type* infinity_;
  Type* minus_infinity_;
83 84 85
  Type* singleton_false_;
  Type* singleton_true_;
  Type* singleton_the_hole_;
86 87
  Type* signed32ish_;
  Type* unsigned32ish_;
88 89 90 91 92 93 94
};

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

#endif  // V8_COMPILER_OPERATION_TYPER_H_