| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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/bit-vector.h" | 5 #include "src/bit-vector.h" |
| 6 #include "src/compiler/escape-analysis.h" | 6 #include "src/compiler/escape-analysis.h" |
| 7 #include "src/compiler/escape-analysis-reducer.h" | 7 #include "src/compiler/escape-analysis-reducer.h" |
| 8 #include "src/compiler/graph-visualizer.h" | 8 #include "src/compiler/graph-visualizer.h" |
| 9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 TEST_F(EscapeAnalysisTest, StraightNonEscape) { | 184 TEST_F(EscapeAnalysisTest, StraightNonEscape) { |
| 185 Node* object1 = Constant(1); | 185 Node* object1 = Constant(1); |
| 186 BeginRegion(); | 186 BeginRegion(); |
| 187 Node* allocation = Allocate(Constant(kPointerSize)); | 187 Node* allocation = Allocate(Constant(kPointerSize)); |
| 188 Store(AccessAtIndex(0), allocation, object1); | 188 Store(AccessAtIndex(0), allocation, object1); |
| 189 Node* finish = FinishRegion(allocation); | 189 Node* finish = FinishRegion(allocation); |
| 190 Node* load = Load(AccessAtIndex(0), finish); | 190 Node* load = Load(AccessAtIndex(0), finish); |
| 191 Node* result = Return(load); | 191 Node* result = Return(load); |
| 192 EndGraph(); | 192 EndGraph(); |
| 193 |
| 193 Analysis(); | 194 Analysis(); |
| 194 | 195 |
| 195 ExpectVirtual(allocation); | 196 ExpectVirtual(allocation); |
| 196 ExpectReplacement(load, object1); | 197 ExpectReplacement(load, object1); |
| 197 | 198 |
| 198 Transformation(); | 199 Transformation(); |
| 199 | 200 |
| 200 ASSERT_EQ(object1, NodeProperties::GetValueInput(result, 0)); | 201 ASSERT_EQ(object1, NodeProperties::GetValueInput(result, 0)); |
| 201 } | 202 } |
| 202 | 203 |
| 203 | 204 |
| 204 TEST_F(EscapeAnalysisTest, StraightEscape) { | 205 TEST_F(EscapeAnalysisTest, StraightEscape) { |
| 205 Node* object1 = Constant(1); | 206 Node* object1 = Constant(1); |
| 206 BeginRegion(); | 207 BeginRegion(); |
| 207 Node* allocation = Allocate(Constant(kPointerSize)); | 208 Node* allocation = Allocate(Constant(kPointerSize)); |
| 208 Store(AccessAtIndex(0), allocation, object1); | 209 Store(AccessAtIndex(0), allocation, object1); |
| 209 Node* finish = FinishRegion(allocation); | 210 Node* finish = FinishRegion(allocation); |
| 210 Node* load = Load(AccessAtIndex(0), finish); | 211 Node* load = Load(AccessAtIndex(0), finish); |
| 211 Node* result = Return(allocation); | 212 Node* result = Return(allocation); |
| 212 EndGraph(); | 213 EndGraph(); |
| 214 graph()->end()->AppendInput(zone(), load); |
| 215 |
| 213 Analysis(); | 216 Analysis(); |
| 214 | 217 |
| 215 ExpectEscaped(allocation); | 218 ExpectEscaped(allocation); |
| 216 ExpectReplacement(load, object1); | 219 ExpectReplacement(load, object1); |
| 217 | 220 |
| 218 Transformation(); | 221 Transformation(); |
| 219 | 222 |
| 220 ASSERT_EQ(allocation, NodeProperties::GetValueInput(result, 0)); | 223 ASSERT_EQ(allocation, NodeProperties::GetValueInput(result, 0)); |
| 221 } | 224 } |
| 222 | 225 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 Branch(); | 262 Branch(); |
| 260 Node* ifFalse = IfFalse(); | 263 Node* ifFalse = IfFalse(); |
| 261 Node* ifTrue = IfTrue(); | 264 Node* ifTrue = IfTrue(); |
| 262 Node* effect1 = Store(AccessAtIndex(0), allocation, object1, finish, ifFalse); | 265 Node* effect1 = Store(AccessAtIndex(0), allocation, object1, finish, ifFalse); |
| 263 Node* effect2 = Store(AccessAtIndex(0), allocation, object2, finish, ifTrue); | 266 Node* effect2 = Store(AccessAtIndex(0), allocation, object2, finish, ifTrue); |
| 264 Node* merge = Merge2(ifFalse, ifTrue); | 267 Node* merge = Merge2(ifFalse, ifTrue); |
| 265 Node* phi = graph()->NewNode(common()->EffectPhi(2), effect1, effect2, merge); | 268 Node* phi = graph()->NewNode(common()->EffectPhi(2), effect1, effect2, merge); |
| 266 Node* load = Load(AccessAtIndex(0), finish, phi, merge); | 269 Node* load = Load(AccessAtIndex(0), finish, phi, merge); |
| 267 Node* result = Return(load, phi); | 270 Node* result = Return(load, phi); |
| 268 EndGraph(); | 271 EndGraph(); |
| 272 graph()->end()->AppendInput(zone(), result); |
| 273 |
| 269 Analysis(); | 274 Analysis(); |
| 270 | 275 |
| 271 ExpectVirtual(allocation); | 276 ExpectVirtual(allocation); |
| 272 ExpectReplacementPhi(load, object1, object2); | 277 ExpectReplacementPhi(load, object1, object2); |
| 273 Node* replacement_phi = escape_analysis()->GetReplacement(load); | 278 Node* replacement_phi = escape_analysis()->GetReplacement(load); |
| 274 | 279 |
| 275 Transformation(); | 280 Transformation(); |
| 276 | 281 |
| 277 ASSERT_EQ(replacement_phi, NodeProperties::GetValueInput(result, 0)); | 282 ASSERT_EQ(replacement_phi, NodeProperties::GetValueInput(result, 0)); |
| 278 } | 283 } |
| 279 | 284 |
| 280 | 285 |
| 281 TEST_F(EscapeAnalysisTest, DanglingLoadOrder) { | 286 TEST_F(EscapeAnalysisTest, DanglingLoadOrder) { |
| 282 Node* object1 = Constant(1); | 287 Node* object1 = Constant(1); |
| 283 Node* object2 = Constant(2); | 288 Node* object2 = Constant(2); |
| 284 Node* allocation = Allocate(Constant(kPointerSize)); | 289 Node* allocation = Allocate(Constant(kPointerSize)); |
| 285 Node* store1 = Store(AccessAtIndex(0), allocation, object1); | 290 Node* store1 = Store(AccessAtIndex(0), allocation, object1); |
| 286 Node* load1 = Load(AccessAtIndex(0), allocation); | 291 Node* load1 = Load(AccessAtIndex(0), allocation); |
| 287 Store(AccessAtIndex(0), allocation, object2); | 292 Node* store2 = Store(AccessAtIndex(0), allocation, object2); |
| 288 Node* load2 = Load(AccessAtIndex(0), allocation, store1); | 293 Node* load2 = Load(AccessAtIndex(0), allocation, store1); |
| 289 Node* result = Return(load2); | 294 Node* result = Return(load2); |
| 290 EndGraph(); | 295 EndGraph(); |
| 296 graph()->end()->AppendInput(zone(), store2); |
| 297 graph()->end()->AppendInput(zone(), load1); |
| 291 | 298 |
| 292 Analysis(); | 299 Analysis(); |
| 293 | 300 |
| 294 ExpectVirtual(allocation); | 301 ExpectVirtual(allocation); |
| 295 ExpectReplacement(load1, object1); | 302 ExpectReplacement(load1, object1); |
| 296 ExpectReplacement(load2, object1); | 303 ExpectReplacement(load2, object1); |
| 297 | 304 |
| 298 Transformation(); | 305 Transformation(); |
| 299 | 306 |
| 300 ASSERT_EQ(object1, NodeProperties::GetValueInput(result, 0)); | 307 ASSERT_EQ(object1, NodeProperties::GetValueInput(result, 0)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 ASSERT_EQ(object1, NodeProperties::GetValueInput(object_state, 0)); | 387 ASSERT_EQ(object1, NodeProperties::GetValueInput(object_state, 0)); |
| 381 ASSERT_EQ(object_state, NodeProperties::GetValueInput(object_state, 1)); | 388 ASSERT_EQ(object_state, NodeProperties::GetValueInput(object_state, 1)); |
| 382 | 389 |
| 383 Node* object_state2 = NodeProperties::GetValueInput(state_values1, 0); | 390 Node* object_state2 = NodeProperties::GetValueInput(state_values1, 0); |
| 384 ASSERT_EQ(object_state, object_state2); | 391 ASSERT_EQ(object_state, object_state2); |
| 385 } | 392 } |
| 386 | 393 |
| 387 } // namespace compiler | 394 } // namespace compiler |
| 388 } // namespace internal | 395 } // namespace internal |
| 389 } // namespace v8 | 396 } // namespace v8 |
| OLD | NEW |