blob: 716fee4d3e8ba5553c9d1035b3612ba2ddd2ff10 [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>
Alex Light3a73ffb2021-01-25 14:11:05 +000022#include <ios>
Alexandre Rameseb7b7392015-06-19 14:47:01 +010023#include <sstream>
24
Fabio Rinaldi52d53542020-02-10 17:28:06 +000025#include "android-base/stringprintf.h"
Vladimir Marko69d310e2017-10-09 14:12:23 +010026#include "art_method.h"
Nicolas Geoffray25b9c7d2020-09-17 17:34:34 +010027#include "art_method-inl.h"
Vladimir Marko3fae1292019-06-07 11:26:25 +010028#include "base/intrusive_forward_list.h"
Aart Bik09e8d5f2016-01-22 16:49:55 -080029#include "bounds_check_elimination.h"
David Brazdilbadd8262016-02-02 16:28:56 +000030#include "builder.h"
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010031#include "code_generator.h"
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010032#include "data_type-inl.h"
David Brazdila4b8c212015-05-07 09:59:30 +010033#include "dead_code_elimination.h"
David Sehrb2ec9f52018-02-21 13:20:31 -080034#include "dex/descriptors_names.h"
Alexandre Rameseb7b7392015-06-19 14:47:01 +010035#include "disassembler.h"
Calin Juravlecdfed3d2015-10-26 14:05:01 +000036#include "inliner.h"
Andreas Gampe7c3952f2015-02-19 18:21:24 -080037#include "licm.h"
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010038#include "nodes.h"
Nicolas Geoffray82091da2015-01-26 10:02:45 +000039#include "optimization.h"
Nicolas Geoffray7cb499b2015-06-17 11:35:11 +010040#include "reference_type_propagation.h"
Matthew Gharritye9288852016-07-14 14:08:16 -070041#include "register_allocator_linear_scan.h"
Vladimir Marko69d310e2017-10-09 14:12:23 +010042#include "scoped_thread_state_change-inl.h"
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +010043#include "ssa_liveness_analysis.h"
Alexandre Rameseb7b7392015-06-19 14:47:01 +010044#include "utils/assembler.h"
David Brazdilc74652862015-05-13 17:50:09 +010045
Vladimir Marko0a516052019-10-14 13:00:44 +000046namespace art {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010047
Alex Lightdc281e72021-01-06 12:35:31 -080048// Unique pass-name to identify that the dump is for printing to log.
49constexpr const char* kDebugDumpName = "debug";
50constexpr const char* kDebugDumpGraphName = "debug_graph";
51
Fabio Rinaldi52d53542020-02-10 17:28:06 +000052using android::base::StringPrintf;
53
David Brazdilc74652862015-05-13 17:50:09 +010054static 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
65class StringList {
66 public:
David Brazdilc7a24852015-05-15 16:44:05 +010067 enum Format {
68 kArrayBrackets,
69 kSetBrackets,
70 };
71
David Brazdilc74652862015-05-13 17:50:09 +010072 // Create an empty list
David Brazdilf1a9ff72015-05-18 16:04:53 +010073 explicit StringList(Format format = kArrayBrackets) : format_(format), is_empty_(true) {}
David Brazdilc74652862015-05-13 17:50:09 +010074
75 // Construct StringList from a linked list. List element class T
76 // must provide methods `GetNext` and `Dump`.
77 template<class T>
David Brazdilc7a24852015-05-15 16:44:05 +010078 explicit StringList(T* first_entry, Format format = kArrayBrackets) : StringList(format) {
David Brazdilc74652862015-05-13 17:50:09 +010079 for (T* current = first_entry; current != nullptr; current = current->GetNext()) {
80 current->Dump(NewEntryStream());
81 }
82 }
Vladimir Marko82b07402017-03-01 19:02:04 +000083 // Construct StringList from a list of elements. The value type must provide method `Dump`.
84 template <typename Container>
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 }
David Brazdilc74652862015-05-13 17:50:09 +010090
91 std::ostream& NewEntryStream() {
92 if (is_empty_) {
93 is_empty_ = false;
94 } else {
David Brazdilc57397b2015-05-15 16:01:59 +010095 sstream_ << ",";
David Brazdilc74652862015-05-13 17:50:09 +010096 }
97 return sstream_;
98 }
99
100 private:
David Brazdilc7a24852015-05-15 16:44:05 +0100101 Format format_;
David Brazdilc74652862015-05-13 17:50:09 +0100102 bool is_empty_;
103 std::ostringstream sstream_;
104
105 friend std::ostream& operator<<(std::ostream& os, const StringList& list);
106};
107
108std::ostream& operator<<(std::ostream& os, const StringList& list) {
David Brazdilc7a24852015-05-15 16:44:05 +0100109 switch (list.format_) {
110 case StringList::kArrayBrackets: return os << "[" << list.sstream_.str() << "]";
111 case StringList::kSetBrackets: return os << "{" << list.sstream_.str() << "}";
112 default:
113 LOG(FATAL) << "Invalid StringList format";
114 UNREACHABLE();
115 }
David Brazdilc74652862015-05-13 17:50:09 +0100116}
117
Martin Stjernholm40746872020-09-29 13:58:10 +0100118#ifndef ART_STATIC_LIBART_COMPILER
Andreas Gampec55bb392018-09-21 00:02:02 +0000119using create_disasm_prototype = Disassembler*(InstructionSet, DisassemblerOptions*);
Martin Stjernholm40746872020-09-29 13:58:10 +0100120#endif
121
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100122class HGraphVisualizerDisassembler {
123 public:
Aart Bikd3059e72016-05-11 10:30:47 -0700124 HGraphVisualizerDisassembler(InstructionSet instruction_set,
125 const uint8_t* base_address,
126 const uint8_t* end_address)
David Brazdil3a690be2015-06-23 10:22:38 +0100127 : instruction_set_(instruction_set), disassembler_(nullptr) {
Martin Stjernholm40746872020-09-29 13:58:10 +0100128#ifndef ART_STATIC_LIBART_COMPILER
Roland Levillain5b768892020-02-19 15:49:02 +0000129 constexpr const char* libart_disassembler_so_name =
130 kIsDebugBuild ? "libartd-disassembler.so" : "libart-disassembler.so";
131 libart_disassembler_handle_ = dlopen(libart_disassembler_so_name, RTLD_NOW);
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100132 if (libart_disassembler_handle_ == nullptr) {
Roland Levillain5b768892020-02-19 15:49:02 +0000133 LOG(ERROR) << "Failed to dlopen " << libart_disassembler_so_name << ": " << dlerror();
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100134 return;
135 }
Roland Levillain5b768892020-02-19 15:49:02 +0000136 constexpr const char* create_disassembler_symbol = "create_disassembler";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100137 create_disasm_prototype* create_disassembler = reinterpret_cast<create_disasm_prototype*>(
Roland Levillain5b768892020-02-19 15:49:02 +0000138 dlsym(libart_disassembler_handle_, create_disassembler_symbol));
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100139 if (create_disassembler == nullptr) {
Roland Levillain5b768892020-02-19 15:49:02 +0000140 LOG(ERROR) << "Could not find " << create_disassembler_symbol << " entry in "
141 << libart_disassembler_so_name << ": " << dlerror();
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100142 return;
143 }
Martin Stjernholm40746872020-09-29 13:58:10 +0100144#endif
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100145 // Reading the disassembly from 0x0 is easier, so we print relative
146 // addresses. We will only disassemble the code once everything has
147 // been generated, so we can read data in literal pools.
Martin Stjernholm40746872020-09-29 13:58:10 +0100148 disassembler_ = std::unique_ptr<Disassembler>(create_disassembler(
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100149 instruction_set,
Andreas Gampe3db70682018-12-26 15:12:03 -0800150 new DisassemblerOptions(/* absolute_addresses= */ false,
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100151 base_address,
Aart Bikd3059e72016-05-11 10:30:47 -0700152 end_address,
Andreas Gampe3db70682018-12-26 15:12:03 -0800153 /* can_read_literals= */ true,
Andreas Gampe372f3a32016-08-19 10:49:06 -0700154 Is64BitInstructionSet(instruction_set)
155 ? &Thread::DumpThreadOffset<PointerSize::k64>
156 : &Thread::DumpThreadOffset<PointerSize::k32>)));
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100157 }
158
159 ~HGraphVisualizerDisassembler() {
160 // We need to call ~Disassembler() before we close the library.
161 disassembler_.reset();
Martin Stjernholm40746872020-09-29 13:58:10 +0100162#ifndef ART_STATIC_LIBART_COMPILER
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100163 if (libart_disassembler_handle_ != nullptr) {
164 dlclose(libart_disassembler_handle_);
165 }
Martin Stjernholm40746872020-09-29 13:58:10 +0100166#endif
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100167 }
168
169 void Disassemble(std::ostream& output, size_t start, size_t end) const {
David Brazdil3a690be2015-06-23 10:22:38 +0100170 if (disassembler_ == nullptr) {
171 return;
172 }
173
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100174 const uint8_t* base = disassembler_->GetDisassemblerOptions()->base_address_;
Vladimir Marko33bff252017-11-01 14:35:42 +0000175 if (instruction_set_ == InstructionSet::kThumb2) {
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100176 // ARM and Thumb-2 use the same disassembler. The bottom bit of the
177 // address is used to distinguish between the two.
178 base += 1;
179 }
180 disassembler_->Dump(output, base + start, base + end);
181 }
182
183 private:
184 InstructionSet instruction_set_;
185 std::unique_ptr<Disassembler> disassembler_;
186
Martin Stjernholm40746872020-09-29 13:58:10 +0100187#ifndef ART_STATIC_LIBART_COMPILER
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100188 void* libart_disassembler_handle_;
Martin Stjernholm40746872020-09-29 13:58:10 +0100189#endif
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100190};
191
192
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100193/**
194 * HGraph visitor to generate a file suitable for the c1visualizer tool and IRHydra.
195 */
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100196class HGraphVisualizerPrinter : public HGraphDelegateVisitor {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100197 public:
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100198 HGraphVisualizerPrinter(HGraph* graph,
199 std::ostream& output,
200 const char* pass_name,
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000201 bool is_after_pass,
David Brazdilffee3d32015-07-06 11:48:53 +0100202 bool graph_in_bad_state,
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000203 const CodeGenerator* codegen,
Alex Lightdc281e72021-01-06 12:35:31 -0800204 const BlockNamer& namer,
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100205 const DisassemblyInformation* disasm_info = nullptr)
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100206 : HGraphDelegateVisitor(graph),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100207 output_(output),
208 pass_name_(pass_name),
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000209 is_after_pass_(is_after_pass),
David Brazdilffee3d32015-07-06 11:48:53 +0100210 graph_in_bad_state_(graph_in_bad_state),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100211 codegen_(codegen),
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100212 disasm_info_(disasm_info),
Alex Lightdc281e72021-01-06 12:35:31 -0800213 namer_(namer),
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100214 disassembler_(disasm_info_ != nullptr
215 ? new HGraphVisualizerDisassembler(
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000216 codegen_->GetInstructionSet(),
217 codegen_->GetAssembler().CodeBufferBaseAddress(),
218 codegen_->GetAssembler().CodeBufferBaseAddress()
219 + codegen_->GetAssembler().CodeSize())
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100220 : nullptr),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100221 indent_(0) {}
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100222
David Brazdilfa02c9d2016-03-30 09:41:02 +0100223 void Flush() {
224 // We use "\n" instead of std::endl to avoid implicit flushing which
225 // generates too many syscalls during debug-GC tests (b/27826765).
226 output_ << std::flush;
227 }
228
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100229 void StartTag(const char* name) {
230 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100231 output_ << "begin_" << name << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100232 indent_++;
233 }
234
235 void EndTag(const char* name) {
236 indent_--;
237 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100238 output_ << "end_" << name << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100239 }
240
Alex Lightdc281e72021-01-06 12:35:31 -0800241 void PrintProperty(const char* name, HBasicBlock* blk) {
242 AddIndent();
243 output_ << name << " \"" << namer_.GetName(blk) << "\"\n";
244 }
245
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100246 void PrintProperty(const char* name, const char* property) {
247 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100248 output_ << name << " \"" << property << "\"\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100249 }
250
251 void PrintProperty(const char* name, const char* property, int id) {
252 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100253 output_ << name << " \"" << property << id << "\"\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100254 }
255
256 void PrintEmptyProperty(const char* name) {
257 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100258 output_ << name << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100259 }
260
261 void PrintTime(const char* name) {
262 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100263 output_ << name << " " << time(nullptr) << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100264 }
265
266 void PrintInt(const char* name, int value) {
267 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100268 output_ << name << " " << value << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100269 }
270
271 void AddIndent() {
272 for (size_t i = 0; i < indent_; ++i) {
273 output_ << " ";
274 }
275 }
276
277 void PrintPredecessors(HBasicBlock* block) {
278 AddIndent();
279 output_ << "predecessors";
Vladimir Marko60584552015-09-03 13:35:12 +0000280 for (HBasicBlock* predecessor : block->GetPredecessors()) {
Alex Lightdc281e72021-01-06 12:35:31 -0800281 output_ << " \"" << namer_.GetName(predecessor) << "\" ";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100282 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100283 if (block->IsEntryBlock() && (disasm_info_ != nullptr)) {
284 output_ << " \"" << kDisassemblyBlockFrameEntry << "\" ";
285 }
David Brazdilfa02c9d2016-03-30 09:41:02 +0100286 output_<< "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100287 }
288
289 void PrintSuccessors(HBasicBlock* block) {
290 AddIndent();
291 output_ << "successors";
David Brazdild26a4112015-11-10 11:07:31 +0000292 for (HBasicBlock* successor : block->GetNormalSuccessors()) {
Alex Lightdc281e72021-01-06 12:35:31 -0800293 output_ << " \"" << namer_.GetName(successor) << "\" ";
David Brazdilfc6a86a2015-06-26 10:33:45 +0000294 }
David Brazdilfa02c9d2016-03-30 09:41:02 +0100295 output_<< "\n";
David Brazdilfc6a86a2015-06-26 10:33:45 +0000296 }
297
298 void PrintExceptionHandlers(HBasicBlock* block) {
Alex Lightdc281e72021-01-06 12:35:31 -0800299 bool has_slow_paths = block->IsExitBlock() &&
300 (disasm_info_ != nullptr) &&
301 !disasm_info_->GetSlowPathIntervals().empty();
302 if (IsDebugDump() && block->GetExceptionalSuccessors().empty() && !has_slow_paths) {
303 return;
304 }
David Brazdilfc6a86a2015-06-26 10:33:45 +0000305 AddIndent();
306 output_ << "xhandlers";
David Brazdild26a4112015-11-10 11:07:31 +0000307 for (HBasicBlock* handler : block->GetExceptionalSuccessors()) {
Alex Lightdc281e72021-01-06 12:35:31 -0800308 output_ << " \"" << namer_.GetName(handler) << "\" ";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100309 }
Alex Lightdc281e72021-01-06 12:35:31 -0800310 if (has_slow_paths) {
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100311 output_ << " \"" << kDisassemblyBlockSlowPaths << "\" ";
312 }
David Brazdilfa02c9d2016-03-30 09:41:02 +0100313 output_<< "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100314 }
315
David Brazdilc74652862015-05-13 17:50:09 +0100316 void DumpLocation(std::ostream& stream, const Location& location) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000317 DCHECK(codegen_ != nullptr);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100318 if (location.IsRegister()) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000319 codegen_->DumpCoreRegister(stream, location.reg());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100320 } else if (location.IsFpuRegister()) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000321 codegen_->DumpFloatingPointRegister(stream, location.reg());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100322 } else if (location.IsConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100323 stream << "#";
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100324 HConstant* constant = location.GetConstant();
325 if (constant->IsIntConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100326 stream << constant->AsIntConstant()->GetValue();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100327 } else if (constant->IsLongConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100328 stream << constant->AsLongConstant()->GetValue();
Alexandre Ramesc2c52a12016-08-02 13:45:28 +0100329 } else if (constant->IsFloatConstant()) {
330 stream << constant->AsFloatConstant()->GetValue();
331 } else if (constant->IsDoubleConstant()) {
332 stream << constant->AsDoubleConstant()->GetValue();
333 } else if (constant->IsNullConstant()) {
334 stream << "null";
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100335 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100336 } else if (location.IsInvalid()) {
David Brazdilc74652862015-05-13 17:50:09 +0100337 stream << "invalid";
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100338 } else if (location.IsStackSlot()) {
David Brazdilc74652862015-05-13 17:50:09 +0100339 stream << location.GetStackIndex() << "(sp)";
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000340 } else if (location.IsFpuRegisterPair()) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000341 codegen_->DumpFloatingPointRegister(stream, location.low());
David Brazdilc74652862015-05-13 17:50:09 +0100342 stream << "|";
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000343 codegen_->DumpFloatingPointRegister(stream, location.high());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000344 } else if (location.IsRegisterPair()) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000345 codegen_->DumpCoreRegister(stream, location.low());
David Brazdilc74652862015-05-13 17:50:09 +0100346 stream << "|";
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000347 codegen_->DumpCoreRegister(stream, location.high());
Mark Mendell09ed1a32015-03-25 08:30:06 -0400348 } else if (location.IsUnallocated()) {
David Brazdilc74652862015-05-13 17:50:09 +0100349 stream << "unallocated";
Aart Bik5576f372017-03-23 16:17:37 -0700350 } else if (location.IsDoubleStackSlot()) {
David Brazdilc74652862015-05-13 17:50:09 +0100351 stream << "2x" << location.GetStackIndex() << "(sp)";
Aart Bik5576f372017-03-23 16:17:37 -0700352 } else {
353 DCHECK(location.IsSIMDStackSlot());
354 stream << "4x" << location.GetStackIndex() << "(sp)";
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100355 }
356 }
357
David Brazdilc74652862015-05-13 17:50:09 +0100358 std::ostream& StartAttributeStream(const char* name = nullptr) {
359 if (name == nullptr) {
360 output_ << " ";
361 } else {
362 DCHECK(!HasWhitespace(name)) << "Checker does not allow spaces in attributes";
363 output_ << " " << name << ":";
364 }
365 return output_;
366 }
367
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100368 void VisitParallelMove(HParallelMove* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100369 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
370 StringList moves;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100371 for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) {
372 MoveOperands* move = instruction->MoveOperandsAt(i);
David Brazdilc74652862015-05-13 17:50:09 +0100373 std::ostream& str = moves.NewEntryStream();
374 DumpLocation(str, move->GetSource());
375 str << "->";
376 DumpLocation(str, move->GetDestination());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100377 }
David Brazdilc74652862015-05-13 17:50:09 +0100378 StartAttributeStream("moves") << moves;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100379 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100380
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100381 void VisitIntConstant(HIntConstant* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100382 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000383 }
384
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100385 void VisitLongConstant(HLongConstant* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100386 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000387 }
388
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100389 void VisitFloatConstant(HFloatConstant* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100390 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000391 }
392
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100393 void VisitDoubleConstant(HDoubleConstant* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100394 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000395 }
396
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100397 void VisitPhi(HPhi* phi) override {
David Brazdilc74652862015-05-13 17:50:09 +0100398 StartAttributeStream("reg") << phi->GetRegNumber();
David Brazdilffee3d32015-07-06 11:48:53 +0100399 StartAttributeStream("is_catch_phi") << std::boolalpha << phi->IsCatchPhi() << std::noboolalpha;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000400 }
401
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100402 void VisitMemoryBarrier(HMemoryBarrier* barrier) override {
David Brazdilc74652862015-05-13 17:50:09 +0100403 StartAttributeStream("kind") << barrier->GetBarrierKind();
Calin Juravle27df7582015-04-17 19:12:31 +0100404 }
405
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100406 void VisitMonitorOperation(HMonitorOperation* monitor) override {
David Brazdilbff75032015-07-08 17:26:51 +0000407 StartAttributeStream("kind") << (monitor->IsEnter() ? "enter" : "exit");
408 }
409
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100410 void VisitLoadClass(HLoadClass* load_class) override {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100411 StartAttributeStream("load_kind") << load_class->GetLoadKind();
Alex Lightdc281e72021-01-06 12:35:31 -0800412 StartAttributeStream("class_name")
413 << load_class->GetDexFile().PrettyType(load_class->GetTypeIndex());
414 StartAttributeStream("gen_clinit_check")
415 << std::boolalpha << load_class->MustGenerateClinitCheck() << std::noboolalpha;
Calin Juravle386062d2015-10-07 18:55:43 +0100416 StartAttributeStream("needs_access_check") << std::boolalpha
417 << load_class->NeedsAccessCheck() << std::noboolalpha;
Calin Juravle0ba218d2015-05-19 18:46:01 +0100418 }
419
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100420 void VisitLoadMethodHandle(HLoadMethodHandle* load_method_handle) override {
Orion Hodsondbaa5c72018-05-10 08:22:46 +0100421 StartAttributeStream("load_kind") << "RuntimeCall";
422 StartAttributeStream("method_handle_index") << load_method_handle->GetMethodHandleIndex();
423 }
424
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100425 void VisitLoadMethodType(HLoadMethodType* load_method_type) override {
Orion Hodson18259d72018-04-12 11:18:23 +0100426 StartAttributeStream("load_kind") << "RuntimeCall";
427 const DexFile& dex_file = load_method_type->GetDexFile();
Alex Lightdc281e72021-01-06 12:35:31 -0800428 if (dex_file.NumProtoIds() >= load_method_type->GetProtoIndex().index_) {
429 const dex::ProtoId& proto_id = dex_file.GetProtoId(load_method_type->GetProtoIndex());
430 StartAttributeStream("method_type") << dex_file.GetProtoSignature(proto_id);
431 } else {
432 StartAttributeStream("method_type")
433 << "<<Unknown proto-idx: " << load_method_type->GetProtoIndex() << ">>";
434 }
Orion Hodson18259d72018-04-12 11:18:23 +0100435 }
436
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100437 void VisitLoadString(HLoadString* load_string) override {
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000438 StartAttributeStream("load_kind") << load_string->GetLoadKind();
439 }
440
Vladimir Marko175e7862018-03-27 09:03:13 +0000441 void HandleTypeCheckInstruction(HTypeCheckInstruction* check) {
442 StartAttributeStream("check_kind") << check->GetTypeCheckKind();
Nicolas Geoffraybff7a522018-01-25 13:33:07 +0000443 StartAttributeStream("must_do_null_check") << std::boolalpha
Vladimir Marko175e7862018-03-27 09:03:13 +0000444 << check->MustDoNullCheck() << std::noboolalpha;
445 if (check->GetTypeCheckKind() == TypeCheckKind::kBitstringCheck) {
446 StartAttributeStream("path_to_root") << std::hex
447 << "0x" << check->GetBitstringPathToRoot() << std::dec;
448 StartAttributeStream("mask") << std::hex << "0x" << check->GetBitstringMask() << std::dec;
449 }
450 }
451
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100452 void VisitCheckCast(HCheckCast* check_cast) override {
Vladimir Marko175e7862018-03-27 09:03:13 +0000453 HandleTypeCheckInstruction(check_cast);
Guillaume "Vermeille" Sanchez9099ef72015-05-20 15:19:21 +0100454 }
455
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100456 void VisitInstanceOf(HInstanceOf* instance_of) override {
Vladimir Marko175e7862018-03-27 09:03:13 +0000457 HandleTypeCheckInstruction(instance_of);
Guillaume "Vermeille" Sanchez9099ef72015-05-20 15:19:21 +0100458 }
459
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100460 void VisitArrayLength(HArrayLength* array_length) override {
Vladimir Markodce016e2016-04-28 13:10:02 +0100461 StartAttributeStream("is_string_length") << std::boolalpha
462 << array_length->IsStringLength() << std::noboolalpha;
Mark Mendellee8d9712016-07-12 11:13:15 -0400463 if (array_length->IsEmittedAtUseSite()) {
464 StartAttributeStream("emitted_at_use") << "true";
465 }
Vladimir Markodce016e2016-04-28 13:10:02 +0100466 }
467
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100468 void VisitBoundsCheck(HBoundsCheck* bounds_check) override {
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100469 StartAttributeStream("is_string_char_at") << std::boolalpha
470 << bounds_check->IsStringCharAt() << std::noboolalpha;
471 }
472
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100473 void VisitArrayGet(HArrayGet* array_get) override {
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100474 StartAttributeStream("is_string_char_at") << std::boolalpha
475 << array_get->IsStringCharAt() << std::noboolalpha;
476 }
477
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100478 void VisitArraySet(HArraySet* array_set) override {
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100479 StartAttributeStream("value_can_be_null") << std::boolalpha
480 << array_set->GetValueCanBeNull() << std::noboolalpha;
Roland Levillainb133ec62016-03-23 12:40:35 +0000481 StartAttributeStream("needs_type_check") << std::boolalpha
482 << array_set->NeedsTypeCheck() << std::noboolalpha;
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100483 }
484
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100485 void VisitCompare(HCompare* compare) override {
Vladimir Marko9974e3c2020-06-10 16:27:06 +0100486 StartAttributeStream("bias") << compare->GetBias();
Roland Levillain31dd3d62016-02-16 12:21:02 +0000487 }
488
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100489 void VisitInvoke(HInvoke* invoke) override {
Nicolas Geoffraye6c0f2a2020-09-07 08:30:52 +0100490 StartAttributeStream("dex_file_index") << invoke->GetMethodReference().index;
Nicolas Geoffray5ceac0e2017-06-26 13:19:09 +0100491 ArtMethod* method = invoke->GetResolvedMethod();
492 // We don't print signatures, which conflict with c1visualizer format.
493 static constexpr bool kWithSignature = false;
494 // Note that we can only use the graph's dex file for the unresolved case. The
495 // other invokes might be coming from inlined methods.
496 ScopedObjectAccess soa(Thread::Current());
497 std::string method_name = (method == nullptr)
Nicolas Geoffraye6c0f2a2020-09-07 08:30:52 +0100498 ? invoke->GetMethodReference().PrettyMethod(kWithSignature)
Nicolas Geoffray5ceac0e2017-06-26 13:19:09 +0100499 : method->PrettyMethod(kWithSignature);
500 StartAttributeStream("method_name") << method_name;
Aart Bik2c148f02018-02-02 14:30:35 -0800501 StartAttributeStream("always_throws") << std::boolalpha
502 << invoke->AlwaysThrows()
503 << std::noboolalpha;
Nicolas Geoffray25b9c7d2020-09-17 17:34:34 +0100504 if (method != nullptr) {
505 StartAttributeStream("method_index") << method->GetMethodIndex();
506 }
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100507 }
508
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100509 void VisitInvokeUnresolved(HInvokeUnresolved* invoke) override {
Calin Juravle175dc732015-08-25 15:42:32 +0100510 VisitInvoke(invoke);
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100511 StartAttributeStream("invoke_type") << invoke->GetInvokeType();
Calin Juravle175dc732015-08-25 15:42:32 +0100512 }
513
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100514 void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) override {
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100515 VisitInvoke(invoke);
Vladimir Markof64242a2015-12-01 14:58:23 +0000516 StartAttributeStream("method_load_kind") << invoke->GetMethodLoadKind();
Scott Wakelingd60a1af2015-07-22 14:32:44 +0100517 StartAttributeStream("intrinsic") << invoke->GetIntrinsic();
Vladimir Markofbb184a2015-11-13 14:47:00 +0000518 if (invoke->IsStatic()) {
519 StartAttributeStream("clinit_check") << invoke->GetClinitCheckRequirement();
520 }
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100521 }
522
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100523 void VisitInvokeVirtual(HInvokeVirtual* invoke) override {
Nicolas Geoffraye5234232015-12-02 09:06:11 +0000524 VisitInvoke(invoke);
525 StartAttributeStream("intrinsic") << invoke->GetIntrinsic();
526 }
527
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100528 void VisitInvokePolymorphic(HInvokePolymorphic* invoke) override {
Orion Hodsonac141392017-01-13 11:53:47 +0000529 VisitInvoke(invoke);
530 StartAttributeStream("invoke_type") << "InvokePolymorphic";
531 }
532
Alex Light3a73ffb2021-01-25 14:11:05 +0000533 void VisitPredicatedInstanceFieldGet(HPredicatedInstanceFieldGet* iget) override {
534 StartAttributeStream("field_name") <<
535 iget->GetFieldInfo().GetDexFile().PrettyField(iget->GetFieldInfo().GetFieldIndex(),
536 /* with type */ false);
537 StartAttributeStream("field_type") << iget->GetFieldType();
538 }
539
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100540 void VisitInstanceFieldGet(HInstanceFieldGet* iget) override {
David Sehr709b0702016-10-13 09:12:37 -0700541 StartAttributeStream("field_name") <<
542 iget->GetFieldInfo().GetDexFile().PrettyField(iget->GetFieldInfo().GetFieldIndex(),
David Brazdil11edec72016-03-24 12:40:52 +0000543 /* with type */ false);
544 StartAttributeStream("field_type") << iget->GetFieldType();
545 }
546
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100547 void VisitInstanceFieldSet(HInstanceFieldSet* iset) override {
David Sehr709b0702016-10-13 09:12:37 -0700548 StartAttributeStream("field_name") <<
549 iset->GetFieldInfo().GetDexFile().PrettyField(iset->GetFieldInfo().GetFieldIndex(),
David Brazdil11edec72016-03-24 12:40:52 +0000550 /* with type */ false);
551 StartAttributeStream("field_type") << iset->GetFieldType();
Alex Light3a73ffb2021-01-25 14:11:05 +0000552 StartAttributeStream("predicated") << std::boolalpha << iset->GetIsPredicatedSet();
David Brazdil11edec72016-03-24 12:40:52 +0000553 }
554
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100555 void VisitStaticFieldGet(HStaticFieldGet* sget) override {
Vladimir Markobf3243b2017-08-30 14:06:54 +0100556 StartAttributeStream("field_name") <<
557 sget->GetFieldInfo().GetDexFile().PrettyField(sget->GetFieldInfo().GetFieldIndex(),
558 /* with type */ false);
559 StartAttributeStream("field_type") << sget->GetFieldType();
560 }
561
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100562 void VisitStaticFieldSet(HStaticFieldSet* sset) override {
Vladimir Markobf3243b2017-08-30 14:06:54 +0100563 StartAttributeStream("field_name") <<
564 sset->GetFieldInfo().GetDexFile().PrettyField(sset->GetFieldInfo().GetFieldIndex(),
565 /* with type */ false);
566 StartAttributeStream("field_type") << sset->GetFieldType();
567 }
568
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100569 void VisitUnresolvedInstanceFieldGet(HUnresolvedInstanceFieldGet* field_access) override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100570 StartAttributeStream("field_type") << field_access->GetFieldType();
571 }
572
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100573 void VisitUnresolvedInstanceFieldSet(HUnresolvedInstanceFieldSet* field_access) override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100574 StartAttributeStream("field_type") << field_access->GetFieldType();
575 }
576
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100577 void VisitUnresolvedStaticFieldGet(HUnresolvedStaticFieldGet* field_access) override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100578 StartAttributeStream("field_type") << field_access->GetFieldType();
579 }
580
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100581 void VisitUnresolvedStaticFieldSet(HUnresolvedStaticFieldSet* field_access) override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100582 StartAttributeStream("field_type") << field_access->GetFieldType();
583 }
584
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100585 void VisitTryBoundary(HTryBoundary* try_boundary) override {
David Brazdil56e1acc2015-06-30 15:41:36 +0100586 StartAttributeStream("kind") << (try_boundary->IsEntry() ? "entry" : "exit");
David Brazdilfc6a86a2015-06-26 10:33:45 +0000587 }
588
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100589 void VisitDeoptimize(HDeoptimize* deoptimize) override {
Nicolas Geoffray6f8e2c92017-03-23 14:37:26 +0000590 StartAttributeStream("kind") << deoptimize->GetKind();
591 }
592
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100593 void VisitVecOperation(HVecOperation* vec_operation) override {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100594 StartAttributeStream("packed_type") << vec_operation->GetPackedType();
595 }
596
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100597 void VisitVecMemoryOperation(HVecMemoryOperation* vec_mem_operation) override {
Aart Bik38a3f212017-10-20 17:02:21 -0700598 StartAttributeStream("alignment") << vec_mem_operation->GetAlignment().ToString();
599 }
600
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100601 void VisitVecHalvingAdd(HVecHalvingAdd* hadd) override {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100602 VisitVecBinaryOperation(hadd);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700603 StartAttributeStream("rounded") << std::boolalpha << hadd->IsRounded() << std::noboolalpha;
604 }
605
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100606 void VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) override {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100607 VisitVecOperation(instruction);
Artem Serovf34dd202017-04-10 17:41:46 +0100608 StartAttributeStream("kind") << instruction->GetOpKind();
609 }
610
Artem Serovaaac0e32018-08-07 00:52:22 +0100611 void VisitVecDotProd(HVecDotProd* instruction) override {
612 VisitVecOperation(instruction);
613 DataType::Type arg_type = instruction->InputAt(1)->AsVecOperation()->GetPackedType();
614 StartAttributeStream("type") << (instruction->IsZeroExtending() ?
615 DataType::ToUnsigned(arg_type) :
616 DataType::ToSigned(arg_type));
617 }
618
Artem Udovichenko4a0dad62016-01-26 12:28:31 +0300619#if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64)
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100620 void VisitMultiplyAccumulate(HMultiplyAccumulate* instruction) override {
Artem Udovichenko4a0dad62016-01-26 12:28:31 +0300621 StartAttributeStream("kind") << instruction->GetOpKind();
622 }
Artem Serov7fc63502016-02-09 17:15:29 +0000623
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100624 void VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) override {
Artem Serov7fc63502016-02-09 17:15:29 +0000625 StartAttributeStream("kind") << instruction->GetOpKind();
626 }
Artem Udovichenko4a0dad62016-01-26 12:28:31 +0300627
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100628 void VisitDataProcWithShifterOp(HDataProcWithShifterOp* instruction) override {
Alexandre Rames8626b742015-11-25 16:28:08 +0000629 StartAttributeStream("kind") << instruction->GetInstrKind() << "+" << instruction->GetOpKind();
Anton Kirilov74234da2017-01-13 14:42:47 +0000630 if (HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000631 StartAttributeStream("shift") << instruction->GetShiftAmount();
632 }
633 }
Alexandre Rames418318f2015-11-20 15:55:47 +0000634#endif
635
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800636 bool IsPass(const char* name) {
637 return strcmp(pass_name_, name) == 0;
638 }
639
Alex Lightdc281e72021-01-06 12:35:31 -0800640 bool IsDebugDump() {
641 return IsPass(kDebugDumpGraphName) || IsPass(kDebugDumpName);
642 }
643
David Brazdilb7e4a062014-12-29 15:35:02 +0000644 void PrintInstruction(HInstruction* instruction) {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100645 output_ << instruction->DebugName();
Vladimir Markoe9004912016-06-16 16:50:52 +0100646 HConstInputsRef inputs = instruction->GetInputs();
Vladimir Marko372f10e2016-05-17 16:30:10 +0100647 if (!inputs.empty()) {
648 StringList input_list;
649 for (const HInstruction* input : inputs) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100650 input_list.NewEntryStream() << DataType::TypeId(input->GetType()) << input->GetId();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100651 }
Vladimir Marko372f10e2016-05-17 16:30:10 +0100652 StartAttributeStream() << input_list;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100653 }
Vladimir Markofe948752018-03-23 18:11:43 +0000654 if (instruction->GetDexPc() != kNoDexPc) {
655 StartAttributeStream("dex_pc") << instruction->GetDexPc();
656 } else {
657 StartAttributeStream("dex_pc") << "n/a";
658 }
Vladimir Markodac82392021-05-10 15:44:24 +0000659 HBasicBlock* block = instruction->GetBlock();
Alex Lightdc281e72021-01-06 12:35:31 -0800660 if (IsPass(kDebugDumpName)) {
661 // Include block name for logcat use.
Vladimir Markodac82392021-05-10 15:44:24 +0000662 StartAttributeStream("block") << namer_.GetName(block);
Alex Lightdc281e72021-01-06 12:35:31 -0800663 }
David Brazdilc74652862015-05-13 17:50:09 +0100664 instruction->Accept(this);
Zheng Xubb7a28a2015-01-09 14:40:47 +0800665 if (instruction->HasEnvironment()) {
David Brazdilc74652862015-05-13 17:50:09 +0100666 StringList envs;
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100667 for (HEnvironment* environment = instruction->GetEnvironment();
668 environment != nullptr;
669 environment = environment->GetParent()) {
David Brazdilc74652862015-05-13 17:50:09 +0100670 StringList vregs;
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100671 for (size_t i = 0, e = environment->Size(); i < e; ++i) {
672 HInstruction* insn = environment->GetInstructionAt(i);
673 if (insn != nullptr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100674 vregs.NewEntryStream() << DataType::TypeId(insn->GetType()) << insn->GetId();
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100675 } else {
David Brazdilc74652862015-05-13 17:50:09 +0100676 vregs.NewEntryStream() << "_";
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100677 }
Zheng Xubb7a28a2015-01-09 14:40:47 +0800678 }
David Brazdilc74652862015-05-13 17:50:09 +0100679 envs.NewEntryStream() << vregs;
Zheng Xubb7a28a2015-01-09 14:40:47 +0800680 }
David Brazdilc74652862015-05-13 17:50:09 +0100681 StartAttributeStream("env") << envs;
Zheng Xubb7a28a2015-01-09 14:40:47 +0800682 }
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800683 if (IsPass(SsaLivenessAnalysis::kLivenessPassName)
David Brazdil5e8b1372015-01-23 14:39:08 +0000684 && is_after_pass_
685 && instruction->GetLifetimePosition() != kNoLifetime) {
David Brazdilc74652862015-05-13 17:50:09 +0100686 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100687 if (instruction->HasLiveInterval()) {
David Brazdilc74652862015-05-13 17:50:09 +0100688 LiveInterval* interval = instruction->GetLiveInterval();
David Brazdilc7a24852015-05-15 16:44:05 +0100689 StartAttributeStream("ranges")
690 << StringList(interval->GetFirstRange(), StringList::kSetBrackets);
Vladimir Marko82b07402017-03-01 19:02:04 +0000691 StartAttributeStream("uses") << StringList(interval->GetUses());
692 StartAttributeStream("env_uses") << StringList(interval->GetEnvironmentUses());
David Brazdilc74652862015-05-13 17:50:09 +0100693 StartAttributeStream("is_fixed") << interval->IsFixed();
694 StartAttributeStream("is_split") << interval->IsSplit();
695 StartAttributeStream("is_low") << interval->IsLowInterval();
696 StartAttributeStream("is_high") << interval->IsHighInterval();
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100697 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000698 }
699
700 if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) {
David Brazdilc74652862015-05-13 17:50:09 +0100701 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100702 LocationSummary* locations = instruction->GetLocations();
703 if (locations != nullptr) {
Vladimir Marko372f10e2016-05-17 16:30:10 +0100704 StringList input_list;
705 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
706 DumpLocation(input_list.NewEntryStream(), locations->InAt(i));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100707 }
David Brazdilc74652862015-05-13 17:50:09 +0100708 std::ostream& attr = StartAttributeStream("locations");
Vladimir Marko372f10e2016-05-17 16:30:10 +0100709 attr << input_list << "->";
David Brazdilc74652862015-05-13 17:50:09 +0100710 DumpLocation(attr, locations->Out());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100711 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000712 }
713
Vladimir Markodac82392021-05-10 15:44:24 +0000714 HLoopInformation* loop_info = (block != nullptr) ? block->GetLoopInformation() : nullptr;
Nicolas Geoffrayd7c2fdc2016-05-10 14:35:34 +0100715 if (loop_info == nullptr) {
716 StartAttributeStream("loop") << "none";
717 } else {
Alex Lightdc281e72021-01-06 12:35:31 -0800718 StartAttributeStream("loop") << namer_.GetName(loop_info->GetHeader());
Nicolas Geoffrayd7c2fdc2016-05-10 14:35:34 +0100719 HLoopInformation* outer = loop_info->GetPreHeader()->GetLoopInformation();
720 if (outer != nullptr) {
Alex Lightdc281e72021-01-06 12:35:31 -0800721 StartAttributeStream("outer_loop") << namer_.GetName(outer->GetHeader());
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000722 } else {
Nicolas Geoffrayd7c2fdc2016-05-10 14:35:34 +0100723 StartAttributeStream("outer_loop") << "none";
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000724 }
Nicolas Geoffrayd7c2fdc2016-05-10 14:35:34 +0100725 StartAttributeStream("irreducible")
726 << std::boolalpha << loop_info->IsIrreducible() << std::noboolalpha;
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000727 }
728
Vladimir Marko175e7862018-03-27 09:03:13 +0000729 // For the builder and the inliner, we want to add extra information on HInstructions
730 // that have reference types, and also HInstanceOf/HCheckcast.
David Brazdilbadd8262016-02-02 16:28:56 +0000731 if ((IsPass(HGraphBuilder::kBuilderPassName)
Alex Lightdc281e72021-01-06 12:35:31 -0800732 || IsPass(HInliner::kInlinerPassName)
733 || IsDebugDump())
Vladimir Marko175e7862018-03-27 09:03:13 +0000734 && (instruction->GetType() == DataType::Type::kReference ||
735 instruction->IsInstanceOf() ||
736 instruction->IsCheckCast())) {
737 ReferenceTypeInfo info = (instruction->GetType() == DataType::Type::kReference)
738 ? instruction->IsLoadClass()
739 ? instruction->AsLoadClass()->GetLoadedClassRTI()
740 : instruction->GetReferenceTypeInfo()
741 : instruction->IsInstanceOf()
742 ? instruction->AsInstanceOf()->GetTargetClassRTI()
743 : instruction->AsCheckCast()->GetTargetClassRTI();
Calin Juravle2e768302015-07-28 14:41:11 +0000744 ScopedObjectAccess soa(Thread::Current());
745 if (info.IsValid()) {
David Sehr709b0702016-10-13 09:12:37 -0700746 StartAttributeStream("klass")
747 << mirror::Class::PrettyDescriptor(info.GetTypeHandle().Get());
Vladimir Marko175e7862018-03-27 09:03:13 +0000748 if (instruction->GetType() == DataType::Type::kReference) {
749 StartAttributeStream("can_be_null")
750 << std::boolalpha << instruction->CanBeNull() << std::noboolalpha;
751 }
Calin Juravle2e768302015-07-28 14:41:11 +0000752 StartAttributeStream("exact") << std::boolalpha << info.IsExact() << std::noboolalpha;
Vladimir Marko175e7862018-03-27 09:03:13 +0000753 } else if (instruction->IsLoadClass() ||
754 instruction->IsInstanceOf() ||
755 instruction->IsCheckCast()) {
Calin Juravle98893e12015-10-02 21:05:03 +0100756 StartAttributeStream("klass") << "unresolved";
David Brazdil4833f5a2015-12-16 10:37:39 +0000757 } else {
Mark Mendellb2d38fd2015-11-16 12:21:53 -0500758 // The NullConstant may be added to the graph during other passes that happen between
759 // ReferenceTypePropagation and Inliner (e.g. InstructionSimplifier). If the inliner
760 // doesn't run or doesn't inline anything, the NullConstant remains untyped.
761 // So we should check NullConstants for validity only after reference type propagation.
David Brazdil4833f5a2015-12-16 10:37:39 +0000762 DCHECK(graph_in_bad_state_ ||
Alex Lightdc281e72021-01-06 12:35:31 -0800763 IsDebugDump() ||
David Brazdilbadd8262016-02-02 16:28:56 +0000764 (!is_after_pass_ && IsPass(HGraphBuilder::kBuilderPassName)))
David Brazdil4833f5a2015-12-16 10:37:39 +0000765 << instruction->DebugName() << instruction->GetId() << " has invalid rti "
766 << (is_after_pass_ ? "after" : "before") << " pass " << pass_name_;
Nicolas Geoffray7cb499b2015-06-17 11:35:11 +0100767 }
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100768 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100769 if (disasm_info_ != nullptr) {
770 DCHECK(disassembler_ != nullptr);
771 // If the information is available, disassemble the code generated for
772 // this instruction.
773 auto it = disasm_info_->GetInstructionIntervals().find(instruction);
774 if (it != disasm_info_->GetInstructionIntervals().end()
775 && it->second.start != it->second.end) {
David Brazdilfa02c9d2016-03-30 09:41:02 +0100776 output_ << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100777 disassembler_->Disassemble(output_, it->second.start, it->second.end);
778 }
779 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100780 }
781
782 void PrintInstructions(const HInstructionList& list) {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100783 for (HInstructionIterator it(list); !it.Done(); it.Advance()) {
784 HInstruction* instruction = it.Current();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100785 int bci = 0;
Vladimir Marko46817b82016-03-29 12:21:58 +0100786 size_t num_uses = instruction->GetUses().SizeSlow();
David Brazdilea55b932015-01-27 17:12:29 +0000787 AddIndent();
788 output_ << bci << " " << num_uses << " "
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100789 << DataType::TypeId(instruction->GetType()) << instruction->GetId() << " ";
David Brazdilb7e4a062014-12-29 15:35:02 +0000790 PrintInstruction(instruction);
David Brazdilfa02c9d2016-03-30 09:41:02 +0100791 output_ << " " << kEndInstructionMarker << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100792 }
793 }
794
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100795 void DumpStartOfDisassemblyBlock(const char* block_name,
796 int predecessor_index,
797 int successor_index) {
798 StartTag("block");
799 PrintProperty("name", block_name);
800 PrintInt("from_bci", -1);
801 PrintInt("to_bci", -1);
802 if (predecessor_index != -1) {
803 PrintProperty("predecessors", "B", predecessor_index);
804 } else {
805 PrintEmptyProperty("predecessors");
806 }
807 if (successor_index != -1) {
808 PrintProperty("successors", "B", successor_index);
809 } else {
810 PrintEmptyProperty("successors");
811 }
812 PrintEmptyProperty("xhandlers");
813 PrintEmptyProperty("flags");
814 StartTag("states");
815 StartTag("locals");
816 PrintInt("size", 0);
817 PrintProperty("method", "None");
818 EndTag("locals");
819 EndTag("states");
820 StartTag("HIR");
821 }
822
823 void DumpEndOfDisassemblyBlock() {
824 EndTag("HIR");
825 EndTag("block");
826 }
827
828 void DumpDisassemblyBlockForFrameEntry() {
829 DumpStartOfDisassemblyBlock(kDisassemblyBlockFrameEntry,
830 -1,
831 GetGraph()->GetEntryBlock()->GetBlockId());
832 output_ << " 0 0 disasm " << kDisassemblyBlockFrameEntry << " ";
833 GeneratedCodeInterval frame_entry = disasm_info_->GetFrameEntryInterval();
834 if (frame_entry.start != frame_entry.end) {
David Brazdilfa02c9d2016-03-30 09:41:02 +0100835 output_ << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100836 disassembler_->Disassemble(output_, frame_entry.start, frame_entry.end);
837 }
David Brazdilfa02c9d2016-03-30 09:41:02 +0100838 output_ << kEndInstructionMarker << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100839 DumpEndOfDisassemblyBlock();
840 }
841
842 void DumpDisassemblyBlockForSlowPaths() {
843 if (disasm_info_->GetSlowPathIntervals().empty()) {
844 return;
845 }
846 // If the graph has an exit block we attach the block for the slow paths
847 // after it. Else we just add the block to the graph without linking it to
848 // any other.
849 DumpStartOfDisassemblyBlock(
850 kDisassemblyBlockSlowPaths,
851 GetGraph()->HasExitBlock() ? GetGraph()->GetExitBlock()->GetBlockId() : -1,
852 -1);
853 for (SlowPathCodeInfo info : disasm_info_->GetSlowPathIntervals()) {
David Brazdilfa02c9d2016-03-30 09:41:02 +0100854 output_ << " 0 0 disasm " << info.slow_path->GetDescription() << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100855 disassembler_->Disassemble(output_, info.code_interval.start, info.code_interval.end);
David Brazdilfa02c9d2016-03-30 09:41:02 +0100856 output_ << kEndInstructionMarker << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100857 }
858 DumpEndOfDisassemblyBlock();
859 }
860
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100861 void Run() {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100862 StartTag("cfg");
Alex Lightdc281e72021-01-06 12:35:31 -0800863 std::ostringstream oss;
864 oss << pass_name_;
865 if (!IsDebugDump()) {
866 oss << " (" << (is_after_pass_ ? "after" : "before")
867 << (graph_in_bad_state_ ? ", bad_state" : "") << ")";
868 }
869 PrintProperty("name", oss.str().c_str());
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100870 if (disasm_info_ != nullptr) {
871 DumpDisassemblyBlockForFrameEntry();
872 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100873 VisitInsertionOrder();
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100874 if (disasm_info_ != nullptr) {
875 DumpDisassemblyBlockForSlowPaths();
876 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100877 EndTag("cfg");
David Brazdilfa02c9d2016-03-30 09:41:02 +0100878 Flush();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100879 }
880
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000881 void Run(HInstruction* instruction) {
882 output_ << DataType::TypeId(instruction->GetType()) << instruction->GetId() << " ";
883 PrintInstruction(instruction);
884 Flush();
885 }
886
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100887 void VisitBasicBlock(HBasicBlock* block) override {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100888 StartTag("block");
Alex Lightdc281e72021-01-06 12:35:31 -0800889 PrintProperty("name", block);
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100890 if (block->GetLifetimeStart() != kNoLifetime) {
891 // Piggy back on these fields to show the lifetime of the block.
892 PrintInt("from_bci", block->GetLifetimeStart());
893 PrintInt("to_bci", block->GetLifetimeEnd());
Alex Lightdc281e72021-01-06 12:35:31 -0800894 } else if (!IsDebugDump()) {
895 // Don't print useless information to logcat.
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100896 PrintInt("from_bci", -1);
897 PrintInt("to_bci", -1);
898 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100899 PrintPredecessors(block);
900 PrintSuccessors(block);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000901 PrintExceptionHandlers(block);
902
903 if (block->IsCatchBlock()) {
904 PrintProperty("flags", "catch_block");
Alex Lightdc281e72021-01-06 12:35:31 -0800905 } else if (!IsDebugDump()) {
906 // Don't print useless information to logcat
David Brazdilfc6a86a2015-06-26 10:33:45 +0000907 PrintEmptyProperty("flags");
908 }
909
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100910 if (block->GetDominator() != nullptr) {
Alex Lightdc281e72021-01-06 12:35:31 -0800911 PrintProperty("dominator", block->GetDominator());
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100912 }
913
Alex Lightdc281e72021-01-06 12:35:31 -0800914 if (!IsDebugDump() || !block->GetPhis().IsEmpty()) {
915 StartTag("states");
916 StartTag("locals");
917 PrintInt("size", 0);
918 PrintProperty("method", "None");
919 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
920 AddIndent();
921 HInstruction* instruction = it.Current();
922 output_ << instruction->GetId() << " " << DataType::TypeId(instruction->GetType())
923 << instruction->GetId() << "[ ";
924 for (const HInstruction* input : instruction->GetInputs()) {
925 output_ << input->GetId() << " ";
926 }
927 output_ << "]\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100928 }
Alex Lightdc281e72021-01-06 12:35:31 -0800929 EndTag("locals");
930 EndTag("states");
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100931 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100932
933 StartTag("HIR");
934 PrintInstructions(block->GetPhis());
935 PrintInstructions(block->GetInstructions());
936 EndTag("HIR");
937 EndTag("block");
938 }
939
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100940 static constexpr const char* const kEndInstructionMarker = "<|@";
941 static constexpr const char* const kDisassemblyBlockFrameEntry = "FrameEntry";
942 static constexpr const char* const kDisassemblyBlockSlowPaths = "SlowPaths";
943
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100944 private:
945 std::ostream& output_;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100946 const char* pass_name_;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000947 const bool is_after_pass_;
David Brazdilffee3d32015-07-06 11:48:53 +0100948 const bool graph_in_bad_state_;
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000949 const CodeGenerator* codegen_;
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100950 const DisassemblyInformation* disasm_info_;
Alex Lightdc281e72021-01-06 12:35:31 -0800951 const BlockNamer& namer_;
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100952 std::unique_ptr<HGraphVisualizerDisassembler> disassembler_;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100953 size_t indent_;
954
955 DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter);
956};
957
Alex Lightdc281e72021-01-06 12:35:31 -0800958std::ostream& HGraphVisualizer::OptionalDefaultNamer::PrintName(std::ostream& os,
959 HBasicBlock* blk) const {
960 if (namer_) {
961 return namer_->get().PrintName(os, blk);
962 } else {
963 return BlockNamer::PrintName(os, blk);
964 }
965}
966
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100967HGraphVisualizer::HGraphVisualizer(std::ostream* output,
968 HGraph* graph,
Alex Lightdc281e72021-01-06 12:35:31 -0800969 const CodeGenerator* codegen,
970 std::optional<std::reference_wrapper<const BlockNamer>> namer)
971 : output_(output), graph_(graph), codegen_(codegen), namer_(namer) {}
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100972
David Brazdil62e074f2015-04-07 18:09:37 +0100973void HGraphVisualizer::PrintHeader(const char* method_name) const {
974 DCHECK(output_ != nullptr);
Alex Lightdc281e72021-01-06 12:35:31 -0800975 HGraphVisualizerPrinter printer(graph_, *output_, "", true, false, codegen_, namer_);
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100976 printer.StartTag("compilation");
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000977 printer.PrintProperty("name", method_name);
978 printer.PrintProperty("method", method_name);
Nicolas Geoffray0d3f5782014-05-14 09:43:38 +0100979 printer.PrintTime("date");
980 printer.EndTag("compilation");
David Brazdilfa02c9d2016-03-30 09:41:02 +0100981 printer.Flush();
Nicolas Geoffray0d3f5782014-05-14 09:43:38 +0100982}
983
Fabio Rinaldi52d53542020-02-10 17:28:06 +0000984std::string HGraphVisualizer::InsertMetaDataAsCompilationBlock(const std::string& meta_data) {
985 std::string time_str = std::to_string(time(nullptr));
986 std::string quoted_meta_data = "\"" + meta_data + "\"";
987 return StringPrintf("begin_compilation\n"
988 " name %s\n"
989 " method %s\n"
990 " date %s\n"
991 "end_compilation\n",
992 quoted_meta_data.c_str(),
993 quoted_meta_data.c_str(),
994 time_str.c_str());
995}
996
Alex Lightdc281e72021-01-06 12:35:31 -0800997void HGraphVisualizer::DumpGraphDebug() const {
998 DumpGraph(/* pass_name= */ kDebugDumpGraphName,
999 /* is_after_pass= */ false,
1000 /* graph_in_bad_state= */ true);
1001}
1002
David Brazdilffee3d32015-07-06 11:48:53 +01001003void HGraphVisualizer::DumpGraph(const char* pass_name,
1004 bool is_after_pass,
1005 bool graph_in_bad_state) const {
David Brazdil5e8b1372015-01-23 14:39:08 +00001006 DCHECK(output_ != nullptr);
Vladimir Markofa6b93c2015-09-15 10:15:55 +01001007 if (!graph_->GetBlocks().empty()) {
David Brazdilffee3d32015-07-06 11:48:53 +01001008 HGraphVisualizerPrinter printer(graph_,
1009 *output_,
1010 pass_name,
1011 is_after_pass,
1012 graph_in_bad_state,
Alex Lightdc281e72021-01-06 12:35:31 -08001013 codegen_,
1014 namer_);
David Brazdilee690a32014-12-01 17:04:16 +00001015 printer.Run();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +01001016 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +01001017}
1018
Alexandre Rameseb7b7392015-06-19 14:47:01 +01001019void HGraphVisualizer::DumpGraphWithDisassembly() const {
1020 DCHECK(output_ != nullptr);
Vladimir Markofa6b93c2015-09-15 10:15:55 +01001021 if (!graph_->GetBlocks().empty()) {
David Brazdilffee3d32015-07-06 11:48:53 +01001022 HGraphVisualizerPrinter printer(graph_,
1023 *output_,
1024 "disassembly",
Andreas Gampe3db70682018-12-26 15:12:03 -08001025 /* is_after_pass= */ true,
1026 /* graph_in_bad_state= */ false,
David Brazdilffee3d32015-07-06 11:48:53 +01001027 codegen_,
Alex Lightdc281e72021-01-06 12:35:31 -08001028 namer_,
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001029 codegen_->GetDisassemblyInformation());
Alexandre Rameseb7b7392015-06-19 14:47:01 +01001030 printer.Run();
1031 }
1032}
1033
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001034void HGraphVisualizer::DumpInstruction(std::ostream* output,
1035 HGraph* graph,
1036 HInstruction* instruction) {
Alex Lightdc281e72021-01-06 12:35:31 -08001037 BlockNamer namer;
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001038 HGraphVisualizerPrinter printer(graph,
1039 *output,
Alex Lightdc281e72021-01-06 12:35:31 -08001040 /* pass_name= */ kDebugDumpName,
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001041 /* is_after_pass= */ false,
1042 /* graph_in_bad_state= */ false,
Alex Lightdc281e72021-01-06 12:35:31 -08001043 /* codegen= */ nullptr,
1044 /* namer= */ namer);
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001045 printer.Run(instruction);
1046}
1047
Nicolas Geoffrayf635e632014-05-14 09:43:38 +01001048} // namespace art