Commit 7631358e authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Reuse information from wasm-linkage.h

For generating the WasmCompileLazy builtin, we need to know the list of
parameter registers in wasm. Instead of duplicating this, just use the
existing array from wasm-linkage.h.

R=titzer@chromium.org

Change-Id: Ib552af7b6a3defbc9c8b48390244bf943306a4b7
Reviewed-on: https://chromium-review.googlesource.com/1057310Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53182}
parent 8ae28f32
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#ifndef V8_BASE_ADAPTERS_H_ #ifndef V8_BASE_ADAPTERS_H_
#define V8_BASE_ADAPTERS_H_ #define V8_BASE_ADAPTERS_H_
#include <iterator>
#include "src/base/macros.h" #include "src/base/macros.h"
namespace v8 { namespace v8 {
...@@ -17,13 +19,15 @@ namespace base { ...@@ -17,13 +19,15 @@ namespace base {
template <typename T> template <typename T>
class ReversedAdapter { class ReversedAdapter {
public: public:
typedef decltype(static_cast<T*>(nullptr)->rbegin()) Iterator; using Iterator =
std::reverse_iterator<decltype(std::begin(std::declval<T>()))>;
explicit ReversedAdapter(T& t) : t_(t) {} explicit ReversedAdapter(T& t) : t_(t) {}
ReversedAdapter(const ReversedAdapter& ra) : t_(ra.t_) {} ReversedAdapter(const ReversedAdapter& ra) = default;
Iterator begin() const { return t_.rbegin(); } // TODO(clemensh): Use std::rbegin/std::rend once we have C++14 support.
Iterator end() const { return t_.rend(); } Iterator begin() const { return Iterator(std::end(t_)); }
Iterator end() const { return Iterator(std::begin(t_)); }
private: private:
T& t_; T& t_;
......
...@@ -4,12 +4,14 @@ ...@@ -4,12 +4,14 @@
#if V8_TARGET_ARCH_IA32 #if V8_TARGET_ARCH_IA32
#include "src/base/adapters.h"
#include "src/code-factory.h" #include "src/code-factory.h"
#include "src/debug/debug.h" #include "src/debug/debug.h"
#include "src/deoptimizer.h" #include "src/deoptimizer.h"
#include "src/frame-constants.h" #include "src/frame-constants.h"
#include "src/frames.h" #include "src/frames.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/wasm/wasm-linkage.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -2770,22 +2772,22 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) { ...@@ -2770,22 +2772,22 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
// Save all parameter registers (see wasm-linkage.cc). They might be // Save all parameter registers (see wasm-linkage.cc). They might be
// overwritten in the runtime call below. We don't have any callee-saved // overwritten in the runtime call below. We don't have any callee-saved
// registers in wasm, so no need to store anything else. // registers in wasm, so no need to store anything else.
constexpr Register gp_regs[]{eax, ebx, ecx, edx}; for (Register reg : wasm::kGpParamRegisters) {
constexpr XMMRegister xmm_regs[]{xmm1, xmm2, xmm3, xmm4, xmm5, xmm6}; if (reg == kWasmInstanceRegister) continue;
for (auto reg : gp_regs) {
__ Push(reg); __ Push(reg);
} }
__ sub(esp, Immediate(16 * arraysize(xmm_regs))); __ sub(esp, Immediate(16 * arraysize(wasm::kFpParamRegisters)));
for (int i = 0, e = arraysize(xmm_regs); i < e; ++i) { int offset = 0;
__ movdqu(Operand(esp, 16 * i), xmm_regs[i]); for (DoubleRegister reg : wasm::kFpParamRegisters) {
__ movdqu(Operand(esp, offset), reg);
offset += 16;
} }
// Pass the WASM instance as an explicit argument to WasmCompileLazy. // Pass the WASM instance as an explicit argument to WasmCompileLazy.
__ Push(kWasmInstanceRegister); __ Push(kWasmInstanceRegister);
// Initialize the JavaScript context with 0. CEntry will use it to // Initialize the JavaScript context with 0. CEntry will use it to
// set the current context on the isolate. // set the current context on the isolate.
__ Move(esi, Smi::kZero); __ Move(kContextRegister, Smi::kZero);
__ CallRuntime(Runtime::kWasmCompileLazy); __ CallRuntime(Runtime::kWasmCompileLazy);
// The entrypoint address is the first return value. // The entrypoint address is the first return value.
__ mov(edi, kReturnRegister0); __ mov(edi, kReturnRegister0);
...@@ -2793,12 +2795,15 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) { ...@@ -2793,12 +2795,15 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
__ mov(kWasmInstanceRegister, kReturnRegister1); __ mov(kWasmInstanceRegister, kReturnRegister1);
// Restore registers. // Restore registers.
for (int i = arraysize(xmm_regs) - 1; i >= 0; --i) { for (DoubleRegister reg : base::Reversed(wasm::kFpParamRegisters)) {
__ movdqu(xmm_regs[i], Operand(esp, 16 * i)); offset -= 16;
__ movdqu(reg, Operand(esp, offset));
} }
__ add(esp, Immediate(16 * arraysize(xmm_regs))); DCHECK_EQ(0, offset);
for (int i = arraysize(gp_regs) - 1; i >= 0; --i) { __ add(esp, Immediate(16 * arraysize(wasm::kFpParamRegisters)));
__ Pop(gp_regs[i]); for (Register reg : base::Reversed(wasm::kGpParamRegisters)) {
if (reg == kWasmInstanceRegister) continue;
__ Pop(reg);
} }
} }
// Finally, jump to the entrypoint. // Finally, jump to the entrypoint.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#if V8_TARGET_ARCH_X64 #if V8_TARGET_ARCH_X64
#include "src/base/adapters.h"
#include "src/code-factory.h" #include "src/code-factory.h"
#include "src/counters.h" #include "src/counters.h"
#include "src/deoptimizer.h" #include "src/deoptimizer.h"
...@@ -11,6 +12,7 @@ ...@@ -11,6 +12,7 @@
#include "src/frames.h" #include "src/frames.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/objects/debug-objects.h" #include "src/objects/debug-objects.h"
#include "src/wasm/wasm-linkage.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -2715,22 +2717,22 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) { ...@@ -2715,22 +2717,22 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
// Save all parameter registers (see wasm-linkage.cc). They might be // Save all parameter registers (see wasm-linkage.cc). They might be
// overwritten in the runtime call below. We don't have any callee-saved // overwritten in the runtime call below. We don't have any callee-saved
// registers in wasm, so no need to store anything else. // registers in wasm, so no need to store anything else.
constexpr Register gp_regs[]{rax, rbx, rcx, rdx, rdi}; for (Register reg : wasm::kGpParamRegisters) {
constexpr XMMRegister xmm_regs[]{xmm1, xmm2, xmm3, xmm4, xmm5, xmm6}; if (reg == kWasmInstanceRegister) continue;
for (auto reg : gp_regs) {
__ Push(reg); __ Push(reg);
} }
__ subp(rsp, Immediate(16 * arraysize(xmm_regs))); __ subp(rsp, Immediate(16 * arraysize(wasm::kFpParamRegisters)));
for (int i = 0, e = arraysize(xmm_regs); i < e; ++i) { int offset = 0;
__ movdqu(Operand(rsp, 16 * i), xmm_regs[i]); for (DoubleRegister reg : wasm::kFpParamRegisters) {
__ movdqu(Operand(rsp, offset), reg);
offset += 16;
} }
// Pass the WASM instance as an explicit argument to WasmCompileLazy. // Pass the WASM instance as an explicit argument to WasmCompileLazy.
__ Push(kWasmInstanceRegister); __ Push(kWasmInstanceRegister);
// Initialize the JavaScript context with 0. CEntry will use it to // Initialize the JavaScript context with 0. CEntry will use it to
// set the current context on the isolate. // set the current context on the isolate.
__ Move(rsi, Smi::kZero); __ Move(kContextRegister, Smi::kZero);
__ CallRuntime(Runtime::kWasmCompileLazy); __ CallRuntime(Runtime::kWasmCompileLazy);
// The entrypoint address is the first return value. // The entrypoint address is the first return value.
__ movq(r11, kReturnRegister0); __ movq(r11, kReturnRegister0);
...@@ -2738,12 +2740,15 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) { ...@@ -2738,12 +2740,15 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
__ movq(kWasmInstanceRegister, kReturnRegister1); __ movq(kWasmInstanceRegister, kReturnRegister1);
// Restore registers. // Restore registers.
for (int i = arraysize(xmm_regs) - 1; i >= 0; --i) { for (DoubleRegister reg : base::Reversed(wasm::kFpParamRegisters)) {
__ movdqu(xmm_regs[i], Operand(rsp, 16 * i)); offset -= 16;
__ movdqu(reg, Operand(rsp, offset));
} }
__ addp(rsp, Immediate(16 * arraysize(xmm_regs))); DCHECK_EQ(0, offset);
for (int i = arraysize(gp_regs) - 1; i >= 0; --i) { __ addp(rsp, Immediate(16 * arraysize(wasm::kFpParamRegisters)));
__ Pop(gp_regs[i]); for (Register reg : base::Reversed(wasm::kGpParamRegisters)) {
if (reg == kWasmInstanceRegister) continue;
__ Pop(reg);
} }
} }
// Finally, jump to the entrypoint. // Finally, jump to the entrypoint.
......
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