-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathOMROptimizer.cpp
2823 lines (2500 loc) · 110 KB
/
OMROptimizer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright IBM Corp. and others 2000
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#include "optimizer/Optimizer.hpp"
#include "optimizer/Optimizer_inlines.hpp"
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "codegen/CodeGenerator.hpp"
#include "env/FrontEnd.hpp"
#include "compile/Compilation.hpp"
#include "compile/CompilationTypes.hpp"
#include "compile/Method.hpp"
#include "compile/SymbolReferenceTable.hpp"
#include "control/Options.hpp"
#include "control/Options_inlines.hpp"
#include "control/Recompilation.hpp"
#ifdef J9_PROJECT_SPECIFIC
#include "control/RecompilationInfo.hpp"
#endif
#include "env/CompilerEnv.hpp"
#include "env/IO.hpp"
#include "env/PersistentInfo.hpp"
#include "env/StackMemoryRegion.hpp"
#include "env/TRMemory.hpp"
#include "env/jittypes.h"
#include "il/Block.hpp"
#include "il/DataTypes.hpp"
#include "il/ILOpCodes.hpp"
#include "il/ILOps.hpp"
#include "il/Node.hpp"
#include "il/NodePool.hpp"
#include "il/Node_inlines.hpp"
#include "il/ResolvedMethodSymbol.hpp"
#include "il/Symbol.hpp"
#include "il/SymbolReference.hpp"
#include "il/TreeTop.hpp"
#include "il/TreeTop_inlines.hpp"
#include "infra/Assert.hpp"
#include "infra/BitVector.hpp"
#include "infra/Cfg.hpp"
#include "infra/List.hpp"
#include "infra/SimpleRegex.hpp"
#include "infra/CfgNode.hpp"
#include "infra/Timer.hpp"
#include "optimizer/LoadExtensions.hpp"
#include "optimizer/Optimization.hpp"
#include "optimizer/OptimizationManager.hpp"
#include "optimizer/OptimizationStrategies.hpp"
#include "optimizer/Optimizations.hpp"
#include "optimizer/Structure.hpp"
#include "optimizer/StructuralAnalysis.hpp"
#include "optimizer/UseDefInfo.hpp"
#include "optimizer/ValueNumberInfo.hpp"
#include "optimizer/AsyncCheckInsertion.hpp"
#include "optimizer/DeadStoreElimination.hpp"
#include "optimizer/DeadTreesElimination.hpp"
#include "optimizer/CatchBlockRemover.hpp"
#include "optimizer/CFGSimplifier.hpp"
#include "optimizer/CompactLocals.hpp"
#include "optimizer/CopyPropagation.hpp"
#include "optimizer/ExpressionsSimplification.hpp"
#include "optimizer/GeneralLoopUnroller.hpp"
#include "optimizer/LocalCSE.hpp"
#include "optimizer/LocalDeadStoreElimination.hpp"
#include "optimizer/LocalLiveRangeReducer.hpp"
#include "optimizer/LocalOpts.hpp"
#include "optimizer/LocalReordering.hpp"
#include "optimizer/LoopCanonicalizer.hpp"
#include "optimizer/LoopReducer.hpp"
#include "optimizer/LoopReplicator.hpp"
#include "optimizer/LoopVersioner.hpp"
#include "optimizer/OrderBlocks.hpp"
#include "optimizer/RedundantAsyncCheckRemoval.hpp"
#include "optimizer/Simplifier.hpp"
#include "optimizer/VirtualGuardCoalescer.hpp"
#include "optimizer/VirtualGuardHeadMerger.hpp"
#include "optimizer/Inliner.hpp"
#include "ras/Debug.hpp"
#include "optimizer/InductionVariable.hpp"
#include "optimizer/GlobalValuePropagation.hpp"
#include "optimizer/LocalValuePropagation.hpp"
#include "optimizer/RegDepCopyRemoval.hpp"
#include "optimizer/SinkStores.hpp"
#include "optimizer/PartialRedundancy.hpp"
#include "optimizer/OSRDefAnalysis.hpp"
#include "optimizer/StripMiner.hpp"
#include "optimizer/FieldPrivatizer.hpp"
#include "optimizer/ReorderIndexExpr.hpp"
#include "optimizer/GlobalRegisterAllocator.hpp"
#include "optimizer/RecognizedCallTransformer.hpp"
#include "optimizer/SwitchAnalyzer.hpp"
#include "env/RegionProfiler.hpp"
namespace TR { class AutomaticSymbol; }
using namespace OMR; // Note: used here only to avoid having to prepend all opts in strategies with OMR::
#define MAX_LOCAL_OPTS_ITERS 5
const OptimizationStrategy localValuePropagationOpts[] =
{
{ localCSE },
{ localValuePropagation },
{ localCSE, IfEnabled },
{ localValuePropagation, IfEnabled },
{ endGroup }
};
const OptimizationStrategy arrayPrivatizationOpts[] =
{
{ globalValuePropagation, IfMoreThanOneBlock}, // reduce # of null/bounds checks and setup iv info
{ veryCheapGlobalValuePropagationGroup, IfEnabled}, // enabled by blockVersioner
{ inductionVariableAnalysis, IfLoops },
{ loopCanonicalization, IfLoops }, // setup for any unrolling in arrayPrivatization
{ treeSimplification }, // get rid of null/bnd checks if possible
{ deadTreesElimination },
{ basicBlockOrdering, IfLoops }, // required for loop reduction
{ treesCleansing, IfLoops },
{ inductionVariableAnalysis, IfLoops }, // required for array Privatization
{ basicBlockOrdering, IfEnabled }, // cleanup if unrolling happened
{ globalValuePropagation, IfEnabledAndMoreThanOneBlock }, // ditto
{ endGroup }
};
// To be run just before PRE
const OptimizationStrategy reorderArrayIndexOpts[] =
{
{ inductionVariableAnalysis , IfLoops },// need to id the primary IVs
{ reorderArrayIndexExpr, IfLoops },// try to maximize loop invarient
//expressions in index calculations and be hoisted
{ endGroup }
};
const OptimizationStrategy cheapObjectAllocationOpts[] =
{
{ explicitNewInitialization, IfNews }, // do before local dead store
{ endGroup }
};
const OptimizationStrategy expensiveObjectAllocationOpts[] =
{
{ eachEscapeAnalysisPassGroup, IfEAOpportunities },
{ explicitNewInitialization, IfNews }, // do before local dead store
{ endGroup }
};
const OptimizationStrategy eachEscapeAnalysisPassOpts[] =
{
{ preEscapeAnalysis, IfOSR },
{ escapeAnalysis },
{ postEscapeAnalysis, IfOSR },
{ eachEscapeAnalysisPassGroup, IfEnabled }, // if another pass requested
{ endGroup }
};
const OptimizationStrategy veryCheapGlobalValuePropagationOpts[] =
{
{ globalValuePropagation, IfMoreThanOneBlock},
{ endGroup }
};
const OptimizationStrategy cheapGlobalValuePropagationOpts[] =
{
//{ catchBlockRemoval, },
{ CFGSimplification, IfOptServer }, // for WAS trace folding
{ treeSimplification, IfOptServer }, // for WAS trace folding
{ localCSE, IfEnabledAndOptServer }, // for WAS trace folding
{ treeSimplification, IfEnabledAndOptServer }, // for WAS trace folding
{ globalValuePropagation, IfLoopsMarkLastRun },
{ treeSimplification, IfEnabled },
{ cheapObjectAllocationGroup },
{ treeSimplification, IfEnabled },
{ catchBlockRemoval, IfEnabled }, // if checks were removed
{ osrExceptionEdgeRemoval }, // most inlining is done by now
{ globalValuePropagation, IfEnabledAndMoreThanOneBlockMarkLastRun}, // mark monitors requiring sync
{ virtualGuardTailSplitter, IfEnabled }, // merge virtual guards
{ CFGSimplification },
{ endGroup }
};
const OptimizationStrategy expensiveGlobalValuePropagationOpts[] =
{
///// { innerPreexistence },
{ CFGSimplification, IfOptServer }, // for WAS trace folding
{ treeSimplification, IfOptServer }, // for WAS trace folding
{ localCSE, IfEnabledAndOptServer }, // for WAS trace folding
{ treeSimplification, IfEnabled }, // may be enabled by inner prex
{ globalValuePropagation, IfMoreThanOneBlock },
{ treeSimplification, IfEnabled },
{ deadTreesElimination }, // clean up left-over accesses before escape analysis
#ifdef J9_PROJECT_SPECIFIC
{ expensiveObjectAllocationGroup },
#endif
{ globalValuePropagation, IfEnabledAndMoreThanOneBlock }, // if inlined a call or an object
{ treeSimplification, IfEnabled },
{ catchBlockRemoval, IfEnabled }, // if checks were removed
{ osrExceptionEdgeRemoval }, // most inlining is done by now
#ifdef J9_PROJECT_SPECIFIC
{ redundantMonitorElimination, IfEnabled }, // performed if method has monitors
{ redundantMonitorElimination, IfEnabled }, // performed if method has monitors
#endif
{ globalValuePropagation, IfEnabledAndMoreThanOneBlock }, // mark monitors requiring sync
{ virtualGuardTailSplitter, IfEnabled }, // merge virtual guards
{ CFGSimplification },
{ endGroup }
};
const OptimizationStrategy eachExpensiveGlobalValuePropagationOpts[] =
{
//{ blockSplitter },
/// { innerPreexistence },
{ globalValuePropagation, IfMoreThanOneBlock },
{ treeSimplification, IfEnabled },
{ veryCheapGlobalValuePropagationGroup, IfEnabled }, // enabled by blockversioner
{ deadTreesElimination }, // clean up left-over accesses before escape analysis
#ifdef J9_PROJECT_SPECIFIC
{ expensiveObjectAllocationGroup },
#endif
{ eachExpensiveGlobalValuePropagationGroup, IfEnabled }, // if inlining was done
{ endGroup }
};
const OptimizationStrategy veryExpensiveGlobalValuePropagationOpts[] =
{
{ eachExpensiveGlobalValuePropagationGroup },
//{ basicBlockHoisting, }, // merge block into pred and prepare for local dead store
{ localDeadStoreElimination }, // remove local/parm/some field stores
{ treeSimplification, IfEnabled },
{ catchBlockRemoval, IfEnabled }, // if checks were removed
{ osrExceptionEdgeRemoval }, // most inlining is done by now
#ifdef J9_PROJECT_SPECIFIC
{ redundantMonitorElimination, IfEnabled }, // performed if method has monitors
{ redundantMonitorElimination, IfEnabled }, // performed if method has monitors
#endif
{ globalValuePropagation, IfEnabledAndMoreThanOneBlock }, // mark monitors requiring syncs
{ virtualGuardTailSplitter, IfEnabled }, // merge virtual guards
{ CFGSimplification },
{ endGroup }
};
const OptimizationStrategy partialRedundancyEliminationOpts[] =
{
{ globalValuePropagation, IfMoreThanOneBlock }, // GVP (before PRE)
{ deadTreesElimination },
{ treeSimplification, IfEnabled },
{ treeSimplification }, // might fold expressions created by versioning/induction variables
{ treeSimplification, IfEnabled }, // Array length simplification shd be followed by reassoc before PRE
{ reorderArrayExprGroup, IfEnabled }, // maximize opportunities hoisting of index array expressions
{ partialRedundancyElimination, IfMoreThanOneBlock},
{ localCSE, }, // common up expression which can benefit EA
{ catchBlockRemoval, IfEnabled }, // if checks were removed
{ deadTreesElimination, IfEnabled }, // if checks were removed
{ compactNullChecks, IfEnabled }, // PRE creates explicit null checks in large numbers
{ localReordering, IfEnabled }, // PRE may create temp stores that can be moved closer to uses
{ globalValuePropagation, IfEnabledAndMoreThanOneBlockMarkLastRun }, // GVP (after PRE)
#ifdef J9_PROJECT_SPECIFIC
{ preEscapeAnalysis, IfOSR },
{ escapeAnalysis, IfEAOpportunitiesMarkLastRun }, // to stack-allocate after loopversioner and localCSE
{ postEscapeAnalysis, IfOSR },
#endif
{ basicBlockOrdering, IfLoops }, // early ordering with no extension
{ globalCopyPropagation, IfLoops }, // for Loop Versioner
{ loopVersionerGroup, IfEnabledAndLoops },
{ treeSimplification, IfEnabled }, // loop reduction block should be after PRE so that privatization
{ treesCleansing }, // clean up gotos in code and convert to fall-throughs for loop reducer
{ redundantGotoElimination, IfNotJitProfiling }, // clean up for loop reducer. Note: NEVER run this before PRE
{ loopReduction, IfLoops }, // will have happened and it needs to be before loopStrider
{ localCSE, IfEnabled }, // so that it will not get confused with internal pointers.
{ globalDeadStoreElimination, IfEnabledAndMoreThanOneBlock}, // It may need to be run twice if deadstore elimination is required,
{ deadTreesElimination, }, // but this only happens for unsafe access (arraytranslate.twoToOne)
{ loopReduction, }, // and so is conditional
#ifdef J9_PROJECT_SPECIFIC
{ idiomRecognition, IfLoopsAndNotProfiling }, // after loopReduction!!
#endif
{ lastLoopVersionerGroup, IfLoops },
{ treeSimplification, }, // cleanup before AutoVectorization
{ deadTreesElimination, }, // cleanup before AutoVectorization
{ inductionVariableAnalysis, IfLoopsAndNotProfiling },
#ifdef J9_PROJECT_SPECIFIC
{ SPMDKernelParallelization, IfLoops },
#endif
{ loopStrider, IfLoops },
{ treeSimplification, IfEnabled },
{ lastLoopVersionerGroup, IfEnabledAndLoops },
{ treeSimplification, }, // cleanup before strider
{ localCSE, }, // cleanup before strider so it will not be confused by commoned nodes (mandatory to run local CSE before strider)
{ deadTreesElimination, }, // cleanup before strider so that dead stores can be eliminated more effcientlly (i.e. false uses are not seen)
{ loopStrider, IfLoops },
{ treeSimplification, IfEnabled }, // cleanup after strider
{ loopInversion, IfLoops },
{ endGroup }
};
const OptimizationStrategy methodHandleInvokeInliningOpts[] =
{
{ treeSimplification, }, // Supply some known-object info, and help CSE
{ localCSE, }, // Especially copy propagation to replace temps with more descriptive trees
{ localValuePropagation }, // Propagate known-object info and derive more specific archetype specimen symbols for inlining
#ifdef J9_PROJECT_SPECIFIC
{ targetedInlining, },
#endif
{ deadTreesElimination },
{ methodHandleInvokeInliningGroup, IfEnabled }, // Repeat as required to inline all the MethodHandle.invoke calls we can afford
{ endGroup },
};
const OptimizationStrategy earlyGlobalOpts[] =
{
{ methodHandleInvokeInliningGroup, IfMethodHandleInvokes },
#ifdef J9_PROJECT_SPECIFIC
{ inlining },
#endif
{ osrExceptionEdgeRemoval }, // most inlining is done by now
//{ basicBlockOrdering, IfLoops }, // early ordering with no extension
{ treeSimplification, IfEnabled },
{ compactNullChecks }, // cleans up after inlining; MUST be done before PRE
#ifdef J9_PROJECT_SPECIFIC
{ virtualGuardTailSplitter }, // merge virtual guards
{ treeSimplification },
{ CFGSimplification },
#endif
{ endGroup }
};
const OptimizationStrategy earlyLocalOpts[] =
{
{ localValuePropagation },
//{ localValuePropagationGroup },
{ localReordering },
{ switchAnalyzer, },
{ treeSimplification, IfEnabled }, // simplify any exprs created by LCP/LCSE
#ifdef J9_PROJECT_SPECIFIC
{ catchBlockRemoval }, // if all possible exceptions in a try were removed by inlining/LCP/LCSE
#endif
{ deadTreesElimination }, // remove any anchored dead loads
{ profiledNodeVersioning },
{ endGroup }
};
const OptimizationStrategy isolatedStoreOpts[] =
{
{ isolatedStoreElimination },
{ deadTreesElimination },
{ endGroup }
};
const OptimizationStrategy globalDeadStoreOpts[] =
{
{ globalDeadStoreElimination, IfMoreThanOneBlock },
{ localDeadStoreElimination, IfOneBlock },
{ deadTreesElimination },
{ endGroup }
};
const OptimizationStrategy loopAliasRefinerOpts[] =
{
{ inductionVariableAnalysis, IfLoops },
{ loopCanonicalization },
{ globalValuePropagation, IfMoreThanOneBlock },// create ivs
{ loopAliasRefiner },
{ endGroup }
};
const OptimizationStrategy loopSpecializerOpts[] =
{
{ inductionVariableAnalysis, IfLoops },
{ loopCanonicalization },
{ loopSpecializer },
{ endGroup }
};
const OptimizationStrategy loopVersionerOpts[] =
{
{ basicBlockOrdering },
{ inductionVariableAnalysis, IfLoops },
{ loopCanonicalization },
{ loopVersioner },
{ endGroup }
};
const OptimizationStrategy lastLoopVersionerOpts[] =
{
{ inductionVariableAnalysis, IfLoops },
{ loopCanonicalization },
{ loopVersioner, MarkLastRun },
{ endGroup }
};
const OptimizationStrategy loopCanonicalizationOpts[] =
{
{ globalCopyPropagation, IfLoops }, // propagate copies to allow better invariance detection
{ loopVersionerGroup },
{ deadTreesElimination }, // remove dead anchors created by check removal (versioning)
//{ loopStrider }, // use canonicalized loop to insert initializations
{ treeSimplification }, // remove unreachable blocks (with nullchecks etc.) left by LoopVersioner
{ fieldPrivatization }, // use canonicalized loop to privatize fields
{ treeSimplification }, // might fold expressions created by versioning/induction variables
{ loopSpecializerGroup, IfEnabledAndLoops }, // specialize the versioned loop if possible
{ deadTreesElimination, IfEnabledAndLoops }, // remove dead anchors created by specialization
{ treeSimplification, IfEnabledAndLoops }, // might fold expressions created by specialization
{ endGroup }
};
const OptimizationStrategy stripMiningOpts[] =
{
{ inductionVariableAnalysis, IfLoops },
{ loopCanonicalization },
{ inductionVariableAnalysis },
{ stripMining },
{ endGroup }
};
const OptimizationStrategy blockManipulationOpts[] =
{
// { generalLoopUnroller, IfLoops }, //Unroll Loops
{ coldBlockOutlining } ,
{ CFGSimplification, IfNotJitProfiling },
{ basicBlockHoisting, IfNotJitProfiling },
{ treeSimplification },
{ redundantGotoElimination, IfNotJitProfiling }, // redundant gotos gone
{ treesCleansing }, // maximize fall throughs
{ virtualGuardHeadMerger },
{ basicBlockExtension, MarkLastRun}, // extend blocks; move trees around if reqd
{ treeSimplification }, // revisit; not really required ?
{ basicBlockPeepHole, IfEnabled },
{ endGroup }
};
const OptimizationStrategy eachLocalAnalysisPassOpts[] =
{
{ localValuePropagationGroup, IfEnabled },
#ifdef J9_PROJECT_SPECIFIC
{ arraycopyTransformation },
#endif
{ treeSimplification, IfEnabled },
{ localCSE, IfEnabled },
{ localDeadStoreElimination, IfEnabled }, // after local copy/value propagation
{ rematerialization, IfEnabled },
{ compactNullChecks, IfEnabled },
{ deadTreesElimination, IfEnabled }, // remove dead anchors created by check/store removal
//{ eachLocalAnalysisPassGroup, IfEnabled }, // if another pass requested
{ endGroup }
};
const OptimizationStrategy lateLocalOpts[] =
{
{ OMR::eachLocalAnalysisPassGroup },
{ OMR::andSimplification }, // needs commoning across blocks to work well; must be done after versioning
{ OMR::treesCleansing }, // maximize fall throughs after LCP has converted some conditions to gotos
{ OMR::eachLocalAnalysisPassGroup },
{ OMR::localDeadStoreElimination }, // after latest copy propagation
{ OMR::deadTreesElimination }, // remove dead anchors created by check/store removal
{ OMR::globalDeadStoreGroup, },
{ OMR::eachLocalAnalysisPassGroup },
{ OMR::treeSimplification },
{ OMR::endGroup }
};
static const OptimizationStrategy tacticalGlobalRegisterAllocatorOpts[] =
{
{ OMR::inductionVariableAnalysis, OMR::IfLoops },
{ OMR::loopCanonicalization, OMR::IfLoops },
{ OMR::liveRangeSplitter, OMR::IfLoops },
{ OMR::redundantGotoElimination, OMR::IfNotJitProfiling }, // need to be run before global register allocator
{ OMR::treeSimplification, OMR::MarkLastRun }, // Cleanup the trees after redundantGotoElimination
{ OMR::tacticalGlobalRegisterAllocator, OMR::IfEnabled },
{ OMR::localCSE },
// { isolatedStoreGroup, IfEnabled }, // if global register allocator created stores from registers
{ OMR::globalCopyPropagation, OMR::IfEnabledAndMoreThanOneBlock }, // if live range splitting created copies
{ OMR::localCSE }, // localCSE after post-PRE + post-GRA globalCopyPropagation to clean up whole expression remat (rtc 64659)
{ OMR::globalDeadStoreGroup, OMR::IfEnabled },
{ OMR::redundantGotoElimination, OMR::IfEnabledAndNotJitProfiling }, // if global register allocator created new block
{ OMR::deadTreesElimination }, // remove dangling GlRegDeps
{ OMR::deadTreesElimination, OMR::IfEnabled }, // remove dead RegStores produced by previous deadTrees pass
{ OMR::deadTreesElimination, OMR::IfEnabled }, // remove dead RegStores produced by previous deadTrees pass
{ OMR::endGroup }
};
const OptimizationStrategy finalGlobalOpts[] =
{
{ rematerialization },
{ compactNullChecks, IfEnabled },
{ deadTreesElimination },
//{ treeSimplification, IfEnabled },
{ localLiveRangeReduction },
{ compactLocals, IfNotJitProfiling }, // analysis results are invalidated by jitProfilingGroup
#ifdef J9_PROJECT_SPECIFIC
{ globalLiveVariablesForGC },
#endif
{ endGroup }
};
// **************************************************************************
//
// Strategy that is run for each non-peeking IlGeneration - this allows early
// optimizations to be run even before the IL is available to Inliner
//
// **************************************************************************
static const OptimizationStrategy ilgenStrategyOpts[] =
{
#ifdef J9_PROJECT_SPECIFIC
{ osrLiveRangeAnalysis, IfOSR },
{ osrDefAnalysis, IfInvoluntaryOSR },
{ methodHandleTransformer, },
{ varHandleTransformer, MustBeDone },
{ handleRecompilationOps, MustBeDone },
{ unsafeFastPath },
{ recognizedCallTransformer },
{ coldBlockMarker },
{ CFGSimplification },
{ allocationSinking, IfNews },
{ invariantArgumentPreexistence, IfNotClassLoadPhaseAndNotProfiling }, // Should not run if a recompilation is possible
#endif
{ endOpts },
};
// **********************************************************
//
// OMR Strategies
//
// **********************************************************
static const OptimizationStrategy omrNoOptStrategyOpts[] =
{
{ endOpts },
};
static const OptimizationStrategy omrColdStrategyOpts[] =
{
{ basicBlockExtension },
{ localCSE },
//{ localValuePropagation },
{ treeSimplification },
{ localCSE },
{ endOpts },
};
static const OptimizationStrategy omrWarmStrategyOpts[] =
{
{ basicBlockExtension },
{ localCSE },
//{ localValuePropagation },
{ treeSimplification },
{ localCSE },
{ localDeadStoreElimination },
{ globalDeadStoreGroup },
{ endOpts },
};
static const OptimizationStrategy omrHotStrategyOpts[] =
{
{ OMR::coldBlockOutlining },
{ OMR::earlyGlobalGroup },
{ OMR::earlyLocalGroup },
{ OMR::andSimplification }, // needs commoning across blocks to work well; must be done after versioning
{ OMR::stripMiningGroup, }, // strip mining in loops
{ OMR::loopReplicator, }, // tail-duplication in loops
{ OMR::blockSplitter, }, // treeSimplification + blockSplitter + VP => opportunity for EA
{ OMR::arrayPrivatizationGroup, }, // must preceed escape analysis
{ OMR::veryExpensiveGlobalValuePropagationGroup },
{ OMR::globalDeadStoreGroup, },
{ OMR::globalCopyPropagation, },
{ OMR::loopCanonicalizationGroup, }, // canonicalize loops (improve fall throughs)
{ OMR::expressionsSimplification, },
{ OMR::partialRedundancyEliminationGroup },
{ OMR::globalDeadStoreElimination, },
{ OMR::inductionVariableAnalysis, },
{ OMR::loopSpecializerGroup, },
{ OMR::inductionVariableAnalysis, },
{ OMR::generalLoopUnroller, }, // unroll Loops
{ OMR::blockSplitter, OMR::MarkLastRun },
{ OMR::blockManipulationGroup },
{ OMR::lateLocalGroup },
{ OMR::redundantAsyncCheckRemoval }, // optimize async check placement
#ifdef J9_PROJECT_SPECIFIC
{ OMR::recompilationModifier, }, // do before GRA to avoid commoning of longs afterwards
#endif
{ OMR::globalCopyPropagation, }, // Can produce opportunities for store sinking
{ OMR::generalStoreSinking },
{ OMR::localCSE, }, //common up lit pool refs in the same block
{ OMR::treeSimplification, }, // cleanup the trees after sunk store and localCSE
{ OMR::trivialBlockExtension },
{ OMR::localDeadStoreElimination, }, //remove the astore if no literal pool is required
{ OMR::localCSE, }, //common up lit pool refs in the same block
{ OMR::arraysetStoreElimination },
{ OMR::localValuePropagation, OMR::MarkLastRun },
{ OMR::checkcastAndProfiledGuardCoalescer },
{ OMR::osrExceptionEdgeRemoval, OMR::MarkLastRun },
{ OMR::tacticalGlobalRegisterAllocatorGroup, },
{ OMR::globalDeadStoreElimination, }, // global dead store removal
{ OMR::deadTreesElimination }, // cleanup after dead store removal
{ OMR::compactNullChecks }, // cleanup at the end
{ OMR::finalGlobalGroup }, // done just before codegen
{ OMR::regDepCopyRemoval },
{ endOpts },
};
// The following arrays of Optimization pointers are externally declared in OptimizerStrategies.hpp
// This allows frontends to assist in selection of optimizer strategies.
// (They cannot be made 'static const')
const OptimizationStrategy *omrCompilationStrategies[] =
{
omrNoOptStrategyOpts, // empty strategy
omrColdStrategyOpts, // << specialized
omrWarmStrategyOpts, // << specialized
omrHotStrategyOpts, // currently used to test available omr optimizations
};
#ifdef OPT_TIMING // provide statistics on time taken by individual optimizations
TR_Stats statOptTiming[OMR::numOpts];
TR_Stats statStructuralAnalysisTiming("Structural Analysis");
TR_Stats statUseDefsTiming("Use Defs");
TR_Stats statGlobalValNumTiming("Global Value Numbering");
#endif // OPT_TIMING
TR::Optimizer *OMR::Optimizer::createOptimizer(TR::Compilation *comp, TR::ResolvedMethodSymbol *methodSymbol, bool isIlGen)
{
// returns IL optimizer, performs tree-to-tree optimizing transformations.
if (isIlGen)
return new (comp->trHeapMemory()) TR::Optimizer(comp, methodSymbol, isIlGen, ilgenStrategyOpts);
if (comp->getOptions()->getCustomStrategy())
{
if (comp->getOption(TR_TraceOptDetails))
traceMsg(comp, "Using custom optimization strategy\n");
// Reformat custom strategy as array of Optimization rather than array of int32_t
//
int32_t *srcStrategy = comp->getOptions()->getCustomStrategy();
int32_t size = comp->getOptions()->getCustomStrategySize();
OptimizationStrategy *customStrategy = (OptimizationStrategy *)comp->trMemory()->allocateHeapMemory(size * sizeof(customStrategy[0]));
for (int32_t i = 0; i < size; i++)
{
OptimizationStrategy o = { (OMR::Optimizations)(srcStrategy[i] & TR::Options::OptNumMask) };
if (srcStrategy[i] & TR::Options::MustBeDone)
o._options = MustBeDone;
customStrategy[i] = o;
}
return new (comp->trHeapMemory()) TR::Optimizer(comp, methodSymbol, isIlGen, customStrategy);
}
TR::Optimizer *optimizer = new (comp->trHeapMemory()) TR::Optimizer(
comp,
methodSymbol,
isIlGen,
TR::Optimizer::optimizationStrategy(comp),
TR::Optimizer::valueNumberInfoBuildType());
return optimizer;
}
// ************************************************************************
//
// Implementation of TR::Optimizer
//
// ************************************************************************
OMR::Optimizer::Optimizer(TR::Compilation *comp, TR::ResolvedMethodSymbol *methodSymbol, bool isIlGen,
const OptimizationStrategy *strategy, uint16_t VNType)
: _compilation(comp),
_cg(comp->cg()),
_trMemory(comp->trMemory()),
_methodSymbol(methodSymbol),
_isIlGen(isIlGen),
_strategy(strategy),
_vnInfoType(VNType),
_symReferencesTable(NULL),
_useDefInfo(NULL),
_valueNumberInfo(NULL),
_aliasSetsAreValid(false),
_cantBuildGlobalsUseDefInfo(false),
_cantBuildLocalsUseDefInfo(false),
_cantBuildGlobalsValueNumberInfo(false),
_cantBuildLocalsValueNumberInfo(false),
_canRunBlockByBlockOptimizations(true),
_cachedExtendedBBInfoValid(false),
_inlineSynchronized(true),
_enclosingFinallyBlock(NULL),
_eliminatedCheckcastNodes(comp->trMemory()),
_classPointerNodes(comp->trMemory()),
_optMessageIndex(0),
_seenBlocksGRA(NULL),
_resetExitsGRA(NULL),
_successorBitsGRA(NULL),
_stackedOptimizer(false),
_firstTimeStructureIsBuilt(true),
_disableLoopOptsThatCanCreateLoops(false)
{
// zero opts table
memset(_opts, 0, sizeof(_opts));
/*
* Allow downstream projects to disable the default initialization of optimizations
* and allow them to take full control over this process. This can be an advantage
* if they don't use all of the optimizations initialized here as they can avoid
* getting linked in to the binary in their entirety.
*/
#if !defined(TR_OVERRIDE_OPTIMIZATION_INITIALIZATION)
// initialize OMR optimizations
_opts[OMR::andSimplification] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_SimplifyAnds::create, OMR::andSimplification);
_opts[OMR::arraysetStoreElimination] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_ArraysetStoreElimination::create, OMR::arraysetStoreElimination);
_opts[OMR::asyncCheckInsertion] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_AsyncCheckInsertion::create, OMR::asyncCheckInsertion);
_opts[OMR::basicBlockExtension] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_ExtendBasicBlocks::create, OMR::basicBlockExtension);
_opts[OMR::basicBlockHoisting] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_HoistBlocks::create, OMR::basicBlockHoisting);
_opts[OMR::basicBlockOrdering] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_OrderBlocks::create, OMR::basicBlockOrdering);
_opts[OMR::basicBlockPeepHole] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_PeepHoleBasicBlocks::create, OMR::basicBlockPeepHole);
_opts[OMR::blockShuffling] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_BlockShuffling::create, OMR::blockShuffling);
_opts[OMR::blockSplitter] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_BlockSplitter::create, OMR::blockSplitter);
_opts[OMR::catchBlockRemoval] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_CatchBlockRemover::create, OMR::catchBlockRemoval);
_opts[OMR::CFGSimplification] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::CFGSimplifier::create, OMR::CFGSimplification);
_opts[OMR::checkcastAndProfiledGuardCoalescer] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_CheckcastAndProfiledGuardCoalescer::create, OMR::checkcastAndProfiledGuardCoalescer);
_opts[OMR::coldBlockMarker] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_ColdBlockMarker::create, OMR::coldBlockMarker);
_opts[OMR::coldBlockOutlining] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_ColdBlockOutlining::create, OMR::coldBlockOutlining);
_opts[OMR::compactLocals] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_CompactLocals::create, OMR::compactLocals);
_opts[OMR::compactNullChecks] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_CompactNullChecks::create, OMR::compactNullChecks);
_opts[OMR::deadTreesElimination] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::DeadTreesElimination::create, OMR::deadTreesElimination);
_opts[OMR::expressionsSimplification] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_ExpressionsSimplification::create, OMR::expressionsSimplification);
_opts[OMR::generalLoopUnroller] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_GeneralLoopUnroller::create, OMR::generalLoopUnroller);
_opts[OMR::globalCopyPropagation] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_CopyPropagation::create, OMR::globalCopyPropagation);
_opts[OMR::globalDeadStoreElimination] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_DeadStoreElimination::create, OMR::globalDeadStoreElimination);
_opts[OMR::inlining] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_TrivialInliner::create, OMR::inlining);
_opts[OMR::innerPreexistence] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_InnerPreexistence::create, OMR::innerPreexistence);
_opts[OMR::invariantArgumentPreexistence] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_InvariantArgumentPreexistence::create, OMR::invariantArgumentPreexistence);
_opts[OMR::loadExtensions] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LoadExtensions::create, OMR::loadExtensions);
_opts[OMR::localCSE] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::LocalCSE::create, OMR::localCSE);
_opts[OMR::localDeadStoreElimination] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::LocalDeadStoreElimination::create, OMR::localDeadStoreElimination);
_opts[OMR::localLiveRangeReduction] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LocalLiveRangeReduction::create, OMR::localLiveRangeReduction);
_opts[OMR::localReordering] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LocalReordering::create, OMR::localReordering);
_opts[OMR::loopCanonicalization] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LoopCanonicalizer::create, OMR::loopCanonicalization);
_opts[OMR::loopVersioner] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LoopVersioner::create, OMR::loopVersioner);
_opts[OMR::loopReduction] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LoopReducer::create, OMR::loopReduction);
_opts[OMR::loopReplicator] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LoopReplicator::create, OMR::loopReplicator);
_opts[OMR::profiledNodeVersioning] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_ProfiledNodeVersioning::create, OMR::profiledNodeVersioning);
_opts[OMR::redundantAsyncCheckRemoval] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_RedundantAsyncCheckRemoval::create, OMR::redundantAsyncCheckRemoval);
_opts[OMR::redundantGotoElimination] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_EliminateRedundantGotos::create, OMR::redundantGotoElimination);
_opts[OMR::rematerialization] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_Rematerialization::create, OMR::rematerialization);
_opts[OMR::treesCleansing] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_CleanseTrees::create, OMR::treesCleansing);
_opts[OMR::treeSimplification] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::Simplifier::create, OMR::treeSimplification);
_opts[OMR::trivialBlockExtension] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_TrivialBlockExtension::create, OMR::trivialBlockExtension);
_opts[OMR::trivialDeadTreeRemoval] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_TrivialDeadTreeRemoval::create, OMR::trivialDeadTreeRemoval);
_opts[OMR::virtualGuardHeadMerger] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_VirtualGuardHeadMerger::create, OMR::virtualGuardHeadMerger);
_opts[OMR::virtualGuardTailSplitter] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_VirtualGuardTailSplitter::create, OMR::virtualGuardTailSplitter);
_opts[OMR::generalStoreSinking] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_GeneralSinkStores::create, OMR::generalStoreSinking);
_opts[OMR::globalValuePropagation] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::GlobalValuePropagation::create, OMR::globalValuePropagation);
_opts[OMR::localValuePropagation] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::LocalValuePropagation::create, OMR::localValuePropagation);
_opts[OMR::redundantInductionVarElimination] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_RedundantInductionVarElimination::create, OMR::redundantInductionVarElimination);
_opts[OMR::partialRedundancyElimination] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_PartialRedundancy::create, OMR::partialRedundancyElimination);
_opts[OMR::loopInversion] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LoopInverter::create, OMR::loopInversion);
_opts[OMR::inductionVariableAnalysis] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_InductionVariableAnalysis::create, OMR::inductionVariableAnalysis);
_opts[OMR::osrExceptionEdgeRemoval] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_OSRExceptionEdgeRemoval::create, OMR::osrExceptionEdgeRemoval);
_opts[OMR::regDepCopyRemoval] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::RegDepCopyRemoval::create, OMR::regDepCopyRemoval);
_opts[OMR::stripMining] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_StripMiner::create, OMR::stripMining);
_opts[OMR::fieldPrivatization] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_FieldPrivatizer::create, OMR::fieldPrivatization);
_opts[OMR::reorderArrayIndexExpr] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_IndexExprManipulator::create, OMR::reorderArrayIndexExpr);
_opts[OMR::loopStrider] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LoopStrider::create, OMR::loopStrider);
_opts[OMR::osrDefAnalysis] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_OSRDefAnalysis::create, OMR::osrDefAnalysis);
_opts[OMR::osrLiveRangeAnalysis] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_OSRLiveRangeAnalysis::create, OMR::osrLiveRangeAnalysis);
_opts[OMR::tacticalGlobalRegisterAllocator] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_GlobalRegisterAllocator::create, OMR::tacticalGlobalRegisterAllocator);
_opts[OMR::liveRangeSplitter] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LiveRangeSplitter::create, OMR::liveRangeSplitter);
_opts[OMR::loopSpecializer] =
new (comp->allocator()) TR::OptimizationManager(self(), TR_LoopSpecializer::create, OMR::loopSpecializer);
_opts[OMR::recognizedCallTransformer] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::RecognizedCallTransformer::create, OMR::recognizedCallTransformer);
_opts[OMR::switchAnalyzer] =
new (comp->allocator()) TR::OptimizationManager(self(), TR::SwitchAnalyzer::create, OMR::switchAnalyzer);
// NOTE: Please add new OMR optimizations here!
// initialize OMR optimization groups
_opts[OMR::globalDeadStoreGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::globalDeadStoreGroup, globalDeadStoreOpts);
_opts[OMR::loopCanonicalizationGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::loopCanonicalizationGroup, loopCanonicalizationOpts);
_opts[OMR::loopVersionerGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::loopVersionerGroup, loopVersionerOpts);
_opts[OMR::lastLoopVersionerGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::lastLoopVersionerGroup, lastLoopVersionerOpts);
_opts[OMR::methodHandleInvokeInliningGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::methodHandleInvokeInliningGroup, methodHandleInvokeInliningOpts);
_opts[OMR::earlyGlobalGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::earlyGlobalGroup, earlyGlobalOpts);
_opts[OMR::earlyLocalGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::earlyLocalGroup, earlyLocalOpts);
_opts[OMR::stripMiningGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::stripMiningGroup, stripMiningOpts);
_opts[OMR::arrayPrivatizationGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::arrayPrivatizationGroup, arrayPrivatizationOpts);
_opts[OMR::veryCheapGlobalValuePropagationGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::veryCheapGlobalValuePropagationGroup, veryCheapGlobalValuePropagationOpts);
_opts[OMR::eachExpensiveGlobalValuePropagationGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::eachExpensiveGlobalValuePropagationGroup, eachExpensiveGlobalValuePropagationOpts);
_opts[OMR::veryExpensiveGlobalValuePropagationGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::veryExpensiveGlobalValuePropagationGroup, veryExpensiveGlobalValuePropagationOpts);
_opts[OMR::loopSpecializerGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::loopSpecializerGroup, loopSpecializerOpts);
_opts[OMR::lateLocalGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::lateLocalGroup, lateLocalOpts);
_opts[OMR::eachLocalAnalysisPassGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::eachLocalAnalysisPassGroup, eachLocalAnalysisPassOpts);
_opts[OMR::tacticalGlobalRegisterAllocatorGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::tacticalGlobalRegisterAllocatorGroup, tacticalGlobalRegisterAllocatorOpts);
_opts[OMR::partialRedundancyEliminationGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::partialRedundancyEliminationGroup, partialRedundancyEliminationOpts);
_opts[OMR::reorderArrayExprGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::reorderArrayExprGroup, reorderArrayIndexOpts);
_opts[OMR::blockManipulationGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::blockManipulationGroup, blockManipulationOpts);
_opts[OMR::localValuePropagationGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::localValuePropagationGroup, localValuePropagationOpts);
_opts[OMR::finalGlobalGroup] =
new (comp->allocator()) TR::OptimizationManager(self(), NULL, OMR::finalGlobalGroup, finalGlobalOpts);
// NOTE: Please add new OMR optimization groups here!
#endif
}
// Note: optimizer_name array needs to match Optimizations enum defined
// in compiler/optimizer/Optimizations.hpp
static const char * optimizer_name[] =
{
#define OPTIMIZATION(name) #name,
#define OPTIMIZATION_ENUM_ONLY(entry) "****",
#include "optimizer/Optimizations.enum"
OPTIMIZATION_ENUM_ONLY(numOpts)
#include "optimizer/OptimizationGroups.enum"
OPTIMIZATION_ENUM_ONLY(numGroups)
#undef OPTIMIZATION
#undef OPTIMIZATION_ENUM_ONLY
};
const char *
OMR::Optimizer::getOptimizationName(OMR::Optimizations opt)
{
return ::optimizer_name[opt];
}
bool
OMR::Optimizer::isEnabled(OMR::Optimizations i)
{
if (_opts[i] != NULL)
return _opts[i]->enabled();
return false;
}
TR_Debug *OMR::Optimizer::getDebug()
{
return _compilation->getDebug();
}
void OMR::Optimizer::setCachedExtendedBBInfoValid(bool b)
{
TR_ASSERT(!comp()->isPeekingMethod(), "ERROR: Should not modify _cachedExtendedBBInfoValid while peeking");
_cachedExtendedBBInfoValid = b;
}
TR_UseDefInfo *OMR::Optimizer::setUseDefInfo(TR_UseDefInfo * u)
{
if(_useDefInfo != NULL)
{
dumpOptDetails(comp(), " (Invalidating use/def info)\n");
delete _useDefInfo;
}
return (_useDefInfo = u);
}
TR_ValueNumberInfo *OMR::Optimizer::setValueNumberInfo(TR_ValueNumberInfo *v)
{
if (_valueNumberInfo && !v)
dumpOptDetails(comp(), " (Invalidating value number info)\n");
if (_valueNumberInfo)
delete _valueNumberInfo;
return (_valueNumberInfo = v);
}
TR_UseDefInfo* OMR::Optimizer::createUseDefInfo(TR::Compilation* comp,
bool requiresGlobals, bool prefersGlobals, bool loadsShouldBeDefs, bool cannotOmitTrivialDefs,
bool conversionRegsOnly, bool doCompletion)
{
return new (comp->allocator()) TR_UseDefInfo(comp, comp->getFlowGraph(), self(), requiresGlobals, prefersGlobals, loadsShouldBeDefs,
cannotOmitTrivialDefs, conversionRegsOnly, doCompletion, getCallsAsUses());
}
TR_ValueNumberInfo *OMR::Optimizer::createValueNumberInfo(bool requiresGlobals, bool preferGlobals, bool noUseDefInfo)
{
LexicalTimer t("global value numbering (for globals definitely)", comp()->phaseTimer());
TR::LexicalMemProfiler mp("global value numbering (for globals definitely)", comp()->phaseMemProfiler());
TR_ValueNumberInfo * valueNumberInfo = NULL;
switch(_vnInfoType)
{
case PrePartitionVN:
valueNumberInfo = new (comp()->allocator()) TR_ValueNumberInfo(comp(), self(), requiresGlobals, preferGlobals, noUseDefInfo);
break;
case HashVN:
valueNumberInfo = new (comp()->allocator()) TR_HashValueNumberInfo(comp(), self(), requiresGlobals, preferGlobals, noUseDefInfo);
break;
default:
valueNumberInfo = new (comp()->allocator()) TR_ValueNumberInfo(comp(), self(), requiresGlobals, preferGlobals, noUseDefInfo);
break;
};
TR_ASSERT(valueNumberInfo != NULL, "Failed to create ValueNumber Information");
return valueNumberInfo;
}
void OMR::Optimizer::optimize()