forked from eclipse-omr/omr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VPHandlers.cpp
12556 lines (11194 loc) · 480 KB
/
VPHandlers.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 (c) 2000, 2022 IBM Corp. and others
*
* 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 http://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] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
#include <algorithm>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "codegen/CodeGenerator.hpp"
#include "env/FrontEnd.hpp"
#include "env/KnownObjectTable.hpp"
#include "codegen/RecognizedMethods.hpp"
#include "codegen/InstOpCode.hpp"
#include "compile/Compilation.hpp"
#include "compile/Method.hpp"
#include "compile/ResolvedMethod.hpp"
#include "compile/SymbolReferenceTable.hpp"
#include "compile/VirtualGuard.hpp"
#include "control/Options.hpp"
#include "control/Options_inlines.hpp"
#include "cs2/bitvectr.h"
#include "env/CompilerEnv.hpp"
#include "env/IO.hpp"
#include "env/ObjectModel.hpp"
#include "env/PersistentInfo.hpp"
#include "env/TRMemory.hpp"
#include "env/jittypes.h"
#ifdef J9_PROJECT_SPECIFIC
#include "env/VMAccessCriticalSection.hpp"
#endif
#include "il/AliasSetInterface.hpp"
#include "il/AutomaticSymbol.hpp"
#include "il/Block.hpp"
#include "il/DataTypes.hpp"
#include "il/ILOpCodes.hpp"
#include "il/ILOps.hpp"
#include "il/MethodSymbol.hpp"
#include "il/Node.hpp"
#include "il/Node_inlines.hpp"
#include "il/ResolvedMethodSymbol.hpp"
#include "il/StaticSymbol.hpp"
#include "il/Symbol.hpp"
#include "il/SymbolReference.hpp"
#include "il/TreeTop.hpp"
#include "il/TreeTop_inlines.hpp"
#include "infra/Array.hpp"
#include "infra/Assert.hpp"
#include "infra/Bit.hpp"
#include "infra/Cfg.hpp"
#include "infra/Link.hpp"
#include "infra/List.hpp"
#include "infra/SimpleRegex.hpp"
#include "infra/CfgEdge.hpp"
#include "optimizer/Optimization_inlines.hpp"
#include "optimizer/OptimizationManager.hpp"
#include "optimizer/Optimizations.hpp"
#include "optimizer/Optimizer.hpp"
#include "optimizer/PreExistence.hpp"
#include "optimizer/TransformUtil.hpp"
#include "optimizer/UseDefInfo.hpp"
#include "optimizer/VPConstraint.hpp"
#include "optimizer/ValuePropagation.hpp"
#include "ras/Debug.hpp"
#include "ras/DebugCounter.hpp"
#include "runtime/Runtime.hpp"
#ifdef J9_PROJECT_SPECIFIC
#include "env/CHTable.hpp"
#include "env/PersistentCHTable.hpp"
#include "runtime/RuntimeAssumptions.hpp"
#include "env/VMJ9.h"
#include "optimizer/VPBCDConstraint.hpp"
#endif
#define OPT_DETAILS "O^O VALUE PROPAGATION: "
extern TR::Node *constrainChildren(OMR::ValuePropagation *vp, TR::Node *node);
extern TR::Node *constrainVcall(OMR::ValuePropagation *vp, TR::Node *node);
extern void createGuardSiteForRemovedGuard(TR::Compilation *comp, TR::Node* ifNode);
static void checkForNonNegativeAndOverflowProperties(OMR::ValuePropagation *vp, TR::Node *node, TR::VPConstraint *constraint = NULL)
{
if (!constraint)
{
bool isGlobal;
constraint = vp->getConstraint(node, isGlobal);
}
if (node->getOpCode().isLoad())
{
node->setCannotOverflow(true);
//dumpOptDetails(vp->comp(), "Load node %p cannot overflow\n", node);
}
if (constraint)
{
if (constraint->asIntConst())
{
int32_t low = constraint->asIntConst()->getLowInt();
if (low >= 0)
node->setIsNonNegative(true);
if (low <= 0)
node->setIsNonPositive(true);
}
if (constraint->asLongConst())
{
int64_t low = constraint->asLongConst()->getLowLong();
if (low >= 0)
node->setIsNonNegative(true);
if (low <= 0)
node->setIsNonPositive(true);
}
if (constraint->asShortConst())
{
int16_t low = constraint->asShortConst()->getLowShort();
if (low >= 0)
node->setIsNonNegative(true);
if (low <= 0)
node->setIsNonPositive(true);
}
if (constraint->asIntRange())
{
TR::VPIntRange *range = constraint->asIntRange();
int32_t low = range->getLowInt();
if (low >= 0)
node->setIsNonNegative(true);
int32_t high = range->getHighInt();
if (high <= 0)
node->setIsNonPositive(true);
///if ((node->getOpCode().isArithmetic() || node->getOpCode().isLoad()) &&
/// ((low > TR::getMinSigned<TR::Int32>()) || (high < TR::getMaxSigned<TR::Int32>())))
if ((node->getOpCode().isLoad() &&
((low > TR::getMinSigned<TR::Int32>()) || (high < TR::getMaxSigned<TR::Int32>()))) ||
(node->getOpCode().isArithmetic() &&
(range->canOverflow() != TR_yes)))
{
node->setCannotOverflow(true);
//dumpOptDetails(vp->comp(), "Node %p cannot overflow\n", node);
}
}
else if (constraint->asLongRange())
{
TR::VPLongRange *range = constraint->asLongRange();
int64_t low = range->getLowLong();
if (low >= 0)
node->setIsNonNegative(true);
int64_t high = range->getHighLong();
if (high <= 0)
node->setIsNonPositive(true);
///if ((node->getOpCode().isArithmetic() || node->getOpCode().isLoad()) &&
/// ((low > TR::getMinSigned<TR::Int64>()) || (high < TR::getMaxSigned<TR::Int64>())))
if ((node->getOpCode().isLoad() &&
((low > TR::getMinSigned<TR::Int64>()) || (high < TR::getMaxSigned<TR::Int64>()))) ||
(node->getOpCode().isArithmetic() &&
(range->canOverflow() != TR_yes)))
{
node->setCannotOverflow(true);
//dumpOptDetails(vp->comp(), "Node %p cannot overflow\n", node);
}
}
else if (constraint->asShortRange())
{
TR::VPShortRange *range = constraint->asShortRange();
int16_t low = range->getLowShort();
if (low >= 0)
node->setIsNonNegative(true);
int16_t high = range->getHighShort();
if (high <= 0)
node->setIsNonPositive(true);
if ((node->getOpCode().isLoad() && ((low > TR::getMinSigned<TR::Int16>()) || (high < TR::getMaxSigned<TR::Int16>()))) ||
(node->getOpCode().isArithmetic() && (range->canOverflow() != TR_yes)))
{
node->setCannotOverflow(true);
}
}
}
}
static bool isBoolean(TR::VPConstraint *constraint)
{
if (constraint)
{
if (constraint->asIntConst())
{
int32_t low = constraint->asIntConst()->getLowInt();
if ((low >= 0) && (low <= 1))
return true;
}
if (constraint->asLongConst())
{
int64_t low = constraint->asLongConst()->getLowLong();
if ((low >= 0) && (low <= 1))
return true;
}
if (constraint->asShortConst())
{
int16_t low = constraint->asShortConst()->getLowShort();
if ((low >= 0) && (low <= 1))
return true;
}
if (constraint->asIntRange())
{
TR::VPIntRange *range = constraint->asIntRange();
int32_t low = range->getLowInt();
int32_t high = range->getHighInt();
if ((low >= 0) && (high <= 1))
return true;
}
else if (constraint->asLongRange())
{
TR::VPLongRange *range = constraint->asLongRange();
int64_t low = range->getLowLong();
int64_t high = range->getHighLong();
if ((low >= 0) && (high <= 1))
return true;
}
else if (constraint->asShortRange())
{
TR::VPShortRange *range = constraint->asShortRange();
int16_t low = range->getLowShort();
int16_t high = range->getHighShort();
if ((low >= 0) && (high <= 1))
return true;
}
}
return false;
}
static int32_t arrayElementSize(const char *signature, int32_t len, TR::Node *node, OMR::ValuePropagation *vp)
{
if (signature[0] != '[')
return 0;
// regular array element size
if (signature[0] == '[')
{
switch (signature[1])
{
case 'B': return 1;
case 'C':
case 'S': return 2;
case 'I':
case 'F': return 4;
case 'D':
case 'J': return 8;
case 'Z': return static_cast<int32_t>(TR::Compiler->om.elementSizeOfBooleanArray());
case 'L':
case 'Q':
default :
return TR::Compiler->om.sizeofReferenceField();
}
}
return 0;
}
static void constrainBaseObjectOfIndirectAccess(OMR::ValuePropagation *vp, TR::Node *node)
{
return; // 84287 - disabled for now.
//if (!debug("enableBaseConstraint"))
// return;
int32_t baseObjectSigLen;
TR_ResolvedMethod *method = node->getSymbolReference()->getOwningMethod(vp->comp());
char *baseObjectSig = method->classNameOfFieldOrStatic(node->getSymbolReference()->getCPIndex(), baseObjectSigLen);
if (baseObjectSig)
baseObjectSig = TR::Compiler->cls.classNameToSignature(baseObjectSig, baseObjectSigLen, vp->comp());
if (baseObjectSig)
{
TR_OpaqueClassBlock *baseClass = vp->fe()->getClassFromSignature(baseObjectSig, baseObjectSigLen, method);
if ( baseClass
&& TR::Compiler->cls.isInterfaceClass(vp->comp(), baseClass)
&& !vp->comp()->getOption(TR_TrustAllInterfaceTypeInfo))
{
baseClass = NULL;
}
if (baseClass)
{
// check if there is an existing class constraint
// before trying to refine the constraint
bool isGlobal;
TR::VPConstraint *baseConstraint = vp->getConstraint(node->getFirstChild(), isGlobal);
TR::VPConstraint *constraint = TR::VPClassType::create(vp, baseObjectSig, baseObjectSigLen, method, false, baseClass);
// only if its a class constraint
if (baseConstraint && baseConstraint->getClassType())
{
if (vp->trace())
{
traceMsg(vp->comp(), "Found existing class constraint for node (%p) :\n", node->getFirstChild());
baseConstraint->print(vp->comp(), vp->comp()->getOutFile());
}
// check if it can be refined
if (!constraint->intersect(baseConstraint, vp))
return; // nope, bail
}
vp->addBlockConstraint(node->getFirstChild(), constraint);
}
}
}
// When node is successfully folded, isGlobal is set to true iff all
// constraints in the chain were global, and false otherwise.
static bool tryFoldCompileTimeLoad(
OMR::ValuePropagation *vp,
TR::Node *node,
bool &isGlobal)
{
isGlobal = true;
if (!node->getOpCode().isLoad())
return false;
else if (node->getOpCode().isLoadReg())
return false;
else if (node->getSymbolReference()->isUnresolved())
return false;
if (node->getOpCode().isIndirect())
{
if (vp->trace())
traceMsg(vp->comp(), " constrainCompileTimeLoad inspecting %s %p\n", node->getOpCode().getName(), node);
TR::KnownObjectTable *knot = vp->comp()->getKnownObjectTable();
TR::Node *baseExpression = NULL;
TR::KnownObjectTable::Index baseKnownObject = TR::KnownObjectTable::UNKNOWN;
TR::Node *curNode = node;
for (; !baseExpression; )
{
// Track last curNode because its symref might be improved to ImmutableArrayShadow
TR::Node* prevNode = curNode;
// Look pass aladd/aiadd to get the array object for array shadows
if (curNode->getSymbol()->isArrayShadowSymbol()
&& curNode->getFirstChild()->getOpCode().isArrayRef()
&& curNode->getFirstChild()->getSecondChild()->getOpCode().isLoadConst())
{
curNode = curNode->getFirstChild()->getFirstChild();
}
else curNode = curNode->getFirstChild();
bool curIsGlobal;
TR::VPConstraint *constraint = vp->getConstraint(curNode, curIsGlobal);
if (!curIsGlobal)
isGlobal = false;
if (!constraint)
{
if (vp->trace())
traceMsg(vp->comp(), " - FAIL: %s %p has no constraint\n", curNode->getOpCode().getName(), curNode);
break;
}
else if (curNode->getOpCode().hasSymbolReference() && curNode->getSymbolReference()->isUnresolved())
{
if (vp->trace())
traceMsg(vp->comp(), " - FAIL: %s %p is unresolved\n", curNode->getOpCode().getName(), curNode);
break;
}
else if (constraint->getKnownObject())
{
TR::Symbol* prevNodeSym = prevNode->getSymbol();
// Improve regular array shadows from arrays with immutable content
if (prevNodeSym->isArrayShadowSymbol() &&
// UnsafeShadow responds true to above question, but the type of the array element might not match the type of the symbol,
// it needs to be derived from the array
!prevNodeSym->isUnsafeShadowSymbol() &&
!vp->comp()->getSymRefTab()->isImmutableArrayShadow(prevNode->getSymbolReference()))
{
if (constraint->getKnownObject()->isArrayWithConstantElements(vp->comp()))
{
// Use the DataType of the symbol because it represents the element type of the array
TR::SymbolReference* improvedSymRef = vp->comp()->getSymRefTab()->findOrCreateImmutableArrayShadowSymbolRef(prevNodeSym->getDataType());
if (vp->trace())
traceMsg(vp->comp(), "Found arrayShadow load %p from array with constant elements %p\n", prevNode, curNode);
if (performTransformation(vp->comp(), "%sUsing ImmutableArrayShadow symref #%d for node %p\n", OPT_DETAILS, improvedSymRef->getReferenceNumber(), prevNode))
prevNode->setSymbolReference(improvedSymRef);
// Alias info of calls are computed in createAliasInfo, which is only called if alias info is not available or is invalid.
// Invalidate alias info so that it can be recomputed in the next optimization that needs it
vp->optimizer()->setAliasSetsAreValid(false);
}
else if (!constraint->getKnownObject()->isArrayWithStableElements(vp->comp()))
break;
}
baseExpression = curNode;
baseKnownObject = constraint->getKnownObject()->getIndex();
if (vp->trace())
traceMsg(vp->comp(), " - %s %p is obj%d\n", baseExpression->getOpCode().getName(), baseExpression, baseKnownObject);
break;
}
else if (knot && constraint->isConstString())
{
baseExpression = curNode;
baseKnownObject = knot->getOrCreateIndexAt((uintptr_t*)constraint->getConstString()->getSymRef()->getSymbol()->castToStaticSymbol()->getStaticAddress());
if (vp->trace())
traceMsg(vp->comp(), " - %s %p is string obj%d\n", baseExpression->getOpCode().getName(), baseExpression, baseKnownObject);
break;
}
else if (constraint->isJ9ClassObject() == TR_yes
&& constraint->isNonNullObject()
&& constraint->getClassType()
&& constraint->getClassType()->asFixedClass()
&& constraint->getClass())
{
if (vp->trace())
traceMsg(vp->comp(), " - %s %p is class object - transforming\n", curNode->getOpCode().getName(), curNode);
TR::Node *nodeToRemove = NULL;
uintptr_t clazz = (uintptr_t)constraint->getClass();
bool didSomething = TR::TransformUtil::transformIndirectLoadChainAt(vp->comp(), node, curNode, &clazz, &nodeToRemove);
if (nodeToRemove)
{
TR_ASSERT(didSomething, "How can there be a node to remove if transformIndirectLoadChain didn't do something??");
vp->removeNode(nodeToRemove, true);
return true;
}
return didSomething;
}
else if (node->getSymbolReference() == vp->comp()->getSymRefTab()->findVftSymbolRef()
&& node->getFirstChild() == curNode
&& constraint->isNonNullObject()
&& constraint->getClassType()
&& constraint->getClassType()->asFixedClass()
&& constraint->getClass())
{
TR_OpaqueClassBlock *clazz = constraint->getClass();
#ifdef J9_PROJECT_SPECIFIC
TR_J9VMBase *fej9 = vp->comp()->fej9();
// Non SVM AOT can deal with transformed loadaddr of system class only while Symbol Validation Manager can handle any class.
// Skip the transformation under non SVM AOT when class is not loaded by bootstrap class loader.
// TODO: Disabling tranformation on Power for non SVM AOT because it does not add external relocation record. Enable this once it is fixed.
if (vp->comp()->compileRelocatableCode() && !vp->comp()->getOption(TR_UseSymbolValidationManager) && (vp->comp()->target().cpu.isPower() || fej9->getClassLoader(clazz) != fej9->getSystemClassLoader()))
return false;
#endif
if (vp->trace())
traceMsg(vp->comp(), "VP Transforming VFTLoad to loadaddr: as n%dn is VFT load of known class", node->getGlobalIndex());
node->setNumChildren(0);
TR::Node::recreateWithSymRef(node, TR::loadaddr, vp->comp()->getSymRefTab()->findOrCreateClassSymbol(vp->comp()->getMethodSymbol(), -1, clazz));
node->setFlags(0);
vp->removeNode(curNode, true);
TR::DebugCounter::incStaticDebugCounter(vp->comp(), TR::DebugCounter::debugCounterName(vp->comp(), "VFTLoadKnownObject/(%s)/%s", vp->comp()->signature(), vp->comp()->getHotnessName(vp->comp()->getMethodHotness())));
return true;
}
else if (!curNode->getOpCode().isLoadIndirect())
{
if (curNode->getOpCodeValue() == TR::loadaddr
&& curNode->getSymbolReference()->getSymbol()->isClassObject()
&& !curNode->getSymbolReference()->isUnresolved())
{
TR::Node *nodeToRemove = NULL;
uintptr_t clazz = (uintptr_t)curNode->getSymbolReference()->getSymbol()->getStaticSymbol()->getStaticAddress();
bool didSomething = TR::TransformUtil::transformIndirectLoadChainAt(vp->comp(), node, curNode, &clazz, &nodeToRemove);
if (nodeToRemove)
{
TR_ASSERT(didSomething, "How can there be a node to remove if transformIndirectLoadChain didn't do something??");
vp->removeNode(nodeToRemove, true);
return true;
}
return didSomething;
}
else
{
if (vp->trace())
traceMsg(vp->comp(), " - FAIL: %s %p is not an indirect load and has insufficient constraints\n", curNode->getOpCode().getName(), curNode);
break;
}
}
#ifdef J9_PROJECT_SPECIFIC
else if (vp->comp()->fej9()->isFinalFieldPointingAtJ9Class(curNode->getSymbolReference(), vp->comp()))
{
if (vp->trace())
traceMsg(vp->comp(), " - FAIL: %s %p points to a j9class but has insufficient constraints\n", curNode->getOpCode().getName(), curNode);
baseExpression = NULL;
break;
}
else if (vp->comp()->fej9()->canDereferenceAtCompileTime(curNode->getSymbolReference(), vp->comp()))
{
// we can continue up the dereference chain
if (vp->trace())
traceMsg(vp->comp(), " - %s %p is %s\n", curNode->getOpCode().getName(), curNode, curNode->getSymbolReference()->getName(vp->comp()->getDebug()));
continue;
}
#endif
else
{
if (vp->trace())
traceMsg(vp->comp(), " - FAIL: %s %p is %s\n", curNode->getOpCode().getName(), curNode, curNode->getSymbolReference()->getName(vp->comp()->getDebug()));
break;
}
}
if (baseExpression)
{
// We've got something we can ask the front end to transform
//
TR::Node *nodeToRemove = NULL;
bool didSomething = TR::TransformUtil::transformIndirectLoadChain(vp->comp(), node, baseExpression, baseKnownObject, &nodeToRemove);
if (nodeToRemove)
{
TR_ASSERT(didSomething, "How can there be a node to remove if transformIndirectLoadChain didn't do something??");
vp->removeNode(nodeToRemove, true);
}
return didSomething;
}
else
{
return false;
}
}
else
{
// Do direct loads too
return false;
}
TR_ASSERT(0, "Shouldn't get here");
return true; // Safe default
}
static bool constrainCompileTimeLoad(OMR::ValuePropagation *vp, TR::Node *node)
{
bool isGlobal;
if (!tryFoldCompileTimeLoad(vp, node, isGlobal))
return false;
// Add a constraint so that VP can continue with the constant value.
constrainNewlyFoldedConst(vp, node, isGlobal);
return true;
}
static bool findConstant(OMR::ValuePropagation *vp, TR::Node *node)
{
// See if the node is already known to be a constant
//
bool isGlobal;
TR::VPConstraint *constraint = vp->getConstraint(node, isGlobal);
if (constraint)
{
TR::DataType type = node->getDataType();
switch (type)
{
case TR::Int64:
case TR::Double:
if (constraint->asLongConst())
{
bool replacedConst = false;
if (!vp->cg()->materializesLargeConstants() ||
(!node->getType().isInt64()) ||
(constraint->asLongConst()->getLong() < vp->cg()->getSmallestPosConstThatMustBeMaterialized() &&
constraint->asLongConst()->getLong() > vp->cg()->getLargestNegConstThatMustBeMaterialized()) ||
(vp->getCurrentParent()->getOpCode().isMul() &&
(vp->getCurrentParent()->getSecondChild() == node) &&
isNonNegativePowerOf2(constraint->asLongConst()->getLong())))
{
vp->replaceByConstant(node, constraint, isGlobal);
replacedConst = true;
}
if (constraint->getLowLong())
node->setIsNonZero(true);
else
node->setIsZero(true);
return replacedConst;
}
break;
case TR::Address:
if (constraint->isNullObject())
{
vp->replaceByConstant(node, constraint, isGlobal);
node->setIsNull(true);
return true;
}
else if (constraint->isNonNullObject())
{
node->setIsNonNull(true);
if (constraint->getKnownObject())
{
TR::VPKnownObject *knownObject = constraint->getKnownObject();
// Don't do direct loads here till we get the aliasing right
if (node->getOpCode().isLoadIndirect() && !node->getSymbolReference()->hasKnownObjectIndex())
{
TR::KnownObjectTable *knot = vp->comp()->getKnownObjectTable();
TR_ASSERT(knot, "Can't have a known-object constraint without a known-object table");
TR::SymbolReference *improvedSymRef = vp->comp()->getSymRefTab()->findOrCreateSymRefWithKnownObject(node->getSymbolReference(), knownObject->getIndex());
if (improvedSymRef->hasKnownObjectIndex())
{
if (performTransformation(vp->comp(), "%sUsing known-object specific symref #%d for obj%d at [%p]\n", OPT_DETAILS, improvedSymRef->getReferenceNumber(), knownObject->getIndex(), node))
{
node->setSymbolReference(improvedSymRef);
return true;
}
}
}
}
}
break;
default:
if (constraint->asIntConstraint())
{
int32_t value = constraint->getLowInt();
if (constraint->asIntConst())
{
bool replacedConst = false;
if (!vp->cg()->materializesLargeConstants() ||
(!node->getType().isInt32()) ||
(value < vp->cg()->getSmallestPosConstThatMustBeMaterialized() &&
value > vp->cg()->getLargestNegConstThatMustBeMaterialized()) ||
(vp->getCurrentParent()->getOpCode().isMul() &&
(vp->getCurrentParent()->getSecondChild() == node) &&
isNonNegativePowerOf2(value))
)
{
vp->replaceByConstant(node, constraint, isGlobal);
replacedConst = true;
}
if (value)
node->setIsNonZero(true);
else
node->setIsZero(true);
return replacedConst;
}
else if (value >= 0)
node->setIsNonNegative(true);
if (constraint->getHighInt() <= 0)
node->setIsNonPositive(true);
if ((node->getOpCode().isArithmetic() || node->getOpCode().isLoad()) &&
((value > TR::getMinSigned<TR::Int32>()) || (constraint->getHighInt() < TR::getMaxSigned<TR::Int32>())))
{
node->setCannotOverflow(true);
}
}
else if (constraint->asShortConstraint())
{
int16_t value = constraint->getLowShort();
if (constraint->asShortConst())
{
bool replacedConst = false;
if (!vp->cg()->materializesLargeConstants() ||
(!node->getType().isInt16()) ||
(value < vp->cg()->getSmallestPosConstThatMustBeMaterialized() &&
value > vp->cg()->getLargestNegConstThatMustBeMaterialized()) ||
(vp->getCurrentParent()->getOpCode().isMul() &&
vp->getCurrentParent()->getSecondChild() == node &&
isNonNegativePowerOf2(value)))
{
vp->replaceByConstant(node,constraint,isGlobal);
replacedConst = true;
}
if (value)
node->setIsNonZero(true);
else
node->setIsZero(true);
return replacedConst;
}
else if (value >= 0)
node->setIsNonNegative(true);
if (constraint->getHighShort() <= 0)
node->setIsNonPositive(true);
if ((node->getOpCode().isArithmetic() || node->getOpCode().isLoad()) &&
((value > TR::getMinSigned<TR::Int16>()) || (constraint->getHighShort() < TR::getMaxSigned<TR::Int16>())))
{
node->setCannotOverflow(true);
}
}
break;
}
}
return false;
}
static bool containsUnsafeSymbolReference(OMR::ValuePropagation *vp, TR::Node *node)
{
if (node->getSymbolReference()->isLitPoolReference())
return true;
if (node->getSymbolReference()->getSymbol()->isShadow())
{
if (node->getSymbol()->isUnsafeShadowSymbol())
{
if (vp->trace())
traceMsg(vp->comp(), "Node [%p] has an unsafe symbol reference %d, no constraint\n", node,
node->getSymbolReference()->getReferenceNumber());
return true;
}
if (node->getSymbolReference() == vp->getSymRefTab()->findInstanceShapeSymbolRef() ||
node->getSymbolReference() == vp->getSymRefTab()->findInstanceDescriptionSymbolRef() ||
node->getSymbolReference() == vp->getSymRefTab()->findDescriptionWordFromPtrSymbolRef() ||
#ifdef J9_PROJECT_SPECIFIC
node->getSymbolReference() == vp->getSymRefTab()->findClassFromJavaLangClassAsPrimitiveSymbolRef() ||
#endif
(node->getSymbolReference()->getSymbol() == vp->comp()->getSymRefTab()->findGenericIntShadowSymbol()))
return true;
}
return false;
}
static bool owningMethodDoesNotContainNullChecks(OMR::ValuePropagation *vp, TR::Node *node)
{
TR::ResolvedMethodSymbol *method = node->getSymbolReference()->getOwningMethodSymbol(vp->comp());
if (method && method->skipNullChecks())
return true;
return false;
}
bool constraintFitsInIntegerRange(OMR::ValuePropagation *vp, TR::VPConstraint *constraint)
{
if (constraint == NULL)
return false;
TR::VPLongConstraint *longConstraint = constraint->asLongConstraint();
TR::VPIntConstraint *intConstraint = constraint->asIntConstraint();
TR::VPShortConstraint *shortConstraint = constraint->asShortConstraint();
if (longConstraint)
{
int64_t low = longConstraint->getLowLong(), high = longConstraint->getHighLong();
if (low >= TR::getMinSigned<TR::Int32>() && high <= TR::getMaxSigned<TR::Int32>())
return true;
}
else if (intConstraint || shortConstraint)
return true;
return false;
}
bool canMoveLongOpChildDirectly(TR::Node *node, int32_t numChild, TR::Node *arithNode)
{
return node->getChild(numChild)->getDataType() == arithNode->getDataType() || (node->getOpCodeValue() == TR::lshr && numChild > 0);
}
bool reduceLongOpToIntegerOp(OMR::ValuePropagation *vp, TR::Node *node, TR::VPConstraint *nodeConstraint)
{
if (!constraintFitsInIntegerRange(vp, nodeConstraint))
return false;
for (int32_t i = 0; i < node->getNumChildren(); i++)
{
bool isGlobal;
TR::VPConstraint *childConstraint = vp->getConstraint(node->getChild(i), isGlobal);
if (!constraintFitsInIntegerRange(vp, childConstraint))
return false;
}
// Adding this check because it is likely suboptimal on machines where you can use long registers to convert things to integers and insert conversion trees.
// Conversion trees are not free.
// LoadExtensions (and other codegen peepholes) should in theory catch uneeded conversions (like widening) as described in the case below on 64 bit platforms.
if (vp->comp()->target().is64Bit() || vp->comp()->cg()->use64BitRegsOn32Bit())
return false;
// The node and all children have constraints that fit in integer range.
// lrem becomes i2l
// i2l irem (new node)
// iload iload (get rid of the l2i)
// lconst l2i (new node)
// lconst
TR::ILOpCodes newOp = TR::ILOpCode::integerOpForLongOp(node->getOpCodeValue());
if (newOp == TR::BadILOp)
return false;
if (performTransformation(vp->comp(), "%sReduce %s (0x%p) to integer arithmetic\n",
OPT_DETAILS, node->getOpCode().getName(), node))
{
TR::Node *arithNode = TR::Node::create(node, newOp, node->getNumChildren());
for (int32_t i = 0; i < node->getNumChildren(); i++)
{
TR::Node *child = node->getChild(i);
if (canMoveLongOpChildDirectly(node, i, arithNode))
{
arithNode->setAndIncChild(i, child);
dumpOptDetails(vp->comp(), " Transfer integer child %d %s (0x%p)\n", i, child->getOpCode().getName(), child);
}
else if (child->getOpCode().isConversion() && child->getFirstChild()->getDataType() == arithNode->getDataType())
{
if (child->getReferenceCount() > 1)
vp->anchorNode(child, vp->_curTree);
arithNode->setAndIncChild(i, child->getFirstChild());
dumpOptDetails(vp->comp(), " Replacing child %d %s (0x%p) with grandchild %s (0x%p)\n", i, child->getOpCode().getName(), child, child->getFirstChild()->getOpCode().getName(), child->getFirstChild());
}
else
{
TR::Node *newChild = TR::Node::create(node, TR::ILOpCode::getProperConversion(child->getDataType(), arithNode->getDataType(), false), 1);
newChild->setAndIncChild(0, child);
arithNode->setAndIncChild(i, newChild);
dumpOptDetails(vp->comp(), " Creating new %s (0x%p) above child %d %s (0x%p)\n", newChild->getOpCode().getName(), newChild, i, child->getOpCode().getName(), child);
}
}
vp->prepareToReplaceNode(node, TR::ILOpCode::getProperConversion(arithNode->getDataType(), node->getDataType(), false));
node->setNumChildren(1);
node->setAndIncChild(0, arithNode);
dumpOptDetails(vp->comp(), " Changed (0x%p) to %s with new child %s (0x%p)\n", node, node->getOpCode().getName(), arithNode->getOpCode().getName(), arithNode);
return true;
}
return false;
}
static void constrainAConst(OMR::ValuePropagation *vp, TR::Node *node, bool isGlobal)
{
TR::VPConstraint *constraint = NULL;
if (node->getAddress() == 0)
{
constraint = TR::VPNullObject::create(vp);
node->setIsNull(true);
}
else
{
constraint = TR::VPNonNullObject::create(vp);
node->setIsNonNull(true);
if (node->isClassPointerConstant())
{
TR::VPConstraint *typeConstraint = TR::VPClass::create(vp, TR::VPFixedClass::create(vp, (TR_OpaqueClassBlock *) node->getAddress()),
NULL, NULL, NULL,
TR::VPObjectLocation::create(vp, TR::VPObjectLocation::J9ClassObject));
vp->addBlockOrGlobalConstraint(node, typeConstraint, isGlobal);
}
}
vp->addBlockOrGlobalConstraint(node, constraint, isGlobal);
}
TR::Node *constrainAConst(OMR::ValuePropagation *vp, TR::Node *node)
{
constrainAConst(vp, node, true /* isGlobal */);
return node;
}
static void constrainIntAndFloatConstHelper(OMR::ValuePropagation *vp, TR::Node *node, int32_t value, bool isGlobal)
{
if (value)
{
node->setIsNonZero(true);
if (value & TR::getMinSigned<TR::Int32>())
node->setIsNonPositive(true);
else
node->setIsNonNegative(true);
}
else
{
node->setIsZero(true);
node->setIsNonNegative(true);
node->setIsNonPositive(true);
}
vp->addBlockOrGlobalConstraint(node, TR::VPIntConst::create(vp, value), isGlobal);
}
static void constrainIntConst(OMR::ValuePropagation *vp, TR::Node *node, bool isGlobal)
{
int32_t value = node->getInt();
constrainIntAndFloatConstHelper(vp, node, value, isGlobal);
}
TR::Node *constrainIntConst(OMR::ValuePropagation *vp, TR::Node *node)
{
constrainIntConst(vp, node, true /* isGlobal */);
return node;
}
TR::Node *constrainFloatConst(OMR::ValuePropagation *vp, TR::Node *node)
{
int32_t value = node->getFloatBits();
constrainIntAndFloatConstHelper(vp, node, value, true /* isGlobal */);
return node;
}
static void constrainLongConst(OMR::ValuePropagation *vp, TR::Node *node, bool isGlobal)
{
int64_t value = node->getLongInt();
if (value)
{
node->setIsNonZero(true);
if (value & TR::getMinSigned<TR::Int64>())
node->setIsNonPositive(true);
else
node->setIsNonNegative(true);
}
else
{
node->setIsZero(true);
node->setIsNonNegative(true);
node->setIsNonPositive(true);
}
vp->addBlockOrGlobalConstraint(node, TR::VPLongConst::create(vp, value), isGlobal);
}
TR::Node *constrainLongConst(OMR::ValuePropagation *vp, TR::Node *node)
{
constrainLongConst(vp, node, true /* isGlobal */);
return node;
}
TR::Node *constrainByteConst(OMR::ValuePropagation *vp, TR::Node *node)
{
int8_t value = node->getByte();
if (value)
{
node->setIsNonZero(true);
if (value & TR::getMinSigned<TR::Int8>())
node->setIsNonPositive(true);
else
node->setIsNonNegative(true);
}
else
{
node->setIsZero(true);
node->setIsNonNegative(true);
node->setIsNonPositive(true);
}
// treat constants as always signed. its upto the consumer
// to decide if a sign-extension or zero-extension (for unsigned
// datatypes like c2i, bu2i) is needed
// also donot generate a new global constraint at this point if
// one is already available.
//
bool isGlobal;
TR::VPConstraint *constraint = vp->getConstraint(node, isGlobal);
if (!constraint)
vp->addGlobalConstraint(node, TR::VPIntConst::create(vp, value));
return node;
}
TR::Node *constrainShortConst(OMR::ValuePropagation *vp, TR::Node *node)
{
int16_t value = node->getShortInt();
if (value)
{
node->setIsNonZero(true);
if (value & TR::getMinSigned<TR::Int16>())
node->setIsNonPositive(true);
else
node->setIsNonNegative(true);
}
else
{
node->setIsZero(true);
node->setIsNonNegative(true);
node->setIsNonPositive(true);
}
// see comments above for byteConst
bool isGlobal;
TR::VPConstraint *constraint = vp->getConstraint(node, isGlobal);
if (!constraint)
vp->addGlobalConstraint(node, TR::VPShortConst::create(vp, value));
return node;
}
// constrainBCDSign tracks 3 ways a known sign can be retrieved from a node
// 1) via a specific known sign tracked on the node itself (this could be for any type of BCD node)
// 2a) for a setsign operation where the setsign value is on the node itself
// 2b) for a setsign operation where the setsign value is a const child of the node
//
#ifdef J9_PROJECT_SPECIFIC
#define TR_ENABLE_BCD_SIGN (true)