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