Move constants into the compiled data for the interpreter
authorLars Knoll <lars.knoll@digia.com>
Mon, 28 Oct 2013 21:30:04 +0000 (22:30 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 29 Oct 2013 13:06:08 +0000 (14:06 +0100)
This makes it possible to remove the Value stored as
part of the instruction stream. Reduces the size of the
instruction stream and will allow to optimize Param lookup.

Change-Id: I23dab5dbed76bf8d62df7042934064d4676bc43d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/compiler/qv4instr_moth_p.h
src/qml/compiler/qv4isel_moth.cpp
src/qml/jsruntime/qv4vme_moth.cpp

index f9a46a0..795576b 100644 (file)
@@ -125,29 +125,28 @@ namespace Moth {
 
 struct Param {
     enum {
-        ValueType    = 0,
+        ConstantType    = 0,
         ArgumentType = 1,
         LocalType    = 2,
         TempType     = 3,
         ScopedLocalType  = 4
     };
-    QV4::Primitive value;
     unsigned type  : 3;
     unsigned scope : 29;
     unsigned index;
 
-    bool isValue() const { return type == ValueType; }
+    bool isConstant() const { return type == ConstantType; }
     bool isArgument() const { return type == ArgumentType; }
     bool isLocal() const { return type == LocalType; }
     bool isTemp() const { return type == TempType; }
     bool isScopedLocal() const { return type == ScopedLocalType; }
 
-    static Param createValue(const QV4::Primitive &v)
+    static Param createConstant(int index)
     {
         Param p;
-        p.type = ValueType;
+        p.type = ConstantType;
         p.scope = 0;
-        p.value = v;
+        p.index = index;
         return p;
     }
 
index 835f0a8..295227c 100644 (file)
@@ -774,7 +774,8 @@ void InstructionSelection::callBuiltinDeleteName(const QString &name, V4IR::Temp
 void InstructionSelection::callBuiltinDeleteValue(V4IR::Temp *result)
 {
     Instruction::LoadValue load;
-    load.value = Param::createValue(QV4::Primitive::fromBoolean(false));
+    int idx = jsUnitGenerator()->registerConstant(QV4::Encode(false));
+    load.value = Param::createConstant(idx);
     load.result = getResultParam(result);
     addInstruction(load);
 }
@@ -797,7 +798,8 @@ void InstructionSelection::callBuiltinReThrow()
         _patches[_block->catchBlock].append(loc);
     } else {
         Instruction::Ret ret;
-        ret.result = Param::createValue(QV4::Primitive::undefinedValue());
+        int idx = jsUnitGenerator()->registerConstant(QV4::Encode::undefined());
+        ret.result = Param::createConstant(idx);
         addInstruction(ret);
     }
 }
@@ -988,7 +990,8 @@ Param InstructionSelection::getParam(V4IR::Expr *e) {
     assert(e);
 
     if (V4IR::Const *c = e->asConst()) {
-        return Param::createValue(convertToValue(c));
+        int idx = jsUnitGenerator()->registerConstant(convertToValue(c).asReturnedValue());
+        return Param::createConstant(idx);
     } else if (V4IR::Temp *t = e->asTemp()) {
         switch (t->kind) {
         case V4IR::Temp::Formal:
index 2408ba3..a36d1d8 100644 (file)
@@ -134,7 +134,7 @@ static VMStats vmStats;
 #endif // WITH_STATS
 
 static inline QV4::Value *getValueRef(QV4::ExecutionContext *context,
-                                     QV4::SafeValue* stack,
+                                      QV4::SafeValue* stack,
                                      const Param &param
 #if !defined(QT_NO_DEBUG)
                                      , unsigned stackSize
@@ -157,9 +157,10 @@ static inline QV4::Value *getValueRef(QV4::ExecutionContext *context,
     }
 #endif // DO_TRACE_INSTR
 
-    if (param.isValue()) {
+    if (param.isConstant()) {
         VMSTATS(paramIsValue);
-        return const_cast<QV4::Value *>(&static_cast<const QV4::Value &>(param.value));
+        const QV4::SafeValue *v = context->compilationUnit->data->constants() + param.index;
+        return const_cast<QV4::SafeValue *>(v);
     } else if (param.isArgument()) {
         VMSTATS(paramIsArg);
         QV4::ExecutionContext *c = context;