36 #include "libadt/vectset.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/methodData.hpp"
39 #include "opto/idealGraphPrinter.hpp"
40 #include "opto/phasetype.hpp"
41 #include "opto/phase.hpp"
42 #include "opto/regmask.hpp"
43 #include "runtime/deoptimization.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/timerTrace.hpp"
46 #include "runtime/vmThread.hpp"
47 #include "utilities/ticks.hpp"
48 #include "utilities/vmEnums.hpp"
49 #include "opto/printinlining.hpp"
50
51 class AbstractLockNode;
52 class AddPNode;
53 class Block;
54 class Bundle;
55 class CallGenerator;
56 class CallStaticJavaNode;
57 class CloneMap;
58 class CompilationFailureInfo;
59 class ConnectionGraph;
60 class IdealGraphPrinter;
61 class InlineTree;
62 class Matcher;
63 class MachConstantNode;
64 class MachConstantBaseNode;
65 class MachNode;
66 class MachOper;
67 class MachSafePointNode;
68 class Node;
69 class Node_Array;
70 class Node_List;
71 class Node_Notes;
72 class NodeHash;
73 class NodeCloneInfo;
74 class OpaqueTemplateAssertionPredicateNode;
75 class OptoReg;
79 class PhaseIterGVN;
80 class PhaseRegAlloc;
81 class PhaseCCP;
82 class PhaseOutput;
83 class RootNode;
84 class relocInfo;
85 class StartNode;
86 class SafePointNode;
87 class JVMState;
88 class Type;
89 class TypeInt;
90 class TypeInteger;
91 class TypeKlassPtr;
92 class TypePtr;
93 class TypeOopPtr;
94 class TypeFunc;
95 class TypeVect;
96 class Type_Array;
97 class Unique_Node_List;
98 class UnstableIfTrap;
99 class nmethod;
100 class Node_Stack;
101 struct Final_Reshape_Counts;
102 class VerifyMeetResult;
103
104 enum LoopOptsMode {
105 LoopOptsDefault,
106 LoopOptsNone,
107 LoopOptsMaxUnroll,
108 LoopOptsShenandoahExpand,
109 LoopOptsSkipSplitIf,
110 LoopOptsVerify
111 };
112
113 // The type of all node counts and indexes.
114 // It must hold at least 16 bits, but must also be fast to load and store.
115 // This type, if less than 32 bits, could limit the number of possible nodes.
116 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
117 typedef unsigned int node_idx_t;
118
314 int _max_inline_size; // Max inline size for this compilation
315 int _freq_inline_size; // Max hot method inline size for this compilation
316 int _fixed_slots; // count of frame slots not allocated by the register
317 // allocator i.e. locks, original deopt pc, etc.
318 uintx _max_node_limit; // Max unique node count during a single compilation.
319
320 bool _post_loop_opts_phase; // Loop opts are finished.
321 bool _merge_stores_phase; // Phase for merging stores, after post loop opts phase.
322 bool _allow_macro_nodes; // True if we allow creation of macro nodes.
323
324 int _major_progress; // Count of something big happening
325 bool _inlining_progress; // progress doing incremental inlining?
326 bool _inlining_incrementally;// Are we doing incremental inlining (post parse)
327 bool _do_cleanup; // Cleanup is needed before proceeding with incremental inlining
328 bool _has_loops; // True if the method _may_ have some loops
329 bool _has_split_ifs; // True if the method _may_ have some split-if
330 bool _has_unsafe_access; // True if the method _may_ produce faults in unsafe loads or stores.
331 bool _has_stringbuilder; // True StringBuffers or StringBuilders are allocated
332 bool _has_boxed_value; // True if a boxed object is allocated
333 bool _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess
334 uint _max_vector_size; // Maximum size of generated vectors
335 bool _clear_upper_avx; // Clear upper bits of ymm registers using vzeroupper
336 uint _trap_hist[trapHistLength]; // Cumulative traps
337 bool _trap_can_recompile; // Have we emitted a recompiling trap?
338 uint _decompile_count; // Cumulative decompilation counts.
339 bool _do_inlining; // True if we intend to do inlining
340 bool _do_scheduling; // True if we intend to do scheduling
341 bool _do_freq_based_layout; // True if we intend to do frequency based block layout
342 bool _do_vector_loop; // True if allowed to execute loop in parallel iterations
343 bool _use_cmove; // True if CMove should be used without profitability analysis
344 bool _do_aliasing; // True if we intend to do aliasing
345 bool _print_assembly; // True if we should dump assembly code for this compilation
346 bool _print_inlining; // True if we should print inlining for this compilation
347 bool _print_intrinsics; // True if we should print intrinsics for this compilation
348 #ifndef PRODUCT
349 uint _igv_idx; // Counter for IGV node identifiers
350 uint _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
351 bool _trace_opto_output;
352 bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
353 #endif
354 bool _has_irreducible_loop; // Found irreducible loops
355 // JSR 292
356 bool _has_method_handle_invokes; // True if this method has MethodHandle invokes.
357 bool _has_monitors; // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
358 bool _has_scoped_access; // For shared scope closure
359 bool _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
360 int _loop_opts_cnt; // loop opts round
361 uint _stress_seed; // Seed for stress testing
362
363 // Compilation environment.
364 Arena _comp_arena; // Arena with lifetime equivalent to Compile
365 void* _barrier_set_state; // Potential GC barrier state for Compile
366 ciEnv* _env; // CI interface
367 DirectiveSet* _directive; // Compiler directive
368 CompileLog* _log; // from CompilerThread
369 CHeapStringHolder _failure_reason; // for record_failure/failing pattern
370 CompilationFailureInfo* _first_failure_details; // Details for the first failure happening during compilation
371 GrowableArray<CallGenerator*> _intrinsics; // List of intrinsics.
372 GrowableArray<Node*> _macro_nodes; // List of nodes which need to be expanded before matching.
373 GrowableArray<ParsePredicateNode*> _parse_predicates; // List of Parse Predicates.
374 // List of OpaqueTemplateAssertionPredicateNode nodes for Template Assertion Predicates which can be seen as list
375 // of Template Assertion Predicates themselves.
376 GrowableArray<OpaqueTemplateAssertionPredicateNode*> _template_assertion_predicate_opaques;
377 GrowableArray<Node*> _expensive_nodes; // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
378 GrowableArray<Node*> _for_post_loop_igvn; // List of nodes for IGVN after loop opts are over
379 GrowableArray<Node*> _for_merge_stores_igvn; // List of nodes for IGVN merge stores
380 GrowableArray<UnstableIfTrap*> _unstable_if_traps; // List of ifnodes after IGVN
381 GrowableArray<Node_List*> _coarsened_locks; // List of coarsened Lock and Unlock nodes
382 ConnectionGraph* _congraph;
383 #ifndef PRODUCT
384 IdealGraphPrinter* _igv_printer;
385 static IdealGraphPrinter* _debug_file_printer;
386 static IdealGraphPrinter* _debug_network_printer;
387 #endif
388
389
390 // Node management
391 uint _unique; // Counter for unique Node indices
392 uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N).
393 // So use this to keep count and make the call O(1).
394 VectorSet _dead_node_list; // Set of dead nodes
395 DEBUG_ONLY(Unique_Node_List* _modified_nodes;) // List of nodes which inputs were modified
396 DEBUG_ONLY(bool _phase_optimize_finished;) // Used for live node verification while creating new nodes
397
398 DEBUG_ONLY(bool _phase_verify_ideal_loop;) // Are we in PhaseIdealLoop verification?
585 int do_cleanup() const { return _do_cleanup; }
586 void set_major_progress() { _major_progress++; }
587 void restore_major_progress(int progress) { _major_progress += progress; }
588 void clear_major_progress() { _major_progress = 0; }
589 int max_inline_size() const { return _max_inline_size; }
590 void set_freq_inline_size(int n) { _freq_inline_size = n; }
591 int freq_inline_size() const { return _freq_inline_size; }
592 void set_max_inline_size(int n) { _max_inline_size = n; }
593 bool has_loops() const { return _has_loops; }
594 void set_has_loops(bool z) { _has_loops = z; }
595 bool has_split_ifs() const { return _has_split_ifs; }
596 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
597 bool has_unsafe_access() const { return _has_unsafe_access; }
598 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
599 bool has_stringbuilder() const { return _has_stringbuilder; }
600 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
601 bool has_boxed_value() const { return _has_boxed_value; }
602 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
603 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
604 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
605 uint max_vector_size() const { return _max_vector_size; }
606 void set_max_vector_size(uint s) { _max_vector_size = s; }
607 bool clear_upper_avx() const { return _clear_upper_avx; }
608 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
609 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
610 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
611 bool trap_can_recompile() const { return _trap_can_recompile; }
612 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
613 uint decompile_count() const { return _decompile_count; }
614 void set_decompile_count(uint c) { _decompile_count = c; }
615 bool allow_range_check_smearing() const;
616 bool do_inlining() const { return _do_inlining; }
617 void set_do_inlining(bool z) { _do_inlining = z; }
618 bool do_scheduling() const { return _do_scheduling; }
619 void set_do_scheduling(bool z) { _do_scheduling = z; }
620 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
621 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
622 bool do_vector_loop() const { return _do_vector_loop; }
623 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
624 bool use_cmove() const { return _use_cmove; }
625 void set_use_cmove(bool z) { _use_cmove = z; }
626 bool do_aliasing() const { return _do_aliasing; }
627 bool print_assembly() const { return _print_assembly; }
628 void set_print_assembly(bool z) { _print_assembly = z; }
629 bool print_inlining() const { return _print_inlining; }
630 void set_print_inlining(bool z) { _print_inlining = z; }
631 bool print_intrinsics() const { return _print_intrinsics; }
632 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
633 uint max_node_limit() const { return (uint)_max_node_limit; }
634 void set_max_node_limit(uint n) { _max_node_limit = n; }
635 bool clinit_barrier_on_entry() { return _clinit_barrier_on_entry; }
636 void set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
637 bool has_monitors() const { return _has_monitors; }
638 void set_has_monitors(bool v) { _has_monitors = v; }
639 bool has_scoped_access() const { return _has_scoped_access; }
640 void set_has_scoped_access(bool v) { _has_scoped_access = v; }
641
642 // check the CompilerOracle for special behaviours for this compile
643 bool method_has_option(CompileCommandEnum option) {
644 return method() != nullptr && method()->has_option(option);
645 }
646
647 #ifndef PRODUCT
648 uint next_igv_idx() { return _igv_idx++; }
649 bool trace_opto_output() const { return _trace_opto_output; }
650 void print_ideal_ir(const char* phase_name);
651 bool should_print_ideal() const { return _directive->PrintIdealOption; }
652 bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
653 void set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
654 int _in_dump_cnt; // Required for dumping ir nodes.
655 #endif
656 bool has_irreducible_loop() const { return _has_irreducible_loop; }
750 bool coarsened_locks_consistent();
751 void mark_unbalanced_boxes() const;
752
753 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
754 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
755 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
756
757 #ifdef ASSERT
758 bool phase_verify_ideal_loop() const { return _phase_verify_ideal_loop; }
759 void set_phase_verify_ideal_loop() { _phase_verify_ideal_loop = true; }
760 void reset_phase_verify_ideal_loop() { _phase_verify_ideal_loop = false; }
761 #endif
762
763 bool allow_macro_nodes() { return _allow_macro_nodes; }
764 void reset_allow_macro_nodes() { _allow_macro_nodes = false; }
765
766 void record_for_post_loop_opts_igvn(Node* n);
767 void remove_from_post_loop_opts_igvn(Node* n);
768 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
769
770 void record_unstable_if_trap(UnstableIfTrap* trap);
771 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
772 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
773 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
774
775 bool merge_stores_phase() { return _merge_stores_phase; }
776 void set_merge_stores_phase() { _merge_stores_phase = true; }
777 void record_for_merge_stores_igvn(Node* n);
778 void remove_from_merge_stores_igvn(Node* n);
779 void process_for_merge_stores_igvn(PhaseIterGVN& igvn);
780
781 void shuffle_macro_nodes();
782 void sort_macro_nodes();
783
784 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
785
786 // Are there candidate expensive nodes for optimization?
787 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
788 // Check whether n1 and n2 are similar
789 static int cmp_expensive_nodes(Node* n1, Node* n2);
932 Arena* type_arena() { return _type_arena; }
933 Dict* type_dict() { return _type_dict; }
934 size_t type_last_size() { return _type_last_size; }
935 int num_alias_types() { return _num_alias_types; }
936
937 void init_type_arena() { _type_arena = &_Compile_types; }
938 void set_type_arena(Arena* a) { _type_arena = a; }
939 void set_type_dict(Dict* d) { _type_dict = d; }
940 void set_type_last_size(size_t sz) { _type_last_size = sz; }
941
942 const TypeFunc* last_tf(ciMethod* m) {
943 return (m == _last_tf_m) ? _last_tf : nullptr;
944 }
945 void set_last_tf(ciMethod* m, const TypeFunc* tf) {
946 assert(m != nullptr || tf == nullptr, "");
947 _last_tf_m = m;
948 _last_tf = tf;
949 }
950
951 AliasType* alias_type(int idx) { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
952 AliasType* alias_type(const TypePtr* adr_type, ciField* field = nullptr) { return find_alias_type(adr_type, false, field); }
953 bool have_alias_type(const TypePtr* adr_type);
954 AliasType* alias_type(ciField* field);
955
956 int get_alias_index(const TypePtr* at) { return alias_type(at)->index(); }
957 const TypePtr* get_adr_type(uint aidx) { return alias_type(aidx)->adr_type(); }
958 int get_general_index(uint aidx) { return alias_type(aidx)->general_index(); }
959
960 // Building nodes
961 void rethrow_exceptions(JVMState* jvms);
962 void return_values(JVMState* jvms);
963 JVMState* build_start_state(StartNode* start, const TypeFunc* tf);
964
965 // Decide how to build a call.
966 // The profile factor is a discount to apply to this site's interp. profile.
967 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
968 JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
969 bool allow_intrinsics = true);
970 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
971 return should_delay_string_inlining(call_method, jvms) ||
972 should_delay_boxing_inlining(call_method, jvms) ||
973 should_delay_vector_inlining(call_method, jvms);
974 }
975 bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
976 bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
1177 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1178 // for calls to C. Supports the var-args backing area for register parms.
1179 uint varargs_C_out_slots_killed() const;
1180
1181 // Number of Stack Slots consumed by a synchronization entry
1182 int sync_stack_slots() const;
1183
1184 // Compute the name of old_SP. See <arch>.ad for frame layout.
1185 OptoReg::Name compute_old_SP();
1186
1187 private:
1188 // Phase control:
1189 void Init(bool aliasing); // Prepare for a single compilation
1190 void Optimize(); // Given a graph, optimize it
1191 void Code_Gen(); // Generate code from a graph
1192
1193 // Management of the AliasType table.
1194 void grow_alias_types();
1195 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1196 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1197 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field);
1198
1199 void verify_top(Node*) const PRODUCT_RETURN;
1200
1201 // Intrinsic setup.
1202 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1203 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1204 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1205 void register_intrinsic(CallGenerator* cg); // update fn
1206
1207 #ifndef PRODUCT
1208 static juint _intrinsic_hist_count[];
1209 static jubyte _intrinsic_hist_flags[];
1210 #endif
1211 // Function calls made by the public function final_graph_reshaping.
1212 // No need to be made public as they are not called elsewhere.
1213 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1214 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1215 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1216 void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1217
1267 // End-of-run dumps.
1268 static void print_statistics() PRODUCT_RETURN;
1269
1270 // Verify ADLC assumptions during startup
1271 static void adlc_verification() PRODUCT_RETURN;
1272
1273 // Definitions of pd methods
1274 static void pd_compiler2_init();
1275
1276 // Static parse-time type checking logic for gen_subtype_check:
1277 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1278 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1279
1280 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1281 // Optional control dependency (for example, on range check)
1282 Node* ctrl = nullptr);
1283
1284 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1285 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1286
1287 // Auxiliary methods for randomized fuzzing/stressing
1288 int random();
1289 bool randomized_select(int count);
1290
1291 // seed random number generation and log the seed for repeatability.
1292 void initialize_stress_seed(const DirectiveSet* directive);
1293
1294 // supporting clone_map
1295 CloneMap& clone_map();
1296 void set_clone_map(Dict* d);
1297
1298 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1299 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1300 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1301
1302 #ifdef ASSERT
1303 VerifyMeetResult* _type_verify;
1304 void set_exception_backedge() { _exception_backedge = true; }
1305 bool has_exception_backedge() const { return _exception_backedge; }
1306 #endif
1307
|
36 #include "libadt/vectset.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/methodData.hpp"
39 #include "opto/idealGraphPrinter.hpp"
40 #include "opto/phasetype.hpp"
41 #include "opto/phase.hpp"
42 #include "opto/regmask.hpp"
43 #include "runtime/deoptimization.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/timerTrace.hpp"
46 #include "runtime/vmThread.hpp"
47 #include "utilities/ticks.hpp"
48 #include "utilities/vmEnums.hpp"
49 #include "opto/printinlining.hpp"
50
51 class AbstractLockNode;
52 class AddPNode;
53 class Block;
54 class Bundle;
55 class CallGenerator;
56 class CallNode;
57 class CallStaticJavaNode;
58 class CloneMap;
59 class CompilationFailureInfo;
60 class ConnectionGraph;
61 class IdealGraphPrinter;
62 class InlineTree;
63 class Matcher;
64 class MachConstantNode;
65 class MachConstantBaseNode;
66 class MachNode;
67 class MachOper;
68 class MachSafePointNode;
69 class Node;
70 class Node_Array;
71 class Node_List;
72 class Node_Notes;
73 class NodeHash;
74 class NodeCloneInfo;
75 class OpaqueTemplateAssertionPredicateNode;
76 class OptoReg;
80 class PhaseIterGVN;
81 class PhaseRegAlloc;
82 class PhaseCCP;
83 class PhaseOutput;
84 class RootNode;
85 class relocInfo;
86 class StartNode;
87 class SafePointNode;
88 class JVMState;
89 class Type;
90 class TypeInt;
91 class TypeInteger;
92 class TypeKlassPtr;
93 class TypePtr;
94 class TypeOopPtr;
95 class TypeFunc;
96 class TypeVect;
97 class Type_Array;
98 class Unique_Node_List;
99 class UnstableIfTrap;
100 class InlineTypeNode;
101 class nmethod;
102 class Node_Stack;
103 struct Final_Reshape_Counts;
104 class VerifyMeetResult;
105
106 enum LoopOptsMode {
107 LoopOptsDefault,
108 LoopOptsNone,
109 LoopOptsMaxUnroll,
110 LoopOptsShenandoahExpand,
111 LoopOptsSkipSplitIf,
112 LoopOptsVerify
113 };
114
115 // The type of all node counts and indexes.
116 // It must hold at least 16 bits, but must also be fast to load and store.
117 // This type, if less than 32 bits, could limit the number of possible nodes.
118 // (To make this type platform-specific, move to globalDefinitions_xxx.hpp.)
119 typedef unsigned int node_idx_t;
120
316 int _max_inline_size; // Max inline size for this compilation
317 int _freq_inline_size; // Max hot method inline size for this compilation
318 int _fixed_slots; // count of frame slots not allocated by the register
319 // allocator i.e. locks, original deopt pc, etc.
320 uintx _max_node_limit; // Max unique node count during a single compilation.
321
322 bool _post_loop_opts_phase; // Loop opts are finished.
323 bool _merge_stores_phase; // Phase for merging stores, after post loop opts phase.
324 bool _allow_macro_nodes; // True if we allow creation of macro nodes.
325
326 int _major_progress; // Count of something big happening
327 bool _inlining_progress; // progress doing incremental inlining?
328 bool _inlining_incrementally;// Are we doing incremental inlining (post parse)
329 bool _do_cleanup; // Cleanup is needed before proceeding with incremental inlining
330 bool _has_loops; // True if the method _may_ have some loops
331 bool _has_split_ifs; // True if the method _may_ have some split-if
332 bool _has_unsafe_access; // True if the method _may_ produce faults in unsafe loads or stores.
333 bool _has_stringbuilder; // True StringBuffers or StringBuilders are allocated
334 bool _has_boxed_value; // True if a boxed object is allocated
335 bool _has_reserved_stack_access; // True if the method or an inlined method is annotated with ReservedStackAccess
336 bool _has_circular_inline_type; // True if method loads an inline type with a circular, non-flat field
337 uint _max_vector_size; // Maximum size of generated vectors
338 bool _clear_upper_avx; // Clear upper bits of ymm registers using vzeroupper
339 uint _trap_hist[trapHistLength]; // Cumulative traps
340 bool _trap_can_recompile; // Have we emitted a recompiling trap?
341 uint _decompile_count; // Cumulative decompilation counts.
342 bool _do_inlining; // True if we intend to do inlining
343 bool _do_scheduling; // True if we intend to do scheduling
344 bool _do_freq_based_layout; // True if we intend to do frequency based block layout
345 bool _do_vector_loop; // True if allowed to execute loop in parallel iterations
346 bool _use_cmove; // True if CMove should be used without profitability analysis
347 bool _do_aliasing; // True if we intend to do aliasing
348 bool _print_assembly; // True if we should dump assembly code for this compilation
349 bool _print_inlining; // True if we should print inlining for this compilation
350 bool _print_intrinsics; // True if we should print intrinsics for this compilation
351 #ifndef PRODUCT
352 uint _igv_idx; // Counter for IGV node identifiers
353 uint _igv_phase_iter[PHASE_NUM_TYPES]; // Counters for IGV phase iterations
354 bool _trace_opto_output;
355 bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
356 #endif
357 bool _has_irreducible_loop; // Found irreducible loops
358 // JSR 292
359 bool _has_method_handle_invokes; // True if this method has MethodHandle invokes.
360 bool _has_monitors; // Metadata transfered to nmethod to enable Continuations lock-detection fastpath
361 bool _has_scoped_access; // For shared scope closure
362 bool _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry
363 int _loop_opts_cnt; // loop opts round
364 bool _has_flat_accesses; // Any known flat array accesses?
365 bool _flat_accesses_share_alias; // Initially all flat array share a single slice
366 bool _scalarize_in_safepoints; // Scalarize inline types in safepoint debug info
367 uint _stress_seed; // Seed for stress testing
368
369 // Compilation environment.
370 Arena _comp_arena; // Arena with lifetime equivalent to Compile
371 void* _barrier_set_state; // Potential GC barrier state for Compile
372 ciEnv* _env; // CI interface
373 DirectiveSet* _directive; // Compiler directive
374 CompileLog* _log; // from CompilerThread
375 CHeapStringHolder _failure_reason; // for record_failure/failing pattern
376 CompilationFailureInfo* _first_failure_details; // Details for the first failure happening during compilation
377 GrowableArray<CallGenerator*> _intrinsics; // List of intrinsics.
378 GrowableArray<Node*> _macro_nodes; // List of nodes which need to be expanded before matching.
379 GrowableArray<ParsePredicateNode*> _parse_predicates; // List of Parse Predicates.
380 // List of OpaqueTemplateAssertionPredicateNode nodes for Template Assertion Predicates which can be seen as list
381 // of Template Assertion Predicates themselves.
382 GrowableArray<OpaqueTemplateAssertionPredicateNode*> _template_assertion_predicate_opaques;
383 GrowableArray<Node*> _expensive_nodes; // List of nodes that are expensive to compute and that we'd better not let the GVN freely common
384 GrowableArray<Node*> _for_post_loop_igvn; // List of nodes for IGVN after loop opts are over
385 GrowableArray<Node*> _inline_type_nodes; // List of InlineType nodes
386 GrowableArray<Node*> _for_merge_stores_igvn; // List of nodes for IGVN merge stores
387 GrowableArray<UnstableIfTrap*> _unstable_if_traps; // List of ifnodes after IGVN
388 GrowableArray<Node_List*> _coarsened_locks; // List of coarsened Lock and Unlock nodes
389 ConnectionGraph* _congraph;
390 #ifndef PRODUCT
391 IdealGraphPrinter* _igv_printer;
392 static IdealGraphPrinter* _debug_file_printer;
393 static IdealGraphPrinter* _debug_network_printer;
394 #endif
395
396
397 // Node management
398 uint _unique; // Counter for unique Node indices
399 uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N).
400 // So use this to keep count and make the call O(1).
401 VectorSet _dead_node_list; // Set of dead nodes
402 DEBUG_ONLY(Unique_Node_List* _modified_nodes;) // List of nodes which inputs were modified
403 DEBUG_ONLY(bool _phase_optimize_finished;) // Used for live node verification while creating new nodes
404
405 DEBUG_ONLY(bool _phase_verify_ideal_loop;) // Are we in PhaseIdealLoop verification?
592 int do_cleanup() const { return _do_cleanup; }
593 void set_major_progress() { _major_progress++; }
594 void restore_major_progress(int progress) { _major_progress += progress; }
595 void clear_major_progress() { _major_progress = 0; }
596 int max_inline_size() const { return _max_inline_size; }
597 void set_freq_inline_size(int n) { _freq_inline_size = n; }
598 int freq_inline_size() const { return _freq_inline_size; }
599 void set_max_inline_size(int n) { _max_inline_size = n; }
600 bool has_loops() const { return _has_loops; }
601 void set_has_loops(bool z) { _has_loops = z; }
602 bool has_split_ifs() const { return _has_split_ifs; }
603 void set_has_split_ifs(bool z) { _has_split_ifs = z; }
604 bool has_unsafe_access() const { return _has_unsafe_access; }
605 void set_has_unsafe_access(bool z) { _has_unsafe_access = z; }
606 bool has_stringbuilder() const { return _has_stringbuilder; }
607 void set_has_stringbuilder(bool z) { _has_stringbuilder = z; }
608 bool has_boxed_value() const { return _has_boxed_value; }
609 void set_has_boxed_value(bool z) { _has_boxed_value = z; }
610 bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
611 void set_has_reserved_stack_access(bool z) { _has_reserved_stack_access = z; }
612 bool has_circular_inline_type() const { return _has_circular_inline_type; }
613 void set_has_circular_inline_type(bool z) { _has_circular_inline_type = z; }
614 uint max_vector_size() const { return _max_vector_size; }
615 void set_max_vector_size(uint s) { _max_vector_size = s; }
616 bool clear_upper_avx() const { return _clear_upper_avx; }
617 void set_clear_upper_avx(bool s) { _clear_upper_avx = s; }
618 void set_trap_count(uint r, uint c) { assert(r < trapHistLength, "oob"); _trap_hist[r] = c; }
619 uint trap_count(uint r) const { assert(r < trapHistLength, "oob"); return _trap_hist[r]; }
620 bool trap_can_recompile() const { return _trap_can_recompile; }
621 void set_trap_can_recompile(bool z) { _trap_can_recompile = z; }
622 uint decompile_count() const { return _decompile_count; }
623 void set_decompile_count(uint c) { _decompile_count = c; }
624 bool allow_range_check_smearing() const;
625 bool do_inlining() const { return _do_inlining; }
626 void set_do_inlining(bool z) { _do_inlining = z; }
627 bool do_scheduling() const { return _do_scheduling; }
628 void set_do_scheduling(bool z) { _do_scheduling = z; }
629 bool do_freq_based_layout() const{ return _do_freq_based_layout; }
630 void set_do_freq_based_layout(bool z){ _do_freq_based_layout = z; }
631 bool do_vector_loop() const { return _do_vector_loop; }
632 void set_do_vector_loop(bool z) { _do_vector_loop = z; }
633 bool use_cmove() const { return _use_cmove; }
634 void set_use_cmove(bool z) { _use_cmove = z; }
635 bool do_aliasing() const { return _do_aliasing; }
636 bool print_assembly() const { return _print_assembly; }
637 void set_print_assembly(bool z) { _print_assembly = z; }
638 bool print_inlining() const { return _print_inlining; }
639 void set_print_inlining(bool z) { _print_inlining = z; }
640 bool print_intrinsics() const { return _print_intrinsics; }
641 void set_print_intrinsics(bool z) { _print_intrinsics = z; }
642 uint max_node_limit() const { return (uint)_max_node_limit; }
643 void set_max_node_limit(uint n) { _max_node_limit = n; }
644 bool clinit_barrier_on_entry() { return _clinit_barrier_on_entry; }
645 void set_clinit_barrier_on_entry(bool z) { _clinit_barrier_on_entry = z; }
646 void set_flat_accesses() { _has_flat_accesses = true; }
647 bool flat_accesses_share_alias() const { return _flat_accesses_share_alias; }
648 void set_flat_accesses_share_alias(bool z) { _flat_accesses_share_alias = z; }
649 bool scalarize_in_safepoints() const { return _scalarize_in_safepoints; }
650 void set_scalarize_in_safepoints(bool z) { _scalarize_in_safepoints = z; }
651
652 // Support for scalarized inline type calling convention
653 bool has_scalarized_args() const { return _method != nullptr && _method->has_scalarized_args(); }
654 bool needs_stack_repair() const { return _method != nullptr && _method->get_Method()->c2_needs_stack_repair(); }
655
656 bool has_monitors() const { return _has_monitors; }
657 void set_has_monitors(bool v) { _has_monitors = v; }
658 bool has_scoped_access() const { return _has_scoped_access; }
659 void set_has_scoped_access(bool v) { _has_scoped_access = v; }
660
661 // check the CompilerOracle for special behaviours for this compile
662 bool method_has_option(CompileCommandEnum option) {
663 return method() != nullptr && method()->has_option(option);
664 }
665
666 #ifndef PRODUCT
667 uint next_igv_idx() { return _igv_idx++; }
668 bool trace_opto_output() const { return _trace_opto_output; }
669 void print_ideal_ir(const char* phase_name);
670 bool should_print_ideal() const { return _directive->PrintIdealOption; }
671 bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; }
672 void set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; }
673 int _in_dump_cnt; // Required for dumping ir nodes.
674 #endif
675 bool has_irreducible_loop() const { return _has_irreducible_loop; }
769 bool coarsened_locks_consistent();
770 void mark_unbalanced_boxes() const;
771
772 bool post_loop_opts_phase() { return _post_loop_opts_phase; }
773 void set_post_loop_opts_phase() { _post_loop_opts_phase = true; }
774 void reset_post_loop_opts_phase() { _post_loop_opts_phase = false; }
775
776 #ifdef ASSERT
777 bool phase_verify_ideal_loop() const { return _phase_verify_ideal_loop; }
778 void set_phase_verify_ideal_loop() { _phase_verify_ideal_loop = true; }
779 void reset_phase_verify_ideal_loop() { _phase_verify_ideal_loop = false; }
780 #endif
781
782 bool allow_macro_nodes() { return _allow_macro_nodes; }
783 void reset_allow_macro_nodes() { _allow_macro_nodes = false; }
784
785 void record_for_post_loop_opts_igvn(Node* n);
786 void remove_from_post_loop_opts_igvn(Node* n);
787 void process_for_post_loop_opts_igvn(PhaseIterGVN& igvn);
788
789 // Keep track of inline type nodes for later processing
790 void add_inline_type(Node* n);
791 void remove_inline_type(Node* n);
792 void process_inline_types(PhaseIterGVN &igvn, bool remove = false);
793
794 void adjust_flat_array_access_aliases(PhaseIterGVN& igvn);
795
796 void record_unstable_if_trap(UnstableIfTrap* trap);
797 bool remove_unstable_if_trap(CallStaticJavaNode* unc, bool yield);
798 void remove_useless_unstable_if_traps(Unique_Node_List &useful);
799 void process_for_unstable_if_traps(PhaseIterGVN& igvn);
800
801 bool merge_stores_phase() { return _merge_stores_phase; }
802 void set_merge_stores_phase() { _merge_stores_phase = true; }
803 void record_for_merge_stores_igvn(Node* n);
804 void remove_from_merge_stores_igvn(Node* n);
805 void process_for_merge_stores_igvn(PhaseIterGVN& igvn);
806
807 void shuffle_macro_nodes();
808 void sort_macro_nodes();
809
810 void mark_parse_predicate_nodes_useless(PhaseIterGVN& igvn);
811
812 // Are there candidate expensive nodes for optimization?
813 bool should_optimize_expensive_nodes(PhaseIterGVN &igvn);
814 // Check whether n1 and n2 are similar
815 static int cmp_expensive_nodes(Node* n1, Node* n2);
958 Arena* type_arena() { return _type_arena; }
959 Dict* type_dict() { return _type_dict; }
960 size_t type_last_size() { return _type_last_size; }
961 int num_alias_types() { return _num_alias_types; }
962
963 void init_type_arena() { _type_arena = &_Compile_types; }
964 void set_type_arena(Arena* a) { _type_arena = a; }
965 void set_type_dict(Dict* d) { _type_dict = d; }
966 void set_type_last_size(size_t sz) { _type_last_size = sz; }
967
968 const TypeFunc* last_tf(ciMethod* m) {
969 return (m == _last_tf_m) ? _last_tf : nullptr;
970 }
971 void set_last_tf(ciMethod* m, const TypeFunc* tf) {
972 assert(m != nullptr || tf == nullptr, "");
973 _last_tf_m = m;
974 _last_tf = tf;
975 }
976
977 AliasType* alias_type(int idx) { assert(idx < num_alias_types(), "oob"); return _alias_types[idx]; }
978 AliasType* alias_type(const TypePtr* adr_type, ciField* field = nullptr, bool uncached = false) { return find_alias_type(adr_type, false, field, uncached); }
979 bool have_alias_type(const TypePtr* adr_type);
980 AliasType* alias_type(ciField* field);
981
982 int get_alias_index(const TypePtr* at, bool uncached = false) { return alias_type(at, nullptr, uncached)->index(); }
983 const TypePtr* get_adr_type(uint aidx) { return alias_type(aidx)->adr_type(); }
984 int get_general_index(uint aidx) { return alias_type(aidx)->general_index(); }
985
986 // Building nodes
987 void rethrow_exceptions(JVMState* jvms);
988 void return_values(JVMState* jvms);
989 JVMState* build_start_state(StartNode* start, const TypeFunc* tf);
990
991 // Decide how to build a call.
992 // The profile factor is a discount to apply to this site's interp. profile.
993 CallGenerator* call_generator(ciMethod* call_method, int vtable_index, bool call_does_dispatch,
994 JVMState* jvms, bool allow_inline, float profile_factor, ciKlass* speculative_receiver_type = nullptr,
995 bool allow_intrinsics = true);
996 bool should_delay_inlining(ciMethod* call_method, JVMState* jvms) {
997 return should_delay_string_inlining(call_method, jvms) ||
998 should_delay_boxing_inlining(call_method, jvms) ||
999 should_delay_vector_inlining(call_method, jvms);
1000 }
1001 bool should_delay_string_inlining(ciMethod* call_method, JVMState* jvms);
1002 bool should_delay_boxing_inlining(ciMethod* call_method, JVMState* jvms);
1203 // Number of outgoing stack slots killed above the out_preserve_stack_slots
1204 // for calls to C. Supports the var-args backing area for register parms.
1205 uint varargs_C_out_slots_killed() const;
1206
1207 // Number of Stack Slots consumed by a synchronization entry
1208 int sync_stack_slots() const;
1209
1210 // Compute the name of old_SP. See <arch>.ad for frame layout.
1211 OptoReg::Name compute_old_SP();
1212
1213 private:
1214 // Phase control:
1215 void Init(bool aliasing); // Prepare for a single compilation
1216 void Optimize(); // Given a graph, optimize it
1217 void Code_Gen(); // Generate code from a graph
1218
1219 // Management of the AliasType table.
1220 void grow_alias_types();
1221 AliasCacheEntry* probe_alias_cache(const TypePtr* adr_type);
1222 const TypePtr *flatten_alias_type(const TypePtr* adr_type) const;
1223 AliasType* find_alias_type(const TypePtr* adr_type, bool no_create, ciField* field, bool uncached = false);
1224
1225 void verify_top(Node*) const PRODUCT_RETURN;
1226
1227 // Intrinsic setup.
1228 CallGenerator* make_vm_intrinsic(ciMethod* m, bool is_virtual); // constructor
1229 int intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found); // helper
1230 CallGenerator* find_intrinsic(ciMethod* m, bool is_virtual); // query fn
1231 void register_intrinsic(CallGenerator* cg); // update fn
1232
1233 #ifndef PRODUCT
1234 static juint _intrinsic_hist_count[];
1235 static jubyte _intrinsic_hist_flags[];
1236 #endif
1237 // Function calls made by the public function final_graph_reshaping.
1238 // No need to be made public as they are not called elsewhere.
1239 void final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1240 void final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop, Unique_Node_List& dead_nodes);
1241 void final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes);
1242 void handle_div_mod_op(Node* n, BasicType bt, bool is_unsigned);
1243
1293 // End-of-run dumps.
1294 static void print_statistics() PRODUCT_RETURN;
1295
1296 // Verify ADLC assumptions during startup
1297 static void adlc_verification() PRODUCT_RETURN;
1298
1299 // Definitions of pd methods
1300 static void pd_compiler2_init();
1301
1302 // Static parse-time type checking logic for gen_subtype_check:
1303 enum SubTypeCheckResult { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
1304 SubTypeCheckResult static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip = StressReflectiveCode);
1305
1306 static Node* conv_I2X_index(PhaseGVN* phase, Node* offset, const TypeInt* sizetype,
1307 // Optional control dependency (for example, on range check)
1308 Node* ctrl = nullptr);
1309
1310 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
1311 static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency = false);
1312
1313 Node* optimize_acmp(PhaseGVN* phase, Node* a, Node* b);
1314
1315 // Auxiliary method for randomized fuzzing/stressing
1316 int random();
1317 bool randomized_select(int count);
1318
1319 // seed random number generation and log the seed for repeatability.
1320 void initialize_stress_seed(const DirectiveSet* directive);
1321
1322 // supporting clone_map
1323 CloneMap& clone_map();
1324 void set_clone_map(Dict* d);
1325
1326 bool needs_clinit_barrier(ciField* ik, ciMethod* accessing_method);
1327 bool needs_clinit_barrier(ciMethod* ik, ciMethod* accessing_method);
1328 bool needs_clinit_barrier(ciInstanceKlass* ik, ciMethod* accessing_method);
1329
1330 #ifdef ASSERT
1331 VerifyMeetResult* _type_verify;
1332 void set_exception_backedge() { _exception_backedge = true; }
1333 bool has_exception_backedge() const { return _exception_backedge; }
1334 #endif
1335
|