Skip to content

Commit

Permalink
[turbofan] Prepare mechanism to enable TF on language subset.
Browse files Browse the repository at this point in the history
This allows enabling TurboFan on a certain subset of language features
in the AstNumberingVisitor. The heuristics of when to optimize remain
unchanged, only the choice of which optimizing compiler to use changes.

[email protected]
BUG=v8:4131
LOG=N

Review URL: https://codereview.chromium.org/1155503002

Cr-Commit-Position: refs/heads/master@{#28544}
  • Loading branch information
mstarzinger authored and Commit bot committed May 21, 2015
1 parent c9a49da commit 54b34bd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/ast-numbering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class AstNumberingVisitor final : public AstVisitor {
dont_optimize_reason_ = reason;
DisableSelfOptimization();
}
void DisableCrankshaft(BailoutReason reason) {
if (FLAG_turbo_shipping) {
return properties_.flags()->Add(kDontCrankshaft);
}
dont_optimize_reason_ = reason;
DisableSelfOptimization();
}
void DisableCaching(BailoutReason reason) {
dont_optimize_reason_ = reason;
DisableSelfOptimization();
Expand Down Expand Up @@ -148,7 +155,7 @@ void AstNumberingVisitor::VisitRegExpLiteral(RegExpLiteral* node) {
void AstNumberingVisitor::VisitVariableProxy(VariableProxy* node) {
IncrementNodeCount();
if (node->var()->IsLookupSlot()) {
DisableOptimization(kReferenceToAVariableWhichRequiresDynamicLookup);
DisableCrankshaft(kReferenceToAVariableWhichRequiresDynamicLookup);
}
ReserveFeedbackSlots(node);
node->set_base_id(ReserveIdRange(VariableProxy::num_ids()));
Expand Down Expand Up @@ -249,7 +256,7 @@ void AstNumberingVisitor::VisitCallRuntime(CallRuntime* node) {

void AstNumberingVisitor::VisitWithStatement(WithStatement* node) {
IncrementNodeCount();
DisableOptimization(kWithStatement);
DisableCrankshaft(kWithStatement);
node->set_base_id(ReserveIdRange(WithStatement::num_ids()));
Visit(node->expression());
Visit(node->statement());
Expand Down Expand Up @@ -344,7 +351,7 @@ void AstNumberingVisitor::VisitForInStatement(ForInStatement* node) {

void AstNumberingVisitor::VisitForOfStatement(ForOfStatement* node) {
IncrementNodeCount();
DisableOptimization(kForOfStatement);
DisableCrankshaft(kForOfStatement);
node->set_base_id(ReserveIdRange(ForOfStatement::num_ids()));
Visit(node->assign_iterator());
Visit(node->next_result());
Expand Down Expand Up @@ -511,7 +518,7 @@ bool AstNumberingVisitor::Renumber(FunctionLiteral* node) {
}
if (scope->calls_eval()) DisableOptimization(kFunctionCallsEval);
if (scope->arguments() != NULL && !scope->arguments()->IsStackAllocated()) {
DisableOptimization(kContextAllocatedArguments);
DisableCrankshaft(kContextAllocatedArguments);
}

VisitDeclarations(scope->declarations());
Expand Down
1 change: 1 addition & 0 deletions src/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ typedef ZoneList<Handle<Object> > ZoneObjectList;
enum AstPropertiesFlag {
kDontSelfOptimize,
kDontSoftInline,
kDontCrankshaft,
kDontCache
};

Expand Down
5 changes: 4 additions & 1 deletion src/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
DCHECK(info()->shared_info()->has_deoptimization_support());

// Check the enabling conditions for TurboFan.
bool dont_crankshaft = info()->shared_info()->dont_crankshaft();
if (((FLAG_turbo_asm && info()->shared_info()->asm_function()) ||
(dont_crankshaft && strcmp(FLAG_turbo_filter, "~~") == 0) ||
info()->closure()->PassesFilter(FLAG_turbo_filter)) &&
(FLAG_turbo_osr || !info()->is_osr())) {
// Use TurboFan for the compilation.
Expand Down Expand Up @@ -405,7 +407,7 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
}
}

if (!isolate()->use_crankshaft()) {
if (!isolate()->use_crankshaft() || dont_crankshaft) {
// Crankshaft is entirely disabled.
return SetLastStatus(FAILED);
}
Expand Down Expand Up @@ -741,6 +743,7 @@ static bool Renumber(ParseInfo* parse_info) {
FunctionLiteral* lit = parse_info->function();
shared_info->set_ast_node_count(lit->ast_node_count());
MaybeDisableOptimization(shared_info, lit->dont_optimize_reason());
shared_info->set_dont_crankshaft(lit->flags()->Contains(kDontCrankshaft));
shared_info->set_dont_cache(lit->flags()->Contains(kDontCache));
}
return true;
Expand Down
1 change: 1 addition & 0 deletions src/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ DEFINE_BOOL(omit_map_checks_for_leaf_maps, true,

// Flags for TurboFan.
DEFINE_BOOL(turbo, false, "enable TurboFan compiler")
DEFINE_BOOL(turbo_shipping, false, "enable TurboFan compiler on subset")
DEFINE_BOOL(turbo_greedy_regalloc, false, "use the greedy register allocator")
DEFINE_IMPLICATION(turbo, turbo_asm_deoptimization)
DEFINE_STRING(turbo_filter, "~~", "optimization filter for TurboFan compiler")
Expand Down
2 changes: 2 additions & 0 deletions src/objects-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5790,6 +5790,8 @@ BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints,
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, bound, kBoundFunction)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_anonymous, kIsAnonymous)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_function, kIsFunction)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, dont_crankshaft,
kDontCrankshaft)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, dont_cache, kDontCache)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, dont_flush, kDontFlush)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_arrow, kIsArrow)
Expand Down
2 changes: 2 additions & 0 deletions src/objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10869,6 +10869,8 @@ void SharedFunctionInfo::InitFromFunctionLiteral(
if (lit->dont_optimize_reason() != kNoReason) {
shared_info->DisableOptimization(lit->dont_optimize_reason());
}
shared_info->set_dont_crankshaft(
lit->flags()->Contains(AstPropertiesFlag::kDontCrankshaft));
shared_info->set_dont_cache(
lit->flags()->Contains(AstPropertiesFlag::kDontCache));
shared_info->set_kind(lit->kind());
Expand Down
4 changes: 4 additions & 0 deletions src/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -7134,6 +7134,9 @@ class SharedFunctionInfo: public HeapObject {
// Is this a function or top-level/eval code.
DECL_BOOLEAN_ACCESSORS(is_function)

// Indicates that code for this function cannot be compiled with Crankshaft.
DECL_BOOLEAN_ACCESSORS(dont_crankshaft)

// Indicates that code for this function cannot be cached.
DECL_BOOLEAN_ACCESSORS(dont_cache)

Expand Down Expand Up @@ -7398,6 +7401,7 @@ class SharedFunctionInfo: public HeapObject {
kIsAnonymous,
kNameShouldPrintAsAnonymous,
kIsFunction,
kDontCrankshaft,
kDontCache,
kDontFlush,
kIsArrow,
Expand Down

0 comments on commit 54b34bd

Please sign in to comment.