Get rid of the QV4::Function in the masm isel
authorSimon Hausmann <simon.hausmann@digia.com>
Fri, 16 Aug 2013 13:24:35 +0000 (15:24 +0200)
committerLars Knoll <lars.knoll@digia.com>
Fri, 16 Aug 2013 14:53:37 +0000 (16:53 +0200)
Change-Id: Ide70ca5a3f3dcc793fb96fd64f8b8df6b07d1168
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/compiler/qv4compileddata_p.h
src/qml/compiler/qv4isel_masm.cpp
src/qml/compiler/qv4isel_masm_p.h
src/qml/jsruntime/qv4function.cpp
src/qml/jsruntime/qv4function_p.h

index f050c4c..b2bc25b 100644 (file)
@@ -178,7 +178,6 @@ struct Function
         IsNamedExpression   = 0x8
     };
 
-    QV4::Value (*code)(ExecutionContext *, const uchar *);
     quint32 index; // in CompilationUnit's function table
     quint32 nameIndex;
     qint64 flags;
index 8e7d7a1..bd78256 100644 (file)
@@ -74,7 +74,11 @@ QV4::Function *CompilationUnit::linkBackendToEngine(ExecutionEngine *engine)
         QV4::Function *runtimeFunction = runtimeFunctions.at(i);
         const CompiledData::Function *compiledFunction = data->functionAt(i);
 
-        runtimeFunction->init(this, compiledFunction);
+        runtimeFunction->init(this, compiledFunction,
+                              (Value (*)(QV4::ExecutionContext *, const uchar *)) codeRefs[i].code().executableAddress(),
+                              codeRefs[i].size());
+
+        UnwindHelper::registerFunction(runtimeFunction);
 
         if (compiledFunction == compiledRootFunction) {
             assert(!rootRuntimeFunction);
@@ -208,8 +212,8 @@ const int Assembler::calleeSavedRegisterCount = sizeof(calleeSavedRegisters) / s
 
 const Assembler::VoidType Assembler::Void;
 
-Assembler::Assembler(InstructionSelection *isel, V4IR::Function* function, QV4::Function *vmFunction, QV4::ExecutionEngine *engine)
-    : _function(function), _vmFunction(vmFunction), _isel(isel), _engine(engine), _nextBlock(0)
+Assembler::Assembler(InstructionSelection *isel, V4IR::Function* function, QV4::ExecutionEngine *engine)
+    : _function(function), _isel(isel), _engine(engine), _nextBlock(0)
 {
 }
 
@@ -531,8 +535,7 @@ void Assembler::generateBinOp(V4IR::AluOp operation, V4IR::Temp* target, V4IR::T
         binOpFinished.link(this);
 }
 #if OS(LINUX) || OS(MAC_OS_X)
-static void printDisassembledOutputWithCalls(const char* output, const QHash<void*, const char*>& functions,
-                                             const QVector<String*> &identifiers)
+static void printDisassembledOutputWithCalls(const char* output, const QHash<void*, const char*>& functions)
 {
     QByteArray processedOutput(output);
     for (QHash<void*, const char*>::ConstIterator it = functions.begin(), end = functions.end();
@@ -541,13 +544,6 @@ static void printDisassembledOutputWithCalls(const char* output, const QHash<voi
         ptrString.prepend("0x");
         processedOutput = processedOutput.replace(ptrString, it.value());
     }
-    for (QVector<String*>::ConstIterator it = identifiers.begin(), end = identifiers.end();
-         it != end; ++it) {
-        QByteArray ptrString = QByteArray::number(quintptr(*it), 16);
-        ptrString.prepend("0x");
-        QByteArray replacement = "\"" + (*it)->toQString().toUtf8() + "\"";
-        processedOutput = processedOutput.replace(ptrString, replacement);
-    }
     fprintf(stderr, "%s\n", processedOutput.constData());
 }
 #endif
@@ -561,9 +557,8 @@ void Assembler::recordLineNumber(int lineNumber)
 }
 
 
-JSC::MacroAssemblerCodeRef Assembler::link(QV4::Function *vmFunc)
+JSC::MacroAssemblerCodeRef Assembler::link()
 {
-    Label endOfCode = label();
 #if defined(Q_PROCESSOR_ARM) && !defined(Q_OS_IOS)
     // Let the ARM exception table follow right after that
     for (int i = 0, nops = UnwindHelper::unwindInfoSize() / 2; i < nops; ++i)
@@ -584,7 +579,6 @@ JSC::MacroAssemblerCodeRef Assembler::link(QV4::Function *vmFunc)
 
     JSC::JSGlobalData dummy(_engine->executableAllocator);
     JSC::LinkBuffer linkBuffer(dummy, this, 0);
-    vmFunc->codeSize = linkBuffer.offsetOf(endOfCode);
 
     QVector<uint> lineNumberMapping(codeLineNumberMappings.count() * 2);
 
@@ -659,7 +653,7 @@ JSC::MacroAssemblerCodeRef Assembler::link(QV4::Function *vmFunc)
 #  endif
 #  if CPU(X86) || CPU(X86_64)
         QHash<void*, String*> idents;
-        printDisassembledOutputWithCalls(disasmOutput, functions, _vmFunction->identifiers);
+        printDisassembledOutputWithCalls(disasmOutput, functions);
 #  endif
 #  if OS(LINUX)
         free(disasmOutput);
@@ -669,7 +663,6 @@ JSC::MacroAssemblerCodeRef Assembler::link(QV4::Function *vmFunc)
         codeRef = linkBuffer.finalizeCodeWithoutDisassembly();
     }
 
-    vmFunc->code = (Value (*)(QV4::ExecutionContext *, const uchar *)) codeRef.code().executableAddress();
     return codeRef;
 }
 
@@ -677,7 +670,6 @@ InstructionSelection::InstructionSelection(QV4::ExecutionEngine *engine, V4IR::M
     : EvalInstructionSelection(engine, module)
     , _block(0)
     , _function(0)
-    , _vmFunction(0)
     , _as(0)
     , _locals(0)
 {
@@ -694,10 +686,9 @@ void InstructionSelection::run(QV4::Function *vmFunction, V4IR::Function *functi
     QVector<Lookup> lookups;
     QSet<V4IR::BasicBlock*> reentryBlocks;
     qSwap(_function, function);
-    qSwap(_vmFunction, vmFunction);
     qSwap(_reentryBlocks, reentryBlocks);
     Assembler* oldAssembler = _as;
-    _as = new Assembler(this, _function, _vmFunction, engine());
+    _as = new Assembler(this, _function, engine());
 
     V4IR::Optimizer opt(_function);
     opt.run();
@@ -755,12 +746,9 @@ void InstructionSelection::run(QV4::Function *vmFunction, V4IR::Function *functi
         }
     }
 
-    JSC::MacroAssemblerCodeRef codeRef =_as->link(_vmFunction);
+    JSC::MacroAssemblerCodeRef codeRef =_as->link();
     codeRefs[_function] = codeRef;
 
-    UnwindHelper::registerFunction(_vmFunction);
-
-    qSwap(_vmFunction, vmFunction);
     qSwap(_function, function);
     qSwap(_reentryBlocks, reentryBlocks);
     qSwap(_locals, locals);
index 757d50a..35b2345 100644 (file)
@@ -76,7 +76,7 @@ struct CompilationUnit : public QV4::CompiledData::CompilationUnit
 class Assembler : public JSC::MacroAssembler
 {
 public:
-    Assembler(InstructionSelection *isel, V4IR::Function* function, QV4::Function *vmFunction, QV4::ExecutionEngine *engine);
+    Assembler(InstructionSelection *isel, V4IR::Function* function, QV4::ExecutionEngine *engine);
 #if CPU(X86)
 
 #undef VALUE_FITS_IN_REGISTER
@@ -779,13 +779,12 @@ public:
         return Jump();
     }
 
-    JSC::MacroAssemblerCodeRef link(QV4::Function *vmFunc);
+    JSC::MacroAssemblerCodeRef link();
 
     void recordLineNumber(int lineNumber);
 
 private:
     V4IR::Function *_function;
-    QV4::Function *_vmFunction;
     QHash<V4IR::BasicBlock *, Label> _addrs;
     QHash<V4IR::BasicBlock *, QVector<Jump> > _patches;
     QList<CallToLink> _callsToLink;
@@ -944,7 +943,6 @@ private:
 
     V4IR::BasicBlock *_block;
     V4IR::Function* _function;
-    QV4::Function* _vmFunction;
     Assembler* _as;
     QSet<V4IR::BasicBlock*> _reentryBlocks;
     int _locals;
index b814637..3891bb7 100644 (file)
@@ -64,13 +64,17 @@ Function::~Function()
         compilationUnit->deref();
 }
 
-void Function::init(CompiledData::CompilationUnit *unit, const CompiledData::Function *function)
+void Function::init(CompiledData::CompilationUnit *unit, const CompiledData::Function *function, Value (*codePtr)(ExecutionContext *, const uchar *),
+                    quint32 _codeSize)
 {
     Q_ASSERT(!compilationUnit);
     compilationUnit = unit;
     compilationUnit->ref();
     compiledFunction = function;
 
+    code = codePtr;
+    codeSize = _codeSize;
+
     formals.resize(compiledFunction->nFormals);
     const quint32 *formalsIndices = compiledFunction->formalsTable();
     for (int i = 0; i < compiledFunction->nFormals; ++i)
index eacd7d1..cc6491b 100644 (file)
@@ -119,7 +119,8 @@ struct Function {
     ~Function();
 
     // ### Merge with constructor later.
-    void init(CompiledData::CompilationUnit *unit, const CompiledData::Function *function);
+    void init(CompiledData::CompilationUnit *unit, const CompiledData::Function *function,
+              Value (*codePtr)(ExecutionContext *, const uchar *), quint32 _codeSize);
 
     void ref() { ++refCount; }
     void deref() { if (!--refCount) delete this; }