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