blob: 4b5b919b682ca2563b68c2fe07e03b7eb6b6a85d [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
Alexandre Rameseb7b7392015-06-19 14:47:01 +010019#include <dlfcn.h>
20
21#include <cctype>
22#include <sstream>
23
Aart Bik09e8d5f2016-01-22 16:49:55 -080024#include "bounds_check_elimination.h"
David Brazdilbadd8262016-02-02 16:28:56 +000025#include "builder.h"
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010026#include "code_generator.h"
David Brazdila4b8c212015-05-07 09:59:30 +010027#include "dead_code_elimination.h"
Alexandre Rameseb7b7392015-06-19 14:47:01 +010028#include "disassembler.h"
Calin Juravlecdfed3d2015-10-26 14:05:01 +000029#include "inliner.h"
Andreas Gampe7c3952f2015-02-19 18:21:24 -080030#include "licm.h"
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010031#include "nodes.h"
Nicolas Geoffray82091da2015-01-26 10:02:45 +000032#include "optimization.h"
Nicolas Geoffray7cb499b2015-06-17 11:35:11 +010033#include "reference_type_propagation.h"
Andreas Gampe7c3952f2015-02-19 18:21:24 -080034#include "register_allocator.h"
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +010035#include "ssa_liveness_analysis.h"
Alexandre Rameseb7b7392015-06-19 14:47:01 +010036#include "utils/assembler.h"
David Brazdilc74652862015-05-13 17:50:09 +010037
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010038namespace art {
39
David Brazdilc74652862015-05-13 17:50:09 +010040static bool HasWhitespace(const char* str) {
41 DCHECK(str != nullptr);
42 while (str[0] != 0) {
43 if (isspace(str[0])) {
44 return true;
45 }
46 str++;
47 }
48 return false;
49}
50
51class StringList {
52 public:
David Brazdilc7a24852015-05-15 16:44:05 +010053 enum Format {
54 kArrayBrackets,
55 kSetBrackets,
56 };
57
David Brazdilc74652862015-05-13 17:50:09 +010058 // Create an empty list
David Brazdilf1a9ff72015-05-18 16:04:53 +010059 explicit StringList(Format format = kArrayBrackets) : format_(format), is_empty_(true) {}
David Brazdilc74652862015-05-13 17:50:09 +010060
61 // Construct StringList from a linked list. List element class T
62 // must provide methods `GetNext` and `Dump`.
63 template<class T>
David Brazdilc7a24852015-05-15 16:44:05 +010064 explicit StringList(T* first_entry, Format format = kArrayBrackets) : StringList(format) {
David Brazdilc74652862015-05-13 17:50:09 +010065 for (T* current = first_entry; current != nullptr; current = current->GetNext()) {
66 current->Dump(NewEntryStream());
67 }
68 }
69
70 std::ostream& NewEntryStream() {
71 if (is_empty_) {
72 is_empty_ = false;
73 } else {
David Brazdilc57397b2015-05-15 16:01:59 +010074 sstream_ << ",";
David Brazdilc74652862015-05-13 17:50:09 +010075 }
76 return sstream_;
77 }
78
79 private:
David Brazdilc7a24852015-05-15 16:44:05 +010080 Format format_;
David Brazdilc74652862015-05-13 17:50:09 +010081 bool is_empty_;
82 std::ostringstream sstream_;
83
84 friend std::ostream& operator<<(std::ostream& os, const StringList& list);
85};
86
87std::ostream& operator<<(std::ostream& os, const StringList& list) {
David Brazdilc7a24852015-05-15 16:44:05 +010088 switch (list.format_) {
89 case StringList::kArrayBrackets: return os << "[" << list.sstream_.str() << "]";
90 case StringList::kSetBrackets: return os << "{" << list.sstream_.str() << "}";
91 default:
92 LOG(FATAL) << "Invalid StringList format";
93 UNREACHABLE();
94 }
David Brazdilc74652862015-05-13 17:50:09 +010095}
96
Alexandre Rameseb7b7392015-06-19 14:47:01 +010097typedef Disassembler* create_disasm_prototype(InstructionSet instruction_set,
98 DisassemblerOptions* options);
99class HGraphVisualizerDisassembler {
100 public:
101 HGraphVisualizerDisassembler(InstructionSet instruction_set, const uint8_t* base_address)
David Brazdil3a690be2015-06-23 10:22:38 +0100102 : instruction_set_(instruction_set), disassembler_(nullptr) {
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100103 libart_disassembler_handle_ =
104 dlopen(kIsDebugBuild ? "libartd-disassembler.so" : "libart-disassembler.so", RTLD_NOW);
105 if (libart_disassembler_handle_ == nullptr) {
106 LOG(WARNING) << "Failed to dlopen libart-disassembler: " << dlerror();
107 return;
108 }
109 create_disasm_prototype* create_disassembler = reinterpret_cast<create_disasm_prototype*>(
110 dlsym(libart_disassembler_handle_, "create_disassembler"));
111 if (create_disassembler == nullptr) {
112 LOG(WARNING) << "Could not find create_disassembler entry: " << dlerror();
113 return;
114 }
115 // Reading the disassembly from 0x0 is easier, so we print relative
116 // addresses. We will only disassemble the code once everything has
117 // been generated, so we can read data in literal pools.
118 disassembler_ = std::unique_ptr<Disassembler>((*create_disassembler)(
119 instruction_set,
120 new DisassemblerOptions(/* absolute_addresses */ false,
121 base_address,
122 /* can_read_literals */ true)));
123 }
124
125 ~HGraphVisualizerDisassembler() {
126 // We need to call ~Disassembler() before we close the library.
127 disassembler_.reset();
128 if (libart_disassembler_handle_ != nullptr) {
129 dlclose(libart_disassembler_handle_);
130 }
131 }
132
133 void Disassemble(std::ostream& output, size_t start, size_t end) const {
David Brazdil3a690be2015-06-23 10:22:38 +0100134 if (disassembler_ == nullptr) {
135 return;
136 }
137
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100138 const uint8_t* base = disassembler_->GetDisassemblerOptions()->base_address_;
139 if (instruction_set_ == kThumb2) {
140 // ARM and Thumb-2 use the same disassembler. The bottom bit of the
141 // address is used to distinguish between the two.
142 base += 1;
143 }
144 disassembler_->Dump(output, base + start, base + end);
145 }
146
147 private:
148 InstructionSet instruction_set_;
149 std::unique_ptr<Disassembler> disassembler_;
150
151 void* libart_disassembler_handle_;
152};
153
154
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100155/**
156 * HGraph visitor to generate a file suitable for the c1visualizer tool and IRHydra.
157 */
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100158class HGraphVisualizerPrinter : public HGraphDelegateVisitor {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100159 public:
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100160 HGraphVisualizerPrinter(HGraph* graph,
161 std::ostream& output,
162 const char* pass_name,
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000163 bool is_after_pass,
David Brazdilffee3d32015-07-06 11:48:53 +0100164 bool graph_in_bad_state,
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100165 const CodeGenerator& codegen,
166 const DisassemblyInformation* disasm_info = nullptr)
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100167 : HGraphDelegateVisitor(graph),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100168 output_(output),
169 pass_name_(pass_name),
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000170 is_after_pass_(is_after_pass),
David Brazdilffee3d32015-07-06 11:48:53 +0100171 graph_in_bad_state_(graph_in_bad_state),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100172 codegen_(codegen),
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100173 disasm_info_(disasm_info),
174 disassembler_(disasm_info_ != nullptr
175 ? new HGraphVisualizerDisassembler(
176 codegen_.GetInstructionSet(),
177 codegen_.GetAssembler().CodeBufferBaseAddress())
178 : nullptr),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100179 indent_(0) {}
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100180
181 void StartTag(const char* name) {
182 AddIndent();
183 output_ << "begin_" << name << std::endl;
184 indent_++;
185 }
186
187 void EndTag(const char* name) {
188 indent_--;
189 AddIndent();
190 output_ << "end_" << name << std::endl;
191 }
192
193 void PrintProperty(const char* name, const char* property) {
194 AddIndent();
195 output_ << name << " \"" << property << "\"" << std::endl;
196 }
197
198 void PrintProperty(const char* name, const char* property, int id) {
199 AddIndent();
200 output_ << name << " \"" << property << id << "\"" << std::endl;
201 }
202
203 void PrintEmptyProperty(const char* name) {
204 AddIndent();
205 output_ << name << std::endl;
206 }
207
208 void PrintTime(const char* name) {
209 AddIndent();
Jean Christophe Beyler0ada95d2014-12-04 11:20:20 -0800210 output_ << name << " " << time(nullptr) << std::endl;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100211 }
212
213 void PrintInt(const char* name, int value) {
214 AddIndent();
215 output_ << name << " " << value << std::endl;
216 }
217
218 void AddIndent() {
219 for (size_t i = 0; i < indent_; ++i) {
220 output_ << " ";
221 }
222 }
223
Nicolas Geoffrayb09aacb2014-09-17 18:21:53 +0100224 char GetTypeId(Primitive::Type type) {
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100225 // Note that Primitive::Descriptor would not work for us
226 // because it does not handle reference types (that is kPrimNot).
Nicolas Geoffrayb09aacb2014-09-17 18:21:53 +0100227 switch (type) {
228 case Primitive::kPrimBoolean: return 'z';
229 case Primitive::kPrimByte: return 'b';
230 case Primitive::kPrimChar: return 'c';
231 case Primitive::kPrimShort: return 's';
232 case Primitive::kPrimInt: return 'i';
233 case Primitive::kPrimLong: return 'j';
234 case Primitive::kPrimFloat: return 'f';
235 case Primitive::kPrimDouble: return 'd';
236 case Primitive::kPrimNot: return 'l';
237 case Primitive::kPrimVoid: return 'v';
238 }
239 LOG(FATAL) << "Unreachable";
240 return 'v';
241 }
242
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100243 void PrintPredecessors(HBasicBlock* block) {
244 AddIndent();
245 output_ << "predecessors";
Vladimir Marko60584552015-09-03 13:35:12 +0000246 for (HBasicBlock* predecessor : block->GetPredecessors()) {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100247 output_ << " \"B" << predecessor->GetBlockId() << "\" ";
248 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100249 if (block->IsEntryBlock() && (disasm_info_ != nullptr)) {
250 output_ << " \"" << kDisassemblyBlockFrameEntry << "\" ";
251 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100252 output_<< std::endl;
253 }
254
255 void PrintSuccessors(HBasicBlock* block) {
256 AddIndent();
257 output_ << "successors";
David Brazdild26a4112015-11-10 11:07:31 +0000258 for (HBasicBlock* successor : block->GetNormalSuccessors()) {
David Brazdilffee3d32015-07-06 11:48:53 +0100259 output_ << " \"B" << successor->GetBlockId() << "\" ";
David Brazdilfc6a86a2015-06-26 10:33:45 +0000260 }
261 output_<< std::endl;
262 }
263
264 void PrintExceptionHandlers(HBasicBlock* block) {
265 AddIndent();
266 output_ << "xhandlers";
David Brazdild26a4112015-11-10 11:07:31 +0000267 for (HBasicBlock* handler : block->GetExceptionalSuccessors()) {
David Brazdilffee3d32015-07-06 11:48:53 +0100268 output_ << " \"B" << handler->GetBlockId() << "\" ";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100269 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100270 if (block->IsExitBlock() &&
271 (disasm_info_ != nullptr) &&
272 !disasm_info_->GetSlowPathIntervals().empty()) {
273 output_ << " \"" << kDisassemblyBlockSlowPaths << "\" ";
274 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100275 output_<< std::endl;
276 }
277
David Brazdilc74652862015-05-13 17:50:09 +0100278 void DumpLocation(std::ostream& stream, const Location& location) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100279 if (location.IsRegister()) {
David Brazdilc74652862015-05-13 17:50:09 +0100280 codegen_.DumpCoreRegister(stream, location.reg());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100281 } else if (location.IsFpuRegister()) {
David Brazdilc74652862015-05-13 17:50:09 +0100282 codegen_.DumpFloatingPointRegister(stream, location.reg());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100283 } else if (location.IsConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100284 stream << "#";
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100285 HConstant* constant = location.GetConstant();
286 if (constant->IsIntConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100287 stream << constant->AsIntConstant()->GetValue();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100288 } else if (constant->IsLongConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100289 stream << constant->AsLongConstant()->GetValue();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100290 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100291 } else if (location.IsInvalid()) {
David Brazdilc74652862015-05-13 17:50:09 +0100292 stream << "invalid";
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100293 } else if (location.IsStackSlot()) {
David Brazdilc74652862015-05-13 17:50:09 +0100294 stream << location.GetStackIndex() << "(sp)";
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000295 } else if (location.IsFpuRegisterPair()) {
David Brazdilc74652862015-05-13 17:50:09 +0100296 codegen_.DumpFloatingPointRegister(stream, location.low());
297 stream << "|";
298 codegen_.DumpFloatingPointRegister(stream, location.high());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000299 } else if (location.IsRegisterPair()) {
David Brazdilc74652862015-05-13 17:50:09 +0100300 codegen_.DumpCoreRegister(stream, location.low());
301 stream << "|";
302 codegen_.DumpCoreRegister(stream, location.high());
Mark Mendell09ed1a32015-03-25 08:30:06 -0400303 } else if (location.IsUnallocated()) {
David Brazdilc74652862015-05-13 17:50:09 +0100304 stream << "unallocated";
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100305 } else {
306 DCHECK(location.IsDoubleStackSlot());
David Brazdilc74652862015-05-13 17:50:09 +0100307 stream << "2x" << location.GetStackIndex() << "(sp)";
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100308 }
309 }
310
David Brazdilc74652862015-05-13 17:50:09 +0100311 std::ostream& StartAttributeStream(const char* name = nullptr) {
312 if (name == nullptr) {
313 output_ << " ";
314 } else {
315 DCHECK(!HasWhitespace(name)) << "Checker does not allow spaces in attributes";
316 output_ << " " << name << ":";
317 }
318 return output_;
319 }
320
David Brazdilb7e4a062014-12-29 15:35:02 +0000321 void VisitParallelMove(HParallelMove* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100322 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
323 StringList moves;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100324 for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) {
325 MoveOperands* move = instruction->MoveOperandsAt(i);
David Brazdilc74652862015-05-13 17:50:09 +0100326 std::ostream& str = moves.NewEntryStream();
327 DumpLocation(str, move->GetSource());
328 str << "->";
329 DumpLocation(str, move->GetDestination());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100330 }
David Brazdilc74652862015-05-13 17:50:09 +0100331 StartAttributeStream("moves") << moves;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100332 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100333
David Brazdil36cf0952015-01-08 19:28:33 +0000334 void VisitIntConstant(HIntConstant* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100335 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000336 }
337
David Brazdil36cf0952015-01-08 19:28:33 +0000338 void VisitLongConstant(HLongConstant* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100339 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000340 }
341
David Brazdil36cf0952015-01-08 19:28:33 +0000342 void VisitFloatConstant(HFloatConstant* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100343 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000344 }
345
David Brazdil36cf0952015-01-08 19:28:33 +0000346 void VisitDoubleConstant(HDoubleConstant* instruction) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100347 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000348 }
349
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000350 void VisitPhi(HPhi* phi) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100351 StartAttributeStream("reg") << phi->GetRegNumber();
David Brazdilffee3d32015-07-06 11:48:53 +0100352 StartAttributeStream("is_catch_phi") << std::boolalpha << phi->IsCatchPhi() << std::noboolalpha;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000353 }
354
Calin Juravle27df7582015-04-17 19:12:31 +0100355 void VisitMemoryBarrier(HMemoryBarrier* barrier) OVERRIDE {
David Brazdilc74652862015-05-13 17:50:09 +0100356 StartAttributeStream("kind") << barrier->GetBarrierKind();
Calin Juravle27df7582015-04-17 19:12:31 +0100357 }
358
David Brazdilbff75032015-07-08 17:26:51 +0000359 void VisitMonitorOperation(HMonitorOperation* monitor) OVERRIDE {
360 StartAttributeStream("kind") << (monitor->IsEnter() ? "enter" : "exit");
361 }
362
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100363 void VisitLoadClass(HLoadClass* load_class) OVERRIDE {
Calin Juravle0ba218d2015-05-19 18:46:01 +0100364 StartAttributeStream("gen_clinit_check") << std::boolalpha
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100365 << load_class->MustGenerateClinitCheck() << std::noboolalpha;
Calin Juravle386062d2015-10-07 18:55:43 +0100366 StartAttributeStream("needs_access_check") << std::boolalpha
367 << load_class->NeedsAccessCheck() << std::noboolalpha;
Calin Juravle0ba218d2015-05-19 18:46:01 +0100368 }
369
Guillaume "Vermeille" Sanchez9099ef72015-05-20 15:19:21 +0100370 void VisitCheckCast(HCheckCast* check_cast) OVERRIDE {
Roland Levillain86503782016-02-11 19:07:30 +0000371 StartAttributeStream("check_kind") << check_cast->GetTypeCheckKind();
Guillaume "Vermeille" Sanchez9099ef72015-05-20 15:19:21 +0100372 StartAttributeStream("must_do_null_check") << std::boolalpha
373 << check_cast->MustDoNullCheck() << std::noboolalpha;
374 }
375
376 void VisitInstanceOf(HInstanceOf* instance_of) OVERRIDE {
Roland Levillain86503782016-02-11 19:07:30 +0000377 StartAttributeStream("check_kind") << instance_of->GetTypeCheckKind();
Guillaume "Vermeille" Sanchez9099ef72015-05-20 15:19:21 +0100378 StartAttributeStream("must_do_null_check") << std::boolalpha
379 << instance_of->MustDoNullCheck() << std::noboolalpha;
380 }
381
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100382 void VisitArraySet(HArraySet* array_set) OVERRIDE {
383 StartAttributeStream("value_can_be_null") << std::boolalpha
384 << array_set->GetValueCanBeNull() << std::noboolalpha;
Roland Levillainb133ec62016-03-23 12:40:35 +0000385 StartAttributeStream("needs_type_check") << std::boolalpha
386 << array_set->NeedsTypeCheck() << std::noboolalpha;
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100387 }
388
Roland Levillain31dd3d62016-02-16 12:21:02 +0000389 void VisitCompare(HCompare* compare) OVERRIDE {
390 ComparisonBias bias = compare->GetBias();
391 StartAttributeStream("bias") << (bias == ComparisonBias::kGtBias
392 ? "gt"
393 : (bias == ComparisonBias::kLtBias ? "lt" : "none"));
394 }
395
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100396 void VisitInvoke(HInvoke* invoke) OVERRIDE {
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100397 StartAttributeStream("dex_file_index") << invoke->GetDexMethodIndex();
Nicolas Geoffray242febb2015-07-01 16:10:44 +0100398 StartAttributeStream("method_name") << PrettyMethod(
399 invoke->GetDexMethodIndex(), GetGraph()->GetDexFile(), /* with_signature */ false);
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100400 }
401
Calin Juravle175dc732015-08-25 15:42:32 +0100402 void VisitInvokeUnresolved(HInvokeUnresolved* invoke) OVERRIDE {
403 VisitInvoke(invoke);
404 StartAttributeStream("invoke_type") << invoke->GetOriginalInvokeType();
405 }
406
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100407 void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE {
408 VisitInvoke(invoke);
Vladimir Markof64242a2015-12-01 14:58:23 +0000409 StartAttributeStream("method_load_kind") << invoke->GetMethodLoadKind();
Scott Wakelingd60a1af2015-07-22 14:32:44 +0100410 StartAttributeStream("intrinsic") << invoke->GetIntrinsic();
Vladimir Markofbb184a2015-11-13 14:47:00 +0000411 if (invoke->IsStatic()) {
412 StartAttributeStream("clinit_check") << invoke->GetClinitCheckRequirement();
413 }
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100414 }
415
Nicolas Geoffraye5234232015-12-02 09:06:11 +0000416 void VisitInvokeVirtual(HInvokeVirtual* invoke) OVERRIDE {
417 VisitInvoke(invoke);
418 StartAttributeStream("intrinsic") << invoke->GetIntrinsic();
419 }
420
David Brazdil11edec72016-03-24 12:40:52 +0000421 void VisitInstanceFieldGet(HInstanceFieldGet* iget) OVERRIDE {
422 StartAttributeStream("field_name") << PrettyField(iget->GetFieldInfo().GetFieldIndex(),
423 iget->GetFieldInfo().GetDexFile(),
424 /* with type */ false);
425 StartAttributeStream("field_type") << iget->GetFieldType();
426 }
427
428 void VisitInstanceFieldSet(HInstanceFieldSet* iset) OVERRIDE {
429 StartAttributeStream("field_name") << PrettyField(iset->GetFieldInfo().GetFieldIndex(),
430 iset->GetFieldInfo().GetDexFile(),
431 /* with type */ false);
432 StartAttributeStream("field_type") << iset->GetFieldType();
433 }
434
Calin Juravlee460d1d2015-09-29 04:52:17 +0100435 void VisitUnresolvedInstanceFieldGet(HUnresolvedInstanceFieldGet* field_access) OVERRIDE {
436 StartAttributeStream("field_type") << field_access->GetFieldType();
437 }
438
439 void VisitUnresolvedInstanceFieldSet(HUnresolvedInstanceFieldSet* field_access) OVERRIDE {
440 StartAttributeStream("field_type") << field_access->GetFieldType();
441 }
442
443 void VisitUnresolvedStaticFieldGet(HUnresolvedStaticFieldGet* field_access) OVERRIDE {
444 StartAttributeStream("field_type") << field_access->GetFieldType();
445 }
446
447 void VisitUnresolvedStaticFieldSet(HUnresolvedStaticFieldSet* field_access) OVERRIDE {
448 StartAttributeStream("field_type") << field_access->GetFieldType();
449 }
450
David Brazdilfc6a86a2015-06-26 10:33:45 +0000451 void VisitTryBoundary(HTryBoundary* try_boundary) OVERRIDE {
David Brazdil56e1acc2015-06-30 15:41:36 +0100452 StartAttributeStream("kind") << (try_boundary->IsEntry() ? "entry" : "exit");
David Brazdilfc6a86a2015-06-26 10:33:45 +0000453 }
454
Artem Udovichenko4a0dad62016-01-26 12:28:31 +0300455#if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64)
456 void VisitMultiplyAccumulate(HMultiplyAccumulate* instruction) OVERRIDE {
457 StartAttributeStream("kind") << instruction->GetOpKind();
458 }
Artem Serov7fc63502016-02-09 17:15:29 +0000459
460 void VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) OVERRIDE {
461 StartAttributeStream("kind") << instruction->GetOpKind();
462 }
Artem Udovichenko4a0dad62016-01-26 12:28:31 +0300463#endif
464
Alexandre Rames418318f2015-11-20 15:55:47 +0000465#ifdef ART_ENABLE_CODEGEN_arm64
Alexandre Rames8626b742015-11-25 16:28:08 +0000466 void VisitArm64DataProcWithShifterOp(HArm64DataProcWithShifterOp* instruction) OVERRIDE {
467 StartAttributeStream("kind") << instruction->GetInstrKind() << "+" << instruction->GetOpKind();
468 if (HArm64DataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())) {
469 StartAttributeStream("shift") << instruction->GetShiftAmount();
470 }
471 }
Alexandre Rames418318f2015-11-20 15:55:47 +0000472#endif
473
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800474 bool IsPass(const char* name) {
475 return strcmp(pass_name_, name) == 0;
476 }
477
David Brazdilb7e4a062014-12-29 15:35:02 +0000478 void PrintInstruction(HInstruction* instruction) {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100479 output_ << instruction->DebugName();
480 if (instruction->InputCount() > 0) {
David Brazdilc74652862015-05-13 17:50:09 +0100481 StringList inputs;
482 for (HInputIterator it(instruction); !it.Done(); it.Advance()) {
483 inputs.NewEntryStream() << GetTypeId(it.Current()->GetType()) << it.Current()->GetId();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100484 }
David Brazdilc74652862015-05-13 17:50:09 +0100485 StartAttributeStream() << inputs;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100486 }
David Brazdilc74652862015-05-13 17:50:09 +0100487 instruction->Accept(this);
Zheng Xubb7a28a2015-01-09 14:40:47 +0800488 if (instruction->HasEnvironment()) {
David Brazdilc74652862015-05-13 17:50:09 +0100489 StringList envs;
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100490 for (HEnvironment* environment = instruction->GetEnvironment();
491 environment != nullptr;
492 environment = environment->GetParent()) {
David Brazdilc74652862015-05-13 17:50:09 +0100493 StringList vregs;
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100494 for (size_t i = 0, e = environment->Size(); i < e; ++i) {
495 HInstruction* insn = environment->GetInstructionAt(i);
496 if (insn != nullptr) {
David Brazdilc74652862015-05-13 17:50:09 +0100497 vregs.NewEntryStream() << GetTypeId(insn->GetType()) << insn->GetId();
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100498 } else {
David Brazdilc74652862015-05-13 17:50:09 +0100499 vregs.NewEntryStream() << "_";
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100500 }
Zheng Xubb7a28a2015-01-09 14:40:47 +0800501 }
David Brazdilc74652862015-05-13 17:50:09 +0100502 envs.NewEntryStream() << vregs;
Zheng Xubb7a28a2015-01-09 14:40:47 +0800503 }
David Brazdilc74652862015-05-13 17:50:09 +0100504 StartAttributeStream("env") << envs;
Zheng Xubb7a28a2015-01-09 14:40:47 +0800505 }
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800506 if (IsPass(SsaLivenessAnalysis::kLivenessPassName)
David Brazdil5e8b1372015-01-23 14:39:08 +0000507 && is_after_pass_
508 && instruction->GetLifetimePosition() != kNoLifetime) {
David Brazdilc74652862015-05-13 17:50:09 +0100509 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100510 if (instruction->HasLiveInterval()) {
David Brazdilc74652862015-05-13 17:50:09 +0100511 LiveInterval* interval = instruction->GetLiveInterval();
David Brazdilc7a24852015-05-15 16:44:05 +0100512 StartAttributeStream("ranges")
513 << StringList(interval->GetFirstRange(), StringList::kSetBrackets);
David Brazdilc74652862015-05-13 17:50:09 +0100514 StartAttributeStream("uses") << StringList(interval->GetFirstUse());
515 StartAttributeStream("env_uses") << StringList(interval->GetFirstEnvironmentUse());
516 StartAttributeStream("is_fixed") << interval->IsFixed();
517 StartAttributeStream("is_split") << interval->IsSplit();
518 StartAttributeStream("is_low") << interval->IsLowInterval();
519 StartAttributeStream("is_high") << interval->IsHighInterval();
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100520 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000521 }
522
523 if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) {
David Brazdilc74652862015-05-13 17:50:09 +0100524 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100525 LocationSummary* locations = instruction->GetLocations();
526 if (locations != nullptr) {
David Brazdilc74652862015-05-13 17:50:09 +0100527 StringList inputs;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100528 for (size_t i = 0; i < instruction->InputCount(); ++i) {
David Brazdilc74652862015-05-13 17:50:09 +0100529 DumpLocation(inputs.NewEntryStream(), locations->InAt(i));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100530 }
David Brazdilc74652862015-05-13 17:50:09 +0100531 std::ostream& attr = StartAttributeStream("locations");
532 attr << inputs << "->";
533 DumpLocation(attr, locations->Out());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100534 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000535 }
536
537 if (IsPass(LICM::kLoopInvariantCodeMotionPassName)
538 || IsPass(HDeadCodeElimination::kFinalDeadCodeEliminationPassName)
539 || IsPass(HDeadCodeElimination::kInitialDeadCodeEliminationPassName)
Aart Bik09e8d5f2016-01-22 16:49:55 -0800540 || IsPass(BoundsCheckElimination::kBoundsCheckEliminationPassName)
Nicolas Geoffrayad4ed082016-01-27 14:15:23 +0000541 || IsPass(RegisterAllocator::kRegisterAllocatorPassName)
David Brazdilbadd8262016-02-02 16:28:56 +0000542 || IsPass(HGraphBuilder::kBuilderPassName)) {
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000543 HLoopInformation* info = instruction->GetBlock()->GetLoopInformation();
544 if (info == nullptr) {
David Brazdilc74652862015-05-13 17:50:09 +0100545 StartAttributeStream("loop") << "none";
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000546 } else {
David Brazdilc74652862015-05-13 17:50:09 +0100547 StartAttributeStream("loop") << "B" << info->GetHeader()->GetBlockId();
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000548 HLoopInformation* outer = info->GetPreHeader()->GetLoopInformation();
549 if (outer != nullptr) {
550 StartAttributeStream("outer_loop") << "B" << outer->GetHeader()->GetBlockId();
551 } else {
552 StartAttributeStream("outer_loop") << "none";
553 }
554 StartAttributeStream("irreducible")
555 << std::boolalpha << info->IsIrreducible() << std::noboolalpha;
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000556 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000557 }
558
David Brazdilbadd8262016-02-02 16:28:56 +0000559 if ((IsPass(HGraphBuilder::kBuilderPassName)
Calin Juravlecdfed3d2015-10-26 14:05:01 +0000560 || IsPass(HInliner::kInlinerPassName))
Calin Juravle2e768302015-07-28 14:41:11 +0000561 && (instruction->GetType() == Primitive::kPrimNot)) {
562 ReferenceTypeInfo info = instruction->IsLoadClass()
563 ? instruction->AsLoadClass()->GetLoadedClassRTI()
564 : instruction->GetReferenceTypeInfo();
565 ScopedObjectAccess soa(Thread::Current());
566 if (info.IsValid()) {
567 StartAttributeStream("klass") << PrettyDescriptor(info.GetTypeHandle().Get());
568 StartAttributeStream("can_be_null")
569 << std::boolalpha << instruction->CanBeNull() << std::noboolalpha;
570 StartAttributeStream("exact") << std::boolalpha << info.IsExact() << std::noboolalpha;
Calin Juravle98893e12015-10-02 21:05:03 +0100571 } else if (instruction->IsLoadClass()) {
572 StartAttributeStream("klass") << "unresolved";
David Brazdil4833f5a2015-12-16 10:37:39 +0000573 } else {
Mark Mendellb2d38fd2015-11-16 12:21:53 -0500574 // The NullConstant may be added to the graph during other passes that happen between
575 // ReferenceTypePropagation and Inliner (e.g. InstructionSimplifier). If the inliner
576 // doesn't run or doesn't inline anything, the NullConstant remains untyped.
577 // So we should check NullConstants for validity only after reference type propagation.
David Brazdil4833f5a2015-12-16 10:37:39 +0000578 DCHECK(graph_in_bad_state_ ||
David Brazdilbadd8262016-02-02 16:28:56 +0000579 (!is_after_pass_ && IsPass(HGraphBuilder::kBuilderPassName)))
David Brazdil4833f5a2015-12-16 10:37:39 +0000580 << instruction->DebugName() << instruction->GetId() << " has invalid rti "
581 << (is_after_pass_ ? "after" : "before") << " pass " << pass_name_;
Nicolas Geoffray7cb499b2015-06-17 11:35:11 +0100582 }
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100583 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100584 if (disasm_info_ != nullptr) {
585 DCHECK(disassembler_ != nullptr);
586 // If the information is available, disassemble the code generated for
587 // this instruction.
588 auto it = disasm_info_->GetInstructionIntervals().find(instruction);
589 if (it != disasm_info_->GetInstructionIntervals().end()
590 && it->second.start != it->second.end) {
591 output_ << std::endl;
592 disassembler_->Disassemble(output_, it->second.start, it->second.end);
593 }
594 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100595 }
596
597 void PrintInstructions(const HInstructionList& list) {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100598 for (HInstructionIterator it(list); !it.Done(); it.Advance()) {
599 HInstruction* instruction = it.Current();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100600 int bci = 0;
David Brazdilea55b932015-01-27 17:12:29 +0000601 size_t num_uses = 0;
602 for (HUseIterator<HInstruction*> use_it(instruction->GetUses());
603 !use_it.Done();
604 use_it.Advance()) {
605 ++num_uses;
606 }
607 AddIndent();
608 output_ << bci << " " << num_uses << " "
609 << GetTypeId(instruction->GetType()) << instruction->GetId() << " ";
David Brazdilb7e4a062014-12-29 15:35:02 +0000610 PrintInstruction(instruction);
David Brazdilc74652862015-05-13 17:50:09 +0100611 output_ << " " << kEndInstructionMarker << std::endl;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100612 }
613 }
614
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100615 void DumpStartOfDisassemblyBlock(const char* block_name,
616 int predecessor_index,
617 int successor_index) {
618 StartTag("block");
619 PrintProperty("name", block_name);
620 PrintInt("from_bci", -1);
621 PrintInt("to_bci", -1);
622 if (predecessor_index != -1) {
623 PrintProperty("predecessors", "B", predecessor_index);
624 } else {
625 PrintEmptyProperty("predecessors");
626 }
627 if (successor_index != -1) {
628 PrintProperty("successors", "B", successor_index);
629 } else {
630 PrintEmptyProperty("successors");
631 }
632 PrintEmptyProperty("xhandlers");
633 PrintEmptyProperty("flags");
634 StartTag("states");
635 StartTag("locals");
636 PrintInt("size", 0);
637 PrintProperty("method", "None");
638 EndTag("locals");
639 EndTag("states");
640 StartTag("HIR");
641 }
642
643 void DumpEndOfDisassemblyBlock() {
644 EndTag("HIR");
645 EndTag("block");
646 }
647
648 void DumpDisassemblyBlockForFrameEntry() {
649 DumpStartOfDisassemblyBlock(kDisassemblyBlockFrameEntry,
650 -1,
651 GetGraph()->GetEntryBlock()->GetBlockId());
652 output_ << " 0 0 disasm " << kDisassemblyBlockFrameEntry << " ";
653 GeneratedCodeInterval frame_entry = disasm_info_->GetFrameEntryInterval();
654 if (frame_entry.start != frame_entry.end) {
655 output_ << std::endl;
656 disassembler_->Disassemble(output_, frame_entry.start, frame_entry.end);
657 }
658 output_ << kEndInstructionMarker << std::endl;
659 DumpEndOfDisassemblyBlock();
660 }
661
662 void DumpDisassemblyBlockForSlowPaths() {
663 if (disasm_info_->GetSlowPathIntervals().empty()) {
664 return;
665 }
666 // If the graph has an exit block we attach the block for the slow paths
667 // after it. Else we just add the block to the graph without linking it to
668 // any other.
669 DumpStartOfDisassemblyBlock(
670 kDisassemblyBlockSlowPaths,
671 GetGraph()->HasExitBlock() ? GetGraph()->GetExitBlock()->GetBlockId() : -1,
672 -1);
673 for (SlowPathCodeInfo info : disasm_info_->GetSlowPathIntervals()) {
674 output_ << " 0 0 disasm " << info.slow_path->GetDescription() << std::endl;
675 disassembler_->Disassemble(output_, info.code_interval.start, info.code_interval.end);
676 output_ << kEndInstructionMarker << std::endl;
677 }
678 DumpEndOfDisassemblyBlock();
679 }
680
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100681 void Run() {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100682 StartTag("cfg");
David Brazdilffee3d32015-07-06 11:48:53 +0100683 std::string pass_desc = std::string(pass_name_)
684 + " ("
685 + (is_after_pass_ ? "after" : "before")
686 + (graph_in_bad_state_ ? ", bad_state" : "")
687 + ")";
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000688 PrintProperty("name", pass_desc.c_str());
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100689 if (disasm_info_ != nullptr) {
690 DumpDisassemblyBlockForFrameEntry();
691 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100692 VisitInsertionOrder();
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100693 if (disasm_info_ != nullptr) {
694 DumpDisassemblyBlockForSlowPaths();
695 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100696 EndTag("cfg");
697 }
698
David Brazdilb7e4a062014-12-29 15:35:02 +0000699 void VisitBasicBlock(HBasicBlock* block) OVERRIDE {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100700 StartTag("block");
701 PrintProperty("name", "B", block->GetBlockId());
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100702 if (block->GetLifetimeStart() != kNoLifetime) {
703 // Piggy back on these fields to show the lifetime of the block.
704 PrintInt("from_bci", block->GetLifetimeStart());
705 PrintInt("to_bci", block->GetLifetimeEnd());
706 } else {
707 PrintInt("from_bci", -1);
708 PrintInt("to_bci", -1);
709 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100710 PrintPredecessors(block);
711 PrintSuccessors(block);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000712 PrintExceptionHandlers(block);
713
714 if (block->IsCatchBlock()) {
715 PrintProperty("flags", "catch_block");
716 } else {
717 PrintEmptyProperty("flags");
718 }
719
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100720 if (block->GetDominator() != nullptr) {
721 PrintProperty("dominator", "B", block->GetDominator()->GetBlockId());
722 }
723
724 StartTag("states");
725 StartTag("locals");
726 PrintInt("size", 0);
727 PrintProperty("method", "None");
728 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
729 AddIndent();
730 HInstruction* instruction = it.Current();
Nicolas Geoffrayb09aacb2014-09-17 18:21:53 +0100731 output_ << instruction->GetId() << " " << GetTypeId(instruction->GetType())
732 << instruction->GetId() << "[ ";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100733 for (HInputIterator inputs(instruction); !inputs.Done(); inputs.Advance()) {
734 output_ << inputs.Current()->GetId() << " ";
735 }
736 output_ << "]" << std::endl;
737 }
738 EndTag("locals");
739 EndTag("states");
740
741 StartTag("HIR");
742 PrintInstructions(block->GetPhis());
743 PrintInstructions(block->GetInstructions());
744 EndTag("HIR");
745 EndTag("block");
746 }
747
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100748 static constexpr const char* const kEndInstructionMarker = "<|@";
749 static constexpr const char* const kDisassemblyBlockFrameEntry = "FrameEntry";
750 static constexpr const char* const kDisassemblyBlockSlowPaths = "SlowPaths";
751
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100752 private:
753 std::ostream& output_;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100754 const char* pass_name_;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000755 const bool is_after_pass_;
David Brazdilffee3d32015-07-06 11:48:53 +0100756 const bool graph_in_bad_state_;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100757 const CodeGenerator& codegen_;
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100758 const DisassemblyInformation* disasm_info_;
759 std::unique_ptr<HGraphVisualizerDisassembler> disassembler_;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100760 size_t indent_;
761
762 DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter);
763};
764
765HGraphVisualizer::HGraphVisualizer(std::ostream* output,
766 HGraph* graph,
David Brazdil62e074f2015-04-07 18:09:37 +0100767 const CodeGenerator& codegen)
768 : output_(output), graph_(graph), codegen_(codegen) {}
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100769
David Brazdil62e074f2015-04-07 18:09:37 +0100770void HGraphVisualizer::PrintHeader(const char* method_name) const {
771 DCHECK(output_ != nullptr);
David Brazdilffee3d32015-07-06 11:48:53 +0100772 HGraphVisualizerPrinter printer(graph_, *output_, "", true, false, codegen_);
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100773 printer.StartTag("compilation");
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000774 printer.PrintProperty("name", method_name);
775 printer.PrintProperty("method", method_name);
Nicolas Geoffray0d3f5782014-05-14 09:43:38 +0100776 printer.PrintTime("date");
777 printer.EndTag("compilation");
778}
779
David Brazdilffee3d32015-07-06 11:48:53 +0100780void HGraphVisualizer::DumpGraph(const char* pass_name,
781 bool is_after_pass,
782 bool graph_in_bad_state) const {
David Brazdil5e8b1372015-01-23 14:39:08 +0000783 DCHECK(output_ != nullptr);
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100784 if (!graph_->GetBlocks().empty()) {
David Brazdilffee3d32015-07-06 11:48:53 +0100785 HGraphVisualizerPrinter printer(graph_,
786 *output_,
787 pass_name,
788 is_after_pass,
789 graph_in_bad_state,
790 codegen_);
David Brazdilee690a32014-12-01 17:04:16 +0000791 printer.Run();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100792 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100793}
794
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100795void HGraphVisualizer::DumpGraphWithDisassembly() const {
796 DCHECK(output_ != nullptr);
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100797 if (!graph_->GetBlocks().empty()) {
David Brazdilffee3d32015-07-06 11:48:53 +0100798 HGraphVisualizerPrinter printer(graph_,
799 *output_,
800 "disassembly",
801 /* is_after_pass */ true,
802 /* graph_in_bad_state */ false,
803 codegen_,
804 codegen_.GetDisassemblyInformation());
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100805 printer.Run();
806 }
807}
808
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100809} // namespace art