Bug 1674436 - Share Prepare/Execute functions across JIT test cases. r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D95384
This commit is contained in:
Nicolas B. Pierron 2020-11-03 12:29:05 +00:00
Родитель ad21606ced
Коммит 2e038cc198
5 изменённых файлов: 108 добавлений и 130 удалений

Просмотреть файл

@ -147,6 +147,7 @@ if not CONFIG["JS_CODEGEN_NONE"]:
"testJitRangeAnalysis.cpp",
"testJitRegisterSet.cpp",
"testJitRValueAlloc.cpp",
"testsJit.cpp",
]
if CONFIG["NIGHTLY_BUILD"]:

Просмотреть файл

@ -19,6 +19,7 @@
#include "js/Value.h"
#include "jsapi-tests/tests.h"
#include "jsapi-tests/testsJit.h"
#include "jit/ABIFunctionList-inl.h"
#include "jit/MacroAssembler-inl.h"
@ -615,55 +616,6 @@ JSAPITest* DefineCheckArgs<Res (*)(Args...)>::instance_ = nullptr;
template <typename Res, typename... Args>
bool* DefineCheckArgs<Res (*)(Args...)>::reportTo_ = nullptr;
typedef void (*EnterTest)();
// On entry to the JIT code, save every register.
static void Prepare(MacroAssembler& masm) {
#if defined(JS_CODEGEN_ARM64)
masm.Mov(PseudoStackPointer64, sp);
masm.SetStackPointer64(PseudoStackPointer64);
#endif
AllocatableRegisterSet regs(RegisterSet::All());
LiveRegisterSet save(regs.asLiveSet());
masm.PushRegsInMask(save);
}
// Generate the exit path of the JIT code, which restores every register. Then,
// make it executable and run it.
static bool Execute(JSContext* cx, MacroAssembler& masm) {
AllocatableRegisterSet regs(RegisterSet::All());
LiveRegisterSet save(regs.asLiveSet());
masm.PopRegsInMask(save);
#if defined(JS_CODEGEN_ARM64)
// Return using the value popped into x30.
masm.abiret();
// Reset stack pointer.
masm.SetStackPointer64(PseudoStackPointer64);
#else
masm.ret(); // Add return statement to be sure.
#endif
if (masm.oom()) {
return false;
}
Linker linker(masm);
JitCode* code = linker.newCode(cx, CodeKind::Other);
if (!code) {
return false;
}
if (!ExecutableAllocator::makeExecutableAndFlushICache(
FlushICacheSpec::LocalThreadOnly, code->raw(), code->bufferSize())) {
return false;
}
JS::AutoSuppressGCAnalysis suppress;
EnterTest test = code->as<EnterTest>();
test();
return true;
}
// This is a child class of JSAPITest, which is used behind the scenes to
// register test cases in jsapi-tests. Each instance of it creates a new test
// case. This class is specialized with the type of the function to check, and
@ -682,7 +634,7 @@ class JitABICall final : public JSAPITest, public DefineCheckArgs<Sig> {
this->set_instance(this, &result);
StackMacroAssembler masm(cx);
Prepare(masm);
PrepareJit(masm);
AllocatableGeneralRegisterSet regs(GeneralRegisterSet::All());
// Initialize the base register the same way this is done while reading
@ -713,7 +665,7 @@ class JitABICall final : public JSAPITest, public DefineCheckArgs<Sig> {
this->generateCalls(masm, base, setup);
if (!Execute(cx, masm)) {
if (!ExecuteJit(cx, masm)) {
return false;
}
this->set_instance(nullptr, nullptr);

Просмотреть файл

@ -14,6 +14,7 @@
#include "js/Value.h"
#include "jsapi-tests/tests.h"
#include "jsapi-tests/testsJit.h"
#include "jit/MacroAssembler-inl.h"
@ -25,47 +26,10 @@ using mozilla::PositiveInfinity;
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
typedef void (*EnterTest)();
static bool Prepare(MacroAssembler& masm) {
AllocatableRegisterSet regs(RegisterSet::All());
LiveRegisterSet save(regs.asLiveSet());
masm.PushRegsInMask(save);
return true;
}
static bool Execute(JSContext* cx, MacroAssembler& masm) {
AllocatableRegisterSet regs(RegisterSet::All());
LiveRegisterSet save(regs.asLiveSet());
masm.PopRegsInMask(save);
masm.ret(); // Add return statement to be sure.
if (masm.oom()) {
return false;
}
Linker linker(masm);
JitCode* code = linker.newCode(cx, CodeKind::Other);
if (!code) {
return false;
}
if (!ExecutableAllocator::makeExecutableAndFlushICache(
FlushICacheSpec::LocalThreadOnly, code->raw(), code->bufferSize())) {
return false;
}
JS::AutoSuppressGCAnalysis suppress;
EnterTest test = code->as<EnterTest>();
test();
return true;
}
BEGIN_TEST(testJitMacroAssembler_flexibleDivMod) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
// Test case divides 9/2;
const uintptr_t quotient_result = 4;
@ -114,16 +78,14 @@ BEGIN_TEST(testJitMacroAssembler_flexibleDivMod) {
}
}
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_flexibleDivMod)
BEGIN_TEST(testJitMacroAssembler_flexibleRemainder) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
// Test case divides 9/2;
const uintptr_t dividend = 9;
@ -163,16 +125,14 @@ BEGIN_TEST(testJitMacroAssembler_flexibleRemainder) {
}
}
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_flexibleRemainder)
BEGIN_TEST(testJitMacroAssembler_flexibleQuotient) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
// Test case divides 9/2;
const uintptr_t dividend = 9;
@ -212,7 +172,7 @@ BEGIN_TEST(testJitMacroAssembler_flexibleQuotient) {
}
}
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_flexibleQuotient)
@ -226,9 +186,7 @@ bool shiftTest(JSContext* cx, const char* name,
const uintptr_t* result) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
JS::AutoSuppressGCAnalysis suppress;
AllocatableGeneralRegisterSet leftOutputHandSides(GeneralRegisterSet::All());
@ -297,7 +255,7 @@ bool shiftTest(JSContext* cx, const char* name,
}
}
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
BEGIN_TEST(testJitMacroAssembler_flexibleRshift) {
@ -421,9 +379,7 @@ END_TEST(testJitMacroAssembler_flexibleLshift)
BEGIN_TEST(testJitMacroAssembler_truncateDoubleToInt64) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
AllocatableGeneralRegisterSet allRegs(GeneralRegisterSet::All());
AllocatableFloatRegisterSet allFloatRegs(FloatRegisterSet::All());
@ -462,16 +418,14 @@ BEGIN_TEST(testJitMacroAssembler_truncateDoubleToInt64) {
masm.freeStack(sizeof(int32_t));
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_truncateDoubleToInt64)
BEGIN_TEST(testJitMacroAssembler_truncateDoubleToUInt64) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
AllocatableGeneralRegisterSet allRegs(GeneralRegisterSet::All());
AllocatableFloatRegisterSet allFloatRegs(FloatRegisterSet::All());
@ -515,16 +469,14 @@ BEGIN_TEST(testJitMacroAssembler_truncateDoubleToUInt64) {
masm.freeStack(sizeof(int32_t));
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_truncateDoubleToUInt64)
BEGIN_TEST(testJitMacroAssembler_branchDoubleNotInInt64Range) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
AllocatableGeneralRegisterSet allRegs(GeneralRegisterSet::All());
AllocatableFloatRegisterSet allFloatRegs(FloatRegisterSet::All());
@ -569,16 +521,14 @@ BEGIN_TEST(testJitMacroAssembler_branchDoubleNotInInt64Range) {
masm.freeStack(sizeof(int32_t));
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_branchDoubleNotInInt64Range)
BEGIN_TEST(testJitMacroAssembler_branchDoubleNotInUInt64Range) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
AllocatableGeneralRegisterSet allRegs(GeneralRegisterSet::All());
AllocatableFloatRegisterSet allFloatRegs(FloatRegisterSet::All());
@ -626,16 +576,14 @@ BEGIN_TEST(testJitMacroAssembler_branchDoubleNotInUInt64Range) {
masm.freeStack(sizeof(int32_t));
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_branchDoubleNotInUInt64Range)
BEGIN_TEST(testJitMacroAssembler_lshift64) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
AllocatableGeneralRegisterSet allRegs(GeneralRegisterSet::All());
AllocatableFloatRegisterSet allFloatRegs(FloatRegisterSet::All());
@ -695,16 +643,14 @@ BEGIN_TEST(testJitMacroAssembler_lshift64) {
masm.freeStack(sizeof(int32_t));
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_lshift64)
BEGIN_TEST(testJitMacroAssembler_rshift64Arithmetic) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
AllocatableGeneralRegisterSet allRegs(GeneralRegisterSet::All());
AllocatableFloatRegisterSet allFloatRegs(FloatRegisterSet::All());
@ -764,16 +710,14 @@ BEGIN_TEST(testJitMacroAssembler_rshift64Arithmetic) {
masm.freeStack(sizeof(int32_t));
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_rshift64Arithmetic)
BEGIN_TEST(testJitMacroAssembler_rshift64) {
StackMacroAssembler masm(cx);
if (!Prepare(masm)) {
return false;
}
PrepareJit(masm);
AllocatableGeneralRegisterSet allRegs(GeneralRegisterSet::All());
AllocatableFloatRegisterSet allFloatRegs(FloatRegisterSet::All());
@ -832,7 +776,7 @@ BEGIN_TEST(testJitMacroAssembler_rshift64) {
masm.freeStack(sizeof(int32_t));
return Execute(cx, masm);
return ExecuteJit(cx, masm);
}
END_TEST(testJitMacroAssembler_rshift64)

Просмотреть файл

@ -0,0 +1,60 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "jsapi-tests/testsJit.h"
#include "jit/Linker.h"
#include "jit/MacroAssembler-inl.h"
// On entry to the JIT code, save every register.
void PrepareJit(js::jit::MacroAssembler& masm) {
using namespace js::jit;
#if defined(JS_CODEGEN_ARM64)
masm.Mov(PseudoStackPointer64, sp);
masm.SetStackPointer64(PseudoStackPointer64);
#endif
AllocatableRegisterSet regs(RegisterSet::All());
LiveRegisterSet save(regs.asLiveSet());
masm.PushRegsInMask(save);
}
// Generate the exit path of the JIT code, which restores every register. Then,
// make it executable and run it.
bool ExecuteJit(JSContext* cx, js::jit::MacroAssembler& masm) {
using namespace js::jit;
AllocatableRegisterSet regs(RegisterSet::All());
LiveRegisterSet save(regs.asLiveSet());
masm.PopRegsInMask(save);
#if defined(JS_CODEGEN_ARM64)
// Return using the value popped into x30.
masm.abiret();
// Reset stack pointer.
masm.SetStackPointer64(PseudoStackPointer64);
#else
masm.ret(); // Add return statement to be sure.
#endif
if (masm.oom()) {
return false;
}
Linker linker(masm);
JitCode* code = linker.newCode(cx, CodeKind::Other);
if (!code) {
return false;
}
if (!ExecutableAllocator::makeExecutableAndFlushICache(
FlushICacheSpec::LocalThreadOnly, code->raw(), code->bufferSize())) {
return false;
}
JS::AutoSuppressGCAnalysis suppress;
EnterTest test = code->as<EnterTest>();
test();
return true;
}

Просмотреть файл

@ -0,0 +1,21 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef jsapi_tests_testsJit_h
#define jsapi_tests_testsJit_h
#include "jit/MacroAssembler.h"
typedef void (*EnterTest)();
// On entry to the JIT code, save every register.
void PrepareJit(js::jit::MacroAssembler& masm);
// Generate the exit path of the JIT code, which restores every register. Then,
// make it executable and run it.
bool ExecuteJit(JSContext* cx, js::jit::MacroAssembler& masm);
#endif /* !jsapi_tests_testsJit_h */