Commit b9d583d5 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Don't spread global flag checks all over the compiler code.

Better encapsulate the source position handling in TurboFan.

R=svenpanne@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#28153}
parent 66f428dd
...@@ -117,6 +117,7 @@ CompilationInfo::CompilationInfo(ParseInfo* parse_info) ...@@ -117,6 +117,7 @@ CompilationInfo::CompilationInfo(ParseInfo* parse_info)
if (FLAG_turbo_builtin_inlining) MarkAsBuiltinInliningEnabled(); if (FLAG_turbo_builtin_inlining) MarkAsBuiltinInliningEnabled();
if (FLAG_turbo_deoptimization) MarkAsDeoptimizationEnabled(); if (FLAG_turbo_deoptimization) MarkAsDeoptimizationEnabled();
if (FLAG_turbo_inlining) MarkAsInliningEnabled(); if (FLAG_turbo_inlining) MarkAsInliningEnabled();
if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled();
if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
if (FLAG_turbo_types) MarkAsTypingEnabled(); if (FLAG_turbo_types) MarkAsTypingEnabled();
......
...@@ -127,7 +127,8 @@ class CompilationInfo { ...@@ -127,7 +127,8 @@ class CompilationInfo {
kSplittingEnabled = 1 << 13, kSplittingEnabled = 1 << 13,
kBuiltinInliningEnabled = 1 << 14, kBuiltinInliningEnabled = 1 << 14,
kTypeFeedbackEnabled = 1 << 15, kTypeFeedbackEnabled = 1 << 15,
kDeoptimizationEnabled = 1 << 16 kDeoptimizationEnabled = 1 << 16,
kSourcePositionsEnabled = 1 << 17
}; };
explicit CompilationInfo(ParseInfo* parse_info); explicit CompilationInfo(ParseInfo* parse_info);
...@@ -224,6 +225,12 @@ class CompilationInfo { ...@@ -224,6 +225,12 @@ class CompilationInfo {
return GetFlag(kDeoptimizationEnabled); return GetFlag(kDeoptimizationEnabled);
} }
void MarkAsSourcePositionsEnabled() { SetFlag(kSourcePositionsEnabled); }
bool is_source_positions_enabled() const {
return GetFlag(kSourcePositionsEnabled);
}
void MarkAsInliningEnabled() { SetFlag(kInliningEnabled); } void MarkAsInliningEnabled() { SetFlag(kInliningEnabled); }
bool is_inlining_enabled() const { return GetFlag(kInliningEnabled); } bool is_inlining_enabled() const { return GetFlag(kInliningEnabled); }
......
...@@ -18,16 +18,16 @@ namespace v8 { ...@@ -18,16 +18,16 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
InstructionSelector::InstructionSelector(Zone* zone, size_t node_count, InstructionSelector::InstructionSelector(
Linkage* linkage, Zone* zone, size_t node_count, Linkage* linkage,
InstructionSequence* sequence, InstructionSequence* sequence, Schedule* schedule,
Schedule* schedule, SourcePositionTable* source_positions,
SourcePositionTable* source_positions, SourcePositionMode source_position_mode, Features features)
Features features)
: zone_(zone), : zone_(zone),
linkage_(linkage), linkage_(linkage),
sequence_(sequence), sequence_(sequence),
source_positions_(source_positions), source_positions_(source_positions),
source_position_mode_(source_position_mode),
features_(features), features_(features),
schedule_(schedule), schedule_(schedule),
current_block_(NULL), current_block_(NULL),
...@@ -426,7 +426,8 @@ void InstructionSelector::VisitBlock(BasicBlock* block) { ...@@ -426,7 +426,8 @@ void InstructionSelector::VisitBlock(BasicBlock* block) {
SourcePosition source_position = source_positions_->GetSourcePosition(node); SourcePosition source_position = source_positions_->GetSourcePosition(node);
if (source_position.IsUnknown()) continue; if (source_position.IsUnknown()) continue;
DCHECK(!source_position.IsInvalid()); DCHECK(!source_position.IsInvalid());
if (FLAG_turbo_source_positions || node->opcode() == IrOpcode::kCall) { if (source_position_mode_ == kAllSourcePositions ||
node->opcode() == IrOpcode::kCall) {
sequence()->SetSourcePosition(instructions_[current_node_end], sequence()->SetSourcePosition(instructions_[current_node_end],
source_position); source_position);
} }
......
...@@ -33,10 +33,14 @@ class InstructionSelector final { ...@@ -33,10 +33,14 @@ class InstructionSelector final {
// Forward declarations. // Forward declarations.
class Features; class Features;
InstructionSelector(Zone* zone, size_t node_count, Linkage* linkage, enum SourcePositionMode { kCallSourcePositions, kAllSourcePositions };
InstructionSequence* sequence, Schedule* schedule,
SourcePositionTable* source_positions, InstructionSelector(
Features features = SupportedFeatures()); Zone* zone, size_t node_count, Linkage* linkage,
InstructionSequence* sequence, Schedule* schedule,
SourcePositionTable* source_positions,
SourcePositionMode source_position_mode = kCallSourcePositions,
Features features = SupportedFeatures());
// Visit code for the entire graph with the included schedule. // Visit code for the entire graph with the included schedule.
void SelectInstructions(); void SelectInstructions();
...@@ -219,6 +223,7 @@ class InstructionSelector final { ...@@ -219,6 +223,7 @@ class InstructionSelector final {
Linkage* const linkage_; Linkage* const linkage_;
InstructionSequence* const sequence_; InstructionSequence* const sequence_;
SourcePositionTable* const source_positions_; SourcePositionTable* const source_positions_;
SourcePositionMode const source_position_mode_;
Features features_; Features features_;
Schedule* const schedule_; Schedule* const schedule_;
BasicBlock* current_block_; BasicBlock* current_block_;
......
...@@ -312,6 +312,8 @@ class PipelineData { ...@@ -312,6 +312,8 @@ class PipelineData {
}; };
namespace {
struct TurboCfgFile : public std::ofstream { struct TurboCfgFile : public std::ofstream {
explicit TurboCfgFile(Isolate* isolate) explicit TurboCfgFile(Isolate* isolate)
: std::ofstream(isolate->GetTurboCfgFileName().c_str(), : std::ofstream(isolate->GetTurboCfgFileName().c_str(),
...@@ -319,7 +321,7 @@ struct TurboCfgFile : public std::ofstream { ...@@ -319,7 +321,7 @@ struct TurboCfgFile : public std::ofstream {
}; };
static void TraceSchedule(CompilationInfo* info, Schedule* schedule) { void TraceSchedule(CompilationInfo* info, Schedule* schedule) {
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
FILE* json_file = OpenVisualizerLogFile(info, NULL, "json", "a+"); FILE* json_file = OpenVisualizerLogFile(info, NULL, "json", "a+");
if (json_file != nullptr) { if (json_file != nullptr) {
...@@ -341,7 +343,7 @@ static void TraceSchedule(CompilationInfo* info, Schedule* schedule) { ...@@ -341,7 +343,7 @@ static void TraceSchedule(CompilationInfo* info, Schedule* schedule) {
} }
static SmartArrayPointer<char> GetDebugName(CompilationInfo* info) { SmartArrayPointer<char> GetDebugName(CompilationInfo* info) {
if (info->code_stub() != NULL) { if (info->code_stub() != NULL) {
CodeStub::Major major_key = info->code_stub()->MajorKey(); CodeStub::Major major_key = info->code_stub()->MajorKey();
const char* major_name = CodeStub::MajorName(major_key, false); const char* major_name = CodeStub::MajorName(major_key, false);
...@@ -356,7 +358,7 @@ static SmartArrayPointer<char> GetDebugName(CompilationInfo* info) { ...@@ -356,7 +358,7 @@ static SmartArrayPointer<char> GetDebugName(CompilationInfo* info) {
} }
class AstGraphBuilderWithPositions : public AstGraphBuilder { class AstGraphBuilderWithPositions final : public AstGraphBuilder {
public: public:
AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info,
JSGraph* jsgraph, JSGraph* jsgraph,
...@@ -383,45 +385,43 @@ class AstGraphBuilderWithPositions : public AstGraphBuilder { ...@@ -383,45 +385,43 @@ class AstGraphBuilderWithPositions : public AstGraphBuilder {
#undef DEF_VISIT #undef DEF_VISIT
private: private:
SourcePositionTable* source_positions_; SourcePositionTable* const source_positions_;
SourcePosition start_position_; SourcePosition const start_position_;
}; };
namespace { class SourcePositionWrapper final : public Reducer {
class SourcePositionWrapper : public Reducer {
public: public:
SourcePositionWrapper(Reducer* reducer, SourcePositionTable* table) SourcePositionWrapper(Reducer* reducer, SourcePositionTable* table)
: reducer_(reducer), table_(table) {} : reducer_(reducer), table_(table) {}
virtual ~SourcePositionWrapper() {} ~SourcePositionWrapper() final {}
virtual Reduction Reduce(Node* node) { Reduction Reduce(Node* node) final {
SourcePosition pos = table_->GetSourcePosition(node); SourcePosition const pos = table_->GetSourcePosition(node);
SourcePositionTable::Scope position(table_, pos); SourcePositionTable::Scope position(table_, pos);
return reducer_->Reduce(node); return reducer_->Reduce(node);
} }
private: private:
Reducer* reducer_; Reducer* const reducer_;
SourcePositionTable* table_; SourcePositionTable* const table_;
DISALLOW_COPY_AND_ASSIGN(SourcePositionWrapper); DISALLOW_COPY_AND_ASSIGN(SourcePositionWrapper);
}; };
static void AddReducer(PipelineData* data, GraphReducer* graph_reducer, void AddReducer(PipelineData* data, GraphReducer* graph_reducer,
Reducer* reducer) { Reducer* reducer) {
if (FLAG_turbo_source_positions) { if (data->info()->is_source_positions_enabled()) {
void* buffer = data->graph_zone()->New(sizeof(SourcePositionWrapper)); void* const buffer = data->graph_zone()->New(sizeof(SourcePositionWrapper));
SourcePositionWrapper* wrapper = SourcePositionWrapper* const wrapper =
new (buffer) SourcePositionWrapper(reducer, data->source_positions()); new (buffer) SourcePositionWrapper(reducer, data->source_positions());
graph_reducer->AddReducer(wrapper); graph_reducer->AddReducer(wrapper);
} else { } else {
graph_reducer->AddReducer(reducer); graph_reducer->AddReducer(reducer);
} }
} }
} // namespace
class PipelineRunScope { class PipelineRunScope {
public: public:
...@@ -438,6 +438,8 @@ class PipelineRunScope { ...@@ -438,6 +438,8 @@ class PipelineRunScope {
ZonePool::Scope zone_scope_; ZonePool::Scope zone_scope_;
}; };
} // namespace
template <typename Phase> template <typename Phase>
void Pipeline::Run() { void Pipeline::Run() {
...@@ -712,9 +714,12 @@ struct InstructionSelectionPhase { ...@@ -712,9 +714,12 @@ struct InstructionSelectionPhase {
static const char* phase_name() { return "select instructions"; } static const char* phase_name() { return "select instructions"; }
void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) {
InstructionSelector selector(temp_zone, data->graph()->NodeCount(), linkage, InstructionSelector selector(
data->sequence(), data->schedule(), temp_zone, data->graph()->NodeCount(), linkage, data->sequence(),
data->source_positions()); data->schedule(), data->source_positions(),
data->info()->is_source_positions_enabled()
? InstructionSelector::kAllSourcePositions
: InstructionSelector::kCallSourcePositions);
selector.SelectInstructions(); selector.SelectInstructions();
} }
}; };
......
...@@ -111,13 +111,9 @@ class RepresentationSelector { ...@@ -111,13 +111,9 @@ 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.
if (FLAG_turbo_source_positions) { SourcePositionTable::Scope scope(
SourcePositionTable::Scope scope( source_positions_, source_positions_->GetSourcePosition(node));
source_positions_, source_positions_->GetSourcePosition(node)); VisitNode(node, GetUseInfo(node), lowering);
VisitNode(node, GetUseInfo(node), lowering);
} else {
VisitNode(node, GetUseInfo(node), lowering);
}
} }
// Perform the final replacements. // Perform the final replacements.
......
...@@ -27,22 +27,22 @@ class SourcePositionTable::Decorator final : public GraphDecorator { ...@@ -27,22 +27,22 @@ class SourcePositionTable::Decorator final : public GraphDecorator {
SourcePositionTable::SourcePositionTable(Graph* graph) SourcePositionTable::SourcePositionTable(Graph* graph)
: graph_(graph), : graph_(graph),
decorator_(NULL), decorator_(nullptr),
current_position_(SourcePosition::Invalid()), current_position_(SourcePosition::Invalid()),
table_(graph->zone()) {} table_(graph->zone()) {}
void SourcePositionTable::AddDecorator() { void SourcePositionTable::AddDecorator() {
DCHECK(decorator_ == NULL); DCHECK_NULL(decorator_);
decorator_ = new (graph_->zone()) Decorator(this); decorator_ = new (graph_->zone()) Decorator(this);
graph_->AddDecorator(decorator_); graph_->AddDecorator(decorator_);
} }
void SourcePositionTable::RemoveDecorator() { void SourcePositionTable::RemoveDecorator() {
DCHECK(decorator_ != NULL); DCHECK_NOT_NULL(decorator_);
graph_->RemoveDecorator(decorator_); graph_->RemoveDecorator(decorator_);
decorator_ = NULL; decorator_ = nullptr;
} }
......
...@@ -45,7 +45,7 @@ inline bool operator!=(const SourcePosition& lhs, const SourcePosition& rhs) { ...@@ -45,7 +45,7 @@ inline bool operator!=(const SourcePosition& lhs, const SourcePosition& rhs) {
class SourcePositionTable final { class SourcePositionTable final {
public: public:
class Scope { class Scope final {
public: public:
Scope(SourcePositionTable* source_positions, SourcePosition position) Scope(SourcePositionTable* source_positions, SourcePosition position)
: source_positions_(source_positions), : source_positions_(source_positions),
...@@ -66,14 +66,14 @@ class SourcePositionTable final { ...@@ -66,14 +66,14 @@ class SourcePositionTable final {
} }
} }
SourcePositionTable* source_positions_; SourcePositionTable* const source_positions_;
SourcePosition prev_position_; SourcePosition const prev_position_;
DISALLOW_COPY_AND_ASSIGN(Scope); DISALLOW_COPY_AND_ASSIGN(Scope);
}; };
explicit SourcePositionTable(Graph* graph); explicit SourcePositionTable(Graph* graph);
~SourcePositionTable() { ~SourcePositionTable() {
if (decorator_ != NULL) RemoveDecorator(); if (decorator_) RemoveDecorator();
} }
void AddDecorator(); void AddDecorator();
...@@ -86,7 +86,7 @@ class SourcePositionTable final { ...@@ -86,7 +86,7 @@ class SourcePositionTable final {
private: private:
class Decorator; class Decorator;
Graph* graph_; Graph* const graph_;
Decorator* decorator_; Decorator* decorator_;
SourcePosition current_position_; SourcePosition current_position_;
NodeAuxData<SourcePosition> table_; NodeAuxData<SourcePosition> table_;
...@@ -98,4 +98,4 @@ class SourcePositionTable final { ...@@ -98,4 +98,4 @@ class SourcePositionTable final {
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
#endif #endif // V8_COMPILER_SOURCE_POSITION_H_
...@@ -29,7 +29,8 @@ InstructionSelectorTest::~InstructionSelectorTest() {} ...@@ -29,7 +29,8 @@ InstructionSelectorTest::~InstructionSelectorTest() {}
InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build( InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
InstructionSelector::Features features, InstructionSelector::Features features,
InstructionSelectorTest::StreamBuilderMode mode) { InstructionSelectorTest::StreamBuilderMode mode,
InstructionSelector::SourcePositionMode source_position_mode) {
Schedule* schedule = Export(); Schedule* schedule = Export();
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
OFStream out(stdout); OFStream out(stdout);
...@@ -45,7 +46,8 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build( ...@@ -45,7 +46,8 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
instruction_blocks); instruction_blocks);
SourcePositionTable source_position_table(graph()); SourcePositionTable source_position_table(graph());
InstructionSelector selector(test_->zone(), node_count, &linkage, &sequence, InstructionSelector selector(test_->zone(), node_count, &linkage, &sequence,
schedule, &source_position_table, features); schedule, &source_position_table,
source_position_mode, features);
selector.SelectInstructions(); selector.SelectInstructions();
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
OFStream out(stdout); OFStream out(stdout);
......
...@@ -73,7 +73,9 @@ class InstructionSelectorTest : public TestWithContext, ...@@ -73,7 +73,9 @@ class InstructionSelectorTest : public TestWithContext,
return Build(InstructionSelector::Features(), mode); return Build(InstructionSelector::Features(), mode);
} }
Stream Build(InstructionSelector::Features features, Stream Build(InstructionSelector::Features features,
StreamBuilderMode mode = kTargetInstructions); StreamBuilderMode mode = kTargetInstructions,
InstructionSelector::SourcePositionMode source_position_mode =
InstructionSelector::kAllSourcePositions);
private: private:
MachineSignature* MakeMachineSignature(Zone* zone, MachineSignature* MakeMachineSignature(Zone* zone,
......
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