src/share/vm/opto/parse1.cpp

changeset 2665
9dc311b8473e
parent 2314
f95d63e2154a
child 2708
1d1603768966
     1.1 --- a/src/share/vm/opto/parse1.cpp	Mon Mar 21 02:30:49 2011 -0700
     1.2 +++ b/src/share/vm/opto/parse1.cpp	Mon Mar 21 11:28:14 2011 -0700
     1.3 @@ -637,6 +637,25 @@
     1.4          // (Note that dead locals do not get phis built, ever.)
     1.5          ensure_phis_everywhere();
     1.6  
     1.7 +        if (block->is_SEL_head() &&
     1.8 +            UseLoopPredicate) {
     1.9 +          // Add predicate to single entry (not irreducible) loop head.
    1.10 +          assert(!block->has_merged_backedge(), "only entry paths should be merged for now");
    1.11 +          // Need correct bci for predicate.
    1.12 +          // It is fine to set it here since do_one_block() will set it anyway.
    1.13 +          set_parse_bci(block->start());
    1.14 +          add_predicate();
    1.15 +          // Add new region for back branches.
    1.16 +          int edges = block->pred_count() - block->preds_parsed() + 1; // +1 for original region
    1.17 +          RegionNode *r = new (C, edges+1) RegionNode(edges+1);
    1.18 +          _gvn.set_type(r, Type::CONTROL);
    1.19 +          record_for_igvn(r);
    1.20 +          r->init_req(edges, control());
    1.21 +          set_control(r);
    1.22 +          // Add new phis.
    1.23 +          ensure_phis_everywhere();
    1.24 +        }
    1.25 +
    1.26          // Leave behind an undisturbed copy of the map, for future merges.
    1.27          set_map(clone_map());
    1.28        }
    1.29 @@ -1113,7 +1132,7 @@
    1.30    _preds_parsed = 0;
    1.31    _count = 0;
    1.32    assert(pred_count() == 0 && preds_parsed() == 0, "sanity");
    1.33 -  assert(!(is_merged() || is_parsed() || is_handler()), "sanity");
    1.34 +  assert(!(is_merged() || is_parsed() || is_handler() || has_merged_backedge()), "sanity");
    1.35    assert(_live_locals.size() == 0, "sanity");
    1.36  
    1.37    // entry point has additional predecessor
    1.38 @@ -1350,10 +1369,6 @@
    1.39      set_parse_bci(iter().cur_bci());
    1.40  
    1.41      if (bci() == block()->limit()) {
    1.42 -      // insert a predicate if it falls through to a loop head block
    1.43 -      if (should_add_predicate(bci())){
    1.44 -        add_predicate();
    1.45 -      }
    1.46        // Do not walk into the next block until directed by do_all_blocks.
    1.47        merge(bci());
    1.48        break;
    1.49 @@ -1498,17 +1513,29 @@
    1.50          || target->is_handler()       // These have unpredictable inputs.
    1.51          || target->is_loop_head()     // Known multiple inputs
    1.52          || control()->is_Region()) {  // We must hide this guy.
    1.53 +
    1.54 +      int current_bci = bci();
    1.55 +      set_parse_bci(target->start()); // Set target bci
    1.56 +      if (target->is_SEL_head()) {
    1.57 +        DEBUG_ONLY( target->mark_merged_backedge(block()); )
    1.58 +        if (target->start() == 0) {
    1.59 +          // Add loop predicate for the special case when
    1.60 +          // there are backbranches to the method entry.
    1.61 +          add_predicate();
    1.62 +        }
    1.63 +      }
    1.64        // Add a Region to start the new basic block.  Phis will be added
    1.65        // later lazily.
    1.66        int edges = target->pred_count();
    1.67        if (edges < pnum)  edges = pnum;  // might be a new path!
    1.68 -      Node *r = new (C, edges+1) RegionNode(edges+1);
    1.69 +      RegionNode *r = new (C, edges+1) RegionNode(edges+1);
    1.70        gvn().set_type(r, Type::CONTROL);
    1.71        record_for_igvn(r);
    1.72        // zap all inputs to NULL for debugging (done in Node(uint) constructor)
    1.73        // for (int j = 1; j < edges+1; j++) { r->init_req(j, NULL); }
    1.74        r->init_req(pnum, control());
    1.75        set_control(r);
    1.76 +      set_parse_bci(current_bci); // Restore bci
    1.77      }
    1.78  
    1.79      // Convert the existing Parser mapping into a mapping at this bci.
    1.80 @@ -1517,7 +1544,11 @@
    1.81  
    1.82    } else {                      // Prior mapping at this bci
    1.83      if (TraceOptoParse) {  tty->print(" with previous state"); }
    1.84 -
    1.85 +#ifdef ASSERT
    1.86 +    if (target->is_SEL_head()) {
    1.87 +      target->mark_merged_backedge(block());
    1.88 +    }
    1.89 +#endif
    1.90      // We must not manufacture more phis if the target is already parsed.
    1.91      bool nophi = target->is_parsed();
    1.92  
    1.93 @@ -2054,37 +2085,6 @@
    1.94    }
    1.95  }
    1.96  
    1.97 -//------------------------------should_add_predicate--------------------------
    1.98 -bool Parse::should_add_predicate(int target_bci) {
    1.99 -  if (!UseLoopPredicate) return false;
   1.100 -  Block* target = successor_for_bci(target_bci);
   1.101 -  if (target != NULL          &&
   1.102 -      target->is_loop_head()  &&
   1.103 -      block()->rpo() < target->rpo()) {
   1.104 -    return true;
   1.105 -  }
   1.106 -  return false;
   1.107 -}
   1.108 -
   1.109 -//------------------------------add_predicate---------------------------------
   1.110 -void Parse::add_predicate() {
   1.111 -  assert(UseLoopPredicate,"use only for loop predicate");
   1.112 -  Node *cont    = _gvn.intcon(1);
   1.113 -  Node* opq     = _gvn.transform(new (C, 2) Opaque1Node(C, cont));
   1.114 -  Node *bol     = _gvn.transform(new (C, 2) Conv2BNode(opq));
   1.115 -  IfNode* iff   = create_and_map_if(control(), bol, PROB_MAX, COUNT_UNKNOWN);
   1.116 -  Node* iffalse = _gvn.transform(new (C, 1) IfFalseNode(iff));
   1.117 -  C->add_predicate_opaq(opq);
   1.118 -  {
   1.119 -    PreserveJVMState pjvms(this);
   1.120 -    set_control(iffalse);
   1.121 -    uncommon_trap(Deoptimization::Reason_predicate,
   1.122 -                  Deoptimization::Action_maybe_recompile);
   1.123 -  }
   1.124 -  Node* iftrue = _gvn.transform(new (C, 1) IfTrueNode(iff));
   1.125 -  set_control(iftrue);
   1.126 -}
   1.127 -
   1.128  #ifndef PRODUCT
   1.129  //------------------------show_parse_info--------------------------------------
   1.130  void Parse::show_parse_info() {

mercurial