src/share/vm/opto/idealKit.hpp

Mon, 31 Oct 2011 03:06:42 -0700

author
twisti
date
Mon, 31 Oct 2011 03:06:42 -0700
changeset 3249
e3b0dcc327b9
parent 2750
6c97c830fb6f
child 4115
e626685e9f6c
permissions
-rw-r--r--

7104561: UseRDPCForConstantTableBase doesn't work after shorten branches changes
Reviewed-by: never, kvn

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

mercurial