Fri, 12 Feb 2010 15:27:36 -0800
Merge
duke@435 | 1 | /* |
xdono@1279 | 2 | * Copyright 2007-2009 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | */ |
duke@435 | 23 | |
duke@435 | 24 | // |
duke@435 | 25 | // S U P E R W O R D T R A N S F O R M |
duke@435 | 26 | // |
duke@435 | 27 | // SuperWords are short, fixed length vectors. |
duke@435 | 28 | // |
duke@435 | 29 | // Algorithm from: |
duke@435 | 30 | // |
duke@435 | 31 | // Exploiting SuperWord Level Parallelism with |
duke@435 | 32 | // Multimedia Instruction Sets |
duke@435 | 33 | // by |
duke@435 | 34 | // Samuel Larsen and Saman Amarasighe |
duke@435 | 35 | // MIT Laboratory for Computer Science |
duke@435 | 36 | // date |
duke@435 | 37 | // May 2000 |
duke@435 | 38 | // published in |
duke@435 | 39 | // ACM SIGPLAN Notices |
duke@435 | 40 | // Proceedings of ACM PLDI '00, Volume 35 Issue 5 |
duke@435 | 41 | // |
duke@435 | 42 | // Definition 3.1 A Pack is an n-tuple, <s1, ...,sn>, where |
duke@435 | 43 | // s1,...,sn are independent isomorphic statements in a basic |
duke@435 | 44 | // block. |
duke@435 | 45 | // |
duke@435 | 46 | // Definition 3.2 A PackSet is a set of Packs. |
duke@435 | 47 | // |
duke@435 | 48 | // Definition 3.3 A Pair is a Pack of size two, where the |
duke@435 | 49 | // first statement is considered the left element, and the |
duke@435 | 50 | // second statement is considered the right element. |
duke@435 | 51 | |
duke@435 | 52 | class SWPointer; |
duke@435 | 53 | class OrderedPair; |
duke@435 | 54 | |
duke@435 | 55 | // ========================= Dependence Graph ===================== |
duke@435 | 56 | |
duke@435 | 57 | class DepMem; |
duke@435 | 58 | |
duke@435 | 59 | //------------------------------DepEdge--------------------------- |
duke@435 | 60 | // An edge in the dependence graph. The edges incident to a dependence |
duke@435 | 61 | // node are threaded through _next_in for incoming edges and _next_out |
duke@435 | 62 | // for outgoing edges. |
duke@435 | 63 | class DepEdge : public ResourceObj { |
duke@435 | 64 | protected: |
duke@435 | 65 | DepMem* _pred; |
duke@435 | 66 | DepMem* _succ; |
duke@435 | 67 | DepEdge* _next_in; // list of in edges, null terminated |
duke@435 | 68 | DepEdge* _next_out; // list of out edges, null terminated |
duke@435 | 69 | |
duke@435 | 70 | public: |
duke@435 | 71 | DepEdge(DepMem* pred, DepMem* succ, DepEdge* next_in, DepEdge* next_out) : |
duke@435 | 72 | _pred(pred), _succ(succ), _next_in(next_in), _next_out(next_out) {} |
duke@435 | 73 | |
duke@435 | 74 | DepEdge* next_in() { return _next_in; } |
duke@435 | 75 | DepEdge* next_out() { return _next_out; } |
duke@435 | 76 | DepMem* pred() { return _pred; } |
duke@435 | 77 | DepMem* succ() { return _succ; } |
duke@435 | 78 | |
duke@435 | 79 | void print(); |
duke@435 | 80 | }; |
duke@435 | 81 | |
duke@435 | 82 | //------------------------------DepMem--------------------------- |
duke@435 | 83 | // A node in the dependence graph. _in_head starts the threaded list of |
duke@435 | 84 | // incoming edges, and _out_head starts the list of outgoing edges. |
duke@435 | 85 | class DepMem : public ResourceObj { |
duke@435 | 86 | protected: |
duke@435 | 87 | Node* _node; // Corresponding ideal node |
duke@435 | 88 | DepEdge* _in_head; // Head of list of in edges, null terminated |
duke@435 | 89 | DepEdge* _out_head; // Head of list of out edges, null terminated |
duke@435 | 90 | |
duke@435 | 91 | public: |
duke@435 | 92 | DepMem(Node* node) : _node(node), _in_head(NULL), _out_head(NULL) {} |
duke@435 | 93 | |
duke@435 | 94 | Node* node() { return _node; } |
duke@435 | 95 | DepEdge* in_head() { return _in_head; } |
duke@435 | 96 | DepEdge* out_head() { return _out_head; } |
duke@435 | 97 | void set_in_head(DepEdge* hd) { _in_head = hd; } |
duke@435 | 98 | void set_out_head(DepEdge* hd) { _out_head = hd; } |
duke@435 | 99 | |
duke@435 | 100 | int in_cnt(); // Incoming edge count |
duke@435 | 101 | int out_cnt(); // Outgoing edge count |
duke@435 | 102 | |
duke@435 | 103 | void print(); |
duke@435 | 104 | }; |
duke@435 | 105 | |
duke@435 | 106 | //------------------------------DepGraph--------------------------- |
duke@435 | 107 | class DepGraph VALUE_OBJ_CLASS_SPEC { |
duke@435 | 108 | protected: |
duke@435 | 109 | Arena* _arena; |
duke@435 | 110 | GrowableArray<DepMem*> _map; |
duke@435 | 111 | DepMem* _root; |
duke@435 | 112 | DepMem* _tail; |
duke@435 | 113 | |
duke@435 | 114 | public: |
duke@435 | 115 | DepGraph(Arena* a) : _arena(a), _map(a, 8, 0, NULL) { |
duke@435 | 116 | _root = new (_arena) DepMem(NULL); |
duke@435 | 117 | _tail = new (_arena) DepMem(NULL); |
duke@435 | 118 | } |
duke@435 | 119 | |
duke@435 | 120 | DepMem* root() { return _root; } |
duke@435 | 121 | DepMem* tail() { return _tail; } |
duke@435 | 122 | |
duke@435 | 123 | // Return dependence node corresponding to an ideal node |
duke@435 | 124 | DepMem* dep(Node* node) { return _map.at(node->_idx); } |
duke@435 | 125 | |
duke@435 | 126 | // Make a new dependence graph node for an ideal node. |
duke@435 | 127 | DepMem* make_node(Node* node); |
duke@435 | 128 | |
duke@435 | 129 | // Make a new dependence graph edge dprec->dsucc |
duke@435 | 130 | DepEdge* make_edge(DepMem* dpred, DepMem* dsucc); |
duke@435 | 131 | |
duke@435 | 132 | DepEdge* make_edge(Node* pred, Node* succ) { return make_edge(dep(pred), dep(succ)); } |
duke@435 | 133 | DepEdge* make_edge(DepMem* pred, Node* succ) { return make_edge(pred, dep(succ)); } |
duke@435 | 134 | DepEdge* make_edge(Node* pred, DepMem* succ) { return make_edge(dep(pred), succ); } |
duke@435 | 135 | |
duke@435 | 136 | void init() { _map.clear(); } // initialize |
duke@435 | 137 | |
duke@435 | 138 | void print(Node* n) { dep(n)->print(); } |
duke@435 | 139 | void print(DepMem* d) { d->print(); } |
duke@435 | 140 | }; |
duke@435 | 141 | |
duke@435 | 142 | //------------------------------DepPreds--------------------------- |
duke@435 | 143 | // Iterator over predecessors in the dependence graph and |
duke@435 | 144 | // non-memory-graph inputs of ideal nodes. |
duke@435 | 145 | class DepPreds : public StackObj { |
duke@435 | 146 | private: |
duke@435 | 147 | Node* _n; |
duke@435 | 148 | int _next_idx, _end_idx; |
duke@435 | 149 | DepEdge* _dep_next; |
duke@435 | 150 | Node* _current; |
duke@435 | 151 | bool _done; |
duke@435 | 152 | |
duke@435 | 153 | public: |
duke@435 | 154 | DepPreds(Node* n, DepGraph& dg); |
duke@435 | 155 | Node* current() { return _current; } |
duke@435 | 156 | bool done() { return _done; } |
duke@435 | 157 | void next(); |
duke@435 | 158 | }; |
duke@435 | 159 | |
duke@435 | 160 | //------------------------------DepSuccs--------------------------- |
duke@435 | 161 | // Iterator over successors in the dependence graph and |
duke@435 | 162 | // non-memory-graph outputs of ideal nodes. |
duke@435 | 163 | class DepSuccs : public StackObj { |
duke@435 | 164 | private: |
duke@435 | 165 | Node* _n; |
duke@435 | 166 | int _next_idx, _end_idx; |
duke@435 | 167 | DepEdge* _dep_next; |
duke@435 | 168 | Node* _current; |
duke@435 | 169 | bool _done; |
duke@435 | 170 | |
duke@435 | 171 | public: |
duke@435 | 172 | DepSuccs(Node* n, DepGraph& dg); |
duke@435 | 173 | Node* current() { return _current; } |
duke@435 | 174 | bool done() { return _done; } |
duke@435 | 175 | void next(); |
duke@435 | 176 | }; |
duke@435 | 177 | |
duke@435 | 178 | |
duke@435 | 179 | // ========================= SuperWord ===================== |
duke@435 | 180 | |
duke@435 | 181 | // -----------------------------SWNodeInfo--------------------------------- |
duke@435 | 182 | // Per node info needed by SuperWord |
duke@435 | 183 | class SWNodeInfo VALUE_OBJ_CLASS_SPEC { |
duke@435 | 184 | public: |
duke@435 | 185 | int _alignment; // memory alignment for a node |
duke@435 | 186 | int _depth; // Max expression (DAG) depth from block start |
duke@435 | 187 | const Type* _velt_type; // vector element type |
duke@435 | 188 | Node_List* _my_pack; // pack containing this node |
duke@435 | 189 | |
duke@435 | 190 | SWNodeInfo() : _alignment(-1), _depth(0), _velt_type(NULL), _my_pack(NULL) {} |
duke@435 | 191 | static const SWNodeInfo initial; |
duke@435 | 192 | }; |
duke@435 | 193 | |
duke@435 | 194 | // -----------------------------SuperWord--------------------------------- |
duke@435 | 195 | // Transforms scalar operations into packed (superword) operations. |
duke@435 | 196 | class SuperWord : public ResourceObj { |
duke@435 | 197 | private: |
duke@435 | 198 | PhaseIdealLoop* _phase; |
duke@435 | 199 | Arena* _arena; |
duke@435 | 200 | PhaseIterGVN &_igvn; |
duke@435 | 201 | |
duke@435 | 202 | enum consts { top_align = -1, bottom_align = -666 }; |
duke@435 | 203 | |
duke@435 | 204 | GrowableArray<Node_List*> _packset; // Packs for the current block |
duke@435 | 205 | |
duke@435 | 206 | GrowableArray<int> _bb_idx; // Map from Node _idx to index within block |
duke@435 | 207 | |
duke@435 | 208 | GrowableArray<Node*> _block; // Nodes in current block |
duke@435 | 209 | GrowableArray<Node*> _data_entry; // Nodes with all inputs from outside |
duke@435 | 210 | GrowableArray<Node*> _mem_slice_head; // Memory slice head nodes |
duke@435 | 211 | GrowableArray<Node*> _mem_slice_tail; // Memory slice tail nodes |
duke@435 | 212 | |
duke@435 | 213 | GrowableArray<SWNodeInfo> _node_info; // Info needed per node |
duke@435 | 214 | |
duke@435 | 215 | MemNode* _align_to_ref; // Memory reference that pre-loop will align to |
duke@435 | 216 | |
duke@435 | 217 | GrowableArray<OrderedPair> _disjoint_ptrs; // runtime disambiguated pointer pairs |
duke@435 | 218 | |
duke@435 | 219 | DepGraph _dg; // Dependence graph |
duke@435 | 220 | |
duke@435 | 221 | // Scratch pads |
duke@435 | 222 | VectorSet _visited; // Visited set |
duke@435 | 223 | VectorSet _post_visited; // Post-visited set |
duke@435 | 224 | Node_Stack _n_idx_list; // List of (node,index) pairs |
duke@435 | 225 | GrowableArray<Node*> _nlist; // List of nodes |
duke@435 | 226 | GrowableArray<Node*> _stk; // Stack of nodes |
duke@435 | 227 | |
duke@435 | 228 | public: |
duke@435 | 229 | SuperWord(PhaseIdealLoop* phase); |
duke@435 | 230 | |
duke@435 | 231 | void transform_loop(IdealLoopTree* lpt); |
duke@435 | 232 | |
duke@435 | 233 | // Accessors for SWPointer |
duke@435 | 234 | PhaseIdealLoop* phase() { return _phase; } |
duke@435 | 235 | IdealLoopTree* lpt() { return _lpt; } |
duke@435 | 236 | PhiNode* iv() { return _iv; } |
duke@435 | 237 | |
duke@435 | 238 | private: |
duke@435 | 239 | IdealLoopTree* _lpt; // Current loop tree node |
duke@435 | 240 | LoopNode* _lp; // Current LoopNode |
duke@435 | 241 | Node* _bb; // Current basic block |
duke@435 | 242 | PhiNode* _iv; // Induction var |
duke@435 | 243 | |
duke@435 | 244 | // Accessors |
duke@435 | 245 | Arena* arena() { return _arena; } |
duke@435 | 246 | |
duke@435 | 247 | Node* bb() { return _bb; } |
duke@435 | 248 | void set_bb(Node* bb) { _bb = bb; } |
duke@435 | 249 | |
duke@435 | 250 | void set_lpt(IdealLoopTree* lpt) { _lpt = lpt; } |
duke@435 | 251 | |
duke@435 | 252 | LoopNode* lp() { return _lp; } |
duke@435 | 253 | void set_lp(LoopNode* lp) { _lp = lp; |
duke@435 | 254 | _iv = lp->as_CountedLoop()->phi()->as_Phi(); } |
duke@435 | 255 | int iv_stride() { return lp()->as_CountedLoop()->stride_con(); } |
duke@435 | 256 | |
duke@435 | 257 | int vector_width_in_bytes() { return Matcher::vector_width_in_bytes(); } |
duke@435 | 258 | |
duke@435 | 259 | MemNode* align_to_ref() { return _align_to_ref; } |
duke@435 | 260 | void set_align_to_ref(MemNode* m) { _align_to_ref = m; } |
duke@435 | 261 | |
duke@435 | 262 | Node* ctrl(Node* n) const { return _phase->has_ctrl(n) ? _phase->get_ctrl(n) : n; } |
duke@435 | 263 | |
duke@435 | 264 | // block accessors |
duke@435 | 265 | bool in_bb(Node* n) { return n != NULL && n->outcnt() > 0 && ctrl(n) == _bb; } |
duke@435 | 266 | int bb_idx(Node* n) { assert(in_bb(n), "must be"); return _bb_idx.at(n->_idx); } |
duke@435 | 267 | void set_bb_idx(Node* n, int i) { _bb_idx.at_put_grow(n->_idx, i); } |
duke@435 | 268 | |
duke@435 | 269 | // visited set accessors |
duke@435 | 270 | void visited_clear() { _visited.Clear(); } |
duke@435 | 271 | void visited_set(Node* n) { return _visited.set(bb_idx(n)); } |
duke@435 | 272 | int visited_test(Node* n) { return _visited.test(bb_idx(n)); } |
duke@435 | 273 | int visited_test_set(Node* n) { return _visited.test_set(bb_idx(n)); } |
duke@435 | 274 | void post_visited_clear() { _post_visited.Clear(); } |
duke@435 | 275 | void post_visited_set(Node* n) { return _post_visited.set(bb_idx(n)); } |
duke@435 | 276 | int post_visited_test(Node* n) { return _post_visited.test(bb_idx(n)); } |
duke@435 | 277 | |
duke@435 | 278 | // Ensure node_info contains element "i" |
duke@435 | 279 | void grow_node_info(int i) { if (i >= _node_info.length()) _node_info.at_put_grow(i, SWNodeInfo::initial); } |
duke@435 | 280 | |
duke@435 | 281 | // memory alignment for a node |
duke@435 | 282 | int alignment(Node* n) { return _node_info.adr_at(bb_idx(n))->_alignment; } |
duke@435 | 283 | void set_alignment(Node* n, int a) { int i = bb_idx(n); grow_node_info(i); _node_info.adr_at(i)->_alignment = a; } |
duke@435 | 284 | |
duke@435 | 285 | // Max expression (DAG) depth from beginning of the block for each node |
duke@435 | 286 | int depth(Node* n) { return _node_info.adr_at(bb_idx(n))->_depth; } |
duke@435 | 287 | void set_depth(Node* n, int d) { int i = bb_idx(n); grow_node_info(i); _node_info.adr_at(i)->_depth = d; } |
duke@435 | 288 | |
duke@435 | 289 | // vector element type |
duke@435 | 290 | const Type* velt_type(Node* n) { return _node_info.adr_at(bb_idx(n))->_velt_type; } |
duke@435 | 291 | void set_velt_type(Node* n, const Type* t) { int i = bb_idx(n); grow_node_info(i); _node_info.adr_at(i)->_velt_type = t; } |
duke@435 | 292 | |
duke@435 | 293 | // my_pack |
duke@435 | 294 | Node_List* my_pack(Node* n) { return !in_bb(n) ? NULL : _node_info.adr_at(bb_idx(n))->_my_pack; } |
duke@435 | 295 | void set_my_pack(Node* n, Node_List* p) { int i = bb_idx(n); grow_node_info(i); _node_info.adr_at(i)->_my_pack = p; } |
duke@435 | 296 | |
duke@435 | 297 | // methods |
duke@435 | 298 | |
duke@435 | 299 | // Extract the superword level parallelism |
duke@435 | 300 | void SLP_extract(); |
duke@435 | 301 | // Find the adjacent memory references and create pack pairs for them. |
duke@435 | 302 | void find_adjacent_refs(); |
duke@435 | 303 | // Find a memory reference to align the loop induction variable to. |
duke@435 | 304 | void find_align_to_ref(Node_List &memops); |
duke@435 | 305 | // Can the preloop align the reference to position zero in the vector? |
duke@435 | 306 | bool ref_is_alignable(SWPointer& p); |
duke@435 | 307 | // Construct dependency graph. |
duke@435 | 308 | void dependence_graph(); |
duke@435 | 309 | // Return a memory slice (node list) in predecessor order starting at "start" |
duke@435 | 310 | void mem_slice_preds(Node* start, Node* stop, GrowableArray<Node*> &preds); |
twisti@1040 | 311 | // Can s1 and s2 be in a pack with s1 immediately preceding s2 and s1 aligned at "align" |
duke@435 | 312 | bool stmts_can_pack(Node* s1, Node* s2, int align); |
duke@435 | 313 | // Does s exist in a pack at position pos? |
duke@435 | 314 | bool exists_at(Node* s, uint pos); |
duke@435 | 315 | // Is s1 immediately before s2 in memory? |
duke@435 | 316 | bool are_adjacent_refs(Node* s1, Node* s2); |
duke@435 | 317 | // Are s1 and s2 similar? |
duke@435 | 318 | bool isomorphic(Node* s1, Node* s2); |
duke@435 | 319 | // Is there no data path from s1 to s2 or s2 to s1? |
duke@435 | 320 | bool independent(Node* s1, Node* s2); |
duke@435 | 321 | // Helper for independent |
duke@435 | 322 | bool independent_path(Node* shallow, Node* deep, uint dp=0); |
duke@435 | 323 | void set_alignment(Node* s1, Node* s2, int align); |
duke@435 | 324 | int data_size(Node* s); |
duke@435 | 325 | // Extend packset by following use->def and def->use links from pack members. |
duke@435 | 326 | void extend_packlist(); |
duke@435 | 327 | // Extend the packset by visiting operand definitions of nodes in pack p |
duke@435 | 328 | bool follow_use_defs(Node_List* p); |
duke@435 | 329 | // Extend the packset by visiting uses of nodes in pack p |
duke@435 | 330 | bool follow_def_uses(Node_List* p); |
duke@435 | 331 | // Estimate the savings from executing s1 and s2 as a pack |
duke@435 | 332 | int est_savings(Node* s1, Node* s2); |
duke@435 | 333 | int adjacent_profit(Node* s1, Node* s2); |
duke@435 | 334 | int pack_cost(int ct); |
duke@435 | 335 | int unpack_cost(int ct); |
duke@435 | 336 | // Combine packs A and B with A.last == B.first into A.first..,A.last,B.second,..B.last |
duke@435 | 337 | void combine_packs(); |
duke@435 | 338 | // Construct the map from nodes to packs. |
duke@435 | 339 | void construct_my_pack_map(); |
duke@435 | 340 | // Remove packs that are not implemented or not profitable. |
duke@435 | 341 | void filter_packs(); |
duke@435 | 342 | // Adjust the memory graph for the packed operations |
duke@435 | 343 | void schedule(); |
cfang@1102 | 344 | // Remove "current" from its current position in the memory graph and insert |
cfang@1102 | 345 | // it after the appropriate insert points (lip or uip); |
cfang@1102 | 346 | void remove_and_insert(MemNode *current, MemNode *prev, MemNode *lip, Node *uip, Unique_Node_List &schd_before); |
cfang@1102 | 347 | // Within a store pack, schedule stores together by moving out the sandwiched memory ops according |
cfang@1102 | 348 | // to dependence info; and within a load pack, move loads down to the last executed load. |
duke@435 | 349 | void co_locate_pack(Node_List* p); |
duke@435 | 350 | // Convert packs into vector node operations |
duke@435 | 351 | void output(); |
duke@435 | 352 | // Create a vector operand for the nodes in pack p for operand: in(opd_idx) |
duke@435 | 353 | VectorNode* vector_opd(Node_List* p, int opd_idx); |
duke@435 | 354 | // Can code be generated for pack p? |
duke@435 | 355 | bool implemented(Node_List* p); |
duke@435 | 356 | // For pack p, are all operands and all uses (with in the block) vector? |
duke@435 | 357 | bool profitable(Node_List* p); |
duke@435 | 358 | // If a use of pack p is not a vector use, then replace the use with an extract operation. |
duke@435 | 359 | void insert_extracts(Node_List* p); |
duke@435 | 360 | // Is use->in(u_idx) a vector use? |
duke@435 | 361 | bool is_vector_use(Node* use, int u_idx); |
duke@435 | 362 | // Construct reverse postorder list of block members |
duke@435 | 363 | void construct_bb(); |
duke@435 | 364 | // Initialize per node info |
duke@435 | 365 | void initialize_bb(); |
duke@435 | 366 | // Insert n into block after pos |
duke@435 | 367 | void bb_insert_after(Node* n, int pos); |
duke@435 | 368 | // Compute max depth for expressions from beginning of block |
duke@435 | 369 | void compute_max_depth(); |
duke@435 | 370 | // Compute necessary vector element type for expressions |
duke@435 | 371 | void compute_vector_element_type(); |
duke@435 | 372 | // Are s1 and s2 in a pack pair and ordered as s1,s2? |
duke@435 | 373 | bool in_packset(Node* s1, Node* s2); |
duke@435 | 374 | // Is s in pack p? |
duke@435 | 375 | Node_List* in_pack(Node* s, Node_List* p); |
duke@435 | 376 | // Remove the pack at position pos in the packset |
duke@435 | 377 | void remove_pack_at(int pos); |
duke@435 | 378 | // Return the node executed first in pack p. |
duke@435 | 379 | Node* executed_first(Node_List* p); |
duke@435 | 380 | // Return the node executed last in pack p. |
duke@435 | 381 | Node* executed_last(Node_List* p); |
duke@435 | 382 | // Alignment within a vector memory reference |
duke@435 | 383 | int memory_alignment(MemNode* s, int iv_adjust_in_bytes); |
duke@435 | 384 | // (Start, end] half-open range defining which operands are vector |
duke@435 | 385 | void vector_opd_range(Node* n, uint* start, uint* end); |
duke@435 | 386 | // Smallest type containing range of values |
duke@435 | 387 | static const Type* container_type(const Type* t); |
duke@435 | 388 | // Adjust pre-loop limit so that in main loop, a load/store reference |
duke@435 | 389 | // to align_to_ref will be a position zero in the vector. |
duke@435 | 390 | void align_initial_loop_index(MemNode* align_to_ref); |
duke@435 | 391 | // Find pre loop end from main loop. Returns null if none. |
duke@435 | 392 | CountedLoopEndNode* get_pre_loop_end(CountedLoopNode *cl); |
duke@435 | 393 | // Is the use of d1 in u1 at the same operand position as d2 in u2? |
duke@435 | 394 | bool opnd_positions_match(Node* d1, Node* u1, Node* d2, Node* u2); |
duke@435 | 395 | void init(); |
duke@435 | 396 | |
duke@435 | 397 | // print methods |
duke@435 | 398 | void print_packset(); |
duke@435 | 399 | void print_pack(Node_List* p); |
duke@435 | 400 | void print_bb(); |
duke@435 | 401 | void print_stmt(Node* s); |
duke@435 | 402 | char* blank(uint depth); |
duke@435 | 403 | }; |
duke@435 | 404 | |
duke@435 | 405 | |
duke@435 | 406 | //------------------------------SWPointer--------------------------- |
duke@435 | 407 | // Information about an address for dependence checking and vector alignment |
duke@435 | 408 | class SWPointer VALUE_OBJ_CLASS_SPEC { |
duke@435 | 409 | protected: |
duke@435 | 410 | MemNode* _mem; // My memory reference node |
duke@435 | 411 | SuperWord* _slp; // SuperWord class |
duke@435 | 412 | |
duke@435 | 413 | Node* _base; // NULL if unsafe nonheap reference |
duke@435 | 414 | Node* _adr; // address pointer |
duke@435 | 415 | jint _scale; // multipler for iv (in bytes), 0 if no loop iv |
duke@435 | 416 | jint _offset; // constant offset (in bytes) |
duke@435 | 417 | Node* _invar; // invariant offset (in bytes), NULL if none |
duke@435 | 418 | bool _negate_invar; // if true then use: (0 - _invar) |
duke@435 | 419 | |
duke@435 | 420 | PhaseIdealLoop* phase() { return _slp->phase(); } |
duke@435 | 421 | IdealLoopTree* lpt() { return _slp->lpt(); } |
duke@435 | 422 | PhiNode* iv() { return _slp->iv(); } // Induction var |
duke@435 | 423 | |
duke@435 | 424 | bool invariant(Node* n) { |
duke@435 | 425 | Node *n_c = phase()->get_ctrl(n); |
duke@435 | 426 | return !lpt()->is_member(phase()->get_loop(n_c)); |
duke@435 | 427 | } |
duke@435 | 428 | |
duke@435 | 429 | // Match: k*iv + offset |
duke@435 | 430 | bool scaled_iv_plus_offset(Node* n); |
duke@435 | 431 | // Match: k*iv where k is a constant that's not zero |
duke@435 | 432 | bool scaled_iv(Node* n); |
duke@435 | 433 | // Match: offset is (k [+/- invariant]) |
duke@435 | 434 | bool offset_plus_k(Node* n, bool negate = false); |
duke@435 | 435 | |
duke@435 | 436 | public: |
duke@435 | 437 | enum CMP { |
duke@435 | 438 | Less = 1, |
duke@435 | 439 | Greater = 2, |
duke@435 | 440 | Equal = 4, |
duke@435 | 441 | NotEqual = (Less | Greater), |
duke@435 | 442 | NotComparable = (Less | Greater | Equal) |
duke@435 | 443 | }; |
duke@435 | 444 | |
duke@435 | 445 | SWPointer(MemNode* mem, SuperWord* slp); |
duke@435 | 446 | // Following is used to create a temporary object during |
duke@435 | 447 | // the pattern match of an address expression. |
duke@435 | 448 | SWPointer(SWPointer* p); |
duke@435 | 449 | |
duke@435 | 450 | bool valid() { return _adr != NULL; } |
duke@435 | 451 | bool has_iv() { return _scale != 0; } |
duke@435 | 452 | |
duke@435 | 453 | Node* base() { return _base; } |
duke@435 | 454 | Node* adr() { return _adr; } |
duke@435 | 455 | int scale_in_bytes() { return _scale; } |
duke@435 | 456 | Node* invar() { return _invar; } |
duke@435 | 457 | bool negate_invar() { return _negate_invar; } |
duke@435 | 458 | int offset_in_bytes() { return _offset; } |
duke@435 | 459 | int memory_size() { return _mem->memory_size(); } |
duke@435 | 460 | |
duke@435 | 461 | // Comparable? |
duke@435 | 462 | int cmp(SWPointer& q) { |
duke@435 | 463 | if (valid() && q.valid() && |
duke@435 | 464 | (_adr == q._adr || _base == _adr && q._base == q._adr) && |
duke@435 | 465 | _scale == q._scale && |
duke@435 | 466 | _invar == q._invar && |
duke@435 | 467 | _negate_invar == q._negate_invar) { |
duke@435 | 468 | bool overlap = q._offset < _offset + memory_size() && |
duke@435 | 469 | _offset < q._offset + q.memory_size(); |
duke@435 | 470 | return overlap ? Equal : (_offset < q._offset ? Less : Greater); |
duke@435 | 471 | } else { |
duke@435 | 472 | return NotComparable; |
duke@435 | 473 | } |
duke@435 | 474 | } |
duke@435 | 475 | |
duke@435 | 476 | bool not_equal(SWPointer& q) { return not_equal(cmp(q)); } |
duke@435 | 477 | bool equal(SWPointer& q) { return equal(cmp(q)); } |
duke@435 | 478 | bool comparable(SWPointer& q) { return comparable(cmp(q)); } |
duke@435 | 479 | static bool not_equal(int cmp) { return cmp <= NotEqual; } |
duke@435 | 480 | static bool equal(int cmp) { return cmp == Equal; } |
duke@435 | 481 | static bool comparable(int cmp) { return cmp < NotComparable; } |
duke@435 | 482 | |
duke@435 | 483 | void print(); |
duke@435 | 484 | }; |
duke@435 | 485 | |
duke@435 | 486 | |
duke@435 | 487 | //------------------------------OrderedPair--------------------------- |
duke@435 | 488 | // Ordered pair of Node*. |
duke@435 | 489 | class OrderedPair VALUE_OBJ_CLASS_SPEC { |
duke@435 | 490 | protected: |
duke@435 | 491 | Node* _p1; |
duke@435 | 492 | Node* _p2; |
duke@435 | 493 | public: |
duke@435 | 494 | OrderedPair() : _p1(NULL), _p2(NULL) {} |
duke@435 | 495 | OrderedPair(Node* p1, Node* p2) { |
duke@435 | 496 | if (p1->_idx < p2->_idx) { |
duke@435 | 497 | _p1 = p1; _p2 = p2; |
duke@435 | 498 | } else { |
duke@435 | 499 | _p1 = p2; _p2 = p1; |
duke@435 | 500 | } |
duke@435 | 501 | } |
duke@435 | 502 | |
duke@435 | 503 | bool operator==(const OrderedPair &rhs) { |
duke@435 | 504 | return _p1 == rhs._p1 && _p2 == rhs._p2; |
duke@435 | 505 | } |
duke@435 | 506 | void print() { tty->print(" (%d, %d)", _p1->_idx, _p2->_idx); } |
duke@435 | 507 | |
duke@435 | 508 | static const OrderedPair initial; |
duke@435 | 509 | }; |