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