src/share/vm/opto/idealKit.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_OPTO_IDEALKIT_HPP
aoqi@0 26 #define SHARE_VM_OPTO_IDEALKIT_HPP
aoqi@0 27
aoqi@0 28 #include "opto/addnode.hpp"
aoqi@0 29 #include "opto/cfgnode.hpp"
aoqi@0 30 #include "opto/connode.hpp"
aoqi@0 31 #include "opto/divnode.hpp"
aoqi@0 32 #include "opto/graphKit.hpp"
aoqi@0 33 #include "opto/mulnode.hpp"
aoqi@0 34 #include "opto/phaseX.hpp"
aoqi@0 35 #include "opto/subnode.hpp"
aoqi@0 36 #include "opto/type.hpp"
aoqi@0 37
aoqi@0 38 //-----------------------------------------------------------------------------
aoqi@0 39 //----------------------------IdealKit-----------------------------------------
aoqi@0 40 // Set of utilities for creating control flow and scalar SSA data flow.
aoqi@0 41 // Control:
aoqi@0 42 // if_then(left, relop, right)
aoqi@0 43 // else_ (optional)
aoqi@0 44 // end_if
aoqi@0 45 // loop(iv variable, initial, relop, limit)
aoqi@0 46 // - sets iv to initial for first trip
aoqi@0 47 // - exits when relation on limit is true
aoqi@0 48 // - the values of initial and limit should be loop invariant
aoqi@0 49 // - no increment, must be explicitly coded
aoqi@0 50 // - final value of iv is available after end_loop (until dead())
aoqi@0 51 // end_loop
aoqi@0 52 // make_label(number of gotos)
aoqi@0 53 // goto_(label)
aoqi@0 54 // bind(label)
aoqi@0 55 // Data:
aoqi@0 56 // ConI(integer constant) - create an integer constant
aoqi@0 57 // set(variable, value) - assignment
aoqi@0 58 // value(variable) - reference value
aoqi@0 59 // dead(variable) - variable's value is no longer live
aoqi@0 60 // increment(variable, value) - increment variable by value
aoqi@0 61 // simple operations: AddI, SubI, AndI, LShiftI, etc.
aoqi@0 62 // Example:
aoqi@0 63 // Node* limit = ??
aoqi@0 64 // IdealVariable i(kit), j(kit);
aoqi@0 65 // declarations_done();
aoqi@0 66 // Node* exit = make_label(1); // 1 goto
aoqi@0 67 // set(j, ConI(0));
aoqi@0 68 // loop(i, ConI(0), BoolTest::lt, limit); {
aoqi@0 69 // if_then(value(i), BoolTest::gt, ConI(5)) {
aoqi@0 70 // set(j, ConI(1));
aoqi@0 71 // goto_(exit); dead(i);
aoqi@0 72 // } end_if();
aoqi@0 73 // increment(i, ConI(1));
aoqi@0 74 // } end_loop(); dead(i);
aoqi@0 75 // bind(exit);
aoqi@0 76 //
aoqi@0 77 // See string_indexOf for a more complete example.
aoqi@0 78
aoqi@0 79 class IdealKit;
aoqi@0 80
aoqi@0 81 // Variable definition for IdealKit
aoqi@0 82 class IdealVariable: public StackObj {
aoqi@0 83 friend class IdealKit;
aoqi@0 84 private:
aoqi@0 85 int _id;
aoqi@0 86 void set_id(int id) { _id = id; }
aoqi@0 87 public:
aoqi@0 88 IdealVariable(IdealKit &k);
aoqi@0 89 int id() { assert(has_id(),"uninitialized id"); return _id; }
aoqi@0 90 bool has_id() { return _id >= 0; }
aoqi@0 91 };
aoqi@0 92
aoqi@0 93 class IdealKit: public StackObj {
aoqi@0 94 friend class IdealVariable;
aoqi@0 95 // The main state (called a cvstate for Control and Variables)
aoqi@0 96 // contains both the current values of the variables and the
aoqi@0 97 // current set of predecessor control edges. The variable values
aoqi@0 98 // are managed via a Node [in(1)..in(_var_ct)], and the predecessor
aoqi@0 99 // control edges managed via a RegionNode. The in(0) of the Node
aoqi@0 100 // for variables points to the RegionNode for the control edges.
aoqi@0 101 protected:
aoqi@0 102 Compile * const C;
aoqi@0 103 PhaseGVN &_gvn;
aoqi@0 104 GrowableArray<Node*>* _pending_cvstates; // stack of cvstates
aoqi@0 105 Node* _cvstate; // current cvstate (control, memory and variables)
aoqi@0 106 uint _var_ct; // number of variables
aoqi@0 107 bool _delay_all_transforms; // flag forcing all transforms to be delayed
aoqi@0 108 Node* _initial_ctrl; // saves initial control until variables declared
aoqi@0 109 Node* _initial_memory; // saves initial memory until variables declared
aoqi@0 110 Node* _initial_i_o; // saves initial i_o until variables declared
aoqi@0 111
aoqi@0 112 PhaseGVN& gvn() const { return _gvn; }
aoqi@0 113 // Create a new cvstate filled with nulls
aoqi@0 114 Node* new_cvstate(); // Create a new cvstate
aoqi@0 115 Node* cvstate() { return _cvstate; } // current cvstate
aoqi@0 116 Node* copy_cvstate(); // copy current cvstate
aoqi@0 117
aoqi@0 118 void set_memory(Node* mem, uint alias_idx );
aoqi@0 119 void do_memory_merge(Node* merging, Node* join);
aoqi@0 120 void clear(Node* m); // clear a cvstate
aoqi@0 121 void stop() { clear(_cvstate); } // clear current cvstate
aoqi@0 122 Node* delay_transform(Node* n);
aoqi@0 123 Node* transform(Node* n); // gvn.transform or skip it
aoqi@0 124 Node* promote_to_phi(Node* n, Node* reg);// Promote "n" to a phi on region "reg"
aoqi@0 125 bool was_promoted_to_phi(Node* n, Node* reg) {
aoqi@0 126 return (n->is_Phi() && n->in(0) == reg);
aoqi@0 127 }
aoqi@0 128 void declare(IdealVariable* v) { v->set_id(_var_ct++); }
aoqi@0 129 // This declares the position where vars are kept in the cvstate
aoqi@0 130 // For some degree of consistency we use the TypeFunc enum to
aoqi@0 131 // soak up spots in the inputs even though we only use early Control
aoqi@0 132 // and Memory slots. (So far.)
aoqi@0 133 static const uint first_var; // = TypeFunc::Parms + 1;
aoqi@0 134
aoqi@0 135 #ifdef ASSERT
aoqi@0 136 enum State { NullS=0, BlockS=1, LoopS=2, IfThenS=4, ElseS=8, EndifS= 16 };
aoqi@0 137 GrowableArray<int>* _state;
aoqi@0 138 State state() { return (State)(_state->top()); }
aoqi@0 139 #endif
aoqi@0 140
aoqi@0 141 // Users should not care about slices only MergedMem so no access for them.
aoqi@0 142 Node* memory(uint alias_idx);
aoqi@0 143
aoqi@0 144 public:
aoqi@0 145 IdealKit(GraphKit* gkit, bool delay_all_transforms = false, bool has_declarations = false);
aoqi@0 146 ~IdealKit() {
aoqi@0 147 stop();
aoqi@0 148 }
aoqi@0 149 void sync_kit(GraphKit* gkit);
aoqi@0 150
aoqi@0 151 // Control
aoqi@0 152 Node* ctrl() { return _cvstate->in(TypeFunc::Control); }
aoqi@0 153 void set_ctrl(Node* ctrl) { _cvstate->set_req(TypeFunc::Control, ctrl); }
aoqi@0 154 Node* top() { return C->top(); }
aoqi@0 155 MergeMemNode* merged_memory() { return _cvstate->in(TypeFunc::Memory)->as_MergeMem(); }
aoqi@0 156 void set_all_memory(Node* mem) { _cvstate->set_req(TypeFunc::Memory, mem); }
aoqi@0 157 Node* i_o() { return _cvstate->in(TypeFunc::I_O); }
aoqi@0 158 void set_i_o(Node* c) { _cvstate->set_req(TypeFunc::I_O, c); }
aoqi@0 159 void set(IdealVariable& v, Node* rhs) { _cvstate->set_req(first_var + v.id(), rhs); }
aoqi@0 160 Node* value(IdealVariable& v) { return _cvstate->in(first_var + v.id()); }
aoqi@0 161 void dead(IdealVariable& v) { set(v, (Node*)NULL); }
aoqi@0 162 void if_then(Node* left, BoolTest::mask relop, Node* right,
aoqi@0 163 float prob = PROB_FAIR, float cnt = COUNT_UNKNOWN,
aoqi@0 164 bool push_new_state = true);
aoqi@0 165 void else_();
aoqi@0 166 void end_if();
aoqi@0 167 void loop(GraphKit* gkit, int nargs, IdealVariable& iv, Node* init, BoolTest::mask cmp, Node* limit,
aoqi@0 168 float prob = PROB_LIKELY(0.9), float cnt = COUNT_UNKNOWN);
aoqi@0 169 void end_loop();
aoqi@0 170 Node* make_label(int goto_ct);
aoqi@0 171 void bind(Node* lab);
aoqi@0 172 void goto_(Node* lab, bool bind = false);
aoqi@0 173 void declarations_done();
aoqi@0 174
aoqi@0 175 Node* IfTrue(IfNode* iff) { return transform(new (C) IfTrueNode(iff)); }
aoqi@0 176 Node* IfFalse(IfNode* iff) { return transform(new (C) IfFalseNode(iff)); }
aoqi@0 177
aoqi@0 178 // Data
aoqi@0 179 Node* ConI(jint k) { return (Node*)gvn().intcon(k); }
aoqi@0 180 Node* makecon(const Type *t) const { return _gvn.makecon(t); }
aoqi@0 181
aoqi@0 182 Node* AddI(Node* l, Node* r) { return transform(new (C) AddINode(l, r)); }
aoqi@0 183 Node* SubI(Node* l, Node* r) { return transform(new (C) SubINode(l, r)); }
aoqi@0 184 Node* AndI(Node* l, Node* r) { return transform(new (C) AndINode(l, r)); }
aoqi@0 185 Node* MaxI(Node* l, Node* r) { return transform(new (C) MaxINode(l, r)); }
aoqi@0 186 Node* LShiftI(Node* l, Node* r) { return transform(new (C) LShiftINode(l, r)); }
aoqi@0 187 Node* CmpI(Node* l, Node* r) { return transform(new (C) CmpINode(l, r)); }
aoqi@0 188 Node* Bool(Node* cmp, BoolTest::mask relop) { return transform(new (C) BoolNode(cmp, relop)); }
aoqi@0 189 void increment(IdealVariable& v, Node* j) { set(v, AddI(value(v), j)); }
aoqi@0 190 void decrement(IdealVariable& v, Node* j) { set(v, SubI(value(v), j)); }
aoqi@0 191
aoqi@0 192 Node* CmpL(Node* l, Node* r) { return transform(new (C) CmpLNode(l, r)); }
aoqi@0 193
aoqi@0 194 // TLS
aoqi@0 195 Node* thread() { return gvn().transform(new (C) ThreadLocalNode()); }
aoqi@0 196
aoqi@0 197 // Pointers
aoqi@0 198
aoqi@0 199 // Raw address should be transformed regardless 'delay_transform' flag
aoqi@0 200 // to produce canonical form CastX2P(offset).
aoqi@0 201 Node* AddP(Node *base, Node *ptr, Node *off) { return _gvn.transform(new (C) AddPNode(base, ptr, off)); }
aoqi@0 202
aoqi@0 203 Node* CmpP(Node* l, Node* r) { return transform(new (C) CmpPNode(l, r)); }
aoqi@0 204 #ifdef _LP64
aoqi@0 205 Node* XorX(Node* l, Node* r) { return transform(new (C) XorLNode(l, r)); }
aoqi@0 206 #else // _LP64
aoqi@0 207 Node* XorX(Node* l, Node* r) { return transform(new (C) XorINode(l, r)); }
aoqi@0 208 #endif // _LP64
aoqi@0 209 Node* URShiftX(Node* l, Node* r) { return transform(new (C) URShiftXNode(l, r)); }
aoqi@0 210 Node* ConX(jint k) { return (Node*)gvn().MakeConX(k); }
aoqi@0 211 Node* CastPX(Node* ctl, Node* p) { return transform(new (C) CastP2XNode(ctl, p)); }
aoqi@0 212
aoqi@0 213 // Memory operations
aoqi@0 214
aoqi@0 215 // This is the base version which is given an alias index.
aoqi@0 216 Node* load(Node* ctl,
aoqi@0 217 Node* adr,
aoqi@0 218 const Type* t,
aoqi@0 219 BasicType bt,
aoqi@0 220 int adr_idx,
aoqi@0 221 bool require_atomic_access = false);
aoqi@0 222
aoqi@0 223 // Return the new StoreXNode
aoqi@0 224 Node* store(Node* ctl,
aoqi@0 225 Node* adr,
aoqi@0 226 Node* val,
aoqi@0 227 BasicType bt,
aoqi@0 228 int adr_idx,
aoqi@0 229 MemNode::MemOrd mo,
aoqi@0 230 bool require_atomic_access = false);
aoqi@0 231
aoqi@0 232 // Store a card mark ordered after store_oop
aoqi@0 233 Node* storeCM(Node* ctl,
aoqi@0 234 Node* adr,
aoqi@0 235 Node* val,
aoqi@0 236 Node* oop_store,
aoqi@0 237 int oop_adr_idx,
aoqi@0 238 BasicType bt,
aoqi@0 239 int adr_idx);
aoqi@0 240
aoqi@0 241 // Trivial call
aoqi@0 242 void make_leaf_call(const TypeFunc *slow_call_type,
aoqi@0 243 address slow_call,
aoqi@0 244 const char *leaf_name,
aoqi@0 245 Node* parm0,
aoqi@0 246 Node* parm1 = NULL,
aoqi@0 247 Node* parm2 = NULL,
aoqi@0 248 Node* parm3 = NULL);
aoqi@0 249
aoqi@0 250 void make_leaf_call_no_fp(const TypeFunc *slow_call_type,
aoqi@0 251 address slow_call,
aoqi@0 252 const char *leaf_name,
aoqi@0 253 const TypePtr* adr_type,
aoqi@0 254 Node* parm0,
aoqi@0 255 Node* parm1,
aoqi@0 256 Node* parm2,
aoqi@0 257 Node* parm3);
aoqi@0 258
aoqi@0 259 };
aoqi@0 260
aoqi@0 261 #endif // SHARE_VM_OPTO_IDEALKIT_HPP

mercurial