提交 4d97e042 编写于 作者: A adlertz

8023988: Move local scheduling of nodes to the CFG creation and code motion phase (PhaseCFG)

Summary: Moved local scheduling code from class Block to class PhaseCFG
Reviewed-by: kvn, roland
上级 83f5e055
...@@ -209,15 +209,15 @@ bool Block::has_uncommon_code() const { ...@@ -209,15 +209,15 @@ bool Block::has_uncommon_code() const {
// True if block is low enough frequency or guarded by a test which // True if block is low enough frequency or guarded by a test which
// mostly does not go here. // mostly does not go here.
bool Block::is_uncommon(PhaseCFG* cfg) const { bool PhaseCFG::is_uncommon(const Block* block) {
// Initial blocks must never be moved, so are never uncommon. // Initial blocks must never be moved, so are never uncommon.
if (head()->is_Root() || head()->is_Start()) return false; if (block->head()->is_Root() || block->head()->is_Start()) return false;
// Check for way-low freq // Check for way-low freq
if( _freq < BLOCK_FREQUENCY(0.00001f) ) return true; if(block->_freq < BLOCK_FREQUENCY(0.00001f) ) return true;
// Look for code shape indicating uncommon_trap or slow path // Look for code shape indicating uncommon_trap or slow path
if (has_uncommon_code()) return true; if (block->has_uncommon_code()) return true;
const float epsilon = 0.05f; const float epsilon = 0.05f;
const float guard_factor = PROB_UNLIKELY_MAG(4) / (1.f - epsilon); const float guard_factor = PROB_UNLIKELY_MAG(4) / (1.f - epsilon);
...@@ -225,8 +225,8 @@ bool Block::is_uncommon(PhaseCFG* cfg) const { ...@@ -225,8 +225,8 @@ bool Block::is_uncommon(PhaseCFG* cfg) const {
uint freq_preds = 0; uint freq_preds = 0;
uint uncommon_for_freq_preds = 0; uint uncommon_for_freq_preds = 0;
for( uint i=1; i<num_preds(); i++ ) { for( uint i=1; i< block->num_preds(); i++ ) {
Block* guard = cfg->get_block_for_node(pred(i)); Block* guard = get_block_for_node(block->pred(i));
// Check to see if this block follows its guard 1 time out of 10000 // Check to see if this block follows its guard 1 time out of 10000
// or less. // or less.
// //
...@@ -244,14 +244,14 @@ bool Block::is_uncommon(PhaseCFG* cfg) const { ...@@ -244,14 +244,14 @@ bool Block::is_uncommon(PhaseCFG* cfg) const {
uncommon_preds++; uncommon_preds++;
} else { } else {
freq_preds++; freq_preds++;
if( _freq < guard->_freq * guard_factor ) { if(block->_freq < guard->_freq * guard_factor ) {
uncommon_for_freq_preds++; uncommon_for_freq_preds++;
} }
} }
} }
if( num_preds() > 1 && if( block->num_preds() > 1 &&
// The block is uncommon if all preds are uncommon or // The block is uncommon if all preds are uncommon or
(uncommon_preds == (num_preds()-1) || (uncommon_preds == (block->num_preds()-1) ||
// it is uncommon for all frequent preds. // it is uncommon for all frequent preds.
uncommon_for_freq_preds == freq_preds) ) { uncommon_for_freq_preds == freq_preds) ) {
return true; return true;
...@@ -669,7 +669,7 @@ void PhaseCFG::remove_empty_blocks() { ...@@ -669,7 +669,7 @@ void PhaseCFG::remove_empty_blocks() {
// Look for uncommon blocks and move to end. // Look for uncommon blocks and move to end.
if (!C->do_freq_based_layout()) { if (!C->do_freq_based_layout()) {
if (block->is_uncommon(this)) { if (is_uncommon(block)) {
move_to_end(block, i); move_to_end(block, i);
last--; // No longer check for being uncommon! last--; // No longer check for being uncommon!
if (no_flip_branch(block)) { // Fall-thru case must follow? if (no_flip_branch(block)) { // Fall-thru case must follow?
......
...@@ -318,23 +318,6 @@ public: ...@@ -318,23 +318,6 @@ public:
// Find and remove n from block list // Find and remove n from block list
void find_remove( const Node *n ); void find_remove( const Node *n );
// helper function that adds caller save registers to MachProjNode
void add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_policy, bool exclude_soe);
// Schedule a call next in the block
uint sched_call(Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_List &worklist, GrowableArray<int> &ready_cnt, MachCallNode *mcall, VectorSet &next_call);
// Perform basic-block local scheduling
Node *select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &ready_cnt, VectorSet &next_call, uint sched_slot);
void set_next_call( Node *n, VectorSet &next_call, PhaseCFG* cfg);
void needed_for_next_call(Node *this_call, VectorSet &next_call, PhaseCFG* cfg);
bool schedule_local(PhaseCFG *cfg, Matcher &m, GrowableArray<int> &ready_cnt, VectorSet &next_call);
// Cleanup if any code lands between a Call and his Catch
void call_catch_cleanup(PhaseCFG* cfg, Compile *C);
// Detect implicit-null-check opportunities. Basically, find NULL checks
// with suitable memory ops nearby. Use the memory op to do the NULL check.
// I can generate a memory op if there is not one nearby.
void implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowed_reasons);
// Return the empty status of a block // Return the empty status of a block
enum { not_empty, empty_with_goto, completely_empty }; enum { not_empty, empty_with_goto, completely_empty };
int is_Empty() const; int is_Empty() const;
...@@ -366,10 +349,6 @@ public: ...@@ -366,10 +349,6 @@ public:
// Examine block's code shape to predict if it is not commonly executed. // Examine block's code shape to predict if it is not commonly executed.
bool has_uncommon_code() const; bool has_uncommon_code() const;
// Use frequency calculations and code shape to predict if the block
// is uncommon.
bool is_uncommon(PhaseCFG* cfg) const;
#ifndef PRODUCT #ifndef PRODUCT
// Debugging print of basic block // Debugging print of basic block
void dump_bidx(const Block* orig, outputStream* st = tty) const; void dump_bidx(const Block* orig, outputStream* st = tty) const;
...@@ -452,6 +431,27 @@ class PhaseCFG : public Phase { ...@@ -452,6 +431,27 @@ class PhaseCFG : public Phase {
// to late. Helper for schedule_late. // to late. Helper for schedule_late.
Block* hoist_to_cheaper_block(Block* LCA, Block* early, Node* self); Block* hoist_to_cheaper_block(Block* LCA, Block* early, Node* self);
bool schedule_local(Block* block, GrowableArray<int>& ready_cnt, VectorSet& next_call);
void set_next_call(Block* block, Node* n, VectorSet& next_call);
void needed_for_next_call(Block* block, Node* this_call, VectorSet& next_call);
// Perform basic-block local scheduling
Node* select(Block* block, Node_List& worklist, GrowableArray<int>& ready_cnt, VectorSet& next_call, uint sched_slot);
// Schedule a call next in the block
uint sched_call(Block* block, uint node_cnt, Node_List& worklist, GrowableArray<int>& ready_cnt, MachCallNode* mcall, VectorSet& next_call);
// Cleanup if any code lands between a Call and his Catch
void call_catch_cleanup(Block* block);
Node* catch_cleanup_find_cloned_def(Block* use_blk, Node* def, Block* def_blk, int n_clone_idx);
void catch_cleanup_inter_block(Node *use, Block *use_blk, Node *def, Block *def_blk, int n_clone_idx);
// Detect implicit-null-check opportunities. Basically, find NULL checks
// with suitable memory ops nearby. Use the memory op to do the NULL check.
// I can generate a memory op if there is not one nearby.
void implicit_null_check(Block* block, Node *proj, Node *val, int allowed_reasons);
// Perform a Depth First Search (DFS). // Perform a Depth First Search (DFS).
// Setup 'vertex' as DFS to vertex mapping. // Setup 'vertex' as DFS to vertex mapping.
// Setup 'semi' as vertex to DFS mapping. // Setup 'semi' as vertex to DFS mapping.
...@@ -568,6 +568,10 @@ class PhaseCFG : public Phase { ...@@ -568,6 +568,10 @@ class PhaseCFG : public Phase {
return (_node_to_block_mapping.lookup(node->_idx) != NULL); return (_node_to_block_mapping.lookup(node->_idx) != NULL);
} }
// Use frequency calculations and code shape to predict if the block
// is uncommon.
bool is_uncommon(const Block* block);
#ifdef ASSERT #ifdef ASSERT
Unique_Node_List _raw_oops; Unique_Node_List _raw_oops;
#endif #endif
......
...@@ -339,7 +339,7 @@ void PhaseAggressiveCoalesce::insert_copies( Matcher &matcher ) { ...@@ -339,7 +339,7 @@ void PhaseAggressiveCoalesce::insert_copies( Matcher &matcher ) {
} // End of is two-adr } // End of is two-adr
// Insert a copy at a debug use for a lrg which has high frequency // Insert a copy at a debug use for a lrg which has high frequency
if (b->_freq < OPTO_DEBUG_SPLIT_FREQ || b->is_uncommon(&_phc._cfg)) { if (b->_freq < OPTO_DEBUG_SPLIT_FREQ || _phc._cfg.is_uncommon(b)) {
// Walk the debug inputs to the node and check for lrg freq // Walk the debug inputs to the node and check for lrg freq
JVMState* jvms = n->jvms(); JVMState* jvms = n->jvms();
uint debug_start = jvms ? jvms->debug_start() : 999999; uint debug_start = jvms ? jvms->debug_start() : 999999;
...@@ -769,7 +769,7 @@ bool PhaseConservativeCoalesce::copy_copy(Node *dst_copy, Node *src_copy, Block ...@@ -769,7 +769,7 @@ bool PhaseConservativeCoalesce::copy_copy(Node *dst_copy, Node *src_copy, Block
// Conservative (but pessimistic) copy coalescing of a single block // Conservative (but pessimistic) copy coalescing of a single block
void PhaseConservativeCoalesce::coalesce( Block *b ) { void PhaseConservativeCoalesce::coalesce( Block *b ) {
// Bail out on infrequent blocks // Bail out on infrequent blocks
if (b->is_uncommon(&_phc._cfg)) { if (_phc._cfg.is_uncommon(b)) {
return; return;
} }
// Check this block for copies. // Check this block for copies.
......
...@@ -1342,7 +1342,7 @@ void PhaseCFG::global_code_motion() { ...@@ -1342,7 +1342,7 @@ void PhaseCFG::global_code_motion() {
Node* proj = _matcher._null_check_tests[i]; Node* proj = _matcher._null_check_tests[i];
Node* val = _matcher._null_check_tests[i + 1]; Node* val = _matcher._null_check_tests[i + 1];
Block* block = get_block_for_node(proj); Block* block = get_block_for_node(proj);
block->implicit_null_check(this, proj, val, allowed_reasons); implicit_null_check(block, proj, val, allowed_reasons);
// The implicit_null_check will only perform the transformation // The implicit_null_check will only perform the transformation
// if the null branch is truly uncommon, *and* it leads to an // if the null branch is truly uncommon, *and* it leads to an
// uncommon trap. Combined with the too_many_traps guards // uncommon trap. Combined with the too_many_traps guards
...@@ -1363,7 +1363,7 @@ void PhaseCFG::global_code_motion() { ...@@ -1363,7 +1363,7 @@ void PhaseCFG::global_code_motion() {
visited.Clear(); visited.Clear();
for (uint i = 0; i < number_of_blocks(); i++) { for (uint i = 0; i < number_of_blocks(); i++) {
Block* block = get_block(i); Block* block = get_block(i);
if (!block->schedule_local(this, _matcher, ready_cnt, visited)) { if (!schedule_local(block, ready_cnt, visited)) {
if (!C->failure_reason_is(C2Compiler::retry_no_subsuming_loads())) { if (!C->failure_reason_is(C2Compiler::retry_no_subsuming_loads())) {
C->record_method_not_compilable("local schedule failed"); C->record_method_not_compilable("local schedule failed");
} }
...@@ -1375,7 +1375,7 @@ void PhaseCFG::global_code_motion() { ...@@ -1375,7 +1375,7 @@ void PhaseCFG::global_code_motion() {
// clone the instructions on all paths below the Catch. // clone the instructions on all paths below the Catch.
for (uint i = 0; i < number_of_blocks(); i++) { for (uint i = 0; i < number_of_blocks(); i++) {
Block* block = get_block(i); Block* block = get_block(i);
block->call_catch_cleanup(this, C); call_catch_cleanup(block);
} }
#ifndef PRODUCT #ifndef PRODUCT
......
...@@ -58,14 +58,14 @@ ...@@ -58,14 +58,14 @@
// The proj is the control projection for the not-null case. // The proj is the control projection for the not-null case.
// The val is the pointer being checked for nullness or // The val is the pointer being checked for nullness or
// decodeHeapOop_not_null node if it did not fold into address. // decodeHeapOop_not_null node if it did not fold into address.
void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowed_reasons) { void PhaseCFG::implicit_null_check(Block* block, Node *proj, Node *val, int allowed_reasons) {
// Assume if null check need for 0 offset then always needed // Assume if null check need for 0 offset then always needed
// Intel solaris doesn't support any null checks yet and no // Intel solaris doesn't support any null checks yet and no
// mechanism exists (yet) to set the switches at an os_cpu level // mechanism exists (yet) to set the switches at an os_cpu level
if( !ImplicitNullChecks || MacroAssembler::needs_explicit_null_check(0)) return; if( !ImplicitNullChecks || MacroAssembler::needs_explicit_null_check(0)) return;
// Make sure the ptr-is-null path appears to be uncommon! // Make sure the ptr-is-null path appears to be uncommon!
float f = end()->as_MachIf()->_prob; float f = block->end()->as_MachIf()->_prob;
if( proj->Opcode() == Op_IfTrue ) f = 1.0f - f; if( proj->Opcode() == Op_IfTrue ) f = 1.0f - f;
if( f > PROB_UNLIKELY_MAG(4) ) return; if( f > PROB_UNLIKELY_MAG(4) ) return;
...@@ -75,13 +75,13 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -75,13 +75,13 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
// Get the successor block for if the test ptr is non-null // Get the successor block for if the test ptr is non-null
Block* not_null_block; // this one goes with the proj Block* not_null_block; // this one goes with the proj
Block* null_block; Block* null_block;
if (get_node(number_of_nodes()-1) == proj) { if (block->get_node(block->number_of_nodes()-1) == proj) {
null_block = _succs[0]; null_block = block->_succs[0];
not_null_block = _succs[1]; not_null_block = block->_succs[1];
} else { } else {
assert(get_node(number_of_nodes()-2) == proj, "proj is one or the other"); assert(block->get_node(block->number_of_nodes()-2) == proj, "proj is one or the other");
not_null_block = _succs[0]; not_null_block = block->_succs[0];
null_block = _succs[1]; null_block = block->_succs[1];
} }
while (null_block->is_Empty() == Block::empty_with_goto) { while (null_block->is_Empty() == Block::empty_with_goto) {
null_block = null_block->_succs[0]; null_block = null_block->_succs[0];
...@@ -93,7 +93,7 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -93,7 +93,7 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
// detect failure of this optimization, as in 6366351.) // detect failure of this optimization, as in 6366351.)
{ {
bool found_trap = false; bool found_trap = false;
for (uint i1 = 0; i1 < null_block->_nodes.size(); i1++) { for (uint i1 = 0; i1 < null_block->number_of_nodes(); i1++) {
Node* nn = null_block->get_node(i1); Node* nn = null_block->get_node(i1);
if (nn->is_MachCall() && if (nn->is_MachCall() &&
nn->as_MachCall()->entry_point() == SharedRuntime::uncommon_trap_blob()->entry_point()) { nn->as_MachCall()->entry_point() == SharedRuntime::uncommon_trap_blob()->entry_point()) {
...@@ -237,20 +237,20 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -237,20 +237,20 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
} }
// Check ctrl input to see if the null-check dominates the memory op // Check ctrl input to see if the null-check dominates the memory op
Block *cb = cfg->get_block_for_node(mach); Block *cb = get_block_for_node(mach);
cb = cb->_idom; // Always hoist at least 1 block cb = cb->_idom; // Always hoist at least 1 block
if( !was_store ) { // Stores can be hoisted only one block if( !was_store ) { // Stores can be hoisted only one block
while( cb->_dom_depth > (_dom_depth + 1)) while( cb->_dom_depth > (block->_dom_depth + 1))
cb = cb->_idom; // Hoist loads as far as we want cb = cb->_idom; // Hoist loads as far as we want
// The non-null-block should dominate the memory op, too. Live // The non-null-block should dominate the memory op, too. Live
// range spilling will insert a spill in the non-null-block if it is // range spilling will insert a spill in the non-null-block if it is
// needs to spill the memory op for an implicit null check. // needs to spill the memory op for an implicit null check.
if (cb->_dom_depth == (_dom_depth + 1)) { if (cb->_dom_depth == (block->_dom_depth + 1)) {
if (cb != not_null_block) continue; if (cb != not_null_block) continue;
cb = cb->_idom; cb = cb->_idom;
} }
} }
if( cb != this ) continue; if( cb != block ) continue;
// Found a memory user; see if it can be hoisted to check-block // Found a memory user; see if it can be hoisted to check-block
uint vidx = 0; // Capture index of value into memop uint vidx = 0; // Capture index of value into memop
...@@ -262,8 +262,8 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -262,8 +262,8 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
if( is_decoden ) continue; if( is_decoden ) continue;
} }
// Block of memory-op input // Block of memory-op input
Block *inb = cfg->get_block_for_node(mach->in(j)); Block *inb = get_block_for_node(mach->in(j));
Block *b = this; // Start from nul check Block *b = block; // Start from nul check
while( b != inb && b->_dom_depth > inb->_dom_depth ) while( b != inb && b->_dom_depth > inb->_dom_depth )
b = b->_idom; // search upwards for input b = b->_idom; // search upwards for input
// See if input dominates null check // See if input dominates null check
...@@ -272,28 +272,28 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -272,28 +272,28 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
} }
if( j > 0 ) if( j > 0 )
continue; continue;
Block *mb = cfg->get_block_for_node(mach); Block *mb = get_block_for_node(mach);
// Hoisting stores requires more checks for the anti-dependence case. // Hoisting stores requires more checks for the anti-dependence case.
// Give up hoisting if we have to move the store past any load. // Give up hoisting if we have to move the store past any load.
if( was_store ) { if( was_store ) {
Block *b = mb; // Start searching here for a local load Block *b = mb; // Start searching here for a local load
// mach use (faulting) trying to hoist // mach use (faulting) trying to hoist
// n might be blocker to hoisting // n might be blocker to hoisting
while( b != this ) { while( b != block ) {
uint k; uint k;
for( k = 1; k < b->_nodes.size(); k++ ) { for( k = 1; k < b->number_of_nodes(); k++ ) {
Node *n = b->get_node(k); Node *n = b->get_node(k);
if( n->needs_anti_dependence_check() && if( n->needs_anti_dependence_check() &&
n->in(LoadNode::Memory) == mach->in(StoreNode::Memory) ) n->in(LoadNode::Memory) == mach->in(StoreNode::Memory) )
break; // Found anti-dependent load break; // Found anti-dependent load
} }
if( k < b->_nodes.size() ) if( k < b->number_of_nodes() )
break; // Found anti-dependent load break; // Found anti-dependent load
// Make sure control does not do a merge (would have to check allpaths) // Make sure control does not do a merge (would have to check allpaths)
if( b->num_preds() != 2 ) break; if( b->num_preds() != 2 ) break;
b = cfg->get_block_for_node(b->pred(1)); // Move up to predecessor block b = get_block_for_node(b->pred(1)); // Move up to predecessor block
} }
if( b != this ) continue; if( b != block ) continue;
} }
// Make sure this memory op is not already being used for a NullCheck // Make sure this memory op is not already being used for a NullCheck
...@@ -303,7 +303,7 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -303,7 +303,7 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
// Found a candidate! Pick one with least dom depth - the highest // Found a candidate! Pick one with least dom depth - the highest
// in the dom tree should be closest to the null check. // in the dom tree should be closest to the null check.
if (best == NULL || cfg->get_block_for_node(mach)->_dom_depth < cfg->get_block_for_node(best)->_dom_depth) { if (best == NULL || get_block_for_node(mach)->_dom_depth < get_block_for_node(best)->_dom_depth) {
best = mach; best = mach;
bidx = vidx; bidx = vidx;
} }
...@@ -319,46 +319,45 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -319,46 +319,45 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
if( is_decoden ) { if( is_decoden ) {
// Check if we need to hoist decodeHeapOop_not_null first. // Check if we need to hoist decodeHeapOop_not_null first.
Block *valb = cfg->get_block_for_node(val); Block *valb = get_block_for_node(val);
if( this != valb && this->_dom_depth < valb->_dom_depth ) { if( block != valb && block->_dom_depth < valb->_dom_depth ) {
// Hoist it up to the end of the test block. // Hoist it up to the end of the test block.
valb->find_remove(val); valb->find_remove(val);
this->add_inst(val); block->add_inst(val);
cfg->map_node_to_block(val, this); map_node_to_block(val, block);
// DecodeN on x86 may kill flags. Check for flag-killing projections // DecodeN on x86 may kill flags. Check for flag-killing projections
// that also need to be hoisted. // that also need to be hoisted.
for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) { for (DUIterator_Fast jmax, j = val->fast_outs(jmax); j < jmax; j++) {
Node* n = val->fast_out(j); Node* n = val->fast_out(j);
if( n->is_MachProj() ) { if( n->is_MachProj() ) {
cfg->get_block_for_node(n)->find_remove(n); get_block_for_node(n)->find_remove(n);
this->add_inst(n); block->add_inst(n);
cfg->map_node_to_block(n, this); map_node_to_block(n, block);
} }
} }
} }
} }
// Hoist the memory candidate up to the end of the test block. // Hoist the memory candidate up to the end of the test block.
Block *old_block = cfg->get_block_for_node(best); Block *old_block = get_block_for_node(best);
old_block->find_remove(best); old_block->find_remove(best);
add_inst(best); block->add_inst(best);
cfg->map_node_to_block(best, this); map_node_to_block(best, block);
// Move the control dependence // Move the control dependence
if (best->in(0) && best->in(0) == old_block->head()) if (best->in(0) && best->in(0) == old_block->head())
best->set_req(0, head()); best->set_req(0, block->head());
// Check for flag-killing projections that also need to be hoisted // Check for flag-killing projections that also need to be hoisted
// Should be DU safe because no edge updates. // Should be DU safe because no edge updates.
for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) { for (DUIterator_Fast jmax, j = best->fast_outs(jmax); j < jmax; j++) {
Node* n = best->fast_out(j); Node* n = best->fast_out(j);
if( n->is_MachProj() ) { if( n->is_MachProj() ) {
cfg->get_block_for_node(n)->find_remove(n); get_block_for_node(n)->find_remove(n);
add_inst(n); block->add_inst(n);
cfg->map_node_to_block(n, this); map_node_to_block(n, block);
} }
} }
Compile *C = cfg->C;
// proj==Op_True --> ne test; proj==Op_False --> eq test. // proj==Op_True --> ne test; proj==Op_False --> eq test.
// One of two graph shapes got matched: // One of two graph shapes got matched:
// (IfTrue (If (Bool NE (CmpP ptr NULL)))) // (IfTrue (If (Bool NE (CmpP ptr NULL))))
...@@ -368,10 +367,10 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -368,10 +367,10 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
// We need to flip the projections to keep the same semantics. // We need to flip the projections to keep the same semantics.
if( proj->Opcode() == Op_IfTrue ) { if( proj->Opcode() == Op_IfTrue ) {
// Swap order of projections in basic block to swap branch targets // Swap order of projections in basic block to swap branch targets
Node *tmp1 = get_node(end_idx()+1); Node *tmp1 = block->get_node(block->end_idx()+1);
Node *tmp2 = get_node(end_idx()+2); Node *tmp2 = block->get_node(block->end_idx()+2);
_nodes.map(end_idx()+1, tmp2); block->map_node(tmp2, block->end_idx()+1);
_nodes.map(end_idx()+2, tmp1); block->map_node(tmp1, block->end_idx()+2);
Node *tmp = new (C) Node(C->top()); // Use not NULL input Node *tmp = new (C) Node(C->top()); // Use not NULL input
tmp1->replace_by(tmp); tmp1->replace_by(tmp);
tmp2->replace_by(tmp1); tmp2->replace_by(tmp1);
...@@ -384,8 +383,8 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -384,8 +383,8 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
// it as well. // it as well.
Node *old_tst = proj->in(0); Node *old_tst = proj->in(0);
MachNode *nul_chk = new (C) MachNullCheckNode(old_tst->in(0),best,bidx); MachNode *nul_chk = new (C) MachNullCheckNode(old_tst->in(0),best,bidx);
_nodes.map(end_idx(),nul_chk); block->map_node(nul_chk, block->end_idx());
cfg->map_node_to_block(nul_chk, this); map_node_to_block(nul_chk, block);
// Redirect users of old_test to nul_chk // Redirect users of old_test to nul_chk
for (DUIterator_Last i2min, i2 = old_tst->last_outs(i2min); i2 >= i2min; --i2) for (DUIterator_Last i2min, i2 = old_tst->last_outs(i2min); i2 >= i2min; --i2)
old_tst->last_out(i2)->set_req(0, nul_chk); old_tst->last_out(i2)->set_req(0, nul_chk);
...@@ -393,8 +392,8 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -393,8 +392,8 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
for (uint i3 = 0; i3 < old_tst->req(); i3++) for (uint i3 = 0; i3 < old_tst->req(); i3++)
old_tst->set_req(i3, NULL); old_tst->set_req(i3, NULL);
cfg->latency_from_uses(nul_chk); latency_from_uses(nul_chk);
cfg->latency_from_uses(best); latency_from_uses(best);
} }
...@@ -408,7 +407,7 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe ...@@ -408,7 +407,7 @@ void Block::implicit_null_check(PhaseCFG *cfg, Node *proj, Node *val, int allowe
// remaining cases (most), choose the instruction with the greatest latency // remaining cases (most), choose the instruction with the greatest latency
// (that is, the most number of pseudo-cycles required to the end of the // (that is, the most number of pseudo-cycles required to the end of the
// routine). If there is a tie, choose the instruction with the most inputs. // routine). If there is a tie, choose the instruction with the most inputs.
Node *Block::select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &ready_cnt, VectorSet &next_call, uint sched_slot) { Node* PhaseCFG::select(Block* block, Node_List &worklist, GrowableArray<int> &ready_cnt, VectorSet &next_call, uint sched_slot) {
// If only a single entry on the stack, use it // If only a single entry on the stack, use it
uint cnt = worklist.size(); uint cnt = worklist.size();
...@@ -442,7 +441,7 @@ Node *Block::select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &read ...@@ -442,7 +441,7 @@ Node *Block::select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &read
} }
// Final call in a block must be adjacent to 'catch' // Final call in a block must be adjacent to 'catch'
Node *e = end(); Node *e = block->end();
if( e->is_Catch() && e->in(0)->in(0) == n ) if( e->is_Catch() && e->in(0)->in(0) == n )
continue; continue;
...@@ -468,7 +467,7 @@ Node *Block::select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &read ...@@ -468,7 +467,7 @@ Node *Block::select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &read
Node* use = n->fast_out(j); Node* use = n->fast_out(j);
// The use is a conditional branch, make them adjacent // The use is a conditional branch, make them adjacent
if (use->is_MachIf() && cfg->get_block_for_node(use) == this) { if (use->is_MachIf() && get_block_for_node(use) == block) {
found_machif = true; found_machif = true;
break; break;
} }
...@@ -501,7 +500,7 @@ Node *Block::select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &read ...@@ -501,7 +500,7 @@ Node *Block::select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &read
n_choice = 1; n_choice = 1;
} }
uint n_latency = cfg->get_latency_for_node(n); uint n_latency = get_latency_for_node(n);
uint n_score = n->req(); // Many inputs get high score to break ties uint n_score = n->req(); // Many inputs get high score to break ties
// Keep best latency found // Keep best latency found
...@@ -529,13 +528,13 @@ Node *Block::select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &read ...@@ -529,13 +528,13 @@ Node *Block::select(PhaseCFG *cfg, Node_List &worklist, GrowableArray<int> &read
//------------------------------set_next_call---------------------------------- //------------------------------set_next_call----------------------------------
void Block::set_next_call( Node *n, VectorSet &next_call, PhaseCFG* cfg) { void PhaseCFG::set_next_call(Block* block, Node* n, VectorSet& next_call) {
if( next_call.test_set(n->_idx) ) return; if( next_call.test_set(n->_idx) ) return;
for( uint i=0; i<n->len(); i++ ) { for( uint i=0; i<n->len(); i++ ) {
Node *m = n->in(i); Node *m = n->in(i);
if( !m ) continue; // must see all nodes in block that precede call if( !m ) continue; // must see all nodes in block that precede call
if (cfg->get_block_for_node(m) == this) { if (get_block_for_node(m) == block) {
set_next_call(m, next_call, cfg); set_next_call(block, m, next_call);
} }
} }
} }
...@@ -546,12 +545,12 @@ void Block::set_next_call( Node *n, VectorSet &next_call, PhaseCFG* cfg) { ...@@ -546,12 +545,12 @@ void Block::set_next_call( Node *n, VectorSet &next_call, PhaseCFG* cfg) {
// next subroutine call get priority - basically it moves things NOT needed // next subroutine call get priority - basically it moves things NOT needed
// for the next call till after the call. This prevents me from trying to // for the next call till after the call. This prevents me from trying to
// carry lots of stuff live across a call. // carry lots of stuff live across a call.
void Block::needed_for_next_call(Node *this_call, VectorSet &next_call, PhaseCFG* cfg) { void PhaseCFG::needed_for_next_call(Block* block, Node* this_call, VectorSet& next_call) {
// Find the next control-defining Node in this block // Find the next control-defining Node in this block
Node* call = NULL; Node* call = NULL;
for (DUIterator_Fast imax, i = this_call->fast_outs(imax); i < imax; i++) { for (DUIterator_Fast imax, i = this_call->fast_outs(imax); i < imax; i++) {
Node* m = this_call->fast_out(i); Node* m = this_call->fast_out(i);
if(cfg->get_block_for_node(m) == this && // Local-block user if(get_block_for_node(m) == block && // Local-block user
m != this_call && // Not self-start node m != this_call && // Not self-start node
m->is_MachCall() ) m->is_MachCall() )
call = m; call = m;
...@@ -559,11 +558,12 @@ void Block::needed_for_next_call(Node *this_call, VectorSet &next_call, PhaseCFG ...@@ -559,11 +558,12 @@ void Block::needed_for_next_call(Node *this_call, VectorSet &next_call, PhaseCFG
} }
if (call == NULL) return; // No next call (e.g., block end is near) if (call == NULL) return; // No next call (e.g., block end is near)
// Set next-call for all inputs to this call // Set next-call for all inputs to this call
set_next_call(call, next_call, cfg); set_next_call(block, call, next_call);
} }
//------------------------------add_call_kills------------------------------------- //------------------------------add_call_kills-------------------------------------
void Block::add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_policy, bool exclude_soe) { // helper function that adds caller save registers to MachProjNode
static void add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_policy, bool exclude_soe) {
// Fill in the kill mask for the call // Fill in the kill mask for the call
for( OptoReg::Name r = OptoReg::Name(0); r < _last_Mach_Reg; r=OptoReg::add(r,1) ) { for( OptoReg::Name r = OptoReg::Name(0); r < _last_Mach_Reg; r=OptoReg::add(r,1) ) {
if( !regs.Member(r) ) { // Not already defined by the call if( !regs.Member(r) ) { // Not already defined by the call
...@@ -579,7 +579,7 @@ void Block::add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_p ...@@ -579,7 +579,7 @@ void Block::add_call_kills(MachProjNode *proj, RegMask& regs, const char* save_p
//------------------------------sched_call------------------------------------- //------------------------------sched_call-------------------------------------
uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_List &worklist, GrowableArray<int> &ready_cnt, MachCallNode *mcall, VectorSet &next_call ) { uint PhaseCFG::sched_call(Block* block, uint node_cnt, Node_List& worklist, GrowableArray<int>& ready_cnt, MachCallNode* mcall, VectorSet& next_call) {
RegMask regs; RegMask regs;
// Schedule all the users of the call right now. All the users are // Schedule all the users of the call right now. All the users are
...@@ -592,18 +592,18 @@ uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_Lis ...@@ -592,18 +592,18 @@ uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_Lis
ready_cnt.at_put(n->_idx, n_cnt); ready_cnt.at_put(n->_idx, n_cnt);
assert( n_cnt == 0, "" ); assert( n_cnt == 0, "" );
// Schedule next to call // Schedule next to call
_nodes.map(node_cnt++, n); block->map_node(n, node_cnt++);
// Collect defined registers // Collect defined registers
regs.OR(n->out_RegMask()); regs.OR(n->out_RegMask());
// Check for scheduling the next control-definer // Check for scheduling the next control-definer
if( n->bottom_type() == Type::CONTROL ) if( n->bottom_type() == Type::CONTROL )
// Warm up next pile of heuristic bits // Warm up next pile of heuristic bits
needed_for_next_call(n, next_call, cfg); needed_for_next_call(block, n, next_call);
// Children of projections are now all ready // Children of projections are now all ready
for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) { for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
Node* m = n->fast_out(j); // Get user Node* m = n->fast_out(j); // Get user
if(cfg->get_block_for_node(m) != this) { if(get_block_for_node(m) != block) {
continue; continue;
} }
if( m->is_Phi() ) continue; if( m->is_Phi() ) continue;
...@@ -617,14 +617,14 @@ uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_Lis ...@@ -617,14 +617,14 @@ uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_Lis
// Act as if the call defines the Frame Pointer. // Act as if the call defines the Frame Pointer.
// Certainly the FP is alive and well after the call. // Certainly the FP is alive and well after the call.
regs.Insert(matcher.c_frame_pointer()); regs.Insert(_matcher.c_frame_pointer());
// Set all registers killed and not already defined by the call. // Set all registers killed and not already defined by the call.
uint r_cnt = mcall->tf()->range()->cnt(); uint r_cnt = mcall->tf()->range()->cnt();
int op = mcall->ideal_Opcode(); int op = mcall->ideal_Opcode();
MachProjNode *proj = new (matcher.C) MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj ); MachProjNode *proj = new (C) MachProjNode( mcall, r_cnt+1, RegMask::Empty, MachProjNode::fat_proj );
cfg->map_node_to_block(proj, this); map_node_to_block(proj, block);
insert_node(proj, node_cnt++); block->insert_node(proj, node_cnt++);
// Select the right register save policy. // Select the right register save policy.
const char * save_policy; const char * save_policy;
...@@ -633,13 +633,13 @@ uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_Lis ...@@ -633,13 +633,13 @@ uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_Lis
case Op_CallLeaf: case Op_CallLeaf:
case Op_CallLeafNoFP: case Op_CallLeafNoFP:
// Calling C code so use C calling convention // Calling C code so use C calling convention
save_policy = matcher._c_reg_save_policy; save_policy = _matcher._c_reg_save_policy;
break; break;
case Op_CallStaticJava: case Op_CallStaticJava:
case Op_CallDynamicJava: case Op_CallDynamicJava:
// Calling Java code so use Java calling convention // Calling Java code so use Java calling convention
save_policy = matcher._register_save_policy; save_policy = _matcher._register_save_policy;
break; break;
default: default:
...@@ -674,44 +674,46 @@ uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_Lis ...@@ -674,44 +674,46 @@ uint Block::sched_call( Matcher &matcher, PhaseCFG* cfg, uint node_cnt, Node_Lis
//------------------------------schedule_local--------------------------------- //------------------------------schedule_local---------------------------------
// Topological sort within a block. Someday become a real scheduler. // Topological sort within a block. Someday become a real scheduler.
bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &ready_cnt, VectorSet &next_call) { bool PhaseCFG::schedule_local(Block* block, GrowableArray<int>& ready_cnt, VectorSet& next_call) {
// Already "sorted" are the block start Node (as the first entry), and // Already "sorted" are the block start Node (as the first entry), and
// the block-ending Node and any trailing control projections. We leave // the block-ending Node and any trailing control projections. We leave
// these alone. PhiNodes and ParmNodes are made to follow the block start // these alone. PhiNodes and ParmNodes are made to follow the block start
// Node. Everything else gets topo-sorted. // Node. Everything else gets topo-sorted.
#ifndef PRODUCT #ifndef PRODUCT
if (cfg->trace_opto_pipelining()) { if (trace_opto_pipelining()) {
tty->print_cr("# --- schedule_local B%d, before: ---", _pre_order); tty->print_cr("# --- schedule_local B%d, before: ---", block->_pre_order);
for (uint i = 0;i < _nodes.size();i++) { for (uint i = 0;i < block->number_of_nodes(); i++) {
tty->print("# "); tty->print("# ");
get_node(i)->fast_dump(); block->get_node(i)->fast_dump();
} }
tty->print_cr("#"); tty->print_cr("#");
} }
#endif #endif
// RootNode is already sorted // RootNode is already sorted
if( _nodes.size() == 1 ) return true; if (block->number_of_nodes() == 1) {
return true;
}
// Move PhiNodes and ParmNodes from 1 to cnt up to the start // Move PhiNodes and ParmNodes from 1 to cnt up to the start
uint node_cnt = end_idx(); uint node_cnt = block->end_idx();
uint phi_cnt = 1; uint phi_cnt = 1;
uint i; uint i;
for( i = 1; i<node_cnt; i++ ) { // Scan for Phi for( i = 1; i<node_cnt; i++ ) { // Scan for Phi
Node *n = get_node(i); Node *n = block->get_node(i);
if( n->is_Phi() || // Found a PhiNode or ParmNode if( n->is_Phi() || // Found a PhiNode or ParmNode
(n->is_Proj() && n->in(0) == head()) ) { (n->is_Proj() && n->in(0) == block->head()) ) {
// Move guy at 'phi_cnt' to the end; makes a hole at phi_cnt // Move guy at 'phi_cnt' to the end; makes a hole at phi_cnt
_nodes.map(i,get_node(phi_cnt)); block->map_node(block->get_node(phi_cnt), i);
_nodes.map(phi_cnt++,n); // swap Phi/Parm up front block->map_node(n, phi_cnt++); // swap Phi/Parm up front
} else { // All others } else { // All others
// Count block-local inputs to 'n' // Count block-local inputs to 'n'
uint cnt = n->len(); // Input count uint cnt = n->len(); // Input count
uint local = 0; uint local = 0;
for( uint j=0; j<cnt; j++ ) { for( uint j=0; j<cnt; j++ ) {
Node *m = n->in(j); Node *m = n->in(j);
if( m && cfg->get_block_for_node(m) == this && !m->is_top() ) if( m && get_block_for_node(m) == block && !m->is_top() )
local++; // One more block-local input local++; // One more block-local input
} }
ready_cnt.at_put(n->_idx, local); // Count em up ready_cnt.at_put(n->_idx, local); // Count em up
...@@ -723,7 +725,7 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> & ...@@ -723,7 +725,7 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &
for (uint prec = n->req(); prec < n->len(); prec++) { for (uint prec = n->req(); prec < n->len(); prec++) {
Node* oop_store = n->in(prec); Node* oop_store = n->in(prec);
if (oop_store != NULL) { if (oop_store != NULL) {
assert(cfg->get_block_for_node(oop_store)->_dom_depth <= this->_dom_depth, "oop_store must dominate card-mark"); assert(get_block_for_node(oop_store)->_dom_depth <= block->_dom_depth, "oop_store must dominate card-mark");
} }
} }
} }
...@@ -747,16 +749,16 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> & ...@@ -747,16 +749,16 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &
} }
} }
} }
for(uint i2=i; i2<_nodes.size(); i2++ ) // Trailing guys get zapped count for(uint i2=i; i2< block->number_of_nodes(); i2++ ) // Trailing guys get zapped count
ready_cnt.at_put(get_node(i2)->_idx, 0); ready_cnt.at_put(block->get_node(i2)->_idx, 0);
// All the prescheduled guys do not hold back internal nodes // All the prescheduled guys do not hold back internal nodes
uint i3; uint i3;
for(i3 = 0; i3<phi_cnt; i3++ ) { // For all pre-scheduled for(i3 = 0; i3<phi_cnt; i3++ ) { // For all pre-scheduled
Node *n = get_node(i3); // Get pre-scheduled Node *n = block->get_node(i3); // Get pre-scheduled
for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) { for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
Node* m = n->fast_out(j); Node* m = n->fast_out(j);
if (cfg->get_block_for_node(m) == this) { // Local-block user if (get_block_for_node(m) == block) { // Local-block user
int m_cnt = ready_cnt.at(m->_idx)-1; int m_cnt = ready_cnt.at(m->_idx)-1;
ready_cnt.at_put(m->_idx, m_cnt); // Fix ready count ready_cnt.at_put(m->_idx, m_cnt); // Fix ready count
} }
...@@ -767,7 +769,7 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> & ...@@ -767,7 +769,7 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &
// Make a worklist // Make a worklist
Node_List worklist; Node_List worklist;
for(uint i4=i3; i4<node_cnt; i4++ ) { // Put ready guys on worklist for(uint i4=i3; i4<node_cnt; i4++ ) { // Put ready guys on worklist
Node *m = get_node(i4); Node *m = block->get_node(i4);
if( !ready_cnt.at(m->_idx) ) { // Zero ready count? if( !ready_cnt.at(m->_idx) ) { // Zero ready count?
if (m->is_iteratively_computed()) { if (m->is_iteratively_computed()) {
// Push induction variable increments last to allow other uses // Push induction variable increments last to allow other uses
...@@ -789,15 +791,15 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> & ...@@ -789,15 +791,15 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &
} }
// Warm up the 'next_call' heuristic bits // Warm up the 'next_call' heuristic bits
needed_for_next_call(head(), next_call, cfg); needed_for_next_call(block, block->head(), next_call);
#ifndef PRODUCT #ifndef PRODUCT
if (cfg->trace_opto_pipelining()) { if (trace_opto_pipelining()) {
for (uint j=0; j<_nodes.size(); j++) { for (uint j=0; j< block->number_of_nodes(); j++) {
Node *n = get_node(j); Node *n = block->get_node(j);
int idx = n->_idx; int idx = n->_idx;
tty->print("# ready cnt:%3d ", ready_cnt.at(idx)); tty->print("# ready cnt:%3d ", ready_cnt.at(idx));
tty->print("latency:%3d ", cfg->get_latency_for_node(n)); tty->print("latency:%3d ", get_latency_for_node(n));
tty->print("%4d: %s\n", idx, n->Name()); tty->print("%4d: %s\n", idx, n->Name());
} }
} }
...@@ -808,7 +810,7 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> & ...@@ -808,7 +810,7 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &
while( worklist.size() ) { // Worklist is not ready while( worklist.size() ) { // Worklist is not ready
#ifndef PRODUCT #ifndef PRODUCT
if (cfg->trace_opto_pipelining()) { if (trace_opto_pipelining()) {
tty->print("# ready list:"); tty->print("# ready list:");
for( uint i=0; i<worklist.size(); i++ ) { // Inspect entire worklist for( uint i=0; i<worklist.size(); i++ ) { // Inspect entire worklist
Node *n = worklist[i]; // Get Node on worklist Node *n = worklist[i]; // Get Node on worklist
...@@ -819,13 +821,13 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> & ...@@ -819,13 +821,13 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &
#endif #endif
// Select and pop a ready guy from worklist // Select and pop a ready guy from worklist
Node* n = select(cfg, worklist, ready_cnt, next_call, phi_cnt); Node* n = select(block, worklist, ready_cnt, next_call, phi_cnt);
_nodes.map(phi_cnt++,n); // Schedule him next block->map_node(n, phi_cnt++); // Schedule him next
#ifndef PRODUCT #ifndef PRODUCT
if (cfg->trace_opto_pipelining()) { if (trace_opto_pipelining()) {
tty->print("# select %d: %s", n->_idx, n->Name()); tty->print("# select %d: %s", n->_idx, n->Name());
tty->print(", latency:%d", cfg->get_latency_for_node(n)); tty->print(", latency:%d", get_latency_for_node(n));
n->dump(); n->dump();
if (Verbose) { if (Verbose) {
tty->print("# ready list:"); tty->print("# ready list:");
...@@ -840,26 +842,26 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> & ...@@ -840,26 +842,26 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &
#endif #endif
if( n->is_MachCall() ) { if( n->is_MachCall() ) {
MachCallNode *mcall = n->as_MachCall(); MachCallNode *mcall = n->as_MachCall();
phi_cnt = sched_call(matcher, cfg, phi_cnt, worklist, ready_cnt, mcall, next_call); phi_cnt = sched_call(block, phi_cnt, worklist, ready_cnt, mcall, next_call);
continue; continue;
} }
if (n->is_Mach() && n->as_Mach()->has_call()) { if (n->is_Mach() && n->as_Mach()->has_call()) {
RegMask regs; RegMask regs;
regs.Insert(matcher.c_frame_pointer()); regs.Insert(_matcher.c_frame_pointer());
regs.OR(n->out_RegMask()); regs.OR(n->out_RegMask());
MachProjNode *proj = new (matcher.C) MachProjNode( n, 1, RegMask::Empty, MachProjNode::fat_proj ); MachProjNode *proj = new (C) MachProjNode( n, 1, RegMask::Empty, MachProjNode::fat_proj );
cfg->map_node_to_block(proj, this); map_node_to_block(proj, block);
insert_node(proj, phi_cnt++); block->insert_node(proj, phi_cnt++);
add_call_kills(proj, regs, matcher._c_reg_save_policy, false); add_call_kills(proj, regs, _matcher._c_reg_save_policy, false);
} }
// Children are now all ready // Children are now all ready
for (DUIterator_Fast i5max, i5 = n->fast_outs(i5max); i5 < i5max; i5++) { for (DUIterator_Fast i5max, i5 = n->fast_outs(i5max); i5 < i5max; i5++) {
Node* m = n->fast_out(i5); // Get user Node* m = n->fast_out(i5); // Get user
if (cfg->get_block_for_node(m) != this) { if (get_block_for_node(m) != block) {
continue; continue;
} }
if( m->is_Phi() ) continue; if( m->is_Phi() ) continue;
...@@ -874,9 +876,8 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> & ...@@ -874,9 +876,8 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &
} }
} }
if( phi_cnt != end_idx() ) { if( phi_cnt != block->end_idx() ) {
// did not schedule all. Retry, Bailout, or Die // did not schedule all. Retry, Bailout, or Die
Compile* C = matcher.C;
if (C->subsume_loads() == true && !C->failing()) { if (C->subsume_loads() == true && !C->failing()) {
// Retry with subsume_loads == false // Retry with subsume_loads == false
// If this is the first failure, the sentinel string will "stick" // If this is the first failure, the sentinel string will "stick"
...@@ -888,12 +889,12 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> & ...@@ -888,12 +889,12 @@ bool Block::schedule_local(PhaseCFG *cfg, Matcher &matcher, GrowableArray<int> &
} }
#ifndef PRODUCT #ifndef PRODUCT
if (cfg->trace_opto_pipelining()) { if (trace_opto_pipelining()) {
tty->print_cr("#"); tty->print_cr("#");
tty->print_cr("# after schedule_local"); tty->print_cr("# after schedule_local");
for (uint i = 0;i < _nodes.size();i++) { for (uint i = 0;i < block->number_of_nodes();i++) {
tty->print("# "); tty->print("# ");
get_node(i)->fast_dump(); block->get_node(i)->fast_dump();
} }
tty->cr(); tty->cr();
} }
...@@ -919,7 +920,7 @@ static void catch_cleanup_fix_all_inputs(Node *use, Node *old_def, Node *new_def ...@@ -919,7 +920,7 @@ static void catch_cleanup_fix_all_inputs(Node *use, Node *old_def, Node *new_def
} }
//------------------------------catch_cleanup_find_cloned_def------------------ //------------------------------catch_cleanup_find_cloned_def------------------
static Node *catch_cleanup_find_cloned_def(Block *use_blk, Node *def, Block *def_blk, PhaseCFG* cfg, int n_clone_idx) { Node* PhaseCFG::catch_cleanup_find_cloned_def(Block *use_blk, Node *def, Block *def_blk, int n_clone_idx) {
assert( use_blk != def_blk, "Inter-block cleanup only"); assert( use_blk != def_blk, "Inter-block cleanup only");
// The use is some block below the Catch. Find and return the clone of the def // The use is some block below the Catch. Find and return the clone of the def
...@@ -945,8 +946,8 @@ static Node *catch_cleanup_find_cloned_def(Block *use_blk, Node *def, Block *def ...@@ -945,8 +946,8 @@ static Node *catch_cleanup_find_cloned_def(Block *use_blk, Node *def, Block *def
// PhiNode, the PhiNode uses from the def and IT's uses need fixup. // PhiNode, the PhiNode uses from the def and IT's uses need fixup.
Node_Array inputs = new Node_List(Thread::current()->resource_area()); Node_Array inputs = new Node_List(Thread::current()->resource_area());
for(uint k = 1; k < use_blk->num_preds(); k++) { for(uint k = 1; k < use_blk->num_preds(); k++) {
Block* block = cfg->get_block_for_node(use_blk->pred(k)); Block* block = get_block_for_node(use_blk->pred(k));
inputs.map(k, catch_cleanup_find_cloned_def(block, def, def_blk, cfg, n_clone_idx)); inputs.map(k, catch_cleanup_find_cloned_def(block, def, def_blk, n_clone_idx));
} }
// Check to see if the use_blk already has an identical phi inserted. // Check to see if the use_blk already has an identical phi inserted.
...@@ -968,7 +969,7 @@ static Node *catch_cleanup_find_cloned_def(Block *use_blk, Node *def, Block *def ...@@ -968,7 +969,7 @@ static Node *catch_cleanup_find_cloned_def(Block *use_blk, Node *def, Block *def
if (fixup == NULL) { if (fixup == NULL) {
Node *new_phi = PhiNode::make(use_blk->head(), def); Node *new_phi = PhiNode::make(use_blk->head(), def);
use_blk->insert_node(new_phi, 1); use_blk->insert_node(new_phi, 1);
cfg->map_node_to_block(new_phi, use_blk); map_node_to_block(new_phi, use_blk);
for (uint k = 1; k < use_blk->num_preds(); k++) { for (uint k = 1; k < use_blk->num_preds(); k++) {
new_phi->set_req(k, inputs[k]); new_phi->set_req(k, inputs[k]);
} }
...@@ -1008,25 +1009,25 @@ static void catch_cleanup_intra_block(Node *use, Node *def, Block *blk, int beg, ...@@ -1008,25 +1009,25 @@ static void catch_cleanup_intra_block(Node *use, Node *def, Block *blk, int beg,
//------------------------------catch_cleanup_inter_block--------------------- //------------------------------catch_cleanup_inter_block---------------------
// Fix all input edges in use that reference "def". The use is in a different // Fix all input edges in use that reference "def". The use is in a different
// block than the def. // block than the def.
static void catch_cleanup_inter_block(Node *use, Block *use_blk, Node *def, Block *def_blk, PhaseCFG* cfg, int n_clone_idx) { void PhaseCFG::catch_cleanup_inter_block(Node *use, Block *use_blk, Node *def, Block *def_blk, int n_clone_idx) {
if( !use_blk ) return; // Can happen if the use is a precedence edge if( !use_blk ) return; // Can happen if the use is a precedence edge
Node *new_def = catch_cleanup_find_cloned_def(use_blk, def, def_blk, cfg, n_clone_idx); Node *new_def = catch_cleanup_find_cloned_def(use_blk, def, def_blk, n_clone_idx);
catch_cleanup_fix_all_inputs(use, def, new_def); catch_cleanup_fix_all_inputs(use, def, new_def);
} }
//------------------------------call_catch_cleanup----------------------------- //------------------------------call_catch_cleanup-----------------------------
// If we inserted any instructions between a Call and his CatchNode, // If we inserted any instructions between a Call and his CatchNode,
// clone the instructions on all paths below the Catch. // clone the instructions on all paths below the Catch.
void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) { void PhaseCFG::call_catch_cleanup(Block* block) {
// End of region to clone // End of region to clone
uint end = end_idx(); uint end = block->end_idx();
if( !get_node(end)->is_Catch() ) return; if( !block->get_node(end)->is_Catch() ) return;
// Start of region to clone // Start of region to clone
uint beg = end; uint beg = end;
while(!get_node(beg-1)->is_MachProj() || while(!block->get_node(beg-1)->is_MachProj() ||
!get_node(beg-1)->in(0)->is_MachCall() ) { !block->get_node(beg-1)->in(0)->is_MachCall() ) {
beg--; beg--;
assert(beg > 0,"Catch cleanup walking beyond block boundary"); assert(beg > 0,"Catch cleanup walking beyond block boundary");
} }
...@@ -1035,15 +1036,15 @@ void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) { ...@@ -1035,15 +1036,15 @@ void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) {
// Clone along all Catch output paths. Clone area between the 'beg' and // Clone along all Catch output paths. Clone area between the 'beg' and
// 'end' indices. // 'end' indices.
for( uint i = 0; i < _num_succs; i++ ) { for( uint i = 0; i < block->_num_succs; i++ ) {
Block *sb = _succs[i]; Block *sb = block->_succs[i];
// Clone the entire area; ignoring the edge fixup for now. // Clone the entire area; ignoring the edge fixup for now.
for( uint j = end; j > beg; j-- ) { for( uint j = end; j > beg; j-- ) {
// It is safe here to clone a node with anti_dependence // It is safe here to clone a node with anti_dependence
// since clones dominate on each path. // since clones dominate on each path.
Node *clone = get_node(j-1)->clone(); Node *clone = block->get_node(j-1)->clone();
sb->insert_node(clone, 1); sb->insert_node(clone, 1);
cfg->map_node_to_block(clone, sb); map_node_to_block(clone, sb);
} }
} }
...@@ -1051,7 +1052,7 @@ void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) { ...@@ -1051,7 +1052,7 @@ void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) {
// Fixup edges. Check the def-use info per cloned Node // Fixup edges. Check the def-use info per cloned Node
for(uint i2 = beg; i2 < end; i2++ ) { for(uint i2 = beg; i2 < end; i2++ ) {
uint n_clone_idx = i2-beg+1; // Index of clone of n in each successor block uint n_clone_idx = i2-beg+1; // Index of clone of n in each successor block
Node *n = get_node(i2); // Node that got cloned Node *n = block->get_node(i2); // Node that got cloned
// Need DU safe iterator because of edge manipulation in calls. // Need DU safe iterator because of edge manipulation in calls.
Unique_Node_List *out = new Unique_Node_List(Thread::current()->resource_area()); Unique_Node_List *out = new Unique_Node_List(Thread::current()->resource_area());
for (DUIterator_Fast j1max, j1 = n->fast_outs(j1max); j1 < j1max; j1++) { for (DUIterator_Fast j1max, j1 = n->fast_outs(j1max); j1 < j1max; j1++) {
...@@ -1060,19 +1061,19 @@ void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) { ...@@ -1060,19 +1061,19 @@ void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) {
uint max = out->size(); uint max = out->size();
for (uint j = 0; j < max; j++) {// For all users for (uint j = 0; j < max; j++) {// For all users
Node *use = out->pop(); Node *use = out->pop();
Block *buse = cfg->get_block_for_node(use); Block *buse = get_block_for_node(use);
if( use->is_Phi() ) { if( use->is_Phi() ) {
for( uint k = 1; k < use->req(); k++ ) for( uint k = 1; k < use->req(); k++ )
if( use->in(k) == n ) { if( use->in(k) == n ) {
Block* block = cfg->get_block_for_node(buse->pred(k)); Block* b = get_block_for_node(buse->pred(k));
Node *fixup = catch_cleanup_find_cloned_def(block, n, this, cfg, n_clone_idx); Node *fixup = catch_cleanup_find_cloned_def(b, n, block, n_clone_idx);
use->set_req(k, fixup); use->set_req(k, fixup);
} }
} else { } else {
if (this == buse) { if (block == buse) {
catch_cleanup_intra_block(use, n, this, beg, n_clone_idx); catch_cleanup_intra_block(use, n, block, beg, n_clone_idx);
} else { } else {
catch_cleanup_inter_block(use, buse, n, this, cfg, n_clone_idx); catch_cleanup_inter_block(use, buse, n, block, n_clone_idx);
} }
} }
} // End for all users } // End for all users
...@@ -1081,13 +1082,13 @@ void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) { ...@@ -1081,13 +1082,13 @@ void Block::call_catch_cleanup(PhaseCFG* cfg, Compile* C) {
// Remove the now-dead cloned ops // Remove the now-dead cloned ops
for(uint i3 = beg; i3 < end; i3++ ) { for(uint i3 = beg; i3 < end; i3++ ) {
get_node(beg)->disconnect_inputs(NULL, C); block->get_node(beg)->disconnect_inputs(NULL, C);
remove_node(beg); block->remove_node(beg);
} }
// If the successor blocks have a CreateEx node, move it back to the top // If the successor blocks have a CreateEx node, move it back to the top
for(uint i4 = 0; i4 < _num_succs; i4++ ) { for(uint i4 = 0; i4 < block->_num_succs; i4++ ) {
Block *sb = _succs[i4]; Block *sb = block->_succs[i4];
uint new_cnt = end - beg; uint new_cnt = end - beg;
// Remove any newly created, but dead, nodes. // Remove any newly created, but dead, nodes.
for( uint j = new_cnt; j > 0; j-- ) { for( uint j = new_cnt; j > 0; j-- ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册