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

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

Issue 1787733002: [wasm] Fix OpcodeLength() calculation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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
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/base/platform/elapsed-timer.h" 5 #include "src/base/platform/elapsed-timer.h"
6 #include "src/signature.h" 6 #include "src/signature.h"
7 7
8 #include "src/bit-vector.h" 8 #include "src/bit-vector.h"
9 #include "src/flags.h" 9 #include "src/flags.h"
10 #include "src/handles.h" 10 #include "src/handles.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 328
329 case kExprSetLocal: 329 case kExprSetLocal:
330 case kExprGetLocal: { 330 case kExprGetLocal: {
331 LocalIndexOperand operand(this, pc); 331 LocalIndexOperand operand(this, pc);
332 return 1 + operand.length; 332 return 1 + operand.length;
333 } 333 }
334 case kExprBrTable: { 334 case kExprBrTable: {
335 BranchTableOperand operand(this, pc); 335 BranchTableOperand operand(this, pc);
336 return 1 + operand.length; 336 return 1 + operand.length;
337 } 337 }
338 case kExprI32Const: {
binji 2016/03/11 18:10:03 oops, sorry about this. Didn't notice!
339 ImmI32Operand operand(this, pc);
340 return 1 + operand.length;
341 }
342 case kExprI64Const: {
343 ImmI64Operand operand(this, pc);
344 return 1 + operand.length;
345 }
338 case kExprI8Const: 346 case kExprI8Const:
339 return 2; 347 return 2;
340 case kExprI32Const:
341 case kExprF32Const: 348 case kExprF32Const:
342 return 5; 349 return 5;
343 case kExprI64Const:
344 case kExprF64Const: 350 case kExprF64Const:
345 return 9; 351 return 9;
346 352
347 default: 353 default:
348 return 1; 354 return 1;
349 } 355 }
350 } 356 }
351 }; 357 };
352 358
353 359
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 BlockCountOperand operand(this, pc_); 663 BlockCountOperand operand(this, pc_);
658 if (operand.count < 1) { 664 if (operand.count < 1) {
659 Leaf(kAstStmt); 665 Leaf(kAstStmt);
660 } else { 666 } else {
661 Shift(kAstEnd, operand.count); 667 Shift(kAstEnd, operand.count);
662 // The break environment is the outer environment. 668 // The break environment is the outer environment.
663 SsaEnv* break_env = ssa_env_; 669 SsaEnv* break_env = ssa_env_;
664 PushBlock(break_env); 670 PushBlock(break_env);
665 SsaEnv* cont_env = Steal(break_env); 671 SsaEnv* cont_env = Steal(break_env);
666 // The continue environment is the inner environment. 672 // The continue environment is the inner environment.
667 PrepareForLoop(cont_env); 673 PrepareForLoop(pc_, cont_env);
668 SetEnv("loop:start", Split(cont_env)); 674 SetEnv("loop:start", Split(cont_env));
669 if (ssa_env_->go()) ssa_env_->state = SsaEnv::kReached; 675 if (ssa_env_->go()) ssa_env_->state = SsaEnv::kReached;
670 PushBlock(cont_env); 676 PushBlock(cont_env);
671 blocks_.back().stack_depth = -1; // no production for inner block. 677 blocks_.back().stack_depth = -1; // no production for inner block.
672 } 678 }
673 len = 1 + operand.length; 679 len = 1 + operand.length;
674 break; 680 break;
675 } 681 }
676 case kExprIf: 682 case kExprIf:
677 Shift(kAstStmt, 2); 683 Shift(kAstStmt, 2);
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 } else if (tnode != fnode) { 1462 } else if (tnode != fnode) {
1457 uint32_t count = builder_->InputCount(merge); 1463 uint32_t count = builder_->InputCount(merge);
1458 TFNode** vals = builder_->Buffer(count); 1464 TFNode** vals = builder_->Buffer(count);
1459 for (uint32_t j = 0; j < count - 1; j++) vals[j] = tnode; 1465 for (uint32_t j = 0; j < count - 1; j++) vals[j] = tnode;
1460 vals[count - 1] = fnode; 1466 vals[count - 1] = fnode;
1461 return builder_->Phi(type, count, vals, merge); 1467 return builder_->Phi(type, count, vals, merge);
1462 } 1468 }
1463 return tnode; 1469 return tnode;
1464 } 1470 }
1465 1471
1466 void BuildInfiniteLoop() { 1472 void PrepareForLoop(const byte* pc, SsaEnv* env) {
Mircea Trofin 2016/03/11 17:15:41 Looks like the change below is aesthetic only. Wha
titzer 2016/03/11 17:17:35 Ah, an artifact of splitting this CL off. The next
1467 if (ssa_env_->go()) { 1473 if (!env->go()) return;
1468 PrepareForLoop(ssa_env_); 1474 env->state = SsaEnv::kMerged;
1469 SsaEnv* cont_env = ssa_env_; 1475 if (!builder_) return;
1470 ssa_env_ = Split(ssa_env_); 1476
1471 ssa_env_->state = SsaEnv::kReached; 1477 env->control = builder_->Loop(env->control);
1472 Goto(ssa_env_, cont_env); 1478 env->effect = builder_->EffectPhi(1, &env->effect, env->control);
1479 builder_->Terminate(env->effect, env->control);
1480 // Conservatively introduce phis for all local variables.
1481 for (int i = EnvironmentCount() - 1; i >= 0; i--) {
1482 env->locals[i] =
1483 builder_->Phi(local_type_vec_[i], 1, &env->locals[i], env->control);
1473 } 1484 }
1474 } 1485 }
1475 1486
1476 void PrepareForLoop(SsaEnv* env) {
1477 if (env->go()) {
1478 env->state = SsaEnv::kMerged;
1479 if (builder_) {
1480 env->control = builder_->Loop(env->control);
1481 env->effect = builder_->EffectPhi(1, &env->effect, env->control);
1482 builder_->Terminate(env->effect, env->control);
1483 for (int i = EnvironmentCount() - 1; i >= 0; i--) {
1484 env->locals[i] = builder_->Phi(local_type_vec_[i], 1, &env->locals[i],
1485 env->control);
1486 }
1487 }
1488 }
1489 }
1490
1491 // Create a complete copy of the {from}. 1487 // Create a complete copy of the {from}.
1492 SsaEnv* Split(SsaEnv* from) { 1488 SsaEnv* Split(SsaEnv* from) {
1493 DCHECK_NOT_NULL(from); 1489 DCHECK_NOT_NULL(from);
1494 SsaEnv* result = reinterpret_cast<SsaEnv*>(zone_->New(sizeof(SsaEnv))); 1490 SsaEnv* result = reinterpret_cast<SsaEnv*>(zone_->New(sizeof(SsaEnv)));
1495 size_t size = sizeof(TFNode*) * EnvironmentCount(); 1491 size_t size = sizeof(TFNode*) * EnvironmentCount();
1496 result->control = from->control; 1492 result->control = from->control;
1497 result->effect = from->effect; 1493 result->effect = from->effect;
1498 result->state = from->state == SsaEnv::kUnreachable ? SsaEnv::kUnreachable 1494 result->state = from->state == SsaEnv::kUnreachable ? SsaEnv::kUnreachable
1499 : SsaEnv::kReached; 1495 : SsaEnv::kReached;
1500 1496
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 // Unverified code might have an out-of-bounds index. 1592 // Unverified code might have an out-of-bounds index.
1597 assigned->Add(operand.index); 1593 assigned->Add(operand.index);
1598 } 1594 }
1599 arity = 1; 1595 arity = 1;
1600 length = 1 + operand.length; 1596 length = 1 + operand.length;
1601 } else { 1597 } else {
1602 arity = OpcodeArity(pc); 1598 arity = OpcodeArity(pc);
1603 length = OpcodeLength(pc); 1599 length = OpcodeLength(pc);
1604 } 1600 }
1605 1601
1602 TRACE("loop-assign module+%-6d %s func+%d: 0x%02x %s (len=%d)\n",
1603 baserel(pc), indentation(), startrel(pc), opcode,
1604 WasmOpcodes::OpcodeName(opcode), length);
1606 pc += length; 1605 pc += length;
1607 arity_stack.push_back(arity); 1606 arity_stack.push_back(arity);
1608 while (arity_stack.back() == 0) { 1607 while (arity_stack.back() == 0) {
1609 arity_stack.pop_back(); 1608 arity_stack.pop_back();
1610 if (arity_stack.empty()) return assigned; // reached end of loop 1609 if (arity_stack.empty()) return assigned; // reached end of loop
1611 arity_stack.back()--; 1610 arity_stack.back()--;
1612 } 1611 }
1613 } 1612 }
1614 return assigned; 1613 return assigned;
1615 } 1614 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, 1708 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
1710 const byte* start, const byte* end) { 1709 const byte* start, const byte* end) {
1711 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; 1710 FunctionBody body = {nullptr, nullptr, nullptr, start, end};
1712 SR_WasmDecoder decoder(zone, nullptr, body); 1711 SR_WasmDecoder decoder(zone, nullptr, body);
1713 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); 1712 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals);
1714 } 1713 }
1715 1714
1716 } // namespace wasm 1715 } // namespace wasm
1717 } // namespace internal 1716 } // namespace internal
1718 } // namespace v8 1717 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/ast-decoder.h ('k') | src/wasm/wasm-macro-gen.h » ('j') | src/wasm/wasm-macro-gen.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698