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/code-stubs.h" | 6 #include "src/code-stubs.h" |
7 #include "src/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
8 #include "src/compiler/js-generic-lowering.h" | 8 #include "src/compiler/js-generic-lowering.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 node->ReplaceInput(0, test); | 55 node->ReplaceInput(0, test); |
56 } | 56 } |
57 // Fall-through. | 57 // Fall-through. |
58 default: | 58 default: |
59 // Nothing to see. | 59 // Nothing to see. |
60 return NoChange(); | 60 return NoChange(); |
61 } | 61 } |
62 return Changed(node); | 62 return Changed(node); |
63 } | 63 } |
64 | 64 |
65 | 65 #define REPLACE_BINARY_OP_IC_CALL(Op, token) \ |
66 #define REPLACE_BINARY_OP_IC_CALL(Op, token) \ | 66 void JSGenericLowering::Lower##Op(Node* node) { \ |
67 void JSGenericLowering::Lower##Op(Node* node) { \ | 67 CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); \ |
68 BinaryOperationParameters const& p = \ | 68 ReplaceWithStubCall(node, CodeFactory::BinaryOpIC(isolate(), token), \ |
69 BinaryOperationParametersOf(node->op()); \ | 69 CallDescriptor::kPatchableCallSiteWithNop | flags); \ |
70 CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); \ | |
71 ReplaceWithStubCall(node, \ | |
72 CodeFactory::BinaryOpIC(isolate(), token, \ | |
73 strength(p.language_mode())), \ | |
74 CallDescriptor::kPatchableCallSiteWithNop | flags); \ | |
75 } | 70 } |
76 REPLACE_BINARY_OP_IC_CALL(JSBitwiseOr, Token::BIT_OR) | 71 REPLACE_BINARY_OP_IC_CALL(JSBitwiseOr, Token::BIT_OR) |
77 REPLACE_BINARY_OP_IC_CALL(JSBitwiseXor, Token::BIT_XOR) | 72 REPLACE_BINARY_OP_IC_CALL(JSBitwiseXor, Token::BIT_XOR) |
78 REPLACE_BINARY_OP_IC_CALL(JSBitwiseAnd, Token::BIT_AND) | 73 REPLACE_BINARY_OP_IC_CALL(JSBitwiseAnd, Token::BIT_AND) |
79 REPLACE_BINARY_OP_IC_CALL(JSShiftLeft, Token::SHL) | 74 REPLACE_BINARY_OP_IC_CALL(JSShiftLeft, Token::SHL) |
80 REPLACE_BINARY_OP_IC_CALL(JSShiftRight, Token::SAR) | 75 REPLACE_BINARY_OP_IC_CALL(JSShiftRight, Token::SAR) |
81 REPLACE_BINARY_OP_IC_CALL(JSShiftRightLogical, Token::SHR) | 76 REPLACE_BINARY_OP_IC_CALL(JSShiftRightLogical, Token::SHR) |
82 REPLACE_BINARY_OP_IC_CALL(JSAdd, Token::ADD) | 77 REPLACE_BINARY_OP_IC_CALL(JSAdd, Token::ADD) |
83 REPLACE_BINARY_OP_IC_CALL(JSSubtract, Token::SUB) | 78 REPLACE_BINARY_OP_IC_CALL(JSSubtract, Token::SUB) |
84 REPLACE_BINARY_OP_IC_CALL(JSMultiply, Token::MUL) | 79 REPLACE_BINARY_OP_IC_CALL(JSMultiply, Token::MUL) |
85 REPLACE_BINARY_OP_IC_CALL(JSDivide, Token::DIV) | 80 REPLACE_BINARY_OP_IC_CALL(JSDivide, Token::DIV) |
86 REPLACE_BINARY_OP_IC_CALL(JSModulus, Token::MOD) | 81 REPLACE_BINARY_OP_IC_CALL(JSModulus, Token::MOD) |
87 #undef REPLACE_BINARY_OP_IC_CALL | 82 #undef REPLACE_BINARY_OP_IC_CALL |
88 | 83 |
89 | 84 |
90 // These ops are not language mode dependent; we arbitrarily pass Strength::WEAK | 85 // These ops are not language mode dependent; we arbitrarily pass Strength::WEAK |
91 // here. | 86 // here. |
92 #define REPLACE_COMPARE_IC_CALL(op, token) \ | 87 #define REPLACE_COMPARE_IC_CALL(op, token) \ |
93 void JSGenericLowering::Lower##op(Node* node) { \ | 88 void JSGenericLowering::Lower##op(Node* node) { \ |
94 ReplaceWithCompareIC(node, token, Strength::WEAK); \ | 89 ReplaceWithCompareIC(node, token); \ |
95 } | 90 } |
96 REPLACE_COMPARE_IC_CALL(JSEqual, Token::EQ) | 91 REPLACE_COMPARE_IC_CALL(JSEqual, Token::EQ) |
97 REPLACE_COMPARE_IC_CALL(JSNotEqual, Token::NE) | 92 REPLACE_COMPARE_IC_CALL(JSNotEqual, Token::NE) |
98 REPLACE_COMPARE_IC_CALL(JSStrictEqual, Token::EQ_STRICT) | 93 REPLACE_COMPARE_IC_CALL(JSStrictEqual, Token::EQ_STRICT) |
99 REPLACE_COMPARE_IC_CALL(JSStrictNotEqual, Token::NE_STRICT) | 94 REPLACE_COMPARE_IC_CALL(JSStrictNotEqual, Token::NE_STRICT) |
| 95 REPLACE_COMPARE_IC_CALL(JSLessThan, Token::LT) |
| 96 REPLACE_COMPARE_IC_CALL(JSGreaterThan, Token::GT) |
| 97 REPLACE_COMPARE_IC_CALL(JSLessThanOrEqual, Token::LTE) |
| 98 REPLACE_COMPARE_IC_CALL(JSGreaterThanOrEqual, Token::GTE) |
100 #undef REPLACE_COMPARE_IC_CALL | 99 #undef REPLACE_COMPARE_IC_CALL |
101 | 100 |
102 | 101 |
103 #define REPLACE_COMPARE_IC_CALL_WITH_LANGUAGE_MODE(op, token) \ | |
104 void JSGenericLowering::Lower##op(Node* node) { \ | |
105 ReplaceWithCompareIC(node, token, \ | |
106 strength(OpParameter<LanguageMode>(node))); \ | |
107 } | |
108 REPLACE_COMPARE_IC_CALL_WITH_LANGUAGE_MODE(JSLessThan, Token::LT) | |
109 REPLACE_COMPARE_IC_CALL_WITH_LANGUAGE_MODE(JSGreaterThan, Token::GT) | |
110 REPLACE_COMPARE_IC_CALL_WITH_LANGUAGE_MODE(JSLessThanOrEqual, Token::LTE) | |
111 REPLACE_COMPARE_IC_CALL_WITH_LANGUAGE_MODE(JSGreaterThanOrEqual, Token::GTE) | |
112 #undef REPLACE_COMPARE_IC_CALL_WITH_LANGUAGE_MODE | |
113 | |
114 | |
115 #define REPLACE_RUNTIME_CALL(op, fun) \ | 102 #define REPLACE_RUNTIME_CALL(op, fun) \ |
116 void JSGenericLowering::Lower##op(Node* node) { \ | 103 void JSGenericLowering::Lower##op(Node* node) { \ |
117 ReplaceWithRuntimeCall(node, fun); \ | 104 ReplaceWithRuntimeCall(node, fun); \ |
118 } | 105 } |
119 REPLACE_RUNTIME_CALL(JSCreateWithContext, Runtime::kPushWithContext) | 106 REPLACE_RUNTIME_CALL(JSCreateWithContext, Runtime::kPushWithContext) |
120 REPLACE_RUNTIME_CALL(JSCreateModuleContext, Runtime::kPushModuleContext) | 107 REPLACE_RUNTIME_CALL(JSCreateModuleContext, Runtime::kPushModuleContext) |
121 REPLACE_RUNTIME_CALL(JSConvertReceiver, Runtime::kConvertReceiver) | 108 REPLACE_RUNTIME_CALL(JSConvertReceiver, Runtime::kConvertReceiver) |
122 #undef REPLACE_RUNTIME | 109 #undef REPLACE_RUNTIME |
123 | 110 |
124 | 111 |
125 static CallDescriptor::Flags FlagsForNode(Node* node) { | 112 static CallDescriptor::Flags FlagsForNode(Node* node) { |
126 CallDescriptor::Flags result = CallDescriptor::kNoFlags; | 113 CallDescriptor::Flags result = CallDescriptor::kNoFlags; |
127 if (OperatorProperties::GetFrameStateInputCount(node->op()) > 0) { | 114 if (OperatorProperties::GetFrameStateInputCount(node->op()) > 0) { |
128 result |= CallDescriptor::kNeedsFrameState; | 115 result |= CallDescriptor::kNeedsFrameState; |
129 } | 116 } |
130 return result; | 117 return result; |
131 } | 118 } |
132 | 119 |
133 | 120 void JSGenericLowering::ReplaceWithCompareIC(Node* node, Token::Value token) { |
134 void JSGenericLowering::ReplaceWithCompareIC(Node* node, Token::Value token, | 121 Callable callable = CodeFactory::CompareIC(isolate(), token); |
135 Strength str) { | |
136 Callable callable = CodeFactory::CompareIC(isolate(), token, str); | |
137 | 122 |
138 // Create a new call node asking a CompareIC for help. | 123 // Create a new call node asking a CompareIC for help. |
139 NodeVector inputs(zone()); | 124 NodeVector inputs(zone()); |
140 inputs.reserve(node->InputCount() + 1); | 125 inputs.reserve(node->InputCount() + 1); |
141 inputs.push_back(jsgraph()->HeapConstant(callable.code())); | 126 inputs.push_back(jsgraph()->HeapConstant(callable.code())); |
142 inputs.push_back(NodeProperties::GetValueInput(node, 0)); | 127 inputs.push_back(NodeProperties::GetValueInput(node, 0)); |
143 inputs.push_back(NodeProperties::GetValueInput(node, 1)); | 128 inputs.push_back(NodeProperties::GetValueInput(node, 1)); |
144 inputs.push_back(NodeProperties::GetContextInput(node)); | 129 inputs.push_back(NodeProperties::GetContextInput(node)); |
145 // Some comparisons (StrictEqual) don't have an effect, control or frame | 130 // Some comparisons (StrictEqual) don't have an effect, control or frame |
146 // state inputs, so handle those cases here. | 131 // state inputs, so handle those cases here. |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 } | 859 } |
875 | 860 |
876 | 861 |
877 MachineOperatorBuilder* JSGenericLowering::machine() const { | 862 MachineOperatorBuilder* JSGenericLowering::machine() const { |
878 return jsgraph()->machine(); | 863 return jsgraph()->machine(); |
879 } | 864 } |
880 | 865 |
881 } // namespace compiler | 866 } // namespace compiler |
882 } // namespace internal | 867 } // namespace internal |
883 } // namespace v8 | 868 } // namespace v8 |
OLD | NEW |