Chromium Code Reviews| 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/signature.h" | 5 #include "src/signature.h" |
| 6 | 6 |
| 7 #include "src/bit-vector.h" | 7 #include "src/bit-vector.h" |
| 8 #include "src/flags.h" | 8 #include "src/flags.h" |
| 9 #include "src/handles.h" | 9 #include "src/handles.h" |
| 10 #include "src/zone/zone-containers.h" | 10 #include "src/zone/zone-containers.h" |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 ssa_env_->locals[operand.index] = exception_as_i32; | 677 ssa_env_->locals[operand.index] = exception_as_i32; |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 | 680 |
| 681 break; | 681 break; |
| 682 } | 682 } |
| 683 case kExprLoop: { | 683 case kExprLoop: { |
| 684 BlockTypeOperand operand(this, pc_); | 684 BlockTypeOperand operand(this, pc_); |
| 685 SsaEnv* finish_try_env = Steal(ssa_env_); | 685 SsaEnv* finish_try_env = Steal(ssa_env_); |
| 686 // The continue environment is the inner environment. | 686 // The continue environment is the inner environment. |
| 687 PrepareForLoop(pc_, finish_try_env); | 687 SetEnv("loop:start", PrepareForLoop(pc_, finish_try_env)); |
|
titzer
2016/10/12 19:16:25
Please introduce a local variable here to make it
ahaas
2016/10/13 10:51:55
Done.
| |
| 688 SetEnv("loop:start", Split(finish_try_env)); | |
| 689 ssa_env_->SetNotMerged(); | 688 ssa_env_->SetNotMerged(); |
| 690 PushLoop(finish_try_env); | 689 PushLoop(finish_try_env); |
| 691 SetBlockType(&control_.back(), operand); | 690 SetBlockType(&control_.back(), operand); |
| 692 len = 1 + operand.length; | 691 len = 1 + operand.length; |
| 693 break; | 692 break; |
| 694 } | 693 } |
| 695 case kExprIf: { | 694 case kExprIf: { |
| 696 // Condition on top of stack. Split environments for branches. | 695 // Condition on top of stack. Split environments for branches. |
| 697 BlockTypeOperand operand(this, pc_); | 696 BlockTypeOperand operand(this, pc_); |
| 698 Value cond = Pop(0, kAstI32); | 697 Value cond = Pop(0, kAstI32); |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1604 } else if (tnode != fnode) { | 1603 } else if (tnode != fnode) { |
| 1605 uint32_t count = builder_->InputCount(merge); | 1604 uint32_t count = builder_->InputCount(merge); |
| 1606 TFNode** vals = builder_->Buffer(count); | 1605 TFNode** vals = builder_->Buffer(count); |
| 1607 for (uint32_t j = 0; j < count - 1; j++) vals[j] = tnode; | 1606 for (uint32_t j = 0; j < count - 1; j++) vals[j] = tnode; |
| 1608 vals[count - 1] = fnode; | 1607 vals[count - 1] = fnode; |
| 1609 return builder_->Phi(type, count, vals, merge); | 1608 return builder_->Phi(type, count, vals, merge); |
| 1610 } | 1609 } |
| 1611 return tnode; | 1610 return tnode; |
| 1612 } | 1611 } |
| 1613 | 1612 |
| 1614 void PrepareForLoop(const byte* pc, SsaEnv* env) { | 1613 SsaEnv* BuildLoopStackCheck(SsaEnv* env) { |
|
titzer
2016/10/12 19:16:25
You can inline this.
ahaas
2016/10/13 10:51:55
Done.
| |
| 1615 if (!env->go()) return; | 1614 builder_->StackCheck(position(), &(env->effect), &(env->control)); |
| 1615 return env; | |
| 1616 } | |
| 1617 | |
| 1618 SsaEnv* PrepareForLoop(const byte* pc, SsaEnv* env) { | |
| 1619 if (!builder_) return Split(env); | |
| 1620 if (!env->go()) return BuildLoopStackCheck(Split(env)); | |
|
titzer
2016/10/12 19:16:25
You shouldn't build the stack check if the ssa env
ahaas
2016/10/13 10:51:55
Done.
| |
| 1616 env->state = SsaEnv::kMerged; | 1621 env->state = SsaEnv::kMerged; |
| 1617 if (!builder_) return; | |
| 1618 | 1622 |
| 1619 env->control = builder_->Loop(env->control); | 1623 env->control = builder_->Loop(env->control); |
| 1620 env->effect = builder_->EffectPhi(1, &env->effect, env->control); | 1624 env->effect = builder_->EffectPhi(1, &env->effect, env->control); |
| 1621 builder_->Terminate(env->effect, env->control); | 1625 builder_->Terminate(env->effect, env->control); |
| 1622 if (FLAG_wasm_loop_assignment_analysis) { | 1626 if (FLAG_wasm_loop_assignment_analysis) { |
| 1623 BitVector* assigned = AnalyzeLoopAssignment(pc); | 1627 BitVector* assigned = AnalyzeLoopAssignment(pc); |
| 1624 if (assigned != nullptr) { | 1628 if (assigned != nullptr) { |
| 1625 // Only introduce phis for variables assigned in this loop. | 1629 // Only introduce phis for variables assigned in this loop. |
| 1626 for (int i = EnvironmentCount() - 1; i >= 0; i--) { | 1630 for (int i = EnvironmentCount() - 1; i >= 0; i--) { |
| 1627 if (!assigned->Contains(i)) continue; | 1631 if (!assigned->Contains(i)) continue; |
| 1628 env->locals[i] = builder_->Phi(local_type_vec_[i], 1, &env->locals[i], | 1632 env->locals[i] = builder_->Phi(local_type_vec_[i], 1, &env->locals[i], |
| 1629 env->control); | 1633 env->control); |
| 1630 } | 1634 } |
| 1631 return; | 1635 return BuildLoopStackCheck(Split(env)); |
| 1632 } | 1636 } |
| 1633 } | 1637 } |
| 1634 | 1638 |
| 1635 // Conservatively introduce phis for all local variables. | 1639 // Conservatively introduce phis for all local variables. |
| 1636 for (int i = EnvironmentCount() - 1; i >= 0; i--) { | 1640 for (int i = EnvironmentCount() - 1; i >= 0; i--) { |
| 1637 env->locals[i] = | 1641 env->locals[i] = |
| 1638 builder_->Phi(local_type_vec_[i], 1, &env->locals[i], env->control); | 1642 builder_->Phi(local_type_vec_[i], 1, &env->locals[i], env->control); |
| 1639 } | 1643 } |
| 1644 | |
| 1645 return BuildLoopStackCheck(Split(env)); | |
| 1640 } | 1646 } |
| 1641 | 1647 |
| 1642 // Create a complete copy of the {from}. | 1648 // Create a complete copy of the {from}. |
| 1643 SsaEnv* Split(SsaEnv* from) { | 1649 SsaEnv* Split(SsaEnv* from) { |
| 1644 DCHECK_NOT_NULL(from); | 1650 DCHECK_NOT_NULL(from); |
| 1645 SsaEnv* result = reinterpret_cast<SsaEnv*>(zone_->New(sizeof(SsaEnv))); | 1651 SsaEnv* result = reinterpret_cast<SsaEnv*>(zone_->New(sizeof(SsaEnv))); |
| 1646 size_t size = sizeof(TFNode*) * EnvironmentCount(); | 1652 size_t size = sizeof(TFNode*) * EnvironmentCount(); |
| 1647 result->control = from->control; | 1653 result->control = from->control; |
| 1648 result->effect = from->effect; | 1654 result->effect = from->effect; |
| 1649 | 1655 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1936 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 1942 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
| 1937 const byte* start, const byte* end) { | 1943 const byte* start, const byte* end) { |
| 1938 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1944 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
| 1939 WasmFullDecoder decoder(zone, nullptr, body); | 1945 WasmFullDecoder decoder(zone, nullptr, body); |
| 1940 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); | 1946 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); |
| 1941 } | 1947 } |
| 1942 | 1948 |
| 1943 } // namespace wasm | 1949 } // namespace wasm |
| 1944 } // namespace internal | 1950 } // namespace internal |
| 1945 } // namespace v8 | 1951 } // namespace v8 |
| OLD | NEW |