| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "graph_visualizer.h" |
| 18 | |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 19 | #include <dlfcn.h> |
| 20 | |
| 21 | #include <cctype> |
| 22 | #include <sstream> |
| 23 | |
| Fabio Rinaldi | 52d5354 | 2020-02-10 17:28:06 +0000 | [diff] [blame] | 24 | #include "android-base/stringprintf.h" |
| Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 25 | #include "art_method.h" |
| Vladimir Marko | 3fae129 | 2019-06-07 11:26:25 +0100 | [diff] [blame] | 26 | #include "base/intrusive_forward_list.h" |
| Aart Bik | 09e8d5f | 2016-01-22 16:49:55 -0800 | [diff] [blame] | 27 | #include "bounds_check_elimination.h" |
| David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 28 | #include "builder.h" |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 29 | #include "code_generator.h" |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 30 | #include "data_type-inl.h" |
| David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 31 | #include "dead_code_elimination.h" |
| David Sehr | b2ec9f5 | 2018-02-21 13:20:31 -0800 | [diff] [blame] | 32 | #include "dex/descriptors_names.h" |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 33 | #include "disassembler.h" |
| Calin Juravle | cdfed3d | 2015-10-26 14:05:01 +0000 | [diff] [blame] | 34 | #include "inliner.h" |
| Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 35 | #include "licm.h" |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 36 | #include "nodes.h" |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 37 | #include "optimization.h" |
| Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 38 | #include "reference_type_propagation.h" |
| Matthew Gharrity | e928885 | 2016-07-14 14:08:16 -0700 | [diff] [blame] | 39 | #include "register_allocator_linear_scan.h" |
| Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 40 | #include "scoped_thread_state_change-inl.h" |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 41 | #include "ssa_liveness_analysis.h" |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 42 | #include "utils/assembler.h" |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 43 | |
| Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 44 | namespace art { |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 45 | |
| Fabio Rinaldi | 52d5354 | 2020-02-10 17:28:06 +0000 | [diff] [blame] | 46 | using android::base::StringPrintf; |
| 47 | |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 48 | static bool HasWhitespace(const char* str) { |
| 49 | DCHECK(str != nullptr); |
| 50 | while (str[0] != 0) { |
| 51 | if (isspace(str[0])) { |
| 52 | return true; |
| 53 | } |
| 54 | str++; |
| 55 | } |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | class StringList { |
| 60 | public: |
| David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 61 | enum Format { |
| 62 | kArrayBrackets, |
| 63 | kSetBrackets, |
| 64 | }; |
| 65 | |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 66 | // Create an empty list |
| David Brazdil | f1a9ff7 | 2015-05-18 16:04:53 +0100 | [diff] [blame] | 67 | explicit StringList(Format format = kArrayBrackets) : format_(format), is_empty_(true) {} |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 68 | |
| 69 | // Construct StringList from a linked list. List element class T |
| 70 | // must provide methods `GetNext` and `Dump`. |
| 71 | template<class T> |
| David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 72 | explicit StringList(T* first_entry, Format format = kArrayBrackets) : StringList(format) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 73 | for (T* current = first_entry; current != nullptr; current = current->GetNext()) { |
| 74 | current->Dump(NewEntryStream()); |
| 75 | } |
| 76 | } |
| Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 77 | // Construct StringList from a list of elements. The value type must provide method `Dump`. |
| 78 | template <typename Container> |
| 79 | explicit StringList(const Container& list, Format format = kArrayBrackets) : StringList(format) { |
| 80 | for (const typename Container::value_type& current : list) { |
| 81 | current.Dump(NewEntryStream()); |
| 82 | } |
| 83 | } |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 84 | |
| 85 | std::ostream& NewEntryStream() { |
| 86 | if (is_empty_) { |
| 87 | is_empty_ = false; |
| 88 | } else { |
| David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame] | 89 | sstream_ << ","; |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 90 | } |
| 91 | return sstream_; |
| 92 | } |
| 93 | |
| 94 | private: |
| David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 95 | Format format_; |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 96 | bool is_empty_; |
| 97 | std::ostringstream sstream_; |
| 98 | |
| 99 | friend std::ostream& operator<<(std::ostream& os, const StringList& list); |
| 100 | }; |
| 101 | |
| 102 | std::ostream& operator<<(std::ostream& os, const StringList& list) { |
| David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 103 | switch (list.format_) { |
| 104 | case StringList::kArrayBrackets: return os << "[" << list.sstream_.str() << "]"; |
| 105 | case StringList::kSetBrackets: return os << "{" << list.sstream_.str() << "}"; |
| 106 | default: |
| 107 | LOG(FATAL) << "Invalid StringList format"; |
| 108 | UNREACHABLE(); |
| 109 | } |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 112 | using create_disasm_prototype = Disassembler*(InstructionSet, DisassemblerOptions*); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 113 | class HGraphVisualizerDisassembler { |
| 114 | public: |
| Aart Bik | d3059e7 | 2016-05-11 10:30:47 -0700 | [diff] [blame] | 115 | HGraphVisualizerDisassembler(InstructionSet instruction_set, |
| 116 | const uint8_t* base_address, |
| 117 | const uint8_t* end_address) |
| David Brazdil | 3a690be | 2015-06-23 10:22:38 +0100 | [diff] [blame] | 118 | : instruction_set_(instruction_set), disassembler_(nullptr) { |
| Roland Levillain | 5b76889 | 2020-02-19 15:49:02 +0000 | [diff] [blame] | 119 | constexpr const char* libart_disassembler_so_name = |
| 120 | kIsDebugBuild ? "libartd-disassembler.so" : "libart-disassembler.so"; |
| 121 | libart_disassembler_handle_ = dlopen(libart_disassembler_so_name, RTLD_NOW); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 122 | if (libart_disassembler_handle_ == nullptr) { |
| Roland Levillain | 5b76889 | 2020-02-19 15:49:02 +0000 | [diff] [blame] | 123 | LOG(ERROR) << "Failed to dlopen " << libart_disassembler_so_name << ": " << dlerror(); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 124 | return; |
| 125 | } |
| Roland Levillain | 5b76889 | 2020-02-19 15:49:02 +0000 | [diff] [blame] | 126 | constexpr const char* create_disassembler_symbol = "create_disassembler"; |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 127 | create_disasm_prototype* create_disassembler = reinterpret_cast<create_disasm_prototype*>( |
| Roland Levillain | 5b76889 | 2020-02-19 15:49:02 +0000 | [diff] [blame] | 128 | dlsym(libart_disassembler_handle_, create_disassembler_symbol)); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 129 | if (create_disassembler == nullptr) { |
| Roland Levillain | 5b76889 | 2020-02-19 15:49:02 +0000 | [diff] [blame] | 130 | LOG(ERROR) << "Could not find " << create_disassembler_symbol << " entry in " |
| 131 | << libart_disassembler_so_name << ": " << dlerror(); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 132 | return; |
| 133 | } |
| 134 | // Reading the disassembly from 0x0 is easier, so we print relative |
| 135 | // addresses. We will only disassemble the code once everything has |
| 136 | // been generated, so we can read data in literal pools. |
| 137 | disassembler_ = std::unique_ptr<Disassembler>((*create_disassembler)( |
| 138 | instruction_set, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 139 | new DisassemblerOptions(/* absolute_addresses= */ false, |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 140 | base_address, |
| Aart Bik | d3059e7 | 2016-05-11 10:30:47 -0700 | [diff] [blame] | 141 | end_address, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 142 | /* can_read_literals= */ true, |
| Andreas Gampe | 372f3a3 | 2016-08-19 10:49:06 -0700 | [diff] [blame] | 143 | Is64BitInstructionSet(instruction_set) |
| 144 | ? &Thread::DumpThreadOffset<PointerSize::k64> |
| 145 | : &Thread::DumpThreadOffset<PointerSize::k32>))); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | ~HGraphVisualizerDisassembler() { |
| 149 | // We need to call ~Disassembler() before we close the library. |
| 150 | disassembler_.reset(); |
| 151 | if (libart_disassembler_handle_ != nullptr) { |
| 152 | dlclose(libart_disassembler_handle_); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | void Disassemble(std::ostream& output, size_t start, size_t end) const { |
| David Brazdil | 3a690be | 2015-06-23 10:22:38 +0100 | [diff] [blame] | 157 | if (disassembler_ == nullptr) { |
| 158 | return; |
| 159 | } |
| 160 | |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 161 | const uint8_t* base = disassembler_->GetDisassemblerOptions()->base_address_; |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 162 | if (instruction_set_ == InstructionSet::kThumb2) { |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 163 | // ARM and Thumb-2 use the same disassembler. The bottom bit of the |
| 164 | // address is used to distinguish between the two. |
| 165 | base += 1; |
| 166 | } |
| 167 | disassembler_->Dump(output, base + start, base + end); |
| 168 | } |
| 169 | |
| 170 | private: |
| 171 | InstructionSet instruction_set_; |
| 172 | std::unique_ptr<Disassembler> disassembler_; |
| 173 | |
| 174 | void* libart_disassembler_handle_; |
| 175 | }; |
| 176 | |
| 177 | |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 178 | /** |
| 179 | * HGraph visitor to generate a file suitable for the c1visualizer tool and IRHydra. |
| 180 | */ |
| Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 181 | class HGraphVisualizerPrinter : public HGraphDelegateVisitor { |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 182 | public: |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 183 | HGraphVisualizerPrinter(HGraph* graph, |
| 184 | std::ostream& output, |
| 185 | const char* pass_name, |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 186 | bool is_after_pass, |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 187 | bool graph_in_bad_state, |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 188 | const CodeGenerator& codegen, |
| 189 | const DisassemblyInformation* disasm_info = nullptr) |
| Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 190 | : HGraphDelegateVisitor(graph), |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 191 | output_(output), |
| 192 | pass_name_(pass_name), |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 193 | is_after_pass_(is_after_pass), |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 194 | graph_in_bad_state_(graph_in_bad_state), |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 195 | codegen_(codegen), |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 196 | disasm_info_(disasm_info), |
| 197 | disassembler_(disasm_info_ != nullptr |
| 198 | ? new HGraphVisualizerDisassembler( |
| 199 | codegen_.GetInstructionSet(), |
| Aart Bik | d3059e7 | 2016-05-11 10:30:47 -0700 | [diff] [blame] | 200 | codegen_.GetAssembler().CodeBufferBaseAddress(), |
| 201 | codegen_.GetAssembler().CodeBufferBaseAddress() |
| 202 | + codegen_.GetAssembler().CodeSize()) |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 203 | : nullptr), |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 204 | indent_(0) {} |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 205 | |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 206 | void Flush() { |
| 207 | // We use "\n" instead of std::endl to avoid implicit flushing which |
| 208 | // generates too many syscalls during debug-GC tests (b/27826765). |
| 209 | output_ << std::flush; |
| 210 | } |
| 211 | |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 212 | void StartTag(const char* name) { |
| 213 | AddIndent(); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 214 | output_ << "begin_" << name << "\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 215 | indent_++; |
| 216 | } |
| 217 | |
| 218 | void EndTag(const char* name) { |
| 219 | indent_--; |
| 220 | AddIndent(); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 221 | output_ << "end_" << name << "\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void PrintProperty(const char* name, const char* property) { |
| 225 | AddIndent(); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 226 | output_ << name << " \"" << property << "\"\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void PrintProperty(const char* name, const char* property, int id) { |
| 230 | AddIndent(); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 231 | output_ << name << " \"" << property << id << "\"\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void PrintEmptyProperty(const char* name) { |
| 235 | AddIndent(); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 236 | output_ << name << "\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void PrintTime(const char* name) { |
| 240 | AddIndent(); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 241 | output_ << name << " " << time(nullptr) << "\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | void PrintInt(const char* name, int value) { |
| 245 | AddIndent(); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 246 | output_ << name << " " << value << "\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | void AddIndent() { |
| 250 | for (size_t i = 0; i < indent_; ++i) { |
| 251 | output_ << " "; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | void PrintPredecessors(HBasicBlock* block) { |
| 256 | AddIndent(); |
| 257 | output_ << "predecessors"; |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 258 | for (HBasicBlock* predecessor : block->GetPredecessors()) { |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 259 | output_ << " \"B" << predecessor->GetBlockId() << "\" "; |
| 260 | } |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 261 | if (block->IsEntryBlock() && (disasm_info_ != nullptr)) { |
| 262 | output_ << " \"" << kDisassemblyBlockFrameEntry << "\" "; |
| 263 | } |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 264 | output_<< "\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | void PrintSuccessors(HBasicBlock* block) { |
| 268 | AddIndent(); |
| 269 | output_ << "successors"; |
| David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 270 | for (HBasicBlock* successor : block->GetNormalSuccessors()) { |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 271 | output_ << " \"B" << successor->GetBlockId() << "\" "; |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 272 | } |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 273 | output_<< "\n"; |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | void PrintExceptionHandlers(HBasicBlock* block) { |
| 277 | AddIndent(); |
| 278 | output_ << "xhandlers"; |
| David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 279 | for (HBasicBlock* handler : block->GetExceptionalSuccessors()) { |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 280 | output_ << " \"B" << handler->GetBlockId() << "\" "; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 281 | } |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 282 | if (block->IsExitBlock() && |
| 283 | (disasm_info_ != nullptr) && |
| 284 | !disasm_info_->GetSlowPathIntervals().empty()) { |
| 285 | output_ << " \"" << kDisassemblyBlockSlowPaths << "\" "; |
| 286 | } |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 287 | output_<< "\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 288 | } |
| 289 | |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 290 | void DumpLocation(std::ostream& stream, const Location& location) { |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 291 | if (location.IsRegister()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 292 | codegen_.DumpCoreRegister(stream, location.reg()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 293 | } else if (location.IsFpuRegister()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 294 | codegen_.DumpFloatingPointRegister(stream, location.reg()); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 295 | } else if (location.IsConstant()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 296 | stream << "#"; |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 297 | HConstant* constant = location.GetConstant(); |
| 298 | if (constant->IsIntConstant()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 299 | stream << constant->AsIntConstant()->GetValue(); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 300 | } else if (constant->IsLongConstant()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 301 | stream << constant->AsLongConstant()->GetValue(); |
| Alexandre Rames | c2c52a1 | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 302 | } else if (constant->IsFloatConstant()) { |
| 303 | stream << constant->AsFloatConstant()->GetValue(); |
| 304 | } else if (constant->IsDoubleConstant()) { |
| 305 | stream << constant->AsDoubleConstant()->GetValue(); |
| 306 | } else if (constant->IsNullConstant()) { |
| 307 | stream << "null"; |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 308 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 309 | } else if (location.IsInvalid()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 310 | stream << "invalid"; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 311 | } else if (location.IsStackSlot()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 312 | stream << location.GetStackIndex() << "(sp)"; |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 313 | } else if (location.IsFpuRegisterPair()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 314 | codegen_.DumpFloatingPointRegister(stream, location.low()); |
| 315 | stream << "|"; |
| 316 | codegen_.DumpFloatingPointRegister(stream, location.high()); |
| Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 317 | } else if (location.IsRegisterPair()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 318 | codegen_.DumpCoreRegister(stream, location.low()); |
| 319 | stream << "|"; |
| 320 | codegen_.DumpCoreRegister(stream, location.high()); |
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 321 | } else if (location.IsUnallocated()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 322 | stream << "unallocated"; |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 323 | } else if (location.IsDoubleStackSlot()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 324 | stream << "2x" << location.GetStackIndex() << "(sp)"; |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 325 | } else { |
| 326 | DCHECK(location.IsSIMDStackSlot()); |
| 327 | stream << "4x" << location.GetStackIndex() << "(sp)"; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 331 | std::ostream& StartAttributeStream(const char* name = nullptr) { |
| 332 | if (name == nullptr) { |
| 333 | output_ << " "; |
| 334 | } else { |
| 335 | DCHECK(!HasWhitespace(name)) << "Checker does not allow spaces in attributes"; |
| 336 | output_ << " " << name << ":"; |
| 337 | } |
| 338 | return output_; |
| 339 | } |
| 340 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 341 | void VisitParallelMove(HParallelMove* instruction) override { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 342 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
| 343 | StringList moves; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 344 | for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) { |
| 345 | MoveOperands* move = instruction->MoveOperandsAt(i); |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 346 | std::ostream& str = moves.NewEntryStream(); |
| 347 | DumpLocation(str, move->GetSource()); |
| 348 | str << "->"; |
| 349 | DumpLocation(str, move->GetDestination()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 350 | } |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 351 | StartAttributeStream("moves") << moves; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 352 | } |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 353 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 354 | void VisitIntConstant(HIntConstant* instruction) override { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 355 | StartAttributeStream() << instruction->GetValue(); |
| David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 358 | void VisitLongConstant(HLongConstant* instruction) override { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 359 | StartAttributeStream() << instruction->GetValue(); |
| David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 362 | void VisitFloatConstant(HFloatConstant* instruction) override { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 363 | StartAttributeStream() << instruction->GetValue(); |
| David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 366 | void VisitDoubleConstant(HDoubleConstant* instruction) override { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 367 | StartAttributeStream() << instruction->GetValue(); |
| David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 370 | void VisitPhi(HPhi* phi) override { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 371 | StartAttributeStream("reg") << phi->GetRegNumber(); |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 372 | StartAttributeStream("is_catch_phi") << std::boolalpha << phi->IsCatchPhi() << std::noboolalpha; |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 375 | void VisitMemoryBarrier(HMemoryBarrier* barrier) override { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 376 | StartAttributeStream("kind") << barrier->GetBarrierKind(); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 377 | } |
| 378 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 379 | void VisitMonitorOperation(HMonitorOperation* monitor) override { |
| David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 380 | StartAttributeStream("kind") << (monitor->IsEnter() ? "enter" : "exit"); |
| 381 | } |
| 382 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 383 | void VisitLoadClass(HLoadClass* load_class) override { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 384 | StartAttributeStream("load_kind") << load_class->GetLoadKind(); |
| 385 | const char* descriptor = load_class->GetDexFile().GetTypeDescriptor( |
| 386 | load_class->GetDexFile().GetTypeId(load_class->GetTypeIndex())); |
| 387 | StartAttributeStream("class_name") << PrettyDescriptor(descriptor); |
| Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 388 | StartAttributeStream("gen_clinit_check") << std::boolalpha |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 389 | << load_class->MustGenerateClinitCheck() << std::noboolalpha; |
| Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 390 | StartAttributeStream("needs_access_check") << std::boolalpha |
| 391 | << load_class->NeedsAccessCheck() << std::noboolalpha; |
| Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 392 | } |
| 393 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 394 | void VisitLoadMethodHandle(HLoadMethodHandle* load_method_handle) override { |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 395 | StartAttributeStream("load_kind") << "RuntimeCall"; |
| 396 | StartAttributeStream("method_handle_index") << load_method_handle->GetMethodHandleIndex(); |
| 397 | } |
| 398 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 399 | void VisitLoadMethodType(HLoadMethodType* load_method_type) override { |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 400 | StartAttributeStream("load_kind") << "RuntimeCall"; |
| 401 | const DexFile& dex_file = load_method_type->GetDexFile(); |
| Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 402 | const dex::ProtoId& proto_id = dex_file.GetProtoId(load_method_type->GetProtoIndex()); |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 403 | StartAttributeStream("method_type") << dex_file.GetProtoSignature(proto_id); |
| 404 | } |
| 405 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 406 | void VisitLoadString(HLoadString* load_string) override { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 407 | StartAttributeStream("load_kind") << load_string->GetLoadKind(); |
| 408 | } |
| 409 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 410 | void HandleTypeCheckInstruction(HTypeCheckInstruction* check) { |
| 411 | StartAttributeStream("check_kind") << check->GetTypeCheckKind(); |
| Nicolas Geoffray | bff7a52 | 2018-01-25 13:33:07 +0000 | [diff] [blame] | 412 | StartAttributeStream("must_do_null_check") << std::boolalpha |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 413 | << check->MustDoNullCheck() << std::noboolalpha; |
| 414 | if (check->GetTypeCheckKind() == TypeCheckKind::kBitstringCheck) { |
| 415 | StartAttributeStream("path_to_root") << std::hex |
| 416 | << "0x" << check->GetBitstringPathToRoot() << std::dec; |
| 417 | StartAttributeStream("mask") << std::hex << "0x" << check->GetBitstringMask() << std::dec; |
| 418 | } |
| 419 | } |
| 420 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 421 | void VisitCheckCast(HCheckCast* check_cast) override { |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 422 | HandleTypeCheckInstruction(check_cast); |
| Guillaume "Vermeille" Sanchez | 9099ef7 | 2015-05-20 15:19:21 +0100 | [diff] [blame] | 423 | } |
| 424 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 425 | void VisitInstanceOf(HInstanceOf* instance_of) override { |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 426 | HandleTypeCheckInstruction(instance_of); |
| Guillaume "Vermeille" Sanchez | 9099ef7 | 2015-05-20 15:19:21 +0100 | [diff] [blame] | 427 | } |
| 428 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 429 | void VisitArrayLength(HArrayLength* array_length) override { |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 430 | StartAttributeStream("is_string_length") << std::boolalpha |
| 431 | << array_length->IsStringLength() << std::noboolalpha; |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 432 | if (array_length->IsEmittedAtUseSite()) { |
| 433 | StartAttributeStream("emitted_at_use") << "true"; |
| 434 | } |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 435 | } |
| 436 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 437 | void VisitBoundsCheck(HBoundsCheck* bounds_check) override { |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 438 | StartAttributeStream("is_string_char_at") << std::boolalpha |
| 439 | << bounds_check->IsStringCharAt() << std::noboolalpha; |
| 440 | } |
| 441 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 442 | void VisitArrayGet(HArrayGet* array_get) override { |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 443 | StartAttributeStream("is_string_char_at") << std::boolalpha |
| 444 | << array_get->IsStringCharAt() << std::noboolalpha; |
| 445 | } |
| 446 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 447 | void VisitArraySet(HArraySet* array_set) override { |
| Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 448 | StartAttributeStream("value_can_be_null") << std::boolalpha |
| 449 | << array_set->GetValueCanBeNull() << std::noboolalpha; |
| Roland Levillain | b133ec6 | 2016-03-23 12:40:35 +0000 | [diff] [blame] | 450 | StartAttributeStream("needs_type_check") << std::boolalpha |
| 451 | << array_set->NeedsTypeCheck() << std::noboolalpha; |
| Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 452 | } |
| 453 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 454 | void VisitCompare(HCompare* compare) override { |
| Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 455 | StartAttributeStream("bias") << compare->GetBias(); |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 458 | void VisitInvoke(HInvoke* invoke) override { |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 459 | StartAttributeStream("dex_file_index") << invoke->GetDexMethodIndex(); |
| Nicolas Geoffray | 5ceac0e | 2017-06-26 13:19:09 +0100 | [diff] [blame] | 460 | ArtMethod* method = invoke->GetResolvedMethod(); |
| 461 | // We don't print signatures, which conflict with c1visualizer format. |
| 462 | static constexpr bool kWithSignature = false; |
| 463 | // Note that we can only use the graph's dex file for the unresolved case. The |
| 464 | // other invokes might be coming from inlined methods. |
| 465 | ScopedObjectAccess soa(Thread::Current()); |
| 466 | std::string method_name = (method == nullptr) |
| 467 | ? GetGraph()->GetDexFile().PrettyMethod(invoke->GetDexMethodIndex(), kWithSignature) |
| 468 | : method->PrettyMethod(kWithSignature); |
| 469 | StartAttributeStream("method_name") << method_name; |
| Aart Bik | 2c148f0 | 2018-02-02 14:30:35 -0800 | [diff] [blame] | 470 | StartAttributeStream("always_throws") << std::boolalpha |
| 471 | << invoke->AlwaysThrows() |
| 472 | << std::noboolalpha; |
| Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 473 | } |
| 474 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 475 | void VisitInvokeUnresolved(HInvokeUnresolved* invoke) override { |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 476 | VisitInvoke(invoke); |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 477 | StartAttributeStream("invoke_type") << invoke->GetInvokeType(); |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 478 | } |
| 479 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 480 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) override { |
| Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 481 | VisitInvoke(invoke); |
| Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 482 | StartAttributeStream("method_load_kind") << invoke->GetMethodLoadKind(); |
| Scott Wakeling | d60a1af | 2015-07-22 14:32:44 +0100 | [diff] [blame] | 483 | StartAttributeStream("intrinsic") << invoke->GetIntrinsic(); |
| Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 484 | if (invoke->IsStatic()) { |
| 485 | StartAttributeStream("clinit_check") << invoke->GetClinitCheckRequirement(); |
| 486 | } |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 487 | } |
| 488 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 489 | void VisitInvokeVirtual(HInvokeVirtual* invoke) override { |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 490 | VisitInvoke(invoke); |
| 491 | StartAttributeStream("intrinsic") << invoke->GetIntrinsic(); |
| 492 | } |
| 493 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 494 | void VisitInvokePolymorphic(HInvokePolymorphic* invoke) override { |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 495 | VisitInvoke(invoke); |
| 496 | StartAttributeStream("invoke_type") << "InvokePolymorphic"; |
| 497 | } |
| 498 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 499 | void VisitInstanceFieldGet(HInstanceFieldGet* iget) override { |
| David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 500 | StartAttributeStream("field_name") << |
| 501 | iget->GetFieldInfo().GetDexFile().PrettyField(iget->GetFieldInfo().GetFieldIndex(), |
| David Brazdil | 11edec7 | 2016-03-24 12:40:52 +0000 | [diff] [blame] | 502 | /* with type */ false); |
| 503 | StartAttributeStream("field_type") << iget->GetFieldType(); |
| 504 | } |
| 505 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 506 | void VisitInstanceFieldSet(HInstanceFieldSet* iset) override { |
| David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 507 | StartAttributeStream("field_name") << |
| 508 | iset->GetFieldInfo().GetDexFile().PrettyField(iset->GetFieldInfo().GetFieldIndex(), |
| David Brazdil | 11edec7 | 2016-03-24 12:40:52 +0000 | [diff] [blame] | 509 | /* with type */ false); |
| 510 | StartAttributeStream("field_type") << iset->GetFieldType(); |
| 511 | } |
| 512 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 513 | void VisitStaticFieldGet(HStaticFieldGet* sget) override { |
| Vladimir Marko | bf3243b | 2017-08-30 14:06:54 +0100 | [diff] [blame] | 514 | StartAttributeStream("field_name") << |
| 515 | sget->GetFieldInfo().GetDexFile().PrettyField(sget->GetFieldInfo().GetFieldIndex(), |
| 516 | /* with type */ false); |
| 517 | StartAttributeStream("field_type") << sget->GetFieldType(); |
| 518 | } |
| 519 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 520 | void VisitStaticFieldSet(HStaticFieldSet* sset) override { |
| Vladimir Marko | bf3243b | 2017-08-30 14:06:54 +0100 | [diff] [blame] | 521 | StartAttributeStream("field_name") << |
| 522 | sset->GetFieldInfo().GetDexFile().PrettyField(sset->GetFieldInfo().GetFieldIndex(), |
| 523 | /* with type */ false); |
| 524 | StartAttributeStream("field_type") << sset->GetFieldType(); |
| 525 | } |
| 526 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 527 | void VisitUnresolvedInstanceFieldGet(HUnresolvedInstanceFieldGet* field_access) override { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 528 | StartAttributeStream("field_type") << field_access->GetFieldType(); |
| 529 | } |
| 530 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 531 | void VisitUnresolvedInstanceFieldSet(HUnresolvedInstanceFieldSet* field_access) override { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 532 | StartAttributeStream("field_type") << field_access->GetFieldType(); |
| 533 | } |
| 534 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 535 | void VisitUnresolvedStaticFieldGet(HUnresolvedStaticFieldGet* field_access) override { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 536 | StartAttributeStream("field_type") << field_access->GetFieldType(); |
| 537 | } |
| 538 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 539 | void VisitUnresolvedStaticFieldSet(HUnresolvedStaticFieldSet* field_access) override { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 540 | StartAttributeStream("field_type") << field_access->GetFieldType(); |
| 541 | } |
| 542 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 543 | void VisitTryBoundary(HTryBoundary* try_boundary) override { |
| David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 544 | StartAttributeStream("kind") << (try_boundary->IsEntry() ? "entry" : "exit"); |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 547 | void VisitDeoptimize(HDeoptimize* deoptimize) override { |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 548 | StartAttributeStream("kind") << deoptimize->GetKind(); |
| 549 | } |
| 550 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 551 | void VisitVecOperation(HVecOperation* vec_operation) override { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 552 | StartAttributeStream("packed_type") << vec_operation->GetPackedType(); |
| 553 | } |
| 554 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 555 | void VisitVecMemoryOperation(HVecMemoryOperation* vec_mem_operation) override { |
| Aart Bik | 38a3f21 | 2017-10-20 17:02:21 -0700 | [diff] [blame] | 556 | StartAttributeStream("alignment") << vec_mem_operation->GetAlignment().ToString(); |
| 557 | } |
| 558 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 559 | void VisitVecHalvingAdd(HVecHalvingAdd* hadd) override { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 560 | VisitVecBinaryOperation(hadd); |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 561 | StartAttributeStream("rounded") << std::boolalpha << hadd->IsRounded() << std::noboolalpha; |
| 562 | } |
| 563 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 564 | void VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) override { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 565 | VisitVecOperation(instruction); |
| Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 566 | StartAttributeStream("kind") << instruction->GetOpKind(); |
| 567 | } |
| 568 | |
| Artem Serov | aaac0e3 | 2018-08-07 00:52:22 +0100 | [diff] [blame] | 569 | void VisitVecDotProd(HVecDotProd* instruction) override { |
| 570 | VisitVecOperation(instruction); |
| 571 | DataType::Type arg_type = instruction->InputAt(1)->AsVecOperation()->GetPackedType(); |
| 572 | StartAttributeStream("type") << (instruction->IsZeroExtending() ? |
| 573 | DataType::ToUnsigned(arg_type) : |
| 574 | DataType::ToSigned(arg_type)); |
| 575 | } |
| 576 | |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 577 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 578 | void VisitMultiplyAccumulate(HMultiplyAccumulate* instruction) override { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 579 | StartAttributeStream("kind") << instruction->GetOpKind(); |
| 580 | } |
| Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 581 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 582 | void VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) override { |
| Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 583 | StartAttributeStream("kind") << instruction->GetOpKind(); |
| 584 | } |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 585 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 586 | void VisitDataProcWithShifterOp(HDataProcWithShifterOp* instruction) override { |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 587 | StartAttributeStream("kind") << instruction->GetInstrKind() << "+" << instruction->GetOpKind(); |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 588 | if (HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())) { |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 589 | StartAttributeStream("shift") << instruction->GetShiftAmount(); |
| 590 | } |
| 591 | } |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 592 | #endif |
| 593 | |
| Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 594 | bool IsPass(const char* name) { |
| 595 | return strcmp(pass_name_, name) == 0; |
| 596 | } |
| 597 | |
| David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 598 | void PrintInstruction(HInstruction* instruction) { |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 599 | output_ << instruction->DebugName(); |
| Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 600 | HConstInputsRef inputs = instruction->GetInputs(); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 601 | if (!inputs.empty()) { |
| 602 | StringList input_list; |
| 603 | for (const HInstruction* input : inputs) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 604 | input_list.NewEntryStream() << DataType::TypeId(input->GetType()) << input->GetId(); |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 605 | } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 606 | StartAttributeStream() << input_list; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 607 | } |
| Vladimir Marko | fe94875 | 2018-03-23 18:11:43 +0000 | [diff] [blame] | 608 | if (instruction->GetDexPc() != kNoDexPc) { |
| 609 | StartAttributeStream("dex_pc") << instruction->GetDexPc(); |
| 610 | } else { |
| 611 | StartAttributeStream("dex_pc") << "n/a"; |
| 612 | } |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 613 | instruction->Accept(this); |
| Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 614 | if (instruction->HasEnvironment()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 615 | StringList envs; |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 616 | for (HEnvironment* environment = instruction->GetEnvironment(); |
| 617 | environment != nullptr; |
| 618 | environment = environment->GetParent()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 619 | StringList vregs; |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 620 | for (size_t i = 0, e = environment->Size(); i < e; ++i) { |
| 621 | HInstruction* insn = environment->GetInstructionAt(i); |
| 622 | if (insn != nullptr) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 623 | vregs.NewEntryStream() << DataType::TypeId(insn->GetType()) << insn->GetId(); |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 624 | } else { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 625 | vregs.NewEntryStream() << "_"; |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 626 | } |
| Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 627 | } |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 628 | envs.NewEntryStream() << vregs; |
| Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 629 | } |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 630 | StartAttributeStream("env") << envs; |
| Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 631 | } |
| Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 632 | if (IsPass(SsaLivenessAnalysis::kLivenessPassName) |
| David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 633 | && is_after_pass_ |
| 634 | && instruction->GetLifetimePosition() != kNoLifetime) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 635 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 636 | if (instruction->HasLiveInterval()) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 637 | LiveInterval* interval = instruction->GetLiveInterval(); |
| David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 638 | StartAttributeStream("ranges") |
| 639 | << StringList(interval->GetFirstRange(), StringList::kSetBrackets); |
| Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 640 | StartAttributeStream("uses") << StringList(interval->GetUses()); |
| 641 | StartAttributeStream("env_uses") << StringList(interval->GetEnvironmentUses()); |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 642 | StartAttributeStream("is_fixed") << interval->IsFixed(); |
| 643 | StartAttributeStream("is_split") << interval->IsSplit(); |
| 644 | StartAttributeStream("is_low") << interval->IsLowInterval(); |
| 645 | StartAttributeStream("is_high") << interval->IsHighInterval(); |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 646 | } |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 650 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 651 | LocationSummary* locations = instruction->GetLocations(); |
| 652 | if (locations != nullptr) { |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 653 | StringList input_list; |
| 654 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 655 | DumpLocation(input_list.NewEntryStream(), locations->InAt(i)); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 656 | } |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 657 | std::ostream& attr = StartAttributeStream("locations"); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 658 | attr << input_list << "->"; |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 659 | DumpLocation(attr, locations->Out()); |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 660 | } |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 663 | HLoopInformation* loop_info = instruction->GetBlock()->GetLoopInformation(); |
| 664 | if (loop_info == nullptr) { |
| 665 | StartAttributeStream("loop") << "none"; |
| 666 | } else { |
| 667 | StartAttributeStream("loop") << "B" << loop_info->GetHeader()->GetBlockId(); |
| 668 | HLoopInformation* outer = loop_info->GetPreHeader()->GetLoopInformation(); |
| 669 | if (outer != nullptr) { |
| 670 | StartAttributeStream("outer_loop") << "B" << outer->GetHeader()->GetBlockId(); |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 671 | } else { |
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 672 | StartAttributeStream("outer_loop") << "none"; |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 673 | } |
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 674 | StartAttributeStream("irreducible") |
| 675 | << std::boolalpha << loop_info->IsIrreducible() << std::noboolalpha; |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 678 | // For the builder and the inliner, we want to add extra information on HInstructions |
| 679 | // that have reference types, and also HInstanceOf/HCheckcast. |
| David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 680 | if ((IsPass(HGraphBuilder::kBuilderPassName) |
| Calin Juravle | cdfed3d | 2015-10-26 14:05:01 +0000 | [diff] [blame] | 681 | || IsPass(HInliner::kInlinerPassName)) |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 682 | && (instruction->GetType() == DataType::Type::kReference || |
| 683 | instruction->IsInstanceOf() || |
| 684 | instruction->IsCheckCast())) { |
| 685 | ReferenceTypeInfo info = (instruction->GetType() == DataType::Type::kReference) |
| 686 | ? instruction->IsLoadClass() |
| 687 | ? instruction->AsLoadClass()->GetLoadedClassRTI() |
| 688 | : instruction->GetReferenceTypeInfo() |
| 689 | : instruction->IsInstanceOf() |
| 690 | ? instruction->AsInstanceOf()->GetTargetClassRTI() |
| 691 | : instruction->AsCheckCast()->GetTargetClassRTI(); |
| Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 692 | ScopedObjectAccess soa(Thread::Current()); |
| 693 | if (info.IsValid()) { |
| David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 694 | StartAttributeStream("klass") |
| 695 | << mirror::Class::PrettyDescriptor(info.GetTypeHandle().Get()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 696 | if (instruction->GetType() == DataType::Type::kReference) { |
| 697 | StartAttributeStream("can_be_null") |
| 698 | << std::boolalpha << instruction->CanBeNull() << std::noboolalpha; |
| 699 | } |
| Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 700 | StartAttributeStream("exact") << std::boolalpha << info.IsExact() << std::noboolalpha; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 701 | } else if (instruction->IsLoadClass() || |
| 702 | instruction->IsInstanceOf() || |
| 703 | instruction->IsCheckCast()) { |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 704 | StartAttributeStream("klass") << "unresolved"; |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 705 | } else { |
| Mark Mendell | b2d38fd | 2015-11-16 12:21:53 -0500 | [diff] [blame] | 706 | // The NullConstant may be added to the graph during other passes that happen between |
| 707 | // ReferenceTypePropagation and Inliner (e.g. InstructionSimplifier). If the inliner |
| 708 | // doesn't run or doesn't inline anything, the NullConstant remains untyped. |
| 709 | // So we should check NullConstants for validity only after reference type propagation. |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 710 | DCHECK(graph_in_bad_state_ || |
| David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 711 | (!is_after_pass_ && IsPass(HGraphBuilder::kBuilderPassName))) |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 712 | << instruction->DebugName() << instruction->GetId() << " has invalid rti " |
| 713 | << (is_after_pass_ ? "after" : "before") << " pass " << pass_name_; |
| Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 714 | } |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 715 | } |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 716 | if (disasm_info_ != nullptr) { |
| 717 | DCHECK(disassembler_ != nullptr); |
| 718 | // If the information is available, disassemble the code generated for |
| 719 | // this instruction. |
| 720 | auto it = disasm_info_->GetInstructionIntervals().find(instruction); |
| 721 | if (it != disasm_info_->GetInstructionIntervals().end() |
| 722 | && it->second.start != it->second.end) { |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 723 | output_ << "\n"; |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 724 | disassembler_->Disassemble(output_, it->second.start, it->second.end); |
| 725 | } |
| 726 | } |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | void PrintInstructions(const HInstructionList& list) { |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 730 | for (HInstructionIterator it(list); !it.Done(); it.Advance()) { |
| 731 | HInstruction* instruction = it.Current(); |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 732 | int bci = 0; |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 733 | size_t num_uses = instruction->GetUses().SizeSlow(); |
| David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 734 | AddIndent(); |
| 735 | output_ << bci << " " << num_uses << " " |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 736 | << DataType::TypeId(instruction->GetType()) << instruction->GetId() << " "; |
| David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 737 | PrintInstruction(instruction); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 738 | output_ << " " << kEndInstructionMarker << "\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 742 | void DumpStartOfDisassemblyBlock(const char* block_name, |
| 743 | int predecessor_index, |
| 744 | int successor_index) { |
| 745 | StartTag("block"); |
| 746 | PrintProperty("name", block_name); |
| 747 | PrintInt("from_bci", -1); |
| 748 | PrintInt("to_bci", -1); |
| 749 | if (predecessor_index != -1) { |
| 750 | PrintProperty("predecessors", "B", predecessor_index); |
| 751 | } else { |
| 752 | PrintEmptyProperty("predecessors"); |
| 753 | } |
| 754 | if (successor_index != -1) { |
| 755 | PrintProperty("successors", "B", successor_index); |
| 756 | } else { |
| 757 | PrintEmptyProperty("successors"); |
| 758 | } |
| 759 | PrintEmptyProperty("xhandlers"); |
| 760 | PrintEmptyProperty("flags"); |
| 761 | StartTag("states"); |
| 762 | StartTag("locals"); |
| 763 | PrintInt("size", 0); |
| 764 | PrintProperty("method", "None"); |
| 765 | EndTag("locals"); |
| 766 | EndTag("states"); |
| 767 | StartTag("HIR"); |
| 768 | } |
| 769 | |
| 770 | void DumpEndOfDisassemblyBlock() { |
| 771 | EndTag("HIR"); |
| 772 | EndTag("block"); |
| 773 | } |
| 774 | |
| 775 | void DumpDisassemblyBlockForFrameEntry() { |
| 776 | DumpStartOfDisassemblyBlock(kDisassemblyBlockFrameEntry, |
| 777 | -1, |
| 778 | GetGraph()->GetEntryBlock()->GetBlockId()); |
| 779 | output_ << " 0 0 disasm " << kDisassemblyBlockFrameEntry << " "; |
| 780 | GeneratedCodeInterval frame_entry = disasm_info_->GetFrameEntryInterval(); |
| 781 | if (frame_entry.start != frame_entry.end) { |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 782 | output_ << "\n"; |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 783 | disassembler_->Disassemble(output_, frame_entry.start, frame_entry.end); |
| 784 | } |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 785 | output_ << kEndInstructionMarker << "\n"; |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 786 | DumpEndOfDisassemblyBlock(); |
| 787 | } |
| 788 | |
| 789 | void DumpDisassemblyBlockForSlowPaths() { |
| 790 | if (disasm_info_->GetSlowPathIntervals().empty()) { |
| 791 | return; |
| 792 | } |
| 793 | // If the graph has an exit block we attach the block for the slow paths |
| 794 | // after it. Else we just add the block to the graph without linking it to |
| 795 | // any other. |
| 796 | DumpStartOfDisassemblyBlock( |
| 797 | kDisassemblyBlockSlowPaths, |
| 798 | GetGraph()->HasExitBlock() ? GetGraph()->GetExitBlock()->GetBlockId() : -1, |
| 799 | -1); |
| 800 | for (SlowPathCodeInfo info : disasm_info_->GetSlowPathIntervals()) { |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 801 | output_ << " 0 0 disasm " << info.slow_path->GetDescription() << "\n"; |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 802 | disassembler_->Disassemble(output_, info.code_interval.start, info.code_interval.end); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 803 | output_ << kEndInstructionMarker << "\n"; |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 804 | } |
| 805 | DumpEndOfDisassemblyBlock(); |
| 806 | } |
| 807 | |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 808 | void Run() { |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 809 | StartTag("cfg"); |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 810 | std::string pass_desc = std::string(pass_name_) |
| 811 | + " (" |
| 812 | + (is_after_pass_ ? "after" : "before") |
| 813 | + (graph_in_bad_state_ ? ", bad_state" : "") |
| 814 | + ")"; |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 815 | PrintProperty("name", pass_desc.c_str()); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 816 | if (disasm_info_ != nullptr) { |
| 817 | DumpDisassemblyBlockForFrameEntry(); |
| 818 | } |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 819 | VisitInsertionOrder(); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 820 | if (disasm_info_ != nullptr) { |
| 821 | DumpDisassemblyBlockForSlowPaths(); |
| 822 | } |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 823 | EndTag("cfg"); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 824 | Flush(); |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 825 | } |
| 826 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 827 | void VisitBasicBlock(HBasicBlock* block) override { |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 828 | StartTag("block"); |
| 829 | PrintProperty("name", "B", block->GetBlockId()); |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 830 | if (block->GetLifetimeStart() != kNoLifetime) { |
| 831 | // Piggy back on these fields to show the lifetime of the block. |
| 832 | PrintInt("from_bci", block->GetLifetimeStart()); |
| 833 | PrintInt("to_bci", block->GetLifetimeEnd()); |
| 834 | } else { |
| 835 | PrintInt("from_bci", -1); |
| 836 | PrintInt("to_bci", -1); |
| 837 | } |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 838 | PrintPredecessors(block); |
| 839 | PrintSuccessors(block); |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 840 | PrintExceptionHandlers(block); |
| 841 | |
| 842 | if (block->IsCatchBlock()) { |
| 843 | PrintProperty("flags", "catch_block"); |
| 844 | } else { |
| 845 | PrintEmptyProperty("flags"); |
| 846 | } |
| 847 | |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 848 | if (block->GetDominator() != nullptr) { |
| 849 | PrintProperty("dominator", "B", block->GetDominator()->GetBlockId()); |
| 850 | } |
| 851 | |
| 852 | StartTag("states"); |
| 853 | StartTag("locals"); |
| 854 | PrintInt("size", 0); |
| 855 | PrintProperty("method", "None"); |
| 856 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 857 | AddIndent(); |
| 858 | HInstruction* instruction = it.Current(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 859 | output_ << instruction->GetId() << " " << DataType::TypeId(instruction->GetType()) |
| Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 860 | << instruction->GetId() << "[ "; |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 861 | for (const HInstruction* input : instruction->GetInputs()) { |
| 862 | output_ << input->GetId() << " "; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 863 | } |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 864 | output_ << "]\n"; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 865 | } |
| 866 | EndTag("locals"); |
| 867 | EndTag("states"); |
| 868 | |
| 869 | StartTag("HIR"); |
| 870 | PrintInstructions(block->GetPhis()); |
| 871 | PrintInstructions(block->GetInstructions()); |
| 872 | EndTag("HIR"); |
| 873 | EndTag("block"); |
| 874 | } |
| 875 | |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 876 | static constexpr const char* const kEndInstructionMarker = "<|@"; |
| 877 | static constexpr const char* const kDisassemblyBlockFrameEntry = "FrameEntry"; |
| 878 | static constexpr const char* const kDisassemblyBlockSlowPaths = "SlowPaths"; |
| 879 | |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 880 | private: |
| 881 | std::ostream& output_; |
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 882 | const char* pass_name_; |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 883 | const bool is_after_pass_; |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 884 | const bool graph_in_bad_state_; |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 885 | const CodeGenerator& codegen_; |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 886 | const DisassemblyInformation* disasm_info_; |
| 887 | std::unique_ptr<HGraphVisualizerDisassembler> disassembler_; |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 888 | size_t indent_; |
| 889 | |
| 890 | DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter); |
| 891 | }; |
| 892 | |
| 893 | HGraphVisualizer::HGraphVisualizer(std::ostream* output, |
| 894 | HGraph* graph, |
| David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 895 | const CodeGenerator& codegen) |
| 896 | : output_(output), graph_(graph), codegen_(codegen) {} |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 897 | |
| David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 898 | void HGraphVisualizer::PrintHeader(const char* method_name) const { |
| 899 | DCHECK(output_ != nullptr); |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 900 | HGraphVisualizerPrinter printer(graph_, *output_, "", true, false, codegen_); |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 901 | printer.StartTag("compilation"); |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 902 | printer.PrintProperty("name", method_name); |
| 903 | printer.PrintProperty("method", method_name); |
| Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 904 | printer.PrintTime("date"); |
| 905 | printer.EndTag("compilation"); |
| David Brazdil | fa02c9d | 2016-03-30 09:41:02 +0100 | [diff] [blame] | 906 | printer.Flush(); |
| Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 907 | } |
| 908 | |
| Fabio Rinaldi | 52d5354 | 2020-02-10 17:28:06 +0000 | [diff] [blame] | 909 | std::string HGraphVisualizer::InsertMetaDataAsCompilationBlock(const std::string& meta_data) { |
| 910 | std::string time_str = std::to_string(time(nullptr)); |
| 911 | std::string quoted_meta_data = "\"" + meta_data + "\""; |
| 912 | return StringPrintf("begin_compilation\n" |
| 913 | " name %s\n" |
| 914 | " method %s\n" |
| 915 | " date %s\n" |
| 916 | "end_compilation\n", |
| 917 | quoted_meta_data.c_str(), |
| 918 | quoted_meta_data.c_str(), |
| 919 | time_str.c_str()); |
| 920 | } |
| 921 | |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 922 | void HGraphVisualizer::DumpGraph(const char* pass_name, |
| 923 | bool is_after_pass, |
| 924 | bool graph_in_bad_state) const { |
| David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 925 | DCHECK(output_ != nullptr); |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 926 | if (!graph_->GetBlocks().empty()) { |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 927 | HGraphVisualizerPrinter printer(graph_, |
| 928 | *output_, |
| 929 | pass_name, |
| 930 | is_after_pass, |
| 931 | graph_in_bad_state, |
| 932 | codegen_); |
| David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 933 | printer.Run(); |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 934 | } |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 935 | } |
| 936 | |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 937 | void HGraphVisualizer::DumpGraphWithDisassembly() const { |
| 938 | DCHECK(output_ != nullptr); |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 939 | if (!graph_->GetBlocks().empty()) { |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 940 | HGraphVisualizerPrinter printer(graph_, |
| 941 | *output_, |
| 942 | "disassembly", |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 943 | /* is_after_pass= */ true, |
| 944 | /* graph_in_bad_state= */ false, |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 945 | codegen_, |
| 946 | codegen_.GetDisassemblyInformation()); |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 947 | printer.Run(); |
| 948 | } |
| 949 | } |
| 950 | |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 951 | } // namespace art |