Commit 0a91a4c9 authored by titzer's avatar titzer Committed by Commit Bot

[wasm] Move the CallDescriptor creation methods out of ModuleEnv into the compiler.

R=clemensh@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2959963002
Cr-Commit-Position: refs/heads/master@{#46263}
parent 5dd17993
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "src/compiler/node-properties.h" #include "src/compiler/node-properties.h"
#include "src/compiler/node.h" #include "src/compiler/node.h"
#include "src/compiler/wasm-compiler.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
#include "src/zone/zone.h" #include "src/zone/zone.h"
...@@ -296,8 +297,8 @@ void Int64Lowering::LowerNode(Node* node) { ...@@ -296,8 +297,8 @@ void Int64Lowering::LowerNode(Node* node) {
(descriptor->ReturnCount() == 1 && (descriptor->ReturnCount() == 1 &&
descriptor->GetReturnType(0) == MachineType::Int64())) { descriptor->GetReturnType(0) == MachineType::Int64())) {
// We have to adjust the call descriptor. // We have to adjust the call descriptor.
const Operator* op = common()->Call( const Operator* op =
wasm::ModuleEnv::GetI32WasmCallDescriptor(zone(), descriptor)); common()->Call(GetI32WasmCallDescriptor(zone(), descriptor));
NodeProperties::ChangeOp(node, op); NodeProperties::ChangeOp(node, op);
} }
if (descriptor->ReturnCount() == 1 && if (descriptor->ReturnCount() == 1 &&
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "src/compiler/node-properties.h" #include "src/compiler/node-properties.h"
#include "src/compiler/node.h" #include "src/compiler/node.h"
#include "src/compiler/wasm-compiler.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
...@@ -786,8 +787,7 @@ void SimdScalarLowering::LowerNode(Node* node) { ...@@ -786,8 +787,7 @@ void SimdScalarLowering::LowerNode(Node* node) {
descriptor->GetReturnType(0) == MachineType::Simd128())) { descriptor->GetReturnType(0) == MachineType::Simd128())) {
// We have to adjust the call descriptor. // We have to adjust the call descriptor.
const Operator* op = const Operator* op =
common()->Call(wasm::ModuleEnv::GetI32WasmCallDescriptorForSimd( common()->Call(GetI32WasmCallDescriptorForSimd(zone(), descriptor));
zone(), descriptor));
NodeProperties::ChangeOp(node, op); NodeProperties::ChangeOp(node, op);
} }
if (descriptor->ReturnCount() == 1 && if (descriptor->ReturnCount() == 1 &&
......
...@@ -2190,8 +2190,7 @@ Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args, ...@@ -2190,8 +2190,7 @@ Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args,
args[params + 1] = *effect_; args[params + 1] = *effect_;
args[params + 2] = *control_; args[params + 2] = *control_;
CallDescriptor* descriptor = CallDescriptor* descriptor = GetWasmCallDescriptor(jsgraph()->zone(), sig);
wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig);
const Operator* op = jsgraph()->common()->Call(descriptor); const Operator* op = jsgraph()->common()->Call(descriptor);
Node* call = graph()->NewNode(op, static_cast<int>(count), args); Node* call = graph()->NewNode(op, static_cast<int>(count), args);
SetSourcePosition(call, position); SetSourcePosition(call, position);
...@@ -2655,8 +2654,8 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code, ...@@ -2655,8 +2654,8 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
// We only need a dummy call descriptor. // We only need a dummy call descriptor.
wasm::FunctionSig::Builder dummy_sig_builder(jsgraph()->zone(), 0, 0); wasm::FunctionSig::Builder dummy_sig_builder(jsgraph()->zone(), 0, 0);
CallDescriptor* desc = wasm::ModuleEnv::GetWasmCallDescriptor( CallDescriptor* desc =
jsgraph()->zone(), dummy_sig_builder.Build()); GetWasmCallDescriptor(jsgraph()->zone(), dummy_sig_builder.Build());
*effect_ = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); *effect_ = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args);
Return(jsgraph()->UndefinedConstant()); Return(jsgraph()->UndefinedConstant());
return; return;
...@@ -2676,8 +2675,7 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code, ...@@ -2676,8 +2675,7 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
args[pos++] = *control_; args[pos++] = *control_;
// Call the wasm code. // Call the wasm code.
CallDescriptor* desc = CallDescriptor* desc = GetWasmCallDescriptor(jsgraph()->zone(), sig);
wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig);
Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args); Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args);
*effect_ = call; *effect_ = call;
...@@ -3753,10 +3751,9 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, ...@@ -3753,10 +3751,9 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
} }
// Schedule and compile to machine code. // Schedule and compile to machine code.
CallDescriptor* incoming = CallDescriptor* incoming = GetWasmCallDescriptor(&zone, sig);
wasm::ModuleEnv::GetWasmCallDescriptor(&zone, sig);
if (machine.Is32()) { if (machine.Is32()) {
incoming = wasm::ModuleEnv::GetI32WasmCallDescriptor(&zone, incoming); incoming = GetI32WasmCallDescriptor(&zone, incoming);
} }
Code::Flags flags = Code::ComputeFlags(Code::WASM_TO_JS_FUNCTION); Code::Flags flags = Code::ComputeFlags(Code::WASM_TO_JS_FUNCTION);
bool debugging = bool debugging =
...@@ -3838,10 +3835,9 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index, ...@@ -3838,10 +3835,9 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index,
} }
// Schedule and compile to machine code. // Schedule and compile to machine code.
CallDescriptor* incoming = CallDescriptor* incoming = GetWasmCallDescriptor(&zone, sig);
wasm::ModuleEnv::GetWasmCallDescriptor(&zone, sig);
if (machine.Is32()) { if (machine.Is32()) {
incoming = wasm::ModuleEnv::GetI32WasmCallDescriptor(&zone, incoming); incoming = GetI32WasmCallDescriptor(&zone, incoming);
} }
Code::Flags flags = Code::ComputeFlags(Code::WASM_INTERPRETER_ENTRY); Code::Flags flags = Code::ComputeFlags(Code::WASM_INTERPRETER_ENTRY);
EmbeddedVector<char, 32> debug_name; EmbeddedVector<char, 32> debug_name;
...@@ -4015,11 +4011,11 @@ void WasmCompilationUnit::ExecuteCompilation() { ...@@ -4015,11 +4011,11 @@ void WasmCompilationUnit::ExecuteCompilation() {
compilation_zone_.reset(new Zone(isolate_->allocator(), ZONE_NAME)); compilation_zone_.reset(new Zone(isolate_->allocator(), ZONE_NAME));
// Run the compiler pipeline to generate machine code. // Run the compiler pipeline to generate machine code.
CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor( CallDescriptor* descriptor =
compilation_zone_.get(), func_body_.sig); GetWasmCallDescriptor(compilation_zone_.get(), func_body_.sig);
if (jsgraph_->machine()->Is32()) { if (jsgraph_->machine()->Is32()) {
descriptor = module_env_->GetI32WasmCallDescriptor( descriptor =
compilation_zone_.get(), descriptor); GetI32WasmCallDescriptor(compilation_zone_.get(), descriptor);
} }
info_.reset(new CompilationInfo( info_.reset(new CompilationInfo(
GetDebugName(compilation_zone_.get(), func_name_, func_index_), GetDebugName(compilation_zone_.get(), func_name_, func_index_),
......
...@@ -411,6 +411,13 @@ class WasmGraphBuilder { ...@@ -411,6 +411,13 @@ class WasmGraphBuilder {
void SetNeedsStackCheck() { needs_stack_check_ = true; } void SetNeedsStackCheck() { needs_stack_check_ = true; }
}; };
V8_EXPORT_PRIVATE CallDescriptor* GetWasmCallDescriptor(Zone* zone,
wasm::FunctionSig* sig);
V8_EXPORT_PRIVATE CallDescriptor* GetI32WasmCallDescriptor(
Zone* zone, CallDescriptor* descriptor);
V8_EXPORT_PRIVATE CallDescriptor* GetI32WasmCallDescriptorForSimd(
Zone* zone, CallDescriptor* descriptor);
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -8,34 +8,30 @@ ...@@ -8,34 +8,30 @@
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/register-configuration.h" #include "src/register-configuration.h"
#include "src/wasm/wasm-module.h"
#include "src/compiler/linkage.h" #include "src/compiler/linkage.h"
#include "src/compiler/wasm-compiler.h"
#include "src/zone/zone.h" #include "src/zone/zone.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// TODO(titzer): this should not be in the wasm namespace. namespace compiler {
namespace wasm {
using compiler::LocationSignature; using wasm::ValueType;
using compiler::CallDescriptor;
using compiler::LinkageLocation;
namespace { namespace {
MachineType MachineTypeFor(ValueType type) { MachineType MachineTypeFor(ValueType type) {
switch (type) { switch (type) {
case kWasmI32: case wasm::kWasmI32:
return MachineType::Int32(); return MachineType::Int32();
case kWasmI64: case wasm::kWasmI64:
return MachineType::Int64(); return MachineType::Int64();
case kWasmF64: case wasm::kWasmF64:
return MachineType::Float64(); return MachineType::Float64();
case kWasmF32: case wasm::kWasmF32:
return MachineType::Float32(); return MachineType::Float32();
case kWasmS128: case wasm::kWasmS128:
return MachineType::Simd128(); return MachineType::Simd128();
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -182,7 +178,7 @@ struct Allocator { ...@@ -182,7 +178,7 @@ struct Allocator {
// Allocate floats using a double register, but modify the code to // Allocate floats using a double register, but modify the code to
// reflect how ARM FP registers alias. // reflect how ARM FP registers alias.
// TODO(bbudge) Modify wasm linkage to allow use of all float regs. // TODO(bbudge) Modify wasm linkage to allow use of all float regs.
if (type == kWasmF32) { if (type == wasm::kWasmF32) {
int float_reg_code = reg.code() * 2; int float_reg_code = reg.code() * 2;
DCHECK(float_reg_code < RegisterConfiguration::kMaxFPRegisters); DCHECK(float_reg_code < RegisterConfiguration::kMaxFPRegisters);
return regloc(DoubleRegister::from_code(float_reg_code), return regloc(DoubleRegister::from_code(float_reg_code),
...@@ -207,10 +203,11 @@ struct Allocator { ...@@ -207,10 +203,11 @@ struct Allocator {
} }
} }
bool IsFloatingPoint(ValueType type) { bool IsFloatingPoint(ValueType type) {
return type == kWasmF32 || type == kWasmF64; return type == wasm::kWasmF32 || type == wasm::kWasmF64;
} }
int Words(ValueType type) { int Words(ValueType type) {
if (kPointerSize < 8 && (type == kWasmI64 || type == kWasmF64)) { if (kPointerSize < 8 &&
(type == wasm::kWasmI64 || type == wasm::kWasmF64)) {
return 2; return 2;
} }
return 1; return 1;
...@@ -275,8 +272,7 @@ static base::LazyInstance<Allocator, ReturnRegistersCreateTrait>::type ...@@ -275,8 +272,7 @@ static base::LazyInstance<Allocator, ReturnRegistersCreateTrait>::type
return_registers = LAZY_INSTANCE_INITIALIZER; return_registers = LAZY_INSTANCE_INITIALIZER;
// General code uses the above configuration data. // General code uses the above configuration data.
CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone, CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig) {
FunctionSig* fsig) {
LocationSignature::Builder locations(zone, fsig->return_count(), LocationSignature::Builder locations(zone, fsig->return_count(),
fsig->parameter_count()); fsig->parameter_count());
...@@ -379,20 +375,20 @@ CallDescriptor* ReplaceTypeInCallDescriptorWith( ...@@ -379,20 +375,20 @@ CallDescriptor* ReplaceTypeInCallDescriptorWith(
descriptor->debug_name()); descriptor->debug_name());
} }
CallDescriptor* ModuleEnv::GetI32WasmCallDescriptor( CallDescriptor* GetI32WasmCallDescriptor(Zone* zone,
Zone* zone, CallDescriptor* descriptor) { CallDescriptor* descriptor) {
return ReplaceTypeInCallDescriptorWith(zone, descriptor, 2, return ReplaceTypeInCallDescriptorWith(zone, descriptor, 2,
MachineType::Int64(), MachineType::Int64(),
MachineRepresentation::kWord32); MachineRepresentation::kWord32);
} }
CallDescriptor* ModuleEnv::GetI32WasmCallDescriptorForSimd( CallDescriptor* GetI32WasmCallDescriptorForSimd(Zone* zone,
Zone* zone, CallDescriptor* descriptor) { CallDescriptor* descriptor) {
return ReplaceTypeInCallDescriptorWith(zone, descriptor, 4, return ReplaceTypeInCallDescriptorWith(zone, descriptor, 4,
MachineType::Simd128(), MachineType::Simd128(),
MachineRepresentation::kWord32); MachineRepresentation::kWord32);
} }
} // namespace wasm } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -268,9 +268,6 @@ class InstanceBuilder { ...@@ -268,9 +268,6 @@ class InstanceBuilder {
// of the work of compilation) can be background tasks. // of the work of compilation) can be background tasks.
// TODO(wasm): factor out common parts of this with the synchronous pipeline. // TODO(wasm): factor out common parts of this with the synchronous pipeline.
class AsyncCompileJob { class AsyncCompileJob {
// TODO(ahaas): Fix https://bugs.chromium.org/p/v8/issues/detail?id=6263 to
// make sure that d8 does not shut down before the AsyncCompileJob is
// finished.
public: public:
explicit AsyncCompileJob(Isolate* isolate, std::unique_ptr<byte[]> bytes_copy, explicit AsyncCompileJob(Isolate* isolate, std::unique_ptr<byte[]> bytes_copy,
size_t length, Handle<Context> context, size_t length, Handle<Context> context,
......
...@@ -162,15 +162,12 @@ struct V8_EXPORT_PRIVATE WasmModule { ...@@ -162,15 +162,12 @@ struct V8_EXPORT_PRIVATE WasmModule {
static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb
std::unique_ptr<Zone> signature_zone; std::unique_ptr<Zone> signature_zone;
uint32_t min_mem_pages = 0; // minimum size of the memory in 64k pages uint32_t min_mem_pages = 0; // minimum size of the memory in 64k pages
uint32_t max_mem_pages = 0; // maximum size of the memory in 64k pages uint32_t max_mem_pages = 0; // maximum size of the memory in 64k pages
bool has_max_mem = false; // try if a maximum memory size exists bool has_max_mem = false; // try if a maximum memory size exists
bool has_memory = false; // true if the memory was defined or imported bool has_memory = false; // true if the memory was defined or imported
bool mem_export = false; // true if the memory is exported bool mem_export = false; // true if the memory is exported
// TODO(wasm): reconcile start function index being an int with int start_function_index = -1; // start function, >= 0 if any
// the fact that we index on uint32_t, so we may technically not be
// able to represent some start_function_index -es.
int start_function_index = -1; // start function, if any
std::vector<WasmGlobal> globals; // globals in this module. std::vector<WasmGlobal> globals; // globals in this module.
uint32_t globals_size = 0; // size of globals table. uint32_t globals_size = 0; // size of globals table.
...@@ -365,14 +362,6 @@ struct V8_EXPORT_PRIVATE ModuleEnv { ...@@ -365,14 +362,6 @@ struct V8_EXPORT_PRIVATE ModuleEnv {
DCHECK_NOT_NULL(instance); DCHECK_NOT_NULL(instance);
return instance->function_code[index]; return instance->function_code[index];
} }
// TODO(titzer): move these into src/compiler/wasm-compiler.cc
static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone,
FunctionSig* sig);
static compiler::CallDescriptor* GetI32WasmCallDescriptor(
Zone* zone, compiler::CallDescriptor* descriptor);
static compiler::CallDescriptor* GetI32WasmCallDescriptorForSimd(
Zone* zone, compiler::CallDescriptor* descriptor);
}; };
// A ModuleEnv together with ModuleWireBytes. // A ModuleEnv together with ModuleWireBytes.
......
...@@ -517,7 +517,7 @@ class WasmFunctionCompiler : private GraphAndBuilders { ...@@ -517,7 +517,7 @@ class WasmFunctionCompiler : private GraphAndBuilders {
MachineOperatorBuilder* machine() { return &main_machine_; } MachineOperatorBuilder* machine() { return &main_machine_; }
CallDescriptor* descriptor() { CallDescriptor* descriptor() {
if (descriptor_ == nullptr) { if (descriptor_ == nullptr) {
descriptor_ = testing_module_->GetWasmCallDescriptor(zone(), sig); descriptor_ = compiler::GetWasmCallDescriptor(zone(), sig);
} }
return descriptor_; return descriptor_;
} }
...@@ -604,7 +604,7 @@ class WasmFunctionCompiler : private GraphAndBuilders { ...@@ -604,7 +604,7 @@ class WasmFunctionCompiler : private GraphAndBuilders {
Handle<Code> Compile() { Handle<Code> Compile() {
CallDescriptor* desc = descriptor(); CallDescriptor* desc = descriptor();
if (kPointerSize == 4) { if (kPointerSize == 4) {
desc = testing_module_->GetI32WasmCallDescriptor(this->zone(), desc); desc = compiler::GetI32WasmCallDescriptor(this->zone(), desc);
} }
EmbeddedVector<char, 16> comp_name; EmbeddedVector<char, 16> comp_name;
int comp_name_len = SNPrintF(comp_name, "wasm#%u", this->function_index()); int comp_name_len = SNPrintF(comp_name, "wasm#%u", this->function_index());
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/compiler/linkage.h" #include "src/compiler/linkage.h"
#include "src/compiler/machine-operator.h" #include "src/compiler/machine-operator.h"
#include "src/compiler/node.h" #include "src/compiler/node.h"
#include "src/compiler/wasm-compiler.h"
#include "src/compiler/node-properties.h" #include "src/compiler/node-properties.h"
...@@ -331,7 +332,7 @@ TEST_F(Int64LoweringTest, CallI64Return) { ...@@ -331,7 +332,7 @@ TEST_F(Int64LoweringTest, CallI64Return) {
sig_builder.AddReturn(MachineRepresentation::kWord64); sig_builder.AddReturn(MachineRepresentation::kWord64);
compiler::CallDescriptor* desc = compiler::CallDescriptor* desc =
wasm::ModuleEnv::GetWasmCallDescriptor(zone(), sig_builder.Build()); compiler::GetWasmCallDescriptor(zone(), sig_builder.Build());
LowerGraph(graph()->NewNode(common()->Call(desc), Int32Constant(function), LowerGraph(graph()->NewNode(common()->Call(desc), Int32Constant(function),
start(), start()), start(), start()),
...@@ -349,7 +350,7 @@ TEST_F(Int64LoweringTest, CallI64Return) { ...@@ -349,7 +350,7 @@ TEST_F(Int64LoweringTest, CallI64Return) {
CompareCallDescriptors( CompareCallDescriptors(
OpParameter<const CallDescriptor*>( OpParameter<const CallDescriptor*>(
graph()->end()->InputAt(1)->InputAt(1)->InputAt(0)), graph()->end()->InputAt(1)->InputAt(1)->InputAt(0)),
wasm::ModuleEnv::GetI32WasmCallDescriptor(zone(), desc)); compiler::GetI32WasmCallDescriptor(zone(), desc));
} }
TEST_F(Int64LoweringTest, CallI64Parameter) { TEST_F(Int64LoweringTest, CallI64Parameter) {
...@@ -362,7 +363,7 @@ TEST_F(Int64LoweringTest, CallI64Parameter) { ...@@ -362,7 +363,7 @@ TEST_F(Int64LoweringTest, CallI64Parameter) {
sig_builder.AddParam(MachineRepresentation::kWord64); sig_builder.AddParam(MachineRepresentation::kWord64);
compiler::CallDescriptor* desc = compiler::CallDescriptor* desc =
wasm::ModuleEnv::GetWasmCallDescriptor(zone(), sig_builder.Build()); compiler::GetWasmCallDescriptor(zone(), sig_builder.Build());
LowerGraph(graph()->NewNode(common()->Call(desc), Int32Constant(function), LowerGraph(graph()->NewNode(common()->Call(desc), Int32Constant(function),
Int64Constant(value(0)), Int64Constant(value(0)),
...@@ -380,10 +381,9 @@ TEST_F(Int64LoweringTest, CallI64Parameter) { ...@@ -380,10 +381,9 @@ TEST_F(Int64LoweringTest, CallI64Parameter) {
IsInt32Constant(high_word_value(2)), start(), start()), IsInt32Constant(high_word_value(2)), start(), start()),
start(), start())); start(), start()));
CompareCallDescriptors( CompareCallDescriptors(OpParameter<const CallDescriptor*>(
OpParameter<const CallDescriptor*>( graph()->end()->InputAt(1)->InputAt(1)),
graph()->end()->InputAt(1)->InputAt(1)), compiler::GetI32WasmCallDescriptor(zone(), desc));
wasm::ModuleEnv::GetI32WasmCallDescriptor(zone(), desc));
} }
TEST_F(Int64LoweringTest, Int64Add) { TEST_F(Int64LoweringTest, Int64Add) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment