Merge V8 5.3.332.45. DO NOT MERGE
Test: Manual
FPIIM-449
Change-Id: Id3254828b068abdea3cb10442e0172a8c9a98e03
(cherry picked from commit 13e2dadd00298019ed862f2b2fc5068bba730bcf)
diff --git a/src/wasm/ast-decoder.cc b/src/wasm/ast-decoder.cc
index b8a86c3..ef83c67 100644
--- a/src/wasm/ast-decoder.cc
+++ b/src/wasm/ast-decoder.cc
@@ -157,10 +157,17 @@
return false;
}
- inline bool Validate(const byte* pc, CallFunctionOperand& operand) {
+ inline bool Complete(const byte* pc, CallFunctionOperand& operand) {
ModuleEnv* m = module_;
if (m && m->module && operand.index < m->module->functions.size()) {
operand.sig = m->module->functions[operand.index].sig;
+ return true;
+ }
+ return false;
+ }
+
+ inline bool Validate(const byte* pc, CallFunctionOperand& operand) {
+ if (Complete(pc, operand)) {
uint32_t expected = static_cast<uint32_t>(operand.sig->parameter_count());
if (operand.arity != expected) {
error(pc, pc + 1,
@@ -174,10 +181,17 @@
return false;
}
- inline bool Validate(const byte* pc, CallIndirectOperand& operand) {
+ inline bool Complete(const byte* pc, CallIndirectOperand& operand) {
ModuleEnv* m = module_;
if (m && m->module && operand.index < m->module->signatures.size()) {
operand.sig = m->module->signatures[operand.index];
+ return true;
+ }
+ return false;
+ }
+
+ inline bool Validate(const byte* pc, CallIndirectOperand& operand) {
+ if (Complete(pc, operand)) {
uint32_t expected = static_cast<uint32_t>(operand.sig->parameter_count());
if (operand.arity != expected) {
error(pc, pc + 1,
@@ -191,10 +205,17 @@
return false;
}
- inline bool Validate(const byte* pc, CallImportOperand& operand) {
+ inline bool Complete(const byte* pc, CallImportOperand& operand) {
ModuleEnv* m = module_;
if (m && m->module && operand.index < m->module->import_table.size()) {
operand.sig = m->module->import_table[operand.index].sig;
+ return true;
+ }
+ return false;
+ }
+
+ inline bool Validate(const byte* pc, CallImportOperand& operand) {
+ if (Complete(pc, operand)) {
uint32_t expected = static_cast<uint32_t>(operand.sig->parameter_count());
if (operand.arity != expected) {
error(pc, pc + 1, "arity mismatch in import call (expected %u, got %u)",
@@ -228,7 +249,7 @@
return false;
}
// Verify table.
- for (uint32_t i = 0; i < operand.table_count + 1; i++) {
+ for (uint32_t i = 0; i < operand.table_count + 1; ++i) {
uint32_t target = operand.read_entry(this, i);
if (target >= block_depth) {
error(operand.table + i * 2, "improper branch in br_table");
@@ -238,7 +259,7 @@
return true;
}
- int OpcodeArity(const byte* pc) {
+ unsigned OpcodeArity(const byte* pc) {
#define DECLARE_ARITY(name, ...) \
static const LocalType kTypes_##name[] = {__VA_ARGS__}; \
static const int kArity_##name = \
@@ -311,6 +332,7 @@
FOREACH_MISC_MEM_OPCODE(DECLARE_OPCODE_CASE)
FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE)
FOREACH_ASMJS_COMPAT_OPCODE(DECLARE_OPCODE_CASE)
+ FOREACH_SIMD_OPCODE(DECLARE_OPCODE_CASE)
#undef DECLARE_OPCODE_CASE
default:
UNREACHABLE();
@@ -318,7 +340,7 @@
}
}
- int OpcodeLength(const byte* pc) {
+ unsigned OpcodeLength(const byte* pc) {
switch (static_cast<WasmOpcode>(*pc)) {
#define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name:
FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE)
@@ -390,7 +412,7 @@
// shift-reduce strategy with multiple internal stacks.
class SR_WasmDecoder : public WasmDecoder {
public:
- SR_WasmDecoder(Zone* zone, TFBuilder* builder, FunctionBody& body)
+ SR_WasmDecoder(Zone* zone, TFBuilder* builder, const FunctionBody& body)
: WasmDecoder(body.module, body.sig, body.start, body.end),
zone_(zone),
builder_(builder),
@@ -543,7 +565,7 @@
char* indentation() {
static const int kMaxIndent = 64;
static char bytes[kMaxIndent + 1];
- for (int i = 0; i < kMaxIndent; i++) bytes[i] = ' ';
+ for (int i = 0; i < kMaxIndent; ++i) bytes[i] = ' ';
bytes[kMaxIndent] = 0;
if (stack_.size() < kMaxIndent / 2) {
bytes[stack_.size() * 2] = 0;
@@ -557,15 +579,14 @@
// Initialize {local_type_vec} from signature.
if (sig_) {
local_type_vec_.reserve(sig_->parameter_count());
- for (size_t i = 0; i < sig_->parameter_count(); i++) {
+ for (size_t i = 0; i < sig_->parameter_count(); ++i) {
local_type_vec_.push_back(sig_->GetParam(i));
}
}
// Decode local declarations, if any.
- int length;
- uint32_t entries = consume_u32v(&length, "local decls count");
+ uint32_t entries = consume_u32v("local decls count");
while (entries-- > 0 && pc_ < limit_) {
- uint32_t count = consume_u32v(&length, "local count");
+ uint32_t count = consume_u32v("local count");
byte code = consume_u8("local type");
LocalType type;
switch (code) {
@@ -600,7 +621,7 @@
if (pc_ >= limit_) return; // Nothing to do.
while (true) { // decoding loop.
- int len = 1;
+ unsigned len = 1;
WasmOpcode opcode = static_cast<WasmOpcode>(*pc_);
TRACE(" @%-6d #%02x:%-20s|", startrel(pc_), opcode,
WasmOpcodes::ShortOpcodeName(opcode));
@@ -792,7 +813,7 @@
SsaEnv* copy = Steal(break_env);
ssa_env_ = copy;
- for (uint32_t i = 0; i < operand.table_count + 1; i++) {
+ for (uint32_t i = 0; i < operand.table_count + 1; ++i) {
uint16_t target = operand.read_entry(this, i);
ssa_env_ = Split(copy);
ssa_env_->control = (i == operand.table_count)
@@ -1023,7 +1044,7 @@
#if DEBUG
if (FLAG_trace_wasm_decoder) {
- for (size_t i = 0; i < stack_.size(); i++) {
+ for (size_t i = 0; i < stack_.size(); ++i) {
Value& val = stack_[i];
WasmOpcode opcode = static_cast<WasmOpcode>(*val.pc);
PrintF(" %c@%d:%s", WasmOpcodes::ShortNameOf(val.type),
@@ -1104,8 +1125,8 @@
int DecodeLoadMem(LocalType type, MachineType mem_type) {
MemoryAccessOperand operand(this, pc_);
Value index = Pop(0, kAstI32);
- TFNode* node =
- BUILD(LoadMem, type, mem_type, index.node, operand.offset, position());
+ TFNode* node = BUILD(LoadMem, type, mem_type, index.node, operand.offset,
+ operand.alignment, position());
Push(type, node);
return 1 + operand.length;
}
@@ -1114,7 +1135,8 @@
MemoryAccessOperand operand(this, pc_);
Value val = Pop(1, type);
Value index = Pop(0, kAstI32);
- BUILD(StoreMem, mem_type, index.node, operand.offset, val.node, position());
+ BUILD(StoreMem, mem_type, index.node, operand.offset, operand.alignment,
+ val.node, position());
Push(type, val.node);
return 1 + operand.length;
}
@@ -1433,9 +1455,9 @@
new (zone_) BitVector(static_cast<int>(local_type_vec_.size()), zone_);
int depth = 0;
// Iteratively process all AST nodes nested inside the loop.
- while (pc < limit_) {
+ while (pc < limit_ && ok()) {
WasmOpcode opcode = static_cast<WasmOpcode>(*pc);
- int length = 1;
+ unsigned length = 1;
switch (opcode) {
case kExprLoop:
case kExprIf:
@@ -1463,7 +1485,7 @@
if (depth <= 0) break;
pc += length;
}
- return assigned;
+ return ok() ? assigned : nullptr;
}
inline wasm::WasmCodePosition position() {
@@ -1505,7 +1527,7 @@
}
PrintF("%s", WasmOpcodes::OpcodeName(tree.opcode()));
if (tree.count > 0) os << "(";
- for (uint32_t i = 0; i < tree.count; i++) {
+ for (uint32_t i = 0; i < tree.count; ++i) {
if (i > 0) os << ", ";
os << *tree.children[i];
}
@@ -1513,31 +1535,33 @@
return os;
}
-int OpcodeLength(const byte* pc, const byte* end) {
+unsigned OpcodeLength(const byte* pc, const byte* end) {
WasmDecoder decoder(nullptr, nullptr, pc, end);
return decoder.OpcodeLength(pc);
}
-int OpcodeArity(const byte* pc, const byte* end) {
+unsigned OpcodeArity(const byte* pc, const byte* end) {
WasmDecoder decoder(nullptr, nullptr, pc, end);
return decoder.OpcodeArity(pc);
}
void PrintAstForDebugging(const byte* start, const byte* end) {
- FunctionBody body = {nullptr, nullptr, start, start, end};
base::AccountingAllocator allocator;
- PrintAst(&allocator, body);
+ OFStream os(stdout);
+ PrintAst(&allocator, FunctionBodyForTesting(start, end), os, nullptr);
}
-void PrintAst(base::AccountingAllocator* allocator, FunctionBody& body) {
+bool PrintAst(base::AccountingAllocator* allocator, const FunctionBody& body,
+ std::ostream& os,
+ std::vector<std::tuple<uint32_t, int, int>>* offset_table) {
Zone zone(allocator);
SR_WasmDecoder decoder(&zone, nullptr, body);
-
- OFStream os(stdout);
+ int line_nr = 0;
// Print the function signature.
if (body.sig) {
os << "// signature: " << *body.sig << std::endl;
+ ++line_nr;
}
// Print the local declarations.
@@ -1554,24 +1578,35 @@
os << std::endl;
for (const byte* locals = body.start; locals < pc; locals++) {
- printf(" 0x%02x,", *locals);
+ os << (locals == body.start ? "0x" : " 0x") << AsHex(*locals, 2) << ",";
}
os << std::endl;
+ ++line_nr;
}
- os << "// body: \n";
- int control_depth = 0;
+ os << "// body: " << std::endl;
+ ++line_nr;
+ unsigned control_depth = 0;
while (pc < body.end) {
- size_t length = decoder.OpcodeLength(pc);
+ unsigned length = decoder.OpcodeLength(pc);
WasmOpcode opcode = static_cast<WasmOpcode>(*pc);
if (opcode == kExprElse) control_depth--;
- for (int i = 0; i < control_depth && i < 32; i++) printf(" ");
- printf("k%s,", WasmOpcodes::OpcodeName(opcode));
+ int num_whitespaces = control_depth < 32 ? 2 * control_depth : 64;
+ if (offset_table) {
+ offset_table->push_back(
+ std::make_tuple(pc - body.start, line_nr, num_whitespaces));
+ }
- for (size_t i = 1; i < length; i++) {
- printf(" 0x%02x,", pc[i]);
+ // 64 whitespaces
+ const char* padding =
+ " ";
+ os.write(padding, num_whitespaces);
+ os << "k" << WasmOpcodes::OpcodeName(opcode) << ",";
+
+ for (size_t i = 1; i < length; ++i) {
+ os << " " << AsHex(pc[i], 2) << ",";
}
switch (opcode) {
@@ -1604,7 +1639,7 @@
}
case kExprCallIndirect: {
CallIndirectOperand operand(&decoder, pc);
- if (decoder.Validate(pc, operand)) {
+ if (decoder.Complete(pc, operand)) {
os << " // sig #" << operand.index << ": " << *operand.sig;
} else {
os << " // arity=" << operand.arity << " sig #" << operand.index;
@@ -1613,7 +1648,7 @@
}
case kExprCallImport: {
CallImportOperand operand(&decoder, pc);
- if (decoder.Validate(pc, operand)) {
+ if (decoder.Complete(pc, operand)) {
os << " // import #" << operand.index << ": " << *operand.sig;
} else {
os << " // arity=" << operand.arity << " import #" << operand.index;
@@ -1622,7 +1657,7 @@
}
case kExprCallFunction: {
CallFunctionOperand operand(&decoder, pc);
- if (decoder.Validate(pc, operand)) {
+ if (decoder.Complete(pc, operand)) {
os << " // function #" << operand.index << ": " << *operand.sig;
} else {
os << " // arity=" << operand.arity << " function #" << operand.index;
@@ -1640,7 +1675,10 @@
pc += length;
os << std::endl;
+ ++line_nr;
}
+
+ return decoder.ok();
}
BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,