aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jit
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-06-05 15:41:39 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2018-06-27 12:02:26 +0000
commiteb98186670db90c7420b46e1442ad67b076d9af3 (patch)
treeb43ee2228aeaf2d01595924e23bf0406b4c8ec31 /src/qml/jit
parente62826fd6a40f2c41e8c252181bf3ab7d460bc50 (diff)
Move JIT helper functions into a reusable namespace
Change-Id: I61a87f56c3713fbab58ebe5b752e67180cd05a21 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/jit')
-rw-r--r--src/qml/jit/jit.pri2
-rw-r--r--src/qml/jit/qv4baselinejit.cpp120
-rw-r--r--src/qml/jit/qv4jithelpers.cpp153
-rw-r--r--src/qml/jit/qv4jithelpers_p.h89
4 files changed, 258 insertions, 106 deletions
diff --git a/src/qml/jit/jit.pri b/src/qml/jit/jit.pri
index 2b6b2e7c3c..9e3cf44387 100644
--- a/src/qml/jit/jit.pri
+++ b/src/qml/jit/jit.pri
@@ -2,9 +2,11 @@ INCLUDEPATH += $$PWD
INCLUDEPATH += $$OUT_PWD
SOURCES += \
+ $$PWD/qv4jithelpers.cpp \
$$PWD/qv4baselinejit.cpp \
$$PWD/qv4assembler.cpp
HEADERS += \
+ $$PWD/qv4jithelpers_p.h \
$$PWD/qv4baselinejit_p.h \
$$PWD/qv4assembler_p.h
diff --git a/src/qml/jit/qv4baselinejit.cpp b/src/qml/jit/qv4baselinejit.cpp
index ed4434d4a0..ed98ca5f4c 100644
--- a/src/qml/jit/qv4baselinejit.cpp
+++ b/src/qml/jit/qv4baselinejit.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qv4baselinejit_p.h"
+#include "qv4jithelpers_p.h"
#include "qv4assembler_p.h"
#include <private/qv4lookup_p.h>
#include <private/qv4generatorobject_p.h>
@@ -193,19 +194,13 @@ void BaselineJIT::generate_LoadName(int name)
as->checkException();
}
-static ReturnedValue loadGlobalLookupHelper(ExecutionEngine *engine, QV4::Function *f, int index)
-{
- QV4::Lookup *l = f->compilationUnit->runtimeLookups + index;
- return l->globalGetter(l, engine);
-}
-
void BaselineJIT::generate_LoadGlobalLookup(int index)
{
as->prepareCallWithArgCount(3);
as->passInt32AsArg(index, 2);
as->passFunctionAsArg(1);
as->passEngineAsArg(0);
- JIT_GENERATE_RUNTIME_CALL(loadGlobalLookupHelper, Assembler::ResultInAccumulator);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::loadGlobalLookup, Assembler::ResultInAccumulator);
as->checkException();
}
@@ -270,12 +265,6 @@ void BaselineJIT::generate_LoadProperty(int name)
as->checkException();
}
-static ReturnedValue getLookupHelper(ExecutionEngine *engine, QV4::Function *f, int index, const QV4::Value &base)
-{
- QV4::Lookup *l = f->compilationUnit->runtimeLookups + index;
- return l->getter(l, engine, base);
-}
-
void BaselineJIT::generate_GetLookup(int index, int base)
{
STORE_IP();
@@ -284,7 +273,7 @@ void BaselineJIT::generate_GetLookup(int index, int base)
as->passInt32AsArg(index, 2);
as->passFunctionAsArg(1);
as->passEngineAsArg(0);
- JIT_GENERATE_RUNTIME_CALL(getLookupHelper, Assembler::ResultInAccumulator);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::getLookup, Assembler::ResultInAccumulator);
as->checkException();
}
@@ -297,7 +286,7 @@ void BaselineJIT::generate_GetLookupA(int index)
as->passInt32AsArg(index, 2);
as->passFunctionAsArg(1);
as->passEngineAsArg(0);
- JIT_GENERATE_RUNTIME_CALL(getLookupHelper, Assembler::ResultInAccumulator);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::getLookup, Assembler::ResultInAccumulator);
as->checkException();
}
@@ -314,14 +303,6 @@ void BaselineJIT::generate_StoreProperty(int name, int base)
as->checkException();
}
-static void setLookupHelper(QV4::Function *f, int index, QV4::Value &base, const QV4::Value &value)
-{
- ExecutionEngine *engine = f->internalClass->engine;
- QV4::Lookup *l = f->compilationUnit->runtimeLookups + index;
- if (!l->setter(l, engine, base, value) && f->isStrict())
- engine->throwTypeError();
-}
-
void BaselineJIT::generate_SetLookup(int index, int base)
{
STORE_IP();
@@ -331,7 +312,7 @@ void BaselineJIT::generate_SetLookup(int index, int base)
as->passRegAsArg(base, 2);
as->passInt32AsArg(index, 1);
as->passFunctionAsArg(0);
- JIT_GENERATE_RUNTIME_CALL(setLookupHelper, Assembler::ResultInAccumulator);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::setLookup, Assembler::ResultInAccumulator);
as->checkException();
}
@@ -612,24 +593,13 @@ void BaselineJIT::generate_PushWithContext()
as->storeHeapObject(CallData::Context);
}
-static void pushBlockContextHelper(QV4::Value *stack, int index)
-{
- ExecutionContext *c = static_cast<ExecutionContext *>(stack + CallData::Context);
- stack[CallData::Context] = Runtime::method_createBlockContext(c, index);
-}
-
void BaselineJIT::generate_PushBlockContext(int index)
{
as->saveAccumulatorInFrame();
as->prepareCallWithArgCount(2);
as->passInt32AsArg(index, 1);
as->passRegAsArg(0, 0);
- JIT_GENERATE_RUNTIME_CALL(pushBlockContextHelper, Assembler::IgnoreResult);
-}
-
-static void cloneBlockContextHelper(QV4::Value *contextSlot)
-{
- *contextSlot = Runtime::method_cloneBlockContext(static_cast<QV4::ExecutionContext *>(contextSlot));
+ JIT_GENERATE_RUNTIME_CALL(Helpers::pushBlockContext, Assembler::IgnoreResult);
}
void BaselineJIT::generate_CloneBlockContext()
@@ -637,12 +607,7 @@ void BaselineJIT::generate_CloneBlockContext()
as->saveAccumulatorInFrame();
as->prepareCallWithArgCount(1);
as->passRegAsArg(CallData::Context, 0);
- JIT_GENERATE_RUNTIME_CALL(cloneBlockContextHelper, Assembler::IgnoreResult);
-}
-
-static void pushScriptContextHelper(QV4::Value *stack, ExecutionEngine *engine, int index)
-{
- stack[CallData::Context] = Runtime::method_createScriptContext(engine, index);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::cloneBlockContext, Assembler::IgnoreResult);
}
void BaselineJIT::generate_PushScriptContext(int index)
@@ -652,12 +617,7 @@ void BaselineJIT::generate_PushScriptContext(int index)
as->passInt32AsArg(index, 2);
as->passEngineAsArg(1);
as->passRegAsArg(0, 0);
- JIT_GENERATE_RUNTIME_CALL(pushScriptContextHelper, Assembler::IgnoreResult);
-}
-
-static void popScriptContextHelper(QV4::Value *stack, ExecutionEngine *engine)
-{
- stack[CallData::Context] = Runtime::method_popScriptContext(engine);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::pushScriptContext, Assembler::IgnoreResult);
}
void BaselineJIT::generate_PopScriptContext()
@@ -666,7 +626,7 @@ void BaselineJIT::generate_PopScriptContext()
as->prepareCallWithArgCount(2);
as->passEngineAsArg(1);
as->passRegAsArg(0, 0);
- JIT_GENERATE_RUNTIME_CALL(popScriptContextHelper, Assembler::IgnoreResult);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::popScriptContext, Assembler::IgnoreResult);
}
void BaselineJIT::generate_PopContext() { as->popContext(); }
@@ -714,18 +674,6 @@ void BaselineJIT::generate_DestructureRestElement()
as->checkException();
}
-static ReturnedValue deletePropertyHelper(QV4::Function *function, const QV4::Value &base, const QV4::Value &index)
-{
- auto engine = function->internalClass->engine;
- if (!Runtime::method_deleteProperty(engine, base, index)) {
- if (function->isStrict())
- engine->throwTypeError();
- return Encode(false);
- } else {
- return Encode(true);
- }
-}
-
void BaselineJIT::generate_DeleteProperty(int base, int index)
{
STORE_IP();
@@ -733,29 +681,17 @@ void BaselineJIT::generate_DeleteProperty(int base, int index)
as->passRegAsArg(index, 2);
as->passRegAsArg(base, 1);
as->passFunctionAsArg(0);
- JIT_GENERATE_RUNTIME_CALL(deletePropertyHelper, Assembler::ResultInAccumulator);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::deleteProperty, Assembler::ResultInAccumulator);
as->checkException();
}
-static ReturnedValue deleteNameHelper(QV4::Function *function, int name)
-{
- auto engine = function->internalClass->engine;
- if (!Runtime::method_deleteName(engine, name)) {
- if (function->isStrict())
- engine->throwTypeError();
- return Encode(false);
- } else {
- return Encode(true);
- }
-}
-
void BaselineJIT::generate_DeleteName(int name)
{
STORE_IP();
as->prepareCallWithArgCount(2);
as->passInt32AsArg(name, 1);
as->passFunctionAsArg(0);
- JIT_GENERATE_RUNTIME_CALL(deleteNameHelper, Assembler::ResultInAccumulator);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::deleteName, Assembler::ResultInAccumulator);
as->checkException();
}
@@ -838,41 +774,22 @@ void BaselineJIT::generate_CreateRestParameter(int argIndex)
JIT_GENERATE_RUNTIME_CALL(Runtime::method_createRestParameter, Assembler::ResultInAccumulator);
}
-static void convertThisToObjectHelper(ExecutionEngine *engine, Value *t)
-{
- if (!t->isObject()) {
- if (t->isNullOrUndefined()) {
- *t = engine->globalObject->asReturnedValue();
- } else {
- *t = t->toObject(engine)->asReturnedValue();
- }
- }
-}
-
void BaselineJIT::generate_ConvertThisToObject()
{
as->prepareCallWithArgCount(2);
as->passRegAsArg(CallData::This, 1);
as->passEngineAsArg(0);
- JIT_GENERATE_RUNTIME_CALL(convertThisToObjectHelper, Assembler::IgnoreResult);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::convertThisToObject, Assembler::IgnoreResult);
as->checkException();
}
-static ReturnedValue ToObjectHelper(ExecutionEngine *engine, const Value &obj)
-{
- if (obj.isObject())
- return obj.asReturnedValue();
-
- return obj.toObject(engine)->asReturnedValue();
-}
-
void BaselineJIT::generate_ToObject()
{
STORE_ACC();
as->prepareCallWithArgCount(2);
as->passAccumulatorAsArg(1);
as->passEngineAsArg(0);
- JIT_GENERATE_RUNTIME_CALL(ToObjectHelper, Assembler::ResultInAccumulator);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::toObject, Assembler::ResultInAccumulator);
as->checkException();
}
@@ -940,22 +857,13 @@ void BaselineJIT::generate_UShrConst(int rhs) { as->ushrConst(rhs); }
void BaselineJIT::generate_ShrConst(int rhs) { as->shrConst(rhs); }
void BaselineJIT::generate_ShlConst(int rhs) { as->shlConst(rhs); }
-static ReturnedValue expHelper(const Value &base, const Value &exp)
-{
- double b = base.toNumber();
- double e = exp.toNumber();
- if (qIsInf(e) && (b == 1 || b == -1))
- return Encode(qSNaN());
- return Encode(pow(b,e));
-}
-
void BaselineJIT::generate_Exp(int lhs) {
STORE_IP();
STORE_ACC();
as->prepareCallWithArgCount(2);
as->passAccumulatorAsArg(1);
as->passRegAsArg(lhs, 0);
- JIT_GENERATE_RUNTIME_CALL(expHelper, Assembler::ResultInAccumulator);
+ JIT_GENERATE_RUNTIME_CALL(Helpers::exp, Assembler::ResultInAccumulator);
as->checkException();
}
void BaselineJIT::generate_Mul(int lhs) { as->mul(lhs); }
diff --git a/src/qml/jit/qv4jithelpers.cpp b/src/qml/jit/qv4jithelpers.cpp
new file mode 100644
index 0000000000..f644d8c782
--- /dev/null
+++ b/src/qml/jit/qv4jithelpers.cpp
@@ -0,0 +1,153 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv4jithelpers_p.h"
+#include "qv4engine_p.h"
+#include "qv4function_p.h"
+#include "qv4value_p.h"
+#include "qv4object_p.h"
+#include "qv4lookup_p.h"
+#include <QtCore/private/qnumeric_p.h>
+
+#ifdef V4_ENABLE_JIT
+
+QT_BEGIN_NAMESPACE
+namespace QV4 {
+namespace JIT {
+namespace Helpers {
+
+void convertThisToObject(ExecutionEngine *engine, Value *t)
+{
+ if (!t->isObject()) {
+ if (t->isNullOrUndefined()) {
+ *t = engine->globalObject->asReturnedValue();
+ } else {
+ *t = t->toObject(engine)->asReturnedValue();
+ }
+ }
+}
+
+ReturnedValue loadGlobalLookup(ExecutionEngine *engine, Function *f, int index)
+{
+ Lookup *l = f->compilationUnit->runtimeLookups + index;
+ return l->globalGetter(l, engine);
+}
+
+ReturnedValue toObject(ExecutionEngine *engine, const Value &obj)
+{
+ if (obj.isObject())
+ return obj.asReturnedValue();
+
+ return obj.toObject(engine)->asReturnedValue();
+}
+
+ReturnedValue exp(const Value &base, const Value &exp)
+{
+ double b = base.toNumber();
+ double e = exp.toNumber();
+ if (qt_is_inf(e) && (b == 1 || b == -1))
+ return Encode(qt_snan());
+ return Encode(pow(b,e));
+}
+
+ReturnedValue getLookup(ExecutionEngine *engine, Function *f, int index, const Value &base)
+{
+ Lookup *l = f->compilationUnit->runtimeLookups + index;
+ return l->getter(l, engine, base);
+}
+
+void setLookup(Function *f, int index, Value &base, const Value &value)
+{
+ ExecutionEngine *engine = f->internalClass->engine;
+ QV4::Lookup *l = f->compilationUnit->runtimeLookups + index;
+ if (!l->setter(l, engine, base, value) && f->isStrict())
+ engine->throwTypeError();
+}
+
+void pushBlockContext(Value *stack, int index)
+{
+ ExecutionContext *c = static_cast<ExecutionContext *>(stack + CallData::Context);
+ stack[CallData::Context] = Runtime::method_createBlockContext(c, index);
+}
+
+void cloneBlockContext(Value *contextSlot)
+{
+ *contextSlot = Runtime::method_cloneBlockContext(static_cast<QV4::ExecutionContext *>(contextSlot));
+}
+
+void pushScriptContext(Value *stack, ExecutionEngine *engine, int index)
+{
+ stack[CallData::Context] = Runtime::method_createScriptContext(engine, index);
+}
+
+void popScriptContext(Value *stack, ExecutionEngine *engine)
+{
+ stack[CallData::Context] = Runtime::method_popScriptContext(engine);
+}
+
+ReturnedValue deleteProperty(QV4::Function *function, const QV4::Value &base, const QV4::Value &index)
+{
+ auto engine = function->internalClass->engine;
+ if (!Runtime::method_deleteProperty(engine, base, index)) {
+ if (function->isStrict())
+ engine->throwTypeError();
+ return Encode(false);
+ } else {
+ return Encode(true);
+ }
+}
+
+ReturnedValue deleteName(Function *function, int name)
+{
+ auto engine = function->internalClass->engine;
+ if (!Runtime::method_deleteName(engine, name)) {
+ if (function->isStrict())
+ engine->throwTypeError();
+ return Encode(false);
+ } else {
+ return Encode(true);
+ }
+}
+
+} // Helpers namespace
+} // JIT namespace
+} // QV4 namespace
+QT_END_NAMESPACE
+
+#endif // V4_ENABLE_JIT
diff --git a/src/qml/jit/qv4jithelpers_p.h b/src/qml/jit/qv4jithelpers_p.h
new file mode 100644
index 0000000000..bb10d5722b
--- /dev/null
+++ b/src/qml/jit/qv4jithelpers_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEMPLATE_H
+#define TEMPLATE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qv4global_p.h>
+
+//QT_REQUIRE_CONFIG(qml_jit);
+
+QT_BEGIN_NAMESPACE
+
+namespace QV4 {
+
+#ifdef V4_ENABLE_JIT
+
+namespace JIT {
+namespace Helpers {
+
+void convertThisToObject(ExecutionEngine *engine, Value *t);
+ReturnedValue loadGlobalLookup(ExecutionEngine *engine, Function *f, int index);
+ReturnedValue toObject(ExecutionEngine *engine, const Value &obj);
+ReturnedValue exp(const Value &base, const Value &exp);
+ReturnedValue getLookup(ExecutionEngine *engine, Function *f, int index, const Value &base);
+void setLookup(Function *f, int index, Value &base, const Value &value);
+void pushBlockContext(Value *stack, int index);
+void cloneBlockContext(Value *contextSlot);
+void pushScriptContext(Value *stack, ExecutionEngine *engine, int index);
+void popScriptContext(Value *stack, ExecutionEngine *engine);
+ReturnedValue deleteProperty(QV4::Function *function, const QV4::Value &base, const QV4::Value &index);
+ReturnedValue deleteName(Function *function, int name);
+
+} // Helpers namespace
+} // JIT namespace
+
+#endif // V4_ENABLE_JIT
+
+} // QV4 namespace
+
+QT_END_NAMESPACE
+
+#endif // TEMPLATE_H