5 #include "src/compiler/type-narrowing-reducer.h" 7 #include "src/compiler/js-graph.h" 8 #include "src/objects-inl.h" 14 TypeNarrowingReducer::TypeNarrowingReducer(Editor* editor, JSGraph* jsgraph,
16 : AdvancedReducer(editor), jsgraph_(jsgraph), op_typer_(broker, zone()) {}
18 TypeNarrowingReducer::~TypeNarrowingReducer() =
default;
20 Reduction TypeNarrowingReducer::Reduce(Node* node) {
21 DisallowHeapAccess no_heap_access;
23 Type new_type = Type::Any();
25 switch (node->opcode()) {
26 case IrOpcode::kNumberLessThan: {
29 Type left_type = NodeProperties::GetType(node->InputAt(0));
30 Type right_type = NodeProperties::GetType(node->InputAt(1));
31 if (left_type.Is(Type::PlainNumber()) &&
32 right_type.Is(Type::PlainNumber())) {
33 if (left_type.Max() < right_type.Min()) {
34 new_type = op_typer_.singleton_true();
35 }
else if (left_type.Min() >= right_type.Max()) {
36 new_type = op_typer_.singleton_false();
42 case IrOpcode::kTypeGuard: {
43 new_type = op_typer_.TypeTypeGuard(
44 node->op(), NodeProperties::GetType(node->InputAt(0)));
48 #define DECLARE_CASE(Name) \ 49 case IrOpcode::k##Name: { \ 50 new_type = op_typer_.Name(NodeProperties::GetType(node->InputAt(0)), \ 51 NodeProperties::GetType(node->InputAt(1))); \ 54 SIMPLIFIED_NUMBER_BINOP_LIST(DECLARE_CASE)
55 DECLARE_CASE(SameValue)
58 #define DECLARE_CASE(Name) \ 59 case IrOpcode::k##Name: { \ 60 new_type = op_typer_.Name(NodeProperties::GetType(node->InputAt(0))); \ 63 SIMPLIFIED_NUMBER_UNOP_LIST(DECLARE_CASE)
64 DECLARE_CASE(ToBoolean)
71 Type original_type = NodeProperties::GetType(node);
72 Type restricted = Type::Intersect(new_type, original_type, zone());
73 if (!original_type.Is(restricted)) {
74 NodeProperties::SetType(node, restricted);
80 Graph* TypeNarrowingReducer::graph()
const {
return jsgraph()->graph(); }
82 Zone* TypeNarrowingReducer::zone()
const {
return graph()->zone(); }