Skip to content

Commit

Permalink
[Perf] Reduce temporary generation
Browse files Browse the repository at this point in the history
Summary:
Fix a few issues:
 - if any child node had a side effect, and produces a temporary anyway, we
would enforce ordering. But this isnt needed for a single child node, and is
counter-productive for eg isset and empty.
 - if we wanted to output a fast-cast, we would force a temporary. But this is
wrong in exist context for ArrayElementExpression and ObjectProperty expression
(the temporary will be evaluated using rvalAt, rather than isset/empty). So in
these cases, we would emit both an rvalAt, and an isset/empty.
 - type inference was wrong for static method calls to non-static functions,
when there is (or might be) no object available (it failed to set
implementedType to Variant, which it needs to because the call will be
dispatched via an invoke helper).

Test Plan: fast_tests slow_tests

Reviewers: myang, qigao

Reviewed By: myang

CC: ps, mwilliams, myang

Differential Revision: 345684
  • Loading branch information
mwilliams authored and macvicar committed Oct 18, 2011
1 parent e0e572e commit 389a833
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/compiler/expression/expression.cpp
Expand Up @@ -961,6 +961,11 @@ bool Expression::preOutputCPP(CodeGenerator &cg, AnalysisResultPtr ar,
return false;
}

bool paramList =
is(KindOfExpressionList) &&
static_cast<ExpressionList*>(this)->getListKind() ==
ExpressionList::ListKindParam;

bool stashAll = state & StashAll;
state &= ~StashAll;
bool doStash = (state & FixOrder) != 0 || needsFastCastTemp(ar);
Expand All @@ -976,7 +981,10 @@ bool Expression::preOutputCPP(CodeGenerator &cg, AnalysisResultPtr ar,
if (k && !k->isScalar()) {
if (k->hasEffect()) {
lastEffect = i;
if (!j && k->isTemporary()) {
if (!j && (n > 1 || paramList) && k->isTemporary() &&
(!k->hasContext(ExistContext) ||
(!k->is(KindOfObjectPropertyExpression) &&
!k->is(KindOfArrayElementExpression)))) {
j++;
}
}
Expand Down Expand Up @@ -1347,6 +1355,11 @@ bool Expression::getTypeCastPtrs(
bool Expression::needsFastCastTemp(AnalysisResultPtr ar) {
if (is(KindOfSimpleVariable)) return false;
if (!canUseFastCast(ar)) return false;
if (hasAnyContext(ExistContext|AccessContext) &&
(is(KindOfObjectPropertyExpression) ||
is(KindOfArrayElementExpression))) {
return false;
}
ASSERT(m_actualType);
return !m_actualType->isPrimitive();
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/expression/simple_function_call.cpp
Expand Up @@ -1126,7 +1126,7 @@ TypePtr SimpleFunctionCall::inferAndCheck(AnalysisResultPtr ar, TypePtr type,
(!m_funcScope || !m_funcScope->isStatic())) {
int objCall = checkObjCall(ar);

if (objCall < 0 || (objCall > 0 && !m_localThis.empty())) {
if (objCall <= 0 || !m_localThis.empty()) {
m_implementedType = Type::Variant;
}
}
Expand Down

0 comments on commit 389a833

Please sign in to comment.