提交 41139e91 编写于 作者: A adlertz

8024646: Remove LRG_List container, replace it with GrowableArray

Summary: We already have GrowableArray, use it instead of LRG_List
Reviewed-by: kvn
上级 e989bacd
......@@ -122,40 +122,23 @@ double LRG::score() const {
return score;
}
LRG_List::LRG_List( uint max ) : _cnt(max), _max(max), _lidxs(NEW_RESOURCE_ARRAY(uint,max)) {
memset( _lidxs, 0, sizeof(uint)*max );
}
void LRG_List::extend( uint nidx, uint lidx ) {
_nesting.check();
if( nidx >= _max ) {
uint size = 16;
while( size <= nidx ) size <<=1;
_lidxs = REALLOC_RESOURCE_ARRAY( uint, _lidxs, _max, size );
_max = size;
}
while( _cnt <= nidx )
_lidxs[_cnt++] = 0;
_lidxs[nidx] = lidx;
}
#define NUMBUCKS 3
// Straight out of Tarjan's union-find algorithm
uint LiveRangeMap::find_compress(uint lrg) {
uint cur = lrg;
uint next = _uf_map[cur];
uint next = _uf_map.at(cur);
while (next != cur) { // Scan chain of equivalences
assert( next < cur, "always union smaller");
cur = next; // until find a fixed-point
next = _uf_map[cur];
next = _uf_map.at(cur);
}
// Core of union-find algorithm: update chain of
// equivalences to be equal to the root.
while (lrg != next) {
uint tmp = _uf_map[lrg];
_uf_map.map(lrg, next);
uint tmp = _uf_map.at(lrg);
_uf_map.at_put(lrg, next);
lrg = tmp;
}
return lrg;
......@@ -165,10 +148,10 @@ uint LiveRangeMap::find_compress(uint lrg) {
void LiveRangeMap::reset_uf_map(uint max_lrg_id) {
_max_lrg_id= max_lrg_id;
// Force the Union-Find mapping to be at least this large
_uf_map.extend(_max_lrg_id, 0);
_uf_map.at_put_grow(_max_lrg_id, 0);
// Initialize it to be the ID mapping.
for (uint i = 0; i < _max_lrg_id; ++i) {
_uf_map.map(i, i);
_uf_map.at_put(i, i);
}
}
......@@ -176,12 +159,12 @@ void LiveRangeMap::reset_uf_map(uint max_lrg_id) {
// the Union-Find mapping after this call.
void LiveRangeMap::compress_uf_map_for_nodes() {
// For all Nodes, compress mapping
uint unique = _names.Size();
uint unique = _names.length();
for (uint i = 0; i < unique; ++i) {
uint lrg = _names[i];
uint lrg = _names.at(i);
uint compressed_lrg = find(lrg);
if (lrg != compressed_lrg) {
_names.map(i, compressed_lrg);
_names.at_put(i, compressed_lrg);
}
}
}
......@@ -198,11 +181,11 @@ uint LiveRangeMap::find_const(uint lrg) const {
return lrg;
}
uint next = _uf_map[lrg];
uint next = _uf_map.at(lrg);
while (next != lrg) { // Scan chain of equivalences
assert(next < lrg, "always union smaller");
lrg = next; // until find a fixed-point
next = _uf_map[lrg];
next = _uf_map.at(lrg);
}
return next;
}
......@@ -215,7 +198,7 @@ PhaseChaitin::PhaseChaitin(uint unique, PhaseCFG &cfg, Matcher &matcher)
NULL
#endif
)
, _lrg_map(unique)
, _lrg_map(Thread::current()->resource_area(), unique)
, _live(0)
, _spilled_once(Thread::current()->resource_area())
, _spilled_twice(Thread::current()->resource_area())
......@@ -692,6 +675,7 @@ void PhaseChaitin::de_ssa() {
_lrg_map.map(n->_idx, rm.is_NotEmpty() ? lr_counter++ : 0);
}
}
// Reset the Union-Find mapping to be identity
_lrg_map.reset_uf_map(lr_counter);
}
......
......@@ -283,8 +283,8 @@ private:
// Straight out of Tarjan's union-find algorithm
uint find_compress(const Node *node) {
uint lrg_id = find_compress(_names[node->_idx]);
_names.map(node->_idx, lrg_id);
uint lrg_id = find_compress(_names.at(node->_idx));
_names.at_put(node->_idx, lrg_id);
return lrg_id;
}
......@@ -305,40 +305,40 @@ public:
}
uint size() const {
return _names.Size();
return _names.length();
}
uint live_range_id(uint idx) const {
return _names[idx];
return _names.at(idx);
}
uint live_range_id(const Node *node) const {
return _names[node->_idx];
return _names.at(node->_idx);
}
uint uf_live_range_id(uint lrg_id) const {
return _uf_map[lrg_id];
return _uf_map.at(lrg_id);
}
void map(uint idx, uint lrg_id) {
_names.map(idx, lrg_id);
_names.at_put(idx, lrg_id);
}
void uf_map(uint dst_lrg_id, uint src_lrg_id) {
_uf_map.map(dst_lrg_id, src_lrg_id);
_uf_map.at_put(dst_lrg_id, src_lrg_id);
}
void extend(uint idx, uint lrg_id) {
_names.extend(idx, lrg_id);
_names.at_put_grow(idx, lrg_id);
}
void uf_extend(uint dst_lrg_id, uint src_lrg_id) {
_uf_map.extend(dst_lrg_id, src_lrg_id);
_uf_map.at_put_grow(dst_lrg_id, src_lrg_id);
}
LiveRangeMap(uint unique)
: _names(unique)
, _uf_map(unique)
LiveRangeMap(Arena* arena, uint unique)
: _names(arena, unique, unique, 0)
, _uf_map(arena, unique, unique, 0)
, _max_lrg_id(0) {}
uint find_id( const Node *n ) {
......@@ -355,14 +355,14 @@ public:
void compress_uf_map_for_nodes();
uint find(uint lidx) {
uint uf_lidx = _uf_map[lidx];
uint uf_lidx = _uf_map.at(lidx);
return (uf_lidx == lidx) ? uf_lidx : find_compress(lidx);
}
// Convert a Node into a Live Range Index - a lidx
uint find(const Node *node) {
uint lidx = live_range_id(node);
uint uf_lidx = _uf_map[lidx];
uint uf_lidx = _uf_map.at(lidx);
return (uf_lidx == lidx) ? uf_lidx : find_compress(node);
}
......@@ -371,10 +371,10 @@ public:
// Like Find above, but no path compress, so bad asymptotic behavior
uint find_const(const Node *node) const {
if(node->_idx >= _names.Size()) {
if(node->_idx >= (uint)_names.length()) {
return 0; // not mapped, usual for debug dump
}
return find_const(_names[node->_idx]);
return find_const(_names.at(node->_idx));
}
};
......
......@@ -29,7 +29,6 @@
class LoopTree;
class LRG;
class LRG_List;
class Matcher;
class PhaseIFG;
class PhaseCFG;
......
......@@ -91,7 +91,7 @@ void PhaseLive::compute(uint maxlrg) {
break;
}
uint r = _names[n->_idx];
uint r = _names.at(n->_idx);
assert(!def_outside->member(r), "Use of external LRG overlaps the same LRG defined in this block");
def->insert( r );
use->remove( r );
......@@ -100,7 +100,7 @@ void PhaseLive::compute(uint maxlrg) {
Node *nk = n->in(k);
uint nkidx = nk->_idx;
if (_cfg.get_block_for_node(nk) != block) {
uint u = _names[nkidx];
uint u = _names.at(nkidx);
use->insert(u);
DEBUG_ONLY(def_outside->insert(u);)
}
......@@ -112,7 +112,7 @@ void PhaseLive::compute(uint maxlrg) {
#endif
// Remove anything defined by Phis and the block start instruction
for (uint k = i; k > 0; k--) {
uint r = _names[block->get_node(k - 1)->_idx];
uint r = _names.at(block->get_node(k - 1)->_idx);
def->insert(r);
use->remove(r);
}
......@@ -124,7 +124,7 @@ void PhaseLive::compute(uint maxlrg) {
// PhiNode uses go in the live-out set of prior blocks.
for (uint k = i; k > 0; k--) {
add_liveout(p, _names[block->get_node(k-1)->in(l)->_idx], first_pass);
add_liveout(p, _names.at(block->get_node(k-1)->in(l)->_idx), first_pass);
}
}
freeset(block);
......@@ -256,7 +256,7 @@ void PhaseLive::dump( const Block *b ) const {
tty->print("LiveOut: "); _live[b->_pre_order-1].dump();
uint cnt = b->number_of_nodes();
for( uint i=0; i<cnt; i++ ) {
tty->print("L%d/", _names[b->get_node(i)->_idx] );
tty->print("L%d/", _names.at(b->get_node(i)->_idx));
b->get_node(i)->dump();
}
tty->print("\n");
......
......@@ -40,27 +40,7 @@ class IndexSet;
//------------------------------LRG_List---------------------------------------
// Map Node indices to Live RanGe indices.
// Array lookup in the optimized case.
class LRG_List : public ResourceObj {
friend class VMStructs;
uint _cnt, _max;
uint* _lidxs;
ReallocMark _nesting; // assertion check for reallocations
public:
LRG_List( uint max );
uint lookup( uint nidx ) const {
return _lidxs[nidx];
}
uint operator[] (uint nidx) const { return lookup(nidx); }
void map( uint nidx, uint lidx ) {
assert( nidx < _cnt, "oob" );
_lidxs[nidx] = lidx;
}
void extend( uint nidx, uint lidx );
uint Size() const { return _cnt; }
};
typedef GrowableArray<uint> LRG_List;
//------------------------------PhaseLive--------------------------------------
// Compute live-in/live-out
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册