hotspot/src/share/vm/c1/c1_RangeCheckElimination.hpp
author roland
Wed, 09 Oct 2013 16:32:21 +0200
changeset 20702 bbe0fcde6e13
parent 17011 def8879c5b81
child 20709 034be898bf04
permissions -rw-r--r--
8023657: New type profiling points: arguments to call Summary: x86 interpreter and c1 type profiling for arguments at calls Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
     1
/*
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
     4
 *
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
     8
 *
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    13
 * accompanied this code).
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    14
 *
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    18
 *
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    21
 * questions.
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    22
 *
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    23
 */
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    24
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    25
#ifndef SHARE_VM_C1_C1_RANGECHECKELIMINATION_HPP
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    26
#define SHARE_VM_C1_C1_RANGECHECKELIMINATION_HPP
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    27
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    28
#include "c1/c1_Instruction.hpp"
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    29
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    30
// Base class for range check elimination
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    31
class RangeCheckElimination : AllStatic {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    32
public:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    33
  static void eliminate(IR *ir);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    34
};
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    35
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    36
// Implementation
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    37
class RangeCheckEliminator VALUE_OBJ_CLASS_SPEC {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    38
private:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    39
  int _number_of_instructions;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    40
  bool _optimistic; // Insert predicates and deoptimize when they fail
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    41
  IR *_ir;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    42
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    43
  define_array(BlockBeginArray, BlockBegin*)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    44
  define_stack(BlockBeginList, BlockBeginArray)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    45
  define_stack(IntegerStack, intArray)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    46
  define_array(IntegerMap, IntegerStack*)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    47
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    48
  class Verification : public _ValueObj /*VALUE_OBJ_CLASS_SPEC*/, public BlockClosure {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    49
  private:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    50
    IR *_ir;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    51
    boolArray _used;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    52
    BlockBeginList _current;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    53
    BlockBeginList _successors;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    54
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    55
  public:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    56
    Verification(IR *ir);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    57
    virtual void block_do(BlockBegin *block);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    58
    bool can_reach(BlockBegin *start, BlockBegin *end, BlockBegin *dont_use = NULL);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    59
    bool dominates(BlockBegin *dominator, BlockBegin *block);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    60
  };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    61
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    62
public:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    63
  // Bounds for an instruction in the form x + c which c integer
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    64
  // constant and x another instruction
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    65
  class Bound : public CompilationResourceObj {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    66
  private:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    67
    int _upper;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    68
    Value _upper_instr;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    69
    int _lower;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    70
    Value _lower_instr;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    71
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    72
  public:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    73
    Bound();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    74
    Bound(Value v);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    75
    Bound(Instruction::Condition cond, Value v, int constant = 0);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    76
    Bound(int lower, Value lower_instr, int upper, Value upper_instr);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    77
    ~Bound();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    78
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    79
#ifdef ASSERT
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    80
    void add_assertion(Instruction *instruction, Instruction *position, int i, Value instr, Instruction::Condition cond);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    81
#endif
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    82
    int upper();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    83
    Value upper_instr();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    84
    int lower();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    85
    Value lower_instr();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    86
    void print();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    87
    bool check_no_overflow(int const_value);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    88
    void or_op(Bound *b);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    89
    void and_op(Bound *b);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    90
    bool has_upper();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    91
    bool has_lower();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    92
    void set_upper(int upper, Value upper_instr);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    93
    void set_lower(int lower, Value lower_instr);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    94
    bool is_smaller(Bound *b);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    95
    void remove_upper();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    96
    void remove_lower();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    97
    void add_constant(int value);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    98
    Bound *copy();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
    99
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   100
  private:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   101
    void init();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   102
  };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   103
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   104
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   105
  class Visitor : public InstructionVisitor {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   106
  private:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   107
    Bound *_bound;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   108
    RangeCheckEliminator *_rce;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   109
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   110
  public:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   111
    void set_range_check_eliminator(RangeCheckEliminator *rce) { _rce = rce; }
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   112
    Bound *bound() const { return _bound; }
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   113
    void clear_bound() { _bound = NULL; }
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   114
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   115
  protected:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   116
    // visitor functions
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   117
    void do_Constant       (Constant*        x);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   118
    void do_IfOp           (IfOp*            x);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   119
    void do_LogicOp        (LogicOp*         x);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   120
    void do_ArithmeticOp   (ArithmeticOp*    x);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   121
    void do_Phi            (Phi*             x);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   122
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   123
    void do_StoreField     (StoreField*      x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   124
    void do_StoreIndexed   (StoreIndexed*    x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   125
    void do_MonitorEnter   (MonitorEnter*    x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   126
    void do_MonitorExit    (MonitorExit*     x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   127
    void do_Invoke         (Invoke*          x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   128
    void do_UnsafePutRaw   (UnsafePutRaw*    x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   129
    void do_UnsafePutObject(UnsafePutObject* x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   130
    void do_Intrinsic      (Intrinsic*       x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   131
    void do_Local          (Local*           x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   132
    void do_LoadField      (LoadField*       x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   133
    void do_ArrayLength    (ArrayLength*     x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   134
    void do_LoadIndexed    (LoadIndexed*     x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   135
    void do_NegateOp       (NegateOp*        x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   136
    void do_ShiftOp        (ShiftOp*         x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   137
    void do_CompareOp      (CompareOp*       x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   138
    void do_Convert        (Convert*         x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   139
    void do_NullCheck      (NullCheck*       x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   140
    void do_TypeCast       (TypeCast*        x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   141
    void do_NewInstance    (NewInstance*     x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   142
    void do_NewTypeArray   (NewTypeArray*    x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   143
    void do_NewObjectArray (NewObjectArray*  x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   144
    void do_NewMultiArray  (NewMultiArray*   x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   145
    void do_CheckCast      (CheckCast*       x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   146
    void do_InstanceOf     (InstanceOf*      x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   147
    void do_BlockBegin     (BlockBegin*      x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   148
    void do_Goto           (Goto*            x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   149
    void do_If             (If*              x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   150
    void do_IfInstanceOf   (IfInstanceOf*    x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   151
    void do_TableSwitch    (TableSwitch*     x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   152
    void do_LookupSwitch   (LookupSwitch*    x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   153
    void do_Return         (Return*          x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   154
    void do_Throw          (Throw*           x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   155
    void do_Base           (Base*            x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   156
    void do_OsrEntry       (OsrEntry*        x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   157
    void do_ExceptionObject(ExceptionObject* x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   158
    void do_RoundFP        (RoundFP*         x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   159
    void do_UnsafeGetRaw   (UnsafeGetRaw*    x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   160
    void do_UnsafeGetObject(UnsafeGetObject* x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   161
    void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   162
    void do_UnsafePrefetchRead (UnsafePrefetchRead*  x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   163
    void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   164
    void do_ProfileCall    (ProfileCall*     x) { /* nothing to do */ };
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 17011
diff changeset
   165
    void do_ProfileInvoke  (ProfileInvoke*   x) { /* nothing to do */ };
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   166
    void do_RuntimeCall    (RuntimeCall*     x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   167
    void do_MemBar         (MemBar*          x) { /* nothing to do */ };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   168
    void do_RangeCheckPredicate(RangeCheckPredicate* x) { /* nothing to do */ };
17011
def8879c5b81 8011648: C1: optimized build is broken after 7153771
roland
parents: 16611
diff changeset
   169
#ifdef ASSERT
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   170
    void do_Assert         (Assert*          x) { /* nothing to do */ };
17011
def8879c5b81 8011648: C1: optimized build is broken after 7153771
roland
parents: 16611
diff changeset
   171
#endif
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   172
  };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   173
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   174
#ifdef ASSERT
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   175
  void add_assertions(Bound *bound, Instruction *instruction, Instruction *position);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   176
#endif
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   177
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   178
  define_array(BoundArray, Bound *)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   179
  define_stack(BoundStack, BoundArray)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   180
  define_array(BoundMap, BoundStack *)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   181
  define_array(AccessIndexedArray, AccessIndexed *)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   182
  define_stack(AccessIndexedList, AccessIndexedArray)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   183
  define_array(InstructionArray, Instruction *)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   184
  define_stack(InstructionList, InstructionArray)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   185
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   186
  class AccessIndexedInfo : public CompilationResourceObj  {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   187
  public:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   188
    AccessIndexedList *_list;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   189
    int _min;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   190
    int _max;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   191
  };
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   192
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   193
  define_array(AccessIndexedInfoArray, AccessIndexedInfo *)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   194
  BoundMap _bounds; // Mapping from Instruction's id to current bound
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   195
  AccessIndexedInfoArray _access_indexed_info; // Mapping from Instruction's id to AccessIndexedInfo for in block motion
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   196
  Visitor _visitor;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   197
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   198
public:
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   199
  RangeCheckEliminator(IR *ir);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   200
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   201
  IR *ir() const { return _ir; }
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   202
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   203
  // Pass over the dominator tree to identify blocks where there's an oppportunity for optimization
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   204
  bool set_process_block_flags(BlockBegin *block);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   205
  // The core of the optimization work: pass over the dominator tree
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   206
  // to propagate bound information, insert predicate out of loops,
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   207
  // eliminate bound checks when possible and perform in block motion
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   208
  void calc_bounds(BlockBegin *block, BlockBegin *loop_header);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   209
  // reorder bound checks within a block in order to eliminate some of them
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   210
  void in_block_motion(BlockBegin *block, AccessIndexedList &accessIndexed, InstructionList &arrays);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   211
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   212
  // update/access current bound
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   213
  void update_bound(IntegerStack &pushed, Value v, Instruction::Condition cond, Value value, int constant);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   214
  void update_bound(IntegerStack &pushed, Value v, Bound *bound);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   215
  Bound *get_bound(Value v);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   216
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   217
  bool loop_invariant(BlockBegin *loop_header, Instruction *instruction);                                    // check for loop invariance
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   218
  void add_access_indexed_info(InstructionList &indices, int i, Value instruction, AccessIndexed *ai); // record indexed access for in block motion
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   219
  void remove_range_check(AccessIndexed *ai);                                                                // Mark this instructions as not needing a range check
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   220
  void add_if_condition(IntegerStack &pushed, Value x, Value y, Instruction::Condition condition);           // Update bound for an If
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   221
  bool in_array_bound(Bound *bound, Value array);                                                            // Check whether bound is known to fall within array
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   222
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   223
  // helper functions to work with predicates
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   224
  Instruction* insert_after(Instruction* insert_position, Instruction* instr, int bci);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   225
  Instruction* predicate(Instruction* left, Instruction::Condition cond, Instruction* right, ValueStack* state, Instruction *insert_position, int bci=-1);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   226
  Instruction* predicate_cmp_with_const(Instruction* instr, Instruction::Condition cond, int constant, ValueStack* state, Instruction *insert_position, int bci=1);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   227
  Instruction* predicate_add(Instruction* left, int left_const, Instruction::Condition cond, Instruction* right, ValueStack* state, Instruction *insert_position, int bci=-1);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   228
  Instruction* predicate_add_cmp_with_const(Instruction* left, int left_const, Instruction::Condition cond, int constant, ValueStack* state, Instruction *insert_position, int bci=-1);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   229
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   230
  void insert_deoptimization(ValueStack *state, Instruction *insert_position, Instruction *array_instr,      // Add predicate
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   231
                             Instruction *length_instruction, Instruction *lower_instr, int lower,
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   232
                             Instruction *upper_instr, int upper, AccessIndexed *ai);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   233
  bool is_ok_for_deoptimization(Instruction *insert_position, Instruction *array_instr,                      // Can we safely add a predicate?
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   234
                                Instruction *length_instr, Instruction *lower_instr,
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   235
                                int lower, Instruction *upper_instr, int upper);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   236
  void process_if(IntegerStack &pushed, BlockBegin *block, If *cond);                                        // process If Instruction
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   237
  void process_access_indexed(BlockBegin *loop_header, BlockBegin *block, AccessIndexed *ai);                // process indexed access
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   238
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   239
  void dump_condition_stack(BlockBegin *cur_block);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   240
  static void print_statistics();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   241
};
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   242
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents:
diff changeset
   243
#endif // SHARE_VM_C1_C1_RANGECHECKELIMINATION_HPP