/* * Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// // S U P E R W O R D T R A N S F O R M // // SuperWords are short, fixed length vectors. // // Algorithm from: // // Exploiting SuperWord Level Parallelism with // Multimedia Instruction Sets // by // Samuel Larsen and Saman Amarasinghe // MIT Laboratory for Computer Science // date // May 2000 // published in // ACM SIGPLAN Notices // Proceedings of ACM PLDI '00, Volume 35 Issue 5 // // Definition 3.1 A Pack is an n-tuple, <s1, ...,sn>, where // s1,...,sn are independent isomorphic statements in a basic // block. // // Definition 3.2 A PackSet is a set of Packs. // // Definition 3.3 A Pair is a Pack of size two, where the // first statement is considered the left element, and the // second statement is considered the right element.
//------------------------------DepEdge--------------------------- // An edge in the dependence graph. The edges incident to a dependence // node are threaded through _next_in for incoming edges and _next_out // for outgoing edges. class DepEdge : public ArenaObj { protected:
DepMem* _pred;
DepMem* _succ;
DepEdge* _next_in; // list of in edges, null terminated
DepEdge* _next_out; // list of out edges, null terminated
//------------------------------DepMem--------------------------- // A node in the dependence graph. _in_head starts the threaded list of // incoming edges, and _out_head starts the list of outgoing edges. class DepMem : public ArenaObj { protected:
Node* _node; // Corresponding ideal node
DepEdge* _in_head; // Head of list of in edges, null terminated
DepEdge* _out_head; // Head of list of out edges, null terminated
//------------------------------DepPreds--------------------------- // Iterator over predecessors in the dependence graph and // non-memory-graph inputs of ideal nodes. class DepPreds : public StackObj { private:
Node* _n; int _next_idx, _end_idx;
DepEdge* _dep_next;
Node* _current; bool _done;
//------------------------------DepSuccs--------------------------- // Iterator over successors in the dependence graph and // non-memory-graph outputs of ideal nodes. class DepSuccs : public StackObj { private:
Node* _n; int _next_idx, _end_idx;
DepEdge* _dep_next;
Node* _current; bool _done;
// -----------------------------SWNodeInfo--------------------------------- // Per node info needed by SuperWord class SWNodeInfo { public: int _alignment; // memory alignment for a node int _depth; // Max expression (DAG) depth from block start const Type* _velt_type; // vector element type
Node_List* _my_pack; // pack containing this node
GrowableArray<Node_List*> _packset; // Packs for the current block
GrowableArray<int> _bb_idx; // Map from Node _idx to index within block
GrowableArray<Node*> _block; // Nodes in current block
GrowableArray<Node*> _post_block; // Nodes in post loop block
GrowableArray<Node*> _data_entry; // Nodes with all inputs from outside
GrowableArray<Node*> _mem_slice_head; // Memory slice head nodes
GrowableArray<Node*> _mem_slice_tail; // Memory slice tail nodes
GrowableArray<Node*> _iteration_first; // nodes in the generation that has deps from phi
GrowableArray<Node*> _iteration_last; // nodes in the generation that has deps to phi
GrowableArray<SWNodeInfo> _node_info; // Info needed per node
CloneMap& _clone_map; // map of nodes created in cloning
CMoveKit _cmovev_kit; // support for vectorization of CMov
MemNode* _align_to_ref; // Memory reference that pre-loop will align to
// Scratch pads
VectorSet _visited; // Visited set
VectorSet _post_visited; // Post-visited set
Node_Stack _n_idx_list; // List of (node,index) pairs
GrowableArray<Node*> _nlist; // List of nodes
GrowableArray<Node*> _stk; // Stack of nodes
#ifndef PRODUCT bool is_debug() { return _vector_loop_debug > 0; } bool is_trace_alignment() { return (_vector_loop_debug & 2) > 0; } bool is_trace_mem_slice() { return (_vector_loop_debug & 4) > 0; } bool is_trace_loop() { return (_vector_loop_debug & 8) > 0; } bool is_trace_adjacent() { return (_vector_loop_debug & 16) > 0; } bool is_trace_cmov() { return (_vector_loop_debug & 32) > 0; } bool is_trace_loop_reverse() { return (_vector_loop_debug & 64) > 0; } #endif bool do_vector_loop() { return _do_vector_loop; } bool do_reserve_copy() { return _do_reserve_copy; } private:
IdealLoopTree* _lpt; // Current loop tree node
CountedLoopNode* _lp; // Current CountedLoopNode
CountedLoopEndNode* _pre_loop_end; // Current CountedLoopEndNode of pre loop
Node* _bb; // Current basic block
PhiNode* _iv; // Induction var bool _race_possible; // In cases where SDMU is true bool _early_return; // True if we do not initialize bool _do_vector_loop; // whether to do vectorization/simd style bool _do_reserve_copy; // do reserve copy of the graph(loop) before final modification in output int _num_work_vecs; // Number of non memory vector operations int _num_reductions; // Number of reduction expressions applied int _ii_first; // generation with direct deps from mem phi int _ii_last; // generation with direct deps to mem phi
GrowableArray<int> _ii_order; #ifndef PRODUCT
uintx _vector_loop_debug; // provide more printing in debug mode #endif
// Ensure node_info contains element "i" void grow_node_info(int i) { if (i >= _node_info.length()) _node_info.at_put_grow(i, SWNodeInfo::initial); }
// should we align vector memory references on this platform? bool vectors_should_be_aligned() { return !Matcher::misaligned_vectors_ok() || AlignVector; }
// memory alignment for a node int alignment(Node* n) { return _node_info.adr_at(bb_idx(n))->_alignment; } void set_alignment(Node* n, int a) { int i = bb_idx(n); grow_node_info(i); _node_info.adr_at(i)->_alignment = a; }
// Max expression (DAG) depth from beginning of the block for each node int depth(Node* n) { return _node_info.adr_at(bb_idx(n))->_depth; } void set_depth(Node* n, int d) { int i = bb_idx(n); grow_node_info(i); _node_info.adr_at(i)->_depth = d; }
// vector element type const Type* velt_type(Node* n) { return _node_info.adr_at(bb_idx(n))->_velt_type; }
BasicType velt_basic_type(Node* n) { return velt_type(n)->array_element_basic_type(); } void set_velt_type(Node* n, const Type* t) { int i = bb_idx(n); grow_node_info(i); _node_info.adr_at(i)->_velt_type = t; } bool same_velt_type(Node* n1, Node* n2);
// my_pack
Node_List* my_pack(Node* n) { return !in_bb(n) ? NULL : _node_info.adr_at(bb_idx(n))->_my_pack; } void set_my_pack(Node* n, Node_List* p) { int i = bb_idx(n); grow_node_info(i); _node_info.adr_at(i)->_my_pack = p; } // is pack good for converting into one vector node replacing bunches of Cmp, Bool, CMov nodes. bool is_cmov_pack(Node_List* p); bool is_cmov_pack_internal_node(Node_List* p, Node* nd) { return is_cmov_pack(p) && !nd->is_CMove(); } staticbool is_cmove_fp_opcode(int opc) { return (opc == Op_CMoveF || opc == Op_CMoveD); } staticbool requires_long_to_int_conversion(int opc); // For pack p, are all idx operands the same? bool same_inputs(Node_List* p, int idx); // CloneMap utilities bool same_origin_idx(Node* a, Node* b) const; bool same_generation(Node* a, Node* b) const;
// methods
// Extract the superword level parallelism bool SLP_extract(); // Find the adjacent memory references and create pack pairs for them. void find_adjacent_refs(); // Tracing support #ifndef PRODUCT void find_adjacent_refs_trace_1(Node* best_align_to_mem_ref, int best_iv_adjustment); void print_loop(bool whole); #endif // Find a memory reference to align the loop induction variable to.
MemNode* find_align_to_ref(Node_List &memops, int &idx); // Calculate loop's iv adjustment for this memory ops. int get_iv_adjustment(MemNode* mem); // Can the preloop align the reference to position zero in the vector? bool ref_is_alignable(SWPointer& p); // rebuild the graph so all loads in different iterations of cloned loop become dependent on phi node (in _do_vector_loop only) bool hoist_loads_in_graph(); // Test whether MemNode::Memory dependency to the same load but in the first iteration of this loop is coming from memory phi // Return false if failed
Node* find_phi_for_mem_dep(LoadNode* ld); // Return same node but from the first generation. Return 0, if not found
Node* first_node(Node* nd); // Return same node as this but from the last generation. Return 0, if not found
Node* last_node(Node* n); // Mark nodes belonging to first and last generation // returns first generation index or -1 if vectorization/simd is impossible int mark_generations(); // swapping inputs of commutative instruction (Add or Mul) bool fix_commutative_inputs(Node* gold, Node* fix); // make packs forcefully (in _do_vector_loop only) bool pack_parallel(); // Construct dependency graph. void dependence_graph(); // Return a memory slice (node list) in predecessor order starting at "start" void mem_slice_preds(Node* start, Node* stop, GrowableArray<Node*> &preds); // Can s1 and s2 be in a pack with s1 immediately preceding s2 and s1 aligned at "align" bool stmts_can_pack(Node* s1, Node* s2, int align); // Does s exist in a pack at position pos? bool exists_at(Node* s, uint pos); // Is s1 immediately before s2 in memory? bool are_adjacent_refs(Node* s1, Node* s2); // Are s1 and s2 similar? bool isomorphic(Node* s1, Node* s2); // Is there no data path from s1 to s2 or s2 to s1? bool independent(Node* s1, Node* s2); // For a node pair (s1, s2) which is isomorphic and independent, // do s1 and s2 have similar input edges? bool have_similar_inputs(Node* s1, Node* s2); // Is there a data path between s1 and s2 and both are reductions? bool reduction(Node* s1, Node* s2); // Helper for independent bool independent_path(Node* shallow, Node* deep, uint dp=0); void set_alignment(Node* s1, Node* s2, int align); int data_size(Node* s); // Extend packset by following use->def and def->use links from pack members. void extend_packlist(); int adjust_alignment_for_type_conversion(Node* s, Node* t, int align); // Extend the packset by visiting operand definitions of nodes in pack p bool follow_use_defs(Node_List* p); // Extend the packset by visiting uses of nodes in pack p bool follow_def_uses(Node_List* p); // For extended packsets, ordinally arrange uses packset by major component void order_def_uses(Node_List* p); // Estimate the savings from executing s1 and s2 as a pack int est_savings(Node* s1, Node* s2); int adjacent_profit(Node* s1, Node* s2); int pack_cost(int ct); int unpack_cost(int ct); // Combine packs A and B with A.last == B.first into A.first..,A.last,B.second,..B.last void combine_packs(); // Construct the map from nodes to packs. void construct_my_pack_map(); // Remove packs that are not implemented or not profitable. void filter_packs(); // Merge CMove into new vector-nodes void merge_packs_to_cmove(); // Adjust the memory graph for the packed operations void schedule(); // Remove "current" from its current position in the memory graph and insert // it after the appropriate insert points (lip or uip); void remove_and_insert(MemNode *current, MemNode *prev, MemNode *lip, Node *uip, Unique_Node_List &schd_before); // Within a store pack, schedule stores together by moving out the sandwiched memory ops according // to dependence info; and within a load pack, move loads down to the last executed load. void co_locate_pack(Node_List* p);
Node* pick_mem_state(Node_List* pk);
Node* find_first_mem_state(Node_List* pk);
Node* find_last_mem_state(Node_List* pk, Node* first_mem, bool &is_dependent);
// Convert packs into vector node operations bool output(); // Create vector mask for post loop vectorization
Node* create_post_loop_vmask(); // Create a vector operand for the nodes in pack p for operand: in(opd_idx)
Node* vector_opd(Node_List* p, int opd_idx); // Can code be generated for pack p? bool implemented(Node_List* p); // For pack p, are all operands and all uses (with in the block) vector? bool profitable(Node_List* p); // If a use of pack p is not a vector use, then replace the use with an extract operation. void insert_extracts(Node_List* p); // Is use->in(u_idx) a vector use? bool is_vector_use(Node* use, int u_idx); // Construct reverse postorder list of block members bool construct_bb(); // Initialize per node info void initialize_bb(); // Insert n into block after pos void bb_insert_after(Node* n, int pos); // Compute max depth for expressions from beginning of block void compute_max_depth(); // Return the longer type for vectorizable type-conversion node or illegal type for other nodes.
BasicType longer_type_for_conversion(Node* n); // Find the longest type in def-use chain for packed nodes, and then compute the max vector size. int max_vector_size_in_def_use_chain(Node* n); // Compute necessary vector element type for expressions void compute_vector_element_type(); // Are s1 and s2 in a pack pair and ordered as s1,s2? bool in_packset(Node* s1, Node* s2); // Is s in pack p?
Node_List* in_pack(Node* s, Node_List* p); // Remove the pack at position pos in the packset void remove_pack_at(int pos); // Return the node executed first in pack p.
Node* executed_first(Node_List* p); // Return the node executed last in pack p.
Node* executed_last(Node_List* p); static LoadNode::ControlDependency control_dependency(Node_List* p); // Alignment within a vector memory reference int memory_alignment(MemNode* s, int iv_adjust); // (Start, end] half-open range defining which operands are vector void vector_opd_range(Node* n, uint* start, uint* end); // Smallest type containing range of values const Type* container_type(Node* n); // Adjust pre-loop limit so that in main loop, a load/store reference // to align_to_ref will be a position zero in the vector. void align_initial_loop_index(MemNode* align_to_ref); // Find pre loop end from main loop. Returns null if none.
CountedLoopEndNode* find_pre_loop_end(CountedLoopNode *cl) const; // Is the use of d1 in u1 at the same operand position as d2 in u2? bool opnd_positions_match(Node* d1, Node* u1, Node* d2, Node* u2); void init(); // clean up some basic structures - used if the ideal graph was rebuilt void restart();
//------------------------------SWPointer--------------------------- // Information about an address for dependence checking and vector alignment class SWPointer : public ArenaObj { protected:
MemNode* _mem; // My memory reference node
SuperWord* _slp; // SuperWord class
Node* _base; // NULL if unsafe nonheap reference
Node* _adr; // address pointer int _scale; // multiplier for iv (in bytes), 0 if no loop iv int _offset; // constant offset (in bytes)
Node* _invar; // invariant offset (in bytes), NULL if none bool _negate_invar; // if true then use: (0 - _invar)
Node* _invar_scale; // multiplier for invariant
Node_Stack* _nstack; // stack used to record a swpointer trace of variants bool _analyze_only; // Used in loop unrolling only for swpointer trace
uint _stack_idx; // Used in loop unrolling only for swpointer trace
// Match: k*iv + offset bool scaled_iv_plus_offset(Node* n); // Match: k*iv where k is a constant that's not zero bool scaled_iv(Node* n); // Match: offset is (k [+/- invariant]) bool offset_plus_k(Node* n, bool negate = false);
SWPointer(MemNode* mem, SuperWord* slp, Node_Stack *nstack, bool analyze_only); // Following is used to create a temporary object during // the pattern match of an address expression.
SWPointer(SWPointer* p);
void scaled_iv_1(Node* n); void scaled_iv_2(Node* n, int scale); void scaled_iv_3(Node* n, int scale); void scaled_iv_4(Node* n, int scale); void scaled_iv_5(Node* n, int scale); void scaled_iv_6(Node* n, int scale); void scaled_iv_7(Node* n); void scaled_iv_8(Node* n, SWPointer* tmp); void scaled_iv_9(Node* n, int _scale, int _offset, Node* _invar, bool _negate_invar); void scaled_iv_10(Node* n);
void offset_plus_k_1(Node* n); void offset_plus_k_2(Node* n, int _offset); void offset_plus_k_3(Node* n, int _offset); void offset_plus_k_4(Node* n); void offset_plus_k_5(Node* n, Node* _invar); void offset_plus_k_6(Node* n, Node* _invar, bool _negate_invar, int _offset); void offset_plus_k_7(Node* n, Node* _invar, bool _negate_invar, int _offset); void offset_plus_k_8(Node* n, Node* _invar, bool _negate_invar, int _offset); void offset_plus_k_9(Node* n, Node* _invar, bool _negate_invar, int _offset); void offset_plus_k_10(Node* n, Node* _invar, bool _negate_invar, int _offset); void offset_plus_k_11(Node* n);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.