Commit 60247ea2 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[turbofan] maintain source positions in loop peeling and polymorphic inlining

I also used the opportunity to clean up the loop peeler a bit by making the
class stateful, to avoid passing long argument lists around.

Bug: v8:5864
Change-Id: I2e034c6eabd381b01e15cf3e6aa3ce7b14e7b3d8
Reviewed-on: https://chromium-review.googlesource.com/822933
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50067}
parent 1edca59f
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "src/compilation-info.h" #include "src/compilation-info.h"
#include "src/compiler/common-operator.h" #include "src/compiler/common-operator.h"
#include "src/compiler/compiler-source-position-table.h"
#include "src/compiler/node-matchers.h" #include "src/compiler/node-matchers.h"
#include "src/compiler/simplified-operator.h" #include "src/compiler/simplified-operator.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
...@@ -556,6 +557,8 @@ void JSInliningHeuristic::CreateOrReuseDispatch(Node* node, Node* callee, ...@@ -556,6 +557,8 @@ void JSInliningHeuristic::CreateOrReuseDispatch(Node* node, Node* callee,
Node** if_successes, Node** if_successes,
Node** calls, Node** inputs, Node** calls, Node** inputs,
int input_count) { int input_count) {
SourcePositionTable::Scope position(
source_positions_, source_positions_->GetSourcePosition(node));
if (TryReuseDispatch(node, callee, candidate, if_successes, calls, inputs, if (TryReuseDispatch(node, callee, candidate, if_successes, calls, inputs,
input_count)) { input_count)) {
return; return;
......
...@@ -22,6 +22,7 @@ class JSInliningHeuristic final : public AdvancedReducer { ...@@ -22,6 +22,7 @@ class JSInliningHeuristic final : public AdvancedReducer {
inliner_(editor, local_zone, info, jsgraph, source_positions), inliner_(editor, local_zone, info, jsgraph, source_positions),
candidates_(local_zone), candidates_(local_zone),
seen_(local_zone), seen_(local_zone),
source_positions_(source_positions),
jsgraph_(jsgraph) {} jsgraph_(jsgraph) {}
const char* reducer_name() const override { return "JSInliningHeuristic"; } const char* reducer_name() const override { return "JSInliningHeuristic"; }
...@@ -85,6 +86,7 @@ class JSInliningHeuristic final : public AdvancedReducer { ...@@ -85,6 +86,7 @@ class JSInliningHeuristic final : public AdvancedReducer {
JSInliner inliner_; JSInliner inliner_;
Candidates candidates_; Candidates candidates_;
ZoneSet<NodeId> seen_; ZoneSet<NodeId> seen_;
SourcePositionTable* source_positions_;
JSGraph* const jsgraph_; JSGraph* const jsgraph_;
int cumulative_count_ = 0; int cumulative_count_ = 0;
}; };
......
This diff is collapsed.
...@@ -13,6 +13,8 @@ namespace v8 { ...@@ -13,6 +13,8 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
class SourcePositionTable;
// Represents the output of peeling a loop, which is basically the mapping // Represents the output of peeling a loop, which is basically the mapping
// from the body of the loop to the corresponding nodes in the peeled // from the body of the loop to the corresponding nodes in the peeled
// iteration. // iteration.
...@@ -31,15 +33,28 @@ class CommonOperatorBuilder; ...@@ -31,15 +33,28 @@ class CommonOperatorBuilder;
// Implements loop peeling. // Implements loop peeling.
class V8_EXPORT_PRIVATE LoopPeeler { class V8_EXPORT_PRIVATE LoopPeeler {
public: public:
static bool CanPeel(LoopTree* loop_tree, LoopTree::Loop* loop); LoopPeeler(Graph* graph, CommonOperatorBuilder* common, LoopTree* loop_tree,
static PeeledIteration* Peel(Graph* graph, CommonOperatorBuilder* common, Zone* tmp_zone, SourcePositionTable* source_positions)
LoopTree* loop_tree, LoopTree::Loop* loop, : graph_(graph),
Zone* tmp_zone); common_(common),
static void PeelInnerLoopsOfTree(Graph* graph, CommonOperatorBuilder* common, loop_tree_(loop_tree),
LoopTree* loop_tree, Zone* tmp_zone); tmp_zone_(tmp_zone),
source_positions_(source_positions) {}
static void EliminateLoopExits(Graph* graph, Zone* temp_zone); bool CanPeel(LoopTree::Loop* loop);
PeeledIteration* Peel(LoopTree::Loop* loop);
void PeelInnerLoopsOfTree();
static void EliminateLoopExits(Graph* graph, Zone* tmp_zone);
static const size_t kMaxPeeledNodes = 1000; static const size_t kMaxPeeledNodes = 1000;
private:
Graph* const graph_;
CommonOperatorBuilder* const common_;
LoopTree* const loop_tree_;
Zone* const tmp_zone_;
SourcePositionTable* const source_positions_;
void PeelInnerLoops(LoopTree::Loop* loop);
}; };
......
...@@ -1268,8 +1268,9 @@ struct LoopPeelingPhase { ...@@ -1268,8 +1268,9 @@ struct LoopPeelingPhase {
LoopTree* loop_tree = LoopTree* loop_tree =
LoopFinder::BuildLoopTree(data->jsgraph()->graph(), temp_zone); LoopFinder::BuildLoopTree(data->jsgraph()->graph(), temp_zone);
LoopPeeler::PeelInnerLoopsOfTree(data->graph(), data->common(), loop_tree, LoopPeeler(data->graph(), data->common(), loop_tree, temp_zone,
temp_zone); data->source_positions())
.PeelInnerLoopsOfTree();
} }
}; };
......
...@@ -17,7 +17,8 @@ GraphTest::GraphTest(int num_parameters) ...@@ -17,7 +17,8 @@ GraphTest::GraphTest(int num_parameters)
: TestWithNativeContext(), : TestWithNativeContext(),
TestWithIsolateAndZone(), TestWithIsolateAndZone(),
common_(zone()), common_(zone()),
graph_(zone()) { graph_(zone()),
source_positions_(&graph_) {
graph()->SetStart(graph()->NewNode(common()->Start(num_parameters))); graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
graph()->SetEnd(graph()->NewNode(common()->End(1), graph()->start())); graph()->SetEnd(graph()->NewNode(common()->End(1), graph()->start()));
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_ #define V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
#include "src/compiler/common-operator.h" #include "src/compiler/common-operator.h"
#include "src/compiler/compiler-source-position-table.h"
#include "src/compiler/graph.h" #include "src/compiler/graph.h"
#include "src/compiler/typer.h" #include "src/compiler/typer.h"
#include "test/unittests/test-utils.h" #include "test/unittests/test-utils.h"
...@@ -58,10 +59,12 @@ class GraphTest : public virtual TestWithNativeContext, ...@@ -58,10 +59,12 @@ class GraphTest : public virtual TestWithNativeContext,
CommonOperatorBuilder* common() { return &common_; } CommonOperatorBuilder* common() { return &common_; }
Graph* graph() { return &graph_; } Graph* graph() { return &graph_; }
SourcePositionTable* source_positions() { return &source_positions_; }
private: private:
CommonOperatorBuilder common_; CommonOperatorBuilder common_;
Graph graph_; Graph graph_;
SourcePositionTable source_positions_;
}; };
......
...@@ -74,14 +74,14 @@ class LoopPeelingTest : public GraphTest { ...@@ -74,14 +74,14 @@ class LoopPeelingTest : public GraphTest {
PeeledIteration* PeelOne() { PeeledIteration* PeelOne() {
LoopTree* loop_tree = GetLoopTree(); LoopTree* loop_tree = GetLoopTree();
LoopTree::Loop* loop = loop_tree->outer_loops()[0]; LoopTree::Loop* loop = loop_tree->outer_loops()[0];
EXPECT_TRUE(LoopPeeler::CanPeel(loop_tree, loop)); LoopPeeler peeler(graph(), common(), loop_tree, zone(), source_positions());
return Peel(loop_tree, loop); EXPECT_TRUE(peeler.CanPeel(loop));
return Peel(peeler, loop);
} }
PeeledIteration* Peel(LoopTree* loop_tree, LoopTree::Loop* loop) { PeeledIteration* Peel(LoopPeeler peeler, LoopTree::Loop* loop) {
EXPECT_TRUE(LoopPeeler::CanPeel(loop_tree, loop)); EXPECT_TRUE(peeler.CanPeel(loop));
PeeledIteration* peeled = PeeledIteration* peeled = peeler.Peel(loop);
LoopPeeler::Peel(graph(), common(), loop_tree, loop, zone());
if (FLAG_trace_turbo_graph) { if (FLAG_trace_turbo_graph) {
OFStream os(stdout); OFStream os(stdout);
os << AsRPO(*graph()); os << AsRPO(*graph());
...@@ -250,7 +250,8 @@ TEST_F(LoopPeelingTest, SimpleNestedLoopWithCounter_peel_inner) { ...@@ -250,7 +250,8 @@ TEST_F(LoopPeelingTest, SimpleNestedLoopWithCounter_peel_inner) {
EXPECT_NE(nullptr, loop); EXPECT_NE(nullptr, loop);
EXPECT_EQ(1u, loop->depth()); EXPECT_EQ(1u, loop->depth());
PeeledIteration* peeled = Peel(loop_tree, loop); LoopPeeler peeler(graph(), common(), loop_tree, zone(), source_positions());
PeeledIteration* peeled = Peel(peeler, loop);
ExpectNotPeeled(outer.loop, peeled); ExpectNotPeeled(outer.loop, peeled);
ExpectNotPeeled(outer.branch, peeled); ExpectNotPeeled(outer.branch, peeled);
...@@ -289,7 +290,8 @@ TEST_F(LoopPeelingTest, SimpleInnerCounter_peel_inner) { ...@@ -289,7 +290,8 @@ TEST_F(LoopPeelingTest, SimpleInnerCounter_peel_inner) {
EXPECT_NE(nullptr, loop); EXPECT_NE(nullptr, loop);
EXPECT_EQ(1u, loop->depth()); EXPECT_EQ(1u, loop->depth());
PeeledIteration* peeled = Peel(loop_tree, loop); LoopPeeler peeler(graph(), common(), loop_tree, zone(), source_positions());
PeeledIteration* peeled = Peel(peeler, loop);
ExpectNotPeeled(outer.loop, peeled); ExpectNotPeeled(outer.loop, peeled);
ExpectNotPeeled(outer.branch, peeled); ExpectNotPeeled(outer.branch, peeled);
...@@ -517,7 +519,8 @@ TEST_F(LoopPeelingTest, SimpleLoopWithUnmarkedExit) { ...@@ -517,7 +519,8 @@ TEST_F(LoopPeelingTest, SimpleLoopWithUnmarkedExit) {
{ {
LoopTree* loop_tree = GetLoopTree(); LoopTree* loop_tree = GetLoopTree();
LoopTree::Loop* loop = loop_tree->outer_loops()[0]; LoopTree::Loop* loop = loop_tree->outer_loops()[0];
EXPECT_FALSE(LoopPeeler::CanPeel(loop_tree, loop)); LoopPeeler peeler(graph(), common(), loop_tree, zone(), source_positions());
EXPECT_FALSE(peeler.CanPeel(loop));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment