1 /*
2 * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
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 *
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 // Additional data collected during macro expansion
87 bool _has_locks;
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 const TypeFunc* slow_call_type,
94 address slow_call_address,
95 Node* valid_length_test);
96 void yank_alloc_node(AllocateNode* alloc);
97 Node *value_from_mem(Node *mem, Node *ctl, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, AllocateNode *alloc);
98 Node *value_from_mem_phi(Node *mem, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, AllocateNode *alloc, Node_Stack *value_phis, int level);
99
100 bool eliminate_boxing_node(CallStaticJavaNode *boxing);
101 bool eliminate_allocate_node(AllocateNode *alloc);
102 void undo_previous_scalarizations(GrowableArray <SafePointNode *> safepoints_done, AllocateNode* alloc);
103 bool scalar_replacement(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints);
104 void process_users_of_allocation(CallNode *alloc);
105
106 void eliminate_gc_barrier(Node *p2x);
107 void mark_eliminated_box(Node* box, Node* obj);
108 void mark_eliminated_locking_nodes(AbstractLockNode *alock);
109 bool eliminate_locking_node(AbstractLockNode *alock);
110 void expand_lock_node(LockNode *lock);
111 void expand_unlock_node(UnlockNode *unlock);
112
113 // More helper methods modeled after GraphKit for array copy
114 void insert_mem_bar(Node** ctrl, Node** mem, int opcode, int alias_idx, Node* precedent = nullptr);
115 Node* array_element_address(Node* ary, Node* idx, BasicType elembt);
116 Node* ConvI2L(Node* offset);
117
118 // helper methods modeled after LibraryCallKit for array copy
119 Node* generate_guard(Node** ctrl, Node* test, RegionNode* region, float true_prob);
120 Node* generate_slow_guard(Node** ctrl, Node* test, RegionNode* region);
121
122 void generate_partial_inlining_block(Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type,
123 RegionNode** exit_block, Node** result_memory, Node* length,
124 Node* src_start, Node* dst_start, BasicType type);
125
126 void generate_negative_guard(Node** ctrl, Node* index, RegionNode* region);
127 void generate_limit_guard(Node** ctrl, Node* offset, Node* subseq_length, Node* array_length, RegionNode* region);
128
129 // More helper methods for array copy
130 Node* generate_nonpositive_guard(Node** ctrl, Node* index, bool never_negative);
131 void finish_arraycopy_call(Node* call, Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type);
132 Node* generate_arraycopy(ArrayCopyNode *ac,
133 AllocateArrayNode* alloc,
134 Node** ctrl, MergeMemNode* mem, Node** io,
135 const TypePtr* adr_type,
136 BasicType basic_elem_type,
137 Node* src, Node* src_offset,
138 Node* dest, Node* dest_offset,
139 Node* copy_length,
140 bool disjoint_bases = false,
141 bool length_never_negative = false,
142 RegionNode* slow_region = nullptr);
143 void generate_clear_array(Node* ctrl, MergeMemNode* merge_mem,
144 const TypePtr* adr_type,
145 Node* dest,
146 BasicType basic_elem_type,
147 Node* slice_idx,
148 Node* slice_len,
149 Node* dest_size);
150 bool generate_block_arraycopy(Node** ctrl, MergeMemNode** mem, Node* io,
151 const TypePtr* adr_type,
152 BasicType basic_elem_type,
153 AllocateNode* alloc,
154 Node* src, Node* src_offset,
155 Node* dest, Node* dest_offset,
156 Node* dest_size, bool dest_uninitialized);
157 MergeMemNode* generate_slow_arraycopy(ArrayCopyNode *ac,
158 Node** ctrl, Node* mem, Node** io,
159 const TypePtr* adr_type,
160 Node* src, Node* src_offset,
161 Node* dest, Node* dest_offset,
162 Node* copy_length, bool dest_uninitialized);
163 Node* generate_checkcast_arraycopy(Node** ctrl, MergeMemNode** mem,
164 const TypePtr* adr_type,
165 Node* dest_elem_klass,
166 Node* src, Node* src_offset,
167 Node* dest, Node* dest_offset,
168 Node* copy_length, bool dest_uninitialized);
169 Node* generate_generic_arraycopy(Node** ctrl, MergeMemNode** mem,
170 const TypePtr* adr_type,
171 Node* src, Node* src_offset,
172 Node* dest, Node* dest_offset,
173 Node* copy_length, bool dest_uninitialized);
174 void generate_unchecked_arraycopy(Node** ctrl, MergeMemNode** mem,
175 const TypePtr* adr_type,
176 BasicType basic_elem_type,
177 bool disjoint_bases,
178 Node* src, Node* src_offset,
179 Node* dest, Node* dest_offset,
180 Node* copy_length, bool dest_uninitialized);
181
182 void expand_arraycopy_node(ArrayCopyNode *ac);
183
184 void expand_subtypecheck_node(SubTypeCheckNode *check);
185
186 int replace_input(Node *use, Node *oldref, Node *newref);
187 void migrate_outs(Node *old, Node *target);
188 Node* opt_bits_test(Node* ctrl, Node* region, int edge, Node* word, int mask, int bits, bool return_fast_path = false);
189 void copy_predefined_input_for_runtime_call(Node * ctrl, CallNode* oldcall, CallNode* call);
190 CallNode* make_slow_call(CallNode *oldcall, const TypeFunc* slow_call_type, address slow_call,
191 const char* leaf_name, Node* slow_path, Node* parm0, Node* parm1,
192 Node* parm2);
193
194 Node* initialize_object(AllocateNode* alloc,
195 Node* control, Node* rawmem, Node* object,
196 Node* klass_node, Node* length,
197 Node* size_in_bytes);
198
199 Node* make_arraycopy_load(ArrayCopyNode* ac, intptr_t offset, Node* ctl, Node* mem, BasicType ft, const Type *ftype, AllocateNode *alloc);
200
201 public:
202 PhaseMacroExpand(PhaseIterGVN &igvn) : Phase(Macro_Expand), _igvn(igvn), _has_locks(false) {
203 _igvn.set_delay_transform(true);
204 }
205 void eliminate_macro_nodes();
206 bool expand_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); }
|
1 /*
2 * Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
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 *
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 Node* init_val,
91 const TypeFunc* slow_call_type,
92 address slow_call_address,
93 Node* valid_length_test);
94 void yank_alloc_node(AllocateNode* alloc);
95 Node *value_from_mem(Node *mem, Node *ctl, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, AllocateNode *alloc);
96 Node *value_from_mem_phi(Node *mem, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, AllocateNode *alloc, Node_Stack *value_phis, int level);
97 Node* inline_type_from_mem(Node* mem, Node* ctl, ciInlineKlass* vk, const TypeAryPtr* adr_type, int offset, AllocateNode* alloc);
98
99 bool eliminate_boxing_node(CallStaticJavaNode *boxing);
100 bool eliminate_allocate_node(AllocateNode *alloc);
101 void undo_previous_scalarizations(GrowableArray <SafePointNode *> safepoints_done, AllocateNode* alloc);
102 bool scalar_replacement(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints);
103 void process_users_of_allocation(CallNode *alloc, bool inline_alloc = false);
104
105 void eliminate_gc_barrier(Node *p2x);
106 void mark_eliminated_box(Node* box, Node* obj);
107 void mark_eliminated_locking_nodes(AbstractLockNode *alock);
108 bool eliminate_locking_node(AbstractLockNode *alock);
109 void expand_lock_node(LockNode *lock);
110 void expand_unlock_node(UnlockNode *unlock);
111 void expand_mh_intrinsic_return(CallStaticJavaNode* call);
112
113 // More helper methods modeled after GraphKit for array copy
114 void insert_mem_bar(Node** ctrl, Node** mem, int opcode, int alias_idx, Node* precedent = nullptr);
115 Node* array_element_address(Node* ary, Node* idx, BasicType elembt);
116 Node* ConvI2L(Node* offset);
117
118 // helper methods modeled after LibraryCallKit for array copy
119 Node* generate_guard(Node** ctrl, Node* test, RegionNode* region, float true_prob);
120 Node* generate_slow_guard(Node** ctrl, Node* test, RegionNode* region);
121 Node* generate_fair_guard(Node** ctrl, Node* test, RegionNode* region);
122
123 void generate_partial_inlining_block(Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type,
124 RegionNode** exit_block, Node** result_memory, Node* length,
125 Node* src_start, Node* dst_start, BasicType type);
126
127 void generate_negative_guard(Node** ctrl, Node* index, RegionNode* region);
128 void generate_limit_guard(Node** ctrl, Node* offset, Node* subseq_length, Node* array_length, RegionNode* region);
129
130 // More helper methods for array copy
131 Node* generate_nonpositive_guard(Node** ctrl, Node* index, bool never_negative);
132 Node* mark_word_test(Node** ctrl, Node* obj, MergeMemNode* mem, uintptr_t mask_val, RegionNode* region);
133 Node* generate_flat_array_guard(Node** ctrl, Node* array, MergeMemNode* mem, RegionNode* region);
134 Node* generate_null_free_array_guard(Node** ctrl, Node* array, MergeMemNode* mem, RegionNode* region);
135
136 void finish_arraycopy_call(Node* call, Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type);
137 Node* generate_arraycopy(ArrayCopyNode *ac,
138 AllocateArrayNode* alloc,
139 Node** ctrl, MergeMemNode* mem, Node** io,
140 const TypePtr* adr_type,
141 BasicType basic_elem_type,
142 Node* src, Node* src_offset,
143 Node* dest, Node* dest_offset,
144 Node* copy_length,
145 Node* dest_length,
146 bool disjoint_bases = false,
147 bool length_never_negative = false,
148 RegionNode* slow_region = nullptr);
149 void generate_clear_array(Node* ctrl, MergeMemNode* merge_mem,
150 const TypePtr* adr_type,
151 Node* dest,
152 Node* val,
153 Node* raw_val,
154 BasicType basic_elem_type,
155 Node* slice_idx,
156 Node* slice_len,
157 Node* dest_size);
158 bool generate_block_arraycopy(Node** ctrl, MergeMemNode** mem, Node* io,
159 const TypePtr* adr_type,
160 BasicType basic_elem_type,
161 AllocateNode* alloc,
162 Node* src, Node* src_offset,
163 Node* dest, Node* dest_offset,
164 Node* dest_size, bool dest_uninitialized);
165 MergeMemNode* generate_slow_arraycopy(ArrayCopyNode *ac,
166 Node** ctrl, Node* mem, Node** io,
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 Node* generate_checkcast_arraycopy(Node** ctrl, MergeMemNode** mem,
172 const TypePtr* adr_type,
173 Node* dest_elem_klass,
174 Node* src, Node* src_offset,
175 Node* dest, Node* dest_offset,
176 Node* copy_length, bool dest_uninitialized);
177 Node* generate_generic_arraycopy(Node** ctrl, MergeMemNode** mem,
178 const TypePtr* adr_type,
179 Node* src, Node* src_offset,
180 Node* dest, Node* dest_offset,
181 Node* copy_length, bool dest_uninitialized);
182 void generate_unchecked_arraycopy(Node** ctrl, MergeMemNode** mem,
183 const TypePtr* adr_type,
184 BasicType basic_elem_type,
185 bool disjoint_bases,
186 Node* src, Node* src_offset,
187 Node* dest, Node* dest_offset,
188 Node* copy_length, bool dest_uninitialized);
189 const TypePtr* adjust_for_flat_array(const TypeAryPtr* top_dest, Node*& src_offset,
190 Node*& dest_offset, Node*& length, BasicType& dest_elem,
191 Node*& dest_length);
192 void expand_arraycopy_node(ArrayCopyNode *ac);
193
194 void expand_subtypecheck_node(SubTypeCheckNode *check);
195
196 void expand_flatarraycheck_node(FlatArrayCheckNode* check);
197
198 int replace_input(Node *use, Node *oldref, Node *newref);
199 void migrate_outs(Node *old, Node *target);
200 Node* opt_bits_test(Node* ctrl, Node* region, int edge, Node* word, int mask, int bits, bool return_fast_path = false);
201 void copy_predefined_input_for_runtime_call(Node * ctrl, CallNode* oldcall, CallNode* call);
202 CallNode* make_slow_call(CallNode *oldcall, const TypeFunc* slow_call_type, address slow_call,
203 const char* leaf_name, Node* slow_path, Node* parm0, Node* parm1,
204 Node* parm2);
205
206 Node* initialize_object(AllocateNode* alloc,
207 Node* control, Node* rawmem, Node* object,
208 Node* klass_node, Node* length,
209 Node* size_in_bytes);
210
211 Node* make_arraycopy_load(ArrayCopyNode* ac, intptr_t offset, Node* ctl, Node* mem, BasicType ft, const Type *ftype, AllocateNode *alloc);
212
213 public:
214 PhaseMacroExpand(PhaseIterGVN &igvn) : Phase(Macro_Expand), _igvn(igvn) {
215 _igvn.set_delay_transform(true);
216 }
217 void eliminate_macro_nodes();
218 bool expand_macro_nodes();
219
220 SafePointScalarObjectNode* create_scalarized_object_description(AllocateNode *alloc, SafePointNode* sfpt, Unique_Node_List* value_worklist);
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); }
|