src/share/vm/opto/idealKit.hpp

changeset 435
a61af66fc99e
child 1286
fc4be448891f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/opto/idealKit.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,230 @@
     1.4 +/*
     1.5 + * Copyright 2005-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +//-----------------------------------------------------------------------------
    1.29 +//----------------------------IdealKit-----------------------------------------
    1.30 +// Set of utilities for creating control flow and scalar SSA data flow.
    1.31 +// Control:
    1.32 +//    if_then(left, relop, right)
    1.33 +//    else_ (optional)
    1.34 +//    end_if
    1.35 +//    loop(iv variable, initial, relop, limit)
    1.36 +//       - sets iv to initial for first trip
    1.37 +//       - exits when relation on limit is true
    1.38 +//       - the values of initial and limit should be loop invariant
    1.39 +//       - no increment, must be explicitly coded
    1.40 +//       - final value of iv is available after end_loop (until dead())
    1.41 +//    end_loop
    1.42 +//    make_label(number of gotos)
    1.43 +//    goto_(label)
    1.44 +//    bind(label)
    1.45 +// Data:
    1.46 +//    ConI(integer constant)     - create an integer constant
    1.47 +//    set(variable, value)       - assignment
    1.48 +//    value(variable)            - reference value
    1.49 +//    dead(variable)             - variable's value is no longer live
    1.50 +//    increment(variable, value) - increment variable by value
    1.51 +//    simple operations: AddI, SubI, AndI, LShiftI, etc.
    1.52 +// Example:
    1.53 +//    Node* limit = ??
    1.54 +//    IdealVariable i(kit), j(kit);
    1.55 +//    declares_done();
    1.56 +//    Node* exit = make_label(1); // 1 goto
    1.57 +//    set(j, ConI(0));
    1.58 +//    loop(i, ConI(0), BoolTest::lt, limit); {
    1.59 +//       if_then(value(i), BoolTest::gt, ConI(5)) {
    1.60 +//         set(j, ConI(1));
    1.61 +//         goto_(exit); dead(i);
    1.62 +//       } end_if();
    1.63 +//       increment(i, ConI(1));
    1.64 +//    } end_loop(); dead(i);
    1.65 +//    bind(exit);
    1.66 +//
    1.67 +// See string_indexOf for a more complete example.
    1.68 +
    1.69 +class IdealKit;
    1.70 +
    1.71 +// Variable definition for IdealKit
    1.72 +class IdealVariable: public StackObj {
    1.73 + friend class IdealKit;
    1.74 + private:
    1.75 +  int _id;
    1.76 +  void set_id(int id) { _id = id; }
    1.77 + public:
    1.78 +  IdealVariable(IdealKit &k);
    1.79 +  int id() { assert(has_id(),"uninitialized id"); return _id; }
    1.80 +  bool has_id() { return _id >= 0; }
    1.81 +};
    1.82 +
    1.83 +class IdealKit: public StackObj {
    1.84 + friend class IdealVariable;
    1.85 +  // The main state (called a cvstate for Control and Variables)
    1.86 +  // contains both the current values of the variables and the
    1.87 +  // current set of predecessor control edges.  The variable values
    1.88 +  // are managed via a Node [in(1)..in(_var_ct)], and the predecessor
    1.89 +  // control edges managed via a RegionNode. The in(0) of the Node
    1.90 +  // for variables points to the RegionNode for the control edges.
    1.91 + protected:
    1.92 +  Compile * const C;
    1.93 +  PhaseGVN &_gvn;
    1.94 +  GrowableArray<Node*>* _pending_cvstates; // stack of cvstates
    1.95 +  GrowableArray<Node*>* _delay_transform;  // delay invoking gvn.transform until drain
    1.96 +  Node* _cvstate;                          // current cvstate (control, memory and variables)
    1.97 +  uint _var_ct;                            // number of variables
    1.98 +  bool _delay_all_transforms;              // flag forcing all transforms to be delayed
    1.99 +  Node* _initial_ctrl;                     // saves initial control until variables declared
   1.100 +  Node* _initial_memory;                   // saves initial memory  until variables declared
   1.101 +
   1.102 +  PhaseGVN& gvn() const { return _gvn; }
   1.103 +  // Create a new cvstate filled with nulls
   1.104 +  Node* new_cvstate();                     // Create a new cvstate
   1.105 +  Node* cvstate() { return _cvstate; }     // current cvstate
   1.106 +  Node* copy_cvstate();                    // copy current cvstate
   1.107 +  void set_ctrl(Node* ctrl) { _cvstate->set_req(TypeFunc::Control, ctrl); }
   1.108 +
   1.109 +  // Should this assert this is a MergeMem???
   1.110 +  void set_all_memory(Node* mem){ _cvstate->set_req(TypeFunc::Memory, mem); }
   1.111 +  void set_memory(Node* mem, uint alias_idx );
   1.112 +  void do_memory_merge(Node* merging, Node* join);
   1.113 +  void clear(Node* m);                     // clear a cvstate
   1.114 +  void stop() { clear(_cvstate); }         // clear current cvstate
   1.115 +  Node* delay_transform(Node* n);
   1.116 +  Node* transform(Node* n);                // gvn.transform or push node on delay list
   1.117 +  Node* promote_to_phi(Node* n, Node* reg);// Promote "n" to a phi on region "reg"
   1.118 +  bool was_promoted_to_phi(Node* n, Node* reg) {
   1.119 +    return (n->is_Phi() && n->in(0) == reg);
   1.120 +  }
   1.121 +  void declare(IdealVariable* v) { v->set_id(_var_ct++); }
   1.122 +  // This declares the position where vars are kept in the cvstate
   1.123 +  // For some degree of consistency we use the TypeFunc enum to
   1.124 +  // soak up spots in the inputs even though we only use early Control
   1.125 +  // and Memory slots. (So far.)
   1.126 +  static const uint first_var; // = TypeFunc::Parms + 1;
   1.127 +
   1.128 +#ifdef ASSERT
   1.129 +  enum State { NullS=0, BlockS=1, LoopS=2, IfThenS=4, ElseS=8, EndifS= 16 };
   1.130 +  GrowableArray<int>* _state;
   1.131 +  State state() { return (State)(_state->top()); }
   1.132 +#endif
   1.133 +
   1.134 +  // Users should not care about slices only MergedMem so no access for them.
   1.135 +  Node* memory(uint alias_idx);
   1.136 +
   1.137 + public:
   1.138 +  IdealKit(PhaseGVN &gvn, Node* control, Node* memory, bool delay_all_transforms = false);
   1.139 +  ~IdealKit() {
   1.140 +    stop();
   1.141 +    drain_delay_transform();
   1.142 +  }
   1.143 +  // Control
   1.144 +  Node* ctrl()                          { return _cvstate->in(TypeFunc::Control); }
   1.145 +  Node* top()                           { return C->top(); }
   1.146 +  MergeMemNode* merged_memory()         { return _cvstate->in(TypeFunc::Memory)->as_MergeMem(); }
   1.147 +  void set(IdealVariable& v, Node* rhs) { _cvstate->set_req(first_var + v.id(), rhs); }
   1.148 +  Node* value(IdealVariable& v)         { return _cvstate->in(first_var + v.id()); }
   1.149 +  void dead(IdealVariable& v)           { set(v, (Node*)NULL); }
   1.150 +  void if_then(Node* left, BoolTest::mask relop, Node* right,
   1.151 +               float prob = PROB_FAIR, float cnt = COUNT_UNKNOWN,
   1.152 +               bool push_new_state = true);
   1.153 +  void else_();
   1.154 +  void end_if();
   1.155 +  void loop(IdealVariable& iv, Node* init, BoolTest::mask cmp, Node* limit,
   1.156 +            float prob = PROB_LIKELY(0.9), float cnt = COUNT_UNKNOWN);
   1.157 +  void end_loop();
   1.158 +  Node* make_label(int goto_ct);
   1.159 +  void bind(Node* lab);
   1.160 +  void goto_(Node* lab, bool bind = false);
   1.161 +  void declares_done();
   1.162 +  void drain_delay_transform();
   1.163 +
   1.164 +  Node* IfTrue(IfNode* iff)  { return transform(new (C,1) IfTrueNode(iff)); }
   1.165 +  Node* IfFalse(IfNode* iff) { return transform(new (C,1) IfFalseNode(iff)); }
   1.166 +
   1.167 +  // Data
   1.168 +  Node* ConI(jint k) { return (Node*)gvn().intcon(k); }
   1.169 +  Node* makecon(const Type *t)  const { return _gvn.makecon(t); }
   1.170 +
   1.171 +  Node* AddI(Node* l, Node* r) { return transform(new (C,3) AddINode(l, r)); }
   1.172 +  Node* SubI(Node* l, Node* r) { return transform(new (C,3) SubINode(l, r)); }
   1.173 +  Node* AndI(Node* l, Node* r) { return transform(new (C,3) AndINode(l, r)); }
   1.174 +  Node* MaxI(Node* l, Node* r) { return transform(new (C,3) MaxINode(l, r)); }
   1.175 +  Node* LShiftI(Node* l, Node* r) { return transform(new (C,3) LShiftINode(l, r)); }
   1.176 +  Node* CmpI(Node* l, Node* r) { return transform(new (C,3) CmpINode(l, r)); }
   1.177 +  Node* Bool(Node* cmp, BoolTest::mask relop) { return transform(new (C,2) BoolNode(cmp, relop)); }
   1.178 +  void  increment(IdealVariable& v, Node* j)  { set(v, AddI(value(v), j)); }
   1.179 +  void  decrement(IdealVariable& v, Node* j)  { set(v, SubI(value(v), j)); }
   1.180 +
   1.181 +  Node* CmpL(Node* l, Node* r) { return transform(new (C,3) CmpLNode(l, r)); }
   1.182 +
   1.183 +  // TLS
   1.184 +  Node* thread()  {  return gvn().transform(new (C, 1) ThreadLocalNode()); }
   1.185 +
   1.186 +  // Pointers
   1.187 +  Node* AddP(Node *base, Node *ptr, Node *off) { return transform(new (C,4) AddPNode(base, ptr, off)); }
   1.188 +  Node* CmpP(Node* l, Node* r) { return transform(new (C,3) CmpPNode(l, r)); }
   1.189 +#ifdef _LP64
   1.190 +  Node* XorX(Node* l, Node* r) { return transform(new (C,3) XorLNode(l, r)); }
   1.191 +#else // _LP64
   1.192 +  Node* XorX(Node* l, Node* r) { return transform(new (C,3) XorINode(l, r)); }
   1.193 +#endif // _LP64
   1.194 +  Node* URShiftX(Node* l, Node* r) { return transform(new (C,3) URShiftXNode(l, r)); }
   1.195 +  Node* ConX(jint k) { return (Node*)gvn().MakeConX(k); }
   1.196 +  Node* CastPX(Node* ctl, Node* p) { return transform(new (C,2) CastP2XNode(ctl, p)); }
   1.197 +  // Add a fixed offset to a pointer
   1.198 +  Node* basic_plus_adr(Node* base, Node* ptr, intptr_t offset);
   1.199 +
   1.200 +  // Memory operations
   1.201 +
   1.202 +  // This is the base version which is given an alias index.
   1.203 +  Node* load(Node* ctl,
   1.204 +             Node* adr,
   1.205 +             const Type* t,
   1.206 +             BasicType bt,
   1.207 +             int adr_idx,
   1.208 +             bool require_atomic_access = false);
   1.209 +
   1.210 +  // Return the new StoreXNode
   1.211 +  Node* store(Node* ctl,
   1.212 +              Node* adr,
   1.213 +              Node* val,
   1.214 +              BasicType bt,
   1.215 +              int adr_idx,
   1.216 +              bool require_atomic_access = false);
   1.217 +
   1.218 +  // Store a card mark ordered after store_oop
   1.219 +  Node* storeCM(Node* ctl,
   1.220 +                Node* adr,
   1.221 +                Node* val,
   1.222 +                Node* oop_store,
   1.223 +                BasicType bt,
   1.224 +                int adr_idx);
   1.225 +
   1.226 +  // Trivial call
   1.227 +  void make_leaf_call(const TypeFunc *slow_call_type,
   1.228 +                      address slow_call,
   1.229 +                      const char *leaf_name,
   1.230 +                      Node* parm0,
   1.231 +                      Node* parm1 = NULL,
   1.232 +                      Node* parm2 = NULL);
   1.233 +};

mercurial