< prev index next >

src/hotspot/share/opto/macro.hpp

Print this page

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_OPTO_MACRO_HPP
 26 #define SHARE_OPTO_MACRO_HPP
 27 



 28 #include "opto/phase.hpp"
 29 
 30 class  AllocateNode;
 31 class  AllocateArrayNode;
 32 class  CallNode;
 33 class  SubTypeCheckNode;
 34 class  Node;
 35 class  PhaseIterGVN;
 36 
 37 class PhaseMacroExpand : public Phase {
 38 private:
 39   PhaseIterGVN &_igvn;
 40 
 41 public:
 42   // Helper methods roughly modeled after GraphKit:
 43   Node* basic_plus_adr(Node* ptr, int offset, bool raw_base = false) {
 44     return basic_plus_adr(ptr, MakeConX(offset), raw_base);
 45   }
 46 
 47   Node* basic_plus_adr(Node* base, Node* ptr, int offset) {

 77                        Node* value, BasicType bt);
 78 
 79   Node* make_leaf_call(Node* ctrl, Node* mem,
 80                        const TypeFunc* call_type, address call_addr,
 81                        const char* call_name,
 82                        const TypePtr* adr_type,
 83                        Node* parm0 = nullptr, Node* parm1 = nullptr,
 84                        Node* parm2 = nullptr, Node* parm3 = nullptr,
 85                        Node* parm4 = nullptr, Node* parm5 = nullptr,
 86                        Node* parm6 = nullptr, Node* parm7 = nullptr);
 87 
 88   address basictype2arraycopy(BasicType t,
 89                               Node* src_offset,
 90                               Node* dest_offset,
 91                               bool disjoint_bases,
 92                               const char* &name,
 93                               bool dest_uninitialized);
 94 
 95 private:
 96   // projections extracted from a call node
 97   CallProjections _callprojs;
 98 
 99   void expand_allocate(AllocateNode *alloc);
100   void expand_allocate_array(AllocateArrayNode *alloc);
101   void expand_allocate_common(AllocateNode* alloc,
102                               Node* length,

103                               const TypeFunc* slow_call_type,
104                               address slow_call_address,
105                               Node* valid_length_test);
106   void yank_alloc_node(AllocateNode* alloc);
107   Node *value_from_mem(Node *mem, Node *ctl, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, AllocateNode *alloc);
108   Node *value_from_mem_phi(Node *mem, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, AllocateNode *alloc, Node_Stack *value_phis, int level);






109 
110   bool eliminate_boxing_node(CallStaticJavaNode *boxing);
111   bool eliminate_allocate_node(AllocateNode *alloc);
112   void undo_previous_scalarizations(GrowableArray <SafePointNode *> safepoints_done, AllocateNode* alloc);
113   bool scalar_replacement(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints);
114   void process_users_of_allocation(CallNode *alloc);
115 
116   void eliminate_gc_barrier(Node *p2x);
117   void mark_eliminated_box(Node* box, Node* obj);
118   void mark_eliminated_locking_nodes(AbstractLockNode *alock);
119   bool eliminate_locking_node(AbstractLockNode *alock);
120   void expand_lock_node(LockNode *lock);
121   void expand_unlock_node(UnlockNode *unlock);

122 
123   // More helper methods modeled after GraphKit for array copy
124   void insert_mem_bar(Node** ctrl, Node** mem, int opcode, int alias_idx, Node* precedent = nullptr);
125   Node* array_element_address(Node* ary, Node* idx, BasicType elembt, bool raw_base);
126   Node* ConvI2L(Node* offset);
127 
128   // helper methods modeled after LibraryCallKit for array copy
129   Node* generate_guard(Node** ctrl, Node* test, RegionNode* region, float true_prob);
130   Node* generate_slow_guard(Node** ctrl, Node* test, RegionNode* region);

131 
132   void generate_partial_inlining_block(Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type,
133                                        RegionNode** exit_block, Node** result_memory, Node* length,
134                                        Node* src_start, Node* dst_start, BasicType type);
135 
136   void generate_negative_guard(Node** ctrl, Node* index, RegionNode* region);
137   void generate_limit_guard(Node** ctrl, Node* offset, Node* subseq_length, Node* array_length, RegionNode* region);
138 
139   // More helper methods for array copy
140   Node* generate_nonpositive_guard(Node** ctrl, Node* index, bool never_negative);




141   void finish_arraycopy_call(Node* call, Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type);
142   Node* generate_arraycopy(ArrayCopyNode *ac,
143                            AllocateArrayNode* alloc,
144                            Node** ctrl, MergeMemNode* mem, Node** io,
145                            const TypePtr* adr_type,
146                            BasicType basic_elem_type,
147                            Node* src,  Node* src_offset,
148                            Node* dest, Node* dest_offset,
149                            Node* copy_length,


150                            bool disjoint_bases = false,
151                            bool length_never_negative = false,
152                            RegionNode* slow_region = nullptr);
153   void generate_clear_array(Node* ctrl, MergeMemNode* merge_mem,
154                             const TypePtr* adr_type,
155                             Node* dest,


156                             BasicType basic_elem_type,
157                             Node* slice_idx,
158                             Node* slice_len,
159                             Node* dest_size);

160   bool generate_block_arraycopy(Node** ctrl, MergeMemNode** mem,
161                                 const TypePtr* adr_type,
162                                 BasicType basic_elem_type,
163                                 Node* src, Node* src_offset,
164                                 Node* dest, Node* dest_offset,
165                                 Node* dest_size, bool dest_uninitialized);

166   MergeMemNode* generate_slow_arraycopy(ArrayCopyNode *ac,
167                                         Node** ctrl, Node* mem, Node** io,
168                                         const TypePtr* adr_type,
169                                         Node* src,  Node* src_offset,
170                                         Node* dest, Node* dest_offset,
171                                         Node* copy_length, bool dest_uninitialized);
172   Node* generate_checkcast_arraycopy(Node** ctrl, MergeMemNode** mem,
173                                      const TypePtr* adr_type,
174                                      Node* dest_elem_klass,
175                                      Node* src,  Node* src_offset,
176                                      Node* dest, Node* dest_offset,
177                                      Node* copy_length, bool dest_uninitialized);

178   Node* generate_generic_arraycopy(Node** ctrl, MergeMemNode** mem,
179                                    const TypePtr* adr_type,
180                                    Node* src,  Node* src_offset,
181                                    Node* dest, Node* dest_offset,
182                                    Node* copy_length, bool dest_uninitialized);
183   void generate_unchecked_arraycopy(Node** ctrl, MergeMemNode** mem,
184                                     const TypePtr* adr_type,
185                                     BasicType basic_elem_type,
186                                     bool disjoint_bases,
187                                     Node* src,  Node* src_offset,
188                                     Node* dest, Node* dest_offset,
189                                     Node* copy_length, bool dest_uninitialized);
190 



191   void expand_arraycopy_node(ArrayCopyNode *ac);
192 
193   void expand_subtypecheck_node(SubTypeCheckNode *check);
194 


195   int replace_input(Node *use, Node *oldref, Node *newref);
196   void migrate_outs(Node *old, Node *target);
197   Node* opt_bits_test(Node* ctrl, Node* region, int edge, Node* word);
198   void copy_predefined_input_for_runtime_call(Node * ctrl, CallNode* oldcall, CallNode* call);
199   CallNode* make_slow_call(CallNode *oldcall, const TypeFunc* slow_call_type, address slow_call,
200                            const char* leaf_name, Node* slow_path, Node* parm0, Node* parm1,
201                            Node* parm2);
202 
203   Node* initialize_object(AllocateNode* alloc,
204                           Node* control, Node* rawmem, Node* object,
205                           Node* klass_node, Node* length,
206                           Node* size_in_bytes);
207 
208   Node* make_arraycopy_load(ArrayCopyNode* ac, intptr_t offset, Node* ctl, Node* mem, BasicType ft, const Type *ftype, AllocateNode *alloc);
209 
210 public:
211   PhaseMacroExpand(PhaseIterGVN &igvn) : Phase(Macro_Expand), _igvn(igvn) {
212     _igvn.set_delay_transform(true);
213   }
214 
215   void refine_strip_mined_loop_macro_nodes();
216   void eliminate_macro_nodes();
217   bool expand_macro_nodes();
218   void eliminate_opaque_looplimit_macro_nodes();
219 
220   SafePointScalarObjectNode* create_scalarized_object_description(AllocateNode *alloc, SafePointNode* sfpt);
221   static bool can_eliminate_allocation(PhaseIterGVN *igvn, AllocateNode *alloc, GrowableArray <SafePointNode *> *safepoints);
222 
223 
224   PhaseIterGVN &igvn() const { return _igvn; }
225 
226 #ifndef PRODUCT
227     static int _objs_scalar_replaced_counter;
228     static int _monitor_objects_removed_counter;
229     static int _GC_barriers_removed_counter;
230     static int _memory_barriers_removed_counter;
231     static void print_statistics();
232     static int count_MemBar(Compile *C);
233 #endif
234 
235   // Members accessed from BarrierSetC2
236   void replace_node(Node* source, Node* target) { _igvn.replace_node(source, target); }
237   Node* intcon(jint con)        const { return _igvn.intcon(con); }
238   Node* longcon(jlong con)      const { return _igvn.longcon(con); }
239   Node* makecon(const Type *t)  const { return _igvn.makecon(t); }
240   Node* zerocon(BasicType bt)   const { return _igvn.zerocon(bt); }

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_OPTO_MACRO_HPP
 26 #define SHARE_OPTO_MACRO_HPP
 27 
 28 #include "ci/ciInstanceKlass.hpp"
 29 #include "opto/callnode.hpp"
 30 #include "opto/node.hpp"
 31 #include "opto/phase.hpp"
 32 
 33 class  AllocateNode;
 34 class  AllocateArrayNode;
 35 class  CallNode;
 36 class  SubTypeCheckNode;
 37 class  Node;
 38 class  PhaseIterGVN;
 39 
 40 class PhaseMacroExpand : public Phase {
 41 private:
 42   PhaseIterGVN &_igvn;
 43 
 44 public:
 45   // Helper methods roughly modeled after GraphKit:
 46   Node* basic_plus_adr(Node* ptr, int offset, bool raw_base = false) {
 47     return basic_plus_adr(ptr, MakeConX(offset), raw_base);
 48   }
 49 
 50   Node* basic_plus_adr(Node* base, Node* ptr, int offset) {

 80                        Node* value, BasicType bt);
 81 
 82   Node* make_leaf_call(Node* ctrl, Node* mem,
 83                        const TypeFunc* call_type, address call_addr,
 84                        const char* call_name,
 85                        const TypePtr* adr_type,
 86                        Node* parm0 = nullptr, Node* parm1 = nullptr,
 87                        Node* parm2 = nullptr, Node* parm3 = nullptr,
 88                        Node* parm4 = nullptr, Node* parm5 = nullptr,
 89                        Node* parm6 = nullptr, Node* parm7 = nullptr);
 90 
 91   address basictype2arraycopy(BasicType t,
 92                               Node* src_offset,
 93                               Node* dest_offset,
 94                               bool disjoint_bases,
 95                               const char* &name,
 96                               bool dest_uninitialized);
 97 
 98 private:
 99   // projections extracted from a call node
100   CallProjections* _callprojs;
101 
102   void expand_allocate(AllocateNode *alloc);
103   void expand_allocate_array(AllocateArrayNode *alloc);
104   void expand_allocate_common(AllocateNode* alloc,
105                               Node* length,
106                               Node* init_val,
107                               const TypeFunc* slow_call_type,
108                               address slow_call_address,
109                               Node* valid_length_test);
110   void yank_alloc_node(AllocateNode* alloc);
111 
112   void process_field_value_at_safepoint(const Type* field_type, Node* field_val, SafePointNode* sfpt, Unique_Node_List* value_worklist);
113   bool add_array_elems_to_safepoint(AllocateNode* alloc, const TypeAryPtr* array_type, SafePointNode* sfpt, Unique_Node_List* value_worklist);
114   bool add_inst_fields_to_safepoint(ciInstanceKlass* iklass, AllocateNode* alloc, Node* base, int offset_minus_header, SafePointNode* sfpt, Unique_Node_List* value_worklist);
115   Node* value_from_alloc(BasicType ft, const TypeOopPtr* adr_t, AllocateNode* alloc);
116   Node* value_from_mem(Node* mem, Node* ctl, BasicType ft, const Type* ftype, const TypeOopPtr* adr_t, AllocateNode* alloc);
117   Node* value_from_mem_phi(Node* mem, BasicType ft, const Type* ftype, const TypeOopPtr* adr_t, AllocateNode* alloc, Node_Stack* value_phis, int level);
118   Node* inline_type_from_mem(ciInlineKlass* vk, const TypeAryPtr* elem_adr_type, int elem_idx, int offset_in_element, bool null_free, AllocateNode* alloc, SafePointNode* sfpt);
119 
120   bool eliminate_boxing_node(CallStaticJavaNode *boxing);
121   bool eliminate_allocate_node(AllocateNode *alloc);
122   void undo_previous_scalarizations(GrowableArray <SafePointNode *> safepoints_done, AllocateNode* alloc);
123   bool scalar_replacement(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints);
124   void process_users_of_allocation(CallNode *alloc, bool inline_alloc = false);
125 
126   void eliminate_gc_barrier(Node *p2x);
127   void mark_eliminated_box(Node* box, Node* obj);
128   void mark_eliminated_locking_nodes(AbstractLockNode *alock);
129   bool eliminate_locking_node(AbstractLockNode *alock);
130   void expand_lock_node(LockNode *lock);
131   void expand_unlock_node(UnlockNode *unlock);
132   void expand_mh_intrinsic_return(CallStaticJavaNode* call);
133 
134   // More helper methods modeled after GraphKit for array copy
135   void insert_mem_bar(Node** ctrl, Node** mem, int opcode, int alias_idx, Node* precedent = nullptr);
136   Node* array_element_address(Node* ary, Node* idx, BasicType elembt, bool raw_base);
137   Node* ConvI2L(Node* offset);
138 
139   // helper methods modeled after LibraryCallKit for array copy
140   Node* generate_guard(Node** ctrl, Node* test, RegionNode* region, float true_prob);
141   Node* generate_slow_guard(Node** ctrl, Node* test, RegionNode* region);
142   Node* generate_fair_guard(Node** ctrl, Node* test, RegionNode* region);
143 
144   void generate_partial_inlining_block(Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type,
145                                        RegionNode** exit_block, Node** result_memory, Node* length,
146                                        Node* src_start, Node* dst_start, BasicType type);
147 
148   void generate_negative_guard(Node** ctrl, Node* index, RegionNode* region);
149   void generate_limit_guard(Node** ctrl, Node* offset, Node* subseq_length, Node* array_length, RegionNode* region);
150 
151   // More helper methods for array copy
152   Node* generate_nonpositive_guard(Node** ctrl, Node* index, bool never_negative);
153   Node* mark_word_test(Node** ctrl, Node* obj, MergeMemNode* mem, uintptr_t mask_val, RegionNode* region);
154   Node* generate_flat_array_guard(Node** ctrl, Node* array, MergeMemNode* mem, RegionNode* region);
155   Node* generate_null_free_array_guard(Node** ctrl, Node* array, MergeMemNode* mem, RegionNode* region);
156 
157   void finish_arraycopy_call(Node* call, Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type);
158   Node* generate_arraycopy(ArrayCopyNode *ac,
159                            AllocateArrayNode* alloc,
160                            Node** ctrl, MergeMemNode* mem, Node** io,
161                            const TypePtr* adr_type,
162                            BasicType basic_elem_type,
163                            Node* src,  Node* src_offset,
164                            Node* dest, Node* dest_offset,
165                            Node* copy_length,
166                            Node* dest_length,
167                            bool raw_base,
168                            bool disjoint_bases = false,
169                            bool length_never_negative = false,
170                            RegionNode* slow_region = nullptr);
171   void generate_clear_array(Node* ctrl, MergeMemNode* merge_mem,
172                             const TypePtr* adr_type,
173                             Node* dest,
174                             Node* val,
175                             Node* raw_val,
176                             BasicType basic_elem_type,
177                             Node* slice_idx,
178                             Node* slice_len,
179                             Node* dest_size,
180                             bool raw_base);
181   bool generate_block_arraycopy(Node** ctrl, MergeMemNode** mem,
182                                 const TypePtr* adr_type,
183                                 BasicType basic_elem_type,
184                                 Node* src, Node* src_offset,
185                                 Node* dest, Node* dest_offset,
186                                 Node* dest_size, bool dest_uninitialized,
187                                 bool raw_base);
188   MergeMemNode* generate_slow_arraycopy(ArrayCopyNode *ac,
189                                         Node** ctrl, Node* mem, Node** io,
190                                         const TypePtr* adr_type,
191                                         Node* src,  Node* src_offset,
192                                         Node* dest, Node* dest_offset,
193                                         Node* copy_length, bool dest_uninitialized);
194   Node* generate_checkcast_arraycopy(Node** ctrl, MergeMemNode** mem,
195                                      const TypePtr* adr_type,
196                                      Node* dest_elem_klass,
197                                      Node* src,  Node* src_offset,
198                                      Node* dest, Node* dest_offset,
199                                      Node* copy_length, bool dest_uninitialized,
200                                      bool raw_base);
201   Node* generate_generic_arraycopy(Node** ctrl, MergeMemNode** mem,
202                                    const TypePtr* adr_type,
203                                    Node* src,  Node* src_offset,
204                                    Node* dest, Node* dest_offset,
205                                    Node* copy_length, bool dest_uninitialized);
206   void generate_unchecked_arraycopy(Node** ctrl, MergeMemNode** mem,
207                                     const TypePtr* adr_type,
208                                     BasicType basic_elem_type,
209                                     bool disjoint_bases,
210                                     Node* src,  Node* src_offset,
211                                     Node* dest, Node* dest_offset,
212                                     Node* copy_length, bool dest_uninitialized,
213                                     bool raw_base);
214   const TypePtr* adjust_for_flat_array(const TypeAryPtr* top_dest, Node*& src_offset,
215                                        Node*& dest_offset, Node*& length, BasicType& dest_elem,
216                                        Node*& dest_length);
217   void expand_arraycopy_node(ArrayCopyNode *ac);
218 
219   void expand_subtypecheck_node(SubTypeCheckNode *check);
220 
221   void expand_flatarraycheck_node(FlatArrayCheckNode* check);
222 
223   int replace_input(Node *use, Node *oldref, Node *newref);
224   void migrate_outs(Node *old, Node *target);
225   Node* opt_bits_test(Node* ctrl, Node* region, int edge, Node* word);
226   void copy_predefined_input_for_runtime_call(Node * ctrl, CallNode* oldcall, CallNode* call);
227   CallNode* make_slow_call(CallNode *oldcall, const TypeFunc* slow_call_type, address slow_call,
228                            const char* leaf_name, Node* slow_path, Node* parm0, Node* parm1,
229                            Node* parm2);
230 
231   Node* initialize_object(AllocateNode* alloc,
232                           Node* control, Node* rawmem, Node* object,
233                           Node* klass_node, Node* length,
234                           Node* size_in_bytes);
235 
236   Node* make_arraycopy_load(ArrayCopyNode* ac, intptr_t offset, Node* ctl, Node* mem, BasicType ft, const Type *ftype, AllocateNode *alloc);
237 
238 public:
239   PhaseMacroExpand(PhaseIterGVN &igvn) : Phase(Macro_Expand), _igvn(igvn) {
240     _igvn.set_delay_transform(true);
241   }
242 
243   void refine_strip_mined_loop_macro_nodes();
244   void eliminate_macro_nodes(bool eliminate_locks = true);
245   bool expand_macro_nodes();
246   void eliminate_opaque_looplimit_macro_nodes();
247 
248   SafePointScalarObjectNode* create_scalarized_object_description(AllocateNode *alloc, SafePointNode* sfpt, Unique_Node_List* value_worklist);
249   static bool can_eliminate_allocation(PhaseIterGVN *igvn, AllocateNode *alloc, GrowableArray <SafePointNode *> *safepoints);
250 
251 
252   PhaseIterGVN &igvn() const { return _igvn; }
253 
254 #ifndef PRODUCT
255     static int _objs_scalar_replaced_counter;
256     static int _monitor_objects_removed_counter;
257     static int _GC_barriers_removed_counter;
258     static int _memory_barriers_removed_counter;
259     static void print_statistics();
260     static int count_MemBar(Compile *C);
261 #endif
262 
263   // Members accessed from BarrierSetC2
264   void replace_node(Node* source, Node* target) { _igvn.replace_node(source, target); }
265   Node* intcon(jint con)        const { return _igvn.intcon(con); }
266   Node* longcon(jlong con)      const { return _igvn.longcon(con); }
267   Node* makecon(const Type *t)  const { return _igvn.makecon(t); }
268   Node* zerocon(BasicType bt)   const { return _igvn.zerocon(bt); }
< prev index next >