aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4jsir_p.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2014-04-30 15:38:01 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-23 12:23:32 +0200
commit75c22465cf8fe262edfe6178bb9ca19661fb710e (patch)
tree69da4cbb16124ae88678f96ca3e37b76851e72f0 /src/qml/compiler/qv4jsir_p.h
parente950557e1133e8aac65a453597ab35400a5b9a10 (diff)
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/compiler/qv4jsir_p.h')
-rw-r--r--src/qml/compiler/qv4jsir_p.h78
1 files changed, 56 insertions, 22 deletions
diff --git a/src/qml/compiler/qv4jsir_p.h b/src/qml/compiler/qv4jsir_p.h
index 2940fd50f4..2551c3d275 100644
--- a/src/qml/compiler/qv4jsir_p.h
+++ b/src/qml/compiler/qv4jsir_p.h
@@ -108,6 +108,7 @@ struct String;
struct RegExp;
struct Name;
struct Temp;
+struct ArgLocal;
struct Closure;
struct Convert;
struct Unop;
@@ -210,6 +211,7 @@ struct ExprVisitor {
virtual void visitRegExp(RegExp *) = 0;
virtual void visitName(Name *) = 0;
virtual void visitTemp(Temp *) = 0;
+ virtual void visitArgLocal(ArgLocal *) = 0;
virtual void visitClosure(Closure *) = 0;
virtual void visitConvert(Convert *) = 0;
virtual void visitUnop(Unop *) = 0;
@@ -260,6 +262,7 @@ struct Q_AUTOTEST_EXPORT Expr {
virtual RegExp *asRegExp() { return 0; }
virtual Name *asName() { return 0; }
virtual Temp *asTemp() { return 0; }
+ virtual ArgLocal *asArgLocal() { return 0; }
virtual Closure *asClosure() { return 0; }
virtual Convert *asConvert() { return 0; }
virtual Unop *asUnop() { return 0; }
@@ -372,33 +375,21 @@ struct Name: Expr {
struct Q_AUTOTEST_EXPORT Temp: Expr {
enum Kind {
- Formal = 0,
- ScopedFormal,
- Local,
- ScopedLocal,
- VirtualRegister,
+ VirtualRegister = 0,
PhysicalRegister,
StackSlot
};
- unsigned index;
- unsigned scope : 27; // how many scopes outside the current one?
- unsigned kind : 3;
- unsigned isArgumentsOrEval : 1;
- unsigned isReadOnly : 1;
+ unsigned index : 28;
+ unsigned kind : 3;
+ unsigned isReadOnly : 1;
// Used when temp is used as base in member expression
MemberExpressionResolver memberResolver;
- void init(unsigned kind, unsigned index, unsigned scope)
+ void init(unsigned kind, unsigned index)
{
- Q_ASSERT((kind == ScopedLocal && scope != 0) ||
- (kind == ScopedFormal && scope != 0) ||
- (scope == 0));
-
this->kind = kind;
this->index = index;
- this->scope = scope;
- this->isArgumentsOrEval = false;
this->isReadOnly = false;
}
@@ -408,16 +399,49 @@ struct Q_AUTOTEST_EXPORT Temp: Expr {
};
inline bool operator==(const Temp &t1, const Temp &t2) Q_DECL_NOTHROW
-{ return t1.index == t2.index && t1.scope == t2.scope && t1.kind == t2.kind && t1.type == t2.type; }
+{ return t1.index == t2.index && t1.kind == t2.kind && t1.type == t2.type; }
inline bool operator!=(const Temp &t1, const Temp &t2) Q_DECL_NOTHROW
{ return !(t1 == t2); }
inline uint qHash(const Temp &t, uint seed = 0) Q_DECL_NOTHROW
-{ return t.index ^ (t.kind | (t.scope << 3)) ^ seed; }
+{ return t.index ^ t.kind ^ seed; }
bool operator<(const Temp &t1, const Temp &t2) Q_DECL_NOTHROW;
+struct Q_AUTOTEST_EXPORT ArgLocal: Expr {
+ enum Kind {
+ Formal = 0,
+ ScopedFormal,
+ Local,
+ ScopedLocal
+ };
+
+ unsigned index;
+ unsigned scope : 29; // how many scopes outside the current one?
+ unsigned kind : 2;
+ unsigned isArgumentsOrEval : 1;
+
+ void init(unsigned kind, unsigned index, unsigned scope)
+ {
+ Q_ASSERT((kind == ScopedLocal && scope != 0) ||
+ (kind == ScopedFormal && scope != 0) ||
+ (scope == 0));
+
+ this->kind = kind;
+ this->index = index;
+ this->scope = scope;
+ this->isArgumentsOrEval = false;
+ }
+
+ virtual void accept(ExprVisitor *v) { v->visitArgLocal(this); }
+ virtual bool isLValue() { return true; }
+ virtual ArgLocal *asArgLocal() { return this; }
+
+ bool operator==(const ArgLocal &other) const
+ { return index == other.index && scope == other.scope && kind == other.kind; }
+};
+
struct Closure: Expr {
int value; // index in _module->functions
const QString *functionName;
@@ -797,8 +821,8 @@ public:
unsigned newTemp();
Temp *TEMP(unsigned kind);
- Temp *ARG(unsigned index, unsigned scope);
- Temp *LOCAL(unsigned index, unsigned scope);
+ ArgLocal *ARG(unsigned index, unsigned scope);
+ ArgLocal *LOCAL(unsigned index, unsigned scope);
Expr *CONST(Type type, double value);
Expr *STRING(const QString *value);
@@ -1040,12 +1064,20 @@ public:
static Temp *cloneTemp(Temp *t, Function *f)
{
Temp *newTemp = f->New<Temp>();
- newTemp->init(t->kind, t->index, t->scope);
+ newTemp->init(t->kind, t->index);
newTemp->type = t->type;
newTemp->memberResolver = t->memberResolver;
return newTemp;
}
+ static ArgLocal *cloneArgLocal(ArgLocal *argLocal, Function *f)
+ {
+ ArgLocal *newArgLocal = f->New<ArgLocal>();
+ newArgLocal->init(argLocal->kind, argLocal->index, argLocal->scope);
+ newArgLocal->type = argLocal->type;
+ return newArgLocal;
+ }
+
protected:
IR::ExprList *clone(IR::ExprList *list);
@@ -1054,6 +1086,7 @@ protected:
virtual void visitRegExp(RegExp *);
virtual void visitName(Name *);
virtual void visitTemp(Temp *);
+ virtual void visitArgLocal(ArgLocal *);
virtual void visitClosure(Closure *);
virtual void visitConvert(Convert *);
virtual void visitUnop(Unop *);
@@ -1093,6 +1126,7 @@ public:
virtual void visitRegExp(RegExp *e);
virtual void visitName(Name *e);
virtual void visitTemp(Temp *e);
+ virtual void visitArgLocal(ArgLocal *e);
virtual void visitClosure(Closure *e);
virtual void visitConvert(Convert *e);
virtual void visitUnop(Unop *e);