diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2014-04-30 15:38:01 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-23 12:23:32 +0200 |
commit | 75c22465cf8fe262edfe6178bb9ca19661fb710e (patch) | |
tree | 69da4cbb16124ae88678f96ca3e37b76851e72f0 /src/qml/jit/qv4assembler.cpp | |
parent | e950557e1133e8aac65a453597ab35400a5b9a10 (diff) | |
download | qtdeclarative-75c22465cf8fe262edfe6178bb9ca19661fb710e.tar.gz |
V4: Split arguments/locals from temps.
There are a couple of reasons to split the temporaries off from the
arguments and locals:
Temporaries are invisible, and changes to them cannot be observed.
On the other hand, arguments and locals are visible, and writes to them
can be seen from other places (nested functions), or by using the
arguments array. So, in practice these correspond to memory locations.
(One could argue that if neither nested functions, nor eval(), nor
arguments[] is used, the loads/stores are invisible too. But that's an
optimization, and changing locals/arguments to temporaries can be done
in a separate pass.)
Because of the "volatile" nature of arguments and locals, their usage
cannot be optimized. All optimizations (SSA construction, register
allocation, copy elimination, etc.) work on temporaries. Being able to
easily ignore all non-temporaries has the benefit that optimizations can
be faster.
Previously, Temps were not uniquely numbered: argument 1, local 1, and
temporary 1 all had the same number and were distinguishable by their
type. So, for any mapping from Temp to something else, a QHash was used.
Now that Temps only hold proper temporaries, the indexes do uniquely
identify them. Add to that the fact that after transforming to SSA form
all temporaries are renumbered starting from 0 and without any holes in
the numbering, many of those datastructures can be changed to simple
vectors. That change gives a noticeable performance improvement.
One implication of this change is that a number of functions that took
a Temp as their argument, now need to take Temp-or-ArgLocal, so Expr.
However, it turns out that there are very few places where that applies,
as many of those places also need to take constants or names. However,
explicitly separating memory loads/stores for arguments/locals from
temporaries adds the benefit that it's now easier to do a peep-hole
optimizer for those load/store operations in the future: when a load is
directly preceded by a store, it can be eliminated if the value is
still available in a temporary.
Change-Id: I4114006b076795d9ea9fe3649cdb3b9d7b7508f0
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jit/qv4assembler.cpp')
-rw-r--r-- | src/qml/jit/qv4assembler.cpp | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/qml/jit/qv4assembler.cpp b/src/qml/jit/qv4assembler.cpp index cd44b537df..f090e7d506 100644 --- a/src/qml/jit/qv4assembler.cpp +++ b/src/qml/jit/qv4assembler.cpp @@ -223,10 +223,27 @@ void Assembler::generateCJumpOnCompare(RelationalCondition cond, RegisterID left } } -Assembler::Pointer Assembler::loadTempAddress(RegisterID baseReg, IR::Temp *t) +Assembler::Pointer Assembler::loadAddress(RegisterID tmp, IR::Expr *e) +{ + IR::Temp *t = e->asTemp(); + if (t) + return loadTempAddress(t); + else + return loadArgLocalAddress(tmp, e->asArgLocal()); +} + +Assembler::Pointer Assembler::loadTempAddress(IR::Temp *t) +{ + if (t->kind == IR::Temp::StackSlot) + return stackSlotPointer(t); + else + Q_UNREACHABLE(); +} + +Assembler::Pointer Assembler::loadArgLocalAddress(RegisterID baseReg, IR::ArgLocal *al) { int32_t offset = 0; - int scope = t->scope; + int scope = al->scope; RegisterID context = ContextRegister; if (scope) { loadPtr(Address(ContextRegister, qOffsetOf(ExecutionContext, outer)), baseReg); @@ -237,19 +254,16 @@ Assembler::Pointer Assembler::loadTempAddress(RegisterID baseReg, IR::Temp *t) --scope; } } - switch (t->kind) { - case IR::Temp::Formal: - case IR::Temp::ScopedFormal: { + switch (al->kind) { + case IR::ArgLocal::Formal: + case IR::ArgLocal::ScopedFormal: { loadPtr(Address(context, qOffsetOf(ExecutionContext, callData)), baseReg); - offset = sizeof(CallData) + (t->index - 1) * sizeof(Value); + offset = sizeof(CallData) + (al->index - 1) * sizeof(Value); } break; - case IR::Temp::Local: - case IR::Temp::ScopedLocal: { + case IR::ArgLocal::Local: + case IR::ArgLocal::ScopedLocal: { loadPtr(Address(context, qOffsetOf(CallContext, locals)), baseReg); - offset = t->index * sizeof(Value); - } break; - case IR::Temp::StackSlot: { - return stackSlotPointer(t); + offset = al->index * sizeof(Value); } break; default: Q_UNREACHABLE(); @@ -273,9 +287,9 @@ void Assembler::loadStringRef(RegisterID reg, const QString &string) addPtr(TrustedImmPtr(id * sizeof(QV4::StringValue)), reg); } -void Assembler::storeValue(QV4::Primitive value, IR::Temp* destination) +void Assembler::storeValue(QV4::Primitive value, IR::Expr *destination) { - Address addr = loadTempAddress(ScratchRegister, destination); + Address addr = loadAddress(ScratchRegister, destination); storeValue(value, addr); } @@ -347,13 +361,12 @@ Assembler::Jump Assembler::genTryDoubleConversion(IR::Expr *src, Assembler::FPRe break; } - IR::Temp *sourceTemp = src->asTemp(); - Q_ASSERT(sourceTemp); + Q_ASSERT(src->asTemp() || src->asArgLocal()); // It's not a number type, so it cannot be in a register. - Q_ASSERT(sourceTemp->kind != IR::Temp::PhysicalRegister || sourceTemp->type == IR::BoolType); + Q_ASSERT(src->asArgLocal() || src->asTemp()->kind != IR::Temp::PhysicalRegister || src->type == IR::BoolType); - Assembler::Pointer tagAddr = loadTempAddress(Assembler::ScratchRegister, sourceTemp); + Assembler::Pointer tagAddr = loadAddress(Assembler::ScratchRegister, src); tagAddr.offset += 4; load32(tagAddr, Assembler::ScratchRegister); |