| 1 | /* |
| 2 | * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef SHARE_OPTO_IDEALGRAPHPRINTER_HPP |
| 26 | #define SHARE_OPTO_IDEALGRAPHPRINTER_HPP |
| 27 | |
| 28 | #include "libadt/dict.hpp" |
| 29 | #include "libadt/vectset.hpp" |
| 30 | #include "utilities/growableArray.hpp" |
| 31 | #include "utilities/ostream.hpp" |
| 32 | #include "utilities/xmlstream.hpp" |
| 33 | |
| 34 | #ifndef PRODUCT |
| 35 | |
| 36 | class Compile; |
| 37 | class PhaseIFG; |
| 38 | class PhaseChaitin; |
| 39 | class Matcher; |
| 40 | class Node; |
| 41 | class InlineTree; |
| 42 | class ciMethod; |
| 43 | |
| 44 | class IdealGraphPrinter : public CHeapObj<mtCompiler> { |
| 45 | private: |
| 46 | |
| 47 | static const char *INDENT; |
| 48 | static const char *TOP_ELEMENT; |
| 49 | static const char *GROUP_ELEMENT; |
| 50 | static const char *GRAPH_ELEMENT; |
| 51 | static const char *PROPERTIES_ELEMENT; |
| 52 | static const char *EDGES_ELEMENT; |
| 53 | static const char *PROPERTY_ELEMENT; |
| 54 | static const char *EDGE_ELEMENT; |
| 55 | static const char *NODE_ELEMENT; |
| 56 | static const char *NODES_ELEMENT; |
| 57 | static const char *CONTROL_FLOW_ELEMENT; |
| 58 | static const char *REMOVE_EDGE_ELEMENT; |
| 59 | static const char *REMOVE_NODE_ELEMENT; |
| 60 | static const char *METHOD_NAME_PROPERTY; |
| 61 | static const char *BLOCK_NAME_PROPERTY; |
| 62 | static const char *BLOCK_DOMINATOR_PROPERTY; |
| 63 | static const char *BLOCK_ELEMENT; |
| 64 | static const char *SUCCESSORS_ELEMENT; |
| 65 | static const char *SUCCESSOR_ELEMENT; |
| 66 | static const char *METHOD_IS_PUBLIC_PROPERTY; |
| 67 | static const char *METHOD_IS_STATIC_PROPERTY; |
| 68 | static const char *TRUE_VALUE; |
| 69 | static const char *NODE_NAME_PROPERTY; |
| 70 | static const char *EDGE_NAME_PROPERTY; |
| 71 | static const char *NODE_ID_PROPERTY; |
| 72 | static const char *FROM_PROPERTY; |
| 73 | static const char *TO_PROPERTY; |
| 74 | static const char *PROPERTY_NAME_PROPERTY; |
| 75 | static const char *GRAPH_NAME_PROPERTY; |
| 76 | static const char *INDEX_PROPERTY; |
| 77 | static const char *METHOD_ELEMENT; |
| 78 | static const char *INLINE_ELEMENT; |
| 79 | static const char *BYTECODES_ELEMENT; |
| 80 | static const char *METHOD_BCI_PROPERTY; |
| 81 | static const char *METHOD_SHORT_NAME_PROPERTY; |
| 82 | static const char *ASSEMBLY_ELEMENT; |
| 83 | |
| 84 | static int _file_count; |
| 85 | networkStream *_stream; |
| 86 | xmlStream *_xml; |
| 87 | outputStream *_output; |
| 88 | ciMethod *_current_method; |
| 89 | int _depth; |
| 90 | char buffer[128]; |
| 91 | bool _should_send_method; |
| 92 | PhaseChaitin* _chaitin; |
| 93 | bool _traverse_outs; |
| 94 | Compile *C; |
| 95 | |
| 96 | void print_method(ciMethod *method, int bci, InlineTree *tree); |
| 97 | void print_inline_tree(InlineTree *tree); |
| 98 | void visit_node(Node *n, bool edges, VectorSet* temp_set); |
| 99 | void walk_nodes(Node *start, bool edges, VectorSet* temp_set); |
| 100 | void begin_elem(const char *s); |
| 101 | void end_elem(); |
| 102 | void begin_head(const char *s); |
| 103 | void end_head(); |
| 104 | void print_attr(const char *name, const char *val); |
| 105 | void print_attr(const char *name, intptr_t val); |
| 106 | void print_prop(const char *name, const char *val); |
| 107 | void print_prop(const char *name, int val); |
| 108 | void tail(const char *name); |
| 109 | void head(const char *name); |
| 110 | void text(const char *s); |
| 111 | IdealGraphPrinter(); |
| 112 | ~IdealGraphPrinter(); |
| 113 | |
| 114 | public: |
| 115 | |
| 116 | static void clean_up(); |
| 117 | static IdealGraphPrinter *printer(); |
| 118 | |
| 119 | bool traverse_outs(); |
| 120 | void set_traverse_outs(bool b); |
| 121 | void print_inlining(); |
| 122 | void begin_method(); |
| 123 | void end_method(); |
| 124 | void print_method(const char *name, int level = 0); |
| 125 | void print(const char *name, Node *root); |
| 126 | bool should_print(int level); |
| 127 | void set_compile(Compile* compile) {C = compile; } |
| 128 | }; |
| 129 | |
| 130 | #endif |
| 131 | |
| 132 | #endif // SHARE_OPTO_IDEALGRAPHPRINTER_HPP |
| 133 | |