• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
19 #include <dlfcn.h>
20 
21 #include <cctype>
22 #include <ios>
23 #include <sstream>
24 
25 #include "android-base/stringprintf.h"
26 #include "art_method.h"
27 #include "art_method-inl.h"
28 #include "base/intrusive_forward_list.h"
29 #include "bounds_check_elimination.h"
30 #include "builder.h"
31 #include "code_generator.h"
32 #include "data_type-inl.h"
33 #include "dead_code_elimination.h"
34 #include "dex/descriptors_names.h"
35 #include "disassembler.h"
36 #include "inliner.h"
37 #include "licm.h"
38 #include "nodes.h"
39 #include "optimization.h"
40 #include "reference_type_propagation.h"
41 #include "register_allocator_linear_scan.h"
42 #include "scoped_thread_state_change-inl.h"
43 #include "ssa_liveness_analysis.h"
44 #include "utils/assembler.h"
45 
46 namespace art HIDDEN {
47 
48 // Unique pass-name to identify that the dump is for printing to log.
49 constexpr const char* kDebugDumpName = "debug";
50 constexpr const char* kDebugDumpGraphName = "debug_graph";
51 
52 using android::base::StringPrintf;
53 
HasWhitespace(const char * str)54 static bool HasWhitespace(const char* str) {
55   DCHECK(str != nullptr);
56   while (str[0] != 0) {
57     if (isspace(str[0])) {
58       return true;
59     }
60     str++;
61   }
62   return false;
63 }
64 
65 class StringList {
66  public:
67   enum Format {
68     kArrayBrackets,
69     kSetBrackets,
70   };
71 
72   // Create an empty list
StringList(Format format=kArrayBrackets)73   explicit StringList(Format format = kArrayBrackets) : format_(format), is_empty_(true) {}
74 
75   // Construct StringList from a linked list. List element class T
76   // must provide methods `GetNext` and `Dump`.
77   template<class T>
StringList(T * first_entry,Format format=kArrayBrackets)78   explicit StringList(T* first_entry, Format format = kArrayBrackets) : StringList(format) {
79     for (T* current = first_entry; current != nullptr; current = current->GetNext()) {
80       current->Dump(NewEntryStream());
81     }
82   }
83   // Construct StringList from a list of elements. The value type must provide method `Dump`.
84   template <typename Container>
StringList(const Container & list,Format format=kArrayBrackets)85   explicit StringList(const Container& list, Format format = kArrayBrackets) : StringList(format) {
86     for (const typename Container::value_type& current : list) {
87       current.Dump(NewEntryStream());
88     }
89   }
90 
NewEntryStream()91   std::ostream& NewEntryStream() {
92     if (is_empty_) {
93       is_empty_ = false;
94     } else {
95       sstream_ << ",";
96     }
97     return sstream_;
98   }
99 
100  private:
101   Format format_;
102   bool is_empty_;
103   std::ostringstream sstream_;
104 
105   friend std::ostream& operator<<(std::ostream& os, const StringList& list);
106 };
107 
operator <<(std::ostream & os,const StringList & list)108 std::ostream& operator<<(std::ostream& os, const StringList& list) {
109   switch (list.format_) {
110     case StringList::kArrayBrackets: return os << "[" << list.sstream_.str() << "]";
111     case StringList::kSetBrackets:   return os << "{" << list.sstream_.str() << "}";
112   }
113 }
114 
115 // On target: load `libart-disassembler` only when required (to save on memory).
116 // On host: `libart-disassembler` should be linked directly (either as a static or dynamic lib)
117 #ifdef ART_TARGET
118 using create_disasm_prototype = Disassembler*(InstructionSet, DisassemblerOptions*);
119 #endif
120 
121 class HGraphVisualizerDisassembler {
122  public:
HGraphVisualizerDisassembler(InstructionSet instruction_set,const uint8_t * base_address,const uint8_t * end_address)123   HGraphVisualizerDisassembler(InstructionSet instruction_set,
124                                const uint8_t* base_address,
125                                const uint8_t* end_address)
126       : instruction_set_(instruction_set), disassembler_(nullptr) {
127 #ifdef ART_TARGET
128     constexpr const char* libart_disassembler_so_name =
129         kIsDebugBuild ? "libartd-disassembler.so" : "libart-disassembler.so";
130     libart_disassembler_handle_ = dlopen(libart_disassembler_so_name, RTLD_NOW);
131     if (libart_disassembler_handle_ == nullptr) {
132       LOG(ERROR) << "Failed to dlopen " << libart_disassembler_so_name << ": " << dlerror();
133       return;
134     }
135     constexpr const char* create_disassembler_symbol = "create_disassembler";
136     create_disasm_prototype* create_disassembler = reinterpret_cast<create_disasm_prototype*>(
137         dlsym(libart_disassembler_handle_, create_disassembler_symbol));
138     if (create_disassembler == nullptr) {
139       LOG(ERROR) << "Could not find " << create_disassembler_symbol << " entry in "
140                  << libart_disassembler_so_name << ": " << dlerror();
141       return;
142     }
143 #endif
144     // Reading the disassembly from 0x0 is easier, so we print relative
145     // addresses. We will only disassemble the code once everything has
146     // been generated, so we can read data in literal pools.
147     disassembler_ = std::unique_ptr<Disassembler>(create_disassembler(
148             instruction_set,
149             new DisassemblerOptions(/* absolute_addresses= */ false,
150                                     base_address,
151                                     end_address,
152                                     /* can_read_literals= */ true,
153                                     Is64BitInstructionSet(instruction_set)
154                                         ? &Thread::DumpThreadOffset<PointerSize::k64>
155                                         : &Thread::DumpThreadOffset<PointerSize::k32>)));
156   }
157 
~HGraphVisualizerDisassembler()158   ~HGraphVisualizerDisassembler() {
159     // We need to call ~Disassembler() before we close the library.
160     disassembler_.reset();
161 #ifdef ART_TARGET
162     if (libart_disassembler_handle_ != nullptr) {
163       dlclose(libart_disassembler_handle_);
164     }
165 #endif
166   }
167 
Disassemble(std::ostream & output,size_t start,size_t end) const168   void Disassemble(std::ostream& output, size_t start, size_t end) const {
169     if (disassembler_ == nullptr) {
170       return;
171     }
172 
173     const uint8_t* base = disassembler_->GetDisassemblerOptions()->base_address_;
174     if (instruction_set_ == InstructionSet::kThumb2) {
175       // ARM and Thumb-2 use the same disassembler. The bottom bit of the
176       // address is used to distinguish between the two.
177       base += 1;
178     }
179     disassembler_->Dump(output, base + start, base + end);
180   }
181 
182  private:
183   InstructionSet instruction_set_;
184   std::unique_ptr<Disassembler> disassembler_;
185 
186 #ifdef ART_TARGET
187   void* libart_disassembler_handle_;
188 #endif
189 };
190 
191 
192 /**
193  * HGraph visitor to generate a file suitable for the c1visualizer tool and IRHydra.
194  */
195 class HGraphVisualizerPrinter final : public HGraphDelegateVisitor {
196  public:
HGraphVisualizerPrinter(HGraph * graph,std::ostream & output,const char * pass_name,bool is_after_pass,bool graph_in_bad_state,const CodeGenerator * codegen,const BlockNamer & namer,const DisassemblyInformation * disasm_info=nullptr)197   HGraphVisualizerPrinter(HGraph* graph,
198                           std::ostream& output,
199                           const char* pass_name,
200                           bool is_after_pass,
201                           bool graph_in_bad_state,
202                           const CodeGenerator* codegen,
203                           const BlockNamer& namer,
204                           const DisassemblyInformation* disasm_info = nullptr)
205       : HGraphDelegateVisitor(graph),
206         output_(output),
207         pass_name_(pass_name),
208         is_after_pass_(is_after_pass),
209         graph_in_bad_state_(graph_in_bad_state),
210         codegen_(codegen),
211         disasm_info_(disasm_info),
212         namer_(namer),
213         disassembler_(disasm_info_ != nullptr
214                       ? new HGraphVisualizerDisassembler(
215                             codegen_->GetInstructionSet(),
216                             codegen_->GetAssembler().CodeBufferBaseAddress(),
217                             codegen_->GetAssembler().CodeBufferBaseAddress()
218                                 + codegen_->GetAssembler().CodeSize())
219                       : nullptr),
220         indent_(0) {}
221 
Flush()222   void Flush() {
223     // We use "\n" instead of std::endl to avoid implicit flushing which
224     // generates too many syscalls during debug-GC tests (b/27826765).
225     output_ << std::flush;
226   }
227 
StartTag(const char * name)228   void StartTag(const char* name) {
229     AddIndent();
230     output_ << "begin_" << name << "\n";
231     indent_++;
232   }
233 
EndTag(const char * name)234   void EndTag(const char* name) {
235     indent_--;
236     AddIndent();
237     output_ << "end_" << name << "\n";
238   }
239 
PrintProperty(const char * name,HBasicBlock * blk)240   void PrintProperty(const char* name, HBasicBlock* blk) {
241     AddIndent();
242     output_ << name << " \"" << namer_.GetName(blk) << "\"\n";
243   }
244 
PrintProperty(const char * name,const char * property)245   void PrintProperty(const char* name, const char* property) {
246     AddIndent();
247     output_ << name << " \"" << property << "\"\n";
248   }
249 
PrintProperty(const char * name,const char * property,int id)250   void PrintProperty(const char* name, const char* property, int id) {
251     AddIndent();
252     output_ << name << " \"" << property << id << "\"\n";
253   }
254 
PrintEmptyProperty(const char * name)255   void PrintEmptyProperty(const char* name) {
256     AddIndent();
257     output_ << name << "\n";
258   }
259 
PrintTime(const char * name)260   void PrintTime(const char* name) {
261     AddIndent();
262     output_ << name << " " << time(nullptr) << "\n";
263   }
264 
PrintInt(const char * name,int value)265   void PrintInt(const char* name, int value) {
266     AddIndent();
267     output_ << name << " " << value << "\n";
268   }
269 
AddIndent()270   void AddIndent() {
271     for (size_t i = 0; i < indent_; ++i) {
272       output_ << "  ";
273     }
274   }
275 
PrintPredecessors(HBasicBlock * block)276   void PrintPredecessors(HBasicBlock* block) {
277     AddIndent();
278     output_ << "predecessors";
279     for (HBasicBlock* predecessor : block->GetPredecessors()) {
280       output_ << " \"" << namer_.GetName(predecessor) << "\" ";
281     }
282     if (block->IsEntryBlock() && (disasm_info_ != nullptr)) {
283       output_ << " \"" << kDisassemblyBlockFrameEntry << "\" ";
284     }
285     output_<< "\n";
286   }
287 
PrintSuccessors(HBasicBlock * block)288   void PrintSuccessors(HBasicBlock* block) {
289     AddIndent();
290     output_ << "successors";
291     for (HBasicBlock* successor : block->GetNormalSuccessors()) {
292       output_ << " \"" << namer_.GetName(successor) << "\" ";
293     }
294     output_<< "\n";
295   }
296 
PrintExceptionHandlers(HBasicBlock * block)297   void PrintExceptionHandlers(HBasicBlock* block) {
298     bool has_slow_paths = block->IsExitBlock() &&
299                           (disasm_info_ != nullptr) &&
300                           !disasm_info_->GetSlowPathIntervals().empty();
301     if (IsDebugDump() && block->GetExceptionalSuccessors().empty() && !has_slow_paths) {
302       return;
303     }
304     AddIndent();
305     output_ << "xhandlers";
306     for (HBasicBlock* handler : block->GetExceptionalSuccessors()) {
307       output_ << " \"" << namer_.GetName(handler) << "\" ";
308     }
309     if (has_slow_paths) {
310       output_ << " \"" << kDisassemblyBlockSlowPaths << "\" ";
311     }
312     output_<< "\n";
313   }
314 
DumpLocation(std::ostream & stream,const Location & location)315   void DumpLocation(std::ostream& stream, const Location& location) {
316     DCHECK(codegen_ != nullptr);
317     if (location.IsRegister()) {
318       codegen_->DumpCoreRegister(stream, location.reg());
319     } else if (location.IsFpuRegister()) {
320       codegen_->DumpFloatingPointRegister(stream, location.reg());
321     } else if (location.IsConstant()) {
322       stream << "#";
323       HConstant* constant = location.GetConstant();
324       if (constant->IsIntConstant()) {
325         stream << constant->AsIntConstant()->GetValue();
326       } else if (constant->IsLongConstant()) {
327         stream << constant->AsLongConstant()->GetValue();
328       } else if (constant->IsFloatConstant()) {
329         stream << constant->AsFloatConstant()->GetValue();
330       } else if (constant->IsDoubleConstant()) {
331         stream << constant->AsDoubleConstant()->GetValue();
332       } else if (constant->IsNullConstant()) {
333         stream << "null";
334       }
335     } else if (location.IsInvalid()) {
336       stream << "invalid";
337     } else if (location.IsStackSlot()) {
338       stream << location.GetStackIndex() << "(sp)";
339     } else if (location.IsFpuRegisterPair()) {
340       codegen_->DumpFloatingPointRegister(stream, location.low());
341       stream << "|";
342       codegen_->DumpFloatingPointRegister(stream, location.high());
343     } else if (location.IsRegisterPair()) {
344       codegen_->DumpCoreRegister(stream, location.low());
345       stream << "|";
346       codegen_->DumpCoreRegister(stream, location.high());
347     } else if (location.IsUnallocated()) {
348       stream << "unallocated";
349     } else if (location.IsDoubleStackSlot()) {
350       stream << "2x" << location.GetStackIndex() << "(sp)";
351     } else {
352       DCHECK(location.IsSIMDStackSlot());
353       stream << "4x" << location.GetStackIndex() << "(sp)";
354     }
355   }
356 
StartAttributeStream(const char * name=nullptr)357   std::ostream& StartAttributeStream(const char* name = nullptr) {
358     if (name == nullptr) {
359       output_ << " ";
360     } else {
361       DCHECK(!HasWhitespace(name)) << "Checker does not allow spaces in attributes";
362       output_ << " " << name << ":";
363     }
364     return output_;
365   }
366 
VisitParallelMove(HParallelMove * instruction)367   void VisitParallelMove(HParallelMove* instruction) override {
368     StartAttributeStream("liveness") << instruction->GetLifetimePosition();
369     StringList moves;
370     for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) {
371       MoveOperands* move = instruction->MoveOperandsAt(i);
372       std::ostream& str = moves.NewEntryStream();
373       DumpLocation(str, move->GetSource());
374       str << "->";
375       DumpLocation(str, move->GetDestination());
376     }
377     StartAttributeStream("moves") << moves;
378   }
379 
VisitParameterValue(HParameterValue * instruction)380   void VisitParameterValue(HParameterValue* instruction) override {
381     StartAttributeStream("is_this") << std::boolalpha << instruction->IsThis() << std::noboolalpha;
382   }
383 
VisitIntConstant(HIntConstant * instruction)384   void VisitIntConstant(HIntConstant* instruction) override {
385     StartAttributeStream() << instruction->GetValue();
386   }
387 
VisitLongConstant(HLongConstant * instruction)388   void VisitLongConstant(HLongConstant* instruction) override {
389     StartAttributeStream() << instruction->GetValue();
390   }
391 
VisitFloatConstant(HFloatConstant * instruction)392   void VisitFloatConstant(HFloatConstant* instruction) override {
393     StartAttributeStream() << instruction->GetValue();
394   }
395 
VisitDoubleConstant(HDoubleConstant * instruction)396   void VisitDoubleConstant(HDoubleConstant* instruction) override {
397     StartAttributeStream() << instruction->GetValue();
398   }
399 
VisitPhi(HPhi * phi)400   void VisitPhi(HPhi* phi) override {
401     StartAttributeStream("reg") << phi->GetRegNumber();
402     StartAttributeStream("is_catch_phi") << std::boolalpha << phi->IsCatchPhi() << std::noboolalpha;
403     StartAttributeStream("is_live") << std::boolalpha << phi->IsLive() << std::noboolalpha;
404   }
405 
VisitMemoryBarrier(HMemoryBarrier * barrier)406   void VisitMemoryBarrier(HMemoryBarrier* barrier) override {
407     StartAttributeStream("kind") << barrier->GetBarrierKind();
408   }
409 
VisitMonitorOperation(HMonitorOperation * monitor)410   void VisitMonitorOperation(HMonitorOperation* monitor) override {
411     StartAttributeStream("kind") << (monitor->IsEnter() ? "enter" : "exit");
412   }
413 
VisitLoadClass(HLoadClass * load_class)414   void VisitLoadClass(HLoadClass* load_class) override {
415     StartAttributeStream("load_kind") << load_class->GetLoadKind();
416     StartAttributeStream("in_image") << std::boolalpha << load_class->IsInImage();
417     StartAttributeStream("class_name")
418         << load_class->GetDexFile().PrettyType(load_class->GetTypeIndex());
419     StartAttributeStream("gen_clinit_check")
420         << std::boolalpha << load_class->MustGenerateClinitCheck() << std::noboolalpha;
421     StartAttributeStream("needs_access_check") << std::boolalpha
422         << load_class->NeedsAccessCheck() << std::noboolalpha;
423   }
424 
VisitLoadMethodHandle(HLoadMethodHandle * load_method_handle)425   void VisitLoadMethodHandle(HLoadMethodHandle* load_method_handle) override {
426     StartAttributeStream("load_kind") << "RuntimeCall";
427     StartAttributeStream("method_handle_index") << load_method_handle->GetMethodHandleIndex();
428   }
429 
VisitLoadMethodType(HLoadMethodType * load_method_type)430   void VisitLoadMethodType(HLoadMethodType* load_method_type) override {
431     StartAttributeStream("load_kind") << "RuntimeCall";
432     const DexFile& dex_file = load_method_type->GetDexFile();
433     if (dex_file.NumProtoIds() >= load_method_type->GetProtoIndex().index_) {
434       const dex::ProtoId& proto_id = dex_file.GetProtoId(load_method_type->GetProtoIndex());
435       StartAttributeStream("method_type") << dex_file.GetProtoSignature(proto_id);
436     } else {
437       StartAttributeStream("method_type")
438           << "<<Unknown proto-idx: " << load_method_type->GetProtoIndex() << ">>";
439     }
440   }
441 
VisitLoadString(HLoadString * load_string)442   void VisitLoadString(HLoadString* load_string) override {
443     StartAttributeStream("load_kind") << load_string->GetLoadKind();
444   }
445 
HandleTypeCheckInstruction(HTypeCheckInstruction * check)446   void HandleTypeCheckInstruction(HTypeCheckInstruction* check) {
447     StartAttributeStream("check_kind") << check->GetTypeCheckKind();
448     StartAttributeStream("must_do_null_check") << std::boolalpha
449         << check->MustDoNullCheck() << std::noboolalpha;
450     if (check->GetTypeCheckKind() == TypeCheckKind::kBitstringCheck) {
451       StartAttributeStream("path_to_root") << std::hex
452           << "0x" << check->GetBitstringPathToRoot() << std::dec;
453       StartAttributeStream("mask") << std::hex << "0x" << check->GetBitstringMask() << std::dec;
454     }
455   }
456 
VisitCheckCast(HCheckCast * check_cast)457   void VisitCheckCast(HCheckCast* check_cast) override {
458     HandleTypeCheckInstruction(check_cast);
459   }
460 
VisitInstanceOf(HInstanceOf * instance_of)461   void VisitInstanceOf(HInstanceOf* instance_of) override {
462     HandleTypeCheckInstruction(instance_of);
463   }
464 
VisitArrayLength(HArrayLength * array_length)465   void VisitArrayLength(HArrayLength* array_length) override {
466     StartAttributeStream("is_string_length") << std::boolalpha
467         << array_length->IsStringLength() << std::noboolalpha;
468     if (array_length->IsEmittedAtUseSite()) {
469       StartAttributeStream("emitted_at_use") << "true";
470     }
471   }
472 
VisitBoundsCheck(HBoundsCheck * bounds_check)473   void VisitBoundsCheck(HBoundsCheck* bounds_check) override {
474     StartAttributeStream("is_string_char_at") << std::boolalpha
475         << bounds_check->IsStringCharAt() << std::noboolalpha;
476   }
477 
VisitSuspendCheck(HSuspendCheck * suspend_check)478   void VisitSuspendCheck(HSuspendCheck* suspend_check) override {
479     StartAttributeStream("is_no_op")
480         << std::boolalpha << suspend_check->IsNoOp() << std::noboolalpha;
481   }
482 
VisitArrayGet(HArrayGet * array_get)483   void VisitArrayGet(HArrayGet* array_get) override {
484     StartAttributeStream("is_string_char_at") << std::boolalpha
485         << array_get->IsStringCharAt() << std::noboolalpha;
486   }
487 
VisitArraySet(HArraySet * array_set)488   void VisitArraySet(HArraySet* array_set) override {
489     StartAttributeStream("value_can_be_null")
490         << std::boolalpha << array_set->GetValueCanBeNull() << std::noboolalpha;
491     StartAttributeStream("needs_type_check")
492         << std::boolalpha << array_set->NeedsTypeCheck() << std::noboolalpha;
493     StartAttributeStream("static_type_of_array_is_object_array")
494         << std::boolalpha << array_set->StaticTypeOfArrayIsObjectArray() << std::noboolalpha;
495     StartAttributeStream("can_trigger_gc")
496         << std::boolalpha << array_set->GetSideEffects().Includes(SideEffects::CanTriggerGC())
497         << std::noboolalpha;
498     StartAttributeStream("write_barrier_kind") << array_set->GetWriteBarrierKind();
499   }
500 
VisitNewInstance(HNewInstance * new_instance)501   void VisitNewInstance(HNewInstance* new_instance) override {
502     StartAttributeStream("is_finalizable")
503         << std::boolalpha << new_instance->IsFinalizable() << std::noboolalpha;
504     StartAttributeStream("is_partial_materialization")
505         << std::boolalpha << new_instance->IsPartialMaterialization() << std::noboolalpha;
506   }
507 
VisitCompare(HCompare * compare)508   void VisitCompare(HCompare* compare) override {
509     StartAttributeStream("bias") << compare->GetBias();
510     StartAttributeStream("comparison_type") << compare->GetComparisonType();
511   }
512 
VisitCondition(HCondition * condition)513   void VisitCondition(HCondition* condition) override {
514     StartAttributeStream("bias") << condition->GetBias();
515     StartAttributeStream("emitted_at_use_site")
516         << std::boolalpha << condition->IsEmittedAtUseSite() << std::noboolalpha;
517   }
518 
VisitIf(HIf * if_instr)519   void VisitIf(HIf* if_instr) override {
520     StartAttributeStream("true_count") << if_instr->GetTrueCount();
521     StartAttributeStream("false_count") << if_instr->GetFalseCount();
522   }
523 
VisitInvoke(HInvoke * invoke)524   void VisitInvoke(HInvoke* invoke) override {
525     StartAttributeStream("dex_file_index") << invoke->GetMethodReference().index;
526     ArtMethod* method = invoke->GetResolvedMethod();
527     // We don't print signatures, which conflict with c1visualizer format.
528     static constexpr bool kWithSignature = false;
529     // Note that we can only use the graph's dex file for the unresolved case. The
530     // other invokes might be coming from inlined methods.
531     ScopedObjectAccess soa(Thread::Current());
532     std::string method_name = (method == nullptr)
533         ? invoke->GetMethodReference().PrettyMethod(kWithSignature)
534         : method->PrettyMethod(kWithSignature);
535     StartAttributeStream("method_name") << method_name;
536     StartAttributeStream("always_throws") << std::boolalpha
537                                           << invoke->AlwaysThrows()
538                                           << std::noboolalpha;
539     if (method != nullptr) {
540       StartAttributeStream("method_index") << method->GetMethodIndex();
541     }
542     StartAttributeStream("intrinsic") << invoke->GetIntrinsic();
543   }
544 
VisitInvokeUnresolved(HInvokeUnresolved * invoke)545   void VisitInvokeUnresolved(HInvokeUnresolved* invoke) override {
546     VisitInvoke(invoke);
547     StartAttributeStream("invoke_type") << invoke->GetInvokeType();
548   }
549 
VisitInvokeStaticOrDirect(HInvokeStaticOrDirect * invoke)550   void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) override {
551     VisitInvoke(invoke);
552     StartAttributeStream("method_load_kind") << invoke->GetMethodLoadKind();
553     if (invoke->IsStatic()) {
554       StartAttributeStream("clinit_check") << invoke->GetClinitCheckRequirement();
555     }
556   }
557 
VisitInvokeVirtual(HInvokeVirtual * invoke)558   void VisitInvokeVirtual(HInvokeVirtual* invoke) override {
559     VisitInvoke(invoke);
560   }
561 
VisitInvokePolymorphic(HInvokePolymorphic * invoke)562   void VisitInvokePolymorphic(HInvokePolymorphic* invoke) override {
563     VisitInvoke(invoke);
564     StartAttributeStream("invoke_type") << "InvokePolymorphic";
565   }
566 
VisitInstanceFieldGet(HInstanceFieldGet * iget)567   void VisitInstanceFieldGet(HInstanceFieldGet* iget) override {
568     StartAttributeStream("field_name") <<
569         iget->GetFieldInfo().GetDexFile().PrettyField(iget->GetFieldInfo().GetFieldIndex(),
570                                                       /* with type */ false);
571     StartAttributeStream("field_type") << iget->GetFieldType();
572   }
573 
VisitInstanceFieldSet(HInstanceFieldSet * iset)574   void VisitInstanceFieldSet(HInstanceFieldSet* iset) override {
575     StartAttributeStream("field_name") <<
576         iset->GetFieldInfo().GetDexFile().PrettyField(iset->GetFieldInfo().GetFieldIndex(),
577                                                       /* with type */ false);
578     StartAttributeStream("field_type") << iset->GetFieldType();
579     StartAttributeStream("write_barrier_kind") << iset->GetWriteBarrierKind();
580     StartAttributeStream("value_can_be_null")
581         << std::boolalpha << iset->GetValueCanBeNull() << std::noboolalpha;
582   }
583 
VisitStaticFieldGet(HStaticFieldGet * sget)584   void VisitStaticFieldGet(HStaticFieldGet* sget) override {
585     StartAttributeStream("field_name") <<
586         sget->GetFieldInfo().GetDexFile().PrettyField(sget->GetFieldInfo().GetFieldIndex(),
587                                                       /* with type */ false);
588     StartAttributeStream("field_type") << sget->GetFieldType();
589   }
590 
VisitStaticFieldSet(HStaticFieldSet * sset)591   void VisitStaticFieldSet(HStaticFieldSet* sset) override {
592     StartAttributeStream("field_name") <<
593         sset->GetFieldInfo().GetDexFile().PrettyField(sset->GetFieldInfo().GetFieldIndex(),
594                                                       /* with type */ false);
595     StartAttributeStream("field_type") << sset->GetFieldType();
596     StartAttributeStream("write_barrier_kind") << sset->GetWriteBarrierKind();
597     StartAttributeStream("value_can_be_null")
598         << std::boolalpha << sset->GetValueCanBeNull() << std::noboolalpha;
599   }
600 
VisitUnresolvedInstanceFieldGet(HUnresolvedInstanceFieldGet * field_access)601   void VisitUnresolvedInstanceFieldGet(HUnresolvedInstanceFieldGet* field_access) override {
602     StartAttributeStream("field_type") << field_access->GetFieldType();
603   }
604 
VisitUnresolvedInstanceFieldSet(HUnresolvedInstanceFieldSet * field_access)605   void VisitUnresolvedInstanceFieldSet(HUnresolvedInstanceFieldSet* field_access) override {
606     StartAttributeStream("field_type") << field_access->GetFieldType();
607   }
608 
VisitUnresolvedStaticFieldGet(HUnresolvedStaticFieldGet * field_access)609   void VisitUnresolvedStaticFieldGet(HUnresolvedStaticFieldGet* field_access) override {
610     StartAttributeStream("field_type") << field_access->GetFieldType();
611   }
612 
VisitUnresolvedStaticFieldSet(HUnresolvedStaticFieldSet * field_access)613   void VisitUnresolvedStaticFieldSet(HUnresolvedStaticFieldSet* field_access) override {
614     StartAttributeStream("field_type") << field_access->GetFieldType();
615   }
616 
VisitTryBoundary(HTryBoundary * try_boundary)617   void VisitTryBoundary(HTryBoundary* try_boundary) override {
618     StartAttributeStream("kind") << (try_boundary->IsEntry() ? "entry" : "exit");
619   }
620 
VisitGoto(HGoto * instruction)621   void VisitGoto(HGoto* instruction) override {
622     StartAttributeStream("target") << namer_.GetName(instruction->GetBlock()->GetSingleSuccessor());
623   }
624 
VisitDeoptimize(HDeoptimize * deoptimize)625   void VisitDeoptimize(HDeoptimize* deoptimize) override {
626     StartAttributeStream("kind") << deoptimize->GetKind();
627   }
628 
VisitVecOperation(HVecOperation * vec_operation)629   void VisitVecOperation(HVecOperation* vec_operation) override {
630     StartAttributeStream("packed_type") << vec_operation->GetPackedType();
631   }
632 
VisitVecMemoryOperation(HVecMemoryOperation * vec_mem_operation)633   void VisitVecMemoryOperation(HVecMemoryOperation* vec_mem_operation) override {
634     VisitVecOperation(vec_mem_operation);
635     StartAttributeStream("alignment") << vec_mem_operation->GetAlignment().ToString();
636   }
637 
VisitVecHalvingAdd(HVecHalvingAdd * hadd)638   void VisitVecHalvingAdd(HVecHalvingAdd* hadd) override {
639     VisitVecBinaryOperation(hadd);
640     StartAttributeStream("rounded") << std::boolalpha << hadd->IsRounded() << std::noboolalpha;
641   }
642 
VisitVecMultiplyAccumulate(HVecMultiplyAccumulate * instruction)643   void VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) override {
644     VisitVecOperation(instruction);
645     StartAttributeStream("kind") << instruction->GetOpKind();
646   }
647 
VisitVecDotProd(HVecDotProd * instruction)648   void VisitVecDotProd(HVecDotProd* instruction) override {
649     VisitVecOperation(instruction);
650     DataType::Type arg_type = instruction->InputAt(1)->AsVecOperation()->GetPackedType();
651     StartAttributeStream("type") << (instruction->IsZeroExtending() ?
652                                     DataType::ToUnsigned(arg_type) :
653                                     DataType::ToSigned(arg_type));
654   }
655 
VisitBitwiseNegatedRight(HBitwiseNegatedRight * instruction)656   void VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) override {
657     StartAttributeStream("kind") << instruction->GetOpKind();
658   }
659 
660 #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64)
VisitMultiplyAccumulate(HMultiplyAccumulate * instruction)661   void VisitMultiplyAccumulate(HMultiplyAccumulate* instruction) override {
662     StartAttributeStream("kind") << instruction->GetOpKind();
663   }
664 
VisitDataProcWithShifterOp(HDataProcWithShifterOp * instruction)665   void VisitDataProcWithShifterOp(HDataProcWithShifterOp* instruction) override {
666     StartAttributeStream("kind") << instruction->GetInstrKind() << "+" << instruction->GetOpKind();
667     if (HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())) {
668       StartAttributeStream("shift") << instruction->GetShiftAmount();
669     }
670   }
671 #endif
672 
673 #if defined(ART_ENABLE_CODEGEN_riscv64)
VisitRiscv64ShiftAdd(HRiscv64ShiftAdd * instruction)674   void VisitRiscv64ShiftAdd(HRiscv64ShiftAdd* instruction) override {
675     StartAttributeStream("distance") << instruction->GetDistance();
676   }
677 #endif
678 
IsPass(const char * name)679   bool IsPass(const char* name) {
680     return strcmp(pass_name_, name) == 0;
681   }
682 
IsDebugDump()683   bool IsDebugDump() {
684     return IsPass(kDebugDumpGraphName) || IsPass(kDebugDumpName);
685   }
686 
PrintInstruction(HInstruction * instruction)687   void PrintInstruction(HInstruction* instruction) {
688     output_ << instruction->DebugName();
689     HConstInputsRef inputs = instruction->GetInputs();
690     if (!inputs.empty()) {
691       StringList input_list;
692       for (const HInstruction* input : inputs) {
693         input_list.NewEntryStream() << DataType::TypeId(input->GetType()) << input->GetId();
694       }
695       StartAttributeStream() << input_list;
696     }
697     if (instruction->GetDexPc() != kNoDexPc) {
698       StartAttributeStream("dex_pc") << instruction->GetDexPc();
699     } else {
700       StartAttributeStream("dex_pc") << "n/a";
701     }
702     HBasicBlock* block = instruction->GetBlock();
703     StartAttributeStream("block") << namer_.GetName(block);
704 
705     instruction->Accept(this);
706     if (instruction->HasEnvironment()) {
707       StringList envs;
708       for (HEnvironment* environment = instruction->GetEnvironment();
709            environment != nullptr;
710            environment = environment->GetParent()) {
711         StringList vregs;
712         for (size_t i = 0, e = environment->Size(); i < e; ++i) {
713           HInstruction* insn = environment->GetInstructionAt(i);
714           if (insn != nullptr) {
715             vregs.NewEntryStream() << DataType::TypeId(insn->GetType()) << insn->GetId();
716           } else {
717             vregs.NewEntryStream() << "_";
718           }
719         }
720         envs.NewEntryStream() << vregs;
721       }
722       StartAttributeStream("env") << envs;
723     }
724     if (IsPass(SsaLivenessAnalysis::kLivenessPassName)
725         && is_after_pass_
726         && instruction->GetLifetimePosition() != kNoLifetime) {
727       StartAttributeStream("liveness") << instruction->GetLifetimePosition();
728       if (instruction->HasLiveInterval()) {
729         LiveInterval* interval = instruction->GetLiveInterval();
730         StartAttributeStream("ranges")
731             << StringList(interval->GetFirstRange(), StringList::kSetBrackets);
732         StartAttributeStream("uses") << StringList(interval->GetUses());
733         StartAttributeStream("env_uses") << StringList(interval->GetEnvironmentUses());
734         StartAttributeStream("is_fixed") << interval->IsFixed();
735         StartAttributeStream("is_split") << interval->IsSplit();
736         StartAttributeStream("is_low") << interval->IsLowInterval();
737         StartAttributeStream("is_high") << interval->IsHighInterval();
738       }
739     }
740 
741     if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) {
742       StartAttributeStream("liveness") << instruction->GetLifetimePosition();
743       LocationSummary* locations = instruction->GetLocations();
744       if (locations != nullptr) {
745         StringList input_list;
746         for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
747           DumpLocation(input_list.NewEntryStream(), locations->InAt(i));
748         }
749         std::ostream& attr = StartAttributeStream("locations");
750         attr << input_list << "->";
751         DumpLocation(attr, locations->Out());
752       }
753     }
754 
755     HLoopInformation* loop_info = (block != nullptr) ? block->GetLoopInformation() : nullptr;
756     if (loop_info == nullptr) {
757       StartAttributeStream("loop") << "none";
758     } else {
759       StartAttributeStream("loop") << namer_.GetName(loop_info->GetHeader());
760       HLoopInformation* outer = loop_info->GetPreHeader()->GetLoopInformation();
761       if (outer != nullptr) {
762         StartAttributeStream("outer_loop") << namer_.GetName(outer->GetHeader());
763       } else {
764         StartAttributeStream("outer_loop") << "none";
765       }
766       StartAttributeStream("irreducible")
767           << std::boolalpha << loop_info->IsIrreducible() << std::noboolalpha;
768     }
769 
770     // For the builder and the inliner, we want to add extra information on HInstructions
771     // that have reference types, and also HInstanceOf/HCheckcast.
772     if ((IsPass(HGraphBuilder::kBuilderPassName)
773         || IsPass(HInliner::kInlinerPassName)
774         || IsDebugDump())
775         && (instruction->GetType() == DataType::Type::kReference ||
776             instruction->IsInstanceOf() ||
777             instruction->IsCheckCast())) {
778       ReferenceTypeInfo info = (instruction->GetType() == DataType::Type::kReference)
779           ? instruction->IsLoadClass()
780               ? instruction->AsLoadClass()->GetLoadedClassRTI()
781               : instruction->GetReferenceTypeInfo()
782           : instruction->IsInstanceOf()
783               ? instruction->AsInstanceOf()->GetTargetClassRTI()
784               : instruction->AsCheckCast()->GetTargetClassRTI();
785       ScopedObjectAccess soa(Thread::Current());
786       if (info.IsValid()) {
787         StartAttributeStream("klass")
788             << mirror::Class::PrettyDescriptor(info.GetTypeHandle().Get());
789         if (instruction->GetType() == DataType::Type::kReference) {
790           StartAttributeStream("can_be_null")
791               << std::boolalpha << instruction->CanBeNull() << std::noboolalpha;
792         }
793         StartAttributeStream("exact") << std::boolalpha << info.IsExact() << std::noboolalpha;
794       } else if (instruction->IsLoadClass() ||
795                  instruction->IsInstanceOf() ||
796                  instruction->IsCheckCast()) {
797         StartAttributeStream("klass") << "unresolved";
798       } else {
799         StartAttributeStream("klass") << "invalid";
800       }
801     }
802     if (disasm_info_ != nullptr) {
803       DCHECK(disassembler_ != nullptr);
804       // If the information is available, disassemble the code generated for
805       // this instruction.
806       auto it = disasm_info_->GetInstructionIntervals().find(instruction);
807       if (it != disasm_info_->GetInstructionIntervals().end()
808           && it->second.start != it->second.end) {
809         output_ << "\n";
810         disassembler_->Disassemble(output_, it->second.start, it->second.end);
811       }
812     }
813   }
814 
PrintInstructions(const HInstructionList & list)815   void PrintInstructions(const HInstructionList& list) {
816     for (HInstructionIterator it(list); !it.Done(); it.Advance()) {
817       HInstruction* instruction = it.Current();
818       int bci = 0;
819       size_t num_uses = instruction->GetUses().SizeSlow();
820       AddIndent();
821       output_ << bci << " " << num_uses << " "
822               << DataType::TypeId(instruction->GetType()) << instruction->GetId() << " ";
823       PrintInstruction(instruction);
824       output_ << " " << kEndInstructionMarker << "\n";
825     }
826   }
827 
DumpStartOfDisassemblyBlock(const char * block_name,int predecessor_index,int successor_index)828   void DumpStartOfDisassemblyBlock(const char* block_name,
829                                    int predecessor_index,
830                                    int successor_index) {
831     StartTag("block");
832     PrintProperty("name", block_name);
833     PrintInt("from_bci", -1);
834     PrintInt("to_bci", -1);
835     if (predecessor_index != -1) {
836       PrintProperty("predecessors", "B", predecessor_index);
837     } else {
838       PrintEmptyProperty("predecessors");
839     }
840     if (successor_index != -1) {
841       PrintProperty("successors", "B", successor_index);
842     } else {
843       PrintEmptyProperty("successors");
844     }
845     PrintEmptyProperty("xhandlers");
846     PrintEmptyProperty("flags");
847     StartTag("states");
848     StartTag("locals");
849     PrintInt("size", 0);
850     PrintProperty("method", "None");
851     EndTag("locals");
852     EndTag("states");
853     StartTag("HIR");
854   }
855 
DumpEndOfDisassemblyBlock()856   void DumpEndOfDisassemblyBlock() {
857     EndTag("HIR");
858     EndTag("block");
859   }
860 
DumpDisassemblyBlockForFrameEntry()861   void DumpDisassemblyBlockForFrameEntry() {
862     DumpStartOfDisassemblyBlock(kDisassemblyBlockFrameEntry,
863                                 -1,
864                                 GetGraph()->GetEntryBlock()->GetBlockId());
865     output_ << "    0 0 disasm " << kDisassemblyBlockFrameEntry << " ";
866     GeneratedCodeInterval frame_entry = disasm_info_->GetFrameEntryInterval();
867     if (frame_entry.start != frame_entry.end) {
868       output_ << "\n";
869       disassembler_->Disassemble(output_, frame_entry.start, frame_entry.end);
870     }
871     output_ << kEndInstructionMarker << "\n";
872     DumpEndOfDisassemblyBlock();
873   }
874 
DumpDisassemblyBlockForSlowPaths()875   void DumpDisassemblyBlockForSlowPaths() {
876     if (disasm_info_->GetSlowPathIntervals().empty()) {
877       return;
878     }
879     // If the graph has an exit block we attach the block for the slow paths
880     // after it. Else we just add the block to the graph without linking it to
881     // any other.
882     DumpStartOfDisassemblyBlock(
883         kDisassemblyBlockSlowPaths,
884         GetGraph()->HasExitBlock() ? GetGraph()->GetExitBlock()->GetBlockId() : -1,
885         -1);
886     for (SlowPathCodeInfo info : disasm_info_->GetSlowPathIntervals()) {
887       output_ << "    0 0 disasm " << info.slow_path->GetDescription() << "\n";
888       disassembler_->Disassemble(output_, info.code_interval.start, info.code_interval.end);
889       output_ << kEndInstructionMarker << "\n";
890     }
891     DumpEndOfDisassemblyBlock();
892   }
893 
Run()894   void Run() {
895     StartTag("cfg");
896     std::ostringstream oss;
897     oss << pass_name_;
898     if (!IsDebugDump()) {
899       oss << " (" << (GetGraph()->IsCompilingBaseline() ? "baseline " : "")
900           << (is_after_pass_ ? "after" : "before")
901           << (graph_in_bad_state_ ? ", bad_state" : "") << ")";
902     }
903     PrintProperty("name", oss.str().c_str());
904     if (disasm_info_ != nullptr) {
905       DumpDisassemblyBlockForFrameEntry();
906     }
907     VisitInsertionOrder();
908     if (disasm_info_ != nullptr) {
909       DumpDisassemblyBlockForSlowPaths();
910     }
911     EndTag("cfg");
912     Flush();
913   }
914 
Run(HInstruction * instruction)915   void Run(HInstruction* instruction) {
916     output_ << DataType::TypeId(instruction->GetType()) << instruction->GetId() << " ";
917     PrintInstruction(instruction);
918     Flush();
919   }
920 
VisitBasicBlock(HBasicBlock * block)921   void VisitBasicBlock(HBasicBlock* block) override {
922     StartTag("block");
923     PrintProperty("name", block);
924     if (block->GetLifetimeStart() != kNoLifetime) {
925       // Piggy back on these fields to show the lifetime of the block.
926       PrintInt("from_bci", block->GetLifetimeStart());
927       PrintInt("to_bci", block->GetLifetimeEnd());
928     } else if (!IsDebugDump()) {
929       // Don't print useless information to logcat.
930       PrintInt("from_bci", -1);
931       PrintInt("to_bci", -1);
932     }
933     PrintPredecessors(block);
934     PrintSuccessors(block);
935     PrintExceptionHandlers(block);
936 
937     if (block->IsCatchBlock()) {
938       PrintProperty("flags", "catch_block");
939     } else if (block->IsTryBlock()) {
940       std::stringstream flags_properties;
941       flags_properties << "try_start "
942                        << namer_.GetName(block->GetTryCatchInformation()->GetTryEntry().GetBlock());
943       PrintProperty("flags", flags_properties.str().c_str());
944     } else if (!IsDebugDump()) {
945       // Don't print useless information to logcat
946       PrintEmptyProperty("flags");
947     }
948 
949     if (block->GetDominator() != nullptr) {
950       PrintProperty("dominator", block->GetDominator());
951     }
952 
953     if (!IsDebugDump() || !block->GetPhis().IsEmpty()) {
954       StartTag("states");
955       StartTag("locals");
956       PrintInt("size", 0);
957       PrintProperty("method", "None");
958       for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
959         AddIndent();
960         HInstruction* instruction = it.Current();
961         output_ << instruction->GetId() << " " << DataType::TypeId(instruction->GetType())
962                 << instruction->GetId() << "[ ";
963         for (const HInstruction* input : instruction->GetInputs()) {
964           output_ << input->GetId() << " ";
965         }
966         output_ << "]\n";
967       }
968       EndTag("locals");
969       EndTag("states");
970     }
971 
972     StartTag("HIR");
973     PrintInstructions(block->GetPhis());
974     PrintInstructions(block->GetInstructions());
975     EndTag("HIR");
976     EndTag("block");
977   }
978 
979   static constexpr const char* const kEndInstructionMarker = "<|@";
980   static constexpr const char* const kDisassemblyBlockFrameEntry = "FrameEntry";
981   static constexpr const char* const kDisassemblyBlockSlowPaths = "SlowPaths";
982 
983  private:
984   std::ostream& output_;
985   const char* pass_name_;
986   const bool is_after_pass_;
987   const bool graph_in_bad_state_;
988   const CodeGenerator* codegen_;
989   const DisassemblyInformation* disasm_info_;
990   const BlockNamer& namer_;
991   std::unique_ptr<HGraphVisualizerDisassembler> disassembler_;
992   size_t indent_;
993 
994   DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter);
995 };
996 
PrintName(std::ostream & os,HBasicBlock * blk) const997 std::ostream& HGraphVisualizer::OptionalDefaultNamer::PrintName(std::ostream& os,
998                                                                 HBasicBlock* blk) const {
999   if (namer_) {
1000     return namer_->get().PrintName(os, blk);
1001   } else {
1002     return BlockNamer::PrintName(os, blk);
1003   }
1004 }
1005 
HGraphVisualizer(std::ostream * output,HGraph * graph,const CodeGenerator * codegen,std::optional<std::reference_wrapper<const BlockNamer>> namer)1006 HGraphVisualizer::HGraphVisualizer(std::ostream* output,
1007                                    HGraph* graph,
1008                                    const CodeGenerator* codegen,
1009                                    std::optional<std::reference_wrapper<const BlockNamer>> namer)
1010     : output_(output), graph_(graph), codegen_(codegen), namer_(namer) {}
1011 
PrintHeader(const char * method_name) const1012 void HGraphVisualizer::PrintHeader(const char* method_name) const {
1013   DCHECK(output_ != nullptr);
1014   HGraphVisualizerPrinter printer(graph_, *output_, "", true, false, codegen_, namer_);
1015   printer.StartTag("compilation");
1016   printer.PrintProperty("name", method_name);
1017   printer.PrintProperty("method", method_name);
1018   printer.PrintTime("date");
1019   printer.EndTag("compilation");
1020   printer.Flush();
1021 }
1022 
InsertMetaDataAsCompilationBlock(const std::string & meta_data)1023 std::string HGraphVisualizer::InsertMetaDataAsCompilationBlock(const std::string& meta_data) {
1024   std::string time_str = std::to_string(time(nullptr));
1025   std::string quoted_meta_data = "\"" + meta_data + "\"";
1026   return StringPrintf("begin_compilation\n"
1027                       "  name %s\n"
1028                       "  method %s\n"
1029                       "  date %s\n"
1030                       "end_compilation\n",
1031                       quoted_meta_data.c_str(),
1032                       quoted_meta_data.c_str(),
1033                       time_str.c_str());
1034 }
1035 
DumpGraphDebug() const1036 void HGraphVisualizer::DumpGraphDebug() const {
1037   DumpGraph(/* pass_name= */ kDebugDumpGraphName,
1038             /* is_after_pass= */ false,
1039             /* graph_in_bad_state= */ true);
1040 }
1041 
DumpGraph(const char * pass_name,bool is_after_pass,bool graph_in_bad_state) const1042 void HGraphVisualizer::DumpGraph(const char* pass_name,
1043                                  bool is_after_pass,
1044                                  bool graph_in_bad_state) const {
1045   DCHECK(output_ != nullptr);
1046   if (!graph_->GetBlocks().empty()) {
1047     HGraphVisualizerPrinter printer(graph_,
1048                                     *output_,
1049                                     pass_name,
1050                                     is_after_pass,
1051                                     graph_in_bad_state,
1052                                     codegen_,
1053                                     namer_);
1054     printer.Run();
1055   }
1056 }
1057 
DumpGraphWithDisassembly() const1058 void HGraphVisualizer::DumpGraphWithDisassembly() const {
1059   DCHECK(output_ != nullptr);
1060   if (!graph_->GetBlocks().empty()) {
1061     HGraphVisualizerPrinter printer(graph_,
1062                                     *output_,
1063                                     "disassembly",
1064                                     /* is_after_pass= */ true,
1065                                     /* graph_in_bad_state= */ false,
1066                                     codegen_,
1067                                     namer_,
1068                                     codegen_->GetDisassemblyInformation());
1069     printer.Run();
1070   }
1071 }
1072 
DumpInstruction(std::ostream * output,HGraph * graph,HInstruction * instruction)1073 void HGraphVisualizer::DumpInstruction(std::ostream* output,
1074                                        HGraph* graph,
1075                                        HInstruction* instruction) {
1076   BlockNamer namer;
1077   HGraphVisualizerPrinter printer(graph,
1078                                   *output,
1079                                   /* pass_name= */ kDebugDumpName,
1080                                   /* is_after_pass= */ false,
1081                                   /* graph_in_bad_state= */ false,
1082                                   /* codegen= */ nullptr,
1083                                   /* namer= */ namer);
1084   printer.Run(instruction);
1085 }
1086 
1087 }  // namespace art
1088