Commit 05fa1f99 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[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/1204090Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55646}
parent 58f0497b
...@@ -2526,6 +2526,7 @@ v8_source_set("v8_base") { ...@@ -2526,6 +2526,7 @@ v8_source_set("v8_base") {
"src/wasm/module-compiler.h", "src/wasm/module-compiler.h",
"src/wasm/module-decoder.cc", "src/wasm/module-decoder.cc",
"src/wasm/module-decoder.h", "src/wasm/module-decoder.h",
"src/wasm/object-access.h",
"src/wasm/signature-map.cc", "src/wasm/signature-map.cc",
"src/wasm/signature-map.h", "src/wasm/signature-map.h",
"src/wasm/streaming-decoder.cc", "src/wasm/streaming-decoder.cc",
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "src/builtins/builtins.h" #include "src/builtins/builtins.h"
#include "src/code-factory.h" #include "src/code-factory.h"
#include "src/compiler.h" #include "src/compiler.h"
#include "src/compiler/access-builder.h"
#include "src/compiler/code-generator.h" #include "src/compiler/code-generator.h"
#include "src/compiler/common-operator.h" #include "src/compiler/common-operator.h"
#include "src/compiler/compiler-source-position-table.h" #include "src/compiler/compiler-source-position-table.h"
...@@ -43,6 +42,7 @@ ...@@ -43,6 +42,7 @@
#include "src/wasm/function-compiler.h" #include "src/wasm/function-compiler.h"
#include "src/wasm/jump-table-assembler.h" #include "src/wasm/jump-table-assembler.h"
#include "src/wasm/memory-tracing.h" #include "src/wasm/memory-tracing.h"
#include "src/wasm/object-access.h"
#include "src/wasm/wasm-code-manager.h" #include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-limits.h" #include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-linkage.h" #include "src/wasm/wasm-linkage.h"
...@@ -55,6 +55,8 @@ namespace v8 { ...@@ -55,6 +55,8 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
namespace {
// TODO(titzer): pull WASM_64 up to a common header. // TODO(titzer): pull WASM_64 up to a common header.
#if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64 #if !V8_TARGET_ARCH_32_BIT || V8_TARGET_ARCH_X64
#define WASM_64 1 #define WASM_64 1
...@@ -67,7 +69,7 @@ namespace compiler { ...@@ -67,7 +69,7 @@ namespace compiler {
wasm::WasmOpcodes::OpcodeName(opcode)); wasm::WasmOpcodes::OpcodeName(opcode));
#define WASM_INSTANCE_OBJECT_OFFSET(name) \ #define WASM_INSTANCE_OBJECT_OFFSET(name) \
(WasmInstanceObject::k##name##Offset - kHeapObjectTag) wasm::ObjectAccess::ToTagged(WasmInstanceObject::k##name##Offset)
#define LOAD_INSTANCE_FIELD(name, type) \ #define LOAD_INSTANCE_FIELD(name, type) \
SetEffect(graph()->NewNode( \ SetEffect(graph()->NewNode( \
...@@ -78,15 +80,9 @@ namespace compiler { ...@@ -78,15 +80,9 @@ namespace compiler {
#define LOAD_FIXED_ARRAY_SLOT(array_node, index) \ #define LOAD_FIXED_ARRAY_SLOT(array_node, index) \
SetEffect(graph()->NewNode( \ SetEffect(graph()->NewNode( \
mcgraph()->machine()->Load(MachineType::TaggedPointer()), array_node, \ mcgraph()->machine()->Load(MachineType::TaggedPointer()), array_node, \
mcgraph()->Int32Constant(FixedArrayOffsetMinusTag(index)), Effect(), \ mcgraph()->Int32Constant( \
Control())) wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(index)), \
Effect(), Control()))
int FixedArrayOffsetMinusTag(uint32_t index) {
auto access = AccessBuilder::ForFixedArraySlot(index);
return access.offset - access.tag();
}
namespace {
constexpr uint32_t kBytesPerExceptionValuesArrayElement = 2; constexpr uint32_t kBytesPerExceptionValuesArrayElement = 2;
...@@ -2589,9 +2585,10 @@ Node* WasmGraphBuilder::BuildImportWasmCall(wasm::FunctionSig* sig, Node** args, ...@@ -2589,9 +2585,10 @@ Node* WasmGraphBuilder::BuildImportWasmCall(wasm::FunctionSig* sig, Node** args,
Node* imported_instances = LOAD_INSTANCE_FIELD(ImportedFunctionInstances, Node* imported_instances = LOAD_INSTANCE_FIELD(ImportedFunctionInstances,
MachineType::TaggedPointer()); MachineType::TaggedPointer());
// Access fixed array at {header_size - tag + func_index * kPointerSize}. // Access fixed array at {header_size - tag + func_index * kPointerSize}.
Node* imported_instances_data = Node* imported_instances_data = graph()->NewNode(
graph()->NewNode(mcgraph()->machine()->IntAdd(), imported_instances, mcgraph()->machine()->IntAdd(), imported_instances,
mcgraph()->IntPtrConstant(FixedArrayOffsetMinusTag(0))); mcgraph()->IntPtrConstant(
wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(0)));
Node* func_index_times_pointersize = graph()->NewNode( Node* func_index_times_pointersize = graph()->NewNode(
mcgraph()->machine()->IntMul(), Uint32ToUintptr(func_index), mcgraph()->machine()->IntMul(), Uint32ToUintptr(func_index),
mcgraph()->Int32Constant(kPointerSize)); mcgraph()->Int32Constant(kPointerSize));
...@@ -2690,11 +2687,11 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t sig_index, Node** args, ...@@ -2690,11 +2687,11 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t sig_index, Node** args,
SetEffect(graph()->NewNode(machine->Load(MachineType::Pointer()), SetEffect(graph()->NewNode(machine->Load(MachineType::Pointer()),
ift_targets, scaled_key, Effect(), Control())); ift_targets, scaled_key, Effect(), Control()));
auto access = AccessBuilder::ForFixedArrayElement();
Node* target_instance = SetEffect(graph()->NewNode( Node* target_instance = SetEffect(graph()->NewNode(
machine->Load(MachineType::TaggedPointer()), machine->Load(MachineType::TaggedPointer()),
graph()->NewNode(machine->IntAdd(), ift_instances, scaled_key), 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; args[0] = target;
...@@ -4480,11 +4477,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -4480,11 +4477,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
if (target->IsJSFunction()) { if (target->IsJSFunction()) {
Handle<JSFunction> function = Handle<JSFunction>::cast(target); Handle<JSFunction> function = Handle<JSFunction>::cast(target);
FieldAccess field_access = AccessBuilder::ForJSFunctionContext();
Node* function_context = SetEffect(graph()->NewNode( Node* function_context = SetEffect(graph()->NewNode(
mcgraph()->machine()->Load(MachineType::TaggedPointer()), mcgraph()->machine()->Load(MachineType::TaggedPointer()),
callable_node, callable_node,
mcgraph()->Int32Constant(field_access.offset - field_access.tag()), mcgraph()->Int32Constant(
wasm::ObjectAccess::ContextOffsetInTaggedJSFunction()),
Effect(), Control())); Effect(), Control()));
if (!IsClassConstructor(function->shared()->kind())) { if (!IsClassConstructor(function->shared()->kind())) {
......
...@@ -87,10 +87,6 @@ V8_EXPORT_PRIVATE MaybeHandle<Code> CompileJSToWasmWrapper( ...@@ -87,10 +87,6 @@ V8_EXPORT_PRIVATE MaybeHandle<Code> CompileJSToWasmWrapper(
MaybeHandle<Code> CompileWasmInterpreterEntry(Isolate*, uint32_t func_index, MaybeHandle<Code> CompileWasmInterpreterEntry(Isolate*, uint32_t func_index,
wasm::FunctionSig*); 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 { enum CWasmEntryParameters {
kCodeObject, kCodeObject,
kWasmInstance, kWasmInstance,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "src/wasm/function-body-decoder-impl.h" #include "src/wasm/function-body-decoder-impl.h"
#include "src/wasm/function-compiler.h" #include "src/wasm/function-compiler.h"
#include "src/wasm/memory-tracing.h" #include "src/wasm/memory-tracing.h"
#include "src/wasm/object-access.h"
#include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-linkage.h" #include "src/wasm/wasm-linkage.h"
#include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-objects.h"
...@@ -39,7 +40,7 @@ namespace { ...@@ -39,7 +40,7 @@ namespace {
} while (false) } while (false)
#define WASM_INSTANCE_OBJECT_OFFSET(name) \ #define WASM_INSTANCE_OBJECT_OFFSET(name) \
(WasmInstanceObject::k##name##Offset - kHeapObjectTag) ObjectAccess::ToTagged(WasmInstanceObject::k##name##Offset)
#define LOAD_INSTANCE_FIELD(dst, name, type) \ #define LOAD_INSTANCE_FIELD(dst, name, type) \
__ LoadFromInstance(dst.gp(), WASM_INSTANCE_OBJECT_OFFSET(name), \ __ LoadFromInstance(dst.gp(), WASM_INSTANCE_OBJECT_OFFSET(name), \
...@@ -1605,8 +1606,8 @@ class LiftoffCompiler { ...@@ -1605,8 +1606,8 @@ class LiftoffCompiler {
kPointerLoadType); kPointerLoadType);
LiftoffRegister target_instance = tmp; LiftoffRegister target_instance = tmp;
__ Load(target_instance, imported_instances.gp(), no_reg, __ Load(target_instance, imported_instances.gp(), no_reg,
compiler::FixedArrayOffsetMinusTag(imm.index), kPointerLoadType, ObjectAccess::ElementOffsetInTaggedFixedArray(imm.index),
pinned); kPointerLoadType, pinned);
LiftoffRegister* explicit_instance = &target_instance; LiftoffRegister* explicit_instance = &target_instance;
Register target_reg = target.gp(); Register target_reg = target.gp();
...@@ -1740,7 +1741,7 @@ class LiftoffCompiler { ...@@ -1740,7 +1741,7 @@ class LiftoffCompiler {
LOAD_INSTANCE_FIELD(table, IndirectFunctionTableInstances, LOAD_INSTANCE_FIELD(table, IndirectFunctionTableInstances,
kPointerLoadType); kPointerLoadType);
__ Load(tmp_const, table.gp(), index.gp(), __ Load(tmp_const, table.gp(), index.gp(),
(FixedArray::kHeaderSize - kHeapObjectTag), kPointerLoadType, ObjectAccess::ElementOffsetInTaggedFixedArray(0), kPointerLoadType,
pinned); pinned);
LiftoffRegister* explicit_instance = &tmp_const; LiftoffRegister* explicit_instance = &tmp_const;
......
// 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_
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