src/hotspot/share/opto/opaquenode.hpp
author roland
Thu, 22 Mar 2018 20:21:19 -0700
changeset 49487 bde392011cd8
parent 47216 71c04702a3d5
child 51333 f6641fcf7b7e
permissions -rw-r--r--
8193130: Bad graph when unrolled loop bounds conflicts with range checks Reviewed-by: kvn, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     1
/*
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     4
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     8
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    13
 * accompanied this code).
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    14
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    18
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    21
 * questions.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    22
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    23
 */
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    24
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    25
#ifndef SHARE_VM_OPTO_OPAQUENODE_HPP
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    26
#define SHARE_VM_OPTO_OPAQUENODE_HPP
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    27
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    28
#include "opto/node.hpp"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    29
#include "opto/opcodes.hpp"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    30
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    31
//------------------------------Opaque1Node------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    32
// A node to prevent unwanted optimizations.  Allows constant folding.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    33
// Stops value-numbering, Ideal calls or Identity functions.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    34
class Opaque1Node : public Node {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    35
  virtual uint hash() const ;                  // { return NO_HASH; }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    36
  virtual uint cmp( const Node &n ) const;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    37
  public:
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    38
  Opaque1Node(Compile* C, Node *n) : Node(NULL, n) {
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    39
    // Put it on the Macro nodes list to removed during macro nodes expansion.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    40
    init_flags(Flag_is_macro);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    41
    C->add_macro_node(this);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    42
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    43
  // Special version for the pre-loop to hold the original loop limit
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    44
  // which is consumed by range check elimination.
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    45
  Opaque1Node(Compile* C, Node *n, Node* orig_limit) : Node(NULL, n, orig_limit) {
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    46
    // Put it on the Macro nodes list to removed during macro nodes expansion.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    47
    init_flags(Flag_is_macro);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    48
    C->add_macro_node(this);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    49
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    50
  Node* original_loop_limit() { return req()==3 ? in(2) : NULL; }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    51
  virtual int Opcode() const;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    52
  virtual const Type *bottom_type() const { return TypeInt::INT; }
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 28912
diff changeset
    53
  virtual Node* Identity(PhaseGVN* phase);
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    54
};
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    55
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    56
//------------------------------Opaque2Node------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    57
// A node to prevent unwanted optimizations.  Allows constant folding.  Stops
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    58
// value-numbering, most Ideal calls or Identity functions.  This Node is
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    59
// specifically designed to prevent the pre-increment value of a loop trip
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    60
// counter from being live out of the bottom of the loop (hence causing the
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    61
// pre- and post-increment values both being live and thus requiring an extra
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    62
// temp register and an extra move).  If we "accidentally" optimize through
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    63
// this kind of a Node, we'll get slightly pessimal, but correct, code.  Thus
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    64
// it's OK to be slightly sloppy on optimizations here.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    65
class Opaque2Node : public Node {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    66
  virtual uint hash() const ;                  // { return NO_HASH; }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    67
  virtual uint cmp( const Node &n ) const;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    68
  public:
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    69
  Opaque2Node( Compile* C, Node *n ) : Node(0,n) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    70
    // Put it on the Macro nodes list to removed during macro nodes expansion.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    71
    init_flags(Flag_is_macro);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    72
    C->add_macro_node(this);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    73
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    74
  virtual int Opcode() const;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    75
  virtual const Type *bottom_type() const { return TypeInt::INT; }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    76
};
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    77
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    78
//------------------------------Opaque3Node------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    79
// A node to prevent unwanted optimizations. Will be optimized only during
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    80
// macro nodes expansion.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    81
class Opaque3Node : public Opaque2Node {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    82
  int _opt; // what optimization it was used for
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    83
  public:
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    84
  enum { RTM_OPT };
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    85
  Opaque3Node(Compile* C, Node *n, int opt) : Opaque2Node(C, n), _opt(opt) {}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    86
  virtual int Opcode() const;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    87
  bool rtm_opt() const { return (_opt == RTM_OPT); }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    88
};
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    89
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    90
// Input 1 is a check that we know implicitly is always true or false
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    91
// but the compiler has no way to prove. If during optimizations, that
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    92
// check becomes true or false, the Opaque4 node is replaced by that
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    93
// constant true or false. Input 2 is the constant value we know the
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    94
// test takes. After loop optimizations, we replace input 1 by input 2
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    95
// so the control that depends on that test can be removed and there's
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    96
// no overhead at runtime. Used for instance by
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
    97
// GraphKit::must_be_not_null().
46525
3a5c833a43de 8176506: C2: loop unswitching and unsafe accesses cause crash
roland
parents: 35551
diff changeset
    98
class Opaque4Node : public Node {
3a5c833a43de 8176506: C2: loop unswitching and unsafe accesses cause crash
roland
parents: 35551
diff changeset
    99
  public:
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
   100
  Opaque4Node(Compile* C, Node *tst, Node* final_tst) : Node(NULL, tst, final_tst) {
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
   101
    // Put it on the Opaque4 nodes list to be removed after all optimizations
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 47216
diff changeset
   102
    C->add_opaque4_node(this);
46525
3a5c833a43de 8176506: C2: loop unswitching and unsafe accesses cause crash
roland
parents: 35551
diff changeset
   103
  }
3a5c833a43de 8176506: C2: loop unswitching and unsafe accesses cause crash
roland
parents: 35551
diff changeset
   104
  virtual int Opcode() const;
3a5c833a43de 8176506: C2: loop unswitching and unsafe accesses cause crash
roland
parents: 35551
diff changeset
   105
  virtual const Type *bottom_type() const { return TypeInt::BOOL; }
3a5c833a43de 8176506: C2: loop unswitching and unsafe accesses cause crash
roland
parents: 35551
diff changeset
   106
  virtual const Type* Value(PhaseGVN* phase) const;
3a5c833a43de 8176506: C2: loop unswitching and unsafe accesses cause crash
roland
parents: 35551
diff changeset
   107
};
3a5c833a43de 8176506: C2: loop unswitching and unsafe accesses cause crash
roland
parents: 35551
diff changeset
   108
3a5c833a43de 8176506: C2: loop unswitching and unsafe accesses cause crash
roland
parents: 35551
diff changeset
   109
28912
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   110
//------------------------------ProfileBooleanNode-------------------------------
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   111
// A node represents value profile for a boolean during parsing.
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   112
// Once parsing is over, the node goes away (during IGVN).
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   113
// It is used to override branch frequencies from MDO (see has_injected_profile in parse2.cpp).
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   114
class ProfileBooleanNode : public Node {
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   115
  uint _false_cnt;
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   116
  uint _true_cnt;
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   117
  bool _consumed;
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   118
  bool _delay_removal;
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   119
  virtual uint hash() const ;                  // { return NO_HASH; }
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   120
  virtual uint cmp( const Node &n ) const;
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   121
  public:
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   122
  ProfileBooleanNode(Node *n, uint false_cnt, uint true_cnt) : Node(0, n),
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   123
          _false_cnt(false_cnt), _true_cnt(true_cnt), _delay_removal(true), _consumed(false) {}
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   124
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   125
  uint false_count() const { return _false_cnt; }
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   126
  uint  true_count() const { return  _true_cnt; }
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   127
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   128
  void consume() { _consumed = true;  }
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   129
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   130
  virtual int Opcode() const;
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   131
  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 28912
diff changeset
   132
  virtual Node* Identity(PhaseGVN* phase);
28912
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   133
  virtual const Type *bottom_type() const { return TypeInt::BOOL; }
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   134
};
27fac2f8fdbe 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
vlivanov
parents: 23528
diff changeset
   135
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   136
#endif // SHARE_VM_OPTO_OPAQUENODE_HPP
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   137