blob: da34af28a56689435907d0637cb2fc0040019cf2 [file] [log] [blame]
Nicolas Geoffrayf635e632014-05-14 09:43:38 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "graph_visualizer.h"
18
Alexandre Rameseb7b7392015-06-19 14:47:01 +010019#include <dlfcn.h>
20
21#include <cctype>
22#include <sstream>
23
Fabio Rinaldi52d53542020-02-10 17:28:06 +000024#include "android-base/stringprintf.h"
Vladimir Marko69d310e2017-10-09 14:12:23 +010025#include "art_method.h"
Nicolas Geoffray25b9c7d2020-09-17 17:34:34 +010026#include "art_method-inl.h"
Vladimir Marko3fae1292019-06-07 11:26:25 +010027#include "base/intrusive_forward_list.h"
Aart Bik09e8d5f2016-01-22 16:49:55 -080028#include "bounds_check_elimination.h"
David Brazdilbadd8262016-02-02 16:28:56 +000029#include "builder.h"
Nicolas Geoffraya7062e02014-05-22 12:50:17 +010030#include "code_generator.h"
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010031#include "data_type-inl.h"
David Brazdila4b8c212015-05-07 09:59:30 +010032#include "dead_code_elimination.h"
David Sehrb2ec9f52018-02-21 13:20:31 -080033#include "dex/descriptors_names.h"
Alexandre Rameseb7b7392015-06-19 14:47:01 +010034#include "disassembler.h"
Calin Juravlecdfed3d2015-10-26 14:05:01 +000035#include "inliner.h"
Andreas Gampe7c3952f2015-02-19 18:21:24 -080036#include "licm.h"
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010037#include "nodes.h"
Nicolas Geoffray82091da2015-01-26 10:02:45 +000038#include "optimization.h"
Nicolas Geoffray7cb499b2015-06-17 11:35:11 +010039#include "reference_type_propagation.h"
Matthew Gharritye9288852016-07-14 14:08:16 -070040#include "register_allocator_linear_scan.h"
Vladimir Marko69d310e2017-10-09 14:12:23 +010041#include "scoped_thread_state_change-inl.h"
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +010042#include "ssa_liveness_analysis.h"
Alexandre Rameseb7b7392015-06-19 14:47:01 +010043#include "utils/assembler.h"
David Brazdilc74652862015-05-13 17:50:09 +010044
Vladimir Marko0a516052019-10-14 13:00:44 +000045namespace art {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +010046
Alex Lightdc281e72021-01-06 12:35:31 -080047// Unique pass-name to identify that the dump is for printing to log.
48constexpr const char* kDebugDumpName = "debug";
49constexpr const char* kDebugDumpGraphName = "debug_graph";
50
Fabio Rinaldi52d53542020-02-10 17:28:06 +000051using android::base::StringPrintf;
52
David Brazdilc74652862015-05-13 17:50:09 +010053static bool HasWhitespace(const char* str) {
54 DCHECK(str != nullptr);
55 while (str[0] != 0) {
56 if (isspace(str[0])) {
57 return true;
58 }
59 str++;
60 }
61 return false;
62}
63
64class StringList {
65 public:
David Brazdilc7a24852015-05-15 16:44:05 +010066 enum Format {
67 kArrayBrackets,
68 kSetBrackets,
69 };
70
David Brazdilc74652862015-05-13 17:50:09 +010071 // Create an empty list
David Brazdilf1a9ff72015-05-18 16:04:53 +010072 explicit StringList(Format format = kArrayBrackets) : format_(format), is_empty_(true) {}
David Brazdilc74652862015-05-13 17:50:09 +010073
74 // Construct StringList from a linked list. List element class T
75 // must provide methods `GetNext` and `Dump`.
76 template<class T>
David Brazdilc7a24852015-05-15 16:44:05 +010077 explicit StringList(T* first_entry, Format format = kArrayBrackets) : StringList(format) {
David Brazdilc74652862015-05-13 17:50:09 +010078 for (T* current = first_entry; current != nullptr; current = current->GetNext()) {
79 current->Dump(NewEntryStream());
80 }
81 }
Vladimir Marko82b07402017-03-01 19:02:04 +000082 // Construct StringList from a list of elements. The value type must provide method `Dump`.
83 template <typename Container>
84 explicit StringList(const Container& list, Format format = kArrayBrackets) : StringList(format) {
85 for (const typename Container::value_type& current : list) {
86 current.Dump(NewEntryStream());
87 }
88 }
David Brazdilc74652862015-05-13 17:50:09 +010089
90 std::ostream& NewEntryStream() {
91 if (is_empty_) {
92 is_empty_ = false;
93 } else {
David Brazdilc57397b2015-05-15 16:01:59 +010094 sstream_ << ",";
David Brazdilc74652862015-05-13 17:50:09 +010095 }
96 return sstream_;
97 }
98
99 private:
David Brazdilc7a24852015-05-15 16:44:05 +0100100 Format format_;
David Brazdilc74652862015-05-13 17:50:09 +0100101 bool is_empty_;
102 std::ostringstream sstream_;
103
104 friend std::ostream& operator<<(std::ostream& os, const StringList& list);
105};
106
107std::ostream& operator<<(std::ostream& os, const StringList& list) {
David Brazdilc7a24852015-05-15 16:44:05 +0100108 switch (list.format_) {
109 case StringList::kArrayBrackets: return os << "[" << list.sstream_.str() << "]";
110 case StringList::kSetBrackets: return os << "{" << list.sstream_.str() << "}";
111 default:
112 LOG(FATAL) << "Invalid StringList format";
113 UNREACHABLE();
114 }
David Brazdilc74652862015-05-13 17:50:09 +0100115}
116
Martin Stjernholm40746872020-09-29 13:58:10 +0100117#ifndef ART_STATIC_LIBART_COMPILER
Andreas Gampec55bb392018-09-21 00:02:02 +0000118using create_disasm_prototype = Disassembler*(InstructionSet, DisassemblerOptions*);
Martin Stjernholm40746872020-09-29 13:58:10 +0100119#endif
120
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100121class HGraphVisualizerDisassembler {
122 public:
Aart Bikd3059e72016-05-11 10:30:47 -0700123 HGraphVisualizerDisassembler(InstructionSet instruction_set,
124 const uint8_t* base_address,
125 const uint8_t* end_address)
David Brazdil3a690be2015-06-23 10:22:38 +0100126 : instruction_set_(instruction_set), disassembler_(nullptr) {
Martin Stjernholm40746872020-09-29 13:58:10 +0100127#ifndef ART_STATIC_LIBART_COMPILER
Roland Levillain5b768892020-02-19 15:49:02 +0000128 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);
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100131 if (libart_disassembler_handle_ == nullptr) {
Roland Levillain5b768892020-02-19 15:49:02 +0000132 LOG(ERROR) << "Failed to dlopen " << libart_disassembler_so_name << ": " << dlerror();
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100133 return;
134 }
Roland Levillain5b768892020-02-19 15:49:02 +0000135 constexpr const char* create_disassembler_symbol = "create_disassembler";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100136 create_disasm_prototype* create_disassembler = reinterpret_cast<create_disasm_prototype*>(
Roland Levillain5b768892020-02-19 15:49:02 +0000137 dlsym(libart_disassembler_handle_, create_disassembler_symbol));
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100138 if (create_disassembler == nullptr) {
Roland Levillain5b768892020-02-19 15:49:02 +0000139 LOG(ERROR) << "Could not find " << create_disassembler_symbol << " entry in "
140 << libart_disassembler_so_name << ": " << dlerror();
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100141 return;
142 }
Martin Stjernholm40746872020-09-29 13:58:10 +0100143#endif
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100144 // 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.
Martin Stjernholm40746872020-09-29 13:58:10 +0100147 disassembler_ = std::unique_ptr<Disassembler>(create_disassembler(
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100148 instruction_set,
Andreas Gampe3db70682018-12-26 15:12:03 -0800149 new DisassemblerOptions(/* absolute_addresses= */ false,
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100150 base_address,
Aart Bikd3059e72016-05-11 10:30:47 -0700151 end_address,
Andreas Gampe3db70682018-12-26 15:12:03 -0800152 /* can_read_literals= */ true,
Andreas Gampe372f3a32016-08-19 10:49:06 -0700153 Is64BitInstructionSet(instruction_set)
154 ? &Thread::DumpThreadOffset<PointerSize::k64>
155 : &Thread::DumpThreadOffset<PointerSize::k32>)));
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100156 }
157
158 ~HGraphVisualizerDisassembler() {
159 // We need to call ~Disassembler() before we close the library.
160 disassembler_.reset();
Martin Stjernholm40746872020-09-29 13:58:10 +0100161#ifndef ART_STATIC_LIBART_COMPILER
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100162 if (libart_disassembler_handle_ != nullptr) {
163 dlclose(libart_disassembler_handle_);
164 }
Martin Stjernholm40746872020-09-29 13:58:10 +0100165#endif
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100166 }
167
168 void Disassemble(std::ostream& output, size_t start, size_t end) const {
David Brazdil3a690be2015-06-23 10:22:38 +0100169 if (disassembler_ == nullptr) {
170 return;
171 }
172
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100173 const uint8_t* base = disassembler_->GetDisassemblerOptions()->base_address_;
Vladimir Marko33bff252017-11-01 14:35:42 +0000174 if (instruction_set_ == InstructionSet::kThumb2) {
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100175 // 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
Martin Stjernholm40746872020-09-29 13:58:10 +0100186#ifndef ART_STATIC_LIBART_COMPILER
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100187 void* libart_disassembler_handle_;
Martin Stjernholm40746872020-09-29 13:58:10 +0100188#endif
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100189};
190
191
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100192/**
193 * HGraph visitor to generate a file suitable for the c1visualizer tool and IRHydra.
194 */
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100195class HGraphVisualizerPrinter : public HGraphDelegateVisitor {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100196 public:
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100197 HGraphVisualizerPrinter(HGraph* graph,
198 std::ostream& output,
199 const char* pass_name,
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000200 bool is_after_pass,
David Brazdilffee3d32015-07-06 11:48:53 +0100201 bool graph_in_bad_state,
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000202 const CodeGenerator* codegen,
Alex Lightdc281e72021-01-06 12:35:31 -0800203 const BlockNamer& namer,
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100204 const DisassemblyInformation* disasm_info = nullptr)
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100205 : HGraphDelegateVisitor(graph),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100206 output_(output),
207 pass_name_(pass_name),
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000208 is_after_pass_(is_after_pass),
David Brazdilffee3d32015-07-06 11:48:53 +0100209 graph_in_bad_state_(graph_in_bad_state),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100210 codegen_(codegen),
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100211 disasm_info_(disasm_info),
Alex Lightdc281e72021-01-06 12:35:31 -0800212 namer_(namer),
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100213 disassembler_(disasm_info_ != nullptr
214 ? new HGraphVisualizerDisassembler(
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000215 codegen_->GetInstructionSet(),
216 codegen_->GetAssembler().CodeBufferBaseAddress(),
217 codegen_->GetAssembler().CodeBufferBaseAddress()
218 + codegen_->GetAssembler().CodeSize())
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100219 : nullptr),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100220 indent_(0) {}
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100221
David Brazdilfa02c9d2016-03-30 09:41:02 +0100222 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
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100228 void StartTag(const char* name) {
229 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100230 output_ << "begin_" << name << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100231 indent_++;
232 }
233
234 void EndTag(const char* name) {
235 indent_--;
236 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100237 output_ << "end_" << name << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100238 }
239
Alex Lightdc281e72021-01-06 12:35:31 -0800240 void PrintProperty(const char* name, HBasicBlock* blk) {
241 AddIndent();
242 output_ << name << " \"" << namer_.GetName(blk) << "\"\n";
243 }
244
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100245 void PrintProperty(const char* name, const char* property) {
246 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100247 output_ << name << " \"" << property << "\"\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100248 }
249
250 void PrintProperty(const char* name, const char* property, int id) {
251 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100252 output_ << name << " \"" << property << id << "\"\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100253 }
254
255 void PrintEmptyProperty(const char* name) {
256 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100257 output_ << name << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100258 }
259
260 void PrintTime(const char* name) {
261 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100262 output_ << name << " " << time(nullptr) << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100263 }
264
265 void PrintInt(const char* name, int value) {
266 AddIndent();
David Brazdilfa02c9d2016-03-30 09:41:02 +0100267 output_ << name << " " << value << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100268 }
269
270 void AddIndent() {
271 for (size_t i = 0; i < indent_; ++i) {
272 output_ << " ";
273 }
274 }
275
276 void PrintPredecessors(HBasicBlock* block) {
277 AddIndent();
278 output_ << "predecessors";
Vladimir Marko60584552015-09-03 13:35:12 +0000279 for (HBasicBlock* predecessor : block->GetPredecessors()) {
Alex Lightdc281e72021-01-06 12:35:31 -0800280 output_ << " \"" << namer_.GetName(predecessor) << "\" ";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100281 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100282 if (block->IsEntryBlock() && (disasm_info_ != nullptr)) {
283 output_ << " \"" << kDisassemblyBlockFrameEntry << "\" ";
284 }
David Brazdilfa02c9d2016-03-30 09:41:02 +0100285 output_<< "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100286 }
287
288 void PrintSuccessors(HBasicBlock* block) {
289 AddIndent();
290 output_ << "successors";
David Brazdild26a4112015-11-10 11:07:31 +0000291 for (HBasicBlock* successor : block->GetNormalSuccessors()) {
Alex Lightdc281e72021-01-06 12:35:31 -0800292 output_ << " \"" << namer_.GetName(successor) << "\" ";
David Brazdilfc6a86a2015-06-26 10:33:45 +0000293 }
David Brazdilfa02c9d2016-03-30 09:41:02 +0100294 output_<< "\n";
David Brazdilfc6a86a2015-06-26 10:33:45 +0000295 }
296
297 void PrintExceptionHandlers(HBasicBlock* block) {
Alex Lightdc281e72021-01-06 12:35:31 -0800298 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 }
David Brazdilfc6a86a2015-06-26 10:33:45 +0000304 AddIndent();
305 output_ << "xhandlers";
David Brazdild26a4112015-11-10 11:07:31 +0000306 for (HBasicBlock* handler : block->GetExceptionalSuccessors()) {
Alex Lightdc281e72021-01-06 12:35:31 -0800307 output_ << " \"" << namer_.GetName(handler) << "\" ";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100308 }
Alex Lightdc281e72021-01-06 12:35:31 -0800309 if (has_slow_paths) {
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100310 output_ << " \"" << kDisassemblyBlockSlowPaths << "\" ";
311 }
David Brazdilfa02c9d2016-03-30 09:41:02 +0100312 output_<< "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100313 }
314
David Brazdilc74652862015-05-13 17:50:09 +0100315 void DumpLocation(std::ostream& stream, const Location& location) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000316 DCHECK(codegen_ != nullptr);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100317 if (location.IsRegister()) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000318 codegen_->DumpCoreRegister(stream, location.reg());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100319 } else if (location.IsFpuRegister()) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000320 codegen_->DumpFloatingPointRegister(stream, location.reg());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100321 } else if (location.IsConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100322 stream << "#";
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100323 HConstant* constant = location.GetConstant();
324 if (constant->IsIntConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100325 stream << constant->AsIntConstant()->GetValue();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100326 } else if (constant->IsLongConstant()) {
David Brazdilc74652862015-05-13 17:50:09 +0100327 stream << constant->AsLongConstant()->GetValue();
Alexandre Ramesc2c52a12016-08-02 13:45:28 +0100328 } 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";
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100334 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100335 } else if (location.IsInvalid()) {
David Brazdilc74652862015-05-13 17:50:09 +0100336 stream << "invalid";
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100337 } else if (location.IsStackSlot()) {
David Brazdilc74652862015-05-13 17:50:09 +0100338 stream << location.GetStackIndex() << "(sp)";
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000339 } else if (location.IsFpuRegisterPair()) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000340 codegen_->DumpFloatingPointRegister(stream, location.low());
David Brazdilc74652862015-05-13 17:50:09 +0100341 stream << "|";
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000342 codegen_->DumpFloatingPointRegister(stream, location.high());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000343 } else if (location.IsRegisterPair()) {
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000344 codegen_->DumpCoreRegister(stream, location.low());
David Brazdilc74652862015-05-13 17:50:09 +0100345 stream << "|";
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000346 codegen_->DumpCoreRegister(stream, location.high());
Mark Mendell09ed1a32015-03-25 08:30:06 -0400347 } else if (location.IsUnallocated()) {
David Brazdilc74652862015-05-13 17:50:09 +0100348 stream << "unallocated";
Aart Bik5576f372017-03-23 16:17:37 -0700349 } else if (location.IsDoubleStackSlot()) {
David Brazdilc74652862015-05-13 17:50:09 +0100350 stream << "2x" << location.GetStackIndex() << "(sp)";
Aart Bik5576f372017-03-23 16:17:37 -0700351 } else {
352 DCHECK(location.IsSIMDStackSlot());
353 stream << "4x" << location.GetStackIndex() << "(sp)";
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100354 }
355 }
356
David Brazdilc74652862015-05-13 17:50:09 +0100357 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
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100367 void VisitParallelMove(HParallelMove* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100368 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
369 StringList moves;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100370 for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) {
371 MoveOperands* move = instruction->MoveOperandsAt(i);
David Brazdilc74652862015-05-13 17:50:09 +0100372 std::ostream& str = moves.NewEntryStream();
373 DumpLocation(str, move->GetSource());
374 str << "->";
375 DumpLocation(str, move->GetDestination());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100376 }
David Brazdilc74652862015-05-13 17:50:09 +0100377 StartAttributeStream("moves") << moves;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100378 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100379
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100380 void VisitIntConstant(HIntConstant* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100381 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000382 }
383
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100384 void VisitLongConstant(HLongConstant* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100385 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000386 }
387
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100388 void VisitFloatConstant(HFloatConstant* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100389 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000390 }
391
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100392 void VisitDoubleConstant(HDoubleConstant* instruction) override {
David Brazdilc74652862015-05-13 17:50:09 +0100393 StartAttributeStream() << instruction->GetValue();
David Brazdilb7e4a062014-12-29 15:35:02 +0000394 }
395
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100396 void VisitPhi(HPhi* phi) override {
David Brazdilc74652862015-05-13 17:50:09 +0100397 StartAttributeStream("reg") << phi->GetRegNumber();
David Brazdilffee3d32015-07-06 11:48:53 +0100398 StartAttributeStream("is_catch_phi") << std::boolalpha << phi->IsCatchPhi() << std::noboolalpha;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000399 }
400
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100401 void VisitMemoryBarrier(HMemoryBarrier* barrier) override {
David Brazdilc74652862015-05-13 17:50:09 +0100402 StartAttributeStream("kind") << barrier->GetBarrierKind();
Calin Juravle27df7582015-04-17 19:12:31 +0100403 }
404
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100405 void VisitMonitorOperation(HMonitorOperation* monitor) override {
David Brazdilbff75032015-07-08 17:26:51 +0000406 StartAttributeStream("kind") << (monitor->IsEnter() ? "enter" : "exit");
407 }
408
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100409 void VisitLoadClass(HLoadClass* load_class) override {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100410 StartAttributeStream("load_kind") << load_class->GetLoadKind();
Alex Lightdc281e72021-01-06 12:35:31 -0800411 StartAttributeStream("class_name")
412 << load_class->GetDexFile().PrettyType(load_class->GetTypeIndex());
413 StartAttributeStream("gen_clinit_check")
414 << std::boolalpha << load_class->MustGenerateClinitCheck() << std::noboolalpha;
Calin Juravle386062d2015-10-07 18:55:43 +0100415 StartAttributeStream("needs_access_check") << std::boolalpha
416 << load_class->NeedsAccessCheck() << std::noboolalpha;
Calin Juravle0ba218d2015-05-19 18:46:01 +0100417 }
418
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100419 void VisitLoadMethodHandle(HLoadMethodHandle* load_method_handle) override {
Orion Hodsondbaa5c72018-05-10 08:22:46 +0100420 StartAttributeStream("load_kind") << "RuntimeCall";
421 StartAttributeStream("method_handle_index") << load_method_handle->GetMethodHandleIndex();
422 }
423
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100424 void VisitLoadMethodType(HLoadMethodType* load_method_type) override {
Orion Hodson18259d72018-04-12 11:18:23 +0100425 StartAttributeStream("load_kind") << "RuntimeCall";
426 const DexFile& dex_file = load_method_type->GetDexFile();
Alex Lightdc281e72021-01-06 12:35:31 -0800427 if (dex_file.NumProtoIds() >= load_method_type->GetProtoIndex().index_) {
428 const dex::ProtoId& proto_id = dex_file.GetProtoId(load_method_type->GetProtoIndex());
429 StartAttributeStream("method_type") << dex_file.GetProtoSignature(proto_id);
430 } else {
431 StartAttributeStream("method_type")
432 << "<<Unknown proto-idx: " << load_method_type->GetProtoIndex() << ">>";
433 }
Orion Hodson18259d72018-04-12 11:18:23 +0100434 }
435
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100436 void VisitLoadString(HLoadString* load_string) override {
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000437 StartAttributeStream("load_kind") << load_string->GetLoadKind();
438 }
439
Vladimir Marko175e7862018-03-27 09:03:13 +0000440 void HandleTypeCheckInstruction(HTypeCheckInstruction* check) {
441 StartAttributeStream("check_kind") << check->GetTypeCheckKind();
Nicolas Geoffraybff7a522018-01-25 13:33:07 +0000442 StartAttributeStream("must_do_null_check") << std::boolalpha
Vladimir Marko175e7862018-03-27 09:03:13 +0000443 << check->MustDoNullCheck() << std::noboolalpha;
444 if (check->GetTypeCheckKind() == TypeCheckKind::kBitstringCheck) {
445 StartAttributeStream("path_to_root") << std::hex
446 << "0x" << check->GetBitstringPathToRoot() << std::dec;
447 StartAttributeStream("mask") << std::hex << "0x" << check->GetBitstringMask() << std::dec;
448 }
449 }
450
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100451 void VisitCheckCast(HCheckCast* check_cast) override {
Vladimir Marko175e7862018-03-27 09:03:13 +0000452 HandleTypeCheckInstruction(check_cast);
Guillaume "Vermeille" Sanchez9099ef72015-05-20 15:19:21 +0100453 }
454
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100455 void VisitInstanceOf(HInstanceOf* instance_of) override {
Vladimir Marko175e7862018-03-27 09:03:13 +0000456 HandleTypeCheckInstruction(instance_of);
Guillaume "Vermeille" Sanchez9099ef72015-05-20 15:19:21 +0100457 }
458
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100459 void VisitArrayLength(HArrayLength* array_length) override {
Vladimir Markodce016e2016-04-28 13:10:02 +0100460 StartAttributeStream("is_string_length") << std::boolalpha
461 << array_length->IsStringLength() << std::noboolalpha;
Mark Mendellee8d9712016-07-12 11:13:15 -0400462 if (array_length->IsEmittedAtUseSite()) {
463 StartAttributeStream("emitted_at_use") << "true";
464 }
Vladimir Markodce016e2016-04-28 13:10:02 +0100465 }
466
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100467 void VisitBoundsCheck(HBoundsCheck* bounds_check) override {
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100468 StartAttributeStream("is_string_char_at") << std::boolalpha
469 << bounds_check->IsStringCharAt() << std::noboolalpha;
470 }
471
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100472 void VisitArrayGet(HArrayGet* array_get) override {
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100473 StartAttributeStream("is_string_char_at") << std::boolalpha
474 << array_get->IsStringCharAt() << std::noboolalpha;
475 }
476
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100477 void VisitArraySet(HArraySet* array_set) override {
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100478 StartAttributeStream("value_can_be_null") << std::boolalpha
479 << array_set->GetValueCanBeNull() << std::noboolalpha;
Roland Levillainb133ec62016-03-23 12:40:35 +0000480 StartAttributeStream("needs_type_check") << std::boolalpha
481 << array_set->NeedsTypeCheck() << std::noboolalpha;
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100482 }
483
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100484 void VisitCompare(HCompare* compare) override {
Vladimir Marko9974e3c2020-06-10 16:27:06 +0100485 StartAttributeStream("bias") << compare->GetBias();
Roland Levillain31dd3d62016-02-16 12:21:02 +0000486 }
487
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100488 void VisitInvoke(HInvoke* invoke) override {
Nicolas Geoffraye6c0f2a2020-09-07 08:30:52 +0100489 StartAttributeStream("dex_file_index") << invoke->GetMethodReference().index;
Nicolas Geoffray5ceac0e2017-06-26 13:19:09 +0100490 ArtMethod* method = invoke->GetResolvedMethod();
491 // We don't print signatures, which conflict with c1visualizer format.
492 static constexpr bool kWithSignature = false;
493 // Note that we can only use the graph's dex file for the unresolved case. The
494 // other invokes might be coming from inlined methods.
495 ScopedObjectAccess soa(Thread::Current());
496 std::string method_name = (method == nullptr)
Nicolas Geoffraye6c0f2a2020-09-07 08:30:52 +0100497 ? invoke->GetMethodReference().PrettyMethod(kWithSignature)
Nicolas Geoffray5ceac0e2017-06-26 13:19:09 +0100498 : method->PrettyMethod(kWithSignature);
499 StartAttributeStream("method_name") << method_name;
Aart Bik2c148f02018-02-02 14:30:35 -0800500 StartAttributeStream("always_throws") << std::boolalpha
501 << invoke->AlwaysThrows()
502 << std::noboolalpha;
Nicolas Geoffray25b9c7d2020-09-17 17:34:34 +0100503 if (method != nullptr) {
504 StartAttributeStream("method_index") << method->GetMethodIndex();
505 }
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100506 }
507
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100508 void VisitInvokeUnresolved(HInvokeUnresolved* invoke) override {
Calin Juravle175dc732015-08-25 15:42:32 +0100509 VisitInvoke(invoke);
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100510 StartAttributeStream("invoke_type") << invoke->GetInvokeType();
Calin Juravle175dc732015-08-25 15:42:32 +0100511 }
512
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100513 void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) override {
Nicolas Geoffray842acd42015-07-01 13:00:15 +0100514 VisitInvoke(invoke);
Vladimir Markof64242a2015-12-01 14:58:23 +0000515 StartAttributeStream("method_load_kind") << invoke->GetMethodLoadKind();
Scott Wakelingd60a1af2015-07-22 14:32:44 +0100516 StartAttributeStream("intrinsic") << invoke->GetIntrinsic();
Vladimir Markofbb184a2015-11-13 14:47:00 +0000517 if (invoke->IsStatic()) {
518 StartAttributeStream("clinit_check") << invoke->GetClinitCheckRequirement();
519 }
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100520 }
521
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100522 void VisitInvokeVirtual(HInvokeVirtual* invoke) override {
Nicolas Geoffraye5234232015-12-02 09:06:11 +0000523 VisitInvoke(invoke);
524 StartAttributeStream("intrinsic") << invoke->GetIntrinsic();
525 }
526
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100527 void VisitInvokePolymorphic(HInvokePolymorphic* invoke) override {
Orion Hodsonac141392017-01-13 11:53:47 +0000528 VisitInvoke(invoke);
529 StartAttributeStream("invoke_type") << "InvokePolymorphic";
530 }
531
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100532 void VisitInstanceFieldGet(HInstanceFieldGet* iget) override {
David Sehr709b0702016-10-13 09:12:37 -0700533 StartAttributeStream("field_name") <<
534 iget->GetFieldInfo().GetDexFile().PrettyField(iget->GetFieldInfo().GetFieldIndex(),
David Brazdil11edec72016-03-24 12:40:52 +0000535 /* with type */ false);
536 StartAttributeStream("field_type") << iget->GetFieldType();
537 }
538
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100539 void VisitInstanceFieldSet(HInstanceFieldSet* iset) override {
David Sehr709b0702016-10-13 09:12:37 -0700540 StartAttributeStream("field_name") <<
541 iset->GetFieldInfo().GetDexFile().PrettyField(iset->GetFieldInfo().GetFieldIndex(),
David Brazdil11edec72016-03-24 12:40:52 +0000542 /* with type */ false);
543 StartAttributeStream("field_type") << iset->GetFieldType();
544 }
545
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100546 void VisitStaticFieldGet(HStaticFieldGet* sget) override {
Vladimir Markobf3243b2017-08-30 14:06:54 +0100547 StartAttributeStream("field_name") <<
548 sget->GetFieldInfo().GetDexFile().PrettyField(sget->GetFieldInfo().GetFieldIndex(),
549 /* with type */ false);
550 StartAttributeStream("field_type") << sget->GetFieldType();
551 }
552
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100553 void VisitStaticFieldSet(HStaticFieldSet* sset) override {
Vladimir Markobf3243b2017-08-30 14:06:54 +0100554 StartAttributeStream("field_name") <<
555 sset->GetFieldInfo().GetDexFile().PrettyField(sset->GetFieldInfo().GetFieldIndex(),
556 /* with type */ false);
557 StartAttributeStream("field_type") << sset->GetFieldType();
558 }
559
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100560 void VisitUnresolvedInstanceFieldGet(HUnresolvedInstanceFieldGet* field_access) override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100561 StartAttributeStream("field_type") << field_access->GetFieldType();
562 }
563
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100564 void VisitUnresolvedInstanceFieldSet(HUnresolvedInstanceFieldSet* field_access) override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100565 StartAttributeStream("field_type") << field_access->GetFieldType();
566 }
567
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100568 void VisitUnresolvedStaticFieldGet(HUnresolvedStaticFieldGet* field_access) override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100569 StartAttributeStream("field_type") << field_access->GetFieldType();
570 }
571
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100572 void VisitUnresolvedStaticFieldSet(HUnresolvedStaticFieldSet* field_access) override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100573 StartAttributeStream("field_type") << field_access->GetFieldType();
574 }
575
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100576 void VisitTryBoundary(HTryBoundary* try_boundary) override {
David Brazdil56e1acc2015-06-30 15:41:36 +0100577 StartAttributeStream("kind") << (try_boundary->IsEntry() ? "entry" : "exit");
David Brazdilfc6a86a2015-06-26 10:33:45 +0000578 }
579
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100580 void VisitDeoptimize(HDeoptimize* deoptimize) override {
Nicolas Geoffray6f8e2c92017-03-23 14:37:26 +0000581 StartAttributeStream("kind") << deoptimize->GetKind();
582 }
583
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100584 void VisitVecOperation(HVecOperation* vec_operation) override {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100585 StartAttributeStream("packed_type") << vec_operation->GetPackedType();
586 }
587
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100588 void VisitVecMemoryOperation(HVecMemoryOperation* vec_mem_operation) override {
Aart Bik38a3f212017-10-20 17:02:21 -0700589 StartAttributeStream("alignment") << vec_mem_operation->GetAlignment().ToString();
590 }
591
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100592 void VisitVecHalvingAdd(HVecHalvingAdd* hadd) override {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100593 VisitVecBinaryOperation(hadd);
Aart Bikf3e61ee2017-04-12 17:09:20 -0700594 StartAttributeStream("rounded") << std::boolalpha << hadd->IsRounded() << std::noboolalpha;
595 }
596
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100597 void VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) override {
Vladimir Markod5d2f2c2017-09-26 12:37:26 +0100598 VisitVecOperation(instruction);
Artem Serovf34dd202017-04-10 17:41:46 +0100599 StartAttributeStream("kind") << instruction->GetOpKind();
600 }
601
Artem Serovaaac0e32018-08-07 00:52:22 +0100602 void VisitVecDotProd(HVecDotProd* instruction) override {
603 VisitVecOperation(instruction);
604 DataType::Type arg_type = instruction->InputAt(1)->AsVecOperation()->GetPackedType();
605 StartAttributeStream("type") << (instruction->IsZeroExtending() ?
606 DataType::ToUnsigned(arg_type) :
607 DataType::ToSigned(arg_type));
608 }
609
Artem Udovichenko4a0dad62016-01-26 12:28:31 +0300610#if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64)
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100611 void VisitMultiplyAccumulate(HMultiplyAccumulate* instruction) override {
Artem Udovichenko4a0dad62016-01-26 12:28:31 +0300612 StartAttributeStream("kind") << instruction->GetOpKind();
613 }
Artem Serov7fc63502016-02-09 17:15:29 +0000614
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100615 void VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) override {
Artem Serov7fc63502016-02-09 17:15:29 +0000616 StartAttributeStream("kind") << instruction->GetOpKind();
617 }
Artem Udovichenko4a0dad62016-01-26 12:28:31 +0300618
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100619 void VisitDataProcWithShifterOp(HDataProcWithShifterOp* instruction) override {
Alexandre Rames8626b742015-11-25 16:28:08 +0000620 StartAttributeStream("kind") << instruction->GetInstrKind() << "+" << instruction->GetOpKind();
Anton Kirilov74234da2017-01-13 14:42:47 +0000621 if (HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000622 StartAttributeStream("shift") << instruction->GetShiftAmount();
623 }
624 }
Alexandre Rames418318f2015-11-20 15:55:47 +0000625#endif
626
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800627 bool IsPass(const char* name) {
628 return strcmp(pass_name_, name) == 0;
629 }
630
Alex Lightdc281e72021-01-06 12:35:31 -0800631 bool IsDebugDump() {
632 return IsPass(kDebugDumpGraphName) || IsPass(kDebugDumpName);
633 }
634
David Brazdilb7e4a062014-12-29 15:35:02 +0000635 void PrintInstruction(HInstruction* instruction) {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100636 output_ << instruction->DebugName();
Vladimir Markoe9004912016-06-16 16:50:52 +0100637 HConstInputsRef inputs = instruction->GetInputs();
Vladimir Marko372f10e2016-05-17 16:30:10 +0100638 if (!inputs.empty()) {
639 StringList input_list;
640 for (const HInstruction* input : inputs) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100641 input_list.NewEntryStream() << DataType::TypeId(input->GetType()) << input->GetId();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100642 }
Vladimir Marko372f10e2016-05-17 16:30:10 +0100643 StartAttributeStream() << input_list;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100644 }
Vladimir Markofe948752018-03-23 18:11:43 +0000645 if (instruction->GetDexPc() != kNoDexPc) {
646 StartAttributeStream("dex_pc") << instruction->GetDexPc();
647 } else {
648 StartAttributeStream("dex_pc") << "n/a";
649 }
Alex Lightdc281e72021-01-06 12:35:31 -0800650 if (IsPass(kDebugDumpName)) {
651 // Include block name for logcat use.
652 StartAttributeStream("block") << namer_.GetName(instruction->GetBlock());
653 }
David Brazdilc74652862015-05-13 17:50:09 +0100654 instruction->Accept(this);
Zheng Xubb7a28a2015-01-09 14:40:47 +0800655 if (instruction->HasEnvironment()) {
David Brazdilc74652862015-05-13 17:50:09 +0100656 StringList envs;
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100657 for (HEnvironment* environment = instruction->GetEnvironment();
658 environment != nullptr;
659 environment = environment->GetParent()) {
David Brazdilc74652862015-05-13 17:50:09 +0100660 StringList vregs;
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100661 for (size_t i = 0, e = environment->Size(); i < e; ++i) {
662 HInstruction* insn = environment->GetInstructionAt(i);
663 if (insn != nullptr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100664 vregs.NewEntryStream() << DataType::TypeId(insn->GetType()) << insn->GetId();
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100665 } else {
David Brazdilc74652862015-05-13 17:50:09 +0100666 vregs.NewEntryStream() << "_";
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100667 }
Zheng Xubb7a28a2015-01-09 14:40:47 +0800668 }
David Brazdilc74652862015-05-13 17:50:09 +0100669 envs.NewEntryStream() << vregs;
Zheng Xubb7a28a2015-01-09 14:40:47 +0800670 }
David Brazdilc74652862015-05-13 17:50:09 +0100671 StartAttributeStream("env") << envs;
Zheng Xubb7a28a2015-01-09 14:40:47 +0800672 }
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800673 if (IsPass(SsaLivenessAnalysis::kLivenessPassName)
David Brazdil5e8b1372015-01-23 14:39:08 +0000674 && is_after_pass_
675 && instruction->GetLifetimePosition() != kNoLifetime) {
David Brazdilc74652862015-05-13 17:50:09 +0100676 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100677 if (instruction->HasLiveInterval()) {
David Brazdilc74652862015-05-13 17:50:09 +0100678 LiveInterval* interval = instruction->GetLiveInterval();
David Brazdilc7a24852015-05-15 16:44:05 +0100679 StartAttributeStream("ranges")
680 << StringList(interval->GetFirstRange(), StringList::kSetBrackets);
Vladimir Marko82b07402017-03-01 19:02:04 +0000681 StartAttributeStream("uses") << StringList(interval->GetUses());
682 StartAttributeStream("env_uses") << StringList(interval->GetEnvironmentUses());
David Brazdilc74652862015-05-13 17:50:09 +0100683 StartAttributeStream("is_fixed") << interval->IsFixed();
684 StartAttributeStream("is_split") << interval->IsSplit();
685 StartAttributeStream("is_low") << interval->IsLowInterval();
686 StartAttributeStream("is_high") << interval->IsHighInterval();
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100687 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000688 }
689
690 if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) {
David Brazdilc74652862015-05-13 17:50:09 +0100691 StartAttributeStream("liveness") << instruction->GetLifetimePosition();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100692 LocationSummary* locations = instruction->GetLocations();
693 if (locations != nullptr) {
Vladimir Marko372f10e2016-05-17 16:30:10 +0100694 StringList input_list;
695 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
696 DumpLocation(input_list.NewEntryStream(), locations->InAt(i));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100697 }
David Brazdilc74652862015-05-13 17:50:09 +0100698 std::ostream& attr = StartAttributeStream("locations");
Vladimir Marko372f10e2016-05-17 16:30:10 +0100699 attr << input_list << "->";
David Brazdilc74652862015-05-13 17:50:09 +0100700 DumpLocation(attr, locations->Out());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100701 }
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000702 }
703
Nicolas Geoffrayd7c2fdc2016-05-10 14:35:34 +0100704 HLoopInformation* loop_info = instruction->GetBlock()->GetLoopInformation();
705 if (loop_info == nullptr) {
706 StartAttributeStream("loop") << "none";
707 } else {
Alex Lightdc281e72021-01-06 12:35:31 -0800708 StartAttributeStream("loop") << namer_.GetName(loop_info->GetHeader());
Nicolas Geoffrayd7c2fdc2016-05-10 14:35:34 +0100709 HLoopInformation* outer = loop_info->GetPreHeader()->GetLoopInformation();
710 if (outer != nullptr) {
Alex Lightdc281e72021-01-06 12:35:31 -0800711 StartAttributeStream("outer_loop") << namer_.GetName(outer->GetHeader());
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000712 } else {
Nicolas Geoffrayd7c2fdc2016-05-10 14:35:34 +0100713 StartAttributeStream("outer_loop") << "none";
Nicolas Geoffray82091da2015-01-26 10:02:45 +0000714 }
Nicolas Geoffrayd7c2fdc2016-05-10 14:35:34 +0100715 StartAttributeStream("irreducible")
716 << std::boolalpha << loop_info->IsIrreducible() << std::noboolalpha;
Nicolas Geoffray15bd2282016-01-05 15:55:41 +0000717 }
718
Vladimir Marko175e7862018-03-27 09:03:13 +0000719 // For the builder and the inliner, we want to add extra information on HInstructions
720 // that have reference types, and also HInstanceOf/HCheckcast.
David Brazdilbadd8262016-02-02 16:28:56 +0000721 if ((IsPass(HGraphBuilder::kBuilderPassName)
Alex Lightdc281e72021-01-06 12:35:31 -0800722 || IsPass(HInliner::kInlinerPassName)
723 || IsDebugDump())
Vladimir Marko175e7862018-03-27 09:03:13 +0000724 && (instruction->GetType() == DataType::Type::kReference ||
725 instruction->IsInstanceOf() ||
726 instruction->IsCheckCast())) {
727 ReferenceTypeInfo info = (instruction->GetType() == DataType::Type::kReference)
728 ? instruction->IsLoadClass()
729 ? instruction->AsLoadClass()->GetLoadedClassRTI()
730 : instruction->GetReferenceTypeInfo()
731 : instruction->IsInstanceOf()
732 ? instruction->AsInstanceOf()->GetTargetClassRTI()
733 : instruction->AsCheckCast()->GetTargetClassRTI();
Calin Juravle2e768302015-07-28 14:41:11 +0000734 ScopedObjectAccess soa(Thread::Current());
735 if (info.IsValid()) {
David Sehr709b0702016-10-13 09:12:37 -0700736 StartAttributeStream("klass")
737 << mirror::Class::PrettyDescriptor(info.GetTypeHandle().Get());
Vladimir Marko175e7862018-03-27 09:03:13 +0000738 if (instruction->GetType() == DataType::Type::kReference) {
739 StartAttributeStream("can_be_null")
740 << std::boolalpha << instruction->CanBeNull() << std::noboolalpha;
741 }
Calin Juravle2e768302015-07-28 14:41:11 +0000742 StartAttributeStream("exact") << std::boolalpha << info.IsExact() << std::noboolalpha;
Vladimir Marko175e7862018-03-27 09:03:13 +0000743 } else if (instruction->IsLoadClass() ||
744 instruction->IsInstanceOf() ||
745 instruction->IsCheckCast()) {
Calin Juravle98893e12015-10-02 21:05:03 +0100746 StartAttributeStream("klass") << "unresolved";
David Brazdil4833f5a2015-12-16 10:37:39 +0000747 } else {
Mark Mendellb2d38fd2015-11-16 12:21:53 -0500748 // The NullConstant may be added to the graph during other passes that happen between
749 // ReferenceTypePropagation and Inliner (e.g. InstructionSimplifier). If the inliner
750 // doesn't run or doesn't inline anything, the NullConstant remains untyped.
751 // So we should check NullConstants for validity only after reference type propagation.
David Brazdil4833f5a2015-12-16 10:37:39 +0000752 DCHECK(graph_in_bad_state_ ||
Alex Lightdc281e72021-01-06 12:35:31 -0800753 IsDebugDump() ||
David Brazdilbadd8262016-02-02 16:28:56 +0000754 (!is_after_pass_ && IsPass(HGraphBuilder::kBuilderPassName)))
David Brazdil4833f5a2015-12-16 10:37:39 +0000755 << instruction->DebugName() << instruction->GetId() << " has invalid rti "
756 << (is_after_pass_ ? "after" : "before") << " pass " << pass_name_;
Nicolas Geoffray7cb499b2015-06-17 11:35:11 +0100757 }
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100758 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100759 if (disasm_info_ != nullptr) {
760 DCHECK(disassembler_ != nullptr);
761 // If the information is available, disassemble the code generated for
762 // this instruction.
763 auto it = disasm_info_->GetInstructionIntervals().find(instruction);
764 if (it != disasm_info_->GetInstructionIntervals().end()
765 && it->second.start != it->second.end) {
David Brazdilfa02c9d2016-03-30 09:41:02 +0100766 output_ << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100767 disassembler_->Disassemble(output_, it->second.start, it->second.end);
768 }
769 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100770 }
771
772 void PrintInstructions(const HInstructionList& list) {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100773 for (HInstructionIterator it(list); !it.Done(); it.Advance()) {
774 HInstruction* instruction = it.Current();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100775 int bci = 0;
Vladimir Marko46817b82016-03-29 12:21:58 +0100776 size_t num_uses = instruction->GetUses().SizeSlow();
David Brazdilea55b932015-01-27 17:12:29 +0000777 AddIndent();
778 output_ << bci << " " << num_uses << " "
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100779 << DataType::TypeId(instruction->GetType()) << instruction->GetId() << " ";
David Brazdilb7e4a062014-12-29 15:35:02 +0000780 PrintInstruction(instruction);
David Brazdilfa02c9d2016-03-30 09:41:02 +0100781 output_ << " " << kEndInstructionMarker << "\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100782 }
783 }
784
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100785 void DumpStartOfDisassemblyBlock(const char* block_name,
786 int predecessor_index,
787 int successor_index) {
788 StartTag("block");
789 PrintProperty("name", block_name);
790 PrintInt("from_bci", -1);
791 PrintInt("to_bci", -1);
792 if (predecessor_index != -1) {
793 PrintProperty("predecessors", "B", predecessor_index);
794 } else {
795 PrintEmptyProperty("predecessors");
796 }
797 if (successor_index != -1) {
798 PrintProperty("successors", "B", successor_index);
799 } else {
800 PrintEmptyProperty("successors");
801 }
802 PrintEmptyProperty("xhandlers");
803 PrintEmptyProperty("flags");
804 StartTag("states");
805 StartTag("locals");
806 PrintInt("size", 0);
807 PrintProperty("method", "None");
808 EndTag("locals");
809 EndTag("states");
810 StartTag("HIR");
811 }
812
813 void DumpEndOfDisassemblyBlock() {
814 EndTag("HIR");
815 EndTag("block");
816 }
817
818 void DumpDisassemblyBlockForFrameEntry() {
819 DumpStartOfDisassemblyBlock(kDisassemblyBlockFrameEntry,
820 -1,
821 GetGraph()->GetEntryBlock()->GetBlockId());
822 output_ << " 0 0 disasm " << kDisassemblyBlockFrameEntry << " ";
823 GeneratedCodeInterval frame_entry = disasm_info_->GetFrameEntryInterval();
824 if (frame_entry.start != frame_entry.end) {
David Brazdilfa02c9d2016-03-30 09:41:02 +0100825 output_ << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100826 disassembler_->Disassemble(output_, frame_entry.start, frame_entry.end);
827 }
David Brazdilfa02c9d2016-03-30 09:41:02 +0100828 output_ << kEndInstructionMarker << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100829 DumpEndOfDisassemblyBlock();
830 }
831
832 void DumpDisassemblyBlockForSlowPaths() {
833 if (disasm_info_->GetSlowPathIntervals().empty()) {
834 return;
835 }
836 // If the graph has an exit block we attach the block for the slow paths
837 // after it. Else we just add the block to the graph without linking it to
838 // any other.
839 DumpStartOfDisassemblyBlock(
840 kDisassemblyBlockSlowPaths,
841 GetGraph()->HasExitBlock() ? GetGraph()->GetExitBlock()->GetBlockId() : -1,
842 -1);
843 for (SlowPathCodeInfo info : disasm_info_->GetSlowPathIntervals()) {
David Brazdilfa02c9d2016-03-30 09:41:02 +0100844 output_ << " 0 0 disasm " << info.slow_path->GetDescription() << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100845 disassembler_->Disassemble(output_, info.code_interval.start, info.code_interval.end);
David Brazdilfa02c9d2016-03-30 09:41:02 +0100846 output_ << kEndInstructionMarker << "\n";
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100847 }
848 DumpEndOfDisassemblyBlock();
849 }
850
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100851 void Run() {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100852 StartTag("cfg");
Alex Lightdc281e72021-01-06 12:35:31 -0800853 std::ostringstream oss;
854 oss << pass_name_;
855 if (!IsDebugDump()) {
856 oss << " (" << (is_after_pass_ ? "after" : "before")
857 << (graph_in_bad_state_ ? ", bad_state" : "") << ")";
858 }
859 PrintProperty("name", oss.str().c_str());
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100860 if (disasm_info_ != nullptr) {
861 DumpDisassemblyBlockForFrameEntry();
862 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100863 VisitInsertionOrder();
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100864 if (disasm_info_ != nullptr) {
865 DumpDisassemblyBlockForSlowPaths();
866 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100867 EndTag("cfg");
David Brazdilfa02c9d2016-03-30 09:41:02 +0100868 Flush();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100869 }
870
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000871 void Run(HInstruction* instruction) {
872 output_ << DataType::TypeId(instruction->GetType()) << instruction->GetId() << " ";
873 PrintInstruction(instruction);
874 Flush();
875 }
876
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100877 void VisitBasicBlock(HBasicBlock* block) override {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100878 StartTag("block");
Alex Lightdc281e72021-01-06 12:35:31 -0800879 PrintProperty("name", block);
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100880 if (block->GetLifetimeStart() != kNoLifetime) {
881 // Piggy back on these fields to show the lifetime of the block.
882 PrintInt("from_bci", block->GetLifetimeStart());
883 PrintInt("to_bci", block->GetLifetimeEnd());
Alex Lightdc281e72021-01-06 12:35:31 -0800884 } else if (!IsDebugDump()) {
885 // Don't print useless information to logcat.
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100886 PrintInt("from_bci", -1);
887 PrintInt("to_bci", -1);
888 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100889 PrintPredecessors(block);
890 PrintSuccessors(block);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000891 PrintExceptionHandlers(block);
892
893 if (block->IsCatchBlock()) {
894 PrintProperty("flags", "catch_block");
Alex Lightdc281e72021-01-06 12:35:31 -0800895 } else if (!IsDebugDump()) {
896 // Don't print useless information to logcat
David Brazdilfc6a86a2015-06-26 10:33:45 +0000897 PrintEmptyProperty("flags");
898 }
899
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100900 if (block->GetDominator() != nullptr) {
Alex Lightdc281e72021-01-06 12:35:31 -0800901 PrintProperty("dominator", block->GetDominator());
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100902 }
903
Alex Lightdc281e72021-01-06 12:35:31 -0800904 if (!IsDebugDump() || !block->GetPhis().IsEmpty()) {
905 StartTag("states");
906 StartTag("locals");
907 PrintInt("size", 0);
908 PrintProperty("method", "None");
909 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
910 AddIndent();
911 HInstruction* instruction = it.Current();
912 output_ << instruction->GetId() << " " << DataType::TypeId(instruction->GetType())
913 << instruction->GetId() << "[ ";
914 for (const HInstruction* input : instruction->GetInputs()) {
915 output_ << input->GetId() << " ";
916 }
917 output_ << "]\n";
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100918 }
Alex Lightdc281e72021-01-06 12:35:31 -0800919 EndTag("locals");
920 EndTag("states");
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100921 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100922
923 StartTag("HIR");
924 PrintInstructions(block->GetPhis());
925 PrintInstructions(block->GetInstructions());
926 EndTag("HIR");
927 EndTag("block");
928 }
929
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100930 static constexpr const char* const kEndInstructionMarker = "<|@";
931 static constexpr const char* const kDisassemblyBlockFrameEntry = "FrameEntry";
932 static constexpr const char* const kDisassemblyBlockSlowPaths = "SlowPaths";
933
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100934 private:
935 std::ostream& output_;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100936 const char* pass_name_;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000937 const bool is_after_pass_;
David Brazdilffee3d32015-07-06 11:48:53 +0100938 const bool graph_in_bad_state_;
Vladimir Markoc9fcfd02021-01-05 16:57:30 +0000939 const CodeGenerator* codegen_;
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100940 const DisassemblyInformation* disasm_info_;
Alex Lightdc281e72021-01-06 12:35:31 -0800941 const BlockNamer& namer_;
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100942 std::unique_ptr<HGraphVisualizerDisassembler> disassembler_;
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100943 size_t indent_;
944
945 DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter);
946};
947
Alex Lightdc281e72021-01-06 12:35:31 -0800948std::ostream& HGraphVisualizer::OptionalDefaultNamer::PrintName(std::ostream& os,
949 HBasicBlock* blk) const {
950 if (namer_) {
951 return namer_->get().PrintName(os, blk);
952 } else {
953 return BlockNamer::PrintName(os, blk);
954 }
955}
956
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100957HGraphVisualizer::HGraphVisualizer(std::ostream* output,
958 HGraph* graph,
Alex Lightdc281e72021-01-06 12:35:31 -0800959 const CodeGenerator* codegen,
960 std::optional<std::reference_wrapper<const BlockNamer>> namer)
961 : output_(output), graph_(graph), codegen_(codegen), namer_(namer) {}
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100962
David Brazdil62e074f2015-04-07 18:09:37 +0100963void HGraphVisualizer::PrintHeader(const char* method_name) const {
964 DCHECK(output_ != nullptr);
Alex Lightdc281e72021-01-06 12:35:31 -0800965 HGraphVisualizerPrinter printer(graph_, *output_, "", true, false, codegen_, namer_);
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100966 printer.StartTag("compilation");
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000967 printer.PrintProperty("name", method_name);
968 printer.PrintProperty("method", method_name);
Nicolas Geoffray0d3f5782014-05-14 09:43:38 +0100969 printer.PrintTime("date");
970 printer.EndTag("compilation");
David Brazdilfa02c9d2016-03-30 09:41:02 +0100971 printer.Flush();
Nicolas Geoffray0d3f5782014-05-14 09:43:38 +0100972}
973
Fabio Rinaldi52d53542020-02-10 17:28:06 +0000974std::string HGraphVisualizer::InsertMetaDataAsCompilationBlock(const std::string& meta_data) {
975 std::string time_str = std::to_string(time(nullptr));
976 std::string quoted_meta_data = "\"" + meta_data + "\"";
977 return StringPrintf("begin_compilation\n"
978 " name %s\n"
979 " method %s\n"
980 " date %s\n"
981 "end_compilation\n",
982 quoted_meta_data.c_str(),
983 quoted_meta_data.c_str(),
984 time_str.c_str());
985}
986
Alex Lightdc281e72021-01-06 12:35:31 -0800987void HGraphVisualizer::DumpGraphDebug() const {
988 DumpGraph(/* pass_name= */ kDebugDumpGraphName,
989 /* is_after_pass= */ false,
990 /* graph_in_bad_state= */ true);
991}
992
David Brazdilffee3d32015-07-06 11:48:53 +0100993void HGraphVisualizer::DumpGraph(const char* pass_name,
994 bool is_after_pass,
995 bool graph_in_bad_state) const {
David Brazdil5e8b1372015-01-23 14:39:08 +0000996 DCHECK(output_ != nullptr);
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100997 if (!graph_->GetBlocks().empty()) {
David Brazdilffee3d32015-07-06 11:48:53 +0100998 HGraphVisualizerPrinter printer(graph_,
999 *output_,
1000 pass_name,
1001 is_after_pass,
1002 graph_in_bad_state,
Alex Lightdc281e72021-01-06 12:35:31 -08001003 codegen_,
1004 namer_);
David Brazdilee690a32014-12-01 17:04:16 +00001005 printer.Run();
Nicolas Geoffrayf635e632014-05-14 09:43:38 +01001006 }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +01001007}
1008
Alexandre Rameseb7b7392015-06-19 14:47:01 +01001009void HGraphVisualizer::DumpGraphWithDisassembly() const {
1010 DCHECK(output_ != nullptr);
Vladimir Markofa6b93c2015-09-15 10:15:55 +01001011 if (!graph_->GetBlocks().empty()) {
David Brazdilffee3d32015-07-06 11:48:53 +01001012 HGraphVisualizerPrinter printer(graph_,
1013 *output_,
1014 "disassembly",
Andreas Gampe3db70682018-12-26 15:12:03 -08001015 /* is_after_pass= */ true,
1016 /* graph_in_bad_state= */ false,
David Brazdilffee3d32015-07-06 11:48:53 +01001017 codegen_,
Alex Lightdc281e72021-01-06 12:35:31 -08001018 namer_,
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001019 codegen_->GetDisassemblyInformation());
Alexandre Rameseb7b7392015-06-19 14:47:01 +01001020 printer.Run();
1021 }
1022}
1023
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001024void HGraphVisualizer::DumpInstruction(std::ostream* output,
1025 HGraph* graph,
1026 HInstruction* instruction) {
Alex Lightdc281e72021-01-06 12:35:31 -08001027 BlockNamer namer;
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001028 HGraphVisualizerPrinter printer(graph,
1029 *output,
Alex Lightdc281e72021-01-06 12:35:31 -08001030 /* pass_name= */ kDebugDumpName,
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001031 /* is_after_pass= */ false,
1032 /* graph_in_bad_state= */ false,
Alex Lightdc281e72021-01-06 12:35:31 -08001033 /* codegen= */ nullptr,
1034 /* namer= */ namer);
Vladimir Markoc9fcfd02021-01-05 16:57:30 +00001035 printer.Run(instruction);
1036}
1037
Nicolas Geoffrayf635e632014-05-14 09:43:38 +01001038} // namespace art