| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/simplified-operator-reducer.h" |
| 6 |
| 7 #include "src/compiler/access-builder.h" |
| 5 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 6 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
| 7 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| 8 #include "src/compiler/simplified-operator-reducer.h" | 11 #include "src/compiler/node-properties-inl.h" |
| 9 | 12 |
| 10 namespace v8 { | 13 namespace v8 { |
| 11 namespace internal { | 14 namespace internal { |
| 12 namespace compiler { | 15 namespace compiler { |
| 13 | 16 |
| 14 SimplifiedOperatorReducer::SimplifiedOperatorReducer(JSGraph* jsgraph) | 17 SimplifiedOperatorReducer::SimplifiedOperatorReducer(JSGraph* jsgraph) |
| 15 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} | 18 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} |
| 16 | 19 |
| 17 | 20 |
| 18 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} | 21 SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {} |
| 19 | 22 |
| 20 | 23 |
| 21 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { | 24 Reduction SimplifiedOperatorReducer::Reduce(Node* node) { |
| 22 switch (node->opcode()) { | 25 switch (node->opcode()) { |
| 26 case IrOpcode::kAnyToBoolean: |
| 27 return ReduceAnyToBoolean(node); |
| 23 case IrOpcode::kBooleanNot: { | 28 case IrOpcode::kBooleanNot: { |
| 24 HeapObjectMatcher<HeapObject> m(node->InputAt(0)); | 29 HeapObjectMatcher<HeapObject> m(node->InputAt(0)); |
| 25 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) { | 30 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) { |
| 26 return Replace(jsgraph()->TrueConstant()); | 31 return Replace(jsgraph()->TrueConstant()); |
| 27 } | 32 } |
| 28 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->true_value()))) { | 33 if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->true_value()))) { |
| 29 return Replace(jsgraph()->FalseConstant()); | 34 return Replace(jsgraph()->FalseConstant()); |
| 30 } | 35 } |
| 31 if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0)); | 36 if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0)); |
| 32 break; | 37 break; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value())); | 103 if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value())); |
| 99 break; | 104 break; |
| 100 } | 105 } |
| 101 default: | 106 default: |
| 102 break; | 107 break; |
| 103 } | 108 } |
| 104 return NoChange(); | 109 return NoChange(); |
| 105 } | 110 } |
| 106 | 111 |
| 107 | 112 |
| 113 Reduction SimplifiedOperatorReducer::ReduceAnyToBoolean(Node* node) { |
| 114 Node* const input = NodeProperties::GetValueInput(node, 0); |
| 115 Type* const input_type = NodeProperties::GetBounds(input).upper; |
| 116 if (input_type->Is(Type::Boolean())) { |
| 117 // AnyToBoolean(x:boolean) => x |
| 118 return Replace(input); |
| 119 } |
| 120 if (input_type->Is(Type::OrderedNumber())) { |
| 121 // AnyToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x, #0)) |
| 122 Node* compare = graph()->NewNode(simplified()->NumberEqual(), input, |
| 123 jsgraph()->ZeroConstant()); |
| 124 return Change(node, simplified()->BooleanNot(), compare); |
| 125 } |
| 126 if (input_type->Is(Type::String())) { |
| 127 // AnyToBoolean(x:string) => BooleanNot(NumberEqual(x.length, #0)) |
| 128 FieldAccess const access = AccessBuilder::ForStringLength(); |
| 129 Node* length = graph()->NewNode(simplified()->LoadField(access), input, |
| 130 graph()->start(), graph()->start()); |
| 131 Node* compare = graph()->NewNode(simplified()->NumberEqual(), length, |
| 132 jsgraph()->ZeroConstant()); |
| 133 return Change(node, simplified()->BooleanNot(), compare); |
| 134 } |
| 135 return NoChange(); |
| 136 } |
| 137 |
| 138 |
| 108 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, | 139 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, |
| 109 Node* a) { | 140 Node* a) { |
| 141 DCHECK_EQ(node->InputCount(), OperatorProperties::GetTotalInputCount(op)); |
| 142 DCHECK_LE(1, node->InputCount()); |
| 110 node->set_op(op); | 143 node->set_op(op); |
| 111 node->ReplaceInput(0, a); | 144 node->ReplaceInput(0, a); |
| 112 return Changed(node); | 145 return Changed(node); |
| 113 } | 146 } |
| 114 | 147 |
| 115 | 148 |
| 116 Reduction SimplifiedOperatorReducer::ReplaceFloat64(double value) { | 149 Reduction SimplifiedOperatorReducer::ReplaceFloat64(double value) { |
| 117 return Replace(jsgraph()->Float64Constant(value)); | 150 return Replace(jsgraph()->Float64Constant(value)); |
| 118 } | 151 } |
| 119 | 152 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 134 | 167 |
| 135 | 168 |
| 136 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } | 169 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 137 | 170 |
| 138 | 171 |
| 139 Factory* SimplifiedOperatorReducer::factory() const { | 172 Factory* SimplifiedOperatorReducer::factory() const { |
| 140 return jsgraph()->isolate()->factory(); | 173 return jsgraph()->isolate()->factory(); |
| 141 } | 174 } |
| 142 | 175 |
| 143 | 176 |
| 177 CommonOperatorBuilder* SimplifiedOperatorReducer::common() const { |
| 178 return jsgraph()->common(); |
| 179 } |
| 180 |
| 181 |
| 144 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { | 182 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { |
| 145 return jsgraph()->machine(); | 183 return jsgraph()->machine(); |
| 146 } | 184 } |
| 147 | 185 |
| 148 } // namespace compiler | 186 } // namespace compiler |
| 149 } // namespace internal | 187 } // namespace internal |
| 150 } // namespace v8 | 188 } // namespace v8 |
| OLD | NEW |