aoqi@0: /* aoqi@0: * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_OPTO_IDEALKIT_HPP aoqi@0: #define SHARE_VM_OPTO_IDEALKIT_HPP aoqi@0: aoqi@0: #include "opto/addnode.hpp" aoqi@0: #include "opto/cfgnode.hpp" aoqi@0: #include "opto/connode.hpp" aoqi@0: #include "opto/divnode.hpp" aoqi@0: #include "opto/graphKit.hpp" aoqi@0: #include "opto/mulnode.hpp" aoqi@0: #include "opto/phaseX.hpp" aoqi@0: #include "opto/subnode.hpp" aoqi@0: #include "opto/type.hpp" aoqi@0: aoqi@0: //----------------------------------------------------------------------------- aoqi@0: //----------------------------IdealKit----------------------------------------- aoqi@0: // Set of utilities for creating control flow and scalar SSA data flow. aoqi@0: // Control: aoqi@0: // if_then(left, relop, right) aoqi@0: // else_ (optional) aoqi@0: // end_if aoqi@0: // loop(iv variable, initial, relop, limit) aoqi@0: // - sets iv to initial for first trip aoqi@0: // - exits when relation on limit is true aoqi@0: // - the values of initial and limit should be loop invariant aoqi@0: // - no increment, must be explicitly coded aoqi@0: // - final value of iv is available after end_loop (until dead()) aoqi@0: // end_loop aoqi@0: // make_label(number of gotos) aoqi@0: // goto_(label) aoqi@0: // bind(label) aoqi@0: // Data: aoqi@0: // ConI(integer constant) - create an integer constant aoqi@0: // set(variable, value) - assignment aoqi@0: // value(variable) - reference value aoqi@0: // dead(variable) - variable's value is no longer live aoqi@0: // increment(variable, value) - increment variable by value aoqi@0: // simple operations: AddI, SubI, AndI, LShiftI, etc. aoqi@0: // Example: aoqi@0: // Node* limit = ?? aoqi@0: // IdealVariable i(kit), j(kit); aoqi@0: // declarations_done(); aoqi@0: // Node* exit = make_label(1); // 1 goto aoqi@0: // set(j, ConI(0)); aoqi@0: // loop(i, ConI(0), BoolTest::lt, limit); { aoqi@0: // if_then(value(i), BoolTest::gt, ConI(5)) { aoqi@0: // set(j, ConI(1)); aoqi@0: // goto_(exit); dead(i); aoqi@0: // } end_if(); aoqi@0: // increment(i, ConI(1)); aoqi@0: // } end_loop(); dead(i); aoqi@0: // bind(exit); aoqi@0: // aoqi@0: // See string_indexOf for a more complete example. aoqi@0: aoqi@0: class IdealKit; aoqi@0: aoqi@0: // Variable definition for IdealKit aoqi@0: class IdealVariable: public StackObj { aoqi@0: friend class IdealKit; aoqi@0: private: aoqi@0: int _id; aoqi@0: void set_id(int id) { _id = id; } aoqi@0: public: aoqi@0: IdealVariable(IdealKit &k); aoqi@0: int id() { assert(has_id(),"uninitialized id"); return _id; } aoqi@0: bool has_id() { return _id >= 0; } aoqi@0: }; aoqi@0: aoqi@0: class IdealKit: public StackObj { aoqi@0: friend class IdealVariable; aoqi@0: // The main state (called a cvstate for Control and Variables) aoqi@0: // contains both the current values of the variables and the aoqi@0: // current set of predecessor control edges. The variable values aoqi@0: // are managed via a Node [in(1)..in(_var_ct)], and the predecessor aoqi@0: // control edges managed via a RegionNode. The in(0) of the Node aoqi@0: // for variables points to the RegionNode for the control edges. aoqi@0: protected: aoqi@0: Compile * const C; aoqi@0: PhaseGVN &_gvn; aoqi@0: GrowableArray* _pending_cvstates; // stack of cvstates aoqi@0: Node* _cvstate; // current cvstate (control, memory and variables) aoqi@0: uint _var_ct; // number of variables aoqi@0: bool _delay_all_transforms; // flag forcing all transforms to be delayed aoqi@0: Node* _initial_ctrl; // saves initial control until variables declared aoqi@0: Node* _initial_memory; // saves initial memory until variables declared aoqi@0: Node* _initial_i_o; // saves initial i_o until variables declared aoqi@0: aoqi@0: PhaseGVN& gvn() const { return _gvn; } aoqi@0: // Create a new cvstate filled with nulls aoqi@0: Node* new_cvstate(); // Create a new cvstate aoqi@0: Node* cvstate() { return _cvstate; } // current cvstate aoqi@0: Node* copy_cvstate(); // copy current cvstate aoqi@0: aoqi@0: void set_memory(Node* mem, uint alias_idx ); aoqi@0: void do_memory_merge(Node* merging, Node* join); aoqi@0: void clear(Node* m); // clear a cvstate aoqi@0: void stop() { clear(_cvstate); } // clear current cvstate aoqi@0: Node* delay_transform(Node* n); aoqi@0: Node* transform(Node* n); // gvn.transform or skip it aoqi@0: Node* promote_to_phi(Node* n, Node* reg);// Promote "n" to a phi on region "reg" aoqi@0: bool was_promoted_to_phi(Node* n, Node* reg) { aoqi@0: return (n->is_Phi() && n->in(0) == reg); aoqi@0: } aoqi@0: void declare(IdealVariable* v) { v->set_id(_var_ct++); } aoqi@0: // This declares the position where vars are kept in the cvstate aoqi@0: // For some degree of consistency we use the TypeFunc enum to aoqi@0: // soak up spots in the inputs even though we only use early Control aoqi@0: // and Memory slots. (So far.) aoqi@0: static const uint first_var; // = TypeFunc::Parms + 1; aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: enum State { NullS=0, BlockS=1, LoopS=2, IfThenS=4, ElseS=8, EndifS= 16 }; aoqi@0: GrowableArray* _state; aoqi@0: State state() { return (State)(_state->top()); } aoqi@0: #endif aoqi@0: aoqi@0: // Users should not care about slices only MergedMem so no access for them. aoqi@0: Node* memory(uint alias_idx); aoqi@0: aoqi@0: public: aoqi@0: IdealKit(GraphKit* gkit, bool delay_all_transforms = false, bool has_declarations = false); aoqi@0: ~IdealKit() { aoqi@0: stop(); aoqi@0: } aoqi@0: void sync_kit(GraphKit* gkit); aoqi@0: aoqi@0: // Control aoqi@0: Node* ctrl() { return _cvstate->in(TypeFunc::Control); } aoqi@0: void set_ctrl(Node* ctrl) { _cvstate->set_req(TypeFunc::Control, ctrl); } aoqi@0: Node* top() { return C->top(); } aoqi@0: MergeMemNode* merged_memory() { return _cvstate->in(TypeFunc::Memory)->as_MergeMem(); } aoqi@0: void set_all_memory(Node* mem) { _cvstate->set_req(TypeFunc::Memory, mem); } aoqi@0: Node* i_o() { return _cvstate->in(TypeFunc::I_O); } aoqi@0: void set_i_o(Node* c) { _cvstate->set_req(TypeFunc::I_O, c); } aoqi@0: void set(IdealVariable& v, Node* rhs) { _cvstate->set_req(first_var + v.id(), rhs); } aoqi@0: Node* value(IdealVariable& v) { return _cvstate->in(first_var + v.id()); } aoqi@0: void dead(IdealVariable& v) { set(v, (Node*)NULL); } aoqi@0: void if_then(Node* left, BoolTest::mask relop, Node* right, aoqi@0: float prob = PROB_FAIR, float cnt = COUNT_UNKNOWN, aoqi@0: bool push_new_state = true); aoqi@0: void else_(); aoqi@0: void end_if(); aoqi@0: void loop(GraphKit* gkit, int nargs, IdealVariable& iv, Node* init, BoolTest::mask cmp, Node* limit, aoqi@0: float prob = PROB_LIKELY(0.9), float cnt = COUNT_UNKNOWN); aoqi@0: void end_loop(); aoqi@0: Node* make_label(int goto_ct); aoqi@0: void bind(Node* lab); aoqi@0: void goto_(Node* lab, bool bind = false); aoqi@0: void declarations_done(); aoqi@0: aoqi@0: Node* IfTrue(IfNode* iff) { return transform(new (C) IfTrueNode(iff)); } aoqi@0: Node* IfFalse(IfNode* iff) { return transform(new (C) IfFalseNode(iff)); } aoqi@0: aoqi@0: // Data aoqi@0: Node* ConI(jint k) { return (Node*)gvn().intcon(k); } aoqi@0: Node* makecon(const Type *t) const { return _gvn.makecon(t); } aoqi@0: aoqi@0: Node* AddI(Node* l, Node* r) { return transform(new (C) AddINode(l, r)); } aoqi@0: Node* SubI(Node* l, Node* r) { return transform(new (C) SubINode(l, r)); } aoqi@0: Node* AndI(Node* l, Node* r) { return transform(new (C) AndINode(l, r)); } aoqi@0: Node* MaxI(Node* l, Node* r) { return transform(new (C) MaxINode(l, r)); } aoqi@0: Node* LShiftI(Node* l, Node* r) { return transform(new (C) LShiftINode(l, r)); } aoqi@0: Node* CmpI(Node* l, Node* r) { return transform(new (C) CmpINode(l, r)); } aoqi@0: Node* Bool(Node* cmp, BoolTest::mask relop) { return transform(new (C) BoolNode(cmp, relop)); } aoqi@0: void increment(IdealVariable& v, Node* j) { set(v, AddI(value(v), j)); } aoqi@0: void decrement(IdealVariable& v, Node* j) { set(v, SubI(value(v), j)); } aoqi@0: aoqi@0: Node* CmpL(Node* l, Node* r) { return transform(new (C) CmpLNode(l, r)); } aoqi@0: aoqi@0: // TLS aoqi@0: Node* thread() { return gvn().transform(new (C) ThreadLocalNode()); } aoqi@0: aoqi@0: // Pointers aoqi@0: aoqi@0: // Raw address should be transformed regardless 'delay_transform' flag aoqi@0: // to produce canonical form CastX2P(offset). aoqi@0: Node* AddP(Node *base, Node *ptr, Node *off) { return _gvn.transform(new (C) AddPNode(base, ptr, off)); } aoqi@0: aoqi@0: Node* CmpP(Node* l, Node* r) { return transform(new (C) CmpPNode(l, r)); } aoqi@0: #ifdef _LP64 aoqi@0: Node* XorX(Node* l, Node* r) { return transform(new (C) XorLNode(l, r)); } aoqi@0: #else // _LP64 aoqi@0: Node* XorX(Node* l, Node* r) { return transform(new (C) XorINode(l, r)); } aoqi@0: #endif // _LP64 aoqi@0: Node* URShiftX(Node* l, Node* r) { return transform(new (C) URShiftXNode(l, r)); } aoqi@0: Node* ConX(jint k) { return (Node*)gvn().MakeConX(k); } aoqi@0: Node* CastPX(Node* ctl, Node* p) { return transform(new (C) CastP2XNode(ctl, p)); } aoqi@0: aoqi@0: // Memory operations aoqi@0: aoqi@0: // This is the base version which is given an alias index. aoqi@0: Node* load(Node* ctl, aoqi@0: Node* adr, aoqi@0: const Type* t, aoqi@0: BasicType bt, aoqi@0: int adr_idx, aoqi@0: bool require_atomic_access = false); aoqi@0: aoqi@0: // Return the new StoreXNode aoqi@0: Node* store(Node* ctl, aoqi@0: Node* adr, aoqi@0: Node* val, aoqi@0: BasicType bt, aoqi@0: int adr_idx, aoqi@0: MemNode::MemOrd mo, aoqi@0: bool require_atomic_access = false); aoqi@0: aoqi@0: // Store a card mark ordered after store_oop aoqi@0: Node* storeCM(Node* ctl, aoqi@0: Node* adr, aoqi@0: Node* val, aoqi@0: Node* oop_store, aoqi@0: int oop_adr_idx, aoqi@0: BasicType bt, aoqi@0: int adr_idx); aoqi@0: aoqi@0: // Trivial call aoqi@0: void make_leaf_call(const TypeFunc *slow_call_type, aoqi@0: address slow_call, aoqi@0: const char *leaf_name, aoqi@0: Node* parm0, aoqi@0: Node* parm1 = NULL, aoqi@0: Node* parm2 = NULL, aoqi@0: Node* parm3 = NULL); aoqi@0: aoqi@0: void make_leaf_call_no_fp(const TypeFunc *slow_call_type, aoqi@0: address slow_call, aoqi@0: const char *leaf_name, aoqi@0: const TypePtr* adr_type, aoqi@0: Node* parm0, aoqi@0: Node* parm1, aoqi@0: Node* parm2, aoqi@0: Node* parm3); aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_OPTO_IDEALKIT_HPP