Commit f184ff06 authored by danno's avatar danno Committed by Commit bot

[turbofan]: Improved source position information

Make sure the initial graph is fully populated with source position information and automatically propagate that information down through newly allocated nodes during reduction passes in the most unobtrusive way that's currently possible.

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

Cr-Commit-Position: refs/heads/master@{#26459}
parent df986d08
...@@ -22,8 +22,10 @@ Graph::Graph(Zone* zone) ...@@ -22,8 +22,10 @@ Graph::Graph(Zone* zone)
decorators_(zone) {} decorators_(zone) {}
void Graph::Decorate(Node* node) { void Graph::Decorate(Node* node, bool incomplete) {
for (auto const decorator : decorators_) decorator->Decorate(node); for (auto const decorator : decorators_) {
decorator->Decorate(node, incomplete);
}
} }
...@@ -44,7 +46,7 @@ Node* Graph::NewNode(const Operator* op, int input_count, Node** inputs, ...@@ -44,7 +46,7 @@ Node* Graph::NewNode(const Operator* op, int input_count, Node** inputs,
DCHECK_LE(op->ValueInputCount(), input_count); DCHECK_LE(op->ValueInputCount(), input_count);
Node* const node = Node* const node =
Node::New(zone(), NextNodeId(), op, input_count, inputs, incomplete); Node::New(zone(), NextNodeId(), op, input_count, inputs, incomplete);
if (!incomplete) Decorate(node); Decorate(node, incomplete);
return node; return node;
} }
......
...@@ -82,7 +82,7 @@ class Graph : public ZoneObject { ...@@ -82,7 +82,7 @@ class Graph : public ZoneObject {
int NodeCount() const { return next_node_id_; } int NodeCount() const { return next_node_id_; }
void Decorate(Node* node); void Decorate(Node* node, bool incomplete);
void AddDecorator(GraphDecorator* decorator); void AddDecorator(GraphDecorator* decorator);
void RemoveDecorator(GraphDecorator* decorator); void RemoveDecorator(GraphDecorator* decorator);
...@@ -107,7 +107,7 @@ class Graph : public ZoneObject { ...@@ -107,7 +107,7 @@ class Graph : public ZoneObject {
class GraphDecorator : public ZoneObject { class GraphDecorator : public ZoneObject {
public: public:
virtual ~GraphDecorator() {} virtual ~GraphDecorator() {}
virtual void Decorate(Node* node) = 0; virtual void Decorate(Node* node, bool incomplete) = 0;
}; };
} // namespace compiler } // namespace compiler
......
...@@ -290,11 +290,11 @@ class AstGraphBuilderWithPositions : public AstGraphBuilder { ...@@ -290,11 +290,11 @@ class AstGraphBuilderWithPositions : public AstGraphBuilder {
LoopAssignmentAnalysis* loop_assignment, LoopAssignmentAnalysis* loop_assignment,
SourcePositionTable* source_positions) SourcePositionTable* source_positions)
: AstGraphBuilder(local_zone, info, jsgraph, loop_assignment), : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment),
source_positions_(source_positions) {} source_positions_(source_positions),
start_position_(info->shared_info()->start_position()) {}
bool CreateGraph() { bool CreateGraph() {
SourcePositionTable::Scope pos(source_positions_, SourcePositionTable::Scope pos_scope(source_positions_, start_position_);
SourcePosition::Unknown());
return AstGraphBuilder::CreateGraph(); return AstGraphBuilder::CreateGraph();
} }
...@@ -311,9 +311,45 @@ class AstGraphBuilderWithPositions : public AstGraphBuilder { ...@@ -311,9 +311,45 @@ class AstGraphBuilderWithPositions : public AstGraphBuilder {
private: private:
SourcePositionTable* source_positions_; SourcePositionTable* source_positions_;
SourcePosition start_position_;
}; };
namespace {
class SourcePositionWrapper : public Reducer {
public:
SourcePositionWrapper(Reducer* reducer, SourcePositionTable* table)
: reducer_(reducer), table_(table) {}
virtual ~SourcePositionWrapper() {}
virtual Reduction Reduce(Node* node) {
SourcePosition pos = table_->GetSourcePosition(node);
SourcePositionTable::Scope position(table_, pos);
return reducer_->Reduce(node);
}
private:
Reducer* reducer_;
SourcePositionTable* table_;
DISALLOW_COPY_AND_ASSIGN(SourcePositionWrapper);
};
static void AddReducer(PipelineData* data, GraphReducer* graph_reducer,
Reducer* reducer) {
if (FLAG_turbo_source_positions) {
void* buffer = data->graph_zone()->New(sizeof(SourcePositionWrapper));
SourcePositionWrapper* wrapper =
new (buffer) SourcePositionWrapper(reducer, data->source_positions());
graph_reducer->AddReducer(wrapper);
} else {
graph_reducer->AddReducer(reducer);
}
}
} // namespace
class PipelineRunScope { class PipelineRunScope {
public: public:
PipelineRunScope(PipelineData* data, const char* phase_name) PipelineRunScope(PipelineData* data, const char* phase_name)
...@@ -382,7 +418,7 @@ struct ContextSpecializerPhase { ...@@ -382,7 +418,7 @@ struct ContextSpecializerPhase {
JSContextSpecializer spec(data->info(), data->jsgraph(), JSContextSpecializer spec(data->info(), data->jsgraph(),
data->context_node()); data->context_node());
GraphReducer graph_reducer(data->graph(), temp_zone); GraphReducer graph_reducer(data->graph(), temp_zone);
graph_reducer.AddReducer(&spec); AddReducer(data, &graph_reducer, &spec);
graph_reducer.ReduceGraph(); graph_reducer.ReduceGraph();
} }
}; };
...@@ -435,13 +471,13 @@ struct TypedLoweringPhase { ...@@ -435,13 +471,13 @@ struct TypedLoweringPhase {
SimplifiedOperatorReducer simple_reducer(data->jsgraph()); SimplifiedOperatorReducer simple_reducer(data->jsgraph());
CommonOperatorReducer common_reducer; CommonOperatorReducer common_reducer;
GraphReducer graph_reducer(data->graph(), temp_zone); GraphReducer graph_reducer(data->graph(), temp_zone);
graph_reducer.AddReducer(&vn_reducer); AddReducer(data, &graph_reducer, &vn_reducer);
graph_reducer.AddReducer(&builtin_reducer); AddReducer(data, &graph_reducer, &builtin_reducer);
graph_reducer.AddReducer(&typed_lowering); AddReducer(data, &graph_reducer, &typed_lowering);
graph_reducer.AddReducer(&intrinsic_lowering); AddReducer(data, &graph_reducer, &intrinsic_lowering);
graph_reducer.AddReducer(&load_elimination); AddReducer(data, &graph_reducer, &load_elimination);
graph_reducer.AddReducer(&simple_reducer); AddReducer(data, &graph_reducer, &simple_reducer);
graph_reducer.AddReducer(&common_reducer); AddReducer(data, &graph_reducer, &common_reducer);
graph_reducer.ReduceGraph(); graph_reducer.ReduceGraph();
} }
}; };
...@@ -453,17 +489,18 @@ struct SimplifiedLoweringPhase { ...@@ -453,17 +489,18 @@ struct SimplifiedLoweringPhase {
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
SourcePositionTable::Scope pos(data->source_positions(), SourcePositionTable::Scope pos(data->source_positions(),
SourcePosition::Unknown()); SourcePosition::Unknown());
SimplifiedLowering lowering(data->jsgraph(), temp_zone); SimplifiedLowering lowering(data->jsgraph(), temp_zone,
data->source_positions());
lowering.LowerAllNodes(); lowering.LowerAllNodes();
ValueNumberingReducer vn_reducer(temp_zone); ValueNumberingReducer vn_reducer(temp_zone);
SimplifiedOperatorReducer simple_reducer(data->jsgraph()); SimplifiedOperatorReducer simple_reducer(data->jsgraph());
MachineOperatorReducer machine_reducer(data->jsgraph()); MachineOperatorReducer machine_reducer(data->jsgraph());
CommonOperatorReducer common_reducer; CommonOperatorReducer common_reducer;
GraphReducer graph_reducer(data->graph(), temp_zone); GraphReducer graph_reducer(data->graph(), temp_zone);
graph_reducer.AddReducer(&vn_reducer); AddReducer(data, &graph_reducer, &vn_reducer);
graph_reducer.AddReducer(&simple_reducer); AddReducer(data, &graph_reducer, &simple_reducer);
graph_reducer.AddReducer(&machine_reducer); AddReducer(data, &graph_reducer, &machine_reducer);
graph_reducer.AddReducer(&common_reducer); AddReducer(data, &graph_reducer, &common_reducer);
graph_reducer.ReduceGraph(); graph_reducer.ReduceGraph();
} }
}; };
...@@ -483,10 +520,10 @@ struct ChangeLoweringPhase { ...@@ -483,10 +520,10 @@ struct ChangeLoweringPhase {
CommonOperatorReducer common_reducer; CommonOperatorReducer common_reducer;
GraphReducer graph_reducer(data->graph(), temp_zone); GraphReducer graph_reducer(data->graph(), temp_zone);
graph_reducer.AddReducer(&vn_reducer); graph_reducer.AddReducer(&vn_reducer);
graph_reducer.AddReducer(&simple_reducer); AddReducer(data, &graph_reducer, &simple_reducer);
graph_reducer.AddReducer(&lowering); AddReducer(data, &graph_reducer, &lowering);
graph_reducer.AddReducer(&machine_reducer); AddReducer(data, &graph_reducer, &machine_reducer);
graph_reducer.AddReducer(&common_reducer); AddReducer(data, &graph_reducer, &common_reducer);
graph_reducer.ReduceGraph(); graph_reducer.ReduceGraph();
} }
}; };
...@@ -537,8 +574,8 @@ struct GenericLoweringPhase { ...@@ -537,8 +574,8 @@ struct GenericLoweringPhase {
JSGenericLowering generic(data->info(), data->jsgraph()); JSGenericLowering generic(data->info(), data->jsgraph());
SelectLowering select(data->jsgraph()->graph(), data->jsgraph()->common()); SelectLowering select(data->jsgraph()->graph(), data->jsgraph()->common());
GraphReducer graph_reducer(data->graph(), temp_zone); GraphReducer graph_reducer(data->graph(), temp_zone);
graph_reducer.AddReducer(&generic); AddReducer(data, &graph_reducer, &generic);
graph_reducer.AddReducer(&select); AddReducer(data, &graph_reducer, &select);
graph_reducer.ReduceGraph(); graph_reducer.ReduceGraph();
} }
}; };
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "src/compiler/representation-change.h" #include "src/compiler/representation-change.h"
#include "src/compiler/simplified-lowering.h" #include "src/compiler/simplified-lowering.h"
#include "src/compiler/simplified-operator.h" #include "src/compiler/simplified-operator.h"
#include "src/compiler/source-position.h"
#include "src/objects.h" #include "src/objects.h"
namespace v8 { namespace v8 {
...@@ -65,7 +66,8 @@ class RepresentationSelector { ...@@ -65,7 +66,8 @@ class RepresentationSelector {
}; };
RepresentationSelector(JSGraph* jsgraph, Zone* zone, RepresentationSelector(JSGraph* jsgraph, Zone* zone,
RepresentationChanger* changer) RepresentationChanger* changer,
SourcePositionTable* source_positions)
: jsgraph_(jsgraph), : jsgraph_(jsgraph),
count_(jsgraph->graph()->NodeCount()), count_(jsgraph->graph()->NodeCount()),
info_(zone->NewArray<NodeInfo>(count_)), info_(zone->NewArray<NodeInfo>(count_)),
...@@ -73,7 +75,8 @@ class RepresentationSelector { ...@@ -73,7 +75,8 @@ class RepresentationSelector {
replacements_(zone), replacements_(zone),
phase_(PROPAGATE), phase_(PROPAGATE),
changer_(changer), changer_(changer),
queue_(zone) { queue_(zone),
source_positions_(source_positions) {
memset(info_, 0, sizeof(NodeInfo) * count_); memset(info_, 0, sizeof(NodeInfo) * count_);
safe_int_additive_range_ = safe_int_additive_range_ =
...@@ -106,7 +109,13 @@ class RepresentationSelector { ...@@ -106,7 +109,13 @@ class RepresentationSelector {
Node* node = *i; Node* node = *i;
TRACE((" visit #%d: %s\n", node->id(), node->op()->mnemonic())); TRACE((" visit #%d: %s\n", node->id(), node->op()->mnemonic()));
// Reuse {VisitNode()} so the representation rules are in one place. // Reuse {VisitNode()} so the representation rules are in one place.
VisitNode(node, GetUseInfo(node), lowering); if (FLAG_turbo_source_positions) {
SourcePositionTable::Scope scope(
source_positions_, source_positions_->GetSourcePosition(node));
VisitNode(node, GetUseInfo(node), lowering);
} else {
VisitNode(node, GetUseInfo(node), lowering);
}
} }
// Perform the final replacements. // Perform the final replacements.
...@@ -1071,6 +1080,12 @@ class RepresentationSelector { ...@@ -1071,6 +1080,12 @@ class RepresentationSelector {
Phase phase_; // current phase of algorithm Phase phase_; // current phase of algorithm
RepresentationChanger* changer_; // for inserting representation changes RepresentationChanger* changer_; // for inserting representation changes
ZoneQueue<Node*> queue_; // queue for traversing the graph ZoneQueue<Node*> queue_; // queue for traversing the graph
// TODO(danno): RepresentationSelector shouldn't know anything about the
// source positions table, but must for now since there currently is no other
// way to pass down source position information to nodes created during
// lowering. Once this phase becomes a vanilla reducer, it should get source
// position information via the SourcePositionWrapper like all other reducers.
SourcePositionTable* source_positions_;
Type* safe_int_additive_range_; Type* safe_int_additive_range_;
NodeInfo* GetInfo(Node* node) { NodeInfo* GetInfo(Node* node) {
...@@ -1094,7 +1109,8 @@ Node* SimplifiedLowering::IsTagged(Node* node) { ...@@ -1094,7 +1109,8 @@ Node* SimplifiedLowering::IsTagged(Node* node) {
void SimplifiedLowering::LowerAllNodes() { void SimplifiedLowering::LowerAllNodes() {
SimplifiedOperatorBuilder simplified(graph()->zone()); SimplifiedOperatorBuilder simplified(graph()->zone());
RepresentationChanger changer(jsgraph(), &simplified, jsgraph()->isolate()); RepresentationChanger changer(jsgraph(), &simplified, jsgraph()->isolate());
RepresentationSelector selector(jsgraph(), zone_, &changer); RepresentationSelector selector(jsgraph(), zone_, &changer,
source_positions_);
selector.Run(this); selector.Run(this);
} }
......
...@@ -16,12 +16,13 @@ namespace compiler { ...@@ -16,12 +16,13 @@ namespace compiler {
// Forward declarations. // Forward declarations.
class RepresentationChanger; class RepresentationChanger;
class SourcePositionTable;
class SimplifiedLowering FINAL { class SimplifiedLowering FINAL {
public: public:
SimplifiedLowering(JSGraph* jsgraph, Zone* zone) SimplifiedLowering(JSGraph* jsgraph, Zone* zone,
: jsgraph_(jsgraph), zone_(zone) {} SourcePositionTable* source_positions)
: jsgraph_(jsgraph), zone_(zone), source_positions_(source_positions) {}
~SimplifiedLowering() {} ~SimplifiedLowering() {}
void LowerAllNodes(); void LowerAllNodes();
...@@ -45,6 +46,13 @@ class SimplifiedLowering FINAL { ...@@ -45,6 +46,13 @@ class SimplifiedLowering FINAL {
JSGraph* const jsgraph_; JSGraph* const jsgraph_;
Zone* const zone_; Zone* const zone_;
// TODO(danno): SimplifiedLowering shouldn't know anything about the source
// positions table, but must for now since there currently is no other way to
// pass down source position information to nodes created during
// lowering. Once this phase becomes a vanilla reducer, it should get source
// position information via the SourcePositionWrapper like all other reducers.
SourcePositionTable* source_positions_;
Node* SmiTag(Node* node); Node* SmiTag(Node* node);
Node* IsTagged(Node* node); Node* IsTagged(Node* node);
Node* Untag(Node* node); Node* Untag(Node* node);
......
...@@ -15,7 +15,7 @@ class SourcePositionTable::Decorator FINAL : public GraphDecorator { ...@@ -15,7 +15,7 @@ class SourcePositionTable::Decorator FINAL : public GraphDecorator {
explicit Decorator(SourcePositionTable* source_positions) explicit Decorator(SourcePositionTable* source_positions)
: source_positions_(source_positions) {} : source_positions_(source_positions) {}
void Decorate(Node* node) FINAL { void Decorate(Node* node, bool incomplete) FINAL {
DCHECK(!source_positions_->current_position_.IsInvalid()); DCHECK(!source_positions_->current_position_.IsInvalid());
source_positions_->table_.Set(node, source_positions_->current_position_); source_positions_->table_.Set(node, source_positions_->current_position_);
} }
......
...@@ -143,7 +143,7 @@ class LazyTypeCache FINAL : public ZoneObject { ...@@ -143,7 +143,7 @@ class LazyTypeCache FINAL : public ZoneObject {
class Typer::Decorator FINAL : public GraphDecorator { class Typer::Decorator FINAL : public GraphDecorator {
public: public:
explicit Decorator(Typer* typer) : typer_(typer) {} explicit Decorator(Typer* typer) : typer_(typer) {}
void Decorate(Node* node) FINAL; void Decorate(Node* node, bool incomplete) FINAL;
private: private:
Typer* typer_; Typer* typer_;
...@@ -408,7 +408,8 @@ void Typer::Run() { ...@@ -408,7 +408,8 @@ void Typer::Run() {
} }
void Typer::Decorator::Decorate(Node* node) { void Typer::Decorator::Decorate(Node* node, bool incomplete) {
if (incomplete) return;
if (node->op()->ValueOutputCount() > 0) { if (node->op()->ValueOutputCount() > 0) {
// Only eagerly type-decorate nodes with known input types. // Only eagerly type-decorate nodes with known input types.
// Other cases will generally require a proper fixpoint iteration with Run. // Other cases will generally require a proper fixpoint iteration with Run.
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "src/compiler/pipeline.h" #include "src/compiler/pipeline.h"
#include "src/compiler/representation-change.h" #include "src/compiler/representation-change.h"
#include "src/compiler/simplified-lowering.h" #include "src/compiler/simplified-lowering.h"
#include "src/compiler/source-position.h"
#include "src/compiler/typer.h" #include "src/compiler/typer.h"
#include "src/compiler/verifier.h" #include "src/compiler/verifier.h"
#include "src/execution.h" #include "src/execution.h"
...@@ -40,11 +41,13 @@ class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> { ...@@ -40,11 +41,13 @@ class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> {
javascript(this->zone()), javascript(this->zone()),
jsgraph(this->isolate(), this->graph(), this->common(), &javascript, jsgraph(this->isolate(), this->graph(), this->common(), &javascript,
this->machine()), this->machine()),
lowering(&jsgraph, this->zone()) {} source_positions(jsgraph.graph()),
lowering(&jsgraph, this->zone(), &source_positions) {}
Typer typer; Typer typer;
JSOperatorBuilder javascript; JSOperatorBuilder javascript;
JSGraph jsgraph; JSGraph jsgraph;
SourcePositionTable source_positions;
SimplifiedLowering lowering; SimplifiedLowering lowering;
void LowerAllNodes() { void LowerAllNodes() {
...@@ -699,7 +702,10 @@ class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders { ...@@ -699,7 +702,10 @@ class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders {
CHECK_EQ(expected, node->opcode()); CHECK_EQ(expected, node->opcode());
} }
void Lower() { SimplifiedLowering(&jsgraph, jsgraph.zone()).LowerAllNodes(); } void Lower() {
SourcePositionTable table(jsgraph.graph());
SimplifiedLowering(&jsgraph, jsgraph.zone(), &table).LowerAllNodes();
}
// Inserts the node as the return value of the graph. // Inserts the node as the return value of the graph.
Node* Return(Node* node) { Node* Return(Node* node) {
......
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