< prev index next >

hotspot/src/share/vm/c1/c1_RangeCheckElimination.hpp

Print this page
rev 10453 : imported patch update dates
   1 /*
   2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_C1_C1_RANGECHECKELIMINATION_HPP
  26 #define SHARE_VM_C1_C1_RANGECHECKELIMINATION_HPP
  27 
  28 #include "c1/c1_Instruction.hpp"
  29 
  30 // Base class for range check elimination
  31 class RangeCheckElimination : AllStatic {
  32 public:
  33   static void eliminate(IR *ir);
  34 };
  35 
  36 // Implementation
  37 class RangeCheckEliminator VALUE_OBJ_CLASS_SPEC {
  38 private:
  39   int _number_of_instructions;
  40   bool _optimistic; // Insert predicates and deoptimize when they fail
  41   IR *_ir;
  42 
  43   define_array(BlockBeginArray, BlockBegin*)
  44   define_stack(BlockBeginList, BlockBeginArray)
  45   define_stack(IntegerStack, intArray)
  46   define_array(IntegerMap, IntegerStack*)
  47 
  48   class Verification : public BlockClosure {
  49   // RangeCheckEliminator::Verification should never get instatiated on the heap.
  50   private:
  51     void* operator new(size_t size) throw();
  52     void* operator new[](size_t size) throw();
  53     void operator delete(void* p) { ShouldNotReachHere(); }
  54     void operator delete[](void* p) { ShouldNotReachHere(); }
  55 
  56     IR *_ir;
  57     boolArray _used;
  58     BlockBeginList _current;
  59     BlockBeginList _successors;
  60 
  61   public:
  62     Verification(IR *ir);
  63     virtual void block_do(BlockBegin *block);
  64     bool can_reach(BlockBegin *start, BlockBegin *end, BlockBegin *dont_use = NULL);
  65     bool dominates(BlockBegin *dominator, BlockBegin *block);
  66   };


 163     void do_ExceptionObject(ExceptionObject* x) { /* nothing to do */ };
 164     void do_RoundFP        (RoundFP*         x) { /* nothing to do */ };
 165     void do_UnsafeGetRaw   (UnsafeGetRaw*    x) { /* nothing to do */ };
 166     void do_UnsafeGetObject(UnsafeGetObject* x) { /* nothing to do */ };
 167     void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) { /* nothing to do */ };
 168     void do_ProfileCall    (ProfileCall*     x) { /* nothing to do */ };
 169     void do_ProfileReturnType (ProfileReturnType*  x) { /* nothing to do */ };
 170     void do_ProfileInvoke  (ProfileInvoke*   x) { /* nothing to do */ };
 171     void do_RuntimeCall    (RuntimeCall*     x) { /* nothing to do */ };
 172     void do_MemBar         (MemBar*          x) { /* nothing to do */ };
 173     void do_RangeCheckPredicate(RangeCheckPredicate* x) { /* nothing to do */ };
 174 #ifdef ASSERT
 175     void do_Assert         (Assert*          x) { /* nothing to do */ };
 176 #endif
 177   };
 178 
 179 #ifdef ASSERT
 180   void add_assertions(Bound *bound, Instruction *instruction, Instruction *position);
 181 #endif
 182 
 183   define_array(BoundArray, Bound *)
 184   define_stack(BoundStack, BoundArray)
 185   define_array(BoundMap, BoundStack *)
 186   define_array(AccessIndexedArray, AccessIndexed *)
 187   define_stack(AccessIndexedList, AccessIndexedArray)
 188   define_array(InstructionArray, Instruction *)
 189   define_stack(InstructionList, InstructionArray)
 190 
 191   class AccessIndexedInfo : public CompilationResourceObj  {
 192   public:
 193     AccessIndexedList *_list;
 194     int _min;
 195     int _max;
 196   };
 197 
 198   define_array(AccessIndexedInfoArray, AccessIndexedInfo *)
 199   BoundMap _bounds; // Mapping from Instruction's id to current bound
 200   AccessIndexedInfoArray _access_indexed_info; // Mapping from Instruction's id to AccessIndexedInfo for in block motion
 201   Visitor _visitor;
 202 
 203 public:
 204   RangeCheckEliminator(IR *ir);
 205 
 206   IR *ir() const { return _ir; }
 207 
 208   // Pass over the dominator tree to identify blocks where there's an oppportunity for optimization
 209   bool set_process_block_flags(BlockBegin *block);
 210   // The core of the optimization work: pass over the dominator tree
 211   // to propagate bound information, insert predicate out of loops,
 212   // eliminate bound checks when possible and perform in block motion
 213   void calc_bounds(BlockBegin *block, BlockBegin *loop_header);
 214   // reorder bound checks within a block in order to eliminate some of them
 215   void in_block_motion(BlockBegin *block, AccessIndexedList &accessIndexed, InstructionList &arrays);
 216 
 217   // update/access current bound
 218   void update_bound(IntegerStack &pushed, Value v, Instruction::Condition cond, Value value, int constant);


   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_C1_C1_RANGECHECKELIMINATION_HPP
  26 #define SHARE_VM_C1_C1_RANGECHECKELIMINATION_HPP
  27 
  28 #include "c1/c1_Instruction.hpp"
  29 
  30 // Base class for range check elimination
  31 class RangeCheckElimination : AllStatic {
  32 public:
  33   static void eliminate(IR *ir);
  34 };
  35 
  36 // Implementation
  37 class RangeCheckEliminator VALUE_OBJ_CLASS_SPEC {
  38 private:
  39   int _number_of_instructions;
  40   bool _optimistic; // Insert predicates and deoptimize when they fail
  41   IR *_ir;
  42 
  43   typedef GrowableArray<BlockBegin*> BlockBeginList;
  44   typedef GrowableArray<int> IntegerStack;


  45 
  46   class Verification : public BlockClosure {
  47   // RangeCheckEliminator::Verification should never get instatiated on the heap.
  48   private:
  49     void* operator new(size_t size) throw();
  50     void* operator new[](size_t size) throw();
  51     void operator delete(void* p) { ShouldNotReachHere(); }
  52     void operator delete[](void* p) { ShouldNotReachHere(); }
  53 
  54     IR *_ir;
  55     boolArray _used;
  56     BlockBeginList _current;
  57     BlockBeginList _successors;
  58 
  59   public:
  60     Verification(IR *ir);
  61     virtual void block_do(BlockBegin *block);
  62     bool can_reach(BlockBegin *start, BlockBegin *end, BlockBegin *dont_use = NULL);
  63     bool dominates(BlockBegin *dominator, BlockBegin *block);
  64   };


 161     void do_ExceptionObject(ExceptionObject* x) { /* nothing to do */ };
 162     void do_RoundFP        (RoundFP*         x) { /* nothing to do */ };
 163     void do_UnsafeGetRaw   (UnsafeGetRaw*    x) { /* nothing to do */ };
 164     void do_UnsafeGetObject(UnsafeGetObject* x) { /* nothing to do */ };
 165     void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) { /* nothing to do */ };
 166     void do_ProfileCall    (ProfileCall*     x) { /* nothing to do */ };
 167     void do_ProfileReturnType (ProfileReturnType*  x) { /* nothing to do */ };
 168     void do_ProfileInvoke  (ProfileInvoke*   x) { /* nothing to do */ };
 169     void do_RuntimeCall    (RuntimeCall*     x) { /* nothing to do */ };
 170     void do_MemBar         (MemBar*          x) { /* nothing to do */ };
 171     void do_RangeCheckPredicate(RangeCheckPredicate* x) { /* nothing to do */ };
 172 #ifdef ASSERT
 173     void do_Assert         (Assert*          x) { /* nothing to do */ };
 174 #endif
 175   };
 176 
 177 #ifdef ASSERT
 178   void add_assertions(Bound *bound, Instruction *instruction, Instruction *position);
 179 #endif
 180 
 181   typedef GrowableArray<Bound*> BoundStack;
 182   typedef GrowableArray<BoundStack*> BoundMap;
 183   typedef GrowableArray<AccessIndexed*> AccessIndexedList;
 184   typedef GrowableArray<Instruction*> InstructionList;



 185 
 186   class AccessIndexedInfo : public CompilationResourceObj  {
 187   public:
 188     AccessIndexedList *_list;
 189     int _min;
 190     int _max;
 191   };
 192 
 193   typedef GrowableArray<AccessIndexedInfo*> AccessIndexedInfoArray;
 194   BoundMap _bounds; // Mapping from Instruction's id to current bound
 195   AccessIndexedInfoArray _access_indexed_info; // Mapping from Instruction's id to AccessIndexedInfo for in block motion
 196   Visitor _visitor;
 197 
 198 public:
 199   RangeCheckEliminator(IR *ir);
 200 
 201   IR *ir() const { return _ir; }
 202 
 203   // Pass over the dominator tree to identify blocks where there's an oppportunity for optimization
 204   bool set_process_block_flags(BlockBegin *block);
 205   // The core of the optimization work: pass over the dominator tree
 206   // to propagate bound information, insert predicate out of loops,
 207   // eliminate bound checks when possible and perform in block motion
 208   void calc_bounds(BlockBegin *block, BlockBegin *loop_header);
 209   // reorder bound checks within a block in order to eliminate some of them
 210   void in_block_motion(BlockBegin *block, AccessIndexedList &accessIndexed, InstructionList &arrays);
 211 
 212   // update/access current bound
 213   void update_bound(IntegerStack &pushed, Value v, Instruction::Condition cond, Value value, int constant);


< prev index next >