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 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 24 | #include "code_generator.h" |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 25 | #include "dead_code_elimination.h" |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 26 | #include "disassembler.h" |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 27 | #include "licm.h" |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 28 | #include "nodes.h" |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 29 | #include "optimization.h" |
Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 30 | #include "reference_type_propagation.h" |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 31 | #include "register_allocator.h" |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 32 | #include "ssa_liveness_analysis.h" |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 33 | #include "utils/assembler.h" |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 34 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 35 | namespace art { |
| 36 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 37 | static bool HasWhitespace(const char* str) { |
| 38 | DCHECK(str != nullptr); |
| 39 | while (str[0] != 0) { |
| 40 | if (isspace(str[0])) { |
| 41 | return true; |
| 42 | } |
| 43 | str++; |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | class StringList { |
| 49 | public: |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 50 | enum Format { |
| 51 | kArrayBrackets, |
| 52 | kSetBrackets, |
| 53 | }; |
| 54 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 55 | // Create an empty list |
David Brazdil | f1a9ff7 | 2015-05-18 16:04:53 +0100 | [diff] [blame] | 56 | explicit StringList(Format format = kArrayBrackets) : format_(format), is_empty_(true) {} |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 57 | |
| 58 | // Construct StringList from a linked list. List element class T |
| 59 | // must provide methods `GetNext` and `Dump`. |
| 60 | template<class T> |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 61 | explicit StringList(T* first_entry, Format format = kArrayBrackets) : StringList(format) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 62 | for (T* current = first_entry; current != nullptr; current = current->GetNext()) { |
| 63 | current->Dump(NewEntryStream()); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | std::ostream& NewEntryStream() { |
| 68 | if (is_empty_) { |
| 69 | is_empty_ = false; |
| 70 | } else { |
David Brazdil | c57397b | 2015-05-15 16:01:59 +0100 | [diff] [blame] | 71 | sstream_ << ","; |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 72 | } |
| 73 | return sstream_; |
| 74 | } |
| 75 | |
| 76 | private: |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 77 | Format format_; |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 78 | bool is_empty_; |
| 79 | std::ostringstream sstream_; |
| 80 | |
| 81 | friend std::ostream& operator<<(std::ostream& os, const StringList& list); |
| 82 | }; |
| 83 | |
| 84 | std::ostream& operator<<(std::ostream& os, const StringList& list) { |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 85 | switch (list.format_) { |
| 86 | case StringList::kArrayBrackets: return os << "[" << list.sstream_.str() << "]"; |
| 87 | case StringList::kSetBrackets: return os << "{" << list.sstream_.str() << "}"; |
| 88 | default: |
| 89 | LOG(FATAL) << "Invalid StringList format"; |
| 90 | UNREACHABLE(); |
| 91 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 94 | typedef Disassembler* create_disasm_prototype(InstructionSet instruction_set, |
| 95 | DisassemblerOptions* options); |
| 96 | class HGraphVisualizerDisassembler { |
| 97 | public: |
| 98 | HGraphVisualizerDisassembler(InstructionSet instruction_set, const uint8_t* base_address) |
David Brazdil | 3a690be | 2015-06-23 10:22:38 +0100 | [diff] [blame] | 99 | : instruction_set_(instruction_set), disassembler_(nullptr) { |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 100 | libart_disassembler_handle_ = |
| 101 | dlopen(kIsDebugBuild ? "libartd-disassembler.so" : "libart-disassembler.so", RTLD_NOW); |
| 102 | if (libart_disassembler_handle_ == nullptr) { |
| 103 | LOG(WARNING) << "Failed to dlopen libart-disassembler: " << dlerror(); |
| 104 | return; |
| 105 | } |
| 106 | create_disasm_prototype* create_disassembler = reinterpret_cast<create_disasm_prototype*>( |
| 107 | dlsym(libart_disassembler_handle_, "create_disassembler")); |
| 108 | if (create_disassembler == nullptr) { |
| 109 | LOG(WARNING) << "Could not find create_disassembler entry: " << dlerror(); |
| 110 | return; |
| 111 | } |
| 112 | // Reading the disassembly from 0x0 is easier, so we print relative |
| 113 | // addresses. We will only disassemble the code once everything has |
| 114 | // been generated, so we can read data in literal pools. |
| 115 | disassembler_ = std::unique_ptr<Disassembler>((*create_disassembler)( |
| 116 | instruction_set, |
| 117 | new DisassemblerOptions(/* absolute_addresses */ false, |
| 118 | base_address, |
| 119 | /* can_read_literals */ true))); |
| 120 | } |
| 121 | |
| 122 | ~HGraphVisualizerDisassembler() { |
| 123 | // We need to call ~Disassembler() before we close the library. |
| 124 | disassembler_.reset(); |
| 125 | if (libart_disassembler_handle_ != nullptr) { |
| 126 | dlclose(libart_disassembler_handle_); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | void Disassemble(std::ostream& output, size_t start, size_t end) const { |
David Brazdil | 3a690be | 2015-06-23 10:22:38 +0100 | [diff] [blame] | 131 | if (disassembler_ == nullptr) { |
| 132 | return; |
| 133 | } |
| 134 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 135 | const uint8_t* base = disassembler_->GetDisassemblerOptions()->base_address_; |
| 136 | if (instruction_set_ == kThumb2) { |
| 137 | // ARM and Thumb-2 use the same disassembler. The bottom bit of the |
| 138 | // address is used to distinguish between the two. |
| 139 | base += 1; |
| 140 | } |
| 141 | disassembler_->Dump(output, base + start, base + end); |
| 142 | } |
| 143 | |
| 144 | private: |
| 145 | InstructionSet instruction_set_; |
| 146 | std::unique_ptr<Disassembler> disassembler_; |
| 147 | |
| 148 | void* libart_disassembler_handle_; |
| 149 | }; |
| 150 | |
| 151 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 152 | /** |
| 153 | * HGraph visitor to generate a file suitable for the c1visualizer tool and IRHydra. |
| 154 | */ |
Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 155 | class HGraphVisualizerPrinter : public HGraphDelegateVisitor { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 156 | public: |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 157 | HGraphVisualizerPrinter(HGraph* graph, |
| 158 | std::ostream& output, |
| 159 | const char* pass_name, |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 160 | bool is_after_pass, |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 161 | bool graph_in_bad_state, |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 162 | const CodeGenerator& codegen, |
| 163 | const DisassemblyInformation* disasm_info = nullptr) |
Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 164 | : HGraphDelegateVisitor(graph), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 165 | output_(output), |
| 166 | pass_name_(pass_name), |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 167 | is_after_pass_(is_after_pass), |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 168 | graph_in_bad_state_(graph_in_bad_state), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 169 | codegen_(codegen), |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 170 | disasm_info_(disasm_info), |
| 171 | disassembler_(disasm_info_ != nullptr |
| 172 | ? new HGraphVisualizerDisassembler( |
| 173 | codegen_.GetInstructionSet(), |
| 174 | codegen_.GetAssembler().CodeBufferBaseAddress()) |
| 175 | : nullptr), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 176 | indent_(0) {} |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 177 | |
| 178 | void StartTag(const char* name) { |
| 179 | AddIndent(); |
| 180 | output_ << "begin_" << name << std::endl; |
| 181 | indent_++; |
| 182 | } |
| 183 | |
| 184 | void EndTag(const char* name) { |
| 185 | indent_--; |
| 186 | AddIndent(); |
| 187 | output_ << "end_" << name << std::endl; |
| 188 | } |
| 189 | |
| 190 | void PrintProperty(const char* name, const char* property) { |
| 191 | AddIndent(); |
| 192 | output_ << name << " \"" << property << "\"" << std::endl; |
| 193 | } |
| 194 | |
| 195 | void PrintProperty(const char* name, const char* property, int id) { |
| 196 | AddIndent(); |
| 197 | output_ << name << " \"" << property << id << "\"" << std::endl; |
| 198 | } |
| 199 | |
| 200 | void PrintEmptyProperty(const char* name) { |
| 201 | AddIndent(); |
| 202 | output_ << name << std::endl; |
| 203 | } |
| 204 | |
| 205 | void PrintTime(const char* name) { |
| 206 | AddIndent(); |
Jean Christophe Beyler | 0ada95d | 2014-12-04 11:20:20 -0800 | [diff] [blame] | 207 | output_ << name << " " << time(nullptr) << std::endl; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | void PrintInt(const char* name, int value) { |
| 211 | AddIndent(); |
| 212 | output_ << name << " " << value << std::endl; |
| 213 | } |
| 214 | |
| 215 | void AddIndent() { |
| 216 | for (size_t i = 0; i < indent_; ++i) { |
| 217 | output_ << " "; |
| 218 | } |
| 219 | } |
| 220 | |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 221 | char GetTypeId(Primitive::Type type) { |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 222 | // Note that Primitive::Descriptor would not work for us |
| 223 | // because it does not handle reference types (that is kPrimNot). |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 224 | switch (type) { |
| 225 | case Primitive::kPrimBoolean: return 'z'; |
| 226 | case Primitive::kPrimByte: return 'b'; |
| 227 | case Primitive::kPrimChar: return 'c'; |
| 228 | case Primitive::kPrimShort: return 's'; |
| 229 | case Primitive::kPrimInt: return 'i'; |
| 230 | case Primitive::kPrimLong: return 'j'; |
| 231 | case Primitive::kPrimFloat: return 'f'; |
| 232 | case Primitive::kPrimDouble: return 'd'; |
| 233 | case Primitive::kPrimNot: return 'l'; |
| 234 | case Primitive::kPrimVoid: return 'v'; |
| 235 | } |
| 236 | LOG(FATAL) << "Unreachable"; |
| 237 | return 'v'; |
| 238 | } |
| 239 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 240 | void PrintPredecessors(HBasicBlock* block) { |
| 241 | AddIndent(); |
| 242 | output_ << "predecessors"; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame^] | 243 | for (HBasicBlock* predecessor : block->GetPredecessors()) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 244 | output_ << " \"B" << predecessor->GetBlockId() << "\" "; |
| 245 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 246 | if (block->IsEntryBlock() && (disasm_info_ != nullptr)) { |
| 247 | output_ << " \"" << kDisassemblyBlockFrameEntry << "\" "; |
| 248 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 249 | output_<< std::endl; |
| 250 | } |
| 251 | |
| 252 | void PrintSuccessors(HBasicBlock* block) { |
| 253 | AddIndent(); |
| 254 | output_ << "successors"; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 255 | for (size_t i = 0; i < block->NumberOfNormalSuccessors(); ++i) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame^] | 256 | HBasicBlock* successor = block->GetSuccessor(i); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 257 | output_ << " \"B" << successor->GetBlockId() << "\" "; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 258 | } |
| 259 | output_<< std::endl; |
| 260 | } |
| 261 | |
| 262 | void PrintExceptionHandlers(HBasicBlock* block) { |
| 263 | AddIndent(); |
| 264 | output_ << "xhandlers"; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame^] | 265 | for (size_t i = block->NumberOfNormalSuccessors(); i < block->GetSuccessors().size(); ++i) { |
| 266 | HBasicBlock* handler = block->GetSuccessor(i); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 267 | output_ << " \"B" << handler->GetBlockId() << "\" "; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 268 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 269 | if (block->IsExitBlock() && |
| 270 | (disasm_info_ != nullptr) && |
| 271 | !disasm_info_->GetSlowPathIntervals().empty()) { |
| 272 | output_ << " \"" << kDisassemblyBlockSlowPaths << "\" "; |
| 273 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 274 | output_<< std::endl; |
| 275 | } |
| 276 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 277 | void DumpLocation(std::ostream& stream, const Location& location) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 278 | if (location.IsRegister()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 279 | codegen_.DumpCoreRegister(stream, location.reg()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 280 | } else if (location.IsFpuRegister()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 281 | codegen_.DumpFloatingPointRegister(stream, location.reg()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 282 | } else if (location.IsConstant()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 283 | stream << "#"; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 284 | HConstant* constant = location.GetConstant(); |
| 285 | if (constant->IsIntConstant()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 286 | stream << constant->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 287 | } else if (constant->IsLongConstant()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 288 | stream << constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 289 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 290 | } else if (location.IsInvalid()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 291 | stream << "invalid"; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 292 | } else if (location.IsStackSlot()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 293 | stream << location.GetStackIndex() << "(sp)"; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 294 | } else if (location.IsFpuRegisterPair()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 295 | codegen_.DumpFloatingPointRegister(stream, location.low()); |
| 296 | stream << "|"; |
| 297 | codegen_.DumpFloatingPointRegister(stream, location.high()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 298 | } else if (location.IsRegisterPair()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 299 | codegen_.DumpCoreRegister(stream, location.low()); |
| 300 | stream << "|"; |
| 301 | codegen_.DumpCoreRegister(stream, location.high()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 302 | } else if (location.IsUnallocated()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 303 | stream << "unallocated"; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 304 | } else { |
| 305 | DCHECK(location.IsDoubleStackSlot()); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 306 | stream << "2x" << location.GetStackIndex() << "(sp)"; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 310 | std::ostream& StartAttributeStream(const char* name = nullptr) { |
| 311 | if (name == nullptr) { |
| 312 | output_ << " "; |
| 313 | } else { |
| 314 | DCHECK(!HasWhitespace(name)) << "Checker does not allow spaces in attributes"; |
| 315 | output_ << " " << name << ":"; |
| 316 | } |
| 317 | return output_; |
| 318 | } |
| 319 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 320 | void VisitParallelMove(HParallelMove* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 321 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
| 322 | StringList moves; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 323 | for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) { |
| 324 | MoveOperands* move = instruction->MoveOperandsAt(i); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 325 | std::ostream& str = moves.NewEntryStream(); |
| 326 | DumpLocation(str, move->GetSource()); |
| 327 | str << "->"; |
| 328 | DumpLocation(str, move->GetDestination()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 329 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 330 | StartAttributeStream("moves") << moves; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 331 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 332 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 333 | void VisitIntConstant(HIntConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 334 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 335 | } |
| 336 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 337 | void VisitLongConstant(HLongConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 338 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 339 | } |
| 340 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 341 | void VisitFloatConstant(HFloatConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 342 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 343 | } |
| 344 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 345 | void VisitDoubleConstant(HDoubleConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 346 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 349 | void VisitPhi(HPhi* phi) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 350 | StartAttributeStream("reg") << phi->GetRegNumber(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 351 | StartAttributeStream("is_catch_phi") << std::boolalpha << phi->IsCatchPhi() << std::noboolalpha; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 354 | void VisitMemoryBarrier(HMemoryBarrier* barrier) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 355 | StartAttributeStream("kind") << barrier->GetBarrierKind(); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 356 | } |
| 357 | |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 358 | void VisitMonitorOperation(HMonitorOperation* monitor) OVERRIDE { |
| 359 | StartAttributeStream("kind") << (monitor->IsEnter() ? "enter" : "exit"); |
| 360 | } |
| 361 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | void VisitLoadClass(HLoadClass* load_class) OVERRIDE { |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 363 | StartAttributeStream("gen_clinit_check") << std::boolalpha |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 364 | << load_class->MustGenerateClinitCheck() << std::noboolalpha; |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Guillaume "Vermeille" Sanchez | 9099ef7 | 2015-05-20 15:19:21 +0100 | [diff] [blame] | 367 | void VisitCheckCast(HCheckCast* check_cast) OVERRIDE { |
| 368 | StartAttributeStream("must_do_null_check") << std::boolalpha |
| 369 | << check_cast->MustDoNullCheck() << std::noboolalpha; |
| 370 | } |
| 371 | |
| 372 | void VisitInstanceOf(HInstanceOf* instance_of) OVERRIDE { |
| 373 | StartAttributeStream("must_do_null_check") << std::boolalpha |
| 374 | << instance_of->MustDoNullCheck() << std::noboolalpha; |
| 375 | } |
| 376 | |
Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 377 | void VisitInvoke(HInvoke* invoke) OVERRIDE { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 378 | StartAttributeStream("dex_file_index") << invoke->GetDexMethodIndex(); |
Nicolas Geoffray | 242febb | 2015-07-01 16:10:44 +0100 | [diff] [blame] | 379 | StartAttributeStream("method_name") << PrettyMethod( |
| 380 | invoke->GetDexMethodIndex(), GetGraph()->GetDexFile(), /* with_signature */ false); |
Nicolas Geoffray | 842acd4 | 2015-07-01 13:00:15 +0100 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE { |
| 384 | VisitInvoke(invoke); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 385 | StartAttributeStream("recursive") << std::boolalpha |
| 386 | << invoke->IsRecursive() |
| 387 | << std::noboolalpha; |
Scott Wakeling | d60a1af | 2015-07-22 14:32:44 +0100 | [diff] [blame] | 388 | StartAttributeStream("intrinsic") << invoke->GetIntrinsic(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 389 | } |
| 390 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 391 | void VisitTryBoundary(HTryBoundary* try_boundary) OVERRIDE { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 392 | StartAttributeStream("kind") << (try_boundary->IsEntry() ? "entry" : "exit"); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 395 | bool IsPass(const char* name) { |
| 396 | return strcmp(pass_name_, name) == 0; |
| 397 | } |
| 398 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 399 | bool IsReferenceTypePropagationPass() { |
| 400 | return strstr(pass_name_, ReferenceTypePropagation::kReferenceTypePropagationPassName) |
| 401 | != nullptr; |
| 402 | } |
| 403 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 404 | void PrintInstruction(HInstruction* instruction) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 405 | output_ << instruction->DebugName(); |
| 406 | if (instruction->InputCount() > 0) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 407 | StringList inputs; |
| 408 | for (HInputIterator it(instruction); !it.Done(); it.Advance()) { |
| 409 | inputs.NewEntryStream() << GetTypeId(it.Current()->GetType()) << it.Current()->GetId(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 410 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 411 | StartAttributeStream() << inputs; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 412 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 413 | instruction->Accept(this); |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 414 | if (instruction->HasEnvironment()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 415 | StringList envs; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 416 | for (HEnvironment* environment = instruction->GetEnvironment(); |
| 417 | environment != nullptr; |
| 418 | environment = environment->GetParent()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 419 | StringList vregs; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 420 | for (size_t i = 0, e = environment->Size(); i < e; ++i) { |
| 421 | HInstruction* insn = environment->GetInstructionAt(i); |
| 422 | if (insn != nullptr) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 423 | vregs.NewEntryStream() << GetTypeId(insn->GetType()) << insn->GetId(); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 424 | } else { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 425 | vregs.NewEntryStream() << "_"; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 426 | } |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 427 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 428 | envs.NewEntryStream() << vregs; |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 429 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 430 | StartAttributeStream("env") << envs; |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 431 | } |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 432 | if (IsPass(SsaLivenessAnalysis::kLivenessPassName) |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 433 | && is_after_pass_ |
| 434 | && instruction->GetLifetimePosition() != kNoLifetime) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 435 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 436 | if (instruction->HasLiveInterval()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 437 | LiveInterval* interval = instruction->GetLiveInterval(); |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 438 | StartAttributeStream("ranges") |
| 439 | << StringList(interval->GetFirstRange(), StringList::kSetBrackets); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 440 | StartAttributeStream("uses") << StringList(interval->GetFirstUse()); |
| 441 | StartAttributeStream("env_uses") << StringList(interval->GetFirstEnvironmentUse()); |
| 442 | StartAttributeStream("is_fixed") << interval->IsFixed(); |
| 443 | StartAttributeStream("is_split") << interval->IsSplit(); |
| 444 | StartAttributeStream("is_low") << interval->IsLowInterval(); |
| 445 | StartAttributeStream("is_high") << interval->IsHighInterval(); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 446 | } |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 447 | } else if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 448 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 449 | LocationSummary* locations = instruction->GetLocations(); |
| 450 | if (locations != nullptr) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 451 | StringList inputs; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 452 | for (size_t i = 0; i < instruction->InputCount(); ++i) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 453 | DumpLocation(inputs.NewEntryStream(), locations->InAt(i)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 454 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 455 | std::ostream& attr = StartAttributeStream("locations"); |
| 456 | attr << inputs << "->"; |
| 457 | DumpLocation(attr, locations->Out()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 458 | } |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 459 | } else if (IsPass(LICM::kLoopInvariantCodeMotionPassName) |
| 460 | || IsPass(HDeadCodeElimination::kFinalDeadCodeEliminationPassName)) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 461 | HLoopInformation* info = instruction->GetBlock()->GetLoopInformation(); |
| 462 | if (info == nullptr) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 463 | StartAttributeStream("loop") << "none"; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 464 | } else { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 465 | StartAttributeStream("loop") << "B" << info->GetHeader()->GetBlockId(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 466 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 467 | } else if (IsReferenceTypePropagationPass() |
| 468 | && (instruction->GetType() == Primitive::kPrimNot)) { |
| 469 | ReferenceTypeInfo info = instruction->IsLoadClass() |
| 470 | ? instruction->AsLoadClass()->GetLoadedClassRTI() |
| 471 | : instruction->GetReferenceTypeInfo(); |
| 472 | ScopedObjectAccess soa(Thread::Current()); |
| 473 | if (info.IsValid()) { |
| 474 | StartAttributeStream("klass") << PrettyDescriptor(info.GetTypeHandle().Get()); |
| 475 | StartAttributeStream("can_be_null") |
| 476 | << std::boolalpha << instruction->CanBeNull() << std::noboolalpha; |
| 477 | StartAttributeStream("exact") << std::boolalpha << info.IsExact() << std::noboolalpha; |
| 478 | } else { |
| 479 | DCHECK(!is_after_pass_) << "Type info should be valid after reference type propagation"; |
Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 480 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 481 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 482 | if (disasm_info_ != nullptr) { |
| 483 | DCHECK(disassembler_ != nullptr); |
| 484 | // If the information is available, disassemble the code generated for |
| 485 | // this instruction. |
| 486 | auto it = disasm_info_->GetInstructionIntervals().find(instruction); |
| 487 | if (it != disasm_info_->GetInstructionIntervals().end() |
| 488 | && it->second.start != it->second.end) { |
| 489 | output_ << std::endl; |
| 490 | disassembler_->Disassemble(output_, it->second.start, it->second.end); |
| 491 | } |
| 492 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void PrintInstructions(const HInstructionList& list) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 496 | for (HInstructionIterator it(list); !it.Done(); it.Advance()) { |
| 497 | HInstruction* instruction = it.Current(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 498 | int bci = 0; |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 499 | size_t num_uses = 0; |
| 500 | for (HUseIterator<HInstruction*> use_it(instruction->GetUses()); |
| 501 | !use_it.Done(); |
| 502 | use_it.Advance()) { |
| 503 | ++num_uses; |
| 504 | } |
| 505 | AddIndent(); |
| 506 | output_ << bci << " " << num_uses << " " |
| 507 | << GetTypeId(instruction->GetType()) << instruction->GetId() << " "; |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 508 | PrintInstruction(instruction); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 509 | output_ << " " << kEndInstructionMarker << std::endl; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 513 | void DumpStartOfDisassemblyBlock(const char* block_name, |
| 514 | int predecessor_index, |
| 515 | int successor_index) { |
| 516 | StartTag("block"); |
| 517 | PrintProperty("name", block_name); |
| 518 | PrintInt("from_bci", -1); |
| 519 | PrintInt("to_bci", -1); |
| 520 | if (predecessor_index != -1) { |
| 521 | PrintProperty("predecessors", "B", predecessor_index); |
| 522 | } else { |
| 523 | PrintEmptyProperty("predecessors"); |
| 524 | } |
| 525 | if (successor_index != -1) { |
| 526 | PrintProperty("successors", "B", successor_index); |
| 527 | } else { |
| 528 | PrintEmptyProperty("successors"); |
| 529 | } |
| 530 | PrintEmptyProperty("xhandlers"); |
| 531 | PrintEmptyProperty("flags"); |
| 532 | StartTag("states"); |
| 533 | StartTag("locals"); |
| 534 | PrintInt("size", 0); |
| 535 | PrintProperty("method", "None"); |
| 536 | EndTag("locals"); |
| 537 | EndTag("states"); |
| 538 | StartTag("HIR"); |
| 539 | } |
| 540 | |
| 541 | void DumpEndOfDisassemblyBlock() { |
| 542 | EndTag("HIR"); |
| 543 | EndTag("block"); |
| 544 | } |
| 545 | |
| 546 | void DumpDisassemblyBlockForFrameEntry() { |
| 547 | DumpStartOfDisassemblyBlock(kDisassemblyBlockFrameEntry, |
| 548 | -1, |
| 549 | GetGraph()->GetEntryBlock()->GetBlockId()); |
| 550 | output_ << " 0 0 disasm " << kDisassemblyBlockFrameEntry << " "; |
| 551 | GeneratedCodeInterval frame_entry = disasm_info_->GetFrameEntryInterval(); |
| 552 | if (frame_entry.start != frame_entry.end) { |
| 553 | output_ << std::endl; |
| 554 | disassembler_->Disassemble(output_, frame_entry.start, frame_entry.end); |
| 555 | } |
| 556 | output_ << kEndInstructionMarker << std::endl; |
| 557 | DumpEndOfDisassemblyBlock(); |
| 558 | } |
| 559 | |
| 560 | void DumpDisassemblyBlockForSlowPaths() { |
| 561 | if (disasm_info_->GetSlowPathIntervals().empty()) { |
| 562 | return; |
| 563 | } |
| 564 | // If the graph has an exit block we attach the block for the slow paths |
| 565 | // after it. Else we just add the block to the graph without linking it to |
| 566 | // any other. |
| 567 | DumpStartOfDisassemblyBlock( |
| 568 | kDisassemblyBlockSlowPaths, |
| 569 | GetGraph()->HasExitBlock() ? GetGraph()->GetExitBlock()->GetBlockId() : -1, |
| 570 | -1); |
| 571 | for (SlowPathCodeInfo info : disasm_info_->GetSlowPathIntervals()) { |
| 572 | output_ << " 0 0 disasm " << info.slow_path->GetDescription() << std::endl; |
| 573 | disassembler_->Disassemble(output_, info.code_interval.start, info.code_interval.end); |
| 574 | output_ << kEndInstructionMarker << std::endl; |
| 575 | } |
| 576 | DumpEndOfDisassemblyBlock(); |
| 577 | } |
| 578 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 579 | void Run() { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 580 | StartTag("cfg"); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 581 | std::string pass_desc = std::string(pass_name_) |
| 582 | + " (" |
| 583 | + (is_after_pass_ ? "after" : "before") |
| 584 | + (graph_in_bad_state_ ? ", bad_state" : "") |
| 585 | + ")"; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 586 | PrintProperty("name", pass_desc.c_str()); |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 587 | if (disasm_info_ != nullptr) { |
| 588 | DumpDisassemblyBlockForFrameEntry(); |
| 589 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 590 | VisitInsertionOrder(); |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 591 | if (disasm_info_ != nullptr) { |
| 592 | DumpDisassemblyBlockForSlowPaths(); |
| 593 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 594 | EndTag("cfg"); |
| 595 | } |
| 596 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 597 | void VisitBasicBlock(HBasicBlock* block) OVERRIDE { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 598 | StartTag("block"); |
| 599 | PrintProperty("name", "B", block->GetBlockId()); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 600 | if (block->GetLifetimeStart() != kNoLifetime) { |
| 601 | // Piggy back on these fields to show the lifetime of the block. |
| 602 | PrintInt("from_bci", block->GetLifetimeStart()); |
| 603 | PrintInt("to_bci", block->GetLifetimeEnd()); |
| 604 | } else { |
| 605 | PrintInt("from_bci", -1); |
| 606 | PrintInt("to_bci", -1); |
| 607 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 608 | PrintPredecessors(block); |
| 609 | PrintSuccessors(block); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 610 | PrintExceptionHandlers(block); |
| 611 | |
| 612 | if (block->IsCatchBlock()) { |
| 613 | PrintProperty("flags", "catch_block"); |
| 614 | } else { |
| 615 | PrintEmptyProperty("flags"); |
| 616 | } |
| 617 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 618 | if (block->GetDominator() != nullptr) { |
| 619 | PrintProperty("dominator", "B", block->GetDominator()->GetBlockId()); |
| 620 | } |
| 621 | |
| 622 | StartTag("states"); |
| 623 | StartTag("locals"); |
| 624 | PrintInt("size", 0); |
| 625 | PrintProperty("method", "None"); |
| 626 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 627 | AddIndent(); |
| 628 | HInstruction* instruction = it.Current(); |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 629 | output_ << instruction->GetId() << " " << GetTypeId(instruction->GetType()) |
| 630 | << instruction->GetId() << "[ "; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 631 | for (HInputIterator inputs(instruction); !inputs.Done(); inputs.Advance()) { |
| 632 | output_ << inputs.Current()->GetId() << " "; |
| 633 | } |
| 634 | output_ << "]" << std::endl; |
| 635 | } |
| 636 | EndTag("locals"); |
| 637 | EndTag("states"); |
| 638 | |
| 639 | StartTag("HIR"); |
| 640 | PrintInstructions(block->GetPhis()); |
| 641 | PrintInstructions(block->GetInstructions()); |
| 642 | EndTag("HIR"); |
| 643 | EndTag("block"); |
| 644 | } |
| 645 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 646 | static constexpr const char* const kEndInstructionMarker = "<|@"; |
| 647 | static constexpr const char* const kDisassemblyBlockFrameEntry = "FrameEntry"; |
| 648 | static constexpr const char* const kDisassemblyBlockSlowPaths = "SlowPaths"; |
| 649 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 650 | private: |
| 651 | std::ostream& output_; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 652 | const char* pass_name_; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 653 | const bool is_after_pass_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 654 | const bool graph_in_bad_state_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 655 | const CodeGenerator& codegen_; |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 656 | const DisassemblyInformation* disasm_info_; |
| 657 | std::unique_ptr<HGraphVisualizerDisassembler> disassembler_; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 658 | size_t indent_; |
| 659 | |
| 660 | DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter); |
| 661 | }; |
| 662 | |
| 663 | HGraphVisualizer::HGraphVisualizer(std::ostream* output, |
| 664 | HGraph* graph, |
David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 665 | const CodeGenerator& codegen) |
| 666 | : output_(output), graph_(graph), codegen_(codegen) {} |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 667 | |
David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 668 | void HGraphVisualizer::PrintHeader(const char* method_name) const { |
| 669 | DCHECK(output_ != nullptr); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 670 | HGraphVisualizerPrinter printer(graph_, *output_, "", true, false, codegen_); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 671 | printer.StartTag("compilation"); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 672 | printer.PrintProperty("name", method_name); |
| 673 | printer.PrintProperty("method", method_name); |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 674 | printer.PrintTime("date"); |
| 675 | printer.EndTag("compilation"); |
| 676 | } |
| 677 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 678 | void HGraphVisualizer::DumpGraph(const char* pass_name, |
| 679 | bool is_after_pass, |
| 680 | bool graph_in_bad_state) const { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 681 | DCHECK(output_ != nullptr); |
| 682 | if (!graph_->GetBlocks().IsEmpty()) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 683 | HGraphVisualizerPrinter printer(graph_, |
| 684 | *output_, |
| 685 | pass_name, |
| 686 | is_after_pass, |
| 687 | graph_in_bad_state, |
| 688 | codegen_); |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 689 | printer.Run(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 690 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 691 | } |
| 692 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 693 | void HGraphVisualizer::DumpGraphWithDisassembly() const { |
| 694 | DCHECK(output_ != nullptr); |
| 695 | if (!graph_->GetBlocks().IsEmpty()) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 696 | HGraphVisualizerPrinter printer(graph_, |
| 697 | *output_, |
| 698 | "disassembly", |
| 699 | /* is_after_pass */ true, |
| 700 | /* graph_in_bad_state */ false, |
| 701 | codegen_, |
| 702 | codegen_.GetDisassemblyInformation()); |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 703 | printer.Run(); |
| 704 | } |
| 705 | } |
| 706 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 707 | } // namespace art |