1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/idealGraphPrinter.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,323 @@ 1.4 +/* 1.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef PRODUCT 1.29 + 1.30 +class Compile; 1.31 +class PhaseIFG; 1.32 +class PhaseChaitin; 1.33 +class Matcher; 1.34 +class Node; 1.35 +class InlineTree; 1.36 +class ciMethod; 1.37 + 1.38 +class IdealGraphPrinter 1.39 +{ 1.40 +private: 1.41 + 1.42 + enum State 1.43 + { 1.44 + Invalid, 1.45 + Valid, 1.46 + New 1.47 + }; 1.48 + 1.49 +private: 1.50 + 1.51 + static const char *INDENT; 1.52 + static const char *TOP_ELEMENT; 1.53 + static const char *GROUP_ELEMENT; 1.54 + static const char *GRAPH_ELEMENT; 1.55 + static const char *PROPERTIES_ELEMENT; 1.56 + static const char *EDGES_ELEMENT; 1.57 + static const char *PROPERTY_ELEMENT; 1.58 + static const char *EDGE_ELEMENT; 1.59 + static const char *NODE_ELEMENT; 1.60 + static const char *NODES_ELEMENT; 1.61 + static const char *CONTROL_FLOW_ELEMENT; 1.62 + static const char *REMOVE_EDGE_ELEMENT; 1.63 + static const char *REMOVE_NODE_ELEMENT; 1.64 + static const char *METHOD_NAME_PROPERTY; 1.65 + static const char *BLOCK_NAME_PROPERTY; 1.66 + static const char *BLOCK_DOMINATOR_PROPERTY; 1.67 + static const char *BLOCK_ELEMENT; 1.68 + static const char *SUCCESSORS_ELEMENT; 1.69 + static const char *SUCCESSOR_ELEMENT; 1.70 + static const char *METHOD_IS_PUBLIC_PROPERTY; 1.71 + static const char *METHOD_IS_STATIC_PROPERTY; 1.72 + static const char *TRUE_VALUE; 1.73 + static const char *NODE_NAME_PROPERTY; 1.74 + static const char *EDGE_NAME_PROPERTY; 1.75 + static const char *NODE_ID_PROPERTY; 1.76 + static const char *FROM_PROPERTY; 1.77 + static const char *TO_PROPERTY; 1.78 + static const char *PROPERTY_NAME_PROPERTY; 1.79 + static const char *GRAPH_NAME_PROPERTY; 1.80 + static const char *INDEX_PROPERTY; 1.81 + static const char *METHOD_ELEMENT; 1.82 + static const char *INLINE_ELEMENT; 1.83 + static const char *BYTECODES_ELEMENT; 1.84 + static const char *METHOD_BCI_PROPERTY; 1.85 + static const char *METHOD_SHORT_NAME_PROPERTY; 1.86 + static const char *ASSEMBLY_ELEMENT; 1.87 + 1.88 + class Property { 1.89 + 1.90 + private: 1.91 + 1.92 + const char *_name; 1.93 + const char *_value; 1.94 + 1.95 + public: 1.96 + 1.97 + Property(); 1.98 + Property(const Property* p); 1.99 + ~Property(); 1.100 + Property(const char *name, const char *value); 1.101 + Property(const char *name, int value); 1.102 + bool equals(Property* p); 1.103 + void print(IdealGraphPrinter *printer); 1.104 + void print_as_attribute(IdealGraphPrinter *printer); 1.105 + bool is_null(); 1.106 + void clean(); 1.107 + const char *name(); 1.108 + 1.109 + static const char* dup(const char *str) { 1.110 + char * copy = new char[strlen(str)+1]; 1.111 + strcpy(copy, str); 1.112 + return copy; 1.113 + } 1.114 + 1.115 + }; 1.116 + 1.117 + class Properties { 1.118 + 1.119 + private: 1.120 + 1.121 + GrowableArray<Property *> *list; 1.122 + 1.123 + public: 1.124 + 1.125 + Properties(); 1.126 + ~Properties(); 1.127 + void add(Property *p); 1.128 + void remove(const char *name); 1.129 + bool equals(Properties* p); 1.130 + void print(IdealGraphPrinter *printer); 1.131 + void print_as_attributes(IdealGraphPrinter *printer); 1.132 + void clean(); 1.133 + 1.134 + }; 1.135 + 1.136 + 1.137 + class Description { 1.138 + 1.139 + private: 1.140 + 1.141 + State _state; 1.142 + 1.143 + public: 1.144 + 1.145 + Description(); 1.146 + 1.147 + State state(); 1.148 + void set_state(State s); 1.149 + void print(IdealGraphPrinter *printer); 1.150 + virtual void print_changed(IdealGraphPrinter *printer) = 0; 1.151 + virtual void print_removed(IdealGraphPrinter *printer) = 0; 1.152 + 1.153 + }; 1.154 + 1.155 + class NodeDescription : public Description{ 1.156 + 1.157 + public: 1.158 + 1.159 + static int count; 1.160 + 1.161 + private: 1.162 + 1.163 + GrowableArray<NodeDescription *> _succs; 1.164 + int _block_index; 1.165 + uintptr_t _id; 1.166 + Properties _properties; 1.167 + Node* _node; 1.168 + 1.169 + public: 1.170 + 1.171 + NodeDescription(Node* node); 1.172 + ~NodeDescription(); 1.173 + Node* node(); 1.174 + 1.175 + // void set_node(Node* node); 1.176 + GrowableArray<NodeDescription *>* succs(); 1.177 + void init_succs(); 1.178 + void clear_succs(); 1.179 + void add_succ(NodeDescription *desc); 1.180 + int block_index(); 1.181 + void set_block_index(int i); 1.182 + Properties* properties(); 1.183 + virtual void print_changed(IdealGraphPrinter *printer); 1.184 + virtual void print_removed(IdealGraphPrinter *printer); 1.185 + bool equals(NodeDescription *desc); 1.186 + uint id(); 1.187 + 1.188 + }; 1.189 + 1.190 + class Block { 1.191 + 1.192 + private: 1.193 + 1.194 + NodeDescription *_start; 1.195 + NodeDescription *_proj; 1.196 + GrowableArray<int> _succs; 1.197 + GrowableArray<NodeDescription *> _nodes; 1.198 + GrowableArray<int> _dominates; 1.199 + GrowableArray<int> _children; 1.200 + int _semi; 1.201 + int _parent; 1.202 + GrowableArray<int> _pred; 1.203 + GrowableArray<int> _bucket; 1.204 + int _index; 1.205 + int _dominator; 1.206 + int _ancestor; 1.207 + int _label; 1.208 + 1.209 + public: 1.210 + 1.211 + Block(); 1.212 + Block(int index); 1.213 + 1.214 + void add_node(NodeDescription *n); 1.215 + GrowableArray<NodeDescription *>* nodes(); 1.216 + GrowableArray<int>* children(); 1.217 + void add_child(int i); 1.218 + void add_succ(int index); 1.219 + GrowableArray<int>* succs(); 1.220 + GrowableArray<int>* dominates(); 1.221 + void add_dominates(int i); 1.222 + NodeDescription *start(); 1.223 + NodeDescription *proj(); 1.224 + void set_start(NodeDescription *n); 1.225 + void set_proj(NodeDescription *n); 1.226 + 1.227 + int label(); 1.228 + void set_label(int i); 1.229 + int ancestor(); 1.230 + void set_ancestor(int i); 1.231 + int index(); 1.232 + int dominator(); 1.233 + void set_dominator(int i); 1.234 + int parent(); 1.235 + void set_parent(int i); 1.236 + int semi(); 1.237 + GrowableArray<int>* bucket(); 1.238 + void add_to_bucket(int i); 1.239 + void clear_bucket(); 1.240 + GrowableArray<int>* pred(); 1.241 + void set_semi(int i); 1.242 + void add_pred(int i); 1.243 + 1.244 + }; 1.245 + 1.246 + class EdgeDescription : public Description { 1.247 + 1.248 + private: 1.249 + 1.250 + int _from; 1.251 + int _to; 1.252 + int _index; 1.253 + public: 1.254 + 1.255 + EdgeDescription(int from, int to, int index); 1.256 + ~EdgeDescription(); 1.257 + 1.258 + virtual void print_changed(IdealGraphPrinter *printer); 1.259 + virtual void print_removed(IdealGraphPrinter *printer); 1.260 + bool equals(EdgeDescription *desc); 1.261 + int from(); 1.262 + int to(); 1.263 + }; 1.264 + 1.265 + 1.266 + static int _file_count; 1.267 + networkStream *_stream; 1.268 + outputStream *_output; 1.269 + ciMethod *_current_method; 1.270 + GrowableArray<NodeDescription *> _nodes; 1.271 + GrowableArray<EdgeDescription *> _edges; 1.272 + int _depth; 1.273 + Arena *_arena; 1.274 + char buffer[128]; 1.275 + bool _should_send_method; 1.276 + PhaseChaitin* _chaitin; 1.277 + bool _clear_nodes; 1.278 + Matcher* _matcher; 1.279 + bool _traverse_outs; 1.280 + 1.281 + void start_element_helper(const char *name, Properties *properties, bool endElement, bool print_indent = false, bool print_return = true); 1.282 + NodeDescription *create_node_description(Node* node); 1.283 + 1.284 + static void pre_node(Node* node, void *env); 1.285 + static void post_node(Node* node, void *env); 1.286 + 1.287 + void schedule_latest(int **common_dominator, GrowableArray<Block>* blocks); 1.288 + void build_common_dominator(int **common_dominator, int index, GrowableArray<Block>* blocks); 1.289 + void compress(int index, GrowableArray<Block>* blocks); 1.290 + int eval(int index, GrowableArray<Block>* blocks); 1.291 + void link(int index1, int index2, GrowableArray<Block>* blocks); 1.292 + void build_dominators(GrowableArray<Block>* blocks); 1.293 + void build_blocks(Node *node); 1.294 + void walk(Node *n); 1.295 + void start_element(const char *name, Properties *properties = NULL, bool print_indent = false, bool print_return = true); 1.296 + void simple_element(const char *name, Properties *properties = NULL, bool print_indent = false); 1.297 + void end_element(const char *name, bool print_indent = false, bool print_return = true); 1.298 + void print_edge(int from, int to, int index); 1.299 + void print_indent(); 1.300 + void print_method(ciMethod *method, int bci, InlineTree *tree); 1.301 + void print_inline_tree(InlineTree *tree); 1.302 + void clear_nodes(); 1.303 + 1.304 + IdealGraphPrinter(); 1.305 + ~IdealGraphPrinter(); 1.306 + 1.307 +public: 1.308 + 1.309 + static void clean_up(); 1.310 + static IdealGraphPrinter *printer(); 1.311 + 1.312 + bool traverse_outs(); 1.313 + void set_traverse_outs(bool b); 1.314 + void print_ifg(PhaseIFG* ifg); 1.315 + outputStream *output(); 1.316 + void print_inlining(Compile* compile); 1.317 + void begin_method(Compile* compile); 1.318 + void end_method(); 1.319 + void print_method(Compile* compile, const char *name, int level=1, bool clear_nodes = false); 1.320 + void print(Compile* compile, const char *name, Node *root, int level=1, bool clear_nodes = false); 1.321 + void print_xml(const char *name); 1.322 + 1.323 + 1.324 +}; 1.325 + 1.326 +#endif