1 /* 2 * Copyright (c) 2005, 2015, 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 * 23 */ 24 25 #ifndef SHARE_VM_OPTO_MACRO_HPP 26 #define SHARE_VM_OPTO_MACRO_HPP 27 28 #include "opto/phase.hpp" 29 30 class AllocateNode; 31 class AllocateArrayNode; 32 class CallNode; 33 class Node; 34 class PhaseIterGVN; 35 36 class PhaseMacroExpand : public Phase { 37 private: 38 PhaseIterGVN &_igvn; 39 40 // Helper methods roughly modeled after GraphKit: 41 Node* basic_plus_adr(Node* base, int offset) { 42 return (offset == 0)? base: basic_plus_adr(base, MakeConX(offset)); 43 } 44 Node* basic_plus_adr(Node* base, Node* ptr, int offset) { 45 return (offset == 0)? ptr: basic_plus_adr(base, ptr, MakeConX(offset)); 46 } 47 Node* basic_plus_adr(Node* base, Node* offset) { 48 return basic_plus_adr(base, base, offset); 49 } 50 Node* basic_plus_adr(Node* base, Node* ptr, Node* offset) { 51 Node* adr = new AddPNode(base, ptr, offset); 52 return transform_later(adr); 53 } 54 Node* transform_later(Node* n) { 55 // equivalent to _gvn.transform in GraphKit, Ideal, etc. 56 _igvn.register_new_node_with_optimizer(n); 57 return n; 58 } 59 void set_eden_pointers(Node* &eden_top_adr, Node* &eden_end_adr); 60 Node* make_load( Node* ctl, Node* mem, Node* base, int offset, 61 const Type* value_type, BasicType bt); 62 Node* make_store(Node* ctl, Node* mem, Node* base, int offset, 63 Node* value, BasicType bt); 64 65 // projections extracted from a call node 66 ProjNode *_fallthroughproj; 67 ProjNode *_fallthroughcatchproj; 68 ProjNode *_ioproj_fallthrough; 69 ProjNode *_ioproj_catchall; 70 ProjNode *_catchallcatchproj; 71 ProjNode *_memproj_fallthrough; 72 ProjNode *_memproj_catchall; 73 ProjNode *_resproj; 74 75 // Additional data collected during macro expansion 76 bool _has_locks; 77 78 void expand_allocate(AllocateNode *alloc); 79 void expand_allocate_array(AllocateArrayNode *alloc); 80 void expand_allocate_common(AllocateNode* alloc, 81 Node* length, 82 const TypeFunc* slow_call_type, 83 address slow_call_address); 84 Node *value_from_mem(Node *mem, Node *ctl, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, AllocateNode *alloc); 85 Node *value_from_mem_phi(Node *mem, BasicType ft, const Type *ftype, const TypeOopPtr *adr_t, AllocateNode *alloc, Node_Stack *value_phis, int level); 86 87 bool eliminate_boxing_node(CallStaticJavaNode *boxing); 88 bool eliminate_allocate_node(AllocateNode *alloc); 89 bool can_eliminate_allocation(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints); 90 bool scalar_replacement(AllocateNode *alloc, GrowableArray <SafePointNode *>& safepoints_done); 91 void process_users_of_allocation(CallNode *alloc); 92 93 void eliminate_gc_barrier(Node *p2x); 94 void mark_eliminated_box(Node* box, Node* obj); 95 void mark_eliminated_locking_nodes(AbstractLockNode *alock); 96 bool eliminate_locking_node(AbstractLockNode *alock); 97 void expand_lock_node(LockNode *lock); 98 void expand_unlock_node(UnlockNode *unlock); 99 100 // More helper methods modeled after GraphKit for array copy 101 void insert_mem_bar(Node** ctrl, Node** mem, int opcode, Node* precedent = NULL); 102 Node* array_element_address(Node* ary, Node* idx, BasicType elembt); 103 Node* ConvI2L(Node* offset); 104 Node* make_leaf_call(Node* ctrl, Node* mem, 105 const TypeFunc* call_type, address call_addr, 106 const char* call_name, 107 const TypePtr* adr_type, 108 Node* parm0 = NULL, Node* parm1 = NULL, 109 Node* parm2 = NULL, Node* parm3 = NULL, 110 Node* parm4 = NULL, Node* parm5 = NULL, 111 Node* parm6 = NULL, Node* parm7 = NULL); 112 113 // helper methods modeled after LibraryCallKit for array copy 114 Node* generate_guard(Node** ctrl, Node* test, RegionNode* region, float true_prob); 115 Node* generate_slow_guard(Node** ctrl, Node* test, RegionNode* region); 116 void generate_negative_guard(Node** ctrl, Node* index, RegionNode* region); 117 void generate_limit_guard(Node** ctrl, Node* offset, Node* subseq_length, Node* array_length, RegionNode* region); 118 119 // More helper methods for array copy 120 Node* generate_nonpositive_guard(Node** ctrl, Node* index, bool never_negative); 121 void finish_arraycopy_call(Node* call, Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type); 122 address basictype2arraycopy(BasicType t, 123 Node* src_offset, 124 Node* dest_offset, 125 bool disjoint_bases, 126 const char* &name, 127 bool dest_uninitialized); 128 Node* generate_arraycopy(ArrayCopyNode *ac, 129 AllocateArrayNode* alloc, 130 Node** ctrl, MergeMemNode* mem, Node** io, 131 const TypePtr* adr_type, 132 BasicType basic_elem_type, 133 Node* src, Node* src_offset, 134 Node* dest, Node* dest_offset, 135 Node* copy_length, 136 bool disjoint_bases = false, 137 bool length_never_negative = false, 138 RegionNode* slow_region = NULL); 139 void generate_clear_array(Node* ctrl, MergeMemNode* merge_mem, 140 const TypePtr* adr_type, 141 Node* dest, 142 BasicType basic_elem_type, 143 Node* slice_idx, 144 Node* slice_len, 145 Node* dest_size); 146 bool generate_block_arraycopy(Node** ctrl, MergeMemNode** mem, Node* io, 147 const TypePtr* adr_type, 148 BasicType basic_elem_type, 149 AllocateNode* alloc, 150 Node* src, Node* src_offset, 151 Node* dest, Node* dest_offset, 152 Node* dest_size, bool dest_uninitialized); 153 MergeMemNode* generate_slow_arraycopy(ArrayCopyNode *ac, 154 Node** ctrl, Node* mem, Node** io, 155 const TypePtr* adr_type, 156 Node* src, Node* src_offset, 157 Node* dest, Node* dest_offset, 158 Node* copy_length, bool dest_uninitialized); 159 Node* generate_checkcast_arraycopy(Node** ctrl, MergeMemNode** mem, 160 const TypePtr* adr_type, 161 Node* dest_elem_klass, 162 Node* src, Node* src_offset, 163 Node* dest, Node* dest_offset, 164 Node* copy_length, bool dest_uninitialized); 165 Node* generate_generic_arraycopy(Node** ctrl, MergeMemNode** mem, 166 const TypePtr* adr_type, 167 Node* src, Node* src_offset, 168 Node* dest, Node* dest_offset, 169 Node* copy_length, bool dest_uninitialized); 170 void generate_unchecked_arraycopy(Node** ctrl, MergeMemNode** mem, 171 const TypePtr* adr_type, 172 BasicType basic_elem_type, 173 bool disjoint_bases, 174 Node* src, Node* src_offset, 175 Node* dest, Node* dest_offset, 176 Node* copy_length, bool dest_uninitialized); 177 178 void expand_arraycopy_node(ArrayCopyNode *ac); 179 180 int replace_input(Node *use, Node *oldref, Node *newref); 181 void copy_call_debug_info(CallNode *oldcall, CallNode * newcall); 182 Node* opt_bits_test(Node* ctrl, Node* region, int edge, Node* word, int mask, int bits, bool return_fast_path = false); 183 void copy_predefined_input_for_runtime_call(Node * ctrl, CallNode* oldcall, CallNode* call); 184 CallNode* make_slow_call(CallNode *oldcall, const TypeFunc* slow_call_type, address slow_call, 185 const char* leaf_name, Node* slow_path, Node* parm0, Node* parm1, 186 Node* parm2); 187 void extract_call_projections(CallNode *call); 188 189 Node* initialize_object(AllocateNode* alloc, 190 Node* control, Node* rawmem, Node* object, 191 Node* klass_node, Node* length, 192 Node* size_in_bytes); 193 194 Node* prefetch_allocation(Node* i_o, 195 Node*& needgc_false, Node*& contended_phi_rawmem, 196 Node* old_eden_top, Node* new_eden_top, 197 Node* length); 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 // Members accessed from BarrierSetC2 209 void replace_node(Node* source, Node* target) { _igvn.replace_node(source, target); } 210 Node* intcon(jint con) const { return _igvn.intcon(con); } 211 Node* longcon(jlong con) const { return _igvn.longcon(con); } 212 Node* makecon(const Type *t) const { return _igvn.makecon(t); } 213 Node* top() const { return C->top(); } 214 }; 215 216 #endif // SHARE_VM_OPTO_MACRO_HPP