Skip to content
Permalink
Browse files
8274328: C2: Redundant CFG edges fixup in block ordering
Reviewed-by: thartmann, kvn
  • Loading branch information
Yi Yang committed Nov 8, 2021
1 parent 8849154 commit 44047f849fad157dac5df788aa5a2c1838e4aaf7
Showing 2 changed files with 11 additions and 50 deletions.
@@ -905,16 +905,13 @@ void PhaseCFG::fixup_flow() {
// to succs[0], so we want the fall-thru case as the next block in
// succs[1].
if (bnext == bs0) {
// Fall-thru case in succs[0], so flip targets in succs map
// Fall-thru case in succs[0], should be in succs[1], so flip targets in _succs map
Block* tbs0 = block->_succs[0];
Block* tbs1 = block->_succs[1];
block->_succs.map(0, tbs1);
block->_succs.map(1, tbs0);
// Flip projection for each target
ProjNode* tmp = proj0;
proj0 = proj1;
proj1 = tmp;

swap(proj0, proj1);
} else if(bnext != bs1) {
// Need a double-branch
// The existing conditional branch need not change.
@@ -1648,8 +1645,7 @@ void PhaseBlockLayout::merge_traces(bool fall_thru_only) {
}
}

// Order the sequence of the traces in some desirable way, and fixup the
// jumps at the end of each block.
// Order the sequence of the traces in some desirable way
void PhaseBlockLayout::reorder_traces(int count) {
ResourceArea *area = Thread::current()->resource_area();
Trace ** new_traces = NEW_ARENA_ARRAY(area, Trace *, count);
@@ -1671,12 +1667,15 @@ void PhaseBlockLayout::reorder_traces(int count) {
// Sort the new trace list by frequency
qsort(new_traces + 1, new_count - 1, sizeof(new_traces[0]), trace_frequency_order);

// Patch up the successor blocks
// Collect all blocks from existing Traces
_cfg.clear_blocks();
for (int i = 0; i < new_count; i++) {
Trace *tr = new_traces[i];
if (tr != NULL) {
tr->fixup_blocks(_cfg);
// push blocks onto the CFG list
for (Block* b = tr->first_block(); b != NULL; b = tr->next(b)) {
_cfg.add_block(b);
}
}
}
}
@@ -1782,40 +1781,3 @@ bool Trace::backedge(CFGEdge *e) {

return loop_rotated;
}

// push blocks onto the CFG list
// ensure that blocks have the correct two-way branch sense
void Trace::fixup_blocks(PhaseCFG &cfg) {
Block *last = last_block();
for (Block *b = first_block(); b != NULL; b = next(b)) {
cfg.add_block(b);
if (!b->is_connector()) {
int nfallthru = b->num_fall_throughs();
if (b != last) {
if (nfallthru == 2) {
// Ensure that the sense of the branch is correct
Block *bnext = next(b);
Block *bs0 = b->non_connector_successor(0);

MachNode *iff = b->get_node(b->number_of_nodes() - 3)->as_Mach();
ProjNode *proj0 = b->get_node(b->number_of_nodes() - 2)->as_Proj();
ProjNode *proj1 = b->get_node(b->number_of_nodes() - 1)->as_Proj();

if (bnext == bs0) {
// Fall-thru case in succs[0], should be in succs[1]

// Flip targets in _succs map
Block *tbs0 = b->_succs[0];
Block *tbs1 = b->_succs[1];
b->_succs.map( 0, tbs1 );
b->_succs.map( 1, tbs0 );

// Flip projections to match targets
b->map_node(proj1, b->number_of_nodes() - 2);
b->map_node(proj0, b->number_of_nodes() - 1);
}
}
}
}
}
}
@@ -797,8 +797,6 @@ class Trace : public ResourceObj {
Block * _first; // First block in the trace
Block * _last; // Last block in the trace

// Return the block that follows "b" in the trace.
Block * next(Block *b) const { return _next_list[b->_pre_order]; }
void set_next(Block *b, Block *n) const { _next_list[b->_pre_order] = n; }

// Return the block that precedes "b" in the trace.
@@ -836,6 +834,9 @@ class Trace : public ResourceObj {
// Return the last block in the trace
Block * last_block() const { return _last; }

// Return the block that follows "b" in the trace.
Block * next(Block *b) const { return _next_list[b->_pre_order]; }

// Insert a trace in the middle of this one after b
void insert_after(Block *b, Trace *tr) {
set_next(tr->last_block(), next(b));
@@ -869,8 +870,6 @@ class Trace : public ResourceObj {
_last = b;
}

// Adjust the the blocks in this trace
void fixup_blocks(PhaseCFG &cfg);
bool backedge(CFGEdge *e);

#ifndef PRODUCT

1 comment on commit 44047f8

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 44047f8 Nov 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.