/* * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
void ValueMap::increase_table_size() { int old_size = size(); int new_size = old_size * 2 + 1;
ValueMapEntryList worklist(8);
ValueMapEntryArray new_entries(new_size, new_size, NULL); int new_entry_count = 0;
TRACE_VALUE_NUMBERING(tty->print_cr("increasing table size from %d to %d", old_size, new_size));
for (int i = old_size - 1; i >= 0; i--) {
ValueMapEntry* entry; for (entry = entry_at(i); entry != NULL; entry = entry->next()) { if (!is_killed(entry->value())) {
worklist.push(entry);
}
}
while (!worklist.is_empty()) {
entry = worklist.pop(); int new_index = entry_index(entry->hash(), new_size);
if (entry->nesting() != nesting() && new_entries.at(new_index) != entry->next()) { // changing entries with a lower nesting than the current nesting of the table // is not allowed because then the same entry is contained in multiple value maps. // clone entry when next-pointer must be changed
entry = new ValueMapEntry(entry->hash(), entry->value(), entry->nesting(), NULL);
}
entry->set_next(new_entries.at(new_index));
new_entries.at_put(new_index, entry);
new_entry_count++;
}
}
if (entry->nesting() != nesting() && f->as_Constant() == NULL) { // non-constant values of of another block must be pinned, // otherwise it is possible that they are not evaluated
f->pin(Instruction::PinGlobalValueNumbering);
}
assert(x->type()->tag() == f->type()->tag(), "should have same type");
return f;
}
}
}
// x not found, so insert it if (entry_count() >= size_threshold()) {
increase_table_size();
} int idx = entry_index(hash, size());
_entries.at_put(idx, new ValueMapEntry(hash, x, nesting(), entry_at(idx)));
_entry_count++;
void ValueMap::kill_map(ValueMap* map) {
assert(is_global_value_numbering(), "only for global value numbering");
_killed_values.set_union(&map->_killed_values);
}
void ValueMap::kill_all() {
assert(is_local_value_numbering(), "only for local value numbering"); for (int i = size() - 1; i >= 0; i--) {
_entries.at_put(i, NULL);
}
_entry_count = 0;
}
TRACE_VALUE_NUMBERING(tty->print_cr("using loop invariant code motion loop_header = %d", loop_header->block_id()));
TRACE_VALUE_NUMBERING(tty->print_cr("** loop invariant code motion for short loop B%d", loop_header->block_id()));
BlockBegin* insertion_block = loop_header->dominator(); if (insertion_block->number_of_preds() == 0) { return; // only the entry block does not have a predecessor
}
if (!_state) { // If, TableSwitch and LookupSwitch always have state_before when // loop invariant code motion happens..
assert(block_end->as_Goto(), "Block has to be goto");
_state = block_end->state();
}
// the loop_blocks are filled by going backward from the loop header, so this processing order is best
assert(loop_blocks->at(0) == loop_header, "loop header must be first loop block");
process_block(loop_header); for (int i = loop_blocks->length() - 1; i >= 1; i--) {
process_block(loop_blocks->at(i));
}
}
Instruction* prev = block;
Instruction* cur = block->next();
while (cur != NULL) { // determine if cur instruction is loop invariant // only selected instruction types are processed here bool cur_invariant = false;
if (cur_invariant) { // perform value numbering and mark instruction as loop-invariant
_gvn->substitute(cur);
if (cur->as_Constant() == NULL) { // ensure that code for non-constant instructions is always generated
cur->pin();
}
// remove cur instruction from loop block and append it to block before loop
Instruction* next = cur->next();
Instruction* in = _insertion_point->next();
_insertion_point = _insertion_point->set_next(cur);
cur->set_next(in);
// Deoptimize on exception
cur->set_flag(Instruction::DeoptimizeOnException, true);
GlobalValueNumbering::GlobalValueNumbering(IR* ir)
: _compilation(ir->compilation())
, _current_map(NULL)
, _value_maps(ir->linear_scan_order()->length(), ir->linear_scan_order()->length(), NULL)
, _has_substitutions(false)
{
TRACE_VALUE_NUMBERING(tty->print_cr("****** start of global value numbering"));
ShortLoopOptimizer short_loop_optimizer(this);
BlockList* blocks = ir->linear_scan_order(); int num_blocks = blocks->length();
BlockBegin* start_block = blocks->at(0);
assert(start_block == ir->start() && start_block->number_of_preds() == 0 && start_block->dominator() == NULL, "must be start block");
assert(start_block->next()->as_Base() != NULL && start_block->next()->next() == NULL, "start block must not have instructions");
// method parameters are not linked in instructions list, so process them separately
for_each_state_value(start_block->state(), value,
assert(value->as_Local() != NULL, "only method parameters allowed");
set_processed(value);
);
// initial, empty value map with nesting 0
set_value_map_of(start_block, new ValueMap());
for (int i = 1; i < num_blocks; i++) {
BlockBegin* block = blocks->at(i);
TRACE_VALUE_NUMBERING(tty->print_cr("**** processing block B%d", block->block_id()));
int num_preds = block->number_of_preds();
assert(num_preds > 0, "block must have predecessors");
BlockBegin* dominator = block->dominator();
assert(dominator != NULL, "dominator must exist");
assert(value_map_of(dominator) != NULL, "value map of dominator must exist");
// create new value map with increased nesting
_current_map = new ValueMap(value_map_of(dominator));
if (num_preds == 1 && !block->is_set(BlockBegin::exception_entry_flag)) {
assert(dominator == block->pred_at(0), "dominator must be equal to predecessor"); // nothing to do here
} elseif (block->is_set(BlockBegin::linear_scan_loop_header_flag)) { // block has incoming backward branches -> try to optimize short loops if (!short_loop_optimizer.process(block)) { // loop is too complicated, so kill all memory loads because there might be // stores to them in the loop
current_map()->kill_memory();
}
} else { // only incoming forward branches that are already processed for (int j = 0; j < num_preds; j++) {
BlockBegin* pred = block->pred_at(j);
ValueMap* pred_map = value_map_of(pred);
if (pred_map != NULL) { // propagate killed values of the predecessor to this block
current_map()->kill_map(value_map_of(pred));
} else { // kill all memory loads because predecessor not yet processed // (this can happen with non-natural loops and OSR-compiles)
current_map()->kill_memory();
}
}
}
// phi functions are not linked in instructions list, so process them separateley
for_each_phi_fun(block, phi,
set_processed(phi);
);
TRACE_VALUE_NUMBERING(tty->print("value map before processing block: "); current_map()->print());
// visit all instructions of this block for (Value instr = block->next(); instr != NULL; instr = instr->next()) { // check if instruction kills any values
instr->visit(this); // perform actual value numbering
substitute(instr);
}
// remember value map for successors
set_value_map_of(block, current_map());
}
if (_has_substitutions) {
SubstitutionResolver resolver(ir);
}
TRACE_VALUE_NUMBERING(tty->print("****** end of global value numbering. "); ValueMap::print_statistics());
}
void GlobalValueNumbering::substitute(Instruction* instr) {
assert(!instr->has_subst(), "substitution already set");
Value subst = current_map()->find_insert(instr); if (subst != instr) {
assert(!subst->has_subst(), "can't have a substitution");
TRACE_VALUE_NUMBERING(tty->print_cr("substitution for %c%d set to %c%d", instr->type()->tchar(), instr->id(), subst->type()->tchar(), subst->id()));
instr->set_subst(subst);
_has_substitutions = true;
}
set_processed(instr);
}
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.