src/share/vm/c1/c1_IR.cpp

changeset 1939
b812ff5abc73
parent 1934
e9ff18c4ace7
child 2138
d5d065957597
     1.1 --- a/src/share/vm/c1/c1_IR.cpp	Thu Jun 03 14:20:27 2010 -0700
     1.2 +++ b/src/share/vm/c1/c1_IR.cpp	Fri Jun 04 11:18:04 2010 -0700
     1.3 @@ -287,11 +287,6 @@
     1.4  IR::IR(Compilation* compilation, ciMethod* method, int osr_bci) :
     1.5      _locals_size(in_WordSize(-1))
     1.6    , _num_loops(0) {
     1.7 -  // initialize data structures
     1.8 -  ValueType::initialize();
     1.9 -  Instruction::initialize();
    1.10 -  BlockBegin::initialize();
    1.11 -  GraphBuilder::initialize();
    1.12    // setup IR fields
    1.13    _compilation = compilation;
    1.14    _top_scope   = new IRScope(compilation, NULL, -1, method, osr_bci, true);
    1.15 @@ -381,15 +376,15 @@
    1.16  }
    1.17  
    1.18  
    1.19 -class UseCountComputer: public AllStatic {
    1.20 +class UseCountComputer: public ValueVisitor, BlockClosure {
    1.21   private:
    1.22 -  static void update_use_count(Value* n) {
    1.23 +  void visit(Value* n) {
    1.24      // Local instructions and Phis for expression stack values at the
    1.25      // start of basic blocks are not added to the instruction list
    1.26      if ((*n)->bci() == -99 && (*n)->as_Local() == NULL &&
    1.27          (*n)->as_Phi() == NULL) {
    1.28        assert(false, "a node was not appended to the graph");
    1.29 -      Compilation::current_compilation()->bailout("a node was not appended to the graph");
    1.30 +      Compilation::current()->bailout("a node was not appended to the graph");
    1.31      }
    1.32      // use n's input if not visited before
    1.33      if (!(*n)->is_pinned() && !(*n)->has_uses()) {
    1.34 @@ -402,31 +397,31 @@
    1.35      (*n)->_use_count++;
    1.36    }
    1.37  
    1.38 -  static Values* worklist;
    1.39 -  static int depth;
    1.40 +  Values* worklist;
    1.41 +  int depth;
    1.42    enum {
    1.43      max_recurse_depth = 20
    1.44    };
    1.45  
    1.46 -  static void uses_do(Value* n) {
    1.47 +  void uses_do(Value* n) {
    1.48      depth++;
    1.49      if (depth > max_recurse_depth) {
    1.50        // don't allow the traversal to recurse too deeply
    1.51        worklist->push(*n);
    1.52      } else {
    1.53 -      (*n)->input_values_do(update_use_count);
    1.54 +      (*n)->input_values_do(this);
    1.55        // special handling for some instructions
    1.56        if ((*n)->as_BlockEnd() != NULL) {
    1.57          // note on BlockEnd:
    1.58          //   must 'use' the stack only if the method doesn't
    1.59          //   terminate, however, in those cases stack is empty
    1.60 -        (*n)->state_values_do(update_use_count);
    1.61 +        (*n)->state_values_do(this);
    1.62        }
    1.63      }
    1.64      depth--;
    1.65    }
    1.66  
    1.67 -  static void basic_compute_use_count(BlockBegin* b) {
    1.68 +  void block_do(BlockBegin* b) {
    1.69      depth = 0;
    1.70      // process all pinned nodes as the roots of expression trees
    1.71      for (Instruction* n = b; n != NULL; n = n->next()) {
    1.72 @@ -449,18 +444,19 @@
    1.73      assert(depth == 0, "should have counted back down");
    1.74    }
    1.75  
    1.76 +  UseCountComputer() {
    1.77 +    worklist = new Values();
    1.78 +    depth = 0;
    1.79 +  }
    1.80 +
    1.81   public:
    1.82    static void compute(BlockList* blocks) {
    1.83 -    worklist = new Values();
    1.84 -    blocks->blocks_do(basic_compute_use_count);
    1.85 -    worklist = NULL;
    1.86 +    UseCountComputer ucc;
    1.87 +    blocks->iterate_backward(&ucc);
    1.88    }
    1.89  };
    1.90  
    1.91  
    1.92 -Values* UseCountComputer::worklist = NULL;
    1.93 -int UseCountComputer::depth = 0;
    1.94 -
    1.95  // helper macro for short definition of trace-output inside code
    1.96  #ifndef PRODUCT
    1.97    #define TRACE_LINEAR_SCAN(level, code)       \
    1.98 @@ -1302,7 +1298,7 @@
    1.99  
   1.100  #endif // PRODUCT
   1.101  
   1.102 -void SubstitutionResolver::substitute(Value* v) {
   1.103 +void SubstitutionResolver::visit(Value* v) {
   1.104    Value v0 = *v;
   1.105    if (v0) {
   1.106      Value vs = v0->subst();
   1.107 @@ -1313,20 +1309,22 @@
   1.108  }
   1.109  
   1.110  #ifdef ASSERT
   1.111 -void check_substitute(Value* v) {
   1.112 -  Value v0 = *v;
   1.113 -  if (v0) {
   1.114 -    Value vs = v0->subst();
   1.115 -    assert(vs == v0, "missed substitution");
   1.116 +class SubstitutionChecker: public ValueVisitor {
   1.117 +  void visit(Value* v) {
   1.118 +    Value v0 = *v;
   1.119 +    if (v0) {
   1.120 +      Value vs = v0->subst();
   1.121 +      assert(vs == v0, "missed substitution");
   1.122 +    }
   1.123    }
   1.124 -}
   1.125 +};
   1.126  #endif
   1.127  
   1.128  
   1.129  void SubstitutionResolver::block_do(BlockBegin* block) {
   1.130    Instruction* last = NULL;
   1.131    for (Instruction* n = block; n != NULL;) {
   1.132 -    n->values_do(substitute);
   1.133 +    n->values_do(this);
   1.134      // need to remove this instruction from the instruction stream
   1.135      if (n->subst() != n) {
   1.136        assert(last != NULL, "must have last");
   1.137 @@ -1338,8 +1336,9 @@
   1.138    }
   1.139  
   1.140  #ifdef ASSERT
   1.141 -  if (block->state()) block->state()->values_do(check_substitute);
   1.142 -  block->block_values_do(check_substitute);
   1.143 -  if (block->end() && block->end()->state()) block->end()->state()->values_do(check_substitute);
   1.144 +  SubstitutionChecker check_substitute;
   1.145 +  if (block->state()) block->state()->values_do(&check_substitute);
   1.146 +  block->block_values_do(&check_substitute);
   1.147 +  if (block->end() && block->end()->state()) block->end()->state()->values_do(&check_substitute);
   1.148  #endif
   1.149  }

mercurial