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/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
9 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 node_->ReplaceInput(0, left_input); | 136 node_->ReplaceInput(0, left_input); |
137 node_->ReplaceInput(1, right_input); | 137 node_->ReplaceInput(1, right_input); |
138 } | 138 } |
139 | 139 |
140 void ConvertInputsToUI32(Signedness left_signedness, | 140 void ConvertInputsToUI32(Signedness left_signedness, |
141 Signedness right_signedness) { | 141 Signedness right_signedness) { |
142 node_->ReplaceInput(0, ConvertToUI32(left(), left_signedness)); | 142 node_->ReplaceInput(0, ConvertToUI32(left(), left_signedness)); |
143 node_->ReplaceInput(1, ConvertToUI32(right(), right_signedness)); | 143 node_->ReplaceInput(1, ConvertToUI32(right(), right_signedness)); |
144 } | 144 } |
145 | 145 |
146 void ConvertInputsToString() { | |
147 node_->ReplaceInput(0, ConvertToString(left())); | |
148 node_->ReplaceInput(1, ConvertToString(right())); | |
149 } | |
150 | |
151 void SwapInputs() { | 146 void SwapInputs() { |
152 Node* l = left(); | 147 Node* l = left(); |
153 Node* r = right(); | 148 Node* r = right(); |
154 node_->ReplaceInput(0, r); | 149 node_->ReplaceInput(0, r); |
155 node_->ReplaceInput(1, l); | 150 node_->ReplaceInput(1, l); |
156 } | 151 } |
157 | 152 |
158 // Remove all effect and control inputs and outputs to this node and change | 153 // Remove all effect and control inputs and outputs to this node and change |
159 // to the pure operator {op}, possibly inserting a boolean inversion. | 154 // to the pure operator {op}, possibly inserting a boolean inversion. |
160 Reduction ChangeToPureOperator(const Operator* op, bool invert = false, | 155 Reduction ChangeToPureOperator(const Operator* op, bool invert = false, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 JSGraph* jsgraph() { return lowering_->jsgraph(); } | 245 JSGraph* jsgraph() { return lowering_->jsgraph(); } |
251 JSOperatorBuilder* javascript() { return lowering_->javascript(); } | 246 JSOperatorBuilder* javascript() { return lowering_->javascript(); } |
252 MachineOperatorBuilder* machine() { return lowering_->machine(); } | 247 MachineOperatorBuilder* machine() { return lowering_->machine(); } |
253 CommonOperatorBuilder* common() { return jsgraph()->common(); } | 248 CommonOperatorBuilder* common() { return jsgraph()->common(); } |
254 Zone* zone() const { return graph()->zone(); } | 249 Zone* zone() const { return graph()->zone(); } |
255 | 250 |
256 private: | 251 private: |
257 JSTypedLowering* lowering_; // The containing lowering instance. | 252 JSTypedLowering* lowering_; // The containing lowering instance. |
258 Node* node_; // The original node. | 253 Node* node_; // The original node. |
259 | 254 |
260 Node* ConvertToString(Node* node) { | |
261 // Avoid introducing too many eager ToString() operations. | |
262 Reduction reduced = lowering_->ReduceJSToStringInput(node); | |
263 if (reduced.Changed()) return reduced.replacement(); | |
264 Node* n = graph()->NewNode(javascript()->ToString(), node, context(), | |
265 effect(), control()); | |
266 update_effect(n); | |
267 return n; | |
268 } | |
269 | |
270 Node* CreateFrameStateForLeftInput(Node* frame_state) { | 255 Node* CreateFrameStateForLeftInput(Node* frame_state) { |
271 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); | 256 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); |
272 | 257 |
273 if (state_info.bailout_id() == BailoutId::None()) { | 258 if (state_info.bailout_id() == BailoutId::None()) { |
274 // Dummy frame state => just leave it as is. | 259 // Dummy frame state => just leave it as is. |
275 return frame_state; | 260 return frame_state; |
276 } | 261 } |
277 | 262 |
278 // If the frame state is already the right one, just return it. | 263 // If the frame state is already the right one, just return it. |
279 if (state_info.state_combine().kind() == OutputFrameStateCombine::kPokeAt && | 264 if (state_info.state_combine().kind() == OutputFrameStateCombine::kPokeAt && |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 if (input->opcode() == IrOpcode::kJSToString) { | 798 if (input->opcode() == IrOpcode::kJSToString) { |
814 // Recursively try to reduce the input first. | 799 // Recursively try to reduce the input first. |
815 Reduction result = ReduceJSToString(input); | 800 Reduction result = ReduceJSToString(input); |
816 if (result.Changed()) return result; | 801 if (result.Changed()) return result; |
817 return Changed(input); // JSToString(JSToString(x)) => JSToString(x) | 802 return Changed(input); // JSToString(JSToString(x)) => JSToString(x) |
818 } | 803 } |
819 Type* input_type = NodeProperties::GetType(input); | 804 Type* input_type = NodeProperties::GetType(input); |
820 if (input_type->Is(Type::String())) { | 805 if (input_type->Is(Type::String())) { |
821 return Changed(input); // JSToString(x:string) => x | 806 return Changed(input); // JSToString(x:string) => x |
822 } | 807 } |
| 808 if (input_type->Is(Type::Boolean())) { |
| 809 return Replace( |
| 810 graph()->NewNode(common()->Select(kMachAnyTagged), input, |
| 811 jsgraph()->HeapConstant(factory()->true_string()), |
| 812 jsgraph()->HeapConstant(factory()->false_string()))); |
| 813 } |
823 if (input_type->Is(Type::Undefined())) { | 814 if (input_type->Is(Type::Undefined())) { |
824 return Replace(jsgraph()->HeapConstant(factory()->undefined_string())); | 815 return Replace(jsgraph()->HeapConstant(factory()->undefined_string())); |
825 } | 816 } |
826 if (input_type->Is(Type::Null())) { | 817 if (input_type->Is(Type::Null())) { |
827 return Replace(jsgraph()->HeapConstant(factory()->null_string())); | 818 return Replace(jsgraph()->HeapConstant(factory()->null_string())); |
828 } | 819 } |
829 // TODO(turbofan): js-typed-lowering of ToString(x:boolean) | |
830 // TODO(turbofan): js-typed-lowering of ToString(x:number) | 820 // TODO(turbofan): js-typed-lowering of ToString(x:number) |
831 return NoChange(); | 821 return NoChange(); |
832 } | 822 } |
833 | 823 |
834 | 824 |
835 Reduction JSTypedLowering::ReduceJSToString(Node* node) { | 825 Reduction JSTypedLowering::ReduceJSToString(Node* node) { |
836 // Try to reduce the input first. | 826 // Try to reduce the input first. |
837 Node* const input = node->InputAt(0); | 827 Node* const input = node->InputAt(0); |
838 Reduction reduction = ReduceJSToStringInput(input); | 828 Reduction reduction = ReduceJSToStringInput(input); |
839 if (reduction.Changed()) { | 829 if (reduction.Changed()) { |
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2142 } | 2132 } |
2143 | 2133 |
2144 | 2134 |
2145 MachineOperatorBuilder* JSTypedLowering::machine() const { | 2135 MachineOperatorBuilder* JSTypedLowering::machine() const { |
2146 return jsgraph()->machine(); | 2136 return jsgraph()->machine(); |
2147 } | 2137 } |
2148 | 2138 |
2149 } // namespace compiler | 2139 } // namespace compiler |
2150 } // namespace internal | 2140 } // namespace internal |
2151 } // namespace v8 | 2141 } // namespace v8 |
OLD | NEW |