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