[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}
This commit is contained in:
parent
5dd179933c
commit
0a91a4c90f
@ -12,6 +12,7 @@
|
||||
#include "src/compiler/node-properties.h"
|
||||
|
||||
#include "src/compiler/node.h"
|
||||
#include "src/compiler/wasm-compiler.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/wasm/wasm-module.h"
|
||||
#include "src/zone/zone.h"
|
||||
@ -296,8 +297,8 @@ void Int64Lowering::LowerNode(Node* node) {
|
||||
(descriptor->ReturnCount() == 1 &&
|
||||
descriptor->GetReturnType(0) == MachineType::Int64())) {
|
||||
// We have to adjust the call descriptor.
|
||||
const Operator* op = common()->Call(
|
||||
wasm::ModuleEnv::GetI32WasmCallDescriptor(zone(), descriptor));
|
||||
const Operator* op =
|
||||
common()->Call(GetI32WasmCallDescriptor(zone(), descriptor));
|
||||
NodeProperties::ChangeOp(node, op);
|
||||
}
|
||||
if (descriptor->ReturnCount() == 1 &&
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "src/compiler/node-properties.h"
|
||||
|
||||
#include "src/compiler/node.h"
|
||||
#include "src/compiler/wasm-compiler.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/wasm/wasm-module.h"
|
||||
|
||||
@ -786,8 +787,7 @@ void SimdScalarLowering::LowerNode(Node* node) {
|
||||
descriptor->GetReturnType(0) == MachineType::Simd128())) {
|
||||
// We have to adjust the call descriptor.
|
||||
const Operator* op =
|
||||
common()->Call(wasm::ModuleEnv::GetI32WasmCallDescriptorForSimd(
|
||||
zone(), descriptor));
|
||||
common()->Call(GetI32WasmCallDescriptorForSimd(zone(), descriptor));
|
||||
NodeProperties::ChangeOp(node, op);
|
||||
}
|
||||
if (descriptor->ReturnCount() == 1 &&
|
||||
|
@ -2190,8 +2190,7 @@ Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args,
|
||||
args[params + 1] = *effect_;
|
||||
args[params + 2] = *control_;
|
||||
|
||||
CallDescriptor* descriptor =
|
||||
wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig);
|
||||
CallDescriptor* descriptor = GetWasmCallDescriptor(jsgraph()->zone(), sig);
|
||||
const Operator* op = jsgraph()->common()->Call(descriptor);
|
||||
Node* call = graph()->NewNode(op, static_cast<int>(count), args);
|
||||
SetSourcePosition(call, position);
|
||||
@ -2655,8 +2654,8 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
|
||||
|
||||
// We only need a dummy call descriptor.
|
||||
wasm::FunctionSig::Builder dummy_sig_builder(jsgraph()->zone(), 0, 0);
|
||||
CallDescriptor* desc = wasm::ModuleEnv::GetWasmCallDescriptor(
|
||||
jsgraph()->zone(), dummy_sig_builder.Build());
|
||||
CallDescriptor* desc =
|
||||
GetWasmCallDescriptor(jsgraph()->zone(), dummy_sig_builder.Build());
|
||||
*effect_ = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args);
|
||||
Return(jsgraph()->UndefinedConstant());
|
||||
return;
|
||||
@ -2676,8 +2675,7 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
|
||||
args[pos++] = *control_;
|
||||
|
||||
// Call the wasm code.
|
||||
CallDescriptor* desc =
|
||||
wasm::ModuleEnv::GetWasmCallDescriptor(jsgraph()->zone(), sig);
|
||||
CallDescriptor* desc = GetWasmCallDescriptor(jsgraph()->zone(), sig);
|
||||
|
||||
Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args);
|
||||
*effect_ = call;
|
||||
@ -3753,10 +3751,9 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
|
||||
}
|
||||
|
||||
// Schedule and compile to machine code.
|
||||
CallDescriptor* incoming =
|
||||
wasm::ModuleEnv::GetWasmCallDescriptor(&zone, sig);
|
||||
CallDescriptor* incoming = GetWasmCallDescriptor(&zone, sig);
|
||||
if (machine.Is32()) {
|
||||
incoming = wasm::ModuleEnv::GetI32WasmCallDescriptor(&zone, incoming);
|
||||
incoming = GetI32WasmCallDescriptor(&zone, incoming);
|
||||
}
|
||||
Code::Flags flags = Code::ComputeFlags(Code::WASM_TO_JS_FUNCTION);
|
||||
bool debugging =
|
||||
@ -3838,10 +3835,9 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index,
|
||||
}
|
||||
|
||||
// Schedule and compile to machine code.
|
||||
CallDescriptor* incoming =
|
||||
wasm::ModuleEnv::GetWasmCallDescriptor(&zone, sig);
|
||||
CallDescriptor* incoming = GetWasmCallDescriptor(&zone, sig);
|
||||
if (machine.Is32()) {
|
||||
incoming = wasm::ModuleEnv::GetI32WasmCallDescriptor(&zone, incoming);
|
||||
incoming = GetI32WasmCallDescriptor(&zone, incoming);
|
||||
}
|
||||
Code::Flags flags = Code::ComputeFlags(Code::WASM_INTERPRETER_ENTRY);
|
||||
EmbeddedVector<char, 32> debug_name;
|
||||
@ -4015,11 +4011,11 @@ void WasmCompilationUnit::ExecuteCompilation() {
|
||||
compilation_zone_.reset(new Zone(isolate_->allocator(), ZONE_NAME));
|
||||
|
||||
// Run the compiler pipeline to generate machine code.
|
||||
CallDescriptor* descriptor = wasm::ModuleEnv::GetWasmCallDescriptor(
|
||||
compilation_zone_.get(), func_body_.sig);
|
||||
CallDescriptor* descriptor =
|
||||
GetWasmCallDescriptor(compilation_zone_.get(), func_body_.sig);
|
||||
if (jsgraph_->machine()->Is32()) {
|
||||
descriptor = module_env_->GetI32WasmCallDescriptor(
|
||||
compilation_zone_.get(), descriptor);
|
||||
descriptor =
|
||||
GetI32WasmCallDescriptor(compilation_zone_.get(), descriptor);
|
||||
}
|
||||
info_.reset(new CompilationInfo(
|
||||
GetDebugName(compilation_zone_.get(), func_name_, func_index_),
|
||||
|
@ -411,6 +411,13 @@ class WasmGraphBuilder {
|
||||
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 internal
|
||||
} // namespace v8
|
||||
|
@ -8,34 +8,30 @@
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/register-configuration.h"
|
||||
|
||||
#include "src/wasm/wasm-module.h"
|
||||
|
||||
#include "src/compiler/linkage.h"
|
||||
#include "src/compiler/wasm-compiler.h"
|
||||
|
||||
#include "src/zone/zone.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
// TODO(titzer): this should not be in the wasm namespace.
|
||||
namespace wasm {
|
||||
namespace compiler {
|
||||
|
||||
using compiler::LocationSignature;
|
||||
using compiler::CallDescriptor;
|
||||
using compiler::LinkageLocation;
|
||||
using wasm::ValueType;
|
||||
|
||||
namespace {
|
||||
|
||||
MachineType MachineTypeFor(ValueType type) {
|
||||
switch (type) {
|
||||
case kWasmI32:
|
||||
case wasm::kWasmI32:
|
||||
return MachineType::Int32();
|
||||
case kWasmI64:
|
||||
case wasm::kWasmI64:
|
||||
return MachineType::Int64();
|
||||
case kWasmF64:
|
||||
case wasm::kWasmF64:
|
||||
return MachineType::Float64();
|
||||
case kWasmF32:
|
||||
case wasm::kWasmF32:
|
||||
return MachineType::Float32();
|
||||
case kWasmS128:
|
||||
case wasm::kWasmS128:
|
||||
return MachineType::Simd128();
|
||||
default:
|
||||
UNREACHABLE();
|
||||
@ -182,7 +178,7 @@ struct Allocator {
|
||||
// Allocate floats using a double register, but modify the code to
|
||||
// reflect how ARM FP registers alias.
|
||||
// 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;
|
||||
DCHECK(float_reg_code < RegisterConfiguration::kMaxFPRegisters);
|
||||
return regloc(DoubleRegister::from_code(float_reg_code),
|
||||
@ -207,10 +203,11 @@ struct Allocator {
|
||||
}
|
||||
}
|
||||
bool IsFloatingPoint(ValueType type) {
|
||||
return type == kWasmF32 || type == kWasmF64;
|
||||
return type == wasm::kWasmF32 || type == wasm::kWasmF64;
|
||||
}
|
||||
int Words(ValueType type) {
|
||||
if (kPointerSize < 8 && (type == kWasmI64 || type == kWasmF64)) {
|
||||
if (kPointerSize < 8 &&
|
||||
(type == wasm::kWasmI64 || type == wasm::kWasmF64)) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
@ -275,8 +272,7 @@ static base::LazyInstance<Allocator, ReturnRegistersCreateTrait>::type
|
||||
return_registers = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
// General code uses the above configuration data.
|
||||
CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone,
|
||||
FunctionSig* fsig) {
|
||||
CallDescriptor* GetWasmCallDescriptor(Zone* zone, wasm::FunctionSig* fsig) {
|
||||
LocationSignature::Builder locations(zone, fsig->return_count(),
|
||||
fsig->parameter_count());
|
||||
|
||||
@ -379,20 +375,20 @@ CallDescriptor* ReplaceTypeInCallDescriptorWith(
|
||||
descriptor->debug_name());
|
||||
}
|
||||
|
||||
CallDescriptor* ModuleEnv::GetI32WasmCallDescriptor(
|
||||
Zone* zone, CallDescriptor* descriptor) {
|
||||
CallDescriptor* GetI32WasmCallDescriptor(Zone* zone,
|
||||
CallDescriptor* descriptor) {
|
||||
return ReplaceTypeInCallDescriptorWith(zone, descriptor, 2,
|
||||
MachineType::Int64(),
|
||||
MachineRepresentation::kWord32);
|
||||
}
|
||||
|
||||
CallDescriptor* ModuleEnv::GetI32WasmCallDescriptorForSimd(
|
||||
Zone* zone, CallDescriptor* descriptor) {
|
||||
CallDescriptor* GetI32WasmCallDescriptorForSimd(Zone* zone,
|
||||
CallDescriptor* descriptor) {
|
||||
return ReplaceTypeInCallDescriptorWith(zone, descriptor, 4,
|
||||
MachineType::Simd128(),
|
||||
MachineRepresentation::kWord32);
|
||||
}
|
||||
|
||||
} // namespace wasm
|
||||
} // namespace compiler
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -268,9 +268,6 @@ class InstanceBuilder {
|
||||
// of the work of compilation) can be background tasks.
|
||||
// TODO(wasm): factor out common parts of this with the synchronous pipeline.
|
||||
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:
|
||||
explicit AsyncCompileJob(Isolate* isolate, std::unique_ptr<byte[]> bytes_copy,
|
||||
size_t length, Handle<Context> context,
|
||||
|
@ -162,15 +162,12 @@ struct V8_EXPORT_PRIVATE WasmModule {
|
||||
static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb
|
||||
|
||||
std::unique_ptr<Zone> signature_zone;
|
||||
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
|
||||
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 mem_export = false; // true if the memory is exported
|
||||
// TODO(wasm): reconcile start function index being an int with
|
||||
// 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
|
||||
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
|
||||
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 mem_export = false; // true if the memory is exported
|
||||
int start_function_index = -1; // start function, >= 0 if any
|
||||
|
||||
std::vector<WasmGlobal> globals; // globals in this module.
|
||||
uint32_t globals_size = 0; // size of globals table.
|
||||
@ -365,14 +362,6 @@ struct V8_EXPORT_PRIVATE ModuleEnv {
|
||||
DCHECK_NOT_NULL(instance);
|
||||
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.
|
||||
|
@ -517,7 +517,7 @@ class WasmFunctionCompiler : private GraphAndBuilders {
|
||||
MachineOperatorBuilder* machine() { return &main_machine_; }
|
||||
CallDescriptor* descriptor() {
|
||||
if (descriptor_ == nullptr) {
|
||||
descriptor_ = testing_module_->GetWasmCallDescriptor(zone(), sig);
|
||||
descriptor_ = compiler::GetWasmCallDescriptor(zone(), sig);
|
||||
}
|
||||
return descriptor_;
|
||||
}
|
||||
@ -604,7 +604,7 @@ class WasmFunctionCompiler : private GraphAndBuilders {
|
||||
Handle<Code> Compile() {
|
||||
CallDescriptor* desc = descriptor();
|
||||
if (kPointerSize == 4) {
|
||||
desc = testing_module_->GetI32WasmCallDescriptor(this->zone(), desc);
|
||||
desc = compiler::GetI32WasmCallDescriptor(this->zone(), desc);
|
||||
}
|
||||
EmbeddedVector<char, 16> comp_name;
|
||||
int comp_name_len = SNPrintF(comp_name, "wasm#%u", this->function_index());
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "src/compiler/linkage.h"
|
||||
#include "src/compiler/machine-operator.h"
|
||||
#include "src/compiler/node.h"
|
||||
#include "src/compiler/wasm-compiler.h"
|
||||
|
||||
#include "src/compiler/node-properties.h"
|
||||
|
||||
@ -331,7 +332,7 @@ TEST_F(Int64LoweringTest, CallI64Return) {
|
||||
sig_builder.AddReturn(MachineRepresentation::kWord64);
|
||||
|
||||
compiler::CallDescriptor* desc =
|
||||
wasm::ModuleEnv::GetWasmCallDescriptor(zone(), sig_builder.Build());
|
||||
compiler::GetWasmCallDescriptor(zone(), sig_builder.Build());
|
||||
|
||||
LowerGraph(graph()->NewNode(common()->Call(desc), Int32Constant(function),
|
||||
start(), start()),
|
||||
@ -349,7 +350,7 @@ TEST_F(Int64LoweringTest, CallI64Return) {
|
||||
CompareCallDescriptors(
|
||||
OpParameter<const CallDescriptor*>(
|
||||
graph()->end()->InputAt(1)->InputAt(1)->InputAt(0)),
|
||||
wasm::ModuleEnv::GetI32WasmCallDescriptor(zone(), desc));
|
||||
compiler::GetI32WasmCallDescriptor(zone(), desc));
|
||||
}
|
||||
|
||||
TEST_F(Int64LoweringTest, CallI64Parameter) {
|
||||
@ -362,7 +363,7 @@ TEST_F(Int64LoweringTest, CallI64Parameter) {
|
||||
sig_builder.AddParam(MachineRepresentation::kWord64);
|
||||
|
||||
compiler::CallDescriptor* desc =
|
||||
wasm::ModuleEnv::GetWasmCallDescriptor(zone(), sig_builder.Build());
|
||||
compiler::GetWasmCallDescriptor(zone(), sig_builder.Build());
|
||||
|
||||
LowerGraph(graph()->NewNode(common()->Call(desc), Int32Constant(function),
|
||||
Int64Constant(value(0)),
|
||||
@ -380,10 +381,9 @@ TEST_F(Int64LoweringTest, CallI64Parameter) {
|
||||
IsInt32Constant(high_word_value(2)), start(), start()),
|
||||
start(), start()));
|
||||
|
||||
CompareCallDescriptors(
|
||||
OpParameter<const CallDescriptor*>(
|
||||
graph()->end()->InputAt(1)->InputAt(1)),
|
||||
wasm::ModuleEnv::GetI32WasmCallDescriptor(zone(), desc));
|
||||
CompareCallDescriptors(OpParameter<const CallDescriptor*>(
|
||||
graph()->end()->InputAt(1)->InputAt(1)),
|
||||
compiler::GetI32WasmCallDescriptor(zone(), desc));
|
||||
}
|
||||
|
||||
TEST_F(Int64LoweringTest, Int64Add) {
|
||||
|
Loading…
Reference in New Issue
Block a user