Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1202)

Side by Side Diff: src/wasm/ast-decoder.cc

Issue 2405293002: [wasm] Add stack checks to loops. (Closed)
Patch Set: comments addressed Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 SsaEnv* loop_body_env = PrepareForLoop(pc_, finish_try_env);
688 SetEnv("loop:start", Split(finish_try_env)); 688 SetEnv("loop:start", loop_body_env);
689 ssa_env_->SetNotMerged(); 689 ssa_env_->SetNotMerged();
690 PushLoop(finish_try_env); 690 PushLoop(finish_try_env);
691 SetBlockType(&control_.back(), operand); 691 SetBlockType(&control_.back(), operand);
692 len = 1 + operand.length; 692 len = 1 + operand.length;
693 break; 693 break;
694 } 694 }
695 case kExprIf: { 695 case kExprIf: {
696 // Condition on top of stack. Split environments for branches. 696 // Condition on top of stack. Split environments for branches.
697 BlockTypeOperand operand(this, pc_); 697 BlockTypeOperand operand(this, pc_);
698 Value cond = Pop(0, kAstI32); 698 Value cond = Pop(0, kAstI32);
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 } else if (tnode != fnode) { 1604 } else if (tnode != fnode) {
1605 uint32_t count = builder_->InputCount(merge); 1605 uint32_t count = builder_->InputCount(merge);
1606 TFNode** vals = builder_->Buffer(count); 1606 TFNode** vals = builder_->Buffer(count);
1607 for (uint32_t j = 0; j < count - 1; j++) vals[j] = tnode; 1607 for (uint32_t j = 0; j < count - 1; j++) vals[j] = tnode;
1608 vals[count - 1] = fnode; 1608 vals[count - 1] = fnode;
1609 return builder_->Phi(type, count, vals, merge); 1609 return builder_->Phi(type, count, vals, merge);
1610 } 1610 }
1611 return tnode; 1611 return tnode;
1612 } 1612 }
1613 1613
1614 void PrepareForLoop(const byte* pc, SsaEnv* env) { 1614 SsaEnv* PrepareForLoop(const byte* pc, SsaEnv* env) {
1615 if (!env->go()) return; 1615 if (!builder_) return Split(env);
1616 if (!env->go()) return Split(env);
1616 env->state = SsaEnv::kMerged; 1617 env->state = SsaEnv::kMerged;
1617 if (!builder_) return;
1618 1618
1619 env->control = builder_->Loop(env->control); 1619 env->control = builder_->Loop(env->control);
1620 env->effect = builder_->EffectPhi(1, &env->effect, env->control); 1620 env->effect = builder_->EffectPhi(1, &env->effect, env->control);
1621 builder_->Terminate(env->effect, env->control); 1621 builder_->Terminate(env->effect, env->control);
1622 if (FLAG_wasm_loop_assignment_analysis) { 1622 if (FLAG_wasm_loop_assignment_analysis) {
1623 BitVector* assigned = AnalyzeLoopAssignment(pc); 1623 BitVector* assigned = AnalyzeLoopAssignment(pc);
1624 if (assigned != nullptr) { 1624 if (assigned != nullptr) {
1625 // Only introduce phis for variables assigned in this loop. 1625 // Only introduce phis for variables assigned in this loop.
1626 for (int i = EnvironmentCount() - 1; i >= 0; i--) { 1626 for (int i = EnvironmentCount() - 1; i >= 0; i--) {
1627 if (!assigned->Contains(i)) continue; 1627 if (!assigned->Contains(i)) continue;
1628 env->locals[i] = builder_->Phi(local_type_vec_[i], 1, &env->locals[i], 1628 env->locals[i] = builder_->Phi(local_type_vec_[i], 1, &env->locals[i],
1629 env->control); 1629 env->control);
1630 } 1630 }
1631 return; 1631 SsaEnv* loop_body_env = Split(env);
1632 builder_->StackCheck(position(), &(loop_body_env->effect),
1633 &(loop_body_env->control));
1634 return loop_body_env;
1632 } 1635 }
1633 } 1636 }
1634 1637
1635 // Conservatively introduce phis for all local variables. 1638 // Conservatively introduce phis for all local variables.
1636 for (int i = EnvironmentCount() - 1; i >= 0; i--) { 1639 for (int i = EnvironmentCount() - 1; i >= 0; i--) {
1637 env->locals[i] = 1640 env->locals[i] =
1638 builder_->Phi(local_type_vec_[i], 1, &env->locals[i], env->control); 1641 builder_->Phi(local_type_vec_[i], 1, &env->locals[i], env->control);
1639 } 1642 }
1643
1644 SsaEnv* loop_body_env = Split(env);
1645 builder_->StackCheck(position(), &(loop_body_env->effect),
1646 &(loop_body_env->control));
1647 return loop_body_env;
1640 } 1648 }
1641 1649
1642 // Create a complete copy of the {from}. 1650 // Create a complete copy of the {from}.
1643 SsaEnv* Split(SsaEnv* from) { 1651 SsaEnv* Split(SsaEnv* from) {
1644 DCHECK_NOT_NULL(from); 1652 DCHECK_NOT_NULL(from);
1645 SsaEnv* result = reinterpret_cast<SsaEnv*>(zone_->New(sizeof(SsaEnv))); 1653 SsaEnv* result = reinterpret_cast<SsaEnv*>(zone_->New(sizeof(SsaEnv)));
1646 size_t size = sizeof(TFNode*) * EnvironmentCount(); 1654 size_t size = sizeof(TFNode*) * EnvironmentCount();
1647 result->control = from->control; 1655 result->control = from->control;
1648 result->effect = from->effect; 1656 result->effect = from->effect;
1649 1657
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, 1944 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
1937 const byte* start, const byte* end) { 1945 const byte* start, const byte* end) {
1938 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; 1946 FunctionBody body = {nullptr, nullptr, nullptr, start, end};
1939 WasmFullDecoder decoder(zone, nullptr, body); 1947 WasmFullDecoder decoder(zone, nullptr, body);
1940 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); 1948 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals);
1941 } 1949 }
1942 1950
1943 } // namespace wasm 1951 } // namespace wasm
1944 } // namespace internal 1952 } // namespace internal
1945 } // namespace v8 1953 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698