OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #include "src/compiler/js-context-relaxation.h" |
| 6 #include "src/compiler/js-graph.h" |
| 7 #include "test/unittests/compiler/graph-unittest.h" |
| 8 #include "test/unittests/compiler/node-test-utils.h" |
| 9 |
| 10 namespace v8 { |
| 11 namespace internal { |
| 12 namespace compiler { |
| 13 |
| 14 class JSContextRelaxationTest : public GraphTest { |
| 15 public: |
| 16 JSContextRelaxationTest() : GraphTest(3), javascript_(zone()) {} |
| 17 ~JSContextRelaxationTest() override {} |
| 18 |
| 19 protected: |
| 20 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = |
| 21 MachineOperatorBuilder::kNoFlags) { |
| 22 MachineOperatorBuilder machine(zone(), kMachPtr, flags); |
| 23 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &machine); |
| 24 // TODO(titzer): mock the GraphReducer here for better unit testing. |
| 25 GraphReducer graph_reducer(zone(), graph()); |
| 26 JSContextRelaxation reducer; |
| 27 return reducer.Reduce(node); |
| 28 } |
| 29 |
| 30 Node* EmptyFrameState() { |
| 31 MachineOperatorBuilder machine(zone()); |
| 32 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &machine); |
| 33 return jsgraph.EmptyFrameState(); |
| 34 } |
| 35 |
| 36 Node* ShallowFrameStateChain(Node* outer_context, |
| 37 ContextCallingMode context_calling_mode) { |
| 38 const FrameStateFunctionInfo* const frame_state_function_info = |
| 39 common()->CreateFrameStateFunctionInfo( |
| 40 FrameStateType::kJavaScriptFunction, 3, 0, |
| 41 Handle<SharedFunctionInfo>(), context_calling_mode); |
| 42 const Operator* op = common()->FrameState(BailoutId::None(), |
| 43 OutputFrameStateCombine::Ignore(), |
| 44 frame_state_function_info); |
| 45 return graph()->NewNode(op, graph()->start(), graph()->start(), |
| 46 graph()->start(), outer_context, graph()->start(), |
| 47 graph()->start()); |
| 48 } |
| 49 |
| 50 Node* DeepFrameStateChain(Node* outer_context, |
| 51 ContextCallingMode context_calling_mode) { |
| 52 const FrameStateFunctionInfo* const frame_state_function_info = |
| 53 common()->CreateFrameStateFunctionInfo( |
| 54 FrameStateType::kJavaScriptFunction, 3, 0, |
| 55 Handle<SharedFunctionInfo>(), context_calling_mode); |
| 56 const Operator* op = common()->FrameState(BailoutId::None(), |
| 57 OutputFrameStateCombine::Ignore(), |
| 58 frame_state_function_info); |
| 59 Node* shallow_frame_state = |
| 60 ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 61 return graph()->NewNode(op, graph()->start(), graph()->start(), |
| 62 graph()->start(), graph()->start(), |
| 63 graph()->start(), shallow_frame_state); |
| 64 } |
| 65 |
| 66 JSOperatorBuilder* javascript() { return &javascript_; } |
| 67 |
| 68 private: |
| 69 JSOperatorBuilder javascript_; |
| 70 }; |
| 71 |
| 72 |
| 73 TEST_F(JSContextRelaxationTest, |
| 74 RelaxJSCallFunctionShallowFrameStateChainNoCrossCtx) { |
| 75 Node* const input0 = Parameter(0); |
| 76 Node* const input1 = Parameter(1); |
| 77 Node* const context = Parameter(2); |
| 78 Node* const outer_context = Parameter(3); |
| 79 Node* const frame_state = |
| 80 ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 81 Node* const effect = graph()->start(); |
| 82 Node* const control = graph()->start(); |
| 83 Node* node = |
| 84 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 85 STRICT, VectorSlotPair()), |
| 86 input0, input1, context, frame_state, effect, control); |
| 87 Reduction const r = Reduce(node); |
| 88 EXPECT_TRUE(r.Changed()); |
| 89 EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); |
| 90 } |
| 91 |
| 92 TEST_F(JSContextRelaxationTest, |
| 93 RelaxJSCallFunctionShallowFrameStateChainCrossCtx) { |
| 94 Node* const input0 = Parameter(0); |
| 95 Node* const input1 = Parameter(1); |
| 96 Node* const context = Parameter(2); |
| 97 Node* const outer_context = Parameter(3); |
| 98 Node* const frame_state = |
| 99 ShallowFrameStateChain(outer_context, CALL_CHANGES_NATIVE_CONTEXT); |
| 100 Node* const effect = graph()->start(); |
| 101 Node* const control = graph()->start(); |
| 102 Node* node = |
| 103 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 104 STRICT, VectorSlotPair()), |
| 105 input0, input1, context, frame_state, effect, control); |
| 106 Reduction const r = Reduce(node); |
| 107 EXPECT_FALSE(r.Changed()); |
| 108 EXPECT_EQ(context, NodeProperties::GetContextInput(node)); |
| 109 } |
| 110 |
| 111 TEST_F(JSContextRelaxationTest, |
| 112 RelaxJSCallFunctionDeepFrameStateChainNoCrossCtx) { |
| 113 Node* const input0 = Parameter(0); |
| 114 Node* const input1 = Parameter(1); |
| 115 Node* const context = Parameter(2); |
| 116 Node* const outer_context = Parameter(3); |
| 117 Node* const frame_state = |
| 118 DeepFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 119 Node* const effect = graph()->start(); |
| 120 Node* const control = graph()->start(); |
| 121 Node* node = |
| 122 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 123 STRICT, VectorSlotPair()), |
| 124 input0, input1, context, frame_state, effect, control); |
| 125 Reduction const r = Reduce(node); |
| 126 EXPECT_TRUE(r.Changed()); |
| 127 EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); |
| 128 } |
| 129 |
| 130 TEST_F(JSContextRelaxationTest, |
| 131 RelaxJSCallFunctionDeepFrameStateChainCrossCtx) { |
| 132 Node* const input0 = Parameter(0); |
| 133 Node* const input1 = Parameter(1); |
| 134 Node* const context = Parameter(2); |
| 135 Node* const outer_context = Parameter(3); |
| 136 Node* const frame_state = |
| 137 DeepFrameStateChain(outer_context, CALL_CHANGES_NATIVE_CONTEXT); |
| 138 Node* const effect = graph()->start(); |
| 139 Node* const control = graph()->start(); |
| 140 Node* node = |
| 141 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 142 STRICT, VectorSlotPair()), |
| 143 input0, input1, context, frame_state, effect, control); |
| 144 Reduction const r = Reduce(node); |
| 145 EXPECT_FALSE(r.Changed()); |
| 146 EXPECT_EQ(context, NodeProperties::GetContextInput(node)); |
| 147 } |
| 148 |
| 149 TEST_F(JSContextRelaxationTest, |
| 150 RelaxJSCallFunctionDeepContextChainFullRelaxForCatch) { |
| 151 Node* const input0 = Parameter(0); |
| 152 Node* const input1 = Parameter(1); |
| 153 Node* const context = Parameter(2); |
| 154 Node* const outer_context = Parameter(3); |
| 155 const Operator* op = javascript()->CreateCatchContext(Unique<String>()); |
| 156 Node* const frame_state_1 = |
| 157 ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 158 Node* const effect = graph()->start(); |
| 159 Node* const control = graph()->start(); |
| 160 Node* nested_context = |
| 161 graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, |
| 162 frame_state_1, effect, control); |
| 163 Node* const frame_state_2 = |
| 164 ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 165 Node* node = |
| 166 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 167 STRICT, VectorSlotPair()), |
| 168 input0, input1, context, frame_state_2, effect, control); |
| 169 Reduction const r = Reduce(node); |
| 170 EXPECT_TRUE(r.Changed()); |
| 171 EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); |
| 172 } |
| 173 |
| 174 |
| 175 TEST_F(JSContextRelaxationTest, |
| 176 RelaxJSCallFunctionDeepContextChainFullRelaxForWith) { |
| 177 Node* const input0 = Parameter(0); |
| 178 Node* const input1 = Parameter(1); |
| 179 Node* const context = Parameter(2); |
| 180 Node* const outer_context = Parameter(3); |
| 181 const Operator* op = javascript()->CreateWithContext(); |
| 182 Node* const frame_state_1 = |
| 183 ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 184 Node* const effect = graph()->start(); |
| 185 Node* const control = graph()->start(); |
| 186 Node* nested_context = |
| 187 graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, |
| 188 frame_state_1, effect, control); |
| 189 Node* const frame_state_2 = |
| 190 ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 191 Node* node = |
| 192 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 193 STRICT, VectorSlotPair()), |
| 194 input0, input1, context, frame_state_2, effect, control); |
| 195 Reduction const r = Reduce(node); |
| 196 EXPECT_TRUE(r.Changed()); |
| 197 EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); |
| 198 } |
| 199 |
| 200 |
| 201 TEST_F(JSContextRelaxationTest, |
| 202 RelaxJSCallFunctionDeepContextChainFullRelaxForBlock) { |
| 203 Node* const input0 = Parameter(0); |
| 204 Node* const input1 = Parameter(1); |
| 205 Node* const context = Parameter(2); |
| 206 Node* const outer_context = Parameter(3); |
| 207 const Operator* op = javascript()->CreateBlockContext(); |
| 208 Node* const frame_state_1 = |
| 209 ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 210 Node* const effect = graph()->start(); |
| 211 Node* const control = graph()->start(); |
| 212 Node* nested_context = |
| 213 graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, |
| 214 frame_state_1, effect, control); |
| 215 Node* const frame_state_2 = |
| 216 ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 217 Node* node = |
| 218 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 219 STRICT, VectorSlotPair()), |
| 220 input0, input1, context, frame_state_2, effect, control); |
| 221 Reduction const r = Reduce(node); |
| 222 EXPECT_TRUE(r.Changed()); |
| 223 EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); |
| 224 } |
| 225 |
| 226 |
| 227 TEST_F(JSContextRelaxationTest, |
| 228 RelaxJSCallFunctionDeepContextChainPartialRelaxForScript) { |
| 229 Node* const input0 = Parameter(0); |
| 230 Node* const input1 = Parameter(1); |
| 231 Node* const context = Parameter(2); |
| 232 Node* const outer_context = Parameter(3); |
| 233 const Operator* op = javascript()->CreateScriptContext(); |
| 234 Node* const frame_state_1 = |
| 235 ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 236 Node* const effect = graph()->start(); |
| 237 Node* const control = graph()->start(); |
| 238 Node* nested_context = |
| 239 graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, |
| 240 frame_state_1, effect, control); |
| 241 Node* const frame_state_2 = |
| 242 ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 243 Node* node = |
| 244 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 245 STRICT, VectorSlotPair()), |
| 246 input0, input1, context, frame_state_2, effect, control); |
| 247 Reduction const r = Reduce(node); |
| 248 EXPECT_TRUE(r.Changed()); |
| 249 EXPECT_EQ(nested_context, NodeProperties::GetContextInput(node)); |
| 250 } |
| 251 |
| 252 |
| 253 TEST_F(JSContextRelaxationTest, |
| 254 RelaxJSCallFunctionDeepContextChainPartialRelaxForModule) { |
| 255 Node* const input0 = Parameter(0); |
| 256 Node* const input1 = Parameter(1); |
| 257 Node* const context = Parameter(2); |
| 258 Node* const outer_context = Parameter(3); |
| 259 const Operator* op = javascript()->CreateModuleContext(); |
| 260 Node* const frame_state_1 = |
| 261 ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 262 Node* const effect = graph()->start(); |
| 263 Node* const control = graph()->start(); |
| 264 Node* nested_context = |
| 265 graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, |
| 266 frame_state_1, effect, control); |
| 267 Node* const frame_state_2 = |
| 268 ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 269 Node* node = |
| 270 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 271 STRICT, VectorSlotPair()), |
| 272 input0, input1, context, frame_state_2, effect, control); |
| 273 Reduction const r = Reduce(node); |
| 274 EXPECT_TRUE(r.Changed()); |
| 275 EXPECT_EQ(nested_context, NodeProperties::GetContextInput(node)); |
| 276 } |
| 277 |
| 278 |
| 279 TEST_F(JSContextRelaxationTest, |
| 280 RelaxJSCallFunctionDeepContextChainPartialNoRelax) { |
| 281 Node* const input0 = Parameter(0); |
| 282 Node* const input1 = Parameter(1); |
| 283 Node* const context = Parameter(2); |
| 284 Node* const outer_context = Parameter(3); |
| 285 const Operator* op = javascript()->CreateFunctionContext(); |
| 286 Node* const frame_state_1 = |
| 287 ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 288 Node* const effect = graph()->start(); |
| 289 Node* const control = graph()->start(); |
| 290 Node* nested_context = |
| 291 graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, |
| 292 frame_state_1, effect, control); |
| 293 Node* const frame_state_2 = |
| 294 ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); |
| 295 Node* node = |
| 296 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, |
| 297 STRICT, VectorSlotPair()), |
| 298 input0, input1, context, frame_state_2, effect, control); |
| 299 Reduction const r = Reduce(node); |
| 300 EXPECT_FALSE(r.Changed()); |
| 301 EXPECT_EQ(context, NodeProperties::GetContextInput(node)); |
| 302 } |
| 303 |
| 304 } // namespace compiler |
| 305 } // namespace internal |
| 306 } // namespace v8 |
OLD | NEW |