src/share/vm/opto/superword.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 8604
04d83ba48607
child 9756
2be326848943
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 #include "precompiled.hpp"
aoqi@0 25 #include "compiler/compileLog.hpp"
aoqi@0 26 #include "libadt/vectset.hpp"
aoqi@0 27 #include "memory/allocation.inline.hpp"
aoqi@0 28 #include "opto/addnode.hpp"
aoqi@0 29 #include "opto/callnode.hpp"
aoqi@0 30 #include "opto/divnode.hpp"
aoqi@0 31 #include "opto/matcher.hpp"
aoqi@0 32 #include "opto/memnode.hpp"
aoqi@0 33 #include "opto/mulnode.hpp"
aoqi@0 34 #include "opto/opcodes.hpp"
aoqi@0 35 #include "opto/superword.hpp"
aoqi@0 36 #include "opto/vectornode.hpp"
aoqi@0 37
aoqi@0 38 //
aoqi@0 39 // S U P E R W O R D T R A N S F O R M
aoqi@0 40 //=============================================================================
aoqi@0 41
aoqi@0 42 //------------------------------SuperWord---------------------------
aoqi@0 43 SuperWord::SuperWord(PhaseIdealLoop* phase) :
aoqi@0 44 _phase(phase),
aoqi@0 45 _igvn(phase->_igvn),
aoqi@0 46 _arena(phase->C->comp_arena()),
aoqi@0 47 _packset(arena(), 8, 0, NULL), // packs for the current block
aoqi@0 48 _bb_idx(arena(), (int)(1.10 * phase->C->unique()), 0, 0), // node idx to index in bb
aoqi@0 49 _block(arena(), 8, 0, NULL), // nodes in current block
aoqi@0 50 _data_entry(arena(), 8, 0, NULL), // nodes with all inputs from outside
aoqi@0 51 _mem_slice_head(arena(), 8, 0, NULL), // memory slice heads
aoqi@0 52 _mem_slice_tail(arena(), 8, 0, NULL), // memory slice tails
aoqi@0 53 _node_info(arena(), 8, 0, SWNodeInfo::initial), // info needed per node
aoqi@0 54 _align_to_ref(NULL), // memory reference to align vectors to
aoqi@0 55 _disjoint_ptrs(arena(), 8, 0, OrderedPair::initial), // runtime disambiguated pointer pairs
aoqi@0 56 _dg(_arena), // dependence graph
aoqi@0 57 _visited(arena()), // visited node set
aoqi@0 58 _post_visited(arena()), // post visited node set
aoqi@0 59 _n_idx_list(arena(), 8), // scratch list of (node,index) pairs
aoqi@0 60 _stk(arena(), 8, 0, NULL), // scratch stack of nodes
aoqi@0 61 _nlist(arena(), 8, 0, NULL), // scratch list of nodes
aoqi@0 62 _lpt(NULL), // loop tree node
aoqi@0 63 _lp(NULL), // LoopNode
aoqi@0 64 _bb(NULL), // basic block
aoqi@0 65 _iv(NULL) // induction var
aoqi@0 66 {}
aoqi@0 67
aoqi@0 68 //------------------------------transform_loop---------------------------
aoqi@0 69 void SuperWord::transform_loop(IdealLoopTree* lpt) {
aoqi@0 70 assert(UseSuperWord, "should be");
aoqi@0 71 // Do vectors exist on this architecture?
aoqi@0 72 if (Matcher::vector_width_in_bytes(T_BYTE) < 2) return;
aoqi@0 73
aoqi@0 74 assert(lpt->_head->is_CountedLoop(), "must be");
aoqi@0 75 CountedLoopNode *cl = lpt->_head->as_CountedLoop();
aoqi@0 76
aoqi@0 77 if (!cl->is_valid_counted_loop()) return; // skip malformed counted loop
aoqi@0 78
aoqi@0 79 if (!cl->is_main_loop() ) return; // skip normal, pre, and post loops
aoqi@0 80
aoqi@0 81 // Check for no control flow in body (other than exit)
aoqi@0 82 Node *cl_exit = cl->loopexit();
aoqi@0 83 if (cl_exit->in(0) != lpt->_head) return;
aoqi@0 84
aoqi@0 85 // Make sure the are no extra control users of the loop backedge
aoqi@0 86 if (cl->back_control()->outcnt() != 1) {
aoqi@0 87 return;
aoqi@0 88 }
aoqi@0 89
aoqi@0 90 // Check for pre-loop ending with CountedLoopEnd(Bool(Cmp(x,Opaque1(limit))))
aoqi@0 91 CountedLoopEndNode* pre_end = get_pre_loop_end(cl);
aoqi@0 92 if (pre_end == NULL) return;
aoqi@0 93 Node *pre_opaq1 = pre_end->limit();
aoqi@0 94 if (pre_opaq1->Opcode() != Op_Opaque1) return;
aoqi@0 95
aoqi@0 96 init(); // initialize data structures
aoqi@0 97
aoqi@0 98 set_lpt(lpt);
aoqi@0 99 set_lp(cl);
aoqi@0 100
aoqi@0 101 // For now, define one block which is the entire loop body
aoqi@0 102 set_bb(cl);
aoqi@0 103
aoqi@0 104 assert(_packset.length() == 0, "packset must be empty");
aoqi@0 105 SLP_extract();
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 //------------------------------SLP_extract---------------------------
aoqi@0 109 // Extract the superword level parallelism
aoqi@0 110 //
aoqi@0 111 // 1) A reverse post-order of nodes in the block is constructed. By scanning
aoqi@0 112 // this list from first to last, all definitions are visited before their uses.
aoqi@0 113 //
aoqi@0 114 // 2) A point-to-point dependence graph is constructed between memory references.
aoqi@0 115 // This simplies the upcoming "independence" checker.
aoqi@0 116 //
aoqi@0 117 // 3) The maximum depth in the node graph from the beginning of the block
aoqi@0 118 // to each node is computed. This is used to prune the graph search
aoqi@0 119 // in the independence checker.
aoqi@0 120 //
aoqi@0 121 // 4) For integer types, the necessary bit width is propagated backwards
aoqi@0 122 // from stores to allow packed operations on byte, char, and short
aoqi@0 123 // integers. This reverses the promotion to type "int" that javac
aoqi@0 124 // did for operations like: char c1,c2,c3; c1 = c2 + c3.
aoqi@0 125 //
aoqi@0 126 // 5) One of the memory references is picked to be an aligned vector reference.
aoqi@0 127 // The pre-loop trip count is adjusted to align this reference in the
aoqi@0 128 // unrolled body.
aoqi@0 129 //
aoqi@0 130 // 6) The initial set of pack pairs is seeded with memory references.
aoqi@0 131 //
aoqi@0 132 // 7) The set of pack pairs is extended by following use->def and def->use links.
aoqi@0 133 //
aoqi@0 134 // 8) The pairs are combined into vector sized packs.
aoqi@0 135 //
aoqi@0 136 // 9) Reorder the memory slices to co-locate members of the memory packs.
aoqi@0 137 //
aoqi@0 138 // 10) Generate ideal vector nodes for the final set of packs and where necessary,
aoqi@0 139 // inserting scalar promotion, vector creation from multiple scalars, and
aoqi@0 140 // extraction of scalar values from vectors.
aoqi@0 141 //
aoqi@0 142 void SuperWord::SLP_extract() {
aoqi@0 143
aoqi@0 144 // Ready the block
aoqi@0 145
aoqi@0 146 if (!construct_bb())
aoqi@0 147 return; // Exit if no interesting nodes or complex graph.
aoqi@0 148
aoqi@0 149 dependence_graph();
aoqi@0 150
aoqi@0 151 compute_max_depth();
aoqi@0 152
aoqi@0 153 compute_vector_element_type();
aoqi@0 154
aoqi@0 155 // Attempt vectorization
aoqi@0 156
aoqi@0 157 find_adjacent_refs();
aoqi@0 158
aoqi@0 159 extend_packlist();
aoqi@0 160
aoqi@0 161 combine_packs();
aoqi@0 162
aoqi@0 163 construct_my_pack_map();
aoqi@0 164
aoqi@0 165 filter_packs();
aoqi@0 166
aoqi@0 167 schedule();
aoqi@0 168
aoqi@0 169 output();
aoqi@0 170 }
aoqi@0 171
aoqi@0 172 //------------------------------find_adjacent_refs---------------------------
aoqi@0 173 // Find the adjacent memory references and create pack pairs for them.
aoqi@0 174 // This is the initial set of packs that will then be extended by
aoqi@0 175 // following use->def and def->use links. The align positions are
aoqi@0 176 // assigned relative to the reference "align_to_ref"
aoqi@0 177 void SuperWord::find_adjacent_refs() {
aoqi@0 178 // Get list of memory operations
aoqi@0 179 Node_List memops;
aoqi@0 180 for (int i = 0; i < _block.length(); i++) {
aoqi@0 181 Node* n = _block.at(i);
aoqi@0 182 if (n->is_Mem() && !n->is_LoadStore() && in_bb(n) &&
aoqi@0 183 is_java_primitive(n->as_Mem()->memory_type())) {
aoqi@0 184 int align = memory_alignment(n->as_Mem(), 0);
aoqi@0 185 if (align != bottom_align) {
aoqi@0 186 memops.push(n);
aoqi@0 187 }
aoqi@0 188 }
aoqi@0 189 }
aoqi@0 190
aoqi@0 191 Node_List align_to_refs;
aoqi@0 192 int best_iv_adjustment = 0;
aoqi@0 193 MemNode* best_align_to_mem_ref = NULL;
aoqi@0 194
aoqi@0 195 while (memops.size() != 0) {
aoqi@0 196 // Find a memory reference to align to.
aoqi@0 197 MemNode* mem_ref = find_align_to_ref(memops);
aoqi@0 198 if (mem_ref == NULL) break;
aoqi@0 199 align_to_refs.push(mem_ref);
aoqi@0 200 int iv_adjustment = get_iv_adjustment(mem_ref);
aoqi@0 201
aoqi@0 202 if (best_align_to_mem_ref == NULL) {
aoqi@0 203 // Set memory reference which is the best from all memory operations
aoqi@0 204 // to be used for alignment. The pre-loop trip count is modified to align
aoqi@0 205 // this reference to a vector-aligned address.
aoqi@0 206 best_align_to_mem_ref = mem_ref;
aoqi@0 207 best_iv_adjustment = iv_adjustment;
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 SWPointer align_to_ref_p(mem_ref, this);
aoqi@0 211 // Set alignment relative to "align_to_ref" for all related memory operations.
aoqi@0 212 for (int i = memops.size() - 1; i >= 0; i--) {
aoqi@0 213 MemNode* s = memops.at(i)->as_Mem();
aoqi@0 214 if (isomorphic(s, mem_ref)) {
aoqi@0 215 SWPointer p2(s, this);
aoqi@0 216 if (p2.comparable(align_to_ref_p)) {
aoqi@0 217 int align = memory_alignment(s, iv_adjustment);
aoqi@0 218 set_alignment(s, align);
aoqi@0 219 }
aoqi@0 220 }
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 // Create initial pack pairs of memory operations for which
aoqi@0 224 // alignment is set and vectors will be aligned.
aoqi@0 225 bool create_pack = true;
aoqi@0 226 if (memory_alignment(mem_ref, best_iv_adjustment) == 0) {
aoqi@0 227 if (!Matcher::misaligned_vectors_ok()) {
aoqi@0 228 int vw = vector_width(mem_ref);
aoqi@0 229 int vw_best = vector_width(best_align_to_mem_ref);
aoqi@0 230 if (vw > vw_best) {
aoqi@0 231 // Do not vectorize a memory access with more elements per vector
aoqi@0 232 // if unaligned memory access is not allowed because number of
aoqi@0 233 // iterations in pre-loop will be not enough to align it.
aoqi@0 234 create_pack = false;
thartmann@7819 235 } else {
thartmann@7819 236 SWPointer p2(best_align_to_mem_ref, this);
thartmann@7819 237 if (align_to_ref_p.invar() != p2.invar()) {
thartmann@7819 238 // Do not vectorize memory accesses with different invariants
thartmann@7819 239 // if unaligned memory accesses are not allowed.
thartmann@7819 240 create_pack = false;
thartmann@7819 241 }
aoqi@0 242 }
aoqi@0 243 }
aoqi@0 244 } else {
aoqi@0 245 if (same_velt_type(mem_ref, best_align_to_mem_ref)) {
aoqi@0 246 // Can't allow vectorization of unaligned memory accesses with the
aoqi@0 247 // same type since it could be overlapped accesses to the same array.
aoqi@0 248 create_pack = false;
aoqi@0 249 } else {
aoqi@0 250 // Allow independent (different type) unaligned memory operations
aoqi@0 251 // if HW supports them.
aoqi@0 252 if (!Matcher::misaligned_vectors_ok()) {
aoqi@0 253 create_pack = false;
aoqi@0 254 } else {
aoqi@0 255 // Check if packs of the same memory type but
aoqi@0 256 // with a different alignment were created before.
aoqi@0 257 for (uint i = 0; i < align_to_refs.size(); i++) {
aoqi@0 258 MemNode* mr = align_to_refs.at(i)->as_Mem();
aoqi@0 259 if (same_velt_type(mr, mem_ref) &&
aoqi@0 260 memory_alignment(mr, iv_adjustment) != 0)
aoqi@0 261 create_pack = false;
aoqi@0 262 }
aoqi@0 263 }
aoqi@0 264 }
aoqi@0 265 }
aoqi@0 266 if (create_pack) {
aoqi@0 267 for (uint i = 0; i < memops.size(); i++) {
aoqi@0 268 Node* s1 = memops.at(i);
aoqi@0 269 int align = alignment(s1);
aoqi@0 270 if (align == top_align) continue;
aoqi@0 271 for (uint j = 0; j < memops.size(); j++) {
aoqi@0 272 Node* s2 = memops.at(j);
aoqi@0 273 if (alignment(s2) == top_align) continue;
aoqi@0 274 if (s1 != s2 && are_adjacent_refs(s1, s2)) {
aoqi@0 275 if (stmts_can_pack(s1, s2, align)) {
aoqi@0 276 Node_List* pair = new Node_List();
aoqi@0 277 pair->push(s1);
aoqi@0 278 pair->push(s2);
aoqi@0 279 _packset.append(pair);
aoqi@0 280 }
aoqi@0 281 }
aoqi@0 282 }
aoqi@0 283 }
aoqi@0 284 } else { // Don't create unaligned pack
aoqi@0 285 // First, remove remaining memory ops of the same type from the list.
aoqi@0 286 for (int i = memops.size() - 1; i >= 0; i--) {
aoqi@0 287 MemNode* s = memops.at(i)->as_Mem();
aoqi@0 288 if (same_velt_type(s, mem_ref)) {
aoqi@0 289 memops.remove(i);
aoqi@0 290 }
aoqi@0 291 }
aoqi@0 292
aoqi@0 293 // Second, remove already constructed packs of the same type.
aoqi@0 294 for (int i = _packset.length() - 1; i >= 0; i--) {
aoqi@0 295 Node_List* p = _packset.at(i);
aoqi@0 296 MemNode* s = p->at(0)->as_Mem();
aoqi@0 297 if (same_velt_type(s, mem_ref)) {
aoqi@0 298 remove_pack_at(i);
aoqi@0 299 }
aoqi@0 300 }
aoqi@0 301
aoqi@0 302 // If needed find the best memory reference for loop alignment again.
aoqi@0 303 if (same_velt_type(mem_ref, best_align_to_mem_ref)) {
aoqi@0 304 // Put memory ops from remaining packs back on memops list for
aoqi@0 305 // the best alignment search.
aoqi@0 306 uint orig_msize = memops.size();
aoqi@0 307 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 308 Node_List* p = _packset.at(i);
aoqi@0 309 MemNode* s = p->at(0)->as_Mem();
aoqi@0 310 assert(!same_velt_type(s, mem_ref), "sanity");
aoqi@0 311 memops.push(s);
aoqi@0 312 }
aoqi@0 313 MemNode* best_align_to_mem_ref = find_align_to_ref(memops);
aoqi@0 314 if (best_align_to_mem_ref == NULL) break;
aoqi@0 315 best_iv_adjustment = get_iv_adjustment(best_align_to_mem_ref);
aoqi@0 316 // Restore list.
aoqi@0 317 while (memops.size() > orig_msize)
aoqi@0 318 (void)memops.pop();
aoqi@0 319 }
aoqi@0 320 } // unaligned memory accesses
aoqi@0 321
aoqi@0 322 // Remove used mem nodes.
aoqi@0 323 for (int i = memops.size() - 1; i >= 0; i--) {
aoqi@0 324 MemNode* m = memops.at(i)->as_Mem();
aoqi@0 325 if (alignment(m) != top_align) {
aoqi@0 326 memops.remove(i);
aoqi@0 327 }
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 } // while (memops.size() != 0
aoqi@0 331 set_align_to_ref(best_align_to_mem_ref);
aoqi@0 332
aoqi@0 333 #ifndef PRODUCT
aoqi@0 334 if (TraceSuperWord) {
aoqi@0 335 tty->print_cr("\nAfter find_adjacent_refs");
aoqi@0 336 print_packset();
aoqi@0 337 }
aoqi@0 338 #endif
aoqi@0 339 }
aoqi@0 340
aoqi@0 341 //------------------------------find_align_to_ref---------------------------
aoqi@0 342 // Find a memory reference to align the loop induction variable to.
aoqi@0 343 // Looks first at stores then at loads, looking for a memory reference
aoqi@0 344 // with the largest number of references similar to it.
aoqi@0 345 MemNode* SuperWord::find_align_to_ref(Node_List &memops) {
aoqi@0 346 GrowableArray<int> cmp_ct(arena(), memops.size(), memops.size(), 0);
aoqi@0 347
aoqi@0 348 // Count number of comparable memory ops
aoqi@0 349 for (uint i = 0; i < memops.size(); i++) {
aoqi@0 350 MemNode* s1 = memops.at(i)->as_Mem();
aoqi@0 351 SWPointer p1(s1, this);
aoqi@0 352 // Discard if pre loop can't align this reference
aoqi@0 353 if (!ref_is_alignable(p1)) {
aoqi@0 354 *cmp_ct.adr_at(i) = 0;
aoqi@0 355 continue;
aoqi@0 356 }
aoqi@0 357 for (uint j = i+1; j < memops.size(); j++) {
aoqi@0 358 MemNode* s2 = memops.at(j)->as_Mem();
aoqi@0 359 if (isomorphic(s1, s2)) {
aoqi@0 360 SWPointer p2(s2, this);
aoqi@0 361 if (p1.comparable(p2)) {
aoqi@0 362 (*cmp_ct.adr_at(i))++;
aoqi@0 363 (*cmp_ct.adr_at(j))++;
aoqi@0 364 }
aoqi@0 365 }
aoqi@0 366 }
aoqi@0 367 }
aoqi@0 368
aoqi@0 369 // Find Store (or Load) with the greatest number of "comparable" references,
aoqi@0 370 // biggest vector size, smallest data size and smallest iv offset.
aoqi@0 371 int max_ct = 0;
aoqi@0 372 int max_vw = 0;
aoqi@0 373 int max_idx = -1;
aoqi@0 374 int min_size = max_jint;
aoqi@0 375 int min_iv_offset = max_jint;
aoqi@0 376 for (uint j = 0; j < memops.size(); j++) {
aoqi@0 377 MemNode* s = memops.at(j)->as_Mem();
aoqi@0 378 if (s->is_Store()) {
aoqi@0 379 int vw = vector_width_in_bytes(s);
aoqi@0 380 assert(vw > 1, "sanity");
aoqi@0 381 SWPointer p(s, this);
aoqi@0 382 if (cmp_ct.at(j) > max_ct ||
aoqi@0 383 cmp_ct.at(j) == max_ct &&
aoqi@0 384 (vw > max_vw ||
aoqi@0 385 vw == max_vw &&
aoqi@0 386 (data_size(s) < min_size ||
aoqi@0 387 data_size(s) == min_size &&
aoqi@0 388 (p.offset_in_bytes() < min_iv_offset)))) {
aoqi@0 389 max_ct = cmp_ct.at(j);
aoqi@0 390 max_vw = vw;
aoqi@0 391 max_idx = j;
aoqi@0 392 min_size = data_size(s);
aoqi@0 393 min_iv_offset = p.offset_in_bytes();
aoqi@0 394 }
aoqi@0 395 }
aoqi@0 396 }
aoqi@0 397 // If no stores, look at loads
aoqi@0 398 if (max_ct == 0) {
aoqi@0 399 for (uint j = 0; j < memops.size(); j++) {
aoqi@0 400 MemNode* s = memops.at(j)->as_Mem();
aoqi@0 401 if (s->is_Load()) {
aoqi@0 402 int vw = vector_width_in_bytes(s);
aoqi@0 403 assert(vw > 1, "sanity");
aoqi@0 404 SWPointer p(s, this);
aoqi@0 405 if (cmp_ct.at(j) > max_ct ||
aoqi@0 406 cmp_ct.at(j) == max_ct &&
aoqi@0 407 (vw > max_vw ||
aoqi@0 408 vw == max_vw &&
aoqi@0 409 (data_size(s) < min_size ||
aoqi@0 410 data_size(s) == min_size &&
aoqi@0 411 (p.offset_in_bytes() < min_iv_offset)))) {
aoqi@0 412 max_ct = cmp_ct.at(j);
aoqi@0 413 max_vw = vw;
aoqi@0 414 max_idx = j;
aoqi@0 415 min_size = data_size(s);
aoqi@0 416 min_iv_offset = p.offset_in_bytes();
aoqi@0 417 }
aoqi@0 418 }
aoqi@0 419 }
aoqi@0 420 }
aoqi@0 421
aoqi@0 422 #ifdef ASSERT
aoqi@0 423 if (TraceSuperWord && Verbose) {
aoqi@0 424 tty->print_cr("\nVector memops after find_align_to_refs");
aoqi@0 425 for (uint i = 0; i < memops.size(); i++) {
aoqi@0 426 MemNode* s = memops.at(i)->as_Mem();
aoqi@0 427 s->dump();
aoqi@0 428 }
aoqi@0 429 }
aoqi@0 430 #endif
aoqi@0 431
aoqi@0 432 if (max_ct > 0) {
aoqi@0 433 #ifdef ASSERT
aoqi@0 434 if (TraceSuperWord) {
aoqi@0 435 tty->print("\nVector align to node: ");
aoqi@0 436 memops.at(max_idx)->as_Mem()->dump();
aoqi@0 437 }
aoqi@0 438 #endif
aoqi@0 439 return memops.at(max_idx)->as_Mem();
aoqi@0 440 }
aoqi@0 441 return NULL;
aoqi@0 442 }
aoqi@0 443
aoqi@0 444 //------------------------------ref_is_alignable---------------------------
aoqi@0 445 // Can the preloop align the reference to position zero in the vector?
aoqi@0 446 bool SuperWord::ref_is_alignable(SWPointer& p) {
aoqi@0 447 if (!p.has_iv()) {
aoqi@0 448 return true; // no induction variable
aoqi@0 449 }
aoqi@0 450 CountedLoopEndNode* pre_end = get_pre_loop_end(lp()->as_CountedLoop());
aoqi@0 451 assert(pre_end->stride_is_con(), "pre loop stride is constant");
aoqi@0 452 int preloop_stride = pre_end->stride_con();
aoqi@0 453
aoqi@0 454 int span = preloop_stride * p.scale_in_bytes();
kvn@7817 455 int mem_size = p.memory_size();
kvn@7817 456 int offset = p.offset_in_bytes();
kvn@7817 457 // Stride one accesses are alignable if offset is aligned to memory operation size.
kvn@7817 458 // Offset can be unaligned when UseUnalignedAccesses is used.
kvn@7817 459 if (ABS(span) == mem_size && (ABS(offset) % mem_size) == 0) {
aoqi@0 460 return true;
kvn@7817 461 }
thartmann@7819 462 // If the initial offset from start of the object is computable,
thartmann@7819 463 // check if the pre-loop can align the final offset accordingly.
thartmann@7819 464 //
thartmann@7819 465 // In other words: Can we find an i such that the offset
thartmann@7819 466 // after i pre-loop iterations is aligned to vw?
thartmann@7819 467 // (init_offset + pre_loop) % vw == 0 (1)
thartmann@7819 468 // where
thartmann@7819 469 // pre_loop = i * span
thartmann@7819 470 // is the number of bytes added to the offset by i pre-loop iterations.
thartmann@7819 471 //
thartmann@7819 472 // For this to hold we need pre_loop to increase init_offset by
thartmann@7819 473 // pre_loop = vw - (init_offset % vw)
thartmann@7819 474 //
thartmann@7819 475 // This is only possible if pre_loop is divisible by span because each
thartmann@7819 476 // pre-loop iteration increases the initial offset by 'span' bytes:
thartmann@7819 477 // (vw - (init_offset % vw)) % span == 0
thartmann@7819 478 //
aoqi@0 479 int vw = vector_width_in_bytes(p.mem());
aoqi@0 480 assert(vw > 1, "sanity");
thartmann@7819 481 Node* init_nd = pre_end->init_trip();
thartmann@7819 482 if (init_nd->is_Con() && p.invar() == NULL) {
thartmann@7819 483 int init = init_nd->bottom_type()->is_int()->get_con();
thartmann@7819 484 int init_offset = init * p.scale_in_bytes() + offset;
thartmann@7819 485 assert(init_offset >= 0, "positive offset from object start");
thartmann@7819 486 if (vw % span == 0) {
thartmann@7819 487 // If vm is a multiple of span, we use formula (1).
aoqi@0 488 if (span > 0) {
aoqi@0 489 return (vw - (init_offset % vw)) % span == 0;
aoqi@0 490 } else {
aoqi@0 491 assert(span < 0, "nonzero stride * scale");
aoqi@0 492 return (init_offset % vw) % -span == 0;
aoqi@0 493 }
thartmann@7819 494 } else if (span % vw == 0) {
thartmann@7819 495 // If span is a multiple of vw, we can simplify formula (1) to:
thartmann@7819 496 // (init_offset + i * span) % vw == 0
thartmann@7819 497 // =>
thartmann@7819 498 // (init_offset % vw) + ((i * span) % vw) == 0
thartmann@7819 499 // =>
thartmann@7819 500 // init_offset % vw == 0
thartmann@7819 501 //
thartmann@7819 502 // Because we add a multiple of vw to the initial offset, the final
thartmann@7819 503 // offset is a multiple of vw if and only if init_offset is a multiple.
thartmann@7819 504 //
thartmann@7819 505 return (init_offset % vw) == 0;
aoqi@0 506 }
aoqi@0 507 }
aoqi@0 508 return false;
aoqi@0 509 }
aoqi@0 510
aoqi@0 511 //---------------------------get_iv_adjustment---------------------------
aoqi@0 512 // Calculate loop's iv adjustment for this memory ops.
aoqi@0 513 int SuperWord::get_iv_adjustment(MemNode* mem_ref) {
aoqi@0 514 SWPointer align_to_ref_p(mem_ref, this);
aoqi@0 515 int offset = align_to_ref_p.offset_in_bytes();
aoqi@0 516 int scale = align_to_ref_p.scale_in_bytes();
thartmann@7819 517 int elt_size = align_to_ref_p.memory_size();
aoqi@0 518 int vw = vector_width_in_bytes(mem_ref);
aoqi@0 519 assert(vw > 1, "sanity");
thartmann@7819 520 int iv_adjustment;
thartmann@7819 521 if (scale != 0) {
thartmann@7819 522 int stride_sign = (scale * iv_stride()) > 0 ? 1 : -1;
thartmann@7819 523 // At least one iteration is executed in pre-loop by default. As result
thartmann@7819 524 // several iterations are needed to align memory operations in main-loop even
thartmann@7819 525 // if offset is 0.
thartmann@7819 526 int iv_adjustment_in_bytes = (stride_sign * vw - (offset % vw));
thartmann@7819 527 assert(((ABS(iv_adjustment_in_bytes) % elt_size) == 0),
thartmann@7819 528 err_msg_res("(%d) should be divisible by (%d)", iv_adjustment_in_bytes, elt_size));
thartmann@7819 529 iv_adjustment = iv_adjustment_in_bytes/elt_size;
thartmann@7819 530 } else {
thartmann@7819 531 // This memory op is not dependent on iv (scale == 0)
thartmann@7819 532 iv_adjustment = 0;
thartmann@7819 533 }
aoqi@0 534
aoqi@0 535 #ifndef PRODUCT
aoqi@0 536 if (TraceSuperWord)
aoqi@0 537 tty->print_cr("\noffset = %d iv_adjust = %d elt_size = %d scale = %d iv_stride = %d vect_size %d",
aoqi@0 538 offset, iv_adjustment, elt_size, scale, iv_stride(), vw);
aoqi@0 539 #endif
aoqi@0 540 return iv_adjustment;
aoqi@0 541 }
aoqi@0 542
aoqi@0 543 //---------------------------dependence_graph---------------------------
aoqi@0 544 // Construct dependency graph.
aoqi@0 545 // Add dependence edges to load/store nodes for memory dependence
aoqi@0 546 // A.out()->DependNode.in(1) and DependNode.out()->B.prec(x)
aoqi@0 547 void SuperWord::dependence_graph() {
aoqi@0 548 // First, assign a dependence node to each memory node
aoqi@0 549 for (int i = 0; i < _block.length(); i++ ) {
aoqi@0 550 Node *n = _block.at(i);
aoqi@0 551 if (n->is_Mem() || n->is_Phi() && n->bottom_type() == Type::MEMORY) {
aoqi@0 552 _dg.make_node(n);
aoqi@0 553 }
aoqi@0 554 }
aoqi@0 555
aoqi@0 556 // For each memory slice, create the dependences
aoqi@0 557 for (int i = 0; i < _mem_slice_head.length(); i++) {
aoqi@0 558 Node* n = _mem_slice_head.at(i);
aoqi@0 559 Node* n_tail = _mem_slice_tail.at(i);
aoqi@0 560
aoqi@0 561 // Get slice in predecessor order (last is first)
aoqi@0 562 mem_slice_preds(n_tail, n, _nlist);
aoqi@0 563
aoqi@0 564 // Make the slice dependent on the root
aoqi@0 565 DepMem* slice = _dg.dep(n);
aoqi@0 566 _dg.make_edge(_dg.root(), slice);
aoqi@0 567
aoqi@0 568 // Create a sink for the slice
aoqi@0 569 DepMem* slice_sink = _dg.make_node(NULL);
aoqi@0 570 _dg.make_edge(slice_sink, _dg.tail());
aoqi@0 571
aoqi@0 572 // Now visit each pair of memory ops, creating the edges
aoqi@0 573 for (int j = _nlist.length() - 1; j >= 0 ; j--) {
aoqi@0 574 Node* s1 = _nlist.at(j);
aoqi@0 575
aoqi@0 576 // If no dependency yet, use slice
aoqi@0 577 if (_dg.dep(s1)->in_cnt() == 0) {
aoqi@0 578 _dg.make_edge(slice, s1);
aoqi@0 579 }
aoqi@0 580 SWPointer p1(s1->as_Mem(), this);
aoqi@0 581 bool sink_dependent = true;
aoqi@0 582 for (int k = j - 1; k >= 0; k--) {
aoqi@0 583 Node* s2 = _nlist.at(k);
aoqi@0 584 if (s1->is_Load() && s2->is_Load())
aoqi@0 585 continue;
aoqi@0 586 SWPointer p2(s2->as_Mem(), this);
aoqi@0 587
aoqi@0 588 int cmp = p1.cmp(p2);
aoqi@0 589 if (SuperWordRTDepCheck &&
aoqi@0 590 p1.base() != p2.base() && p1.valid() && p2.valid()) {
aoqi@0 591 // Create a runtime check to disambiguate
aoqi@0 592 OrderedPair pp(p1.base(), p2.base());
aoqi@0 593 _disjoint_ptrs.append_if_missing(pp);
aoqi@0 594 } else if (!SWPointer::not_equal(cmp)) {
aoqi@0 595 // Possibly same address
aoqi@0 596 _dg.make_edge(s1, s2);
aoqi@0 597 sink_dependent = false;
aoqi@0 598 }
aoqi@0 599 }
aoqi@0 600 if (sink_dependent) {
aoqi@0 601 _dg.make_edge(s1, slice_sink);
aoqi@0 602 }
aoqi@0 603 }
aoqi@0 604 #ifndef PRODUCT
aoqi@0 605 if (TraceSuperWord) {
aoqi@0 606 tty->print_cr("\nDependence graph for slice: %d", n->_idx);
aoqi@0 607 for (int q = 0; q < _nlist.length(); q++) {
aoqi@0 608 _dg.print(_nlist.at(q));
aoqi@0 609 }
aoqi@0 610 tty->cr();
aoqi@0 611 }
aoqi@0 612 #endif
aoqi@0 613 _nlist.clear();
aoqi@0 614 }
aoqi@0 615
aoqi@0 616 #ifndef PRODUCT
aoqi@0 617 if (TraceSuperWord) {
aoqi@0 618 tty->print_cr("\ndisjoint_ptrs: %s", _disjoint_ptrs.length() > 0 ? "" : "NONE");
aoqi@0 619 for (int r = 0; r < _disjoint_ptrs.length(); r++) {
aoqi@0 620 _disjoint_ptrs.at(r).print();
aoqi@0 621 tty->cr();
aoqi@0 622 }
aoqi@0 623 tty->cr();
aoqi@0 624 }
aoqi@0 625 #endif
aoqi@0 626 }
aoqi@0 627
aoqi@0 628 //---------------------------mem_slice_preds---------------------------
aoqi@0 629 // Return a memory slice (node list) in predecessor order starting at "start"
aoqi@0 630 void SuperWord::mem_slice_preds(Node* start, Node* stop, GrowableArray<Node*> &preds) {
aoqi@0 631 assert(preds.length() == 0, "start empty");
aoqi@0 632 Node* n = start;
aoqi@0 633 Node* prev = NULL;
aoqi@0 634 while (true) {
aoqi@0 635 assert(in_bb(n), "must be in block");
aoqi@0 636 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
aoqi@0 637 Node* out = n->fast_out(i);
aoqi@0 638 if (out->is_Load()) {
aoqi@0 639 if (in_bb(out)) {
aoqi@0 640 preds.push(out);
aoqi@0 641 }
aoqi@0 642 } else {
aoqi@0 643 // FIXME
aoqi@0 644 if (out->is_MergeMem() && !in_bb(out)) {
aoqi@0 645 // Either unrolling is causing a memory edge not to disappear,
aoqi@0 646 // or need to run igvn.optimize() again before SLP
aoqi@0 647 } else if (out->is_Phi() && out->bottom_type() == Type::MEMORY && !in_bb(out)) {
aoqi@0 648 // Ditto. Not sure what else to check further.
aoqi@0 649 } else if (out->Opcode() == Op_StoreCM && out->in(MemNode::OopStore) == n) {
aoqi@0 650 // StoreCM has an input edge used as a precedence edge.
aoqi@0 651 // Maybe an issue when oop stores are vectorized.
aoqi@0 652 } else {
aoqi@0 653 assert(out == prev || prev == NULL, "no branches off of store slice");
aoqi@0 654 }
aoqi@0 655 }
aoqi@0 656 }
aoqi@0 657 if (n == stop) break;
aoqi@0 658 preds.push(n);
aoqi@0 659 prev = n;
aoqi@0 660 assert(n->is_Mem(), err_msg_res("unexpected node %s", n->Name()));
aoqi@0 661 n = n->in(MemNode::Memory);
aoqi@0 662 }
aoqi@0 663 }
aoqi@0 664
aoqi@0 665 //------------------------------stmts_can_pack---------------------------
aoqi@0 666 // Can s1 and s2 be in a pack with s1 immediately preceding s2 and
aoqi@0 667 // s1 aligned at "align"
aoqi@0 668 bool SuperWord::stmts_can_pack(Node* s1, Node* s2, int align) {
aoqi@0 669
aoqi@0 670 // Do not use superword for non-primitives
aoqi@0 671 BasicType bt1 = velt_basic_type(s1);
aoqi@0 672 BasicType bt2 = velt_basic_type(s2);
aoqi@0 673 if(!is_java_primitive(bt1) || !is_java_primitive(bt2))
aoqi@0 674 return false;
aoqi@0 675 if (Matcher::max_vector_size(bt1) < 2) {
aoqi@0 676 return false; // No vectors for this type
aoqi@0 677 }
aoqi@0 678
aoqi@0 679 if (isomorphic(s1, s2)) {
aoqi@0 680 if (independent(s1, s2)) {
aoqi@0 681 if (!exists_at(s1, 0) && !exists_at(s2, 1)) {
aoqi@0 682 if (!s1->is_Mem() || are_adjacent_refs(s1, s2)) {
aoqi@0 683 int s1_align = alignment(s1);
aoqi@0 684 int s2_align = alignment(s2);
aoqi@0 685 if (s1_align == top_align || s1_align == align) {
aoqi@0 686 if (s2_align == top_align || s2_align == align + data_size(s1)) {
aoqi@0 687 return true;
aoqi@0 688 }
aoqi@0 689 }
aoqi@0 690 }
aoqi@0 691 }
aoqi@0 692 }
aoqi@0 693 }
aoqi@0 694 return false;
aoqi@0 695 }
aoqi@0 696
aoqi@0 697 //------------------------------exists_at---------------------------
aoqi@0 698 // Does s exist in a pack at position pos?
aoqi@0 699 bool SuperWord::exists_at(Node* s, uint pos) {
aoqi@0 700 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 701 Node_List* p = _packset.at(i);
aoqi@0 702 if (p->at(pos) == s) {
aoqi@0 703 return true;
aoqi@0 704 }
aoqi@0 705 }
aoqi@0 706 return false;
aoqi@0 707 }
aoqi@0 708
aoqi@0 709 //------------------------------are_adjacent_refs---------------------------
aoqi@0 710 // Is s1 immediately before s2 in memory?
aoqi@0 711 bool SuperWord::are_adjacent_refs(Node* s1, Node* s2) {
aoqi@0 712 if (!s1->is_Mem() || !s2->is_Mem()) return false;
aoqi@0 713 if (!in_bb(s1) || !in_bb(s2)) return false;
aoqi@0 714
aoqi@0 715 // Do not use superword for non-primitives
aoqi@0 716 if (!is_java_primitive(s1->as_Mem()->memory_type()) ||
aoqi@0 717 !is_java_primitive(s2->as_Mem()->memory_type())) {
aoqi@0 718 return false;
aoqi@0 719 }
aoqi@0 720
aoqi@0 721 // FIXME - co_locate_pack fails on Stores in different mem-slices, so
aoqi@0 722 // only pack memops that are in the same alias set until that's fixed.
aoqi@0 723 if (_phase->C->get_alias_index(s1->as_Mem()->adr_type()) !=
aoqi@0 724 _phase->C->get_alias_index(s2->as_Mem()->adr_type()))
aoqi@0 725 return false;
aoqi@0 726 SWPointer p1(s1->as_Mem(), this);
aoqi@0 727 SWPointer p2(s2->as_Mem(), this);
aoqi@0 728 if (p1.base() != p2.base() || !p1.comparable(p2)) return false;
aoqi@0 729 int diff = p2.offset_in_bytes() - p1.offset_in_bytes();
aoqi@0 730 return diff == data_size(s1);
aoqi@0 731 }
aoqi@0 732
aoqi@0 733 //------------------------------isomorphic---------------------------
aoqi@0 734 // Are s1 and s2 similar?
aoqi@0 735 bool SuperWord::isomorphic(Node* s1, Node* s2) {
aoqi@0 736 if (s1->Opcode() != s2->Opcode()) return false;
aoqi@0 737 if (s1->req() != s2->req()) return false;
aoqi@0 738 if (s1->in(0) != s2->in(0)) return false;
aoqi@0 739 if (!same_velt_type(s1, s2)) return false;
aoqi@0 740 return true;
aoqi@0 741 }
aoqi@0 742
aoqi@0 743 //------------------------------independent---------------------------
aoqi@0 744 // Is there no data path from s1 to s2 or s2 to s1?
aoqi@0 745 bool SuperWord::independent(Node* s1, Node* s2) {
aoqi@0 746 // assert(s1->Opcode() == s2->Opcode(), "check isomorphic first");
aoqi@0 747 int d1 = depth(s1);
aoqi@0 748 int d2 = depth(s2);
aoqi@0 749 if (d1 == d2) return s1 != s2;
aoqi@0 750 Node* deep = d1 > d2 ? s1 : s2;
aoqi@0 751 Node* shallow = d1 > d2 ? s2 : s1;
aoqi@0 752
aoqi@0 753 visited_clear();
aoqi@0 754
aoqi@0 755 return independent_path(shallow, deep);
aoqi@0 756 }
aoqi@0 757
aoqi@0 758 //------------------------------independent_path------------------------------
aoqi@0 759 // Helper for independent
aoqi@0 760 bool SuperWord::independent_path(Node* shallow, Node* deep, uint dp) {
aoqi@0 761 if (dp >= 1000) return false; // stop deep recursion
aoqi@0 762 visited_set(deep);
aoqi@0 763 int shal_depth = depth(shallow);
aoqi@0 764 assert(shal_depth <= depth(deep), "must be");
aoqi@0 765 for (DepPreds preds(deep, _dg); !preds.done(); preds.next()) {
aoqi@0 766 Node* pred = preds.current();
aoqi@0 767 if (in_bb(pred) && !visited_test(pred)) {
aoqi@0 768 if (shallow == pred) {
aoqi@0 769 return false;
aoqi@0 770 }
aoqi@0 771 if (shal_depth < depth(pred) && !independent_path(shallow, pred, dp+1)) {
aoqi@0 772 return false;
aoqi@0 773 }
aoqi@0 774 }
aoqi@0 775 }
aoqi@0 776 return true;
aoqi@0 777 }
aoqi@0 778
aoqi@0 779 //------------------------------set_alignment---------------------------
aoqi@0 780 void SuperWord::set_alignment(Node* s1, Node* s2, int align) {
aoqi@0 781 set_alignment(s1, align);
aoqi@0 782 if (align == top_align || align == bottom_align) {
aoqi@0 783 set_alignment(s2, align);
aoqi@0 784 } else {
aoqi@0 785 set_alignment(s2, align + data_size(s1));
aoqi@0 786 }
aoqi@0 787 }
aoqi@0 788
aoqi@0 789 //------------------------------data_size---------------------------
aoqi@0 790 int SuperWord::data_size(Node* s) {
aoqi@0 791 int bsize = type2aelembytes(velt_basic_type(s));
aoqi@0 792 assert(bsize != 0, "valid size");
aoqi@0 793 return bsize;
aoqi@0 794 }
aoqi@0 795
aoqi@0 796 //------------------------------extend_packlist---------------------------
aoqi@0 797 // Extend packset by following use->def and def->use links from pack members.
aoqi@0 798 void SuperWord::extend_packlist() {
aoqi@0 799 bool changed;
aoqi@0 800 do {
aoqi@0 801 changed = false;
aoqi@0 802 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 803 Node_List* p = _packset.at(i);
aoqi@0 804 changed |= follow_use_defs(p);
aoqi@0 805 changed |= follow_def_uses(p);
aoqi@0 806 }
aoqi@0 807 } while (changed);
aoqi@0 808
aoqi@0 809 #ifndef PRODUCT
aoqi@0 810 if (TraceSuperWord) {
aoqi@0 811 tty->print_cr("\nAfter extend_packlist");
aoqi@0 812 print_packset();
aoqi@0 813 }
aoqi@0 814 #endif
aoqi@0 815 }
aoqi@0 816
aoqi@0 817 //------------------------------follow_use_defs---------------------------
aoqi@0 818 // Extend the packset by visiting operand definitions of nodes in pack p
aoqi@0 819 bool SuperWord::follow_use_defs(Node_List* p) {
aoqi@0 820 assert(p->size() == 2, "just checking");
aoqi@0 821 Node* s1 = p->at(0);
aoqi@0 822 Node* s2 = p->at(1);
aoqi@0 823 assert(s1->req() == s2->req(), "just checking");
aoqi@0 824 assert(alignment(s1) + data_size(s1) == alignment(s2), "just checking");
aoqi@0 825
aoqi@0 826 if (s1->is_Load()) return false;
aoqi@0 827
aoqi@0 828 int align = alignment(s1);
aoqi@0 829 bool changed = false;
aoqi@0 830 int start = s1->is_Store() ? MemNode::ValueIn : 1;
aoqi@0 831 int end = s1->is_Store() ? MemNode::ValueIn+1 : s1->req();
aoqi@0 832 for (int j = start; j < end; j++) {
aoqi@0 833 Node* t1 = s1->in(j);
aoqi@0 834 Node* t2 = s2->in(j);
aoqi@0 835 if (!in_bb(t1) || !in_bb(t2))
aoqi@0 836 continue;
aoqi@0 837 if (stmts_can_pack(t1, t2, align)) {
aoqi@0 838 if (est_savings(t1, t2) >= 0) {
aoqi@0 839 Node_List* pair = new Node_List();
aoqi@0 840 pair->push(t1);
aoqi@0 841 pair->push(t2);
aoqi@0 842 _packset.append(pair);
aoqi@0 843 set_alignment(t1, t2, align);
aoqi@0 844 changed = true;
aoqi@0 845 }
aoqi@0 846 }
aoqi@0 847 }
aoqi@0 848 return changed;
aoqi@0 849 }
aoqi@0 850
aoqi@0 851 //------------------------------follow_def_uses---------------------------
aoqi@0 852 // Extend the packset by visiting uses of nodes in pack p
aoqi@0 853 bool SuperWord::follow_def_uses(Node_List* p) {
aoqi@0 854 bool changed = false;
aoqi@0 855 Node* s1 = p->at(0);
aoqi@0 856 Node* s2 = p->at(1);
aoqi@0 857 assert(p->size() == 2, "just checking");
aoqi@0 858 assert(s1->req() == s2->req(), "just checking");
aoqi@0 859 assert(alignment(s1) + data_size(s1) == alignment(s2), "just checking");
aoqi@0 860
aoqi@0 861 if (s1->is_Store()) return false;
aoqi@0 862
aoqi@0 863 int align = alignment(s1);
aoqi@0 864 int savings = -1;
aoqi@0 865 Node* u1 = NULL;
aoqi@0 866 Node* u2 = NULL;
aoqi@0 867 for (DUIterator_Fast imax, i = s1->fast_outs(imax); i < imax; i++) {
aoqi@0 868 Node* t1 = s1->fast_out(i);
aoqi@0 869 if (!in_bb(t1)) continue;
aoqi@0 870 for (DUIterator_Fast jmax, j = s2->fast_outs(jmax); j < jmax; j++) {
aoqi@0 871 Node* t2 = s2->fast_out(j);
aoqi@0 872 if (!in_bb(t2)) continue;
aoqi@0 873 if (!opnd_positions_match(s1, t1, s2, t2))
aoqi@0 874 continue;
aoqi@0 875 if (stmts_can_pack(t1, t2, align)) {
aoqi@0 876 int my_savings = est_savings(t1, t2);
aoqi@0 877 if (my_savings > savings) {
aoqi@0 878 savings = my_savings;
aoqi@0 879 u1 = t1;
aoqi@0 880 u2 = t2;
aoqi@0 881 }
aoqi@0 882 }
aoqi@0 883 }
aoqi@0 884 }
aoqi@0 885 if (savings >= 0) {
aoqi@0 886 Node_List* pair = new Node_List();
aoqi@0 887 pair->push(u1);
aoqi@0 888 pair->push(u2);
aoqi@0 889 _packset.append(pair);
aoqi@0 890 set_alignment(u1, u2, align);
aoqi@0 891 changed = true;
aoqi@0 892 }
aoqi@0 893 return changed;
aoqi@0 894 }
aoqi@0 895
aoqi@0 896 //---------------------------opnd_positions_match-------------------------
aoqi@0 897 // Is the use of d1 in u1 at the same operand position as d2 in u2?
aoqi@0 898 bool SuperWord::opnd_positions_match(Node* d1, Node* u1, Node* d2, Node* u2) {
aoqi@0 899 uint ct = u1->req();
aoqi@0 900 if (ct != u2->req()) return false;
aoqi@0 901 uint i1 = 0;
aoqi@0 902 uint i2 = 0;
aoqi@0 903 do {
aoqi@0 904 for (i1++; i1 < ct; i1++) if (u1->in(i1) == d1) break;
aoqi@0 905 for (i2++; i2 < ct; i2++) if (u2->in(i2) == d2) break;
aoqi@0 906 if (i1 != i2) {
aoqi@0 907 if ((i1 == (3-i2)) && (u2->is_Add() || u2->is_Mul())) {
aoqi@0 908 // Further analysis relies on operands position matching.
aoqi@0 909 u2->swap_edges(i1, i2);
aoqi@0 910 } else {
aoqi@0 911 return false;
aoqi@0 912 }
aoqi@0 913 }
aoqi@0 914 } while (i1 < ct);
aoqi@0 915 return true;
aoqi@0 916 }
aoqi@0 917
aoqi@0 918 //------------------------------est_savings---------------------------
aoqi@0 919 // Estimate the savings from executing s1 and s2 as a pack
aoqi@0 920 int SuperWord::est_savings(Node* s1, Node* s2) {
aoqi@0 921 int save_in = 2 - 1; // 2 operations per instruction in packed form
aoqi@0 922
aoqi@0 923 // inputs
aoqi@0 924 for (uint i = 1; i < s1->req(); i++) {
aoqi@0 925 Node* x1 = s1->in(i);
aoqi@0 926 Node* x2 = s2->in(i);
aoqi@0 927 if (x1 != x2) {
aoqi@0 928 if (are_adjacent_refs(x1, x2)) {
aoqi@0 929 save_in += adjacent_profit(x1, x2);
aoqi@0 930 } else if (!in_packset(x1, x2)) {
aoqi@0 931 save_in -= pack_cost(2);
aoqi@0 932 } else {
aoqi@0 933 save_in += unpack_cost(2);
aoqi@0 934 }
aoqi@0 935 }
aoqi@0 936 }
aoqi@0 937
aoqi@0 938 // uses of result
aoqi@0 939 uint ct = 0;
aoqi@0 940 int save_use = 0;
aoqi@0 941 for (DUIterator_Fast imax, i = s1->fast_outs(imax); i < imax; i++) {
aoqi@0 942 Node* s1_use = s1->fast_out(i);
aoqi@0 943 for (int j = 0; j < _packset.length(); j++) {
aoqi@0 944 Node_List* p = _packset.at(j);
aoqi@0 945 if (p->at(0) == s1_use) {
aoqi@0 946 for (DUIterator_Fast kmax, k = s2->fast_outs(kmax); k < kmax; k++) {
aoqi@0 947 Node* s2_use = s2->fast_out(k);
aoqi@0 948 if (p->at(p->size()-1) == s2_use) {
aoqi@0 949 ct++;
aoqi@0 950 if (are_adjacent_refs(s1_use, s2_use)) {
aoqi@0 951 save_use += adjacent_profit(s1_use, s2_use);
aoqi@0 952 }
aoqi@0 953 }
aoqi@0 954 }
aoqi@0 955 }
aoqi@0 956 }
aoqi@0 957 }
aoqi@0 958
aoqi@0 959 if (ct < s1->outcnt()) save_use += unpack_cost(1);
aoqi@0 960 if (ct < s2->outcnt()) save_use += unpack_cost(1);
aoqi@0 961
aoqi@0 962 return MAX2(save_in, save_use);
aoqi@0 963 }
aoqi@0 964
aoqi@0 965 //------------------------------costs---------------------------
aoqi@0 966 int SuperWord::adjacent_profit(Node* s1, Node* s2) { return 2; }
aoqi@0 967 int SuperWord::pack_cost(int ct) { return ct; }
aoqi@0 968 int SuperWord::unpack_cost(int ct) { return ct; }
aoqi@0 969
aoqi@0 970 //------------------------------combine_packs---------------------------
aoqi@0 971 // Combine packs A and B with A.last == B.first into A.first..,A.last,B.second,..B.last
aoqi@0 972 void SuperWord::combine_packs() {
aoqi@0 973 bool changed = true;
aoqi@0 974 // Combine packs regardless max vector size.
aoqi@0 975 while (changed) {
aoqi@0 976 changed = false;
aoqi@0 977 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 978 Node_List* p1 = _packset.at(i);
aoqi@0 979 if (p1 == NULL) continue;
aoqi@0 980 for (int j = 0; j < _packset.length(); j++) {
aoqi@0 981 Node_List* p2 = _packset.at(j);
aoqi@0 982 if (p2 == NULL) continue;
aoqi@0 983 if (i == j) continue;
aoqi@0 984 if (p1->at(p1->size()-1) == p2->at(0)) {
aoqi@0 985 for (uint k = 1; k < p2->size(); k++) {
aoqi@0 986 p1->push(p2->at(k));
aoqi@0 987 }
aoqi@0 988 _packset.at_put(j, NULL);
aoqi@0 989 changed = true;
aoqi@0 990 }
aoqi@0 991 }
aoqi@0 992 }
aoqi@0 993 }
aoqi@0 994
aoqi@0 995 // Split packs which have size greater then max vector size.
aoqi@0 996 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 997 Node_List* p1 = _packset.at(i);
aoqi@0 998 if (p1 != NULL) {
aoqi@0 999 BasicType bt = velt_basic_type(p1->at(0));
aoqi@0 1000 uint max_vlen = Matcher::max_vector_size(bt); // Max elements in vector
aoqi@0 1001 assert(is_power_of_2(max_vlen), "sanity");
aoqi@0 1002 uint psize = p1->size();
aoqi@0 1003 if (!is_power_of_2(psize)) {
aoqi@0 1004 // Skip pack which can't be vector.
aoqi@0 1005 // case1: for(...) { a[i] = i; } elements values are different (i+x)
aoqi@0 1006 // case2: for(...) { a[i] = b[i+1]; } can't align both, load and store
aoqi@0 1007 _packset.at_put(i, NULL);
aoqi@0 1008 continue;
aoqi@0 1009 }
aoqi@0 1010 if (psize > max_vlen) {
aoqi@0 1011 Node_List* pack = new Node_List();
aoqi@0 1012 for (uint j = 0; j < psize; j++) {
aoqi@0 1013 pack->push(p1->at(j));
aoqi@0 1014 if (pack->size() >= max_vlen) {
aoqi@0 1015 assert(is_power_of_2(pack->size()), "sanity");
aoqi@0 1016 _packset.append(pack);
aoqi@0 1017 pack = new Node_List();
aoqi@0 1018 }
aoqi@0 1019 }
aoqi@0 1020 _packset.at_put(i, NULL);
aoqi@0 1021 }
aoqi@0 1022 }
aoqi@0 1023 }
aoqi@0 1024
aoqi@0 1025 // Compress list.
aoqi@0 1026 for (int i = _packset.length() - 1; i >= 0; i--) {
aoqi@0 1027 Node_List* p1 = _packset.at(i);
aoqi@0 1028 if (p1 == NULL) {
aoqi@0 1029 _packset.remove_at(i);
aoqi@0 1030 }
aoqi@0 1031 }
aoqi@0 1032
aoqi@0 1033 #ifndef PRODUCT
aoqi@0 1034 if (TraceSuperWord) {
aoqi@0 1035 tty->print_cr("\nAfter combine_packs");
aoqi@0 1036 print_packset();
aoqi@0 1037 }
aoqi@0 1038 #endif
aoqi@0 1039 }
aoqi@0 1040
aoqi@0 1041 //-----------------------------construct_my_pack_map--------------------------
aoqi@0 1042 // Construct the map from nodes to packs. Only valid after the
aoqi@0 1043 // point where a node is only in one pack (after combine_packs).
aoqi@0 1044 void SuperWord::construct_my_pack_map() {
aoqi@0 1045 Node_List* rslt = NULL;
aoqi@0 1046 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 1047 Node_List* p = _packset.at(i);
aoqi@0 1048 for (uint j = 0; j < p->size(); j++) {
aoqi@0 1049 Node* s = p->at(j);
aoqi@0 1050 assert(my_pack(s) == NULL, "only in one pack");
aoqi@0 1051 set_my_pack(s, p);
aoqi@0 1052 }
aoqi@0 1053 }
aoqi@0 1054 }
aoqi@0 1055
aoqi@0 1056 //------------------------------filter_packs---------------------------
aoqi@0 1057 // Remove packs that are not implemented or not profitable.
aoqi@0 1058 void SuperWord::filter_packs() {
aoqi@0 1059
aoqi@0 1060 // Remove packs that are not implemented
aoqi@0 1061 for (int i = _packset.length() - 1; i >= 0; i--) {
aoqi@0 1062 Node_List* pk = _packset.at(i);
aoqi@0 1063 bool impl = implemented(pk);
aoqi@0 1064 if (!impl) {
aoqi@0 1065 #ifndef PRODUCT
aoqi@0 1066 if (TraceSuperWord && Verbose) {
aoqi@0 1067 tty->print_cr("Unimplemented");
aoqi@0 1068 pk->at(0)->dump();
aoqi@0 1069 }
aoqi@0 1070 #endif
aoqi@0 1071 remove_pack_at(i);
aoqi@0 1072 }
aoqi@0 1073 }
aoqi@0 1074
aoqi@0 1075 // Remove packs that are not profitable
aoqi@0 1076 bool changed;
aoqi@0 1077 do {
aoqi@0 1078 changed = false;
aoqi@0 1079 for (int i = _packset.length() - 1; i >= 0; i--) {
aoqi@0 1080 Node_List* pk = _packset.at(i);
aoqi@0 1081 bool prof = profitable(pk);
aoqi@0 1082 if (!prof) {
aoqi@0 1083 #ifndef PRODUCT
aoqi@0 1084 if (TraceSuperWord && Verbose) {
aoqi@0 1085 tty->print_cr("Unprofitable");
aoqi@0 1086 pk->at(0)->dump();
aoqi@0 1087 }
aoqi@0 1088 #endif
aoqi@0 1089 remove_pack_at(i);
aoqi@0 1090 changed = true;
aoqi@0 1091 }
aoqi@0 1092 }
aoqi@0 1093 } while (changed);
aoqi@0 1094
aoqi@0 1095 #ifndef PRODUCT
aoqi@0 1096 if (TraceSuperWord) {
aoqi@0 1097 tty->print_cr("\nAfter filter_packs");
aoqi@0 1098 print_packset();
aoqi@0 1099 tty->cr();
aoqi@0 1100 }
aoqi@0 1101 #endif
aoqi@0 1102 }
aoqi@0 1103
aoqi@0 1104 //------------------------------implemented---------------------------
aoqi@0 1105 // Can code be generated for pack p?
aoqi@0 1106 bool SuperWord::implemented(Node_List* p) {
aoqi@0 1107 Node* p0 = p->at(0);
aoqi@0 1108 return VectorNode::implemented(p0->Opcode(), p->size(), velt_basic_type(p0));
aoqi@0 1109 }
aoqi@0 1110
aoqi@0 1111 //------------------------------same_inputs--------------------------
aoqi@0 1112 // For pack p, are all idx operands the same?
aoqi@0 1113 static bool same_inputs(Node_List* p, int idx) {
aoqi@0 1114 Node* p0 = p->at(0);
aoqi@0 1115 uint vlen = p->size();
aoqi@0 1116 Node* p0_def = p0->in(idx);
aoqi@0 1117 for (uint i = 1; i < vlen; i++) {
aoqi@0 1118 Node* pi = p->at(i);
aoqi@0 1119 Node* pi_def = pi->in(idx);
aoqi@0 1120 if (p0_def != pi_def)
aoqi@0 1121 return false;
aoqi@0 1122 }
aoqi@0 1123 return true;
aoqi@0 1124 }
aoqi@0 1125
aoqi@0 1126 //------------------------------profitable---------------------------
aoqi@0 1127 // For pack p, are all operands and all uses (with in the block) vector?
aoqi@0 1128 bool SuperWord::profitable(Node_List* p) {
aoqi@0 1129 Node* p0 = p->at(0);
aoqi@0 1130 uint start, end;
aoqi@0 1131 VectorNode::vector_operands(p0, &start, &end);
aoqi@0 1132
aoqi@0 1133 // Return false if some inputs are not vectors or vectors with different
aoqi@0 1134 // size or alignment.
aoqi@0 1135 // Also, for now, return false if not scalar promotion case when inputs are
aoqi@0 1136 // the same. Later, implement PackNode and allow differing, non-vector inputs
aoqi@0 1137 // (maybe just the ones from outside the block.)
aoqi@0 1138 for (uint i = start; i < end; i++) {
aoqi@0 1139 if (!is_vector_use(p0, i))
aoqi@0 1140 return false;
aoqi@0 1141 }
aoqi@0 1142 if (VectorNode::is_shift(p0)) {
aoqi@0 1143 // For now, return false if shift count is vector or not scalar promotion
aoqi@0 1144 // case (different shift counts) because it is not supported yet.
aoqi@0 1145 Node* cnt = p0->in(2);
aoqi@0 1146 Node_List* cnt_pk = my_pack(cnt);
aoqi@0 1147 if (cnt_pk != NULL)
aoqi@0 1148 return false;
aoqi@0 1149 if (!same_inputs(p, 2))
aoqi@0 1150 return false;
aoqi@0 1151 }
aoqi@0 1152 if (!p0->is_Store()) {
aoqi@0 1153 // For now, return false if not all uses are vector.
aoqi@0 1154 // Later, implement ExtractNode and allow non-vector uses (maybe
aoqi@0 1155 // just the ones outside the block.)
aoqi@0 1156 for (uint i = 0; i < p->size(); i++) {
aoqi@0 1157 Node* def = p->at(i);
aoqi@0 1158 for (DUIterator_Fast jmax, j = def->fast_outs(jmax); j < jmax; j++) {
aoqi@0 1159 Node* use = def->fast_out(j);
aoqi@0 1160 for (uint k = 0; k < use->req(); k++) {
aoqi@0 1161 Node* n = use->in(k);
aoqi@0 1162 if (def == n) {
aoqi@0 1163 if (!is_vector_use(use, k)) {
aoqi@0 1164 return false;
aoqi@0 1165 }
aoqi@0 1166 }
aoqi@0 1167 }
aoqi@0 1168 }
aoqi@0 1169 }
aoqi@0 1170 }
aoqi@0 1171 return true;
aoqi@0 1172 }
aoqi@0 1173
aoqi@0 1174 //------------------------------schedule---------------------------
aoqi@0 1175 // Adjust the memory graph for the packed operations
aoqi@0 1176 void SuperWord::schedule() {
aoqi@0 1177
aoqi@0 1178 // Co-locate in the memory graph the members of each memory pack
aoqi@0 1179 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 1180 co_locate_pack(_packset.at(i));
aoqi@0 1181 }
aoqi@0 1182 }
aoqi@0 1183
aoqi@0 1184 //-------------------------------remove_and_insert-------------------
aoqi@0 1185 // Remove "current" from its current position in the memory graph and insert
aoqi@0 1186 // it after the appropriate insertion point (lip or uip).
aoqi@0 1187 void SuperWord::remove_and_insert(MemNode *current, MemNode *prev, MemNode *lip,
aoqi@0 1188 Node *uip, Unique_Node_List &sched_before) {
aoqi@0 1189 Node* my_mem = current->in(MemNode::Memory);
aoqi@0 1190 bool sched_up = sched_before.member(current);
aoqi@0 1191
aoqi@0 1192 // remove current_store from its current position in the memmory graph
aoqi@0 1193 for (DUIterator i = current->outs(); current->has_out(i); i++) {
aoqi@0 1194 Node* use = current->out(i);
aoqi@0 1195 if (use->is_Mem()) {
aoqi@0 1196 assert(use->in(MemNode::Memory) == current, "must be");
aoqi@0 1197 if (use == prev) { // connect prev to my_mem
aoqi@0 1198 _igvn.replace_input_of(use, MemNode::Memory, my_mem);
aoqi@0 1199 --i; //deleted this edge; rescan position
aoqi@0 1200 } else if (sched_before.member(use)) {
aoqi@0 1201 if (!sched_up) { // Will be moved together with current
aoqi@0 1202 _igvn.replace_input_of(use, MemNode::Memory, uip);
aoqi@0 1203 --i; //deleted this edge; rescan position
aoqi@0 1204 }
aoqi@0 1205 } else {
aoqi@0 1206 if (sched_up) { // Will be moved together with current
aoqi@0 1207 _igvn.replace_input_of(use, MemNode::Memory, lip);
aoqi@0 1208 --i; //deleted this edge; rescan position
aoqi@0 1209 }
aoqi@0 1210 }
aoqi@0 1211 }
aoqi@0 1212 }
aoqi@0 1213
aoqi@0 1214 Node *insert_pt = sched_up ? uip : lip;
aoqi@0 1215
aoqi@0 1216 // all uses of insert_pt's memory state should use current's instead
aoqi@0 1217 for (DUIterator i = insert_pt->outs(); insert_pt->has_out(i); i++) {
aoqi@0 1218 Node* use = insert_pt->out(i);
aoqi@0 1219 if (use->is_Mem()) {
aoqi@0 1220 assert(use->in(MemNode::Memory) == insert_pt, "must be");
aoqi@0 1221 _igvn.replace_input_of(use, MemNode::Memory, current);
aoqi@0 1222 --i; //deleted this edge; rescan position
aoqi@0 1223 } else if (!sched_up && use->is_Phi() && use->bottom_type() == Type::MEMORY) {
aoqi@0 1224 uint pos; //lip (lower insert point) must be the last one in the memory slice
aoqi@0 1225 for (pos=1; pos < use->req(); pos++) {
aoqi@0 1226 if (use->in(pos) == insert_pt) break;
aoqi@0 1227 }
aoqi@0 1228 _igvn.replace_input_of(use, pos, current);
aoqi@0 1229 --i;
aoqi@0 1230 }
aoqi@0 1231 }
aoqi@0 1232
aoqi@0 1233 //connect current to insert_pt
aoqi@0 1234 _igvn.replace_input_of(current, MemNode::Memory, insert_pt);
aoqi@0 1235 }
aoqi@0 1236
aoqi@0 1237 //------------------------------co_locate_pack----------------------------------
aoqi@0 1238 // To schedule a store pack, we need to move any sandwiched memory ops either before
aoqi@0 1239 // or after the pack, based upon dependence information:
aoqi@0 1240 // (1) If any store in the pack depends on the sandwiched memory op, the
aoqi@0 1241 // sandwiched memory op must be scheduled BEFORE the pack;
aoqi@0 1242 // (2) If a sandwiched memory op depends on any store in the pack, the
aoqi@0 1243 // sandwiched memory op must be scheduled AFTER the pack;
aoqi@0 1244 // (3) If a sandwiched memory op (say, memA) depends on another sandwiched
aoqi@0 1245 // memory op (say memB), memB must be scheduled before memA. So, if memA is
aoqi@0 1246 // scheduled before the pack, memB must also be scheduled before the pack;
aoqi@0 1247 // (4) If there is no dependence restriction for a sandwiched memory op, we simply
aoqi@0 1248 // schedule this store AFTER the pack
aoqi@0 1249 // (5) We know there is no dependence cycle, so there in no other case;
aoqi@0 1250 // (6) Finally, all memory ops in another single pack should be moved in the same direction.
aoqi@0 1251 //
aoqi@0 1252 // To schedule a load pack, we use the memory state of either the first or the last load in
aoqi@0 1253 // the pack, based on the dependence constraint.
aoqi@0 1254 void SuperWord::co_locate_pack(Node_List* pk) {
aoqi@0 1255 if (pk->at(0)->is_Store()) {
aoqi@0 1256 MemNode* first = executed_first(pk)->as_Mem();
aoqi@0 1257 MemNode* last = executed_last(pk)->as_Mem();
aoqi@0 1258 Unique_Node_List schedule_before_pack;
aoqi@0 1259 Unique_Node_List memops;
aoqi@0 1260
aoqi@0 1261 MemNode* current = last->in(MemNode::Memory)->as_Mem();
aoqi@0 1262 MemNode* previous = last;
aoqi@0 1263 while (true) {
aoqi@0 1264 assert(in_bb(current), "stay in block");
aoqi@0 1265 memops.push(previous);
aoqi@0 1266 for (DUIterator i = current->outs(); current->has_out(i); i++) {
aoqi@0 1267 Node* use = current->out(i);
aoqi@0 1268 if (use->is_Mem() && use != previous)
aoqi@0 1269 memops.push(use);
aoqi@0 1270 }
aoqi@0 1271 if (current == first) break;
aoqi@0 1272 previous = current;
aoqi@0 1273 current = current->in(MemNode::Memory)->as_Mem();
aoqi@0 1274 }
aoqi@0 1275
aoqi@0 1276 // determine which memory operations should be scheduled before the pack
aoqi@0 1277 for (uint i = 1; i < memops.size(); i++) {
aoqi@0 1278 Node *s1 = memops.at(i);
aoqi@0 1279 if (!in_pack(s1, pk) && !schedule_before_pack.member(s1)) {
aoqi@0 1280 for (uint j = 0; j< i; j++) {
aoqi@0 1281 Node *s2 = memops.at(j);
aoqi@0 1282 if (!independent(s1, s2)) {
aoqi@0 1283 if (in_pack(s2, pk) || schedule_before_pack.member(s2)) {
aoqi@0 1284 schedule_before_pack.push(s1); // s1 must be scheduled before
aoqi@0 1285 Node_List* mem_pk = my_pack(s1);
aoqi@0 1286 if (mem_pk != NULL) {
aoqi@0 1287 for (uint ii = 0; ii < mem_pk->size(); ii++) {
aoqi@0 1288 Node* s = mem_pk->at(ii); // follow partner
aoqi@0 1289 if (memops.member(s) && !schedule_before_pack.member(s))
aoqi@0 1290 schedule_before_pack.push(s);
aoqi@0 1291 }
aoqi@0 1292 }
aoqi@0 1293 break;
aoqi@0 1294 }
aoqi@0 1295 }
aoqi@0 1296 }
aoqi@0 1297 }
aoqi@0 1298 }
aoqi@0 1299
aoqi@0 1300 Node* upper_insert_pt = first->in(MemNode::Memory);
aoqi@0 1301 // Following code moves loads connected to upper_insert_pt below aliased stores.
aoqi@0 1302 // Collect such loads here and reconnect them back to upper_insert_pt later.
aoqi@0 1303 memops.clear();
aoqi@0 1304 for (DUIterator i = upper_insert_pt->outs(); upper_insert_pt->has_out(i); i++) {
aoqi@0 1305 Node* use = upper_insert_pt->out(i);
aoqi@0 1306 if (use->is_Mem() && !use->is_Store()) {
aoqi@0 1307 memops.push(use);
aoqi@0 1308 }
aoqi@0 1309 }
aoqi@0 1310
aoqi@0 1311 MemNode* lower_insert_pt = last;
aoqi@0 1312 previous = last; //previous store in pk
aoqi@0 1313 current = last->in(MemNode::Memory)->as_Mem();
aoqi@0 1314
aoqi@0 1315 // start scheduling from "last" to "first"
aoqi@0 1316 while (true) {
aoqi@0 1317 assert(in_bb(current), "stay in block");
aoqi@0 1318 assert(in_pack(previous, pk), "previous stays in pack");
aoqi@0 1319 Node* my_mem = current->in(MemNode::Memory);
aoqi@0 1320
aoqi@0 1321 if (in_pack(current, pk)) {
aoqi@0 1322 // Forward users of my memory state (except "previous) to my input memory state
aoqi@0 1323 for (DUIterator i = current->outs(); current->has_out(i); i++) {
aoqi@0 1324 Node* use = current->out(i);
aoqi@0 1325 if (use->is_Mem() && use != previous) {
aoqi@0 1326 assert(use->in(MemNode::Memory) == current, "must be");
aoqi@0 1327 if (schedule_before_pack.member(use)) {
aoqi@0 1328 _igvn.replace_input_of(use, MemNode::Memory, upper_insert_pt);
aoqi@0 1329 } else {
aoqi@0 1330 _igvn.replace_input_of(use, MemNode::Memory, lower_insert_pt);
aoqi@0 1331 }
aoqi@0 1332 --i; // deleted this edge; rescan position
aoqi@0 1333 }
aoqi@0 1334 }
aoqi@0 1335 previous = current;
aoqi@0 1336 } else { // !in_pack(current, pk) ==> a sandwiched store
aoqi@0 1337 remove_and_insert(current, previous, lower_insert_pt, upper_insert_pt, schedule_before_pack);
aoqi@0 1338 }
aoqi@0 1339
aoqi@0 1340 if (current == first) break;
aoqi@0 1341 current = my_mem->as_Mem();
aoqi@0 1342 } // end while
aoqi@0 1343
aoqi@0 1344 // Reconnect loads back to upper_insert_pt.
aoqi@0 1345 for (uint i = 0; i < memops.size(); i++) {
aoqi@0 1346 Node *ld = memops.at(i);
aoqi@0 1347 if (ld->in(MemNode::Memory) != upper_insert_pt) {
aoqi@0 1348 _igvn.replace_input_of(ld, MemNode::Memory, upper_insert_pt);
aoqi@0 1349 }
aoqi@0 1350 }
aoqi@0 1351 } else if (pk->at(0)->is_Load()) { //load
aoqi@0 1352 // all loads in the pack should have the same memory state. By default,
aoqi@0 1353 // we use the memory state of the last load. However, if any load could
aoqi@0 1354 // not be moved down due to the dependence constraint, we use the memory
aoqi@0 1355 // state of the first load.
aoqi@0 1356 Node* last_mem = executed_last(pk)->in(MemNode::Memory);
aoqi@0 1357 Node* first_mem = executed_first(pk)->in(MemNode::Memory);
aoqi@0 1358 bool schedule_last = true;
aoqi@0 1359 for (uint i = 0; i < pk->size(); i++) {
aoqi@0 1360 Node* ld = pk->at(i);
aoqi@0 1361 for (Node* current = last_mem; current != ld->in(MemNode::Memory);
aoqi@0 1362 current=current->in(MemNode::Memory)) {
aoqi@0 1363 assert(current != first_mem, "corrupted memory graph");
aoqi@0 1364 if(current->is_Mem() && !independent(current, ld)){
aoqi@0 1365 schedule_last = false; // a later store depends on this load
aoqi@0 1366 break;
aoqi@0 1367 }
aoqi@0 1368 }
aoqi@0 1369 }
aoqi@0 1370
aoqi@0 1371 Node* mem_input = schedule_last ? last_mem : first_mem;
aoqi@0 1372 _igvn.hash_delete(mem_input);
aoqi@0 1373 // Give each load the same memory state
aoqi@0 1374 for (uint i = 0; i < pk->size(); i++) {
aoqi@0 1375 LoadNode* ld = pk->at(i)->as_Load();
aoqi@0 1376 _igvn.replace_input_of(ld, MemNode::Memory, mem_input);
aoqi@0 1377 }
aoqi@0 1378 }
aoqi@0 1379 }
aoqi@0 1380
aoqi@0 1381 //------------------------------output---------------------------
aoqi@0 1382 // Convert packs into vector node operations
aoqi@0 1383 void SuperWord::output() {
aoqi@0 1384 if (_packset.length() == 0) return;
aoqi@0 1385
aoqi@0 1386 #ifndef PRODUCT
aoqi@0 1387 if (TraceLoopOpts) {
aoqi@0 1388 tty->print("SuperWord ");
aoqi@0 1389 lpt()->dump_head();
aoqi@0 1390 }
aoqi@0 1391 #endif
aoqi@0 1392
aoqi@0 1393 // MUST ENSURE main loop's initial value is properly aligned:
aoqi@0 1394 // (iv_initial_value + min_iv_offset) % vector_width_in_bytes() == 0
aoqi@0 1395
aoqi@0 1396 align_initial_loop_index(align_to_ref());
aoqi@0 1397
aoqi@0 1398 // Insert extract (unpack) operations for scalar uses
aoqi@0 1399 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 1400 insert_extracts(_packset.at(i));
aoqi@0 1401 }
aoqi@0 1402
aoqi@0 1403 Compile* C = _phase->C;
aoqi@0 1404 uint max_vlen_in_bytes = 0;
aoqi@0 1405 for (int i = 0; i < _block.length(); i++) {
aoqi@0 1406 Node* n = _block.at(i);
aoqi@0 1407 Node_List* p = my_pack(n);
aoqi@0 1408 if (p && n == executed_last(p)) {
aoqi@0 1409 uint vlen = p->size();
aoqi@0 1410 uint vlen_in_bytes = 0;
aoqi@0 1411 Node* vn = NULL;
aoqi@0 1412 Node* low_adr = p->at(0);
aoqi@0 1413 Node* first = executed_first(p);
aoqi@0 1414 int opc = n->Opcode();
aoqi@0 1415 if (n->is_Load()) {
aoqi@0 1416 Node* ctl = n->in(MemNode::Control);
aoqi@0 1417 Node* mem = first->in(MemNode::Memory);
kvn@7025 1418 SWPointer p1(n->as_Mem(), this);
kvn@7025 1419 // Identify the memory dependency for the new loadVector node by
kvn@7025 1420 // walking up through memory chain.
kvn@7025 1421 // This is done to give flexibility to the new loadVector node so that
kvn@7025 1422 // it can move above independent storeVector nodes.
kvn@7025 1423 while (mem->is_StoreVector()) {
kvn@7025 1424 SWPointer p2(mem->as_Mem(), this);
kvn@7025 1425 int cmp = p1.cmp(p2);
kvn@7025 1426 if (SWPointer::not_equal(cmp) || !SWPointer::comparable(cmp)) {
kvn@7025 1427 mem = mem->in(MemNode::Memory);
kvn@7025 1428 } else {
kvn@7025 1429 break; // dependent memory
kvn@7025 1430 }
kvn@7025 1431 }
aoqi@0 1432 Node* adr = low_adr->in(MemNode::Address);
aoqi@0 1433 const TypePtr* atyp = n->adr_type();
roland@7859 1434 vn = LoadVectorNode::make(C, opc, ctl, mem, adr, atyp, vlen, velt_basic_type(n), control_dependency(p));
aoqi@0 1435 vlen_in_bytes = vn->as_LoadVector()->memory_size();
aoqi@0 1436 } else if (n->is_Store()) {
aoqi@0 1437 // Promote value to be stored to vector
aoqi@0 1438 Node* val = vector_opd(p, MemNode::ValueIn);
aoqi@0 1439 Node* ctl = n->in(MemNode::Control);
aoqi@0 1440 Node* mem = first->in(MemNode::Memory);
aoqi@0 1441 Node* adr = low_adr->in(MemNode::Address);
aoqi@0 1442 const TypePtr* atyp = n->adr_type();
aoqi@0 1443 vn = StoreVectorNode::make(C, opc, ctl, mem, adr, atyp, val, vlen);
aoqi@0 1444 vlen_in_bytes = vn->as_StoreVector()->memory_size();
aoqi@0 1445 } else if (n->req() == 3) {
aoqi@0 1446 // Promote operands to vector
aoqi@0 1447 Node* in1 = vector_opd(p, 1);
aoqi@0 1448 Node* in2 = vector_opd(p, 2);
aoqi@0 1449 if (VectorNode::is_invariant_vector(in1) && (n->is_Add() || n->is_Mul())) {
aoqi@0 1450 // Move invariant vector input into second position to avoid register spilling.
aoqi@0 1451 Node* tmp = in1;
aoqi@0 1452 in1 = in2;
aoqi@0 1453 in2 = tmp;
aoqi@0 1454 }
aoqi@0 1455 vn = VectorNode::make(C, opc, in1, in2, vlen, velt_basic_type(n));
aoqi@0 1456 vlen_in_bytes = vn->as_Vector()->length_in_bytes();
aoqi@0 1457 } else {
aoqi@0 1458 ShouldNotReachHere();
aoqi@0 1459 }
aoqi@0 1460 assert(vn != NULL, "sanity");
aoqi@0 1461 _igvn.register_new_node_with_optimizer(vn);
aoqi@0 1462 _phase->set_ctrl(vn, _phase->get_ctrl(p->at(0)));
aoqi@0 1463 for (uint j = 0; j < p->size(); j++) {
aoqi@0 1464 Node* pm = p->at(j);
aoqi@0 1465 _igvn.replace_node(pm, vn);
aoqi@0 1466 }
aoqi@0 1467 _igvn._worklist.push(vn);
aoqi@0 1468
aoqi@0 1469 if (vlen_in_bytes > max_vlen_in_bytes) {
aoqi@0 1470 max_vlen_in_bytes = vlen_in_bytes;
aoqi@0 1471 }
aoqi@0 1472 #ifdef ASSERT
aoqi@0 1473 if (TraceNewVectors) {
aoqi@0 1474 tty->print("new Vector node: ");
aoqi@0 1475 vn->dump();
aoqi@0 1476 }
aoqi@0 1477 #endif
aoqi@0 1478 }
aoqi@0 1479 }
aoqi@0 1480 C->set_max_vector_size(max_vlen_in_bytes);
aoqi@0 1481 }
aoqi@0 1482
aoqi@0 1483 //------------------------------vector_opd---------------------------
aoqi@0 1484 // Create a vector operand for the nodes in pack p for operand: in(opd_idx)
aoqi@0 1485 Node* SuperWord::vector_opd(Node_List* p, int opd_idx) {
aoqi@0 1486 Node* p0 = p->at(0);
aoqi@0 1487 uint vlen = p->size();
aoqi@0 1488 Node* opd = p0->in(opd_idx);
aoqi@0 1489
aoqi@0 1490 if (same_inputs(p, opd_idx)) {
aoqi@0 1491 if (opd->is_Vector() || opd->is_LoadVector()) {
aoqi@0 1492 assert(((opd_idx != 2) || !VectorNode::is_shift(p0)), "shift's count can't be vector");
aoqi@0 1493 return opd; // input is matching vector
aoqi@0 1494 }
aoqi@0 1495 if ((opd_idx == 2) && VectorNode::is_shift(p0)) {
aoqi@0 1496 Compile* C = _phase->C;
aoqi@0 1497 Node* cnt = opd;
aoqi@0 1498 // Vector instructions do not mask shift count, do it here.
aoqi@0 1499 juint mask = (p0->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1);
aoqi@0 1500 const TypeInt* t = opd->find_int_type();
aoqi@0 1501 if (t != NULL && t->is_con()) {
aoqi@0 1502 juint shift = t->get_con();
aoqi@0 1503 if (shift > mask) { // Unsigned cmp
aoqi@0 1504 cnt = ConNode::make(C, TypeInt::make(shift & mask));
aoqi@0 1505 }
aoqi@0 1506 } else {
aoqi@0 1507 if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) {
aoqi@0 1508 cnt = ConNode::make(C, TypeInt::make(mask));
aoqi@0 1509 _igvn.register_new_node_with_optimizer(cnt);
aoqi@0 1510 cnt = new (C) AndINode(opd, cnt);
aoqi@0 1511 _igvn.register_new_node_with_optimizer(cnt);
aoqi@0 1512 _phase->set_ctrl(cnt, _phase->get_ctrl(opd));
aoqi@0 1513 }
aoqi@0 1514 assert(opd->bottom_type()->isa_int(), "int type only");
aoqi@0 1515 // Move non constant shift count into vector register.
aoqi@0 1516 cnt = VectorNode::shift_count(C, p0, cnt, vlen, velt_basic_type(p0));
aoqi@0 1517 }
aoqi@0 1518 if (cnt != opd) {
aoqi@0 1519 _igvn.register_new_node_with_optimizer(cnt);
aoqi@0 1520 _phase->set_ctrl(cnt, _phase->get_ctrl(opd));
aoqi@0 1521 }
aoqi@0 1522 return cnt;
aoqi@0 1523 }
aoqi@0 1524 assert(!opd->is_StoreVector(), "such vector is not expected here");
aoqi@0 1525 // Convert scalar input to vector with the same number of elements as
aoqi@0 1526 // p0's vector. Use p0's type because size of operand's container in
aoqi@0 1527 // vector should match p0's size regardless operand's size.
aoqi@0 1528 const Type* p0_t = velt_type(p0);
aoqi@0 1529 VectorNode* vn = VectorNode::scalar2vector(_phase->C, opd, vlen, p0_t);
aoqi@0 1530
aoqi@0 1531 _igvn.register_new_node_with_optimizer(vn);
aoqi@0 1532 _phase->set_ctrl(vn, _phase->get_ctrl(opd));
aoqi@0 1533 #ifdef ASSERT
aoqi@0 1534 if (TraceNewVectors) {
aoqi@0 1535 tty->print("new Vector node: ");
aoqi@0 1536 vn->dump();
aoqi@0 1537 }
aoqi@0 1538 #endif
aoqi@0 1539 return vn;
aoqi@0 1540 }
aoqi@0 1541
aoqi@0 1542 // Insert pack operation
aoqi@0 1543 BasicType bt = velt_basic_type(p0);
aoqi@0 1544 PackNode* pk = PackNode::make(_phase->C, opd, vlen, bt);
aoqi@0 1545 DEBUG_ONLY( const BasicType opd_bt = opd->bottom_type()->basic_type(); )
aoqi@0 1546
aoqi@0 1547 for (uint i = 1; i < vlen; i++) {
aoqi@0 1548 Node* pi = p->at(i);
aoqi@0 1549 Node* in = pi->in(opd_idx);
aoqi@0 1550 assert(my_pack(in) == NULL, "Should already have been unpacked");
aoqi@0 1551 assert(opd_bt == in->bottom_type()->basic_type(), "all same type");
aoqi@0 1552 pk->add_opd(in);
aoqi@0 1553 }
aoqi@0 1554 _igvn.register_new_node_with_optimizer(pk);
aoqi@0 1555 _phase->set_ctrl(pk, _phase->get_ctrl(opd));
aoqi@0 1556 #ifdef ASSERT
aoqi@0 1557 if (TraceNewVectors) {
aoqi@0 1558 tty->print("new Vector node: ");
aoqi@0 1559 pk->dump();
aoqi@0 1560 }
aoqi@0 1561 #endif
aoqi@0 1562 return pk;
aoqi@0 1563 }
aoqi@0 1564
aoqi@0 1565 //------------------------------insert_extracts---------------------------
aoqi@0 1566 // If a use of pack p is not a vector use, then replace the
aoqi@0 1567 // use with an extract operation.
aoqi@0 1568 void SuperWord::insert_extracts(Node_List* p) {
aoqi@0 1569 if (p->at(0)->is_Store()) return;
aoqi@0 1570 assert(_n_idx_list.is_empty(), "empty (node,index) list");
aoqi@0 1571
aoqi@0 1572 // Inspect each use of each pack member. For each use that is
aoqi@0 1573 // not a vector use, replace the use with an extract operation.
aoqi@0 1574
aoqi@0 1575 for (uint i = 0; i < p->size(); i++) {
aoqi@0 1576 Node* def = p->at(i);
aoqi@0 1577 for (DUIterator_Fast jmax, j = def->fast_outs(jmax); j < jmax; j++) {
aoqi@0 1578 Node* use = def->fast_out(j);
aoqi@0 1579 for (uint k = 0; k < use->req(); k++) {
aoqi@0 1580 Node* n = use->in(k);
aoqi@0 1581 if (def == n) {
aoqi@0 1582 if (!is_vector_use(use, k)) {
aoqi@0 1583 _n_idx_list.push(use, k);
aoqi@0 1584 }
aoqi@0 1585 }
aoqi@0 1586 }
aoqi@0 1587 }
aoqi@0 1588 }
aoqi@0 1589
aoqi@0 1590 while (_n_idx_list.is_nonempty()) {
aoqi@0 1591 Node* use = _n_idx_list.node();
aoqi@0 1592 int idx = _n_idx_list.index();
aoqi@0 1593 _n_idx_list.pop();
aoqi@0 1594 Node* def = use->in(idx);
aoqi@0 1595
aoqi@0 1596 // Insert extract operation
aoqi@0 1597 _igvn.hash_delete(def);
aoqi@0 1598 int def_pos = alignment(def) / data_size(def);
aoqi@0 1599
aoqi@0 1600 Node* ex = ExtractNode::make(_phase->C, def, def_pos, velt_basic_type(def));
aoqi@0 1601 _igvn.register_new_node_with_optimizer(ex);
aoqi@0 1602 _phase->set_ctrl(ex, _phase->get_ctrl(def));
aoqi@0 1603 _igvn.replace_input_of(use, idx, ex);
aoqi@0 1604 _igvn._worklist.push(def);
aoqi@0 1605
aoqi@0 1606 bb_insert_after(ex, bb_idx(def));
aoqi@0 1607 set_velt_type(ex, velt_type(def));
aoqi@0 1608 }
aoqi@0 1609 }
aoqi@0 1610
aoqi@0 1611 //------------------------------is_vector_use---------------------------
aoqi@0 1612 // Is use->in(u_idx) a vector use?
aoqi@0 1613 bool SuperWord::is_vector_use(Node* use, int u_idx) {
aoqi@0 1614 Node_List* u_pk = my_pack(use);
aoqi@0 1615 if (u_pk == NULL) return false;
aoqi@0 1616 Node* def = use->in(u_idx);
aoqi@0 1617 Node_List* d_pk = my_pack(def);
aoqi@0 1618 if (d_pk == NULL) {
aoqi@0 1619 // check for scalar promotion
aoqi@0 1620 Node* n = u_pk->at(0)->in(u_idx);
aoqi@0 1621 for (uint i = 1; i < u_pk->size(); i++) {
aoqi@0 1622 if (u_pk->at(i)->in(u_idx) != n) return false;
aoqi@0 1623 }
aoqi@0 1624 return true;
aoqi@0 1625 }
aoqi@0 1626 if (u_pk->size() != d_pk->size())
aoqi@0 1627 return false;
aoqi@0 1628 for (uint i = 0; i < u_pk->size(); i++) {
aoqi@0 1629 Node* ui = u_pk->at(i);
aoqi@0 1630 Node* di = d_pk->at(i);
aoqi@0 1631 if (ui->in(u_idx) != di || alignment(ui) != alignment(di))
aoqi@0 1632 return false;
aoqi@0 1633 }
aoqi@0 1634 return true;
aoqi@0 1635 }
aoqi@0 1636
aoqi@0 1637 //------------------------------construct_bb---------------------------
aoqi@0 1638 // Construct reverse postorder list of block members
aoqi@0 1639 bool SuperWord::construct_bb() {
aoqi@0 1640 Node* entry = bb();
aoqi@0 1641
aoqi@0 1642 assert(_stk.length() == 0, "stk is empty");
aoqi@0 1643 assert(_block.length() == 0, "block is empty");
aoqi@0 1644 assert(_data_entry.length() == 0, "data_entry is empty");
aoqi@0 1645 assert(_mem_slice_head.length() == 0, "mem_slice_head is empty");
aoqi@0 1646 assert(_mem_slice_tail.length() == 0, "mem_slice_tail is empty");
aoqi@0 1647
aoqi@0 1648 // Find non-control nodes with no inputs from within block,
aoqi@0 1649 // create a temporary map from node _idx to bb_idx for use
aoqi@0 1650 // by the visited and post_visited sets,
aoqi@0 1651 // and count number of nodes in block.
aoqi@0 1652 int bb_ct = 0;
aoqi@0 1653 for (uint i = 0; i < lpt()->_body.size(); i++ ) {
aoqi@0 1654 Node *n = lpt()->_body.at(i);
aoqi@0 1655 set_bb_idx(n, i); // Create a temporary map
aoqi@0 1656 if (in_bb(n)) {
aoqi@0 1657 if (n->is_LoadStore() || n->is_MergeMem() ||
aoqi@0 1658 (n->is_Proj() && !n->as_Proj()->is_CFG())) {
aoqi@0 1659 // Bailout if the loop has LoadStore, MergeMem or data Proj
aoqi@0 1660 // nodes. Superword optimization does not work with them.
aoqi@0 1661 return false;
aoqi@0 1662 }
aoqi@0 1663 bb_ct++;
aoqi@0 1664 if (!n->is_CFG()) {
aoqi@0 1665 bool found = false;
aoqi@0 1666 for (uint j = 0; j < n->req(); j++) {
aoqi@0 1667 Node* def = n->in(j);
aoqi@0 1668 if (def && in_bb(def)) {
aoqi@0 1669 found = true;
aoqi@0 1670 break;
aoqi@0 1671 }
aoqi@0 1672 }
aoqi@0 1673 if (!found) {
aoqi@0 1674 assert(n != entry, "can't be entry");
aoqi@0 1675 _data_entry.push(n);
aoqi@0 1676 }
aoqi@0 1677 }
aoqi@0 1678 }
aoqi@0 1679 }
aoqi@0 1680
aoqi@0 1681 // Find memory slices (head and tail)
aoqi@0 1682 for (DUIterator_Fast imax, i = lp()->fast_outs(imax); i < imax; i++) {
aoqi@0 1683 Node *n = lp()->fast_out(i);
aoqi@0 1684 if (in_bb(n) && (n->is_Phi() && n->bottom_type() == Type::MEMORY)) {
aoqi@0 1685 Node* n_tail = n->in(LoopNode::LoopBackControl);
aoqi@0 1686 if (n_tail != n->in(LoopNode::EntryControl)) {
aoqi@0 1687 if (!n_tail->is_Mem()) {
aoqi@0 1688 assert(n_tail->is_Mem(), err_msg_res("unexpected node for memory slice: %s", n_tail->Name()));
aoqi@0 1689 return false; // Bailout
aoqi@0 1690 }
aoqi@0 1691 _mem_slice_head.push(n);
aoqi@0 1692 _mem_slice_tail.push(n_tail);
aoqi@0 1693 }
aoqi@0 1694 }
aoqi@0 1695 }
aoqi@0 1696
aoqi@0 1697 // Create an RPO list of nodes in block
aoqi@0 1698
aoqi@0 1699 visited_clear();
aoqi@0 1700 post_visited_clear();
aoqi@0 1701
aoqi@0 1702 // Push all non-control nodes with no inputs from within block, then control entry
aoqi@0 1703 for (int j = 0; j < _data_entry.length(); j++) {
aoqi@0 1704 Node* n = _data_entry.at(j);
aoqi@0 1705 visited_set(n);
aoqi@0 1706 _stk.push(n);
aoqi@0 1707 }
aoqi@0 1708 visited_set(entry);
aoqi@0 1709 _stk.push(entry);
aoqi@0 1710
aoqi@0 1711 // Do a depth first walk over out edges
aoqi@0 1712 int rpo_idx = bb_ct - 1;
aoqi@0 1713 int size;
aoqi@0 1714 while ((size = _stk.length()) > 0) {
aoqi@0 1715 Node* n = _stk.top(); // Leave node on stack
aoqi@0 1716 if (!visited_test_set(n)) {
aoqi@0 1717 // forward arc in graph
aoqi@0 1718 } else if (!post_visited_test(n)) {
aoqi@0 1719 // cross or back arc
aoqi@0 1720 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
aoqi@0 1721 Node *use = n->fast_out(i);
aoqi@0 1722 if (in_bb(use) && !visited_test(use) &&
aoqi@0 1723 // Don't go around backedge
aoqi@0 1724 (!use->is_Phi() || n == entry)) {
aoqi@0 1725 _stk.push(use);
aoqi@0 1726 }
aoqi@0 1727 }
aoqi@0 1728 if (_stk.length() == size) {
aoqi@0 1729 // There were no additional uses, post visit node now
aoqi@0 1730 _stk.pop(); // Remove node from stack
aoqi@0 1731 assert(rpo_idx >= 0, "");
aoqi@0 1732 _block.at_put_grow(rpo_idx, n);
aoqi@0 1733 rpo_idx--;
aoqi@0 1734 post_visited_set(n);
aoqi@0 1735 assert(rpo_idx >= 0 || _stk.is_empty(), "");
aoqi@0 1736 }
aoqi@0 1737 } else {
aoqi@0 1738 _stk.pop(); // Remove post-visited node from stack
aoqi@0 1739 }
aoqi@0 1740 }
aoqi@0 1741
aoqi@0 1742 // Create real map of block indices for nodes
aoqi@0 1743 for (int j = 0; j < _block.length(); j++) {
aoqi@0 1744 Node* n = _block.at(j);
aoqi@0 1745 set_bb_idx(n, j);
aoqi@0 1746 }
aoqi@0 1747
aoqi@0 1748 initialize_bb(); // Ensure extra info is allocated.
aoqi@0 1749
aoqi@0 1750 #ifndef PRODUCT
aoqi@0 1751 if (TraceSuperWord) {
aoqi@0 1752 print_bb();
aoqi@0 1753 tty->print_cr("\ndata entry nodes: %s", _data_entry.length() > 0 ? "" : "NONE");
aoqi@0 1754 for (int m = 0; m < _data_entry.length(); m++) {
aoqi@0 1755 tty->print("%3d ", m);
aoqi@0 1756 _data_entry.at(m)->dump();
aoqi@0 1757 }
aoqi@0 1758 tty->print_cr("\nmemory slices: %s", _mem_slice_head.length() > 0 ? "" : "NONE");
aoqi@0 1759 for (int m = 0; m < _mem_slice_head.length(); m++) {
aoqi@0 1760 tty->print("%3d ", m); _mem_slice_head.at(m)->dump();
aoqi@0 1761 tty->print(" "); _mem_slice_tail.at(m)->dump();
aoqi@0 1762 }
aoqi@0 1763 }
aoqi@0 1764 #endif
aoqi@0 1765 assert(rpo_idx == -1 && bb_ct == _block.length(), "all block members found");
aoqi@0 1766 return (_mem_slice_head.length() > 0) || (_data_entry.length() > 0);
aoqi@0 1767 }
aoqi@0 1768
aoqi@0 1769 //------------------------------initialize_bb---------------------------
aoqi@0 1770 // Initialize per node info
aoqi@0 1771 void SuperWord::initialize_bb() {
aoqi@0 1772 Node* last = _block.at(_block.length() - 1);
aoqi@0 1773 grow_node_info(bb_idx(last));
aoqi@0 1774 }
aoqi@0 1775
aoqi@0 1776 //------------------------------bb_insert_after---------------------------
aoqi@0 1777 // Insert n into block after pos
aoqi@0 1778 void SuperWord::bb_insert_after(Node* n, int pos) {
aoqi@0 1779 int n_pos = pos + 1;
aoqi@0 1780 // Make room
aoqi@0 1781 for (int i = _block.length() - 1; i >= n_pos; i--) {
aoqi@0 1782 _block.at_put_grow(i+1, _block.at(i));
aoqi@0 1783 }
aoqi@0 1784 for (int j = _node_info.length() - 1; j >= n_pos; j--) {
aoqi@0 1785 _node_info.at_put_grow(j+1, _node_info.at(j));
aoqi@0 1786 }
aoqi@0 1787 // Set value
aoqi@0 1788 _block.at_put_grow(n_pos, n);
aoqi@0 1789 _node_info.at_put_grow(n_pos, SWNodeInfo::initial);
aoqi@0 1790 // Adjust map from node->_idx to _block index
aoqi@0 1791 for (int i = n_pos; i < _block.length(); i++) {
aoqi@0 1792 set_bb_idx(_block.at(i), i);
aoqi@0 1793 }
aoqi@0 1794 }
aoqi@0 1795
aoqi@0 1796 //------------------------------compute_max_depth---------------------------
aoqi@0 1797 // Compute max depth for expressions from beginning of block
aoqi@0 1798 // Use to prune search paths during test for independence.
aoqi@0 1799 void SuperWord::compute_max_depth() {
aoqi@0 1800 int ct = 0;
aoqi@0 1801 bool again;
aoqi@0 1802 do {
aoqi@0 1803 again = false;
aoqi@0 1804 for (int i = 0; i < _block.length(); i++) {
aoqi@0 1805 Node* n = _block.at(i);
aoqi@0 1806 if (!n->is_Phi()) {
aoqi@0 1807 int d_orig = depth(n);
aoqi@0 1808 int d_in = 0;
aoqi@0 1809 for (DepPreds preds(n, _dg); !preds.done(); preds.next()) {
aoqi@0 1810 Node* pred = preds.current();
aoqi@0 1811 if (in_bb(pred)) {
aoqi@0 1812 d_in = MAX2(d_in, depth(pred));
aoqi@0 1813 }
aoqi@0 1814 }
aoqi@0 1815 if (d_in + 1 != d_orig) {
aoqi@0 1816 set_depth(n, d_in + 1);
aoqi@0 1817 again = true;
aoqi@0 1818 }
aoqi@0 1819 }
aoqi@0 1820 }
aoqi@0 1821 ct++;
aoqi@0 1822 } while (again);
aoqi@0 1823 #ifndef PRODUCT
aoqi@0 1824 if (TraceSuperWord && Verbose)
aoqi@0 1825 tty->print_cr("compute_max_depth iterated: %d times", ct);
aoqi@0 1826 #endif
aoqi@0 1827 }
aoqi@0 1828
aoqi@0 1829 //-------------------------compute_vector_element_type-----------------------
aoqi@0 1830 // Compute necessary vector element type for expressions
aoqi@0 1831 // This propagates backwards a narrower integer type when the
aoqi@0 1832 // upper bits of the value are not needed.
aoqi@0 1833 // Example: char a,b,c; a = b + c;
aoqi@0 1834 // Normally the type of the add is integer, but for packed character
aoqi@0 1835 // operations the type of the add needs to be char.
aoqi@0 1836 void SuperWord::compute_vector_element_type() {
aoqi@0 1837 #ifndef PRODUCT
aoqi@0 1838 if (TraceSuperWord && Verbose)
aoqi@0 1839 tty->print_cr("\ncompute_velt_type:");
aoqi@0 1840 #endif
aoqi@0 1841
aoqi@0 1842 // Initial type
aoqi@0 1843 for (int i = 0; i < _block.length(); i++) {
aoqi@0 1844 Node* n = _block.at(i);
aoqi@0 1845 set_velt_type(n, container_type(n));
aoqi@0 1846 }
aoqi@0 1847
aoqi@0 1848 // Propagate integer narrowed type backwards through operations
aoqi@0 1849 // that don't depend on higher order bits
aoqi@0 1850 for (int i = _block.length() - 1; i >= 0; i--) {
aoqi@0 1851 Node* n = _block.at(i);
aoqi@0 1852 // Only integer types need be examined
aoqi@0 1853 const Type* vtn = velt_type(n);
aoqi@0 1854 if (vtn->basic_type() == T_INT) {
aoqi@0 1855 uint start, end;
aoqi@0 1856 VectorNode::vector_operands(n, &start, &end);
aoqi@0 1857
aoqi@0 1858 for (uint j = start; j < end; j++) {
aoqi@0 1859 Node* in = n->in(j);
aoqi@0 1860 // Don't propagate through a memory
aoqi@0 1861 if (!in->is_Mem() && in_bb(in) && velt_type(in)->basic_type() == T_INT &&
aoqi@0 1862 data_size(n) < data_size(in)) {
aoqi@0 1863 bool same_type = true;
aoqi@0 1864 for (DUIterator_Fast kmax, k = in->fast_outs(kmax); k < kmax; k++) {
aoqi@0 1865 Node *use = in->fast_out(k);
aoqi@0 1866 if (!in_bb(use) || !same_velt_type(use, n)) {
aoqi@0 1867 same_type = false;
aoqi@0 1868 break;
aoqi@0 1869 }
aoqi@0 1870 }
aoqi@0 1871 if (same_type) {
aoqi@0 1872 // For right shifts of small integer types (bool, byte, char, short)
aoqi@0 1873 // we need precise information about sign-ness. Only Load nodes have
aoqi@0 1874 // this information because Store nodes are the same for signed and
aoqi@0 1875 // unsigned values. And any arithmetic operation after a load may
aoqi@0 1876 // expand a value to signed Int so such right shifts can't be used
aoqi@0 1877 // because vector elements do not have upper bits of Int.
aoqi@0 1878 const Type* vt = vtn;
aoqi@0 1879 if (VectorNode::is_shift(in)) {
aoqi@0 1880 Node* load = in->in(1);
aoqi@0 1881 if (load->is_Load() && in_bb(load) && (velt_type(load)->basic_type() == T_INT)) {
aoqi@0 1882 vt = velt_type(load);
aoqi@0 1883 } else if (in->Opcode() != Op_LShiftI) {
aoqi@0 1884 // Widen type to Int to avoid creation of right shift vector
aoqi@0 1885 // (align + data_size(s1) check in stmts_can_pack() will fail).
aoqi@0 1886 // Note, left shifts work regardless type.
aoqi@0 1887 vt = TypeInt::INT;
aoqi@0 1888 }
aoqi@0 1889 }
aoqi@0 1890 set_velt_type(in, vt);
aoqi@0 1891 }
aoqi@0 1892 }
aoqi@0 1893 }
aoqi@0 1894 }
aoqi@0 1895 }
aoqi@0 1896 #ifndef PRODUCT
aoqi@0 1897 if (TraceSuperWord && Verbose) {
aoqi@0 1898 for (int i = 0; i < _block.length(); i++) {
aoqi@0 1899 Node* n = _block.at(i);
aoqi@0 1900 velt_type(n)->dump();
aoqi@0 1901 tty->print("\t");
aoqi@0 1902 n->dump();
aoqi@0 1903 }
aoqi@0 1904 }
aoqi@0 1905 #endif
aoqi@0 1906 }
aoqi@0 1907
aoqi@0 1908 //------------------------------memory_alignment---------------------------
aoqi@0 1909 // Alignment within a vector memory reference
aoqi@0 1910 int SuperWord::memory_alignment(MemNode* s, int iv_adjust) {
aoqi@0 1911 SWPointer p(s, this);
aoqi@0 1912 if (!p.valid()) {
aoqi@0 1913 return bottom_align;
aoqi@0 1914 }
aoqi@0 1915 int vw = vector_width_in_bytes(s);
aoqi@0 1916 if (vw < 2) {
aoqi@0 1917 return bottom_align; // No vectors for this type
aoqi@0 1918 }
aoqi@0 1919 int offset = p.offset_in_bytes();
aoqi@0 1920 offset += iv_adjust*p.memory_size();
aoqi@0 1921 int off_rem = offset % vw;
aoqi@0 1922 int off_mod = off_rem >= 0 ? off_rem : off_rem + vw;
aoqi@0 1923 return off_mod;
aoqi@0 1924 }
aoqi@0 1925
aoqi@0 1926 //---------------------------container_type---------------------------
aoqi@0 1927 // Smallest type containing range of values
aoqi@0 1928 const Type* SuperWord::container_type(Node* n) {
aoqi@0 1929 if (n->is_Mem()) {
aoqi@0 1930 BasicType bt = n->as_Mem()->memory_type();
aoqi@0 1931 if (n->is_Store() && (bt == T_CHAR)) {
aoqi@0 1932 // Use T_SHORT type instead of T_CHAR for stored values because any
aoqi@0 1933 // preceding arithmetic operation extends values to signed Int.
aoqi@0 1934 bt = T_SHORT;
aoqi@0 1935 }
aoqi@0 1936 if (n->Opcode() == Op_LoadUB) {
aoqi@0 1937 // Adjust type for unsigned byte loads, it is important for right shifts.
aoqi@0 1938 // T_BOOLEAN is used because there is no basic type representing type
aoqi@0 1939 // TypeInt::UBYTE. Use of T_BOOLEAN for vectors is fine because only
aoqi@0 1940 // size (one byte) and sign is important.
aoqi@0 1941 bt = T_BOOLEAN;
aoqi@0 1942 }
aoqi@0 1943 return Type::get_const_basic_type(bt);
aoqi@0 1944 }
aoqi@0 1945 const Type* t = _igvn.type(n);
aoqi@0 1946 if (t->basic_type() == T_INT) {
aoqi@0 1947 // A narrow type of arithmetic operations will be determined by
aoqi@0 1948 // propagating the type of memory operations.
aoqi@0 1949 return TypeInt::INT;
aoqi@0 1950 }
aoqi@0 1951 return t;
aoqi@0 1952 }
aoqi@0 1953
aoqi@0 1954 bool SuperWord::same_velt_type(Node* n1, Node* n2) {
aoqi@0 1955 const Type* vt1 = velt_type(n1);
aoqi@0 1956 const Type* vt2 = velt_type(n2);
aoqi@0 1957 if (vt1->basic_type() == T_INT && vt2->basic_type() == T_INT) {
aoqi@0 1958 // Compare vectors element sizes for integer types.
aoqi@0 1959 return data_size(n1) == data_size(n2);
aoqi@0 1960 }
aoqi@0 1961 return vt1 == vt2;
aoqi@0 1962 }
aoqi@0 1963
aoqi@0 1964 //------------------------------in_packset---------------------------
aoqi@0 1965 // Are s1 and s2 in a pack pair and ordered as s1,s2?
aoqi@0 1966 bool SuperWord::in_packset(Node* s1, Node* s2) {
aoqi@0 1967 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 1968 Node_List* p = _packset.at(i);
aoqi@0 1969 assert(p->size() == 2, "must be");
aoqi@0 1970 if (p->at(0) == s1 && p->at(p->size()-1) == s2) {
aoqi@0 1971 return true;
aoqi@0 1972 }
aoqi@0 1973 }
aoqi@0 1974 return false;
aoqi@0 1975 }
aoqi@0 1976
aoqi@0 1977 //------------------------------in_pack---------------------------
aoqi@0 1978 // Is s in pack p?
aoqi@0 1979 Node_List* SuperWord::in_pack(Node* s, Node_List* p) {
aoqi@0 1980 for (uint i = 0; i < p->size(); i++) {
aoqi@0 1981 if (p->at(i) == s) {
aoqi@0 1982 return p;
aoqi@0 1983 }
aoqi@0 1984 }
aoqi@0 1985 return NULL;
aoqi@0 1986 }
aoqi@0 1987
aoqi@0 1988 //------------------------------remove_pack_at---------------------------
aoqi@0 1989 // Remove the pack at position pos in the packset
aoqi@0 1990 void SuperWord::remove_pack_at(int pos) {
aoqi@0 1991 Node_List* p = _packset.at(pos);
aoqi@0 1992 for (uint i = 0; i < p->size(); i++) {
aoqi@0 1993 Node* s = p->at(i);
aoqi@0 1994 set_my_pack(s, NULL);
aoqi@0 1995 }
aoqi@0 1996 _packset.remove_at(pos);
aoqi@0 1997 }
aoqi@0 1998
aoqi@0 1999 //------------------------------executed_first---------------------------
aoqi@0 2000 // Return the node executed first in pack p. Uses the RPO block list
aoqi@0 2001 // to determine order.
aoqi@0 2002 Node* SuperWord::executed_first(Node_List* p) {
aoqi@0 2003 Node* n = p->at(0);
aoqi@0 2004 int n_rpo = bb_idx(n);
aoqi@0 2005 for (uint i = 1; i < p->size(); i++) {
aoqi@0 2006 Node* s = p->at(i);
aoqi@0 2007 int s_rpo = bb_idx(s);
aoqi@0 2008 if (s_rpo < n_rpo) {
aoqi@0 2009 n = s;
aoqi@0 2010 n_rpo = s_rpo;
aoqi@0 2011 }
aoqi@0 2012 }
aoqi@0 2013 return n;
aoqi@0 2014 }
aoqi@0 2015
aoqi@0 2016 //------------------------------executed_last---------------------------
aoqi@0 2017 // Return the node executed last in pack p.
aoqi@0 2018 Node* SuperWord::executed_last(Node_List* p) {
aoqi@0 2019 Node* n = p->at(0);
aoqi@0 2020 int n_rpo = bb_idx(n);
aoqi@0 2021 for (uint i = 1; i < p->size(); i++) {
aoqi@0 2022 Node* s = p->at(i);
aoqi@0 2023 int s_rpo = bb_idx(s);
aoqi@0 2024 if (s_rpo > n_rpo) {
aoqi@0 2025 n = s;
aoqi@0 2026 n_rpo = s_rpo;
aoqi@0 2027 }
aoqi@0 2028 }
aoqi@0 2029 return n;
aoqi@0 2030 }
aoqi@0 2031
roland@7859 2032 LoadNode::ControlDependency SuperWord::control_dependency(Node_List* p) {
roland@7859 2033 LoadNode::ControlDependency dep = LoadNode::DependsOnlyOnTest;
roland@7859 2034 for (uint i = 0; i < p->size(); i++) {
roland@7859 2035 Node* n = p->at(i);
roland@7859 2036 assert(n->is_Load(), "only meaningful for loads");
roland@7859 2037 if (!n->depends_only_on_test()) {
roland@7859 2038 dep = LoadNode::Pinned;
roland@7859 2039 }
roland@7859 2040 }
roland@7859 2041 return dep;
roland@7859 2042 }
roland@7859 2043
roland@7859 2044
aoqi@0 2045 //----------------------------align_initial_loop_index---------------------------
aoqi@0 2046 // Adjust pre-loop limit so that in main loop, a load/store reference
aoqi@0 2047 // to align_to_ref will be a position zero in the vector.
aoqi@0 2048 // (iv + k) mod vector_align == 0
aoqi@0 2049 void SuperWord::align_initial_loop_index(MemNode* align_to_ref) {
aoqi@0 2050 CountedLoopNode *main_head = lp()->as_CountedLoop();
aoqi@0 2051 assert(main_head->is_main_loop(), "");
aoqi@0 2052 CountedLoopEndNode* pre_end = get_pre_loop_end(main_head);
aoqi@0 2053 assert(pre_end != NULL, "");
aoqi@0 2054 Node *pre_opaq1 = pre_end->limit();
aoqi@0 2055 assert(pre_opaq1->Opcode() == Op_Opaque1, "");
aoqi@0 2056 Opaque1Node *pre_opaq = (Opaque1Node*)pre_opaq1;
aoqi@0 2057 Node *lim0 = pre_opaq->in(1);
aoqi@0 2058
aoqi@0 2059 // Where we put new limit calculations
aoqi@0 2060 Node *pre_ctrl = pre_end->loopnode()->in(LoopNode::EntryControl);
aoqi@0 2061
aoqi@0 2062 // Ensure the original loop limit is available from the
aoqi@0 2063 // pre-loop Opaque1 node.
aoqi@0 2064 Node *orig_limit = pre_opaq->original_loop_limit();
aoqi@0 2065 assert(orig_limit != NULL && _igvn.type(orig_limit) != Type::TOP, "");
aoqi@0 2066
aoqi@0 2067 SWPointer align_to_ref_p(align_to_ref, this);
aoqi@0 2068 assert(align_to_ref_p.valid(), "sanity");
aoqi@0 2069
aoqi@0 2070 // Given:
aoqi@0 2071 // lim0 == original pre loop limit
aoqi@0 2072 // V == v_align (power of 2)
aoqi@0 2073 // invar == extra invariant piece of the address expression
aoqi@0 2074 // e == offset [ +/- invar ]
aoqi@0 2075 //
aoqi@0 2076 // When reassociating expressions involving '%' the basic rules are:
aoqi@0 2077 // (a - b) % k == 0 => a % k == b % k
aoqi@0 2078 // and:
aoqi@0 2079 // (a + b) % k == 0 => a % k == (k - b) % k
aoqi@0 2080 //
aoqi@0 2081 // For stride > 0 && scale > 0,
aoqi@0 2082 // Derive the new pre-loop limit "lim" such that the two constraints:
aoqi@0 2083 // (1) lim = lim0 + N (where N is some positive integer < V)
aoqi@0 2084 // (2) (e + lim) % V == 0
aoqi@0 2085 // are true.
aoqi@0 2086 //
aoqi@0 2087 // Substituting (1) into (2),
aoqi@0 2088 // (e + lim0 + N) % V == 0
aoqi@0 2089 // solve for N:
aoqi@0 2090 // N = (V - (e + lim0)) % V
aoqi@0 2091 // substitute back into (1), so that new limit
aoqi@0 2092 // lim = lim0 + (V - (e + lim0)) % V
aoqi@0 2093 //
aoqi@0 2094 // For stride > 0 && scale < 0
aoqi@0 2095 // Constraints:
aoqi@0 2096 // lim = lim0 + N
aoqi@0 2097 // (e - lim) % V == 0
aoqi@0 2098 // Solving for lim:
aoqi@0 2099 // (e - lim0 - N) % V == 0
aoqi@0 2100 // N = (e - lim0) % V
aoqi@0 2101 // lim = lim0 + (e - lim0) % V
aoqi@0 2102 //
aoqi@0 2103 // For stride < 0 && scale > 0
aoqi@0 2104 // Constraints:
aoqi@0 2105 // lim = lim0 - N
aoqi@0 2106 // (e + lim) % V == 0
aoqi@0 2107 // Solving for lim:
aoqi@0 2108 // (e + lim0 - N) % V == 0
aoqi@0 2109 // N = (e + lim0) % V
aoqi@0 2110 // lim = lim0 - (e + lim0) % V
aoqi@0 2111 //
aoqi@0 2112 // For stride < 0 && scale < 0
aoqi@0 2113 // Constraints:
aoqi@0 2114 // lim = lim0 - N
aoqi@0 2115 // (e - lim) % V == 0
aoqi@0 2116 // Solving for lim:
aoqi@0 2117 // (e - lim0 + N) % V == 0
aoqi@0 2118 // N = (V - (e - lim0)) % V
aoqi@0 2119 // lim = lim0 - (V - (e - lim0)) % V
aoqi@0 2120
aoqi@0 2121 int vw = vector_width_in_bytes(align_to_ref);
aoqi@0 2122 int stride = iv_stride();
aoqi@0 2123 int scale = align_to_ref_p.scale_in_bytes();
aoqi@0 2124 int elt_size = align_to_ref_p.memory_size();
aoqi@0 2125 int v_align = vw / elt_size;
aoqi@0 2126 assert(v_align > 1, "sanity");
aoqi@0 2127 int offset = align_to_ref_p.offset_in_bytes() / elt_size;
aoqi@0 2128 Node *offsn = _igvn.intcon(offset);
aoqi@0 2129
aoqi@0 2130 Node *e = offsn;
aoqi@0 2131 if (align_to_ref_p.invar() != NULL) {
aoqi@0 2132 // incorporate any extra invariant piece producing (offset +/- invar) >>> log2(elt)
aoqi@0 2133 Node* log2_elt = _igvn.intcon(exact_log2(elt_size));
aoqi@0 2134 Node* aref = new (_phase->C) URShiftINode(align_to_ref_p.invar(), log2_elt);
aoqi@0 2135 _igvn.register_new_node_with_optimizer(aref);
aoqi@0 2136 _phase->set_ctrl(aref, pre_ctrl);
aoqi@0 2137 if (align_to_ref_p.negate_invar()) {
aoqi@0 2138 e = new (_phase->C) SubINode(e, aref);
aoqi@0 2139 } else {
aoqi@0 2140 e = new (_phase->C) AddINode(e, aref);
aoqi@0 2141 }
aoqi@0 2142 _igvn.register_new_node_with_optimizer(e);
aoqi@0 2143 _phase->set_ctrl(e, pre_ctrl);
aoqi@0 2144 }
aoqi@0 2145 if (vw > ObjectAlignmentInBytes) {
aoqi@0 2146 // incorporate base e +/- base && Mask >>> log2(elt)
aoqi@0 2147 Node* xbase = new(_phase->C) CastP2XNode(NULL, align_to_ref_p.base());
aoqi@0 2148 _igvn.register_new_node_with_optimizer(xbase);
aoqi@0 2149 #ifdef _LP64
aoqi@0 2150 xbase = new (_phase->C) ConvL2INode(xbase);
aoqi@0 2151 _igvn.register_new_node_with_optimizer(xbase);
aoqi@0 2152 #endif
aoqi@0 2153 Node* mask = _igvn.intcon(vw-1);
aoqi@0 2154 Node* masked_xbase = new (_phase->C) AndINode(xbase, mask);
aoqi@0 2155 _igvn.register_new_node_with_optimizer(masked_xbase);
aoqi@0 2156 Node* log2_elt = _igvn.intcon(exact_log2(elt_size));
aoqi@0 2157 Node* bref = new (_phase->C) URShiftINode(masked_xbase, log2_elt);
aoqi@0 2158 _igvn.register_new_node_with_optimizer(bref);
aoqi@0 2159 _phase->set_ctrl(bref, pre_ctrl);
aoqi@0 2160 e = new (_phase->C) AddINode(e, bref);
aoqi@0 2161 _igvn.register_new_node_with_optimizer(e);
aoqi@0 2162 _phase->set_ctrl(e, pre_ctrl);
aoqi@0 2163 }
aoqi@0 2164
aoqi@0 2165 // compute e +/- lim0
aoqi@0 2166 if (scale < 0) {
aoqi@0 2167 e = new (_phase->C) SubINode(e, lim0);
aoqi@0 2168 } else {
aoqi@0 2169 e = new (_phase->C) AddINode(e, lim0);
aoqi@0 2170 }
aoqi@0 2171 _igvn.register_new_node_with_optimizer(e);
aoqi@0 2172 _phase->set_ctrl(e, pre_ctrl);
aoqi@0 2173
aoqi@0 2174 if (stride * scale > 0) {
aoqi@0 2175 // compute V - (e +/- lim0)
aoqi@0 2176 Node* va = _igvn.intcon(v_align);
aoqi@0 2177 e = new (_phase->C) SubINode(va, e);
aoqi@0 2178 _igvn.register_new_node_with_optimizer(e);
aoqi@0 2179 _phase->set_ctrl(e, pre_ctrl);
aoqi@0 2180 }
aoqi@0 2181 // compute N = (exp) % V
aoqi@0 2182 Node* va_msk = _igvn.intcon(v_align - 1);
aoqi@0 2183 Node* N = new (_phase->C) AndINode(e, va_msk);
aoqi@0 2184 _igvn.register_new_node_with_optimizer(N);
aoqi@0 2185 _phase->set_ctrl(N, pre_ctrl);
aoqi@0 2186
aoqi@0 2187 // substitute back into (1), so that new limit
aoqi@0 2188 // lim = lim0 + N
aoqi@0 2189 Node* lim;
aoqi@0 2190 if (stride < 0) {
aoqi@0 2191 lim = new (_phase->C) SubINode(lim0, N);
aoqi@0 2192 } else {
aoqi@0 2193 lim = new (_phase->C) AddINode(lim0, N);
aoqi@0 2194 }
aoqi@0 2195 _igvn.register_new_node_with_optimizer(lim);
aoqi@0 2196 _phase->set_ctrl(lim, pre_ctrl);
aoqi@0 2197 Node* constrained =
aoqi@0 2198 (stride > 0) ? (Node*) new (_phase->C) MinINode(lim, orig_limit)
aoqi@0 2199 : (Node*) new (_phase->C) MaxINode(lim, orig_limit);
aoqi@0 2200 _igvn.register_new_node_with_optimizer(constrained);
aoqi@0 2201 _phase->set_ctrl(constrained, pre_ctrl);
aoqi@0 2202 _igvn.hash_delete(pre_opaq);
aoqi@0 2203 pre_opaq->set_req(1, constrained);
aoqi@0 2204 }
aoqi@0 2205
aoqi@0 2206 //----------------------------get_pre_loop_end---------------------------
aoqi@0 2207 // Find pre loop end from main loop. Returns null if none.
aoqi@0 2208 CountedLoopEndNode* SuperWord::get_pre_loop_end(CountedLoopNode *cl) {
aoqi@0 2209 Node *ctrl = cl->in(LoopNode::EntryControl);
aoqi@0 2210 if (!ctrl->is_IfTrue() && !ctrl->is_IfFalse()) return NULL;
aoqi@0 2211 Node *iffm = ctrl->in(0);
aoqi@0 2212 if (!iffm->is_If()) return NULL;
aoqi@0 2213 Node *p_f = iffm->in(0);
aoqi@0 2214 if (!p_f->is_IfFalse()) return NULL;
aoqi@0 2215 if (!p_f->in(0)->is_CountedLoopEnd()) return NULL;
aoqi@0 2216 CountedLoopEndNode *pre_end = p_f->in(0)->as_CountedLoopEnd();
aoqi@0 2217 if (!pre_end->loopnode()->is_pre_loop()) return NULL;
aoqi@0 2218 return pre_end;
aoqi@0 2219 }
aoqi@0 2220
aoqi@0 2221
aoqi@0 2222 //------------------------------init---------------------------
aoqi@0 2223 void SuperWord::init() {
aoqi@0 2224 _dg.init();
aoqi@0 2225 _packset.clear();
aoqi@0 2226 _disjoint_ptrs.clear();
aoqi@0 2227 _block.clear();
aoqi@0 2228 _data_entry.clear();
aoqi@0 2229 _mem_slice_head.clear();
aoqi@0 2230 _mem_slice_tail.clear();
aoqi@0 2231 _node_info.clear();
aoqi@0 2232 _align_to_ref = NULL;
aoqi@0 2233 _lpt = NULL;
aoqi@0 2234 _lp = NULL;
aoqi@0 2235 _bb = NULL;
aoqi@0 2236 _iv = NULL;
aoqi@0 2237 }
aoqi@0 2238
aoqi@0 2239 //------------------------------print_packset---------------------------
aoqi@0 2240 void SuperWord::print_packset() {
aoqi@0 2241 #ifndef PRODUCT
aoqi@0 2242 tty->print_cr("packset");
aoqi@0 2243 for (int i = 0; i < _packset.length(); i++) {
aoqi@0 2244 tty->print_cr("Pack: %d", i);
aoqi@0 2245 Node_List* p = _packset.at(i);
aoqi@0 2246 print_pack(p);
aoqi@0 2247 }
aoqi@0 2248 #endif
aoqi@0 2249 }
aoqi@0 2250
aoqi@0 2251 //------------------------------print_pack---------------------------
aoqi@0 2252 void SuperWord::print_pack(Node_List* p) {
aoqi@0 2253 for (uint i = 0; i < p->size(); i++) {
aoqi@0 2254 print_stmt(p->at(i));
aoqi@0 2255 }
aoqi@0 2256 }
aoqi@0 2257
aoqi@0 2258 //------------------------------print_bb---------------------------
aoqi@0 2259 void SuperWord::print_bb() {
aoqi@0 2260 #ifndef PRODUCT
aoqi@0 2261 tty->print_cr("\nBlock");
aoqi@0 2262 for (int i = 0; i < _block.length(); i++) {
aoqi@0 2263 Node* n = _block.at(i);
aoqi@0 2264 tty->print("%d ", i);
aoqi@0 2265 if (n) {
aoqi@0 2266 n->dump();
aoqi@0 2267 }
aoqi@0 2268 }
aoqi@0 2269 #endif
aoqi@0 2270 }
aoqi@0 2271
aoqi@0 2272 //------------------------------print_stmt---------------------------
aoqi@0 2273 void SuperWord::print_stmt(Node* s) {
aoqi@0 2274 #ifndef PRODUCT
aoqi@0 2275 tty->print(" align: %d \t", alignment(s));
aoqi@0 2276 s->dump();
aoqi@0 2277 #endif
aoqi@0 2278 }
aoqi@0 2279
aoqi@0 2280 //------------------------------blank---------------------------
aoqi@0 2281 char* SuperWord::blank(uint depth) {
aoqi@0 2282 static char blanks[101];
aoqi@0 2283 assert(depth < 101, "too deep");
aoqi@0 2284 for (uint i = 0; i < depth; i++) blanks[i] = ' ';
aoqi@0 2285 blanks[depth] = '\0';
aoqi@0 2286 return blanks;
aoqi@0 2287 }
aoqi@0 2288
aoqi@0 2289
aoqi@0 2290 //==============================SWPointer===========================
aoqi@0 2291
aoqi@0 2292 //----------------------------SWPointer------------------------
aoqi@0 2293 SWPointer::SWPointer(MemNode* mem, SuperWord* slp) :
aoqi@0 2294 _mem(mem), _slp(slp), _base(NULL), _adr(NULL),
aoqi@0 2295 _scale(0), _offset(0), _invar(NULL), _negate_invar(false) {
aoqi@0 2296
aoqi@0 2297 Node* adr = mem->in(MemNode::Address);
aoqi@0 2298 if (!adr->is_AddP()) {
aoqi@0 2299 assert(!valid(), "too complex");
aoqi@0 2300 return;
aoqi@0 2301 }
aoqi@0 2302 // Match AddP(base, AddP(ptr, k*iv [+ invariant]), constant)
aoqi@0 2303 Node* base = adr->in(AddPNode::Base);
thartmann@7818 2304 // The base address should be loop invariant
thartmann@7818 2305 if (!invariant(base)) {
thartmann@7818 2306 assert(!valid(), "base address is loop variant");
thartmann@7818 2307 return;
thartmann@7818 2308 }
aoqi@0 2309 //unsafe reference could not be aligned appropriately without runtime checking
aoqi@0 2310 if (base == NULL || base->bottom_type() == Type::TOP) {
aoqi@0 2311 assert(!valid(), "unsafe access");
aoqi@0 2312 return;
aoqi@0 2313 }
aoqi@0 2314 for (int i = 0; i < 3; i++) {
aoqi@0 2315 if (!scaled_iv_plus_offset(adr->in(AddPNode::Offset))) {
aoqi@0 2316 assert(!valid(), "too complex");
aoqi@0 2317 return;
aoqi@0 2318 }
aoqi@0 2319 adr = adr->in(AddPNode::Address);
aoqi@0 2320 if (base == adr || !adr->is_AddP()) {
aoqi@0 2321 break; // stop looking at addp's
aoqi@0 2322 }
aoqi@0 2323 }
aoqi@0 2324 _base = base;
aoqi@0 2325 _adr = adr;
aoqi@0 2326 assert(valid(), "Usable");
aoqi@0 2327 }
aoqi@0 2328
aoqi@0 2329 // Following is used to create a temporary object during
aoqi@0 2330 // the pattern match of an address expression.
aoqi@0 2331 SWPointer::SWPointer(SWPointer* p) :
aoqi@0 2332 _mem(p->_mem), _slp(p->_slp), _base(NULL), _adr(NULL),
aoqi@0 2333 _scale(0), _offset(0), _invar(NULL), _negate_invar(false) {}
aoqi@0 2334
aoqi@0 2335 //------------------------scaled_iv_plus_offset--------------------
aoqi@0 2336 // Match: k*iv + offset
aoqi@0 2337 // where: k is a constant that maybe zero, and
aoqi@0 2338 // offset is (k2 [+/- invariant]) where k2 maybe zero and invariant is optional
aoqi@0 2339 bool SWPointer::scaled_iv_plus_offset(Node* n) {
aoqi@0 2340 if (scaled_iv(n)) {
aoqi@0 2341 return true;
aoqi@0 2342 }
aoqi@0 2343 if (offset_plus_k(n)) {
aoqi@0 2344 return true;
aoqi@0 2345 }
aoqi@0 2346 int opc = n->Opcode();
aoqi@0 2347 if (opc == Op_AddI) {
aoqi@0 2348 if (scaled_iv(n->in(1)) && offset_plus_k(n->in(2))) {
aoqi@0 2349 return true;
aoqi@0 2350 }
aoqi@0 2351 if (scaled_iv(n->in(2)) && offset_plus_k(n->in(1))) {
aoqi@0 2352 return true;
aoqi@0 2353 }
aoqi@0 2354 } else if (opc == Op_SubI) {
aoqi@0 2355 if (scaled_iv(n->in(1)) && offset_plus_k(n->in(2), true)) {
aoqi@0 2356 return true;
aoqi@0 2357 }
aoqi@0 2358 if (scaled_iv(n->in(2)) && offset_plus_k(n->in(1))) {
aoqi@0 2359 _scale *= -1;
aoqi@0 2360 return true;
aoqi@0 2361 }
aoqi@0 2362 }
aoqi@0 2363 return false;
aoqi@0 2364 }
aoqi@0 2365
aoqi@0 2366 //----------------------------scaled_iv------------------------
aoqi@0 2367 // Match: k*iv where k is a constant that's not zero
aoqi@0 2368 bool SWPointer::scaled_iv(Node* n) {
aoqi@0 2369 if (_scale != 0) {
aoqi@0 2370 return false; // already found a scale
aoqi@0 2371 }
aoqi@0 2372 if (n == iv()) {
aoqi@0 2373 _scale = 1;
aoqi@0 2374 return true;
aoqi@0 2375 }
aoqi@0 2376 int opc = n->Opcode();
aoqi@0 2377 if (opc == Op_MulI) {
aoqi@0 2378 if (n->in(1) == iv() && n->in(2)->is_Con()) {
aoqi@0 2379 _scale = n->in(2)->get_int();
aoqi@0 2380 return true;
aoqi@0 2381 } else if (n->in(2) == iv() && n->in(1)->is_Con()) {
aoqi@0 2382 _scale = n->in(1)->get_int();
aoqi@0 2383 return true;
aoqi@0 2384 }
aoqi@0 2385 } else if (opc == Op_LShiftI) {
aoqi@0 2386 if (n->in(1) == iv() && n->in(2)->is_Con()) {
aoqi@0 2387 _scale = 1 << n->in(2)->get_int();
aoqi@0 2388 return true;
aoqi@0 2389 }
aoqi@0 2390 } else if (opc == Op_ConvI2L) {
thartmann@8285 2391 if (n->in(1)->Opcode() == Op_CastII &&
thartmann@8285 2392 n->in(1)->as_CastII()->has_range_check()) {
thartmann@8285 2393 // Skip range check dependent CastII nodes
thartmann@8285 2394 n = n->in(1);
thartmann@8285 2395 }
aoqi@0 2396 if (scaled_iv_plus_offset(n->in(1))) {
aoqi@0 2397 return true;
aoqi@0 2398 }
aoqi@0 2399 } else if (opc == Op_LShiftL) {
aoqi@0 2400 if (!has_iv() && _invar == NULL) {
aoqi@0 2401 // Need to preserve the current _offset value, so
aoqi@0 2402 // create a temporary object for this expression subtree.
aoqi@0 2403 // Hacky, so should re-engineer the address pattern match.
aoqi@0 2404 SWPointer tmp(this);
aoqi@0 2405 if (tmp.scaled_iv_plus_offset(n->in(1))) {
aoqi@0 2406 if (tmp._invar == NULL) {
aoqi@0 2407 int mult = 1 << n->in(2)->get_int();
aoqi@0 2408 _scale = tmp._scale * mult;
aoqi@0 2409 _offset += tmp._offset * mult;
aoqi@0 2410 return true;
aoqi@0 2411 }
aoqi@0 2412 }
aoqi@0 2413 }
aoqi@0 2414 }
aoqi@0 2415 return false;
aoqi@0 2416 }
aoqi@0 2417
aoqi@0 2418 //----------------------------offset_plus_k------------------------
aoqi@0 2419 // Match: offset is (k [+/- invariant])
aoqi@0 2420 // where k maybe zero and invariant is optional, but not both.
aoqi@0 2421 bool SWPointer::offset_plus_k(Node* n, bool negate) {
aoqi@0 2422 int opc = n->Opcode();
aoqi@0 2423 if (opc == Op_ConI) {
aoqi@0 2424 _offset += negate ? -(n->get_int()) : n->get_int();
aoqi@0 2425 return true;
aoqi@0 2426 } else if (opc == Op_ConL) {
aoqi@0 2427 // Okay if value fits into an int
aoqi@0 2428 const TypeLong* t = n->find_long_type();
aoqi@0 2429 if (t->higher_equal(TypeLong::INT)) {
aoqi@0 2430 jlong loff = n->get_long();
aoqi@0 2431 jint off = (jint)loff;
aoqi@0 2432 _offset += negate ? -off : loff;
aoqi@0 2433 return true;
aoqi@0 2434 }
aoqi@0 2435 return false;
aoqi@0 2436 }
aoqi@0 2437 if (_invar != NULL) return false; // already have an invariant
aoqi@0 2438 if (opc == Op_AddI) {
aoqi@0 2439 if (n->in(2)->is_Con() && invariant(n->in(1))) {
aoqi@0 2440 _negate_invar = negate;
aoqi@0 2441 _invar = n->in(1);
aoqi@0 2442 _offset += negate ? -(n->in(2)->get_int()) : n->in(2)->get_int();
aoqi@0 2443 return true;
aoqi@0 2444 } else if (n->in(1)->is_Con() && invariant(n->in(2))) {
aoqi@0 2445 _offset += negate ? -(n->in(1)->get_int()) : n->in(1)->get_int();
aoqi@0 2446 _negate_invar = negate;
aoqi@0 2447 _invar = n->in(2);
aoqi@0 2448 return true;
aoqi@0 2449 }
aoqi@0 2450 }
aoqi@0 2451 if (opc == Op_SubI) {
aoqi@0 2452 if (n->in(2)->is_Con() && invariant(n->in(1))) {
aoqi@0 2453 _negate_invar = negate;
aoqi@0 2454 _invar = n->in(1);
aoqi@0 2455 _offset += !negate ? -(n->in(2)->get_int()) : n->in(2)->get_int();
aoqi@0 2456 return true;
aoqi@0 2457 } else if (n->in(1)->is_Con() && invariant(n->in(2))) {
aoqi@0 2458 _offset += negate ? -(n->in(1)->get_int()) : n->in(1)->get_int();
aoqi@0 2459 _negate_invar = !negate;
aoqi@0 2460 _invar = n->in(2);
aoqi@0 2461 return true;
aoqi@0 2462 }
aoqi@0 2463 }
aoqi@0 2464 if (invariant(n)) {
aoqi@0 2465 _negate_invar = negate;
aoqi@0 2466 _invar = n;
aoqi@0 2467 return true;
aoqi@0 2468 }
aoqi@0 2469 return false;
aoqi@0 2470 }
aoqi@0 2471
aoqi@0 2472 //----------------------------print------------------------
aoqi@0 2473 void SWPointer::print() {
aoqi@0 2474 #ifndef PRODUCT
aoqi@0 2475 tty->print("base: %d adr: %d scale: %d offset: %d invar: %c%d\n",
aoqi@0 2476 _base != NULL ? _base->_idx : 0,
aoqi@0 2477 _adr != NULL ? _adr->_idx : 0,
aoqi@0 2478 _scale, _offset,
aoqi@0 2479 _negate_invar?'-':'+',
aoqi@0 2480 _invar != NULL ? _invar->_idx : 0);
aoqi@0 2481 #endif
aoqi@0 2482 }
aoqi@0 2483
aoqi@0 2484 // ========================= OrderedPair =====================
aoqi@0 2485
aoqi@0 2486 const OrderedPair OrderedPair::initial;
aoqi@0 2487
aoqi@0 2488 // ========================= SWNodeInfo =====================
aoqi@0 2489
aoqi@0 2490 const SWNodeInfo SWNodeInfo::initial;
aoqi@0 2491
aoqi@0 2492
aoqi@0 2493 // ============================ DepGraph ===========================
aoqi@0 2494
aoqi@0 2495 //------------------------------make_node---------------------------
aoqi@0 2496 // Make a new dependence graph node for an ideal node.
aoqi@0 2497 DepMem* DepGraph::make_node(Node* node) {
aoqi@0 2498 DepMem* m = new (_arena) DepMem(node);
aoqi@0 2499 if (node != NULL) {
aoqi@0 2500 assert(_map.at_grow(node->_idx) == NULL, "one init only");
aoqi@0 2501 _map.at_put_grow(node->_idx, m);
aoqi@0 2502 }
aoqi@0 2503 return m;
aoqi@0 2504 }
aoqi@0 2505
aoqi@0 2506 //------------------------------make_edge---------------------------
aoqi@0 2507 // Make a new dependence graph edge from dpred -> dsucc
aoqi@0 2508 DepEdge* DepGraph::make_edge(DepMem* dpred, DepMem* dsucc) {
aoqi@0 2509 DepEdge* e = new (_arena) DepEdge(dpred, dsucc, dsucc->in_head(), dpred->out_head());
aoqi@0 2510 dpred->set_out_head(e);
aoqi@0 2511 dsucc->set_in_head(e);
aoqi@0 2512 return e;
aoqi@0 2513 }
aoqi@0 2514
aoqi@0 2515 // ========================== DepMem ========================
aoqi@0 2516
aoqi@0 2517 //------------------------------in_cnt---------------------------
aoqi@0 2518 int DepMem::in_cnt() {
aoqi@0 2519 int ct = 0;
aoqi@0 2520 for (DepEdge* e = _in_head; e != NULL; e = e->next_in()) ct++;
aoqi@0 2521 return ct;
aoqi@0 2522 }
aoqi@0 2523
aoqi@0 2524 //------------------------------out_cnt---------------------------
aoqi@0 2525 int DepMem::out_cnt() {
aoqi@0 2526 int ct = 0;
aoqi@0 2527 for (DepEdge* e = _out_head; e != NULL; e = e->next_out()) ct++;
aoqi@0 2528 return ct;
aoqi@0 2529 }
aoqi@0 2530
aoqi@0 2531 //------------------------------print-----------------------------
aoqi@0 2532 void DepMem::print() {
aoqi@0 2533 #ifndef PRODUCT
aoqi@0 2534 tty->print(" DepNode %d (", _node->_idx);
aoqi@0 2535 for (DepEdge* p = _in_head; p != NULL; p = p->next_in()) {
aoqi@0 2536 Node* pred = p->pred()->node();
aoqi@0 2537 tty->print(" %d", pred != NULL ? pred->_idx : 0);
aoqi@0 2538 }
aoqi@0 2539 tty->print(") [");
aoqi@0 2540 for (DepEdge* s = _out_head; s != NULL; s = s->next_out()) {
aoqi@0 2541 Node* succ = s->succ()->node();
aoqi@0 2542 tty->print(" %d", succ != NULL ? succ->_idx : 0);
aoqi@0 2543 }
aoqi@0 2544 tty->print_cr(" ]");
aoqi@0 2545 #endif
aoqi@0 2546 }
aoqi@0 2547
aoqi@0 2548 // =========================== DepEdge =========================
aoqi@0 2549
aoqi@0 2550 //------------------------------DepPreds---------------------------
aoqi@0 2551 void DepEdge::print() {
aoqi@0 2552 #ifndef PRODUCT
aoqi@0 2553 tty->print_cr("DepEdge: %d [ %d ]", _pred->node()->_idx, _succ->node()->_idx);
aoqi@0 2554 #endif
aoqi@0 2555 }
aoqi@0 2556
aoqi@0 2557 // =========================== DepPreds =========================
aoqi@0 2558 // Iterator over predecessor edges in the dependence graph.
aoqi@0 2559
aoqi@0 2560 //------------------------------DepPreds---------------------------
aoqi@0 2561 DepPreds::DepPreds(Node* n, DepGraph& dg) {
aoqi@0 2562 _n = n;
aoqi@0 2563 _done = false;
aoqi@0 2564 if (_n->is_Store() || _n->is_Load()) {
aoqi@0 2565 _next_idx = MemNode::Address;
aoqi@0 2566 _end_idx = n->req();
aoqi@0 2567 _dep_next = dg.dep(_n)->in_head();
aoqi@0 2568 } else if (_n->is_Mem()) {
aoqi@0 2569 _next_idx = 0;
aoqi@0 2570 _end_idx = 0;
aoqi@0 2571 _dep_next = dg.dep(_n)->in_head();
aoqi@0 2572 } else {
aoqi@0 2573 _next_idx = 1;
aoqi@0 2574 _end_idx = _n->req();
aoqi@0 2575 _dep_next = NULL;
aoqi@0 2576 }
aoqi@0 2577 next();
aoqi@0 2578 }
aoqi@0 2579
aoqi@0 2580 //------------------------------next---------------------------
aoqi@0 2581 void DepPreds::next() {
aoqi@0 2582 if (_dep_next != NULL) {
aoqi@0 2583 _current = _dep_next->pred()->node();
aoqi@0 2584 _dep_next = _dep_next->next_in();
aoqi@0 2585 } else if (_next_idx < _end_idx) {
aoqi@0 2586 _current = _n->in(_next_idx++);
aoqi@0 2587 } else {
aoqi@0 2588 _done = true;
aoqi@0 2589 }
aoqi@0 2590 }
aoqi@0 2591
aoqi@0 2592 // =========================== DepSuccs =========================
aoqi@0 2593 // Iterator over successor edges in the dependence graph.
aoqi@0 2594
aoqi@0 2595 //------------------------------DepSuccs---------------------------
aoqi@0 2596 DepSuccs::DepSuccs(Node* n, DepGraph& dg) {
aoqi@0 2597 _n = n;
aoqi@0 2598 _done = false;
aoqi@0 2599 if (_n->is_Load()) {
aoqi@0 2600 _next_idx = 0;
aoqi@0 2601 _end_idx = _n->outcnt();
aoqi@0 2602 _dep_next = dg.dep(_n)->out_head();
aoqi@0 2603 } else if (_n->is_Mem() || _n->is_Phi() && _n->bottom_type() == Type::MEMORY) {
aoqi@0 2604 _next_idx = 0;
aoqi@0 2605 _end_idx = 0;
aoqi@0 2606 _dep_next = dg.dep(_n)->out_head();
aoqi@0 2607 } else {
aoqi@0 2608 _next_idx = 0;
aoqi@0 2609 _end_idx = _n->outcnt();
aoqi@0 2610 _dep_next = NULL;
aoqi@0 2611 }
aoqi@0 2612 next();
aoqi@0 2613 }
aoqi@0 2614
aoqi@0 2615 //-------------------------------next---------------------------
aoqi@0 2616 void DepSuccs::next() {
aoqi@0 2617 if (_dep_next != NULL) {
aoqi@0 2618 _current = _dep_next->succ()->node();
aoqi@0 2619 _dep_next = _dep_next->next_out();
aoqi@0 2620 } else if (_next_idx < _end_idx) {
aoqi@0 2621 _current = _n->raw_out(_next_idx++);
aoqi@0 2622 } else {
aoqi@0 2623 _done = true;
aoqi@0 2624 }
aoqi@0 2625 }

mercurial