blob: 7ea1240c5ea98e323904313db43af1298c0fbf4a [file] [log] [blame]
Nicolas Geoffrayf635e632014-05-14 09:43:38 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "graph_visualizer.h"
18
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010019#include "code_generator.h"
David Brazdila4b8c212015-05-07 09:59:30 +010020#include "dead_code_elimination.h"
Andreas Gampe7c3952f2015-02-19 18:21:24 -080021#include "licm.h"
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010022#include "nodes.h"
Nicolas Geoffray82091da2015-01-26 10:02:45 +000023#include "optimization.h"
Andreas Gampe7c3952f2015-02-19 18:21:24 -080024#include "register_allocator.h"
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +010025#include "ssa_liveness_analysis.h"
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010026
David Brazdilc74652862015-05-13 17:50:09 +010027#include <cctype>
28#include <sstream>
29
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010030namespace art {
31
David Brazdilc74652862015-05-13 17:50:09 +010032static bool HasWhitespace(const char* str) {
33 DCHECK(str != nullptr);
34 while (str[0] != 0) {
35 if (isspace(str[0])) {
36 return true;
37 }
38 str++;
39 }
40 return false;
41}
42
43class StringList {
44 public:
45 // Create an empty list
46 StringList() : is_empty_(true) {}
47
48 // Construct StringList from a linked list. List element class T
49 // must provide methods `GetNext` and `Dump`.
50 template<class T>
David Brazdil9f99d922015-05-15 15:15:09 +010051 explicit StringList(T* first_entry) : StringList() {
David Brazdilc74652862015-05-13 17:50:09 +010052 for (T* current = first_entry; current != nullptr; current = current->GetNext()) {
53 current->Dump(NewEntryStream());
54 }
55 }
56
57 std::ostream& NewEntryStream() {
58 if (is_empty_) {
59 is_empty_ = false;
60 } else {
David Brazdilc57397b2015-05-15 16:01:59 +010061 sstream_ << ",";
David Brazdilc74652862015-05-13 17:50:09 +010062 }
63 return sstream_;
64 }
65
66 private:
67 bool is_empty_;
68 std::ostringstream sstream_;
69
70 friend std::ostream& operator<<(std::ostream& os, const StringList& list);
71};
72
73std::ostream& operator<<(std::ostream& os, const StringList& list) {
David Brazdilc57397b2015-05-15 16:01:59 +010074 return os << "[" << list.sstream_.str() << "]";
David Brazdilc74652862015-05-13 17:50:09 +010075}
76
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010077/**
78 * HGraph visitor to generate a file suitable for the c1visualizer tool and IRHydra.
79 */
80class HGraphVisualizerPrinter : public HGraphVisitor {
81 public:
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010082 HGraphVisualizerPrinter(HGraph* graph,
83 std::ostream& output,
84 const char* pass_name,
Nicolas Geoffray840e5462015-01-07 16:01:24 +000085 bool is_after_pass,
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010086 const CodeGenerator& codegen)
87 : HGraphVisitor(graph),
88 output_(output),
89 pass_name_(pass_name),
Nicolas Geoffray840e5462015-01-07 16:01:24 +000090 is_after_pass_(is_after_pass),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010091 codegen_(codegen),
92 indent_(0) {}
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010093
94 void StartTag(const char* name) {
95 AddIndent();
96 output_ << "begin_" << name << std::endl;
97 indent_++;
98 }
99
100 void EndTag(const char* name) {
101 indent_--;
102 AddIndent();
103 output_ << "end_" << name << std::endl;
104 }
105
106 void PrintProperty(const char* name, const char* property) {
107 AddIndent();
108 output_ << name << " \"" << property << "\"" << std::endl;
109 }
110
111 void PrintProperty(const char* name, const char* property, int id) {
112 AddIndent();
113 output_ << name << " \"" << property << id << "\"" << std::endl;
114 }
115
116 void PrintEmptyProperty(const char* name) {
117 AddIndent();
118 output_ << name << std::endl;
119 }
120
121 void PrintTime(const char* name) {
122 AddIndent();
Jean Christophe Beyler0ada95d2014-12-04 11:20:20 -0800123 output_ << name << " " << time(nullptr) << std::endl;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100124 }
125
126 void PrintInt(const char* name, int value) {
127 AddIndent();
128 output_ << name << " " << value << std::endl;
129 }
130
131 void AddIndent() {
132 for (size_t i = 0; i < indent_; ++i) {
133 output_ << " ";
134 }
135 }
136
Nicolas Geoffrayb09aacb2014-09-17 18:21:53 +0100137 char GetTypeId(Primitive::Type type) {
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100138 // Note that Primitive::Descriptor would not work for us
139 // because it does not handle reference types (that is kPrimNot).
Nicolas Geoffrayb09aacb2014-09-17 18:21:53 +0100140 switch (type) {
141 case Primitive::kPrimBoolean: return 'z';
142 case Primitive::kPrimByte: return 'b';
143 case Primitive::kPrimChar: return 'c';
144 case Primitive::kPrimShort: return 's';
145 case Primitive::kPrimInt: return 'i';
146 case Primitive::kPrimLong: return 'j';
147 case Primitive::kPrimFloat: return 'f';
148 case Primitive::kPrimDouble: return 'd';
149 case Primitive::kPrimNot: return 'l';
150 case Primitive::kPrimVoid: return 'v';
151 }
152 LOG(FATAL) << "Unreachable";
153 return 'v';
154 }
155
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100156 void PrintPredecessors(HBasicBlock* block) {
157 AddIndent();
158 output_ << "predecessors";
159 for (size_t i = 0, e = block->GetPredecessors().Size(); i < e; ++i) {
160 HBasicBlock* predecessor = block->GetPredecessors().Get(i);
161 output_ << " \"B" << predecessor->GetBlockId() << "\" ";
162 }
163 output_<< std::endl;
164 }
165
166 void PrintSuccessors(HBasicBlock* block) {
167 AddIndent();
168 output_ << "successors";
169 for (size_t i = 0, e = block->GetSuccessors().Size(); i < e; ++i) {
170 HBasicBlock* successor = block->GetSuccessors().Get(i);
171 output_ << " \"B" << successor->GetBlockId() << "\" ";
172 }
173 output_<< std::endl;
174 }
175
David Brazdilc74652862015-05-13 17:50:09 +0100176 void DumpLocation(std::ostream& stream, const Location& location) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100177 if (location.IsRegister()) {
David Brazdilc74652862015-05-13 17:50:09 +0100178 codegen_.DumpCoreRegister(stream, location.reg());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100179 } else if (location.IsFpuRegister()) {
David Brazdilc74652862015-05-13 17:50:09 +0100180 codegen_.DumpFloatingPointRegister(stream, location.reg());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100181 } else if (location.IsConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100182 stream << "#";
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100183 HConstant* constant = location.GetConstant();
184 if (constant->IsIntConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100185 stream << constant->AsIntConstant()->GetValue();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100186 } else if (constant->IsLongConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100187 stream << constant->AsLongConstant()->GetValue();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100188 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100189 } else if (location.IsInvalid()) {
David Brazdilc74652862015-05-13 17:50:09 +0100190 stream << "invalid";
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100191 } else if (location.IsStackSlot()) {
David Brazdilc74652862015-05-13 17:50:09 +0100192 stream << location.GetStackIndex() << "(sp)";
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000193 } else if (location.IsFpuRegisterPair()) {
David Brazdilc74652862015-05-13 17:50:09 +0100194 codegen_.DumpFloatingPointRegister(stream, location.low());
195 stream << "|";
196 codegen_.DumpFloatingPointRegister(stream, location.high());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000197 } else if (location.IsRegisterPair()) {
David Brazdilc74652862015-05-13 17:50:09 +0100198 codegen_.DumpCoreRegister(stream, location.low());
199 stream << "|";
200 codegen_.DumpCoreRegister(stream, location.high());
Mark Mendell09ed1a32015-03-25 08:30:06 -0400201 } else if (location.IsUnallocated()) {
David Brazdilc74652862015-05-13 17:50:09 +0100202 stream << "unallocated";
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100203 } else {
204 DCHECK(location.IsDoubleStackSlot());
David Brazdilc74652862015-05-13 17:50:09 +0100205 stream << "2x" << location.GetStackIndex() << "(sp)";
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100206 }
207 }
208
David Brazdilc74652862015-05-13 17:50:09 +0100209 std::ostream& StartAttributeStream(const char* name = nullptr) {
210 if (name == nullptr) {
211 output_ << " ";
212 } else {
213 DCHECK(!HasWhitespace(name)) << "Checker does not allow spaces in attributes";
214 output_ << " " << name << ":";
215 }
216 return output_;
217 }
218
David Brazdilb7e4a062014-12-29 15:35:02 +0000219 void VisitParallelMove(HParallelMove* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100220 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
221 StringList moves;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100222 for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) {
223 MoveOperands* move = instruction->MoveOperandsAt(i);
David Brazdilc74652862015-05-13 17:50:09 +0100224 std::ostream& str = moves.NewEntryStream();
225 DumpLocation(str, move->GetSource());
226 str << "->";
227 DumpLocation(str, move->GetDestination());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100228 }
David Brazdilc74652862015-05-13 17:50:09 +0100229 StartAttributeStream("moves") << moves;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100230 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100231
David Brazdil36cf0952015-01-08 19:28:33 +0000232 void VisitIntConstant(HIntConstant* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100233 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000234 }
235
David Brazdil36cf0952015-01-08 19:28:33 +0000236 void VisitLongConstant(HLongConstant* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100237 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000238 }
239
David Brazdil36cf0952015-01-08 19:28:33 +0000240 void VisitFloatConstant(HFloatConstant* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100241 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000242 }
243
David Brazdil36cf0952015-01-08 19:28:33 +0000244 void VisitDoubleConstant(HDoubleConstant* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100245 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000246 }
247
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000248 void VisitPhi(HPhi* phi) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100249 StartAttributeStream("reg") << phi->GetRegNumber();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000250 }
251
Calin Juravle27df7582015-04-17 19:12:31 +0100252 void VisitMemoryBarrier(HMemoryBarrier* barrier) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100253 StartAttributeStream("kind") << barrier->GetBarrierKind();
Calin Juravle27df7582015-04-17 19:12:31 +0100254 }
255
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800256 bool IsPass(const char* name) {
257 return strcmp(pass_name_, name) == 0;
258 }
259
David Brazdilb7e4a062014-12-29 15:35:02 +0000260 void PrintInstruction(HInstruction* instruction) {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100261 output_ << instruction->DebugName();
262 if (instruction->InputCount() > 0) {
David Brazdilc74652862015-05-13 17:50:09 +0100263 StringList inputs;
264 for (HInputIterator it(instruction); !it.Done(); it.Advance()) {
265 inputs.NewEntryStream() << GetTypeId(it.Current()->GetType()) << it.Current()->GetId();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100266 }
David Brazdilc74652862015-05-13 17:50:09 +0100267 StartAttributeStream() << inputs;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100268 }
David Brazdilc74652862015-05-13 17:50:09 +0100269 instruction->Accept(this);
Zheng Xubb7a28a2015-01-09 14:40:47 +0800270 if (instruction->HasEnvironment()) {
David Brazdilc74652862015-05-13 17:50:09 +0100271 StringList envs;
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100272 for (HEnvironment* environment = instruction->GetEnvironment();
273 environment != nullptr;
274 environment = environment->GetParent()) {
David Brazdilc74652862015-05-13 17:50:09 +0100275 StringList vregs;
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100276 for (size_t i = 0, e = environment->Size(); i < e; ++i) {
277 HInstruction* insn = environment->GetInstructionAt(i);
278 if (insn != nullptr) {
David Brazdilc74652862015-05-13 17:50:09 +0100279 vregs.NewEntryStream() << GetTypeId(insn->GetType()) << insn->GetId();
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100280 } else {
David Brazdilc74652862015-05-13 17:50:09 +0100281 vregs.NewEntryStream() << "_";
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100282 }
Zheng Xubb7a28a2015-01-09 14:40:47 +0800283 }
David Brazdilc74652862015-05-13 17:50:09 +0100284 envs.NewEntryStream() << vregs;
Zheng Xubb7a28a2015-01-09 14:40:47 +0800285 }
David Brazdilc74652862015-05-13 17:50:09 +0100286 StartAttributeStream("env") << envs;
Zheng Xubb7a28a2015-01-09 14:40:47 +0800287 }
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800288 if (IsPass(SsaLivenessAnalysis::kLivenessPassName)
David Brazdil5e8b1372015-01-23 14:39:08 +0000289 && is_after_pass_
290 && instruction->GetLifetimePosition() != kNoLifetime) {
David Brazdilc74652862015-05-13 17:50:09 +0100291 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100292 if (instruction->HasLiveInterval()) {
David Brazdilc74652862015-05-13 17:50:09 +0100293 LiveInterval* interval = instruction->GetLiveInterval();
294 StartAttributeStream("ranges") << StringList(interval->GetFirstRange());
295 StartAttributeStream("uses") << StringList(interval->GetFirstUse());
296 StartAttributeStream("env_uses") << StringList(interval->GetFirstEnvironmentUse());
297 StartAttributeStream("is_fixed") << interval->IsFixed();
298 StartAttributeStream("is_split") << interval->IsSplit();
299 StartAttributeStream("is_low") << interval->IsLowInterval();
300 StartAttributeStream("is_high") << interval->IsHighInterval();
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100301 }
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800302 } else if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) {
David Brazdilc74652862015-05-13 17:50:09 +0100303 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100304 LocationSummary* locations = instruction->GetLocations();
305 if (locations != nullptr) {
David Brazdilc74652862015-05-13 17:50:09 +0100306 StringList inputs;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100307 for (size_t i = 0; i < instruction->InputCount(); ++i) {
David Brazdilc74652862015-05-13 17:50:09 +0100308 DumpLocation(inputs.NewEntryStream(), locations->InAt(i));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100309 }
David Brazdilc74652862015-05-13 17:50:09 +0100310 std::ostream& attr = StartAttributeStream("locations");
311 attr << inputs << "->";
312 DumpLocation(attr, locations->Out());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100313 }
David Brazdila4b8c212015-05-07 09:59:30 +0100314 } else if (IsPass(LICM::kLoopInvariantCodeMotionPassName)
315 || IsPass(HDeadCodeElimination::kFinalDeadCodeEliminationPassName)) {
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000316 HLoopInformation* info = instruction->GetBlock()->GetLoopInformation();
317 if (info == nullptr) {
David Brazdilc74652862015-05-13 17:50:09 +0100318 StartAttributeStream("loop") << "none";
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000319 } else {
David Brazdilc74652862015-05-13 17:50:09 +0100320 StartAttributeStream("loop") << "B" << info->GetHeader()->GetBlockId();
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000321 }
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100322 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100323 }
324
325 void PrintInstructions(const HInstructionList& list) {
326 const char* kEndInstructionMarker = "<|@";
327 for (HInstructionIterator it(list); !it.Done(); it.Advance()) {
328 HInstruction* instruction = it.Current();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100329 int bci = 0;
David Brazdilea55b932015-01-27 17:12:29 +0000330 size_t num_uses = 0;
331 for (HUseIterator<HInstruction*> use_it(instruction->GetUses());
332 !use_it.Done();
333 use_it.Advance()) {
334 ++num_uses;
335 }
336 AddIndent();
337 output_ << bci << " " << num_uses << " "
338 << GetTypeId(instruction->GetType()) << instruction->GetId() << " ";
David Brazdilb7e4a062014-12-29 15:35:02 +0000339 PrintInstruction(instruction);
David Brazdilc74652862015-05-13 17:50:09 +0100340 output_ << " " << kEndInstructionMarker << std::endl;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100341 }
342 }
343
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100344 void Run() {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100345 StartTag("cfg");
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000346 std::string pass_desc = std::string(pass_name_) + (is_after_pass_ ? " (after)" : " (before)");
347 PrintProperty("name", pass_desc.c_str());
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100348 VisitInsertionOrder();
349 EndTag("cfg");
350 }
351
David Brazdilb7e4a062014-12-29 15:35:02 +0000352 void VisitBasicBlock(HBasicBlock* block) OVERRIDE {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100353 StartTag("block");
354 PrintProperty("name", "B", block->GetBlockId());
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100355 if (block->GetLifetimeStart() != kNoLifetime) {
356 // Piggy back on these fields to show the lifetime of the block.
357 PrintInt("from_bci", block->GetLifetimeStart());
358 PrintInt("to_bci", block->GetLifetimeEnd());
359 } else {
360 PrintInt("from_bci", -1);
361 PrintInt("to_bci", -1);
362 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100363 PrintPredecessors(block);
364 PrintSuccessors(block);
365 PrintEmptyProperty("xhandlers");
366 PrintEmptyProperty("flags");
367 if (block->GetDominator() != nullptr) {
368 PrintProperty("dominator", "B", block->GetDominator()->GetBlockId());
369 }
370
371 StartTag("states");
372 StartTag("locals");
373 PrintInt("size", 0);
374 PrintProperty("method", "None");
375 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
376 AddIndent();
377 HInstruction* instruction = it.Current();
Nicolas Geoffrayb09aacb2014-09-17 18:21:53 +0100378 output_ << instruction->GetId() << " " << GetTypeId(instruction->GetType())
379 << instruction->GetId() << "[ ";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100380 for (HInputIterator inputs(instruction); !inputs.Done(); inputs.Advance()) {
381 output_ << inputs.Current()->GetId() << " ";
382 }
383 output_ << "]" << std::endl;
384 }
385 EndTag("locals");
386 EndTag("states");
387
388 StartTag("HIR");
389 PrintInstructions(block->GetPhis());
390 PrintInstructions(block->GetInstructions());
391 EndTag("HIR");
392 EndTag("block");
393 }
394
395 private:
396 std::ostream& output_;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100397 const char* pass_name_;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000398 const bool is_after_pass_;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100399 const CodeGenerator& codegen_;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100400 size_t indent_;
401
402 DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter);
403};
404
405HGraphVisualizer::HGraphVisualizer(std::ostream* output,
406 HGraph* graph,
David Brazdil62e074f2015-04-07 18:09:37 +0100407 const CodeGenerator& codegen)
408 : output_(output), graph_(graph), codegen_(codegen) {}
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100409
David Brazdil62e074f2015-04-07 18:09:37 +0100410void HGraphVisualizer::PrintHeader(const char* method_name) const {
411 DCHECK(output_ != nullptr);
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000412 HGraphVisualizerPrinter printer(graph_, *output_, "", true, codegen_);
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100413 printer.StartTag("compilation");
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000414 printer.PrintProperty("name", method_name);
415 printer.PrintProperty("method", method_name);
Nicolas Geoffray0d3f5782014-05-14 09:43:38 +0100416 printer.PrintTime("date");
417 printer.EndTag("compilation");
418}
419
David Brazdilee690a32014-12-01 17:04:16 +0000420void HGraphVisualizer::DumpGraph(const char* pass_name, bool is_after_pass) const {
David Brazdil5e8b1372015-01-23 14:39:08 +0000421 DCHECK(output_ != nullptr);
422 if (!graph_->GetBlocks().IsEmpty()) {
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000423 HGraphVisualizerPrinter printer(graph_, *output_, pass_name, is_after_pass, codegen_);
David Brazdilee690a32014-12-01 17:04:16 +0000424 printer.Run();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100425 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100426}
427
428} // namespace art