chaitin.hpp revision 3056
4632N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4632N/A * This code is free software; you can redistribute it and/or modify it 4632N/A * under the terms of the GNU General Public License version 2 only, as 4632N/A * published by the Free Software Foundation. 4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT 4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4632N/A * version 2 for more details (a copy is included in the LICENSE file that 4632N/A * You should have received a copy of the GNU General Public License version 4632N/A * 2 along with this work; if not, write to the Free Software Foundation, 4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA //------------------------------LRG-------------------------------------------- enum {
SPILL_REG=
29999 };
// Register number of a spilled LRG double _cost;
// 2 for loads/1 for stores times block freq double _area;
// Sum of all simultaneously live values double score()
const;
// Compute score from cost and area double _maxfreq;
// Maximum frequency of any def or use Node *
_def;
// Check for multi-def live ranges uint _next;
// Index of next LRG in linked list uint _prev;
// Index of prev LRG in linked list uint _reg;
// Chosen register; undefined if mask is plural // Return chosen register for this LRG. Error if the LRG is not bound to // Degree starts not valid and any change to the IFG neighbor // set makes it not valid. // Made a change that hammered degree // Incrementally modify degree. If it was correct, it should remain correct // Compute the degree between 2 live ranges // Get the last mask size computed, even if it does not match the // count of bits in the current mask. // Number of registers this live range uses when it colors // except _num_regs is kill count for fat_proj // Number of physical registers this live range uses when it colors // Architecture and register-set dependent // How much 'wiggle room' does this live range have? // How many color choices can it make (scaled by _num_regs)? // Bound LRGs have ZERO degrees of freedom. We also count // Negative degrees-of-freedom; even with no neighbors this // live range must spill. // Is this live range of "low-degree"? Trivially colorable? // Is this live range just barely "low-degree"? Trivially colorable? _is_bound:
1,
// live range starts life with no _must_spill:
1,
// live range has lost all degrees of freedom // If _fat_proj is set, live range does NOT require aligned, adjacent // registers and has NO interferences. // If _fat_proj is clear, live range requires num_regs() to be a power of // 2, and it requires registers to form an aligned, adjacent set. _was_lo:
1,
// Was lo-degree prior to coalesce _has_copy:
1,
// Adjacent to some copy instruction _at_risk:
1;
// Simplify says this guy is at risk to spill // Alive if non-zero, dead if zero //------------------------------LRG_List--------------------------------------- // Map Node indices to Live RanGe indices. // Array lookup in the optimized case. //------------------------------IFG-------------------------------------------- // An undirected graph implementation. Created with a fixed number of // vertices. Edges can be added & tested. Vertices can be removed, then // added back later with all edges intact. Can add edges between one vertex // and a list of other vertices. Can union vertices (and their edges) // together. The IFG needs to be really really fast, and also fairly // abstract! It needs abstraction so I can fiddle with the implementation to // Current implementation: a triangular adjacency list. // Array of adjacency-lists, indexed by live-range number // Assertion bit for proper use of Squaring // Live range structure goes here // Largest live-range number // Keep track of inserted and deleted Nodes // Add edge between a and b. Returns true if actually addded. // Add edge between a and everything in the vector // Test for edge existance // Square-up matrix for faster Union // Return number of LRG neighbors // Union edges of b into a on Squared-up matrix // Test for edge in Squared-up matrix // Yank a Node and all connected edges from the IFG. Be prepared to // re-insert the yanked Node in reverse order of yanking. Return a // list of neighbors (edges) yanked. // Reinsert a yanked Node // Return set of neighbors //--------------- Live Range Accessors // Compute and set effective degree. Might be folded into SquareUp(). // Compute effective degree as the sum of neighbors' _sizes. // TEMPORARILY REPLACED WITH COMMAND LINE FLAG //// !!!!! Magic Constants need to move into ad file //#define FLOAT_PRESSURE 30 /* SFLT_REG_mask.Size() - 1 */ //#define INT_PRESSURE 23 /* NOTEMP_I_REG_mask.Size() - 1 */ //#define FLOAT_PRESSURE 6 //------------------------------Chaitin---------------------------------------- // Briggs-Chaitin style allocation, mostly. // Union-find map. Declared as a short for speed. // Indexed by live-range number, it returns the compacted live-range number // Reset the Union-Find map to identity // Remove the need for the Union-Find mapping // Combine the Live Range Indices for these 2 Nodes into a single live // range. Future requests for any Node in either live range will // return the live range index for the combined live range. // Compact live ranges, removing unused ones. Return new maxlrg. // Helper functions for Split() // True if lidx is used before any real register is def'd in the block // Insert the spill at chosen location. Skip over any intervening Proj's or // Phis. Skip over a CatchNode and projs, inserting in the fall-through block // instead. Update high-pressure indices. Create a new live range. uint _oldphi;
// Node index which separates pre-allocation nodes Block **
_blks;
// Array of blocks sorted by frequency for coalescing // Convert a Node into a Live Range Index - a lidx // Do all the real work of allocate // De-SSA the world. Assign registers to Nodes. Use the same register for // all inputs to a PhiNode, effectively coalescing live ranges. Insert // Add edge between reg and everything in the vector. // Same as _ifg->add_vector(reg,live) EXCEPT use the RegMask // information to trim the set of interferences. Return the // Count register pressure for asserts // Build the interference graph using virtual registers only. // Used for aggressive coalescing. // Build the interference graph using physical registers when available. // That is, if 2 live ranges are simultaneously alive but in their // acceptable register sets do not overlap, then they do not interfere. // Gather LiveRanGe information, including register masks and base pointer/ // derived pointer relationships. // Force the bases of derived pointers to be alive at GC points. // Helper to stretch above; recursively discover the base Node for // a given derived Node. Easy for AddP-related machine nodes, but // needs to be recursive for derived Phis. // Set the was-lo-degree bit. Conservative coalescing should not change the // colorability of the graph. If any live range was of low-degree before // coalescing, it should Simplify. This call sets the was-lo-degree bit. // Split live-ranges that must spill due to register conflicts (as opposed // to capacity spills). Typically these are things def'd in a register // and used on the stack or vice-versa. // Init LRG caching of degree, numregs. Init lo_degree list. // Simplify the IFG by removing LRGs of low degree with no copies // Simplify the IFG by removing LRGs of low degree // Select colors by re-inserting edges into the IFG. // Return TRUE if any spills occurred. // Helper function for select which allows biased coloring // Helper function which implements biasing heuristic // Split uncolorable live ranges // Return new number of live ranges // Copy 'was_spilled'-edness from one Node to another. // Set the 'spilled_once' or 'spilled_twice' flag on a node. // Convert ideal spill-nodes into machine loads & stores // Set C->failing when fixup spills could not complete, node limit exceeded. // Post-Allocation peephole copy removal // Replace the old node with the current live version of that value // and yank the old value if it's dead. // If nreg already contains the same constant as val then eliminate it // Extend the node to LRG mapping // dump defs and uses by default // Verify that base pointers and derived pointers are still sane #
endif // SHARE_VM_OPTO_CHAITIN_HPP