src/share/vm/c1/c1_RangeCheckElimination.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/c1

src/share/vm/c1/c1_RangeCheckElimination.cpp

Print this page




  45 // Entry point for the optimization
  46 void RangeCheckElimination::eliminate(IR *ir) {
  47   bool do_elimination = ir->compilation()->has_access_indexed();
  48   ASSERT_RANGE_CHECK_ELIMINATION(do_elimination = true);
  49   if (do_elimination) {
  50     RangeCheckEliminator rce(ir);
  51   }
  52 }
  53 
  54 // Constructor
  55 RangeCheckEliminator::RangeCheckEliminator(IR *ir) :
  56   _bounds(Instruction::number_of_instructions(), NULL),
  57   _access_indexed_info(Instruction::number_of_instructions(), NULL)
  58 {
  59   _visitor.set_range_check_eliminator(this);
  60   _ir = ir;
  61   _number_of_instructions = Instruction::number_of_instructions();
  62   _optimistic = ir->compilation()->is_optimistic();
  63 
  64   TRACE_RANGE_CHECK_ELIMINATION(
  65     tty->print_cr("");
  66     tty->print_cr("Range check elimination");
  67     ir->method()->print_name(tty);
  68     tty->print_cr("");
  69   );
  70 
  71   TRACE_RANGE_CHECK_ELIMINATION(
  72     tty->print_cr("optimistic=%d", (int)_optimistic);
  73   );
  74 
  75 #ifdef ASSERT
  76   // Verifies several conditions that must be true on the IR-input. Only used for debugging purposes.
  77   TRACE_RANGE_CHECK_ELIMINATION(
  78     tty->print_cr("Verification of IR . . .");
  79   );
  80   Verification verification(ir);
  81 #endif
  82 
  83   // Set process block flags
  84   // Optimization so a blocks is only processed if it contains an access indexed instruction or if
  85   // one of its children in the dominator tree contains an access indexed instruction.
  86   set_process_block_flags(ir->start());
  87 
  88   // Pass over instructions in the dominator tree


1007   for (int i=0; i<pushed.length(); i++) {
1008     _bounds[pushed[i]]->pop();
1009   }
1010 }
1011 
1012 #ifndef PRODUCT
1013 // Dump condition stack
1014 void RangeCheckEliminator::dump_condition_stack(BlockBegin *block) {
1015   for (int i=0; i<_ir->linear_scan_order()->length(); i++) {
1016     BlockBegin *cur_block = _ir->linear_scan_order()->at(i);
1017     Instruction *instr = cur_block;
1018     for_each_phi_fun(cur_block, phi,
1019                      BoundStack *bound_stack = _bounds.at(phi->id());
1020                      if (bound_stack && bound_stack->length() > 0) {
1021                        Bound *bound = bound_stack->top();
1022                        if ((bound->has_lower() || bound->has_upper()) && (bound->lower_instr() != phi || bound->upper_instr() != phi || bound->lower() != 0 || bound->upper() != 0)) {
1023                            TRACE_RANGE_CHECK_ELIMINATION(tty->fill_to(2*block->dominator_depth());
1024                                                          tty->print("i%d", phi->id());
1025                                                          tty->print(": ");
1026                                                          bound->print();
1027                                                          tty->print_cr("");
1028                            );
1029                          }
1030                      });
1031 
1032     while (!instr->as_BlockEnd()) {
1033       if (instr->id() < _bounds.length()) {
1034         BoundStack *bound_stack = _bounds.at(instr->id());
1035         if (bound_stack && bound_stack->length() > 0) {
1036           Bound *bound = bound_stack->top();
1037           if ((bound->has_lower() || bound->has_upper()) && (bound->lower_instr() != instr || bound->upper_instr() != instr || bound->lower() != 0 || bound->upper() != 0)) {
1038               TRACE_RANGE_CHECK_ELIMINATION(tty->fill_to(2*block->dominator_depth());
1039                                             tty->print("i%d", instr->id());
1040                                             tty->print(": ");
1041                                             bound->print();
1042                                             tty->print_cr("");
1043               );
1044           }
1045         }
1046       }
1047       instr = instr->next();
1048     }
1049   }
1050 }
1051 #endif
1052 
1053 // Verification or the IR
1054 RangeCheckEliminator::Verification::Verification(IR *ir) : _used(BlockBegin::number_of_blocks(), false) {
1055   this->_ir = ir;
1056   ir->iterate_linear_scan_order(this);
1057 }
1058 
1059 // Verify this block
1060 void RangeCheckEliminator::Verification::block_do(BlockBegin *block) {
1061   If *cond = block->end()->as_If();
1062   // Watch out: tsux and fsux can be the same!


1383   return _upper;
1384 }
1385 
1386 // lower
1387 int RangeCheckEliminator::Bound::lower() {
1388   return _lower;
1389 }
1390 
1391 // upper_instr
1392 Value RangeCheckEliminator::Bound::upper_instr() {
1393   return _upper_instr;
1394 }
1395 
1396 // lower_instr
1397 Value RangeCheckEliminator::Bound::lower_instr() {
1398   return _lower_instr;
1399 }
1400 
1401 // print
1402 void RangeCheckEliminator::Bound::print() {
1403   tty->print("");
1404   if (this->_lower_instr || this->_lower != min_jint) {
1405     if (this->_lower_instr) {
1406       tty->print("i%d", this->_lower_instr->id());
1407       if (this->_lower > 0) {
1408         tty->print("+%d", _lower);
1409       }
1410       if (this->_lower < 0) {
1411         tty->print("%d", _lower);
1412       }
1413     } else {
1414       tty->print("%d", _lower);
1415     }
1416     tty->print(" <= ");
1417   }
1418   tty->print("x");
1419   if (this->_upper_instr || this->_upper != max_jint) {
1420     tty->print(" <= ");
1421     if (this->_upper_instr) {
1422       tty->print("i%d", this->_upper_instr->id());
1423       if (this->_upper > 0) {




  45 // Entry point for the optimization
  46 void RangeCheckElimination::eliminate(IR *ir) {
  47   bool do_elimination = ir->compilation()->has_access_indexed();
  48   ASSERT_RANGE_CHECK_ELIMINATION(do_elimination = true);
  49   if (do_elimination) {
  50     RangeCheckEliminator rce(ir);
  51   }
  52 }
  53 
  54 // Constructor
  55 RangeCheckEliminator::RangeCheckEliminator(IR *ir) :
  56   _bounds(Instruction::number_of_instructions(), NULL),
  57   _access_indexed_info(Instruction::number_of_instructions(), NULL)
  58 {
  59   _visitor.set_range_check_eliminator(this);
  60   _ir = ir;
  61   _number_of_instructions = Instruction::number_of_instructions();
  62   _optimistic = ir->compilation()->is_optimistic();
  63 
  64   TRACE_RANGE_CHECK_ELIMINATION(
  65     tty->cr();
  66     tty->print_cr("Range check elimination");
  67     ir->method()->print_name(tty);
  68     tty->cr();
  69   );
  70 
  71   TRACE_RANGE_CHECK_ELIMINATION(
  72     tty->print_cr("optimistic=%d", (int)_optimistic);
  73   );
  74 
  75 #ifdef ASSERT
  76   // Verifies several conditions that must be true on the IR-input. Only used for debugging purposes.
  77   TRACE_RANGE_CHECK_ELIMINATION(
  78     tty->print_cr("Verification of IR . . .");
  79   );
  80   Verification verification(ir);
  81 #endif
  82 
  83   // Set process block flags
  84   // Optimization so a blocks is only processed if it contains an access indexed instruction or if
  85   // one of its children in the dominator tree contains an access indexed instruction.
  86   set_process_block_flags(ir->start());
  87 
  88   // Pass over instructions in the dominator tree


1007   for (int i=0; i<pushed.length(); i++) {
1008     _bounds[pushed[i]]->pop();
1009   }
1010 }
1011 
1012 #ifndef PRODUCT
1013 // Dump condition stack
1014 void RangeCheckEliminator::dump_condition_stack(BlockBegin *block) {
1015   for (int i=0; i<_ir->linear_scan_order()->length(); i++) {
1016     BlockBegin *cur_block = _ir->linear_scan_order()->at(i);
1017     Instruction *instr = cur_block;
1018     for_each_phi_fun(cur_block, phi,
1019                      BoundStack *bound_stack = _bounds.at(phi->id());
1020                      if (bound_stack && bound_stack->length() > 0) {
1021                        Bound *bound = bound_stack->top();
1022                        if ((bound->has_lower() || bound->has_upper()) && (bound->lower_instr() != phi || bound->upper_instr() != phi || bound->lower() != 0 || bound->upper() != 0)) {
1023                            TRACE_RANGE_CHECK_ELIMINATION(tty->fill_to(2*block->dominator_depth());
1024                                                          tty->print("i%d", phi->id());
1025                                                          tty->print(": ");
1026                                                          bound->print();
1027                                                          tty->cr();
1028                            );
1029                          }
1030                      });
1031 
1032     while (!instr->as_BlockEnd()) {
1033       if (instr->id() < _bounds.length()) {
1034         BoundStack *bound_stack = _bounds.at(instr->id());
1035         if (bound_stack && bound_stack->length() > 0) {
1036           Bound *bound = bound_stack->top();
1037           if ((bound->has_lower() || bound->has_upper()) && (bound->lower_instr() != instr || bound->upper_instr() != instr || bound->lower() != 0 || bound->upper() != 0)) {
1038               TRACE_RANGE_CHECK_ELIMINATION(tty->fill_to(2*block->dominator_depth());
1039                                             tty->print("i%d", instr->id());
1040                                             tty->print(": ");
1041                                             bound->print();
1042                                             tty->cr();
1043               );
1044           }
1045         }
1046       }
1047       instr = instr->next();
1048     }
1049   }
1050 }
1051 #endif
1052 
1053 // Verification or the IR
1054 RangeCheckEliminator::Verification::Verification(IR *ir) : _used(BlockBegin::number_of_blocks(), false) {
1055   this->_ir = ir;
1056   ir->iterate_linear_scan_order(this);
1057 }
1058 
1059 // Verify this block
1060 void RangeCheckEliminator::Verification::block_do(BlockBegin *block) {
1061   If *cond = block->end()->as_If();
1062   // Watch out: tsux and fsux can be the same!


1383   return _upper;
1384 }
1385 
1386 // lower
1387 int RangeCheckEliminator::Bound::lower() {
1388   return _lower;
1389 }
1390 
1391 // upper_instr
1392 Value RangeCheckEliminator::Bound::upper_instr() {
1393   return _upper_instr;
1394 }
1395 
1396 // lower_instr
1397 Value RangeCheckEliminator::Bound::lower_instr() {
1398   return _lower_instr;
1399 }
1400 
1401 // print
1402 void RangeCheckEliminator::Bound::print() {
1403   tty->print_raw("");
1404   if (this->_lower_instr || this->_lower != min_jint) {
1405     if (this->_lower_instr) {
1406       tty->print("i%d", this->_lower_instr->id());
1407       if (this->_lower > 0) {
1408         tty->print("+%d", _lower);
1409       }
1410       if (this->_lower < 0) {
1411         tty->print("%d", _lower);
1412       }
1413     } else {
1414       tty->print("%d", _lower);
1415     }
1416     tty->print(" <= ");
1417   }
1418   tty->print("x");
1419   if (this->_upper_instr || this->_upper != max_jint) {
1420     tty->print(" <= ");
1421     if (this->_upper_instr) {
1422       tty->print("i%d", this->_upper_instr->id());
1423       if (this->_upper > 0) {


src/share/vm/c1/c1_RangeCheckElimination.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File