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 | */ |
| 155 | class HGraphVisualizerPrinter : public HGraphVisitor { |
| 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, |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 161 | const CodeGenerator& codegen, |
| 162 | const DisassemblyInformation* disasm_info = nullptr) |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 163 | : HGraphVisitor(graph), |
| 164 | output_(output), |
| 165 | pass_name_(pass_name), |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 166 | is_after_pass_(is_after_pass), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 167 | codegen_(codegen), |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 168 | disasm_info_(disasm_info), |
| 169 | disassembler_(disasm_info_ != nullptr |
| 170 | ? new HGraphVisualizerDisassembler( |
| 171 | codegen_.GetInstructionSet(), |
| 172 | codegen_.GetAssembler().CodeBufferBaseAddress()) |
| 173 | : nullptr), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 174 | indent_(0) {} |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 175 | |
| 176 | void StartTag(const char* name) { |
| 177 | AddIndent(); |
| 178 | output_ << "begin_" << name << std::endl; |
| 179 | indent_++; |
| 180 | } |
| 181 | |
| 182 | void EndTag(const char* name) { |
| 183 | indent_--; |
| 184 | AddIndent(); |
| 185 | output_ << "end_" << name << std::endl; |
| 186 | } |
| 187 | |
| 188 | void PrintProperty(const char* name, const char* property) { |
| 189 | AddIndent(); |
| 190 | output_ << name << " \"" << property << "\"" << std::endl; |
| 191 | } |
| 192 | |
| 193 | void PrintProperty(const char* name, const char* property, int id) { |
| 194 | AddIndent(); |
| 195 | output_ << name << " \"" << property << id << "\"" << std::endl; |
| 196 | } |
| 197 | |
| 198 | void PrintEmptyProperty(const char* name) { |
| 199 | AddIndent(); |
| 200 | output_ << name << std::endl; |
| 201 | } |
| 202 | |
| 203 | void PrintTime(const char* name) { |
| 204 | AddIndent(); |
Jean Christophe Beyler | 0ada95d | 2014-12-04 11:20:20 -0800 | [diff] [blame] | 205 | output_ << name << " " << time(nullptr) << std::endl; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void PrintInt(const char* name, int value) { |
| 209 | AddIndent(); |
| 210 | output_ << name << " " << value << std::endl; |
| 211 | } |
| 212 | |
| 213 | void AddIndent() { |
| 214 | for (size_t i = 0; i < indent_; ++i) { |
| 215 | output_ << " "; |
| 216 | } |
| 217 | } |
| 218 | |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 219 | char GetTypeId(Primitive::Type type) { |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 220 | // Note that Primitive::Descriptor would not work for us |
| 221 | // because it does not handle reference types (that is kPrimNot). |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 222 | switch (type) { |
| 223 | case Primitive::kPrimBoolean: return 'z'; |
| 224 | case Primitive::kPrimByte: return 'b'; |
| 225 | case Primitive::kPrimChar: return 'c'; |
| 226 | case Primitive::kPrimShort: return 's'; |
| 227 | case Primitive::kPrimInt: return 'i'; |
| 228 | case Primitive::kPrimLong: return 'j'; |
| 229 | case Primitive::kPrimFloat: return 'f'; |
| 230 | case Primitive::kPrimDouble: return 'd'; |
| 231 | case Primitive::kPrimNot: return 'l'; |
| 232 | case Primitive::kPrimVoid: return 'v'; |
| 233 | } |
| 234 | LOG(FATAL) << "Unreachable"; |
| 235 | return 'v'; |
| 236 | } |
| 237 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 238 | void PrintPredecessors(HBasicBlock* block) { |
| 239 | AddIndent(); |
| 240 | output_ << "predecessors"; |
| 241 | for (size_t i = 0, e = block->GetPredecessors().Size(); i < e; ++i) { |
| 242 | HBasicBlock* predecessor = block->GetPredecessors().Get(i); |
| 243 | output_ << " \"B" << predecessor->GetBlockId() << "\" "; |
| 244 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 245 | if (block->IsEntryBlock() && (disasm_info_ != nullptr)) { |
| 246 | output_ << " \"" << kDisassemblyBlockFrameEntry << "\" "; |
| 247 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 248 | output_<< std::endl; |
| 249 | } |
| 250 | |
| 251 | void PrintSuccessors(HBasicBlock* block) { |
| 252 | AddIndent(); |
| 253 | output_ << "successors"; |
| 254 | for (size_t i = 0, e = block->GetSuccessors().Size(); i < e; ++i) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 255 | if (!block->IsExceptionalSuccessor(i)) { |
| 256 | HBasicBlock* successor = block->GetSuccessors().Get(i); |
| 257 | output_ << " \"B" << successor->GetBlockId() << "\" "; |
| 258 | } |
| 259 | } |
| 260 | output_<< std::endl; |
| 261 | } |
| 262 | |
| 263 | void PrintExceptionHandlers(HBasicBlock* block) { |
| 264 | AddIndent(); |
| 265 | output_ << "xhandlers"; |
| 266 | for (size_t i = 0, e = block->GetSuccessors().Size(); i < e; ++i) { |
| 267 | if (block->IsExceptionalSuccessor(i)) { |
| 268 | HBasicBlock* handler = block->GetSuccessors().Get(i); |
| 269 | output_ << " \"B" << handler->GetBlockId() << "\" "; |
| 270 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 271 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 272 | if (block->IsExitBlock() && |
| 273 | (disasm_info_ != nullptr) && |
| 274 | !disasm_info_->GetSlowPathIntervals().empty()) { |
| 275 | output_ << " \"" << kDisassemblyBlockSlowPaths << "\" "; |
| 276 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 277 | output_<< std::endl; |
| 278 | } |
| 279 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 280 | void DumpLocation(std::ostream& stream, const Location& location) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 281 | if (location.IsRegister()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 282 | codegen_.DumpCoreRegister(stream, location.reg()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 283 | } else if (location.IsFpuRegister()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 284 | codegen_.DumpFloatingPointRegister(stream, location.reg()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 285 | } else if (location.IsConstant()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 286 | stream << "#"; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 287 | HConstant* constant = location.GetConstant(); |
| 288 | if (constant->IsIntConstant()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 289 | stream << constant->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 290 | } else if (constant->IsLongConstant()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 291 | stream << constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 292 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 293 | } else if (location.IsInvalid()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 294 | stream << "invalid"; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 295 | } else if (location.IsStackSlot()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 296 | stream << location.GetStackIndex() << "(sp)"; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 297 | } else if (location.IsFpuRegisterPair()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 298 | codegen_.DumpFloatingPointRegister(stream, location.low()); |
| 299 | stream << "|"; |
| 300 | codegen_.DumpFloatingPointRegister(stream, location.high()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 301 | } else if (location.IsRegisterPair()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 302 | codegen_.DumpCoreRegister(stream, location.low()); |
| 303 | stream << "|"; |
| 304 | codegen_.DumpCoreRegister(stream, location.high()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 305 | } else if (location.IsUnallocated()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 306 | stream << "unallocated"; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 307 | } else { |
| 308 | DCHECK(location.IsDoubleStackSlot()); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 309 | stream << "2x" << location.GetStackIndex() << "(sp)"; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 313 | std::ostream& StartAttributeStream(const char* name = nullptr) { |
| 314 | if (name == nullptr) { |
| 315 | output_ << " "; |
| 316 | } else { |
| 317 | DCHECK(!HasWhitespace(name)) << "Checker does not allow spaces in attributes"; |
| 318 | output_ << " " << name << ":"; |
| 319 | } |
| 320 | return output_; |
| 321 | } |
| 322 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 323 | void VisitParallelMove(HParallelMove* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 324 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
| 325 | StringList moves; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 326 | for (size_t i = 0, e = instruction->NumMoves(); i < e; ++i) { |
| 327 | MoveOperands* move = instruction->MoveOperandsAt(i); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 328 | std::ostream& str = moves.NewEntryStream(); |
| 329 | DumpLocation(str, move->GetSource()); |
| 330 | str << "->"; |
| 331 | DumpLocation(str, move->GetDestination()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 332 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 333 | StartAttributeStream("moves") << moves; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 334 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 335 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 336 | void VisitIntConstant(HIntConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 337 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 338 | } |
| 339 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 340 | void VisitLongConstant(HLongConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 341 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 342 | } |
| 343 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 344 | void VisitFloatConstant(HFloatConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 345 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 346 | } |
| 347 | |
David Brazdil | 36cf095 | 2015-01-08 19:28:33 +0000 | [diff] [blame] | 348 | void VisitDoubleConstant(HDoubleConstant* instruction) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 349 | StartAttributeStream() << instruction->GetValue(); |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 352 | void VisitPhi(HPhi* phi) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 353 | StartAttributeStream("reg") << phi->GetRegNumber(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 356 | void VisitMemoryBarrier(HMemoryBarrier* barrier) OVERRIDE { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 357 | StartAttributeStream("kind") << barrier->GetBarrierKind(); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 360 | void VisitLoadClass(HLoadClass* load_class) OVERRIDE { |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 361 | StartAttributeStream("gen_clinit_check") << std::boolalpha |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | << load_class->MustGenerateClinitCheck() << std::noboolalpha; |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 363 | } |
| 364 | |
Guillaume "Vermeille" Sanchez | 9099ef7 | 2015-05-20 15:19:21 +0100 | [diff] [blame] | 365 | void VisitCheckCast(HCheckCast* check_cast) OVERRIDE { |
| 366 | StartAttributeStream("must_do_null_check") << std::boolalpha |
| 367 | << check_cast->MustDoNullCheck() << std::noboolalpha; |
| 368 | } |
| 369 | |
| 370 | void VisitInstanceOf(HInstanceOf* instance_of) OVERRIDE { |
| 371 | StartAttributeStream("must_do_null_check") << std::boolalpha |
| 372 | << instance_of->MustDoNullCheck() << std::noboolalpha; |
| 373 | } |
| 374 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 375 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE { |
| 376 | StartAttributeStream("dex_file_index") << invoke->GetDexMethodIndex(); |
| 377 | StartAttributeStream("recursive") << std::boolalpha |
| 378 | << invoke->IsRecursive() |
| 379 | << std::noboolalpha; |
| 380 | } |
| 381 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 382 | void VisitTryBoundary(HTryBoundary* try_boundary) OVERRIDE { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame^] | 383 | StartAttributeStream("kind") << (try_boundary->IsEntry() ? "entry" : "exit"); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 386 | bool IsPass(const char* name) { |
| 387 | return strcmp(pass_name_, name) == 0; |
| 388 | } |
| 389 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 390 | void PrintInstruction(HInstruction* instruction) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 391 | output_ << instruction->DebugName(); |
| 392 | if (instruction->InputCount() > 0) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 393 | StringList inputs; |
| 394 | for (HInputIterator it(instruction); !it.Done(); it.Advance()) { |
| 395 | inputs.NewEntryStream() << GetTypeId(it.Current()->GetType()) << it.Current()->GetId(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 396 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 397 | StartAttributeStream() << inputs; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 398 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 399 | instruction->Accept(this); |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 400 | if (instruction->HasEnvironment()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 401 | StringList envs; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 402 | for (HEnvironment* environment = instruction->GetEnvironment(); |
| 403 | environment != nullptr; |
| 404 | environment = environment->GetParent()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 405 | StringList vregs; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 406 | for (size_t i = 0, e = environment->Size(); i < e; ++i) { |
| 407 | HInstruction* insn = environment->GetInstructionAt(i); |
| 408 | if (insn != nullptr) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 409 | vregs.NewEntryStream() << GetTypeId(insn->GetType()) << insn->GetId(); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 410 | } else { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 411 | vregs.NewEntryStream() << "_"; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 412 | } |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 413 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 414 | envs.NewEntryStream() << vregs; |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 415 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 416 | StartAttributeStream("env") << envs; |
Zheng Xu | bb7a28a | 2015-01-09 14:40:47 +0800 | [diff] [blame] | 417 | } |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 418 | if (IsPass(SsaLivenessAnalysis::kLivenessPassName) |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 419 | && is_after_pass_ |
| 420 | && instruction->GetLifetimePosition() != kNoLifetime) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 421 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 422 | if (instruction->HasLiveInterval()) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 423 | LiveInterval* interval = instruction->GetLiveInterval(); |
David Brazdil | c7a2485 | 2015-05-15 16:44:05 +0100 | [diff] [blame] | 424 | StartAttributeStream("ranges") |
| 425 | << StringList(interval->GetFirstRange(), StringList::kSetBrackets); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 426 | StartAttributeStream("uses") << StringList(interval->GetFirstUse()); |
| 427 | StartAttributeStream("env_uses") << StringList(interval->GetFirstEnvironmentUse()); |
| 428 | StartAttributeStream("is_fixed") << interval->IsFixed(); |
| 429 | StartAttributeStream("is_split") << interval->IsSplit(); |
| 430 | StartAttributeStream("is_low") << interval->IsLowInterval(); |
| 431 | StartAttributeStream("is_high") << interval->IsHighInterval(); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 432 | } |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 433 | } else if (IsPass(RegisterAllocator::kRegisterAllocatorPassName) && is_after_pass_) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 434 | StartAttributeStream("liveness") << instruction->GetLifetimePosition(); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 435 | LocationSummary* locations = instruction->GetLocations(); |
| 436 | if (locations != nullptr) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 437 | StringList inputs; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 438 | for (size_t i = 0; i < instruction->InputCount(); ++i) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 439 | DumpLocation(inputs.NewEntryStream(), locations->InAt(i)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 440 | } |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 441 | std::ostream& attr = StartAttributeStream("locations"); |
| 442 | attr << inputs << "->"; |
| 443 | DumpLocation(attr, locations->Out()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 444 | } |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 445 | } else if (IsPass(LICM::kLoopInvariantCodeMotionPassName) |
| 446 | || IsPass(HDeadCodeElimination::kFinalDeadCodeEliminationPassName)) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 447 | HLoopInformation* info = instruction->GetBlock()->GetLoopInformation(); |
| 448 | if (info == nullptr) { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 449 | StartAttributeStream("loop") << "none"; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 450 | } else { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 451 | StartAttributeStream("loop") << "B" << info->GetHeader()->GetBlockId(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 452 | } |
Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 453 | } else if (IsPass(ReferenceTypePropagation::kReferenceTypePropagationPassName) |
| 454 | && is_after_pass_) { |
| 455 | if (instruction->GetType() == Primitive::kPrimNot) { |
| 456 | if (instruction->IsLoadClass()) { |
Nicolas Geoffray | 66389fb | 2015-06-19 10:35:42 +0100 | [diff] [blame] | 457 | ReferenceTypeInfo info = instruction->AsLoadClass()->GetLoadedClassRTI(); |
Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 458 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 66389fb | 2015-06-19 10:35:42 +0100 | [diff] [blame] | 459 | if (info.GetTypeHandle().GetReference() != nullptr) { |
Nicolas Geoffray | f9a1995 | 2015-06-29 13:43:54 +0100 | [diff] [blame] | 460 | StartAttributeStream("klass") << PrettyClass(info.GetTypeHandle().Get()); |
Nicolas Geoffray | 66389fb | 2015-06-19 10:35:42 +0100 | [diff] [blame] | 461 | } else { |
| 462 | StartAttributeStream("klass") << "unresolved"; |
| 463 | } |
Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 464 | } else { |
| 465 | ReferenceTypeInfo info = instruction->GetReferenceTypeInfo(); |
| 466 | if (info.IsTop()) { |
| 467 | StartAttributeStream("klass") << "java.lang.Object"; |
| 468 | } else { |
| 469 | ScopedObjectAccess soa(Thread::Current()); |
| 470 | StartAttributeStream("klass") << PrettyClass(info.GetTypeHandle().Get()); |
| 471 | } |
| 472 | StartAttributeStream("exact") << std::boolalpha << info.IsExact() << std::noboolalpha; |
| 473 | } |
| 474 | } |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 475 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 476 | if (disasm_info_ != nullptr) { |
| 477 | DCHECK(disassembler_ != nullptr); |
| 478 | // If the information is available, disassemble the code generated for |
| 479 | // this instruction. |
| 480 | auto it = disasm_info_->GetInstructionIntervals().find(instruction); |
| 481 | if (it != disasm_info_->GetInstructionIntervals().end() |
| 482 | && it->second.start != it->second.end) { |
| 483 | output_ << std::endl; |
| 484 | disassembler_->Disassemble(output_, it->second.start, it->second.end); |
| 485 | } |
| 486 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | void PrintInstructions(const HInstructionList& list) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 490 | for (HInstructionIterator it(list); !it.Done(); it.Advance()) { |
| 491 | HInstruction* instruction = it.Current(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 492 | int bci = 0; |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 493 | size_t num_uses = 0; |
| 494 | for (HUseIterator<HInstruction*> use_it(instruction->GetUses()); |
| 495 | !use_it.Done(); |
| 496 | use_it.Advance()) { |
| 497 | ++num_uses; |
| 498 | } |
| 499 | AddIndent(); |
| 500 | output_ << bci << " " << num_uses << " " |
| 501 | << GetTypeId(instruction->GetType()) << instruction->GetId() << " "; |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 502 | PrintInstruction(instruction); |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 503 | output_ << " " << kEndInstructionMarker << std::endl; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 507 | void DumpStartOfDisassemblyBlock(const char* block_name, |
| 508 | int predecessor_index, |
| 509 | int successor_index) { |
| 510 | StartTag("block"); |
| 511 | PrintProperty("name", block_name); |
| 512 | PrintInt("from_bci", -1); |
| 513 | PrintInt("to_bci", -1); |
| 514 | if (predecessor_index != -1) { |
| 515 | PrintProperty("predecessors", "B", predecessor_index); |
| 516 | } else { |
| 517 | PrintEmptyProperty("predecessors"); |
| 518 | } |
| 519 | if (successor_index != -1) { |
| 520 | PrintProperty("successors", "B", successor_index); |
| 521 | } else { |
| 522 | PrintEmptyProperty("successors"); |
| 523 | } |
| 524 | PrintEmptyProperty("xhandlers"); |
| 525 | PrintEmptyProperty("flags"); |
| 526 | StartTag("states"); |
| 527 | StartTag("locals"); |
| 528 | PrintInt("size", 0); |
| 529 | PrintProperty("method", "None"); |
| 530 | EndTag("locals"); |
| 531 | EndTag("states"); |
| 532 | StartTag("HIR"); |
| 533 | } |
| 534 | |
| 535 | void DumpEndOfDisassemblyBlock() { |
| 536 | EndTag("HIR"); |
| 537 | EndTag("block"); |
| 538 | } |
| 539 | |
| 540 | void DumpDisassemblyBlockForFrameEntry() { |
| 541 | DumpStartOfDisassemblyBlock(kDisassemblyBlockFrameEntry, |
| 542 | -1, |
| 543 | GetGraph()->GetEntryBlock()->GetBlockId()); |
| 544 | output_ << " 0 0 disasm " << kDisassemblyBlockFrameEntry << " "; |
| 545 | GeneratedCodeInterval frame_entry = disasm_info_->GetFrameEntryInterval(); |
| 546 | if (frame_entry.start != frame_entry.end) { |
| 547 | output_ << std::endl; |
| 548 | disassembler_->Disassemble(output_, frame_entry.start, frame_entry.end); |
| 549 | } |
| 550 | output_ << kEndInstructionMarker << std::endl; |
| 551 | DumpEndOfDisassemblyBlock(); |
| 552 | } |
| 553 | |
| 554 | void DumpDisassemblyBlockForSlowPaths() { |
| 555 | if (disasm_info_->GetSlowPathIntervals().empty()) { |
| 556 | return; |
| 557 | } |
| 558 | // If the graph has an exit block we attach the block for the slow paths |
| 559 | // after it. Else we just add the block to the graph without linking it to |
| 560 | // any other. |
| 561 | DumpStartOfDisassemblyBlock( |
| 562 | kDisassemblyBlockSlowPaths, |
| 563 | GetGraph()->HasExitBlock() ? GetGraph()->GetExitBlock()->GetBlockId() : -1, |
| 564 | -1); |
| 565 | for (SlowPathCodeInfo info : disasm_info_->GetSlowPathIntervals()) { |
| 566 | output_ << " 0 0 disasm " << info.slow_path->GetDescription() << std::endl; |
| 567 | disassembler_->Disassemble(output_, info.code_interval.start, info.code_interval.end); |
| 568 | output_ << kEndInstructionMarker << std::endl; |
| 569 | } |
| 570 | DumpEndOfDisassemblyBlock(); |
| 571 | } |
| 572 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 573 | void Run() { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 574 | StartTag("cfg"); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 575 | std::string pass_desc = std::string(pass_name_) + (is_after_pass_ ? " (after)" : " (before)"); |
| 576 | PrintProperty("name", pass_desc.c_str()); |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 577 | if (disasm_info_ != nullptr) { |
| 578 | DumpDisassemblyBlockForFrameEntry(); |
| 579 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 580 | VisitInsertionOrder(); |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 581 | if (disasm_info_ != nullptr) { |
| 582 | DumpDisassemblyBlockForSlowPaths(); |
| 583 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 584 | EndTag("cfg"); |
| 585 | } |
| 586 | |
David Brazdil | b7e4a06 | 2014-12-29 15:35:02 +0000 | [diff] [blame] | 587 | void VisitBasicBlock(HBasicBlock* block) OVERRIDE { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 588 | StartTag("block"); |
| 589 | PrintProperty("name", "B", block->GetBlockId()); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 590 | if (block->GetLifetimeStart() != kNoLifetime) { |
| 591 | // Piggy back on these fields to show the lifetime of the block. |
| 592 | PrintInt("from_bci", block->GetLifetimeStart()); |
| 593 | PrintInt("to_bci", block->GetLifetimeEnd()); |
| 594 | } else { |
| 595 | PrintInt("from_bci", -1); |
| 596 | PrintInt("to_bci", -1); |
| 597 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 598 | PrintPredecessors(block); |
| 599 | PrintSuccessors(block); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 600 | PrintExceptionHandlers(block); |
| 601 | |
| 602 | if (block->IsCatchBlock()) { |
| 603 | PrintProperty("flags", "catch_block"); |
| 604 | } else { |
| 605 | PrintEmptyProperty("flags"); |
| 606 | } |
| 607 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 608 | if (block->GetDominator() != nullptr) { |
| 609 | PrintProperty("dominator", "B", block->GetDominator()->GetBlockId()); |
| 610 | } |
| 611 | |
| 612 | StartTag("states"); |
| 613 | StartTag("locals"); |
| 614 | PrintInt("size", 0); |
| 615 | PrintProperty("method", "None"); |
| 616 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 617 | AddIndent(); |
| 618 | HInstruction* instruction = it.Current(); |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 619 | output_ << instruction->GetId() << " " << GetTypeId(instruction->GetType()) |
| 620 | << instruction->GetId() << "[ "; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 621 | for (HInputIterator inputs(instruction); !inputs.Done(); inputs.Advance()) { |
| 622 | output_ << inputs.Current()->GetId() << " "; |
| 623 | } |
| 624 | output_ << "]" << std::endl; |
| 625 | } |
| 626 | EndTag("locals"); |
| 627 | EndTag("states"); |
| 628 | |
| 629 | StartTag("HIR"); |
| 630 | PrintInstructions(block->GetPhis()); |
| 631 | PrintInstructions(block->GetInstructions()); |
| 632 | EndTag("HIR"); |
| 633 | EndTag("block"); |
| 634 | } |
| 635 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 636 | static constexpr const char* const kEndInstructionMarker = "<|@"; |
| 637 | static constexpr const char* const kDisassemblyBlockFrameEntry = "FrameEntry"; |
| 638 | static constexpr const char* const kDisassemblyBlockSlowPaths = "SlowPaths"; |
| 639 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 640 | private: |
| 641 | std::ostream& output_; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 642 | const char* pass_name_; |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 643 | const bool is_after_pass_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 644 | const CodeGenerator& codegen_; |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 645 | const DisassemblyInformation* disasm_info_; |
| 646 | std::unique_ptr<HGraphVisualizerDisassembler> disassembler_; |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 647 | size_t indent_; |
| 648 | |
| 649 | DISALLOW_COPY_AND_ASSIGN(HGraphVisualizerPrinter); |
| 650 | }; |
| 651 | |
| 652 | HGraphVisualizer::HGraphVisualizer(std::ostream* output, |
| 653 | HGraph* graph, |
David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 654 | const CodeGenerator& codegen) |
| 655 | : output_(output), graph_(graph), codegen_(codegen) {} |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 656 | |
David Brazdil | 62e074f | 2015-04-07 18:09:37 +0100 | [diff] [blame] | 657 | void HGraphVisualizer::PrintHeader(const char* method_name) const { |
| 658 | DCHECK(output_ != nullptr); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 659 | HGraphVisualizerPrinter printer(graph_, *output_, "", true, codegen_); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 660 | printer.StartTag("compilation"); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 661 | printer.PrintProperty("name", method_name); |
| 662 | printer.PrintProperty("method", method_name); |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 663 | printer.PrintTime("date"); |
| 664 | printer.EndTag("compilation"); |
| 665 | } |
| 666 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 667 | void HGraphVisualizer::DumpGraph(const char* pass_name, bool is_after_pass) const { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 668 | DCHECK(output_ != nullptr); |
| 669 | if (!graph_->GetBlocks().IsEmpty()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 670 | HGraphVisualizerPrinter printer(graph_, *output_, pass_name, is_after_pass, codegen_); |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 671 | printer.Run(); |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 672 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 673 | } |
| 674 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 675 | void HGraphVisualizer::DumpGraphWithDisassembly() const { |
| 676 | DCHECK(output_ != nullptr); |
| 677 | if (!graph_->GetBlocks().IsEmpty()) { |
| 678 | HGraphVisualizerPrinter printer( |
| 679 | graph_, *output_, "disassembly", true, codegen_, codegen_.GetDisassemblyInformation()); |
| 680 | printer.Run(); |
| 681 | } |
| 682 | } |
| 683 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 684 | } // namespace art |