[wasm] Avoid use of AccessBuilder
The main goal is to untangle Liftoff from the TF-based wasm compiler, but since the AccessBuilder does not simplify anything but rather adds complexity I also removed it from the wasm compiler. Instead, we now bottleneck all offset computations through the new ObjectAccess helper. R=titzer@chromium.org Bug: v8:6600 Change-Id: I362b7b889d68e89da8c30d3fad7b5bab07bee5c8 Reviewed-on: https://chromium-review.googlesource.com/1204090 Reviewed-by: Ben Titzer <titzer@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#55646}
This commit is contained in:
parent
58f0497ba9
commit
05fa1f994e
1
BUILD.gn
1
BUILD.gn
@ -2526,6 +2526,7 @@ v8_source_set("v8_base") {
|
||||
"src/wasm/module-compiler.h",
|
||||
"src/wasm/module-decoder.cc",
|
||||
"src/wasm/module-decoder.h",
|
||||
"src/wasm/object-access.h",
|
||||
"src/wasm/signature-map.cc",
|
||||
"src/wasm/signature-map.h",
|
||||
"src/wasm/streaming-decoder.cc",
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "src/builtins/builtins.h"
|
||||
#include "src/code-factory.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/compiler/access-builder.h"
|
||||
#include "src/compiler/code-generator.h"
|
||||
#include "src/compiler/common-operator.h"
|
||||
#include "src/compiler/compiler-source-position-table.h"
|
||||
@ -43,6 +42,7 @@
|
||||
#include "src/wasm/function-compiler.h"
|
||||
#include "src/wasm/jump-table-assembler.h"
|
||||
#include "src/wasm/memory-tracing.h"
|
||||
#include "src/wasm/object-access.h"
|
||||
#include "src/wasm/wasm-code-manager.h"
|
||||
#include "src/wasm/wasm-limits.h"
|
||||
#include "src/wasm/wasm-linkage.h"
|
||||
@ -55,6 +55,8 @@ namespace v8 {
|
||||
namespace internal {
|
||||
namespace compiler {
|
||||
|
||||
namespace {
|
||||
|
||||
// TODO(titzer): pull WASM_64 up to a common header.
|
||||
#if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64
|
||||
#define WASM_64 1
|
||||
@ -67,7 +69,7 @@ namespace compiler {
|
||||
wasm::WasmOpcodes::OpcodeName(opcode));
|
||||
|
||||
#define WASM_INSTANCE_OBJECT_OFFSET(name) \
|
||||
(WasmInstanceObject::k##name##Offset - kHeapObjectTag)
|
||||
wasm::ObjectAccess::ToTagged(WasmInstanceObject::k##name##Offset)
|
||||
|
||||
#define LOAD_INSTANCE_FIELD(name, type) \
|
||||
SetEffect(graph()->NewNode( \
|
||||
@ -78,15 +80,9 @@ namespace compiler {
|
||||
#define LOAD_FIXED_ARRAY_SLOT(array_node, index) \
|
||||
SetEffect(graph()->NewNode( \
|
||||
mcgraph()->machine()->Load(MachineType::TaggedPointer()), array_node, \
|
||||
mcgraph()->Int32Constant(FixedArrayOffsetMinusTag(index)), Effect(), \
|
||||
Control()))
|
||||
|
||||
int FixedArrayOffsetMinusTag(uint32_t index) {
|
||||
auto access = AccessBuilder::ForFixedArraySlot(index);
|
||||
return access.offset - access.tag();
|
||||
}
|
||||
|
||||
namespace {
|
||||
mcgraph()->Int32Constant( \
|
||||
wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(index)), \
|
||||
Effect(), Control()))
|
||||
|
||||
constexpr uint32_t kBytesPerExceptionValuesArrayElement = 2;
|
||||
|
||||
@ -2589,9 +2585,10 @@ Node* WasmGraphBuilder::BuildImportWasmCall(wasm::FunctionSig* sig, Node** args,
|
||||
Node* imported_instances = LOAD_INSTANCE_FIELD(ImportedFunctionInstances,
|
||||
MachineType::TaggedPointer());
|
||||
// Access fixed array at {header_size - tag + func_index * kPointerSize}.
|
||||
Node* imported_instances_data =
|
||||
graph()->NewNode(mcgraph()->machine()->IntAdd(), imported_instances,
|
||||
mcgraph()->IntPtrConstant(FixedArrayOffsetMinusTag(0)));
|
||||
Node* imported_instances_data = graph()->NewNode(
|
||||
mcgraph()->machine()->IntAdd(), imported_instances,
|
||||
mcgraph()->IntPtrConstant(
|
||||
wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(0)));
|
||||
Node* func_index_times_pointersize = graph()->NewNode(
|
||||
mcgraph()->machine()->IntMul(), Uint32ToUintptr(func_index),
|
||||
mcgraph()->Int32Constant(kPointerSize));
|
||||
@ -2690,11 +2687,11 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t sig_index, Node** args,
|
||||
SetEffect(graph()->NewNode(machine->Load(MachineType::Pointer()),
|
||||
ift_targets, scaled_key, Effect(), Control()));
|
||||
|
||||
auto access = AccessBuilder::ForFixedArrayElement();
|
||||
Node* target_instance = SetEffect(graph()->NewNode(
|
||||
machine->Load(MachineType::TaggedPointer()),
|
||||
graph()->NewNode(machine->IntAdd(), ift_instances, scaled_key),
|
||||
Int32Constant(access.header_size - access.tag()), Effect(), Control()));
|
||||
Int32Constant(wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(0)),
|
||||
Effect(), Control()));
|
||||
|
||||
args[0] = target;
|
||||
|
||||
@ -4480,11 +4477,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
|
||||
|
||||
if (target->IsJSFunction()) {
|
||||
Handle<JSFunction> function = Handle<JSFunction>::cast(target);
|
||||
FieldAccess field_access = AccessBuilder::ForJSFunctionContext();
|
||||
Node* function_context = SetEffect(graph()->NewNode(
|
||||
mcgraph()->machine()->Load(MachineType::TaggedPointer()),
|
||||
callable_node,
|
||||
mcgraph()->Int32Constant(field_access.offset - field_access.tag()),
|
||||
mcgraph()->Int32Constant(
|
||||
wasm::ObjectAccess::ContextOffsetInTaggedJSFunction()),
|
||||
Effect(), Control()));
|
||||
|
||||
if (!IsClassConstructor(function->shared()->kind())) {
|
||||
|
@ -87,10 +87,6 @@ V8_EXPORT_PRIVATE MaybeHandle<Code> CompileJSToWasmWrapper(
|
||||
MaybeHandle<Code> CompileWasmInterpreterEntry(Isolate*, uint32_t func_index,
|
||||
wasm::FunctionSig*);
|
||||
|
||||
// Helper function to get the offset into a fixed array for a given {index}.
|
||||
// TODO(titzer): access-builder.h is not accessible outside compiler. Move?
|
||||
int FixedArrayOffsetMinusTag(uint32_t index);
|
||||
|
||||
enum CWasmEntryParameters {
|
||||
kCodeObject,
|
||||
kWasmInstance,
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "src/wasm/function-body-decoder-impl.h"
|
||||
#include "src/wasm/function-compiler.h"
|
||||
#include "src/wasm/memory-tracing.h"
|
||||
#include "src/wasm/object-access.h"
|
||||
#include "src/wasm/wasm-engine.h"
|
||||
#include "src/wasm/wasm-linkage.h"
|
||||
#include "src/wasm/wasm-objects.h"
|
||||
@ -39,7 +40,7 @@ namespace {
|
||||
} while (false)
|
||||
|
||||
#define WASM_INSTANCE_OBJECT_OFFSET(name) \
|
||||
(WasmInstanceObject::k##name##Offset - kHeapObjectTag)
|
||||
ObjectAccess::ToTagged(WasmInstanceObject::k##name##Offset)
|
||||
|
||||
#define LOAD_INSTANCE_FIELD(dst, name, type) \
|
||||
__ LoadFromInstance(dst.gp(), WASM_INSTANCE_OBJECT_OFFSET(name), \
|
||||
@ -1605,8 +1606,8 @@ class LiftoffCompiler {
|
||||
kPointerLoadType);
|
||||
LiftoffRegister target_instance = tmp;
|
||||
__ Load(target_instance, imported_instances.gp(), no_reg,
|
||||
compiler::FixedArrayOffsetMinusTag(imm.index), kPointerLoadType,
|
||||
pinned);
|
||||
ObjectAccess::ElementOffsetInTaggedFixedArray(imm.index),
|
||||
kPointerLoadType, pinned);
|
||||
|
||||
LiftoffRegister* explicit_instance = &target_instance;
|
||||
Register target_reg = target.gp();
|
||||
@ -1740,7 +1741,7 @@ class LiftoffCompiler {
|
||||
LOAD_INSTANCE_FIELD(table, IndirectFunctionTableInstances,
|
||||
kPointerLoadType);
|
||||
__ Load(tmp_const, table.gp(), index.gp(),
|
||||
(FixedArray::kHeaderSize - kHeapObjectTag), kPointerLoadType,
|
||||
ObjectAccess::ElementOffsetInTaggedFixedArray(0), kPointerLoadType,
|
||||
pinned);
|
||||
LiftoffRegister* explicit_instance = &tmp_const;
|
||||
|
||||
|
35
src/wasm/object-access.h
Normal file
35
src/wasm/object-access.h
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright 2018 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_WASM_OBJECT_ACCESS_H_
|
||||
#define V8_WASM_OBJECT_ACCESS_H_
|
||||
|
||||
#include "src/globals.h"
|
||||
#include "src/objects/fixed-array.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
namespace wasm {
|
||||
|
||||
class ObjectAccess : public AllStatic {
|
||||
public:
|
||||
// Convert an offset into an object to an offset into a tagged object.
|
||||
static constexpr int ToTagged(int offset) { return offset - kHeapObjectTag; }
|
||||
|
||||
// Get the offset into a fixed array for a given {index}.
|
||||
static constexpr int ElementOffsetInTaggedFixedArray(int index) {
|
||||
return ToTagged(FixedArray::OffsetOfElementAt(index));
|
||||
}
|
||||
|
||||
// Get the offset of the context stored in a {JSFunction} object.
|
||||
static constexpr int ContextOffsetInTaggedJSFunction() {
|
||||
return ToTagged(JSFunction::kContextOffset);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace wasm
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_WASM_OBJECT_ACCESS_H_
|
Loading…
Reference in New Issue
Block a user