Make loop assignment analysis a separate phase.

R=dcarney@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25751}
This commit is contained in:
mstarzinger 2014-12-10 07:19:53 -08:00 committed by Commit bot
parent 7d13ca278a
commit 0f9d98e053
3 changed files with 38 additions and 16 deletions

View File

@ -20,14 +20,14 @@ namespace internal {
namespace compiler {
AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info,
JSGraph* jsgraph)
JSGraph* jsgraph, LoopAssignmentAnalysis* loop)
: StructuredGraphBuilder(local_zone, jsgraph->graph(), jsgraph->common()),
info_(info),
jsgraph_(jsgraph),
globals_(0, local_zone),
breakable_(NULL),
execution_context_(NULL),
loop_assignment_analysis_(NULL) {
loop_assignment_analysis_(loop) {
InitializeAstVisitor(local_zone);
}
@ -62,12 +62,6 @@ bool AstGraphBuilder::CreateGraph() {
int parameter_count = info()->num_parameters();
graph()->SetStart(graph()->NewNode(common()->Start(parameter_count)));
if (FLAG_loop_assignment_analysis) {
// TODO(turbofan): use a temporary zone for the loop assignment analysis.
AstLoopAssignmentAnalyzer analyzer(zone(), info());
loop_assignment_analysis_ = analyzer.Analyze();
}
// Initialize the top-level environment.
Environment env(this, scope, graph()->start());
set_environment(&env);

View File

@ -26,7 +26,8 @@ class LoopBuilder;
// of function inlining.
class AstGraphBuilder : public StructuredGraphBuilder, public AstVisitor {
public:
AstGraphBuilder(Zone* local_zone, CompilationInfo* info, JSGraph* jsgraph);
AstGraphBuilder(Zone* local_zone, CompilationInfo* info, JSGraph* jsgraph,
LoopAssignmentAnalysis* loop_assignment = NULL);
// Creates a graph by visiting the entire AST.
bool CreateGraph();

View File

@ -9,6 +9,7 @@
#include "src/base/platform/elapsed-timer.h"
#include "src/compiler/ast-graph-builder.h"
#include "src/compiler/ast-loop-assignment-analyzer.h"
#include "src/compiler/basic-block-instrumentor.h"
#include "src/compiler/change-lowering.h"
#include "src/compiler/code-generator.h"
@ -57,6 +58,7 @@ class PipelineData {
graph_zone_scope_(zone_pool_),
graph_zone_(nullptr),
graph_(nullptr),
loop_assignment_(nullptr),
machine_(nullptr),
common_(nullptr),
javascript_(nullptr),
@ -134,6 +136,12 @@ class PipelineData {
JSGraph* jsgraph() const { return jsgraph_; }
Typer* typer() const { return typer_.get(); }
LoopAssignmentAnalysis* loop_assignment() const { return loop_assignment_; }
void set_loop_assignment(LoopAssignmentAnalysis* loop_assignment) {
DCHECK_EQ(nullptr, loop_assignment_);
loop_assignment_ = loop_assignment;
}
Node* context_node() const { return context_node_; }
void set_context_node(Node* context_node) {
DCHECK_EQ(nullptr, context_node_);
@ -160,6 +168,7 @@ class PipelineData {
graph_zone_scope_.Destroy();
graph_zone_ = nullptr;
graph_ = nullptr;
loop_assignment_ = nullptr;
machine_ = nullptr;
common_ = nullptr;
javascript_ = nullptr;
@ -205,13 +214,14 @@ class PipelineData {
bool compilation_failed_;
Handle<Code> code_;
ZonePool::Scope graph_zone_scope_;
Zone* graph_zone_;
// All objects in the following group of fields are allocated in graph_zone_.
// They are all set to NULL when the graph_zone_ is destroyed.
ZonePool::Scope graph_zone_scope_;
Zone* graph_zone_;
Graph* graph_;
// TODO(dcarney): make this into a ZoneObject.
SmartPointer<SourcePositionTable> source_positions_;
LoopAssignmentAnalysis* loop_assignment_;
MachineOperatorBuilder* machine_;
CommonOperatorBuilder* common_;
JSOperatorBuilder* javascript_;
@ -277,10 +287,11 @@ static SmartArrayPointer<char> GetDebugName(CompilationInfo* info) {
class AstGraphBuilderWithPositions : public AstGraphBuilder {
public:
explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info,
JSGraph* jsgraph,
SourcePositionTable* source_positions)
: AstGraphBuilder(local_zone, info, jsgraph),
AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info,
JSGraph* jsgraph,
LoopAssignmentAnalysis* loop_assignment,
SourcePositionTable* source_positions)
: AstGraphBuilder(local_zone, info, jsgraph, loop_assignment),
source_positions_(source_positions) {}
bool CreateGraph() {
@ -337,12 +348,24 @@ void Pipeline::Run(Arg0 arg_0) {
}
struct LoopAssignmentAnalysisPhase {
static const char* phase_name() { return "loop assignment analysis"; }
void Run(PipelineData* data, Zone* temp_zone) {
AstLoopAssignmentAnalyzer analyzer(data->graph_zone(), data->info());
LoopAssignmentAnalysis* loop_assignment = analyzer.Analyze();
data->set_loop_assignment(loop_assignment);
}
};
struct GraphBuilderPhase {
static const char* phase_name() { return "graph builder"; }
void Run(PipelineData* data, Zone* temp_zone) {
AstGraphBuilderWithPositions graph_builder(
temp_zone, data->info(), data->jsgraph(), data->source_positions());
temp_zone, data->info(), data->jsgraph(), data->loop_assignment(),
data->source_positions());
if (graph_builder.CreateGraph()) {
data->set_context_node(graph_builder.GetFunctionContext());
} else {
@ -752,6 +775,10 @@ Handle<Code> Pipeline::GenerateCode() {
data.source_positions()->AddDecorator();
if (FLAG_loop_assignment_analysis) {
Run<LoopAssignmentAnalysisPhase>();
}
Run<GraphBuilderPhase>();
if (data.compilation_failed()) return Handle<Code>::null();
RunPrintAndVerify("Initial untyped", true);