aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4bytecodegenerator_p.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-10-09 14:58:01 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2019-01-25 10:26:13 +0000
commit784a55a15ddc65b59cc4709e54453238438eae48 (patch)
tree2903e0c690a8aef0b49f3e5d6c26ef4ac90543aa /src/qml/compiler/qv4bytecodegenerator_p.h
parent923fef3ad3076e337eba4e603a6f759c54cc404c (diff)
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 <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator_p.h')
-rw-r--r--src/qml/compiler/qv4bytecodegenerator_p.h60
1 files changed, 50 insertions, 10 deletions
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 <private/qv4instr_moth_p.h>
+#include <private/qv4compileddata_p.h>
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<int InstrT>
+ void addTracingInstruction(InstrData<InstrT> 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)
@@ -248,6 +258,13 @@ QT_WARNING_POP
void finalize(Compiler::Context *context);
template<int InstrT>
+ Jump addTracingJumpInstruction(InstrData<InstrT> &&data)
+ {
+ data.traceSlot = nextTraceInfo();
+ return addJumpInstruction(data);
+ }
+
+ template<int InstrT>
Jump addJumpInstruction(const InstrData<InstrT> &data)
{
Instr genericInstr;
@@ -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);
};
}