src/share/vm/opto/phaseX.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_OPTO_PHASEX_HPP
aoqi@0 26 #define SHARE_VM_OPTO_PHASEX_HPP
aoqi@0 27
aoqi@0 28 #include "libadt/dict.hpp"
aoqi@0 29 #include "libadt/vectset.hpp"
aoqi@0 30 #include "memory/resourceArea.hpp"
aoqi@0 31 #include "opto/memnode.hpp"
aoqi@0 32 #include "opto/node.hpp"
aoqi@0 33 #include "opto/phase.hpp"
aoqi@0 34 #include "opto/type.hpp"
aoqi@0 35
aoqi@0 36 class Compile;
aoqi@0 37 class ConINode;
aoqi@0 38 class ConLNode;
aoqi@0 39 class Node;
aoqi@0 40 class Type;
aoqi@0 41 class PhaseTransform;
aoqi@0 42 class PhaseGVN;
aoqi@0 43 class PhaseIterGVN;
aoqi@0 44 class PhaseCCP;
aoqi@0 45 class PhasePeephole;
aoqi@0 46 class PhaseRegAlloc;
aoqi@0 47
aoqi@0 48
aoqi@0 49 //-----------------------------------------------------------------------------
aoqi@0 50 // Expandable closed hash-table of nodes, initialized to NULL.
aoqi@0 51 // Note that the constructor just zeros things
aoqi@0 52 // Storage is reclaimed when the Arena's lifetime is over.
aoqi@0 53 class NodeHash : public StackObj {
aoqi@0 54 protected:
aoqi@0 55 Arena *_a; // Arena to allocate in
aoqi@0 56 uint _max; // Size of table (power of 2)
aoqi@0 57 uint _inserts; // For grow and debug, count of hash_inserts
aoqi@0 58 uint _insert_limit; // 'grow' when _inserts reaches _insert_limit
aoqi@0 59 Node **_table; // Hash table of Node pointers
aoqi@0 60 Node *_sentinel; // Replaces deleted entries in hash table
aoqi@0 61
aoqi@0 62 public:
aoqi@0 63 NodeHash(uint est_max_size);
aoqi@0 64 NodeHash(Arena *arena, uint est_max_size);
aoqi@0 65 NodeHash(NodeHash *use_this_state);
aoqi@0 66 #ifdef ASSERT
aoqi@0 67 ~NodeHash(); // Unlock all nodes upon destruction of table.
aoqi@0 68 void operator=(const NodeHash&); // Unlock all nodes upon replacement of table.
aoqi@0 69 #endif
aoqi@0 70 Node *hash_find(const Node*);// Find an equivalent version in hash table
aoqi@0 71 Node *hash_find_insert(Node*);// If not in table insert else return found node
aoqi@0 72 void hash_insert(Node*); // Insert into hash table
aoqi@0 73 bool hash_delete(const Node*);// Replace with _sentinel in hash table
aoqi@0 74 void check_grow() {
aoqi@0 75 _inserts++;
aoqi@0 76 if( _inserts == _insert_limit ) { grow(); }
aoqi@0 77 assert( _inserts <= _insert_limit, "hash table overflow");
aoqi@0 78 assert( _inserts < _max, "hash table overflow" );
aoqi@0 79 }
aoqi@0 80 static uint round_up(uint); // Round up to nearest power of 2
aoqi@0 81 void grow(); // Grow _table to next power of 2 and rehash
aoqi@0 82 // Return 75% of _max, rounded up.
aoqi@0 83 uint insert_limit() const { return _max - (_max>>2); }
aoqi@0 84
aoqi@0 85 void clear(); // Set all entries to NULL, keep storage.
aoqi@0 86 // Size of hash table
aoqi@0 87 uint size() const { return _max; }
aoqi@0 88 // Return Node* at index in table
aoqi@0 89 Node *at(uint table_index) {
aoqi@0 90 assert(table_index < _max, "Must be within table");
aoqi@0 91 return _table[table_index];
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 void remove_useless_nodes(VectorSet &useful); // replace with sentinel
aoqi@0 95 void replace_with(NodeHash* nh);
aoqi@0 96 void check_no_speculative_types(); // Check no speculative part for type nodes in table
aoqi@0 97
aoqi@0 98 Node *sentinel() { return _sentinel; }
aoqi@0 99
aoqi@0 100 #ifndef PRODUCT
aoqi@0 101 Node *find_index(uint idx); // For debugging
aoqi@0 102 void dump(); // For debugging, dump statistics
aoqi@0 103 #endif
aoqi@0 104 uint _grows; // For debugging, count of table grow()s
aoqi@0 105 uint _look_probes; // For debugging, count of hash probes
aoqi@0 106 uint _lookup_hits; // For debugging, count of hash_finds
aoqi@0 107 uint _lookup_misses; // For debugging, count of hash_finds
aoqi@0 108 uint _insert_probes; // For debugging, count of hash probes
aoqi@0 109 uint _delete_probes; // For debugging, count of hash probes for deletes
aoqi@0 110 uint _delete_hits; // For debugging, count of hash probes for deletes
aoqi@0 111 uint _delete_misses; // For debugging, count of hash probes for deletes
aoqi@0 112 uint _total_inserts; // For debugging, total inserts into hash table
aoqi@0 113 uint _total_insert_probes; // For debugging, total probes while inserting
aoqi@0 114 };
aoqi@0 115
aoqi@0 116
aoqi@0 117 //-----------------------------------------------------------------------------
aoqi@0 118 // Map dense integer indices to Types. Uses classic doubling-array trick.
aoqi@0 119 // Abstractly provides an infinite array of Type*'s, initialized to NULL.
aoqi@0 120 // Note that the constructor just zeros things, and since I use Arena
aoqi@0 121 // allocation I do not need a destructor to reclaim storage.
aoqi@0 122 // Despite the general name, this class is customized for use by PhaseTransform.
aoqi@0 123 class Type_Array : public StackObj {
aoqi@0 124 Arena *_a; // Arena to allocate in
aoqi@0 125 uint _max;
aoqi@0 126 const Type **_types;
aoqi@0 127 void grow( uint i ); // Grow array node to fit
aoqi@0 128 const Type *operator[] ( uint i ) const // Lookup, or NULL for not mapped
aoqi@0 129 { return (i<_max) ? _types[i] : (Type*)NULL; }
aoqi@0 130 friend class PhaseTransform;
aoqi@0 131 public:
aoqi@0 132 Type_Array(Arena *a) : _a(a), _max(0), _types(0) {}
aoqi@0 133 Type_Array(Type_Array *ta) : _a(ta->_a), _max(ta->_max), _types(ta->_types) { }
aoqi@0 134 const Type *fast_lookup(uint i) const{assert(i<_max,"oob");return _types[i];}
aoqi@0 135 // Extend the mapping: index i maps to Type *n.
aoqi@0 136 void map( uint i, const Type *n ) { if( i>=_max ) grow(i); _types[i] = n; }
aoqi@0 137 uint Size() const { return _max; }
aoqi@0 138 #ifndef PRODUCT
aoqi@0 139 void dump() const;
aoqi@0 140 #endif
aoqi@0 141 };
aoqi@0 142
aoqi@0 143
aoqi@0 144 //------------------------------PhaseRemoveUseless-----------------------------
aoqi@0 145 // Remove useless nodes from GVN hash-table, worklist, and graph
aoqi@0 146 class PhaseRemoveUseless : public Phase {
aoqi@0 147 protected:
aoqi@0 148 Unique_Node_List _useful; // Nodes reachable from root
aoqi@0 149 // list is allocated from current resource area
aoqi@0 150 public:
aoqi@0 151 PhaseRemoveUseless( PhaseGVN *gvn, Unique_Node_List *worklist );
aoqi@0 152
aoqi@0 153 Unique_Node_List *get_useful() { return &_useful; }
aoqi@0 154 };
aoqi@0 155
aoqi@0 156
aoqi@0 157 //------------------------------PhaseTransform---------------------------------
aoqi@0 158 // Phases that analyze, then transform. Constructing the Phase object does any
aoqi@0 159 // global or slow analysis. The results are cached later for a fast
aoqi@0 160 // transformation pass. When the Phase object is deleted the cached analysis
aoqi@0 161 // results are deleted.
aoqi@0 162 class PhaseTransform : public Phase {
aoqi@0 163 protected:
aoqi@0 164 Arena* _arena;
aoqi@0 165 Node_Array _nodes; // Map old node indices to new nodes.
aoqi@0 166 Type_Array _types; // Map old node indices to Types.
aoqi@0 167
aoqi@0 168 // ConNode caches:
aoqi@0 169 enum { _icon_min = -1 * HeapWordSize,
aoqi@0 170 _icon_max = 16 * HeapWordSize,
aoqi@0 171 _lcon_min = _icon_min,
aoqi@0 172 _lcon_max = _icon_max,
aoqi@0 173 _zcon_max = (uint)T_CONFLICT
aoqi@0 174 };
aoqi@0 175 ConINode* _icons[_icon_max - _icon_min + 1]; // cached jint constant nodes
aoqi@0 176 ConLNode* _lcons[_lcon_max - _lcon_min + 1]; // cached jlong constant nodes
aoqi@0 177 ConNode* _zcons[_zcon_max + 1]; // cached is_zero_type nodes
aoqi@0 178 void init_con_caches();
aoqi@0 179
aoqi@0 180 // Support both int and long caches because either might be an intptr_t,
aoqi@0 181 // so they show up frequently in address computations.
aoqi@0 182
aoqi@0 183 public:
aoqi@0 184 PhaseTransform( PhaseNumber pnum );
aoqi@0 185 PhaseTransform( Arena *arena, PhaseNumber pnum );
aoqi@0 186 PhaseTransform( PhaseTransform *phase, PhaseNumber pnum );
aoqi@0 187
aoqi@0 188 Arena* arena() { return _arena; }
aoqi@0 189 Type_Array& types() { return _types; }
aoqi@0 190 // _nodes is used in varying ways by subclasses, which define local accessors
aoqi@0 191
aoqi@0 192 public:
aoqi@0 193 // Get a previously recorded type for the node n.
aoqi@0 194 // This type must already have been recorded.
aoqi@0 195 // If you want the type of a very new (untransformed) node,
aoqi@0 196 // you must use type_or_null, and test the result for NULL.
aoqi@0 197 const Type* type(const Node* n) const {
aoqi@0 198 assert(n != NULL, "must not be null");
aoqi@0 199 const Type* t = _types.fast_lookup(n->_idx);
aoqi@0 200 assert(t != NULL, "must set before get");
aoqi@0 201 return t;
aoqi@0 202 }
aoqi@0 203 // Get a previously recorded type for the node n,
aoqi@0 204 // or else return NULL if there is none.
aoqi@0 205 const Type* type_or_null(const Node* n) const {
aoqi@0 206 return _types.fast_lookup(n->_idx);
aoqi@0 207 }
aoqi@0 208 // Record a type for a node.
aoqi@0 209 void set_type(const Node* n, const Type *t) {
aoqi@0 210 assert(t != NULL, "type must not be null");
aoqi@0 211 _types.map(n->_idx, t);
aoqi@0 212 }
aoqi@0 213 // Record an initial type for a node, the node's bottom type.
aoqi@0 214 void set_type_bottom(const Node* n) {
aoqi@0 215 // Use this for initialization when bottom_type() (or better) is not handy.
aoqi@0 216 // Usually the initialization shoudl be to n->Value(this) instead,
aoqi@0 217 // or a hand-optimized value like Type::MEMORY or Type::CONTROL.
aoqi@0 218 assert(_types[n->_idx] == NULL, "must set the initial type just once");
aoqi@0 219 _types.map(n->_idx, n->bottom_type());
aoqi@0 220 }
aoqi@0 221 // Make sure the types array is big enough to record a size for the node n.
aoqi@0 222 // (In product builds, we never want to do range checks on the types array!)
aoqi@0 223 void ensure_type_or_null(const Node* n) {
aoqi@0 224 if (n->_idx >= _types.Size())
aoqi@0 225 _types.map(n->_idx, NULL); // Grow the types array as needed.
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 // Utility functions:
aoqi@0 229 const TypeInt* find_int_type( Node* n);
aoqi@0 230 const TypeLong* find_long_type(Node* n);
aoqi@0 231 jint find_int_con( Node* n, jint value_if_unknown) {
aoqi@0 232 const TypeInt* t = find_int_type(n);
aoqi@0 233 return (t != NULL && t->is_con()) ? t->get_con() : value_if_unknown;
aoqi@0 234 }
aoqi@0 235 jlong find_long_con(Node* n, jlong value_if_unknown) {
aoqi@0 236 const TypeLong* t = find_long_type(n);
aoqi@0 237 return (t != NULL && t->is_con()) ? t->get_con() : value_if_unknown;
aoqi@0 238 }
aoqi@0 239
aoqi@0 240 // Make an idealized constant, i.e., one of ConINode, ConPNode, ConFNode, etc.
aoqi@0 241 // Same as transform(ConNode::make(t)).
aoqi@0 242 ConNode* makecon(const Type* t);
aoqi@0 243 virtual ConNode* uncached_makecon(const Type* t) // override in PhaseValues
aoqi@0 244 { ShouldNotCallThis(); return NULL; }
aoqi@0 245
aoqi@0 246 // Fast int or long constant. Same as TypeInt::make(i) or TypeLong::make(l).
aoqi@0 247 ConINode* intcon(jint i);
aoqi@0 248 ConLNode* longcon(jlong l);
aoqi@0 249
aoqi@0 250 // Fast zero or null constant. Same as makecon(Type::get_zero_type(bt)).
aoqi@0 251 ConNode* zerocon(BasicType bt);
aoqi@0 252
aoqi@0 253 // Return a node which computes the same function as this node, but
aoqi@0 254 // in a faster or cheaper fashion.
aoqi@0 255 virtual Node *transform( Node *n ) = 0;
aoqi@0 256
aoqi@0 257 // Return whether two Nodes are equivalent.
aoqi@0 258 // Must not be recursive, since the recursive version is built from this.
aoqi@0 259 // For pessimistic optimizations this is simply pointer equivalence.
aoqi@0 260 bool eqv(const Node* n1, const Node* n2) const { return n1 == n2; }
aoqi@0 261
aoqi@0 262 // For pessimistic passes, the return type must monotonically narrow.
aoqi@0 263 // For optimistic passes, the return type must monotonically widen.
aoqi@0 264 // It is possible to get into a "death march" in either type of pass,
aoqi@0 265 // where the types are continually moving but it will take 2**31 or
aoqi@0 266 // more steps to converge. This doesn't happen on most normal loops.
aoqi@0 267 //
aoqi@0 268 // Here is an example of a deadly loop for an optimistic pass, along
aoqi@0 269 // with a partial trace of inferred types:
aoqi@0 270 // x = phi(0,x'); L: x' = x+1; if (x' >= 0) goto L;
aoqi@0 271 // 0 1 join([0..max], 1)
aoqi@0 272 // [0..1] [1..2] join([0..max], [1..2])
aoqi@0 273 // [0..2] [1..3] join([0..max], [1..3])
aoqi@0 274 // ... ... ...
aoqi@0 275 // [0..max] [min]u[1..max] join([0..max], [min..max])
aoqi@0 276 // [0..max] ==> fixpoint
aoqi@0 277 // We would have proven, the hard way, that the iteration space is all
aoqi@0 278 // non-negative ints, with the loop terminating due to 32-bit overflow.
aoqi@0 279 //
aoqi@0 280 // Here is the corresponding example for a pessimistic pass:
aoqi@0 281 // x = phi(0,x'); L: x' = x-1; if (x' >= 0) goto L;
aoqi@0 282 // int int join([0..max], int)
aoqi@0 283 // [0..max] [-1..max-1] join([0..max], [-1..max-1])
aoqi@0 284 // [0..max-1] [-1..max-2] join([0..max], [-1..max-2])
aoqi@0 285 // ... ... ...
aoqi@0 286 // [0..1] [-1..0] join([0..max], [-1..0])
aoqi@0 287 // 0 -1 join([0..max], -1)
aoqi@0 288 // 0 == fixpoint
aoqi@0 289 // We would have proven, the hard way, that the iteration space is {0}.
aoqi@0 290 // (Usually, other optimizations will make the "if (x >= 0)" fold up
aoqi@0 291 // before we get into trouble. But not always.)
aoqi@0 292 //
aoqi@0 293 // It's a pleasant thing to observe that the pessimistic pass
aoqi@0 294 // will make short work of the optimistic pass's deadly loop,
aoqi@0 295 // and vice versa. That is a good example of the complementary
aoqi@0 296 // purposes of the CCP (optimistic) vs. GVN (pessimistic) phases.
aoqi@0 297 //
aoqi@0 298 // In any case, only widen or narrow a few times before going to the
aoqi@0 299 // correct flavor of top or bottom.
aoqi@0 300 //
aoqi@0 301 // This call only needs to be made once as the data flows around any
aoqi@0 302 // given cycle. We do it at Phis, and nowhere else.
aoqi@0 303 // The types presented are the new type of a phi (computed by PhiNode::Value)
aoqi@0 304 // and the previously computed type, last time the phi was visited.
aoqi@0 305 //
aoqi@0 306 // The third argument is upper limit for the saturated value,
aoqi@0 307 // if the phase wishes to widen the new_type.
aoqi@0 308 // If the phase is narrowing, the old type provides a lower limit.
aoqi@0 309 // Caller guarantees that old_type and new_type are no higher than limit_type.
aoqi@0 310 virtual const Type* saturate(const Type* new_type, const Type* old_type,
aoqi@0 311 const Type* limit_type) const
aoqi@0 312 { ShouldNotCallThis(); return NULL; }
aoqi@0 313
aoqi@0 314 #ifndef PRODUCT
aoqi@0 315 void dump_old2new_map() const;
aoqi@0 316 void dump_new( uint new_lidx ) const;
aoqi@0 317 void dump_types() const;
aoqi@0 318 void dump_nodes_and_types(const Node *root, uint depth, bool only_ctrl = true);
aoqi@0 319 void dump_nodes_and_types_recur( const Node *n, uint depth, bool only_ctrl, VectorSet &visited);
aoqi@0 320
aoqi@0 321 uint _count_progress; // For profiling, count transforms that make progress
aoqi@0 322 void set_progress() { ++_count_progress; assert( allow_progress(),"No progress allowed during verification"); }
aoqi@0 323 void clear_progress() { _count_progress = 0; }
aoqi@0 324 uint made_progress() const { return _count_progress; }
aoqi@0 325
aoqi@0 326 uint _count_transforms; // For profiling, count transforms performed
aoqi@0 327 void set_transforms() { ++_count_transforms; }
aoqi@0 328 void clear_transforms() { _count_transforms = 0; }
aoqi@0 329 uint made_transforms() const{ return _count_transforms; }
aoqi@0 330
aoqi@0 331 bool _allow_progress; // progress not allowed during verification pass
aoqi@0 332 void set_allow_progress(bool allow) { _allow_progress = allow; }
aoqi@0 333 bool allow_progress() { return _allow_progress; }
aoqi@0 334 #endif
aoqi@0 335 };
aoqi@0 336
aoqi@0 337 //------------------------------PhaseValues------------------------------------
aoqi@0 338 // Phase infrastructure to support values
aoqi@0 339 class PhaseValues : public PhaseTransform {
aoqi@0 340 protected:
aoqi@0 341 NodeHash _table; // Hash table for value-numbering
aoqi@0 342
aoqi@0 343 public:
aoqi@0 344 PhaseValues( Arena *arena, uint est_max_size );
aoqi@0 345 PhaseValues( PhaseValues *pt );
aoqi@0 346 PhaseValues( PhaseValues *ptv, const char *dummy );
aoqi@0 347 NOT_PRODUCT( ~PhaseValues(); )
aoqi@0 348 virtual PhaseIterGVN *is_IterGVN() { return 0; }
aoqi@0 349
aoqi@0 350 // Some Ideal and other transforms delete --> modify --> insert values
aoqi@0 351 bool hash_delete(Node *n) { return _table.hash_delete(n); }
aoqi@0 352 void hash_insert(Node *n) { _table.hash_insert(n); }
aoqi@0 353 Node *hash_find_insert(Node *n){ return _table.hash_find_insert(n); }
aoqi@0 354 Node *hash_find(const Node *n) { return _table.hash_find(n); }
aoqi@0 355
aoqi@0 356 // Used after parsing to eliminate values that are no longer in program
aoqi@0 357 void remove_useless_nodes(VectorSet &useful) {
aoqi@0 358 _table.remove_useless_nodes(useful);
aoqi@0 359 // this may invalidate cached cons so reset the cache
aoqi@0 360 init_con_caches();
aoqi@0 361 }
aoqi@0 362
aoqi@0 363 virtual ConNode* uncached_makecon(const Type* t); // override from PhaseTransform
aoqi@0 364
aoqi@0 365 virtual const Type* saturate(const Type* new_type, const Type* old_type,
aoqi@0 366 const Type* limit_type) const
aoqi@0 367 { return new_type; }
aoqi@0 368
aoqi@0 369 #ifndef PRODUCT
aoqi@0 370 uint _count_new_values; // For profiling, count new values produced
aoqi@0 371 void inc_new_values() { ++_count_new_values; }
aoqi@0 372 void clear_new_values() { _count_new_values = 0; }
aoqi@0 373 uint made_new_values() const { return _count_new_values; }
aoqi@0 374 #endif
aoqi@0 375 };
aoqi@0 376
aoqi@0 377
aoqi@0 378 //------------------------------PhaseGVN---------------------------------------
aoqi@0 379 // Phase for performing local, pessimistic GVN-style optimizations.
aoqi@0 380 class PhaseGVN : public PhaseValues {
aoqi@0 381 public:
aoqi@0 382 PhaseGVN( Arena *arena, uint est_max_size ) : PhaseValues( arena, est_max_size ) {}
aoqi@0 383 PhaseGVN( PhaseGVN *gvn ) : PhaseValues( gvn ) {}
aoqi@0 384 PhaseGVN( PhaseGVN *gvn, const char *dummy ) : PhaseValues( gvn, dummy ) {}
aoqi@0 385
aoqi@0 386 // Return a node which computes the same function as this node, but
aoqi@0 387 // in a faster or cheaper fashion.
aoqi@0 388 Node *transform( Node *n );
aoqi@0 389 Node *transform_no_reclaim( Node *n );
aoqi@0 390
aoqi@0 391 void replace_with(PhaseGVN* gvn) {
aoqi@0 392 _table.replace_with(&gvn->_table);
aoqi@0 393 _types = gvn->_types;
aoqi@0 394 }
aoqi@0 395
aoqi@0 396 // Check for a simple dead loop when a data node references itself.
aoqi@0 397 DEBUG_ONLY(void dead_loop_check(Node *n);)
aoqi@0 398 };
aoqi@0 399
aoqi@0 400 //------------------------------PhaseIterGVN-----------------------------------
aoqi@0 401 // Phase for iteratively performing local, pessimistic GVN-style optimizations.
aoqi@0 402 // and ideal transformations on the graph.
aoqi@0 403 class PhaseIterGVN : public PhaseGVN {
aoqi@0 404 private:
aoqi@0 405 bool _delay_transform; // When true simply register the node when calling transform
aoqi@0 406 // instead of actually optimizing it
aoqi@0 407
aoqi@0 408 // Idealize old Node 'n' with respect to its inputs and its value
aoqi@0 409 virtual Node *transform_old( Node *a_node );
aoqi@0 410
aoqi@0 411 // Subsume users of node 'old' into node 'nn'
aoqi@0 412 void subsume_node( Node *old, Node *nn );
aoqi@0 413
aoqi@0 414 Node_Stack _stack; // Stack used to avoid recursion
aoqi@0 415
aoqi@0 416 protected:
aoqi@0 417
aoqi@0 418 // Idealize new Node 'n' with respect to its inputs and its value
aoqi@0 419 virtual Node *transform( Node *a_node );
aoqi@0 420
aoqi@0 421 // Warm up hash table, type table and initial worklist
aoqi@0 422 void init_worklist( Node *a_root );
aoqi@0 423
aoqi@0 424 virtual const Type* saturate(const Type* new_type, const Type* old_type,
aoqi@0 425 const Type* limit_type) const;
aoqi@0 426 // Usually returns new_type. Returns old_type if new_type is only a slight
aoqi@0 427 // improvement, such that it would take many (>>10) steps to reach 2**32.
aoqi@0 428
aoqi@0 429 public:
aoqi@0 430 PhaseIterGVN( PhaseIterGVN *igvn ); // Used by CCP constructor
aoqi@0 431 PhaseIterGVN( PhaseGVN *gvn ); // Used after Parser
aoqi@0 432 PhaseIterGVN( PhaseIterGVN *igvn, const char *dummy ); // Used after +VerifyOpto
aoqi@0 433
aoqi@0 434 virtual PhaseIterGVN *is_IterGVN() { return this; }
aoqi@0 435
aoqi@0 436 Unique_Node_List _worklist; // Iterative worklist
aoqi@0 437
aoqi@0 438 // Given def-use info and an initial worklist, apply Node::Ideal,
aoqi@0 439 // Node::Value, Node::Identity, hash-based value numbering, Node::Ideal_DU
aoqi@0 440 // and dominator info to a fixed point.
aoqi@0 441 void optimize();
aoqi@0 442
aoqi@0 443 // Register a new node with the iter GVN pass without transforming it.
aoqi@0 444 // Used when we need to restructure a Region/Phi area and all the Regions
aoqi@0 445 // and Phis need to complete this one big transform before any other
aoqi@0 446 // transforms can be triggered on the region.
aoqi@0 447 // Optional 'orig' is an earlier version of this node.
aoqi@0 448 // It is significant only for debugging and profiling.
aoqi@0 449 Node* register_new_node_with_optimizer(Node* n, Node* orig = NULL);
aoqi@0 450
aoqi@0 451 // Kill a globally dead Node. All uses are also globally dead and are
aoqi@0 452 // aggressively trimmed.
aoqi@0 453 void remove_globally_dead_node( Node *dead );
aoqi@0 454
aoqi@0 455 // Kill all inputs to a dead node, recursively making more dead nodes.
aoqi@0 456 // The Node must be dead locally, i.e., have no uses.
aoqi@0 457 void remove_dead_node( Node *dead ) {
aoqi@0 458 assert(dead->outcnt() == 0 && !dead->is_top(), "node must be dead");
aoqi@0 459 remove_globally_dead_node(dead);
aoqi@0 460 }
aoqi@0 461
aoqi@0 462 // Add users of 'n' to worklist
aoqi@0 463 void add_users_to_worklist0( Node *n );
aoqi@0 464 void add_users_to_worklist ( Node *n );
aoqi@0 465
aoqi@0 466 // Replace old node with new one.
aoqi@0 467 void replace_node( Node *old, Node *nn ) {
aoqi@0 468 add_users_to_worklist(old);
aoqi@0 469 hash_delete(old); // Yank from hash before hacking edges
aoqi@0 470 subsume_node(old, nn);
aoqi@0 471 }
aoqi@0 472
aoqi@0 473 // Delayed node rehash: remove a node from the hash table and rehash it during
aoqi@0 474 // next optimizing pass
aoqi@0 475 void rehash_node_delayed(Node* n) {
aoqi@0 476 hash_delete(n);
aoqi@0 477 _worklist.push(n);
aoqi@0 478 }
aoqi@0 479
aoqi@0 480 // Replace ith edge of "n" with "in"
aoqi@0 481 void replace_input_of(Node* n, int i, Node* in) {
aoqi@0 482 rehash_node_delayed(n);
aoqi@0 483 n->set_req(i, in);
aoqi@0 484 }
aoqi@0 485
aoqi@0 486 // Delete ith edge of "n"
aoqi@0 487 void delete_input_of(Node* n, int i) {
aoqi@0 488 rehash_node_delayed(n);
aoqi@0 489 n->del_req(i);
aoqi@0 490 }
aoqi@0 491
aoqi@0 492 bool delay_transform() const { return _delay_transform; }
aoqi@0 493
aoqi@0 494 void set_delay_transform(bool delay) {
aoqi@0 495 _delay_transform = delay;
aoqi@0 496 }
aoqi@0 497
aoqi@0 498 // Clone loop predicates. Defined in loopTransform.cpp.
aoqi@0 499 Node* clone_loop_predicates(Node* old_entry, Node* new_entry, bool clone_limit_check);
aoqi@0 500 // Create a new if below new_entry for the predicate to be cloned
aoqi@0 501 ProjNode* create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
aoqi@0 502 Deoptimization::DeoptReason reason);
aoqi@0 503
aoqi@0 504 void remove_speculative_types();
aoqi@0 505 void check_no_speculative_types() {
aoqi@0 506 _table.check_no_speculative_types();
aoqi@0 507 }
aoqi@0 508
aoqi@0 509 #ifndef PRODUCT
aoqi@0 510 protected:
aoqi@0 511 // Sub-quadratic implementation of VerifyIterativeGVN.
aoqi@0 512 julong _verify_counter;
aoqi@0 513 julong _verify_full_passes;
aoqi@0 514 enum { _verify_window_size = 30 };
aoqi@0 515 Node* _verify_window[_verify_window_size];
aoqi@0 516 void verify_step(Node* n);
aoqi@0 517 #endif
aoqi@0 518 };
aoqi@0 519
aoqi@0 520 //------------------------------PhaseCCP---------------------------------------
aoqi@0 521 // Phase for performing global Conditional Constant Propagation.
aoqi@0 522 // Should be replaced with combined CCP & GVN someday.
aoqi@0 523 class PhaseCCP : public PhaseIterGVN {
aoqi@0 524 // Non-recursive. Use analysis to transform single Node.
aoqi@0 525 virtual Node *transform_once( Node *n );
aoqi@0 526
aoqi@0 527 public:
aoqi@0 528 PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants
aoqi@0 529 NOT_PRODUCT( ~PhaseCCP(); )
aoqi@0 530
aoqi@0 531 // Worklist algorithm identifies constants
aoqi@0 532 void analyze();
aoqi@0 533 // Recursive traversal of program. Used analysis to modify program.
aoqi@0 534 virtual Node *transform( Node *n );
aoqi@0 535 // Do any transformation after analysis
aoqi@0 536 void do_transform();
aoqi@0 537
aoqi@0 538 virtual const Type* saturate(const Type* new_type, const Type* old_type,
aoqi@0 539 const Type* limit_type) const;
aoqi@0 540 // Returns new_type->widen(old_type), which increments the widen bits until
aoqi@0 541 // giving up with TypeInt::INT or TypeLong::LONG.
aoqi@0 542 // Result is clipped to limit_type if necessary.
aoqi@0 543
aoqi@0 544 #ifndef PRODUCT
aoqi@0 545 static uint _total_invokes; // For profiling, count invocations
aoqi@0 546 void inc_invokes() { ++PhaseCCP::_total_invokes; }
aoqi@0 547
aoqi@0 548 static uint _total_constants; // For profiling, count constants found
aoqi@0 549 uint _count_constants;
aoqi@0 550 void clear_constants() { _count_constants = 0; }
aoqi@0 551 void inc_constants() { ++_count_constants; }
aoqi@0 552 uint count_constants() const { return _count_constants; }
aoqi@0 553
aoqi@0 554 static void print_statistics();
aoqi@0 555 #endif
aoqi@0 556 };
aoqi@0 557
aoqi@0 558
aoqi@0 559 //------------------------------PhasePeephole----------------------------------
aoqi@0 560 // Phase for performing peephole optimizations on register allocated basic blocks.
aoqi@0 561 class PhasePeephole : public PhaseTransform {
aoqi@0 562 PhaseRegAlloc *_regalloc;
aoqi@0 563 PhaseCFG &_cfg;
aoqi@0 564 // Recursive traversal of program. Pure function is unused in this phase
aoqi@0 565 virtual Node *transform( Node *n );
aoqi@0 566
aoqi@0 567 public:
aoqi@0 568 PhasePeephole( PhaseRegAlloc *regalloc, PhaseCFG &cfg );
aoqi@0 569 NOT_PRODUCT( ~PhasePeephole(); )
aoqi@0 570
aoqi@0 571 // Do any transformation after analysis
aoqi@0 572 void do_transform();
aoqi@0 573
aoqi@0 574 #ifndef PRODUCT
aoqi@0 575 static uint _total_peepholes; // For profiling, count peephole rules applied
aoqi@0 576 uint _count_peepholes;
aoqi@0 577 void clear_peepholes() { _count_peepholes = 0; }
aoqi@0 578 void inc_peepholes() { ++_count_peepholes; }
aoqi@0 579 uint count_peepholes() const { return _count_peepholes; }
aoqi@0 580
aoqi@0 581 static void print_statistics();
aoqi@0 582 #endif
aoqi@0 583 };
aoqi@0 584
aoqi@0 585 #endif // SHARE_VM_OPTO_PHASEX_HPP

mercurial