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 11namespace v8 { 12namespace internal { 13 14// Forward declarations. 15class Isolate; 16class RangeType; 17class Zone; 18 19namespace compiler { 20 21// Forward declarations. 22class Operator; 23class Type; 24class TypeCache; 25 26class 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 58 Type* singleton_false() const { return singleton_false_; } 59 Type* singleton_true() const { return singleton_true_; } 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 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