Commit 80e0d42b authored by danno's avatar danno Committed by Commit bot

[turbofan] Add schedule to visualizer output

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

Cr-Commit-Position: refs/heads/master@{#27836}
parent 2ff768b2
......@@ -31,10 +31,61 @@ class NodeAuxData {
return (id < aux_data_.size()) ? aux_data_[id] : T();
}
class const_iterator;
friend class const_iterator;
const_iterator begin() const;
const_iterator end() const;
private:
ZoneVector<T> aux_data_;
};
template <class T>
class NodeAuxData<T>::const_iterator {
public:
typedef std::forward_iterator_tag iterator_category;
typedef int difference_type;
typedef std::pair<size_t, T> value_type;
typedef value_type* pointer;
typedef value_type& reference;
const_iterator(const ZoneVector<T>* data, size_t current)
: data_(data), current_(current) {}
const_iterator(const const_iterator& other)
: data_(other.data_), current_(other.current_) {}
value_type operator*() const {
return std::make_pair(current_, (*data_)[current_]);
}
bool operator==(const const_iterator& other) const {
return current_ == other.current_ && data_ == other.data_;
}
bool operator!=(const const_iterator& other) const {
return !(*this == other);
}
const_iterator& operator++() {
++current_;
return *this;
}
const_iterator operator++(int);
private:
const ZoneVector<T>* data_;
size_t current_;
};
template <class T>
typename NodeAuxData<T>::const_iterator NodeAuxData<T>::begin() const {
return typename NodeAuxData<T>::const_iterator(&aux_data_, 0);
}
template <class T>
typename NodeAuxData<T>::const_iterator NodeAuxData<T>::end() const {
return typename NodeAuxData<T>::const_iterator(&aux_data_, aux_data_.size());
}
} // namespace compiler
} // namespace internal
} // namespace v8
......
......@@ -294,7 +294,22 @@ struct TurboCfgFile : public std::ofstream {
};
static void TraceSchedule(Schedule* schedule) {
static void TraceSchedule(CompilationInfo* info, Schedule* schedule) {
if (FLAG_trace_turbo) {
FILE* json_file = OpenVisualizerLogFile(info, NULL, "json", "a+");
if (json_file != nullptr) {
OFStream json_of(json_file);
json_of << "{\"name\":\"Schedule\",\"type\":\"schedule\",\"data\":\"";
std::stringstream schedule_stream;
schedule_stream << *schedule;
std::string schedule_string(schedule_stream.str());
for (const auto& c : schedule_string) {
json_of << AsEscapedUC16ForJSON(c);
}
json_of << "\"},\n";
fclose(json_file);
}
}
if (!FLAG_trace_turbo_graph && !FLAG_trace_turbo_scheduler) return;
OFStream os(stdout);
os << "-- Schedule --------------------------------------\n" << *schedule;
......@@ -1093,7 +1108,7 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode(
CHECK(SupportedBackend());
if (data->schedule() == nullptr) Run<ComputeSchedulePhase>();
TraceSchedule(data->schedule());
TraceSchedule(data->info(), data->schedule());
BasicBlockProfiler::Data* profiler_data = NULL;
if (FLAG_turbo_profiling) {
......@@ -1113,6 +1128,12 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode(
data->sequence());
}
std::ostringstream source_position_output;
if (FLAG_trace_turbo) {
// Output source position information before the graph is deleted.
data_->source_positions()->Print(source_position_output);
}
data->DeleteGraphZone();
BeginPhaseKind("register allocation");
......@@ -1161,7 +1182,10 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode(
json_of << AsEscapedUC16ForJSON(c);
}
#endif // ENABLE_DISASSEMBLER
json_of << "\"}\n]}";
json_of << "\"}\n],\n";
json_of << "\"nodePositions\":";
json_of << source_position_output.str();
json_of << "}";
fclose(json_file);
}
OFStream os(stdout);
......
......@@ -50,6 +50,24 @@ SourcePosition SourcePositionTable::GetSourcePosition(Node* node) const {
return table_.Get(node);
}
void SourcePositionTable::Print(std::ostream& os) const {
os << "{";
bool needs_comma = false;
for (auto i : table_) {
SourcePosition pos = i.second;
if (!pos.IsUnknown()) {
if (needs_comma) {
os << ",";
}
os << "\"" << i.first << "\""
<< ":" << pos.raw();
needs_comma = true;
}
}
os << "}";
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -81,6 +81,8 @@ class SourcePositionTable FINAL {
SourcePosition GetSourcePosition(Node* node) const;
void Print(std::ostream& os) const;
private:
class Decorator;
......
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