1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/idealKit.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,261 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_OPTO_IDEALKIT_HPP 1.29 +#define SHARE_VM_OPTO_IDEALKIT_HPP 1.30 + 1.31 +#include "opto/addnode.hpp" 1.32 +#include "opto/cfgnode.hpp" 1.33 +#include "opto/connode.hpp" 1.34 +#include "opto/divnode.hpp" 1.35 +#include "opto/graphKit.hpp" 1.36 +#include "opto/mulnode.hpp" 1.37 +#include "opto/phaseX.hpp" 1.38 +#include "opto/subnode.hpp" 1.39 +#include "opto/type.hpp" 1.40 + 1.41 +//----------------------------------------------------------------------------- 1.42 +//----------------------------IdealKit----------------------------------------- 1.43 +// Set of utilities for creating control flow and scalar SSA data flow. 1.44 +// Control: 1.45 +// if_then(left, relop, right) 1.46 +// else_ (optional) 1.47 +// end_if 1.48 +// loop(iv variable, initial, relop, limit) 1.49 +// - sets iv to initial for first trip 1.50 +// - exits when relation on limit is true 1.51 +// - the values of initial and limit should be loop invariant 1.52 +// - no increment, must be explicitly coded 1.53 +// - final value of iv is available after end_loop (until dead()) 1.54 +// end_loop 1.55 +// make_label(number of gotos) 1.56 +// goto_(label) 1.57 +// bind(label) 1.58 +// Data: 1.59 +// ConI(integer constant) - create an integer constant 1.60 +// set(variable, value) - assignment 1.61 +// value(variable) - reference value 1.62 +// dead(variable) - variable's value is no longer live 1.63 +// increment(variable, value) - increment variable by value 1.64 +// simple operations: AddI, SubI, AndI, LShiftI, etc. 1.65 +// Example: 1.66 +// Node* limit = ?? 1.67 +// IdealVariable i(kit), j(kit); 1.68 +// declarations_done(); 1.69 +// Node* exit = make_label(1); // 1 goto 1.70 +// set(j, ConI(0)); 1.71 +// loop(i, ConI(0), BoolTest::lt, limit); { 1.72 +// if_then(value(i), BoolTest::gt, ConI(5)) { 1.73 +// set(j, ConI(1)); 1.74 +// goto_(exit); dead(i); 1.75 +// } end_if(); 1.76 +// increment(i, ConI(1)); 1.77 +// } end_loop(); dead(i); 1.78 +// bind(exit); 1.79 +// 1.80 +// See string_indexOf for a more complete example. 1.81 + 1.82 +class IdealKit; 1.83 + 1.84 +// Variable definition for IdealKit 1.85 +class IdealVariable: public StackObj { 1.86 + friend class IdealKit; 1.87 + private: 1.88 + int _id; 1.89 + void set_id(int id) { _id = id; } 1.90 + public: 1.91 + IdealVariable(IdealKit &k); 1.92 + int id() { assert(has_id(),"uninitialized id"); return _id; } 1.93 + bool has_id() { return _id >= 0; } 1.94 +}; 1.95 + 1.96 +class IdealKit: public StackObj { 1.97 + friend class IdealVariable; 1.98 + // The main state (called a cvstate for Control and Variables) 1.99 + // contains both the current values of the variables and the 1.100 + // current set of predecessor control edges. The variable values 1.101 + // are managed via a Node [in(1)..in(_var_ct)], and the predecessor 1.102 + // control edges managed via a RegionNode. The in(0) of the Node 1.103 + // for variables points to the RegionNode for the control edges. 1.104 + protected: 1.105 + Compile * const C; 1.106 + PhaseGVN &_gvn; 1.107 + GrowableArray<Node*>* _pending_cvstates; // stack of cvstates 1.108 + Node* _cvstate; // current cvstate (control, memory and variables) 1.109 + uint _var_ct; // number of variables 1.110 + bool _delay_all_transforms; // flag forcing all transforms to be delayed 1.111 + Node* _initial_ctrl; // saves initial control until variables declared 1.112 + Node* _initial_memory; // saves initial memory until variables declared 1.113 + Node* _initial_i_o; // saves initial i_o until variables declared 1.114 + 1.115 + PhaseGVN& gvn() const { return _gvn; } 1.116 + // Create a new cvstate filled with nulls 1.117 + Node* new_cvstate(); // Create a new cvstate 1.118 + Node* cvstate() { return _cvstate; } // current cvstate 1.119 + Node* copy_cvstate(); // copy current cvstate 1.120 + 1.121 + void set_memory(Node* mem, uint alias_idx ); 1.122 + void do_memory_merge(Node* merging, Node* join); 1.123 + void clear(Node* m); // clear a cvstate 1.124 + void stop() { clear(_cvstate); } // clear current cvstate 1.125 + Node* delay_transform(Node* n); 1.126 + Node* transform(Node* n); // gvn.transform or skip it 1.127 + Node* promote_to_phi(Node* n, Node* reg);// Promote "n" to a phi on region "reg" 1.128 + bool was_promoted_to_phi(Node* n, Node* reg) { 1.129 + return (n->is_Phi() && n->in(0) == reg); 1.130 + } 1.131 + void declare(IdealVariable* v) { v->set_id(_var_ct++); } 1.132 + // This declares the position where vars are kept in the cvstate 1.133 + // For some degree of consistency we use the TypeFunc enum to 1.134 + // soak up spots in the inputs even though we only use early Control 1.135 + // and Memory slots. (So far.) 1.136 + static const uint first_var; // = TypeFunc::Parms + 1; 1.137 + 1.138 +#ifdef ASSERT 1.139 + enum State { NullS=0, BlockS=1, LoopS=2, IfThenS=4, ElseS=8, EndifS= 16 }; 1.140 + GrowableArray<int>* _state; 1.141 + State state() { return (State)(_state->top()); } 1.142 +#endif 1.143 + 1.144 + // Users should not care about slices only MergedMem so no access for them. 1.145 + Node* memory(uint alias_idx); 1.146 + 1.147 + public: 1.148 + IdealKit(GraphKit* gkit, bool delay_all_transforms = false, bool has_declarations = false); 1.149 + ~IdealKit() { 1.150 + stop(); 1.151 + } 1.152 + void sync_kit(GraphKit* gkit); 1.153 + 1.154 + // Control 1.155 + Node* ctrl() { return _cvstate->in(TypeFunc::Control); } 1.156 + void set_ctrl(Node* ctrl) { _cvstate->set_req(TypeFunc::Control, ctrl); } 1.157 + Node* top() { return C->top(); } 1.158 + MergeMemNode* merged_memory() { return _cvstate->in(TypeFunc::Memory)->as_MergeMem(); } 1.159 + void set_all_memory(Node* mem) { _cvstate->set_req(TypeFunc::Memory, mem); } 1.160 + Node* i_o() { return _cvstate->in(TypeFunc::I_O); } 1.161 + void set_i_o(Node* c) { _cvstate->set_req(TypeFunc::I_O, c); } 1.162 + void set(IdealVariable& v, Node* rhs) { _cvstate->set_req(first_var + v.id(), rhs); } 1.163 + Node* value(IdealVariable& v) { return _cvstate->in(first_var + v.id()); } 1.164 + void dead(IdealVariable& v) { set(v, (Node*)NULL); } 1.165 + void if_then(Node* left, BoolTest::mask relop, Node* right, 1.166 + float prob = PROB_FAIR, float cnt = COUNT_UNKNOWN, 1.167 + bool push_new_state = true); 1.168 + void else_(); 1.169 + void end_if(); 1.170 + void loop(GraphKit* gkit, int nargs, IdealVariable& iv, Node* init, BoolTest::mask cmp, Node* limit, 1.171 + float prob = PROB_LIKELY(0.9), float cnt = COUNT_UNKNOWN); 1.172 + void end_loop(); 1.173 + Node* make_label(int goto_ct); 1.174 + void bind(Node* lab); 1.175 + void goto_(Node* lab, bool bind = false); 1.176 + void declarations_done(); 1.177 + 1.178 + Node* IfTrue(IfNode* iff) { return transform(new (C) IfTrueNode(iff)); } 1.179 + Node* IfFalse(IfNode* iff) { return transform(new (C) IfFalseNode(iff)); } 1.180 + 1.181 + // Data 1.182 + Node* ConI(jint k) { return (Node*)gvn().intcon(k); } 1.183 + Node* makecon(const Type *t) const { return _gvn.makecon(t); } 1.184 + 1.185 + Node* AddI(Node* l, Node* r) { return transform(new (C) AddINode(l, r)); } 1.186 + Node* SubI(Node* l, Node* r) { return transform(new (C) SubINode(l, r)); } 1.187 + Node* AndI(Node* l, Node* r) { return transform(new (C) AndINode(l, r)); } 1.188 + Node* MaxI(Node* l, Node* r) { return transform(new (C) MaxINode(l, r)); } 1.189 + Node* LShiftI(Node* l, Node* r) { return transform(new (C) LShiftINode(l, r)); } 1.190 + Node* CmpI(Node* l, Node* r) { return transform(new (C) CmpINode(l, r)); } 1.191 + Node* Bool(Node* cmp, BoolTest::mask relop) { return transform(new (C) BoolNode(cmp, relop)); } 1.192 + void increment(IdealVariable& v, Node* j) { set(v, AddI(value(v), j)); } 1.193 + void decrement(IdealVariable& v, Node* j) { set(v, SubI(value(v), j)); } 1.194 + 1.195 + Node* CmpL(Node* l, Node* r) { return transform(new (C) CmpLNode(l, r)); } 1.196 + 1.197 + // TLS 1.198 + Node* thread() { return gvn().transform(new (C) ThreadLocalNode()); } 1.199 + 1.200 + // Pointers 1.201 + 1.202 + // Raw address should be transformed regardless 'delay_transform' flag 1.203 + // to produce canonical form CastX2P(offset). 1.204 + Node* AddP(Node *base, Node *ptr, Node *off) { return _gvn.transform(new (C) AddPNode(base, ptr, off)); } 1.205 + 1.206 + Node* CmpP(Node* l, Node* r) { return transform(new (C) CmpPNode(l, r)); } 1.207 +#ifdef _LP64 1.208 + Node* XorX(Node* l, Node* r) { return transform(new (C) XorLNode(l, r)); } 1.209 +#else // _LP64 1.210 + Node* XorX(Node* l, Node* r) { return transform(new (C) XorINode(l, r)); } 1.211 +#endif // _LP64 1.212 + Node* URShiftX(Node* l, Node* r) { return transform(new (C) URShiftXNode(l, r)); } 1.213 + Node* ConX(jint k) { return (Node*)gvn().MakeConX(k); } 1.214 + Node* CastPX(Node* ctl, Node* p) { return transform(new (C) CastP2XNode(ctl, p)); } 1.215 + 1.216 + // Memory operations 1.217 + 1.218 + // This is the base version which is given an alias index. 1.219 + Node* load(Node* ctl, 1.220 + Node* adr, 1.221 + const Type* t, 1.222 + BasicType bt, 1.223 + int adr_idx, 1.224 + bool require_atomic_access = false); 1.225 + 1.226 + // Return the new StoreXNode 1.227 + Node* store(Node* ctl, 1.228 + Node* adr, 1.229 + Node* val, 1.230 + BasicType bt, 1.231 + int adr_idx, 1.232 + MemNode::MemOrd mo, 1.233 + bool require_atomic_access = false); 1.234 + 1.235 + // Store a card mark ordered after store_oop 1.236 + Node* storeCM(Node* ctl, 1.237 + Node* adr, 1.238 + Node* val, 1.239 + Node* oop_store, 1.240 + int oop_adr_idx, 1.241 + BasicType bt, 1.242 + int adr_idx); 1.243 + 1.244 + // Trivial call 1.245 + void make_leaf_call(const TypeFunc *slow_call_type, 1.246 + address slow_call, 1.247 + const char *leaf_name, 1.248 + Node* parm0, 1.249 + Node* parm1 = NULL, 1.250 + Node* parm2 = NULL, 1.251 + Node* parm3 = NULL); 1.252 + 1.253 + void make_leaf_call_no_fp(const TypeFunc *slow_call_type, 1.254 + address slow_call, 1.255 + const char *leaf_name, 1.256 + const TypePtr* adr_type, 1.257 + Node* parm0, 1.258 + Node* parm1, 1.259 + Node* parm2, 1.260 + Node* parm3); 1.261 + 1.262 +}; 1.263 + 1.264 +#endif // SHARE_VM_OPTO_IDEALKIT_HPP