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 @@
#include "src/compilation-info.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/compiler-source-position-table.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/simplified-operator.h"
#include "src/objects-inl.h"
......@@ -556,6 +557,8 @@ void JSInliningHeuristic::CreateOrReuseDispatch(Node* node, Node* callee,
Node** if_successes,
Node** calls, Node** inputs,
int input_count) {
SourcePositionTable::Scope position(
source_positions_, source_positions_->GetSourcePosition(node));
if (TryReuseDispatch(node, callee, candidate, if_successes, calls, inputs,
input_count)) {
return;
......
......@@ -22,6 +22,7 @@ class JSInliningHeuristic final : public AdvancedReducer {
inliner_(editor, local_zone, info, jsgraph, source_positions),
candidates_(local_zone),
seen_(local_zone),
source_positions_(source_positions),
jsgraph_(jsgraph) {}
const char* reducer_name() const override { return "JSInliningHeuristic"; }
......@@ -85,6 +86,7 @@ class JSInliningHeuristic final : public AdvancedReducer {
JSInliner inliner_;
Candidates candidates_;
ZoneSet<NodeId> seen_;
SourcePositionTable* source_positions_;
JSGraph* const jsgraph_;
int cumulative_count_ = 0;
};
......
This diff is collapsed.
......@@ -13,6 +13,8 @@ namespace v8 {
namespace internal {
namespace compiler {
class SourcePositionTable;
// 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
// iteration.
......@@ -31,15 +33,28 @@ class CommonOperatorBuilder;
// Implements loop peeling.
class V8_EXPORT_PRIVATE LoopPeeler {
public:
static bool CanPeel(LoopTree* loop_tree, LoopTree::Loop* loop);
static PeeledIteration* Peel(Graph* graph, CommonOperatorBuilder* common,
LoopTree* loop_tree, LoopTree::Loop* loop,
Zone* tmp_zone);
static void PeelInnerLoopsOfTree(Graph* graph, CommonOperatorBuilder* common,
LoopTree* loop_tree, Zone* tmp_zone);
static void EliminateLoopExits(Graph* graph, Zone* temp_zone);
LoopPeeler(Graph* graph, CommonOperatorBuilder* common, LoopTree* loop_tree,
Zone* tmp_zone, SourcePositionTable* source_positions)
: graph_(graph),
common_(common),
loop_tree_(loop_tree),
tmp_zone_(tmp_zone),
source_positions_(source_positions) {}
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;
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 {
LoopTree* loop_tree =
LoopFinder::BuildLoopTree(data->jsgraph()->graph(), temp_zone);
LoopPeeler::PeelInnerLoopsOfTree(data->graph(), data->common(), loop_tree,
temp_zone);
LoopPeeler(data->graph(), data->common(), loop_tree, temp_zone,
data->source_positions())
.PeelInnerLoopsOfTree();
}
};
......
......@@ -17,7 +17,8 @@ GraphTest::GraphTest(int num_parameters)
: TestWithNativeContext(),
TestWithIsolateAndZone(),
common_(zone()),
graph_(zone()) {
graph_(zone()),
source_positions_(&graph_) {
graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
graph()->SetEnd(graph()->NewNode(common()->End(1), graph()->start()));
}
......
......@@ -6,6 +6,7 @@
#define V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
#include "src/compiler/common-operator.h"
#include "src/compiler/compiler-source-position-table.h"
#include "src/compiler/graph.h"
#include "src/compiler/typer.h"
#include "test/unittests/test-utils.h"
......@@ -58,10 +59,12 @@ class GraphTest : public virtual TestWithNativeContext,
CommonOperatorBuilder* common() { return &common_; }
Graph* graph() { return &graph_; }
SourcePositionTable* source_positions() { return &source_positions_; }
private:
CommonOperatorBuilder common_;
Graph graph_;
SourcePositionTable source_positions_;
};
......
......@@ -74,14 +74,14 @@ class LoopPeelingTest : public GraphTest {
PeeledIteration* PeelOne() {
LoopTree* loop_tree = GetLoopTree();
LoopTree::Loop* loop = loop_tree->outer_loops()[0];
EXPECT_TRUE(LoopPeeler::CanPeel(loop_tree, loop));
return Peel(loop_tree, loop);
LoopPeeler peeler(graph(), common(), loop_tree, zone(), source_positions());
EXPECT_TRUE(peeler.CanPeel(loop));
return Peel(peeler, loop);
}
PeeledIteration* Peel(LoopTree* loop_tree, LoopTree::Loop* loop) {
EXPECT_TRUE(LoopPeeler::CanPeel(loop_tree, loop));
PeeledIteration* peeled =
LoopPeeler::Peel(graph(), common(), loop_tree, loop, zone());
PeeledIteration* Peel(LoopPeeler peeler, LoopTree::Loop* loop) {
EXPECT_TRUE(peeler.CanPeel(loop));
PeeledIteration* peeled = peeler.Peel(loop);
if (FLAG_trace_turbo_graph) {
OFStream os(stdout);
os << AsRPO(*graph());
......@@ -250,7 +250,8 @@ TEST_F(LoopPeelingTest, SimpleNestedLoopWithCounter_peel_inner) {
EXPECT_NE(nullptr, loop);
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.branch, peeled);
......@@ -289,7 +290,8 @@ TEST_F(LoopPeelingTest, SimpleInnerCounter_peel_inner) {
EXPECT_NE(nullptr, loop);
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.branch, peeled);
......@@ -517,7 +519,8 @@ TEST_F(LoopPeelingTest, SimpleLoopWithUnmarkedExit) {
{
LoopTree* loop_tree = GetLoopTree();
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