Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Unified Diff: src/compiler/js-inlining.cc

Issue 2216353002: [turbofan] Also inline into try blocks. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@p5-base
Patch Set: Depend on changelist 2245263003 which consists of only the tests. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/js-inlining.h ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-inlining.cc
diff --git a/src/compiler/js-inlining.cc b/src/compiler/js-inlining.cc
index 7aa82c91cb1909c9a5d26a81503dc4699eb86401..5f3bf53da59ef6b34d620fc4915fd397166ce77b 100644
--- a/src/compiler/js-inlining.cc
+++ b/src/compiler/js-inlining.cc
@@ -8,6 +8,7 @@
#include "src/ast/ast.h"
#include "src/ast/scopes.h"
#include "src/compiler.h"
+#include "src/compiler/all-nodes.h"
#include "src/compiler/ast-graph-builder.h"
#include "src/compiler/ast-loop-assignment-analyzer.h"
#include "src/compiler/common-operator.h"
@@ -71,9 +72,10 @@ class JSCallAccessor {
Node* call_;
};
-
Reduction JSInliner::InlineCall(Node* call, Node* new_target, Node* context,
- Node* frame_state, Node* start, Node* end) {
+ Node* frame_state, Node* start, Node* end,
+ Node* exception_target,
+ const NodeVector& uncaught_subcalls) {
// The scheduler is smart enough to place our code; we just ensure {control}
// becomes the control input of the start of the inlinee, and {effect} becomes
// the effect input of the start of the inlinee.
@@ -130,6 +132,44 @@ Reduction JSInliner::InlineCall(Node* call, Node* new_target, Node* context,
}
}
+ if (exception_target != nullptr) {
+ // Link uncaught calls in the inlinee to {exception_target}
+ int subcall_count = static_cast<int>(uncaught_subcalls.size());
+ if (subcall_count > 0) {
+ TRACE(
+ "Inlinee contains %d calls without IfException; "
+ "linking to existing IfException\n",
+ subcall_count);
+ }
+ NodeVector on_exception_nodes(local_zone_);
+ for (Node* subcall : uncaught_subcalls) {
+ Node* on_exception =
+ graph()->NewNode(common()->IfException(), subcall, subcall);
+ on_exception_nodes.push_back(on_exception);
+ }
+
+ DCHECK_EQ(subcall_count, static_cast<int>(on_exception_nodes.size()));
+ if (subcall_count > 0) {
+ Node* control_output =
+ graph()->NewNode(common()->Merge(subcall_count), subcall_count,
+ &on_exception_nodes.front());
+ NodeVector values_effects(local_zone_);
+ values_effects = on_exception_nodes;
+ values_effects.push_back(control_output);
+ Node* value_output = graph()->NewNode(
+ common()->Phi(MachineRepresentation::kTagged, subcall_count),
+ subcall_count + 1, &values_effects.front());
+ Node* effect_output =
+ graph()->NewNode(common()->EffectPhi(subcall_count),
+ subcall_count + 1, &values_effects.front());
+ ReplaceWithValue(exception_target, value_output, effect_output,
+ control_output);
+ } else {
+ ReplaceWithValue(exception_target, exception_target, exception_target,
+ jsgraph()->Dead());
+ }
+ }
+
NodeVector values(local_zone_);
NodeVector effects(local_zone_);
NodeVector controls(local_zone_);
@@ -269,7 +309,6 @@ Reduction JSInliner::Reduce(Node* node) {
return ReduceJSCall(node, function);
}
-
Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
DCHECK(IrOpcode::IsInlineeOpcode(node->opcode()));
JSCallAccessor call(node);
@@ -343,12 +382,25 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
}
}
- // TODO(turbofan): Inlining into a try-block is not yet supported.
- if (NodeProperties::IsExceptionalCall(node)) {
- TRACE("Not inlining %s into %s because of surrounding try-block\n",
- shared_info->DebugName()->ToCString().get(),
- info_->shared_info()->DebugName()->ToCString().get());
- return NoChange();
+ // Find the IfException node, if any.
+ Node* exception_target = nullptr;
+ for (Edge edge : node->use_edges()) {
+ if (NodeProperties::IsControlEdge(edge) &&
+ edge.from()->opcode() == IrOpcode::kIfException) {
+ DCHECK_NULL(exception_target);
+ exception_target = edge.from();
+ }
+ }
+
+ NodeVector uncaught_subcalls(local_zone_);
+
+ if (exception_target != nullptr) {
+ TRACE(
+ "Inlining %s into %s regardless of surrounding try-block to catcher "
+ "#%d:%s\n",
+ shared_info->DebugName()->ToCString().get(),
+ info_->shared_info()->DebugName()->ToCString().get(),
+ exception_target->id(), exception_target->op()->mnemonic());
}
Zone zone(info_->isolate()->allocator());
@@ -415,6 +467,28 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
end = graph()->end();
}
+ if (exception_target != nullptr) {
+ // Find all uncaught 'calls' in the inlinee.
+ AllNodes inlined_nodes(local_zone_, end, graph());
+ for (Node* subnode : inlined_nodes.live) {
+ // Every possibly throwing node with an IfSuccess should get an
+ // IfException.
+ if (subnode->op()->HasProperty(Operator::kNoThrow)) {
+ continue;
+ }
+ bool hasIfException = false;
+ for (Node* use : subnode->uses()) {
+ if (use->opcode() == IrOpcode::kIfException) {
+ hasIfException = true;
Jarin 2016/08/17 11:20:55 break; ?
bgeron 2016/08/18 17:57:25 Done.
+ }
+ }
+ if (!hasIfException) {
+ DCHECK_EQ(2, subnode->op()->ControlOutputCount());
+ uncaught_subcalls.push_back(subnode);
+ }
+ }
+ }
+
Node* frame_state = call.frame_state();
Node* new_target = jsgraph()->UndefinedConstant();
@@ -513,7 +587,8 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
FrameStateType::kArgumentsAdaptor, shared_info);
}
- return InlineCall(node, new_target, context, frame_state, start, end);
+ return InlineCall(node, new_target, context, frame_state, start, end,
+ exception_target, uncaught_subcalls);
}
Graph* JSInliner::graph() const { return jsgraph()->graph(); }
« no previous file with comments | « src/compiler/js-inlining.h ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698