summaryrefslogtreecommitdiff
path: root/deps/v8/src/wasm/function-body-decoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/wasm/function-body-decoder.cc')
-rw-r--r--deps/v8/src/wasm/function-body-decoder.cc171
1 files changed, 82 insertions, 89 deletions
diff --git a/deps/v8/src/wasm/function-body-decoder.cc b/deps/v8/src/wasm/function-body-decoder.cc
index 41398eba25..beb8716d9a 100644
--- a/deps/v8/src/wasm/function-body-decoder.cc
+++ b/deps/v8/src/wasm/function-body-decoder.cc
@@ -61,9 +61,8 @@ constexpr uint32_t kNullCatch = static_cast<uint32_t>(-1);
class WasmGraphBuildingInterface {
public:
- static constexpr wasm::Decoder::ValidateFlag validate =
- wasm::Decoder::kValidate;
- using Decoder = WasmFullDecoder<validate, WasmGraphBuildingInterface>;
+ static constexpr Decoder::ValidateFlag validate = Decoder::kValidate;
+ using FullDecoder = WasmFullDecoder<validate, WasmGraphBuildingInterface>;
struct Value : public ValueWithNamedConstructors<Value> {
TFNode* node;
@@ -85,7 +84,7 @@ class WasmGraphBuildingInterface {
explicit WasmGraphBuildingInterface(TFBuilder* builder) : builder_(builder) {}
- void StartFunction(Decoder* decoder) {
+ void StartFunction(FullDecoder* decoder) {
SsaEnv* ssa_env =
reinterpret_cast<SsaEnv*>(decoder->zone()->New(sizeof(SsaEnv)));
uint32_t num_locals = decoder->NumLocals();
@@ -101,8 +100,7 @@ class WasmGraphBuildingInterface {
TFNode* start = builder_->Start(
static_cast<int>(decoder->sig_->parameter_count() + 1 + 1));
// Initialize the instance parameter (index 0).
- builder_->set_instance_node(
- builder_->Param(wasm::kWasmInstanceParameterIndex));
+ builder_->set_instance_node(builder_->Param(kWasmInstanceParameterIndex));
// Initialize local variables. Parameters are shifted by 1 because of the
// the instance parameter.
uint32_t index = 0;
@@ -132,25 +130,25 @@ class WasmGraphBuildingInterface {
builder_->InitInstanceCache(&ssa_env->instance_cache);
}
- void StartFunctionBody(Decoder* decoder, Control* block) {
+ void StartFunctionBody(FullDecoder* decoder, Control* block) {
SsaEnv* break_env = ssa_env_;
SetEnv(Steal(decoder->zone(), break_env));
block->end_env = break_env;
}
- void FinishFunction(Decoder*) { builder_->PatchInStackCheckIfNeeded(); }
+ void FinishFunction(FullDecoder*) { builder_->PatchInStackCheckIfNeeded(); }
- void OnFirstError(Decoder*) {}
+ void OnFirstError(FullDecoder*) {}
- void NextInstruction(Decoder*, WasmOpcode) {}
+ void NextInstruction(FullDecoder*, WasmOpcode) {}
- void Block(Decoder* decoder, Control* block) {
+ void Block(FullDecoder* decoder, Control* block) {
// The break environment is the outer environment.
block->end_env = ssa_env_;
SetEnv(Steal(decoder->zone(), ssa_env_));
}
- void Loop(Decoder* decoder, Control* block) {
+ void Loop(FullDecoder* decoder, Control* block) {
SsaEnv* finish_try_env = Steal(decoder->zone(), ssa_env_);
block->end_env = finish_try_env;
// The continue environment is the inner environment.
@@ -164,7 +162,7 @@ class WasmGraphBuildingInterface {
}
}
- void Try(Decoder* decoder, Control* block) {
+ void Try(FullDecoder* decoder, Control* block) {
SsaEnv* outer_env = ssa_env_;
SsaEnv* catch_env = Split(decoder, outer_env);
// Mark catch environment as unreachable, since only accessable
@@ -179,7 +177,7 @@ class WasmGraphBuildingInterface {
current_catch_ = static_cast<int32_t>(decoder->control_depth() - 1);
}
- void If(Decoder* decoder, const Value& cond, Control* if_block) {
+ void If(FullDecoder* decoder, const Value& cond, Control* if_block) {
TFNode* if_true = nullptr;
TFNode* if_false = nullptr;
if (ssa_env_->go()) BUILD(BranchNoHint, cond.node, &if_true, &if_false);
@@ -193,51 +191,51 @@ class WasmGraphBuildingInterface {
SetEnv(true_env);
}
- void FallThruTo(Decoder* decoder, Control* c) {
+ void FallThruTo(FullDecoder* decoder, Control* c) {
DCHECK(!c->is_loop());
MergeValuesInto(decoder, c, &c->end_merge);
}
- void PopControl(Decoder* decoder, Control* block) {
+ void PopControl(FullDecoder* decoder, Control* block) {
if (!block->is_loop()) SetEnv(block->end_env);
}
- void EndControl(Decoder* decoder, Control* block) { ssa_env_->Kill(); }
+ void EndControl(FullDecoder* decoder, Control* block) { ssa_env_->Kill(); }
- void UnOp(Decoder* decoder, WasmOpcode opcode, FunctionSig* sig,
+ void UnOp(FullDecoder* decoder, WasmOpcode opcode, FunctionSig* sig,
const Value& value, Value* result) {
result->node = BUILD(Unop, opcode, value.node, decoder->position());
}
- void BinOp(Decoder* decoder, WasmOpcode opcode, FunctionSig* sig,
+ void BinOp(FullDecoder* decoder, WasmOpcode opcode, FunctionSig* sig,
const Value& lhs, const Value& rhs, Value* result) {
auto node = BUILD(Binop, opcode, lhs.node, rhs.node, decoder->position());
if (result) result->node = node;
}
- void I32Const(Decoder* decoder, Value* result, int32_t value) {
+ void I32Const(FullDecoder* decoder, Value* result, int32_t value) {
result->node = builder_->Int32Constant(value);
}
- void I64Const(Decoder* decoder, Value* result, int64_t value) {
+ void I64Const(FullDecoder* decoder, Value* result, int64_t value) {
result->node = builder_->Int64Constant(value);
}
- void F32Const(Decoder* decoder, Value* result, float value) {
+ void F32Const(FullDecoder* decoder, Value* result, float value) {
result->node = builder_->Float32Constant(value);
}
- void F64Const(Decoder* decoder, Value* result, double value) {
+ void F64Const(FullDecoder* decoder, Value* result, double value) {
result->node = builder_->Float64Constant(value);
}
- void RefNull(Decoder* decoder, Value* result) {
+ void RefNull(FullDecoder* decoder, Value* result) {
result->node = builder_->RefNull();
}
- void Drop(Decoder* decoder, const Value& value) {}
+ void Drop(FullDecoder* decoder, const Value& value) {}
- void DoReturn(Decoder* decoder, Vector<Value> values, bool implicit) {
+ void DoReturn(FullDecoder* decoder, Vector<Value> values, bool implicit) {
if (implicit) {
DCHECK_EQ(1, decoder->control_depth());
SetEnv(decoder->control_at(0)->end_env);
@@ -250,40 +248,40 @@ class WasmGraphBuildingInterface {
BUILD(Return, static_cast<unsigned>(values.size()), buffer);
}
- void GetLocal(Decoder* decoder, Value* result,
+ void GetLocal(FullDecoder* decoder, Value* result,
const LocalIndexImmediate<validate>& imm) {
if (!ssa_env_->locals) return; // unreachable
result->node = ssa_env_->locals[imm.index];
}
- void SetLocal(Decoder* decoder, const Value& value,
+ void SetLocal(FullDecoder* decoder, const Value& value,
const LocalIndexImmediate<validate>& imm) {
if (!ssa_env_->locals) return; // unreachable
ssa_env_->locals[imm.index] = value.node;
}
- void TeeLocal(Decoder* decoder, const Value& value, Value* result,
+ void TeeLocal(FullDecoder* decoder, const Value& value, Value* result,
const LocalIndexImmediate<validate>& imm) {
result->node = value.node;
if (!ssa_env_->locals) return; // unreachable
ssa_env_->locals[imm.index] = value.node;
}
- void GetGlobal(Decoder* decoder, Value* result,
+ void GetGlobal(FullDecoder* decoder, Value* result,
const GlobalIndexImmediate<validate>& imm) {
result->node = BUILD(GetGlobal, imm.index);
}
- void SetGlobal(Decoder* decoder, const Value& value,
+ void SetGlobal(FullDecoder* decoder, const Value& value,
const GlobalIndexImmediate<validate>& imm) {
BUILD(SetGlobal, imm.index, value.node);
}
- void Unreachable(Decoder* decoder) {
+ void Unreachable(FullDecoder* decoder) {
BUILD(Unreachable, decoder->position());
}
- void Select(Decoder* decoder, const Value& cond, const Value& fval,
+ void Select(FullDecoder* decoder, const Value& cond, const Value& fval,
const Value& tval, Value* result) {
TFNode* controls[2];
BUILD(BranchNoHint, cond.node, &controls[0], &controls[1]);
@@ -294,11 +292,11 @@ class WasmGraphBuildingInterface {
ssa_env_->control = merge;
}
- void Br(Decoder* decoder, Control* target) {
+ void Br(FullDecoder* decoder, Control* target) {
MergeValuesInto(decoder, target, target->br_merge());
}
- void BrIf(Decoder* decoder, const Value& cond, Control* target) {
+ void BrIf(FullDecoder* decoder, const Value& cond, Control* target) {
SsaEnv* fenv = ssa_env_;
SsaEnv* tenv = Split(decoder, fenv);
fenv->SetNotMerged();
@@ -308,7 +306,7 @@ class WasmGraphBuildingInterface {
ssa_env_ = fenv;
}
- void BrTable(Decoder* decoder, const BranchTableImmediate<validate>& imm,
+ void BrTable(FullDecoder* decoder, const BranchTableImmediate<validate>& imm,
const Value& key) {
if (imm.table_count == 0) {
// Only a default target. Do the equivalent of br.
@@ -336,11 +334,11 @@ class WasmGraphBuildingInterface {
ssa_env_ = break_env;
}
- void Else(Decoder* decoder, Control* if_block) {
+ void Else(FullDecoder* decoder, Control* if_block) {
SetEnv(if_block->false_env);
}
- void LoadMem(Decoder* decoder, LoadType type,
+ void LoadMem(FullDecoder* decoder, LoadType type,
const MemoryAccessImmediate<validate>& imm, const Value& index,
Value* result) {
result->node =
@@ -348,56 +346,57 @@ class WasmGraphBuildingInterface {
imm.offset, imm.alignment, decoder->position());
}
- void StoreMem(Decoder* decoder, StoreType type,
+ void StoreMem(FullDecoder* decoder, StoreType type,
const MemoryAccessImmediate<validate>& imm, const Value& index,
const Value& value) {
BUILD(StoreMem, type.mem_rep(), index.node, imm.offset, imm.alignment,
value.node, decoder->position(), type.value_type());
}
- void CurrentMemoryPages(Decoder* decoder, Value* result) {
+ void CurrentMemoryPages(FullDecoder* decoder, Value* result) {
result->node = BUILD(CurrentMemoryPages);
}
- void GrowMemory(Decoder* decoder, const Value& value, Value* result) {
+ void GrowMemory(FullDecoder* decoder, const Value& value, Value* result) {
result->node = BUILD(GrowMemory, value.node);
// Always reload the instance cache after growing memory.
LoadContextIntoSsa(ssa_env_);
}
- void CallDirect(Decoder* decoder, const CallFunctionImmediate<validate>& imm,
+ void CallDirect(FullDecoder* decoder,
+ const CallFunctionImmediate<validate>& imm,
const Value args[], Value returns[]) {
DoCall(decoder, nullptr, imm.sig, imm.index, args, returns);
}
- void CallIndirect(Decoder* decoder, const Value& index,
+ void CallIndirect(FullDecoder* decoder, const Value& index,
const CallIndirectImmediate<validate>& imm,
const Value args[], Value returns[]) {
DoCall(decoder, index.node, imm.sig, imm.sig_index, args, returns);
}
- void SimdOp(Decoder* decoder, WasmOpcode opcode, Vector<Value> args,
+ void SimdOp(FullDecoder* decoder, WasmOpcode opcode, Vector<Value> args,
Value* result) {
TFNode** inputs = GetNodes(args);
TFNode* node = BUILD(SimdOp, opcode, inputs);
if (result) result->node = node;
}
- void SimdLaneOp(Decoder* decoder, WasmOpcode opcode,
+ void SimdLaneOp(FullDecoder* decoder, WasmOpcode opcode,
const SimdLaneImmediate<validate> imm, Vector<Value> inputs,
Value* result) {
TFNode** nodes = GetNodes(inputs);
result->node = BUILD(SimdLaneOp, opcode, imm.lane, nodes);
}
- void SimdShiftOp(Decoder* decoder, WasmOpcode opcode,
+ void SimdShiftOp(FullDecoder* decoder, WasmOpcode opcode,
const SimdShiftImmediate<validate> imm, const Value& input,
Value* result) {
TFNode* inputs[] = {input.node};
result->node = BUILD(SimdShiftOp, opcode, imm.shift, inputs);
}
- void Simd8x16ShuffleOp(Decoder* decoder,
+ void Simd8x16ShuffleOp(FullDecoder* decoder,
const Simd8x16ShuffleImmediate<validate>& imm,
const Value& input0, const Value& input1,
Value* result) {
@@ -405,14 +404,14 @@ class WasmGraphBuildingInterface {
result->node = BUILD(Simd8x16ShuffleOp, imm.shuffle, input_nodes);
}
- TFNode* GetExceptionTag(Decoder* decoder,
+ TFNode* GetExceptionTag(FullDecoder* decoder,
const ExceptionIndexImmediate<validate>& imm) {
// TODO(kschimpf): Need to get runtime exception tag values. This
// code only handles non-imported/exported exceptions.
return BUILD(Int32Constant, imm.index);
}
- void Throw(Decoder* decoder, const ExceptionIndexImmediate<validate>& imm,
+ void Throw(FullDecoder* decoder, const ExceptionIndexImmediate<validate>& imm,
Control* block, const Vector<Value>& value_args) {
int count = value_args.length();
ZoneVector<TFNode*> args(count, decoder->zone());
@@ -424,7 +423,7 @@ class WasmGraphBuildingInterface {
EndControl(decoder, block);
}
- void CatchException(Decoder* decoder,
+ void CatchException(FullDecoder* decoder,
const ExceptionIndexImmediate<validate>& imm,
Control* block, Vector<Value> values) {
DCHECK(block->is_try_catch());
@@ -483,7 +482,7 @@ class WasmGraphBuildingInterface {
}
}
- void AtomicOp(Decoder* decoder, WasmOpcode opcode, Vector<Value> args,
+ void AtomicOp(FullDecoder* decoder, WasmOpcode opcode, Vector<Value> args,
const MemoryAccessImmediate<validate>& imm, Value* result) {
TFNode** inputs = GetNodes(args);
TFNode* node = BUILD(AtomicOp, opcode, inputs, imm.alignment, imm.offset,
@@ -496,7 +495,7 @@ class WasmGraphBuildingInterface {
TFBuilder* builder_;
uint32_t current_catch_ = kNullCatch;
- TryInfo* current_try_info(Decoder* decoder) {
+ TryInfo* current_try_info(FullDecoder* decoder) {
return decoder->control_at(decoder->control_depth() - 1 - current_catch_)
->try_info;
}
@@ -548,7 +547,7 @@ class WasmGraphBuildingInterface {
builder_->set_instance_cache(&env->instance_cache);
}
- TFNode* CheckForException(Decoder* decoder, TFNode* node) {
+ TFNode* CheckForException(FullDecoder* decoder, TFNode* node) {
if (node == nullptr) return nullptr;
const bool inside_try_scope = current_catch_ != kNullCatch;
@@ -600,7 +599,7 @@ class WasmGraphBuildingInterface {
}
}
- void MergeValuesInto(Decoder* decoder, Control* c, Merge<Value>* merge) {
+ void MergeValuesInto(FullDecoder* decoder, Control* c, Merge<Value>* merge) {
DCHECK(merge == &c->start_merge || merge == &c->end_merge);
if (!ssa_env_->go()) return;
@@ -623,7 +622,7 @@ class WasmGraphBuildingInterface {
}
}
- void Goto(Decoder* decoder, SsaEnv* from, SsaEnv* to) {
+ void Goto(FullDecoder* decoder, SsaEnv* from, SsaEnv* to) {
DCHECK_NOT_NULL(to);
if (!from->go()) return;
switch (to->state) {
@@ -685,7 +684,7 @@ class WasmGraphBuildingInterface {
return from->Kill();
}
- SsaEnv* PrepareForLoop(Decoder* decoder, SsaEnv* env) {
+ SsaEnv* PrepareForLoop(FullDecoder* decoder, SsaEnv* env) {
if (!env->go()) return Split(decoder, env);
env->state = SsaEnv::kMerged;
@@ -732,7 +731,7 @@ class WasmGraphBuildingInterface {
}
// Create a complete copy of {from}.
- SsaEnv* Split(Decoder* decoder, SsaEnv* from) {
+ SsaEnv* Split(FullDecoder* decoder, SsaEnv* from) {
DCHECK_NOT_NULL(from);
SsaEnv* result =
reinterpret_cast<SsaEnv*>(decoder->zone()->New(sizeof(SsaEnv)));
@@ -782,9 +781,8 @@ class WasmGraphBuildingInterface {
return result;
}
- void DoCall(WasmFullDecoder<validate, WasmGraphBuildingInterface>* decoder,
- TFNode* index_node, FunctionSig* sig, uint32_t index,
- const Value args[], Value returns[]) {
+ void DoCall(FullDecoder* decoder, TFNode* index_node, FunctionSig* sig,
+ uint32_t index, const Value args[], Value returns[]) {
int param_count = static_cast<int>(sig->parameter_count());
TFNode** arg_nodes = builder_->Buffer(param_count + 1);
TFNode** return_nodes = nullptr;
@@ -811,10 +809,10 @@ class WasmGraphBuildingInterface {
} // namespace
-bool DecodeLocalDecls(BodyLocalDecls* decls, const byte* start,
- const byte* end) {
+bool DecodeLocalDecls(const WasmFeatures& enabled, BodyLocalDecls* decls,
+ const byte* start, const byte* end) {
Decoder decoder(start, end);
- if (WasmDecoder<Decoder::kValidate>::DecodeLocals(&decoder, nullptr,
+ if (WasmDecoder<Decoder::kValidate>::DecodeLocals(enabled, &decoder, nullptr,
&decls->type_list)) {
DCHECK(decoder.ok());
decls->encoded_size = decoder.pc_offset();
@@ -827,7 +825,7 @@ BytecodeIterator::BytecodeIterator(const byte* start, const byte* end,
BodyLocalDecls* decls)
: Decoder(start, end) {
if (decls != nullptr) {
- if (DecodeLocalDecls(decls, start, end)) {
+ if (DecodeLocalDecls(kAllWasmFeatures, decls, start, end)) {
pc_ += decls->encoded_size;
if (pc_ > end_) pc_ = end_;
}
@@ -835,33 +833,24 @@ BytecodeIterator::BytecodeIterator(const byte* start, const byte* end,
}
DecodeResult VerifyWasmCode(AccountingAllocator* allocator,
- const wasm::WasmModule* module,
+ const WasmFeatures& enabled,
+ const WasmModule* module, WasmFeatures* detected,
FunctionBody& body) {
Zone zone(allocator, ZONE_NAME);
- WasmFullDecoder<Decoder::kValidate, EmptyInterface> decoder(&zone, module,
- body);
+ WasmFullDecoder<Decoder::kValidate, EmptyInterface> decoder(
+ &zone, module, enabled, detected, body);
decoder.Decode();
return decoder.toResult(nullptr);
}
-DecodeResult VerifyWasmCodeWithStats(AccountingAllocator* allocator,
- const wasm::WasmModule* module,
- FunctionBody& body, ModuleOrigin origin,
- Counters* counters) {
- CHECK_LE(0, body.end - body.start);
- auto time_counter = origin == kWasmOrigin
- ? counters->wasm_decode_wasm_function_time()
- : counters->wasm_decode_asm_function_time();
- TimedHistogramScope wasm_decode_function_time_scope(time_counter);
- return VerifyWasmCode(allocator, module, body);
-}
-
-DecodeResult BuildTFGraph(AccountingAllocator* allocator, TFBuilder* builder,
- FunctionBody& body,
+DecodeResult BuildTFGraph(AccountingAllocator* allocator,
+ const WasmFeatures& enabled,
+ const wasm::WasmModule* module, TFBuilder* builder,
+ WasmFeatures* detected, FunctionBody& body,
compiler::NodeOriginTable* node_origins) {
Zone zone(allocator, ZONE_NAME);
WasmFullDecoder<Decoder::kValidate, WasmGraphBuildingInterface> decoder(
- &zone, builder->module(), body, builder);
+ &zone, module, enabled, detected, body, builder);
if (node_origins) {
builder->AddBytecodePositionDecorator(node_origins, &decoder);
}
@@ -880,7 +869,9 @@ unsigned OpcodeLength(const byte* pc, const byte* end) {
std::pair<uint32_t, uint32_t> StackEffect(const WasmModule* module,
FunctionSig* sig, const byte* pc,
const byte* end) {
- WasmDecoder<Decoder::kNoValidate> decoder(module, sig, pc, end);
+ WasmFeatures unused_detected_features;
+ WasmDecoder<Decoder::kNoValidate> decoder(
+ module, kAllWasmFeatures, &unused_detected_features, sig, pc, end);
return decoder.StackEffect(pc);
}
@@ -906,18 +897,19 @@ const char* RawOpcodeName(WasmOpcode opcode) {
} // namespace
bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
- const wasm::WasmModule* module,
- PrintLocals print_locals) {
+ const WasmModule* module, PrintLocals print_locals) {
StdoutStream os;
return PrintRawWasmCode(allocator, body, module, print_locals, os);
}
bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
- const wasm::WasmModule* module, PrintLocals print_locals,
+ const WasmModule* module, PrintLocals print_locals,
std::ostream& os, std::vector<int>* line_numbers) {
Zone zone(allocator, ZONE_NAME);
- WasmDecoder<Decoder::kNoValidate> decoder(module, body.sig, body.start,
- body.end);
+ WasmFeatures unused_detected_features;
+ WasmDecoder<Decoder::kNoValidate> decoder(module, kAllWasmFeatures,
+ &unused_detected_features, body.sig,
+ body.start, body.end);
int line_nr = 0;
constexpr int kNoByteCode = -1;
@@ -1015,7 +1007,8 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
case kExprIf:
case kExprBlock:
case kExprTry: {
- BlockTypeImmediate<Decoder::kNoValidate> imm(&i, i.pc());
+ BlockTypeImmediate<Decoder::kNoValidate> imm(kAllWasmFeatures, &i,
+ i.pc());
os << " // @" << i.pc_offset();
if (decoder.Complete(imm)) {
for (unsigned i = 0; i < imm.out_arity(); i++) {