From 784a55a15ddc65b59cc4709e54453238438eae48 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 9 Oct 2018 14:58:01 +0200 Subject: V4: Collect trace information in the interpreter Collect type information about values used in a function. These include all parameters, and the results of many bytecode instructions. For array loads/stores, it also tracks if the access is in-bounds of a SimpleArrayData. Collection is only enabled when the qml-tracing feature is turned on while configuring. In subsequent patches this is used to generated optimized JITted code. Change-Id: I63985c334c3fdc55fca7fb4addfe3e535989aac5 Reviewed-by: Ulf Hermann --- src/qml/compiler/qv4bytecodegenerator_p.h | 60 +++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'src/qml/compiler/qv4bytecodegenerator_p.h') diff --git a/src/qml/compiler/qv4bytecodegenerator_p.h b/src/qml/compiler/qv4bytecodegenerator_p.h index 4f3dc27acc..5a27d3948c 100644 --- a/src/qml/compiler/qv4bytecodegenerator_p.h +++ b/src/qml/compiler/qv4bytecodegenerator_p.h @@ -51,6 +51,7 @@ // We mean it. // #include +#include QT_BEGIN_NAMESPACE @@ -65,6 +66,8 @@ namespace Moth { class BytecodeGenerator { public: + typedef CompiledData::Function::TraceInfoCount TraceInfoCount; + BytecodeGenerator(int line, bool debug) : startLine(line), debugMode(debug) {} @@ -161,6 +164,15 @@ public: addInstructionHelper(Moth::Instr::Type(InstrT), genericInstr); } + // Same as addInstruction, but also add a trace slot. Move only, because the instruction cannot + // be reused afterwards. + template + void addTracingInstruction(InstrData data) + { + data.traceSlot = nextTraceInfo(); + addInstruction(data); + } + Q_REQUIRED_RESULT Jump jump() { QT_WARNING_PUSH @@ -172,14 +184,12 @@ QT_WARNING_POP Q_REQUIRED_RESULT Jump jumpTrue() { - Instruction::JumpTrue data; - return addJumpInstruction(data); + return addTracingJumpInstruction(Instruction::JumpTrue()); } Q_REQUIRED_RESULT Jump jumpFalse() { - Instruction::JumpFalse data; - return addJumpInstruction(data); + return addTracingJumpInstruction(Instruction::JumpFalse()); } Q_REQUIRED_RESULT Jump jumpNotUndefined() @@ -198,16 +208,16 @@ QT_WARNING_POP { Instruction::CmpStrictEqual cmp; cmp.lhs = lhs; - addInstruction(cmp); - addJumpInstruction(Instruction::JumpTrue()).link(target); + addInstruction(std::move(cmp)); + addTracingJumpInstruction(Instruction::JumpTrue()).link(target); } void jumpStrictNotEqual(const StackSlot &lhs, const Label &target) { Instruction::CmpStrictNotEqual cmp; cmp.lhs = lhs; - addInstruction(cmp); - addJumpInstruction(Instruction::JumpTrue()).link(target); + addInstruction(std::move(cmp)); + addTracingJumpInstruction(Instruction::JumpTrue()).link(target); } void setUnwindHandler(ExceptionHandler *handler) @@ -247,6 +257,13 @@ QT_WARNING_POP void finalize(Compiler::Context *context); + template + Jump addTracingJumpInstruction(InstrData &&data) + { + data.traceSlot = nextTraceInfo(); + return addJumpInstruction(data); + } + template Jump addJumpInstruction(const InstrData &data) { @@ -258,9 +275,9 @@ QT_WARNING_POP void addCJumpInstruction(bool jumpOnFalse, const Label *trueLabel, const Label *falseLabel) { if (jumpOnFalse) - addJumpInstruction(Instruction::JumpFalse()).link(*falseLabel); + addTracingJumpInstruction(Instruction::JumpFalse()).link(*falseLabel); else - addJumpInstruction(Instruction::JumpTrue()).link(*trueLabel); + addTracingJumpInstruction(Instruction::JumpTrue()).link(*trueLabel); } void clearLastInstruction() @@ -268,6 +285,27 @@ QT_WARNING_POP lastInstrType = -1; } + TraceInfoCount nextTraceInfo() + { + // If tracing is disabled, use slot 0 to unconditionally store all trace info + if (nTraceInfos == CompiledData::Function::NoTracing()) + return TraceInfoCount(0); + return nTraceInfos++; + } + + void setTracing(bool onoff, int argumentCount) + { + if (onoff) + nTraceInfos = argumentCount; + else + nTraceInfos = CompiledData::Function::NoTracing(); + } + + TraceInfoCount traceInfoCount() const + { + return nTraceInfos; + } + private: friend struct Jump; friend struct Label; @@ -302,6 +340,8 @@ private: int lastInstrType = -1; Moth::Instr lastInstr; + + TraceInfoCount nTraceInfos = TraceInfoCount(0); }; } -- cgit v1.2.3