-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathOMRMemoryReference.cpp
3552 lines (3164 loc) · 133 KB
/
OMRMemoryReference.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, 2020 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
*******************************************************************************/
//On zOS XLC linker can't handle files with same name at link time
//This workaround with pragma is needed. What this does is essentially
//give a different name to the codesection (csect) for this file. So it
//doesn't conflict with another file with same name.
#pragma csect(CODE,"OMRZMemoryReference#C")
#pragma csect(STATIC,"OMRZMemoryReference#S")
#pragma csect(TEST,"OMRZMemoryReference#T")
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "codegen/CodeGenerator.hpp"
#include "codegen/ConstantDataSnippet.hpp"
#include "env/FrontEnd.hpp"
#include "codegen/InstOpCode.hpp"
#include "codegen/Instruction.hpp"
#include "codegen/Linkage.hpp"
#include "codegen/Linkage_inlines.hpp"
#include "codegen/LiveRegister.hpp"
#include "codegen/Machine.hpp"
#include "codegen/MemoryReference.hpp"
#include "codegen/RealRegister.hpp"
#include "codegen/Register.hpp"
#include "codegen/RegisterConstants.hpp"
#include "codegen/RegisterPair.hpp"
#include "codegen/Relocation.hpp"
#include "codegen/Snippet.hpp"
#include "codegen/TreeEvaluator.hpp"
#include "codegen/UnresolvedDataSnippet.hpp"
#include "compile/Compilation.hpp"
#include "compile/ResolvedMethod.hpp"
#include "compile/SymbolReferenceTable.hpp"
#include "control/Options.hpp"
#include "control/Options_inlines.hpp"
#include "env/CompilerEnv.hpp"
#include "env/ObjectModel.hpp"
#include "env/StackMemoryRegion.hpp"
#include "env/TRMemory.hpp"
#include "env/defines.h"
#include "env/jittypes.h"
#include "il/AutomaticSymbol.hpp"
#include "il/Block.hpp"
#include "il/DataTypes.hpp"
#include "il/ILOpCodes.hpp"
#include "il/ILOps.hpp"
#include "il/Node.hpp"
#include "il/Node_inlines.hpp"
#include "il/RegisterMappedSymbol.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/Flags.hpp"
#include "infra/List.hpp"
#include "ras/Debug.hpp"
#include "z/codegen/EndianConversion.hpp"
#include "z/codegen/S390Evaluator.hpp"
#include "z/codegen/S390GenerateInstructions.hpp"
#include "z/codegen/S390Instruction.hpp"
#if J9_PROJECT_SPECIFIC
#include "z/codegen/S390Register.hpp"
#endif
/**
* Check to see if mem ref is declared during instruction selection phase
* and if so, if the current treetop node is null
* if it is, the mem ref can cause an implicit null pointer exception
*/
void OMR::Z::MemoryReference::setupCausesImplicitNullPointerException(TR::CodeGenerator *cg)
{
if (cg->getSupportsImplicitNullChecks() &&
cg->getCurrentEvaluationTreeTop()->getNode()->getOpCode().isNullCheck())
{
self()->setCausesImplicitNullPointerException();
}
}
/**
* Aligned memRefs are sometimes created with negative offsets that will eventually be removed after applying bumps for left or right alignment
* So a premature LAY or LA/AHI fixup is not done for these negative offsets a flag HasTemporaryNegativeOffset is set on the memRef to prevent this fixup
* However, if there is already a real negative offset then the fixup is required for this part of the negative offset
* To deal with this first split off the real negative offset by calling enforceSSFormatLimits and then set the HasTemporaryNegativeOffset flag and add in the new negative offset
*/
void OMR::Z::MemoryReference::addToTemporaryNegativeOffset(TR::Node *node, int32_t offset, TR::CodeGenerator *cg)
{
TR::Compilation *comp = cg->comp();
if (offset < 0)
{
if (cg->traceBCDCodeGen())
traceMsg(comp,"\taddToTemporaryNegativeOffset : %s (%p) new offset %d, existing mr offset %d (existing mr hasTempNegOffset = %s)\n",
node?node->getOpCode().getName():"NULL",node,offset,self()->getOffset(),self()->hasTemporaryNegativeOffset()?"yes":"no");
if (self()->getOffset() < 0 && !self()->hasTemporaryNegativeOffset()) // if there is a 'real' negative offset then deal with this first before adding in the temporary negative offset
{
if (cg->traceBCDCodeGen())
traceMsg(comp,"\t\texisting mr->offset %d < 0 so call enforceSSFormatLimits to clear this up before setting HasTemporaryNegativeOffset\n",self()->getOffset());
self()->enforceSSFormatLimits(node, cg, NULL); // call SSFormatLimits to also take this chance to fold in an index register if needed
}
self()->addToOffset(offset);
self()->setHasTemporaryNegativeOffset();
}
}
/**
* Check to see if mem ref is declared during inst selection phase
* and then enable the check for the binary phase
*/
void OMR::Z::MemoryReference::setupCheckForLongDispFlag(TR::CodeGenerator *cg)
{
// Enable a check for the long disp slot in generateBin phase
if (cg->getCodeGeneratorPhase() == TR::CodeGenPhase::InstructionSelectionPhase)
{
self()->setCheckForLongDispSlot();
}
}
/**
* forceFolding is not a good idea to always set as it has the side effect of incrementing the
* refCounts for all children in the address tree. So if folding is not done then poorer quality
* code (due to more clobberEvals from the higher refCounts) will be generated.
* In some simple cases where folding is very likely then forceFolding is set (the higher refCounts do not
* matter as the evaluators are not actually going to be called)
* Note that setting forceFolding does not require that folding will be done it only allows it to be possible
*/
bool OMR::Z::MemoryReference::setForceFoldingIfAdvantageous(TR::CodeGenerator * cg, TR::Node * addressChild)
{
TR::Compilation *comp = cg->comp();
// Force folding if it will make a standard memory reference: X(B) or X(I,B)
if (addressChild->getRegister() != NULL)
{
// cannot fold:
//
// aiadd (reg)
// node/tree
// iconst
if (cg->traceBCDCodeGen())
{
traceMsg(comp, " inside setForceFoldingIfAdvantageous, addressChild %s (%p) has register %s\n",
addressChild->getOpCode().getName(), addressChild,
cg->getDebug()->getName(addressChild->getRegister()));
}
return false;
}
if (!addressChild->getOpCode().isAdd())
{
if (cg->traceBCDCodeGen())
{
traceMsg(comp, " inside setForceFoldingIfAdvantageous, addressChild %s (%p) is not an add type - most likely cannot fold\n",
addressChild->getOpCode().getName(), addressChild);
}
return false;
}
if (!addressChild->getSecondChild()->getOpCode().isLoadConst())
{
if (cg->traceBCDCodeGen())
{
traceMsg(comp, " inside setForceFoldingIfAdvantageous, addressChild %s (%p) second child is not a load const - cannot fold\n",
addressChild->getOpCode().getName(), addressChild);
}
return false;
}
if (addressChild->getSecondChild()->getRegister() != NULL)
{
// cannot fold:
//
// aiadd
// node/tree
// iconst (reg)
if (cg->traceBCDCodeGen())
{
traceMsg(comp, " inside setForceFoldingIfAdvantageous, addressChild %s (%p) const child %s (%p) has register %s, cannot fold.\n",
addressChild->getOpCode().getName(), addressChild,
addressChild->getSecondChild()->getOpCode().getName(), addressChild->getSecondChild(),
cg->getDebug()->getName(addressChild->getSecondChild()->getRegister()));
}
return false;
}
if (addressChild->getReferenceCount() != 1)
{
if (cg->traceBCDCodeGen())
{
traceMsg(comp, " inside setForceFoldingIfAdvantageous, addressChild %s (%p) has ref count %d, cannot fold, need value in register.\n",
addressChild->getOpCode().getName(), addressChild, addressChild->getReferenceCount());
}
return false;
}
// Past here, addressChild :
// - has no register
// - is an add
// - second child is a load const and was not evaluated into a register
// - has ref count 1
TR::Node * eventualNonConversion = addressChild->getFirstChild();
TR::Node * foundConvNodeWithRegister = 0;
bool allConvNodesAreUnneeded = true;
bool allConvNodesHaveRefCount1 = true;
bool haveToEvalConvIntoRegister = false;
// "See through" conversions
while (eventualNonConversion->getOpCode().isConversion())
{
if ((foundConvNodeWithRegister == 0) && (eventualNonConversion->getRegister() != NULL))
{
foundConvNodeWithRegister = eventualNonConversion;
}
allConvNodesAreUnneeded = allConvNodesAreUnneeded && eventualNonConversion->isUnneededConversion();
allConvNodesHaveRefCount1 = allConvNodesHaveRefCount1 && (eventualNonConversion->getReferenceCount() == 1);
haveToEvalConvIntoRegister = haveToEvalConvIntoRegister ||
((eventualNonConversion->getReferenceCount() != 1) && (eventualNonConversion->getRegister() == NULL));
eventualNonConversion = eventualNonConversion->getFirstChild();
}
if (haveToEvalConvIntoRegister)
{
if (cg->traceBCDCodeGen())
{
traceMsg(comp,
" inside setForceFoldingIfAdvantageous, addressChild %s (%p) first child has conv. with ref count > 1 and no register, must evaluate - setForceFolding()\n",
addressChild->getOpCode().getName(), addressChild);
}
cg->evaluate(addressChild->getFirstChild());
self()->setForceFolding();
return true;
}
// if conversions are real, don't want to bump up ref counts either for perf reasons
// only allow folding if conversions are deemed 'unneeded' by LoadExtension step
if (!allConvNodesAreUnneeded)
{
if (cg->traceBCDCodeGen())
{
traceMsg(comp,
" inside setForceFoldingIfAdvantageous, addressChild %s (%p) first child has conv. which are needed, folding after evaluation.\n",
addressChild->getOpCode().getName(), addressChild);
}
cg->evaluate(addressChild->getFirstChild());
self()->setForceFolding();
return true;
}
// Past here:
// - each conversion is ref count 1 (with or without register), or ref count > 2 and has a register
bool foundRegister = eventualNonConversion->getRegister() ||
(foundConvNodeWithRegister && foundConvNodeWithRegister->getRegister());
if (foundRegister)
{
// aiadd
// node/tree (reg)
// iconst
//
// or
//
// aiadd
// conv
// conv (reg)
// loadaddr / aload / aRegLoad (reg)
// iconst
//
// or
//
// aiadd
// conv
// conv
// loadaddr / aload / aRegLoad (reg)
// iconst
if (cg->traceBCDCodeGen())
{
TR::Node * dispNode = eventualNonConversion->getRegister() ? eventualNonConversion : foundConvNodeWithRegister;
traceMsg(comp,"\t\taddressChild %s (%p) node %s (%p) is evaluatedReg+const (%s + %lld) so %s=true\n",
addressChild->getOpCode().getName(),addressChild,
dispNode->getOpCode().getName(), dispNode,
cg->getDebug()->getName(dispNode->getRegister()),
addressChild->getSecondChild()->get64bitIntegralValue(),
"setForceFirstTimeFolding");
}
self()->setForceFirstTimeFolding(); // e.g. fold the top level add but not anything below the add
return true;
}
bool eventualNonConversionIsSuitableForFolding =
(eventualNonConversion->getOpCodeValue() == TR::loadaddr ||
eventualNonConversion->getOpCode().isLoad() ||
eventualNonConversion->getRegister() ||
eventualNonConversion->getOpCode().isLoadReg());
if (!eventualNonConversionIsSuitableForFolding)
{
if (cg->traceBCDCodeGen())
{
traceMsg(comp,
" inside setForceFoldingIfAdvantageous, addressChild %s (%p) eventual non conversion %s (%p) is not suitable for folding.\n",
addressChild->getOpCode().getName(), addressChild,
eventualNonConversion->getOpCode().getName(), eventualNonConversion);
}
// TODO: first time folding here? still desirable axadd form
return false;
}
if (!eventualNonConversion->getOpCode().isIndirect())
{
// aiadd
// loadaddr/aload/aRegLoad
// iconst
//
// or
//
// aiadd
// conv
// conv
// loadaddr/aload/aRegLoad
// iconst
if (cg->traceBCDCodeGen())
{
traceMsg(comp," inside setForceFoldingIfAdvantageous, eventualNonConversion %s (%p) has no register and refCount==1 and is a aload+const so setForceFolding=true\n",
eventualNonConversion->getOpCode().getName(),eventualNonConversion);
}
self()->setForceFolding();
return true;
}
else // if (eventualNonConversion->getReferenceCount() == 1)
{
// aiadd
// iaload
// x
// iconst
//
// or
//
// aiadd
// conv
// iaload
// x
// iconst
if (cg->traceBCDCodeGen())
{
traceMsg(comp,
" inside setForceFoldingIfAdvantageous, eventualNonConversion %s (%p) has no register and refCount==1 and is an iaload+const so eval(%s - %p) and setForceFolding=true\n",
eventualNonConversion->getOpCode().getName(),eventualNonConversion,
eventualNonConversion->getFirstChild()->getOpCode().getName(),eventualNonConversion->getFirstChild());
}
self()->setForceFolding();
cg->evaluate(addressChild->getFirstChild());
return true;
}
return false;
}
/**
* Recall that with storage hints, trees are usually traversed / decended twice, both usually with an implied reference.
*
* Evaluation will descend the tree until a register is encountered (much like recursivelyIncrementReferenceCount), so evaluation (and therefore
* the reference count decrementing that evaluators do) will miss nodes that are part of the incremented nodes list and that are under a node that
* was assigned a register after memory reference population. This function will descend the tree and look for this case, only removing nodes if a
* node with a register was seen. It is important to only decend down nodes that are part of the incremented nodes list, because that is what the
* recursivelyIncrementReferenceCount function did before.
*/
void recursivelyDecrementIncrementedNodesIfUnderRegister(TR::CodeGenerator * cg, TR::Node * cur, List<TR::Node> & _incNodesList, List<TR::Node> &nodesToNotRecurse,
vcount_t vc, bool startRemoving)
{
if (cur->getVisitCount() == vc)
{
return;
}
cur->setVisitCount(vc);
bool foundCurNode = false;
TR::Compilation *comp = cg->comp();
// search for the current node in the list, and remove + decrement if found
ListIterator<TR::Node> listIt(&_incNodesList);
TR::Node* listNode;
for (listNode = listIt.getFirst(); listNode; listNode = listIt.getNext())
{
if (listNode == cur)
{
foundCurNode = true;
if (startRemoving)
{
if (cg->traceBCDCodeGen())
{
traceMsg(comp,"\t decReferenceCount on incremented node %p (%d) (%d->%d)\n",
cur, cur->getGlobalIndex(), cur->getReferenceCount(), cur->getReferenceCount()-1);
}
cg->decReferenceCount(cur);
}
break;
}
}
if (!foundCurNode)
{
// Return if the node we are at is not part of the incremented nodes list.
return;
}
// if the node already had a register before recursive increment, then do not recursively decrement its children
listIt.set(&nodesToNotRecurse);
for (listNode = listIt.getFirst(); listNode; listNode = listIt.getNext())
{
if (listNode == cur)
return;
}
// Do not remove the current node if it has a register, so perform check afterwards.
if (cur->getRegister() != NULL)
{
if (cg->traceBCDCodeGen())
{
traceMsg(comp,"\t %s [%p] (%d) has a register, so start removing under it\n",
cur->getOpCode().getName(), cur, cur->getGlobalIndex());
}
startRemoving = true;
}
for (size_t i = 0; i < cur->getNumChildren(); i++)
{
recursivelyDecrementIncrementedNodesIfUnderRegister(cg, cur->getChild(i), _incNodesList, nodesToNotRecurse, vc, startRemoving);
}
}
OMR::Z::MemoryReference::MemoryReference(TR::Node * rootLoadOrStore, TR::CodeGenerator * cg, bool canUseRX, TR_StorageReference *storageReference)
: _baseRegister(NULL), _baseNode(NULL), _indexRegister(NULL), _indexNode(NULL), _targetSnippet(NULL),
_symbolReference(rootLoadOrStore->getOpCode().hasSymbolReference()?rootLoadOrStore->getSymbolReference():NULL),
_originalSymbolReference(rootLoadOrStore->getOpCode().hasSymbolReference()?rootLoadOrStore->getSymbolReference():NULL),
_listingSymbolReference(NULL),
_offset(0), _flags(0), _storageReference(storageReference), _fixedSizeForAlignment(0), _leftMostByte(0), _name(NULL),
_incrementedNodesList(cg->comp()->trMemory())
{
TR::SymbolReference * symRef = rootLoadOrStore->getOpCode().hasSymbolReference() ? rootLoadOrStore->getSymbolReference() : NULL;
TR::Symbol * symbol = symRef ? symRef->getSymbol() : NULL;
bool isStore = rootLoadOrStore->getOpCode().isStore();
TR::Register * tempReg = rootLoadOrStore->getRegister();
bool alloc = false;
TR::Compilation *comp = cg->comp();
List<TR::Node> nodesAlreadyEvaluatedBeforeFoldingList(comp->trMemory());
_listingSymbolReference = TR::MemoryReference::shouldLabelForRAS(_symbolReference, cg)? _symbolReference : NULL;
if (tempReg == NULL || tempReg->getKind() == TR_FPR)
{
tempReg = cg->allocateRegister();
alloc = true;
}
// Enable a check for the long disp slot in generateBin phase
self()->setupCheckForLongDispFlag(cg);
self()->setupCausesImplicitNullPointerException(cg);
_targetSnippetInstruction = NULL;
TR_ASSERT(_incrementedNodesList.getHeadData() == 0,
"_incrementedNodesList size is not zero at beginning of OMR::Z::MemoryReference constructor!");
self()->tryForceFolding(rootLoadOrStore, cg, storageReference, symRef, symbol, nodesAlreadyEvaluatedBeforeFoldingList);
if (rootLoadOrStore->getOpCode().isIndirect() || self()->isExposedConstantAddressing())
{
TR::Node * subTree = rootLoadOrStore->getFirstChild();
if (subTree->getOpCodeValue() == TR::aconst)
{
if (!self()->ZeroBasePtr_EvaluateSubtree(subTree, cg, this))
self()->setBaseRegister(cg->evaluate(subTree), cg);
_baseNode = subTree;
cg->decReferenceCount(subTree);
}
else
{
TR::Node *addressChild = rootLoadOrStore->getFirstChild();
bool tryBID = (addressChild->getOpCodeValue() == TR::aiadd ||
addressChild->getOpCodeValue() == TR::aladd) &&
_baseRegister == NULL && _indexRegister == NULL &&
self()->tryBaseIndexDispl(cg, rootLoadOrStore, addressChild);
if (!tryBID)
{
self()->populateMemoryReference(subTree, cg);
recursivelyDecrementIncrementedNodesIfUnderRegister(cg, subTree, _incrementedNodesList, nodesAlreadyEvaluatedBeforeFoldingList, comp->incOrResetVisitCount(), false);
cg->decReferenceCount(subTree);
}
}
if ((symbol && symbol->isStatic()) &&
rootLoadOrStore->getFirstChild()->getOpCode().hasSymbolReference() &&
rootLoadOrStore->getFirstChild()->getSymbolReference()->getSymbol()->isStatic()&&
rootLoadOrStore->getFirstChild()->getSymbolReference()->isUnresolved()&&
symRef->isUnresolved() && symRef && !symRef->isFromLiteralPool() &&
rootLoadOrStore->getFirstChild()->getSymbolReference()->isFromLiteralPool() )
{
if (alloc)
{
cg->stopUsingRegister(tempReg);
}
return;
}
if ((symbol && symbol->isStatic()) && symRef && symRef->isFromLiteralPool() && !self()->isExposedConstantAddressing())
{
TR_ASSERT(cg->supportsOnDemandLiteralPool() == true, "May not be here with Literal Pool On Demand disabled\n");
if (symRef->isUnresolved())
{
self()->createUnresolvedDataSnippetForiaload(rootLoadOrStore, cg, symRef, tempReg, isStore);
}
else
{
uintptr_t staticAddressValue = (uintptr_t) symbol->getStaticSymbol()->getStaticAddress();
TR::S390ConstantDataSnippet * targetsnippet;
if (cg->comp()->target().is64Bit())
{
targetsnippet = cg->findOrCreate8ByteConstant(0, staticAddressValue);
}
else
{
targetsnippet = cg->findOrCreate4ByteConstant(0, staticAddressValue);
}
self()->initSnippetPointers(targetsnippet, cg);
}
if (alloc)
{
cg->stopUsingRegister(tempReg);
}
return;
}
if (symRef && symRef->isUnresolved())
{
self()->createUnresolvedDataSnippet(rootLoadOrStore, cg, symRef, tempReg, isStore);
}
}
else
{
// symbol is static
if (symbol && symbol->isStatic())
{
// symbol is unresolved
if (symRef && symRef->isUnresolved())
{
TR::UnresolvedDataSnippet * uds = self()->createUnresolvedDataSnippet(rootLoadOrStore, cg, symRef, tempReg, isStore);
self()->createPatchableDataInLitpool(rootLoadOrStore, cg, tempReg, uds);
}
else
{
// symbol is resolved
if (isStore)
{
// Storing to the symbol reference
TR::Register * tempReg;
if (cg->comp()->target().is64Bit())
tempReg = cg->allocateRegister();
else
tempReg = cg->allocateRegister();
self()->setBaseRegister(tempReg, cg);
cg->stopUsingRegister(_baseRegister);
_baseNode = NULL;
}
else
{
if (symbol && symbol->isMethodMetaData())
self()->setBaseRegister(cg->getMethodMetaDataRealRegister(), cg);
else
self()->setBaseRegister(tempReg, cg);
}
genLoadAddressConstant(cg, rootLoadOrStore, (uintptr_t) symRef->getSymbol()->getStaticSymbol()->getStaticAddress(),
_baseRegister);
cg->stopUsingRegister(tempReg);
}
}
else if (!symRef)
{
if (!rootLoadOrStore->getOpCode().isLoad() && !rootLoadOrStore->getOpCode().isStore())
{
// this is a valid path through this constructor, despite what the variable name might mean
//
// for example, calling generateMemoryReference([node], cg) on an aiadd node will arrive here.
self()->populateMemoryReference(rootLoadOrStore, cg);
if (alloc)
{
cg->stopUsingRegister(tempReg);
}
return;
}
else
{
TR_ASSERT(rootLoadOrStore->getDataType() == TR::Address || rootLoadOrStore->getOpCode().isLoadConst(),
"rootLoadOrStore %s %p should be an address type or const op and not dt %s\n", rootLoadOrStore->getOpCode().getName(), rootLoadOrStore,rootLoadOrStore->getDataType().toString());
//TR_ASSERT(rootLoadOrStore->getDataType() == TR::Address,
// "rootLoadOrStore %s %p should be an address type and not dt %d\n",rootLoadOrStore->getOpCode().getName(),rootLoadOrStore,rootLoadOrStore->getDataType());
self()->populateThroughEvaluation(rootLoadOrStore, cg);
if (alloc)
{
cg->stopUsingRegister(tempReg);
}
return;
}
}
else
{
// must be auto, parm or metadata
if (symbol && !symbol->isMethodMetaData())
{
// auto or parm is on stack
self()->setBaseRegister(cg->getStackPointerRealRegister(symbol), cg);
}
else
{
// meta data
self()->setBaseRegister(cg->getMethodMetaDataRealRegister(), cg);
}
_baseNode = NULL;
}
_indexRegister = NULL;
}
if (symRef && symRef->isLiteralPoolAddress())
{
TR_ASSERT(cg->supportsOnDemandLiteralPool() == true, "May not be here with Literal Pool On Demand disabled\n");
TR::S390ConstantDataSnippet * targetsnippet = self()->createLiteralPoolSnippet(rootLoadOrStore, cg);
self()->initSnippetPointers(targetsnippet, cg);
}
else
{
if (self()->getUnresolvedSnippet() == NULL)
{
if (symRef)
_offset += symRef->getOffset();
}
self()->enforceDisplacementLimit(rootLoadOrStore, cg, NULL);
}
if (alloc)
{
cg->stopUsingRegister(tempReg);
}
// TODO: aliasing sets?
}
OMR::Z::MemoryReference::MemoryReference(TR::Node *addressChild, bool canUseIndexReg, TR::CodeGenerator *cg)
: _baseRegister(NULL), _baseNode(NULL), _indexRegister(NULL), _indexNode(NULL), _targetSnippet(NULL), _targetSnippetInstruction(NULL),
_offset(0), _flags(0), _storageReference(NULL), _fixedSizeForAlignment(0), _leftMostByte(0), _name(NULL), _incrementedNodesList(cg->comp()->trMemory())
{
bool done = false;
if (addressChild->getRegister() == NULL)
{
if (addressChild->getReferenceCount() == 1 &&
addressChild->getOpCode().isAdd() &&
addressChild->getSecondChild()->getOpCode().isLoadConst())
{
TR::Node *first = addressChild->getFirstChild();
if (canUseIndexReg &&
first->getOpCode().isAdd())
{
_baseNode = first->getFirstChild();
_baseRegister = cg->evaluate(_baseNode);
cg->decReferenceCount(_baseNode);
_indexNode = first->getSecondChild();
_indexRegister = cg->evaluate(_indexNode);
cg->decReferenceCount(_indexNode);
}
else
{
_baseNode = first;
_baseRegister = cg->evaluate(first);
}
_offset = addressChild->getSecondChild()->getIntegerNodeValue<int32_t>();
if (addressChild->getReferenceCount() == 1)
{
cg->decReferenceCount(addressChild->getFirstChild());
cg->decReferenceCount(addressChild->getSecondChild());
}
done = true;
}
}
if (!done)
{
_baseRegister = cg->evaluate(addressChild);
}
_symbolReference = new (cg->trHeapMemory()) TR::SymbolReference(cg->comp()->getSymRefTab());
_originalSymbolReference = _symbolReference;
_listingSymbolReference = _symbolReference;
self()->setupCausesImplicitNullPointerException(cg);
}
TR::S390ConstantDataSnippet *
OMR::Z::MemoryReference::createLiteralPoolSnippet(TR::Node * node, TR::CodeGenerator * cg)
{
return cg->createLiteralPoolSnippet(node);
}
OMR::Z::MemoryReference::MemoryReference(TR::Node * node, TR::SymbolReference * symRef, TR::CodeGenerator * cg, TR_StorageReference *storageReference)
: _baseRegister(NULL), _baseNode(NULL), _indexRegister(NULL), _indexNode(NULL), _targetSnippet(NULL), _targetSnippetInstruction(NULL),
_flags(0), _storageReference(storageReference), _fixedSizeForAlignment(0), _leftMostByte(0), _name(NULL),
_incrementedNodesList(cg->comp()->trMemory())
{
TR::Symbol * symbol = symRef->getSymbol();
TR::Register * writableLiteralPoolRegister = NULL;
TR::Compilation *comp = cg->comp();
// Enable a check for the long disp slot in generateBin phase
self()->setupCheckForLongDispFlag(cg);
self()->setupCausesImplicitNullPointerException(cg);
if (symbol->isRegisterMappedSymbol())
{
// must be either auto, parm, meta or error.
if (!symbol->isMethodMetaData())
{
self()->setBaseRegister(cg->getStackPointerRealRegister(symbol), cg);
}
else
{
self()->setBaseRegister(cg->getMethodMetaDataRealRegister(), cg);
}
_baseNode = NULL;
}
if (symRef->isUnresolved())
{
self()->createUnresolvedSnippetWithNodeRegister(node, cg, symRef, writableLiteralPoolRegister);
}
if (_baseNode != NULL && _baseNode->getOpCodeValue() == TR::loadaddr && self()->getUnresolvedSnippet() != NULL)
{
self()->createUnresolvedDataSnippetForBaseNode(cg, writableLiteralPoolRegister);
}
_indexRegister = NULL;
_symbolReference = symRef;
_originalSymbolReference = symRef;
_listingSymbolReference = TR::MemoryReference::shouldLabelForRAS(symRef, cg)? symRef : NULL;
if (self()->getUnresolvedSnippet() == NULL)
{
_offset = symRef->getOffset();
}
else
{
_offset = 0;
}
self()->enforceDisplacementLimit(node, cg, NULL);
// TODO: aliasing sets?
}
void
OMR::Z::MemoryReference::initSnippetPointers(TR::Snippet * s, TR::CodeGenerator * cg)
{
if (s->getKind() == TR::Snippet::IsUnresolvedData)
{
self()->setUnresolvedSnippet((TR::UnresolvedDataSnippet *) s);
}
else if (s->getKind() == TR::Snippet::IsWritableData ||
s->getKind() == TR::Snippet::IsConstantInstruction ||
s->getKind() == TR::Snippet::IsConstantData)
{
self()->setConstantDataSnippet((TR::S390ConstantDataSnippet *) s);
}
}
OMR::Z::MemoryReference::MemoryReference(TR::Snippet * s, TR::Register * indx, int32_t disp, TR::CodeGenerator * cg)
: _baseNode(NULL), _baseRegister(NULL), _indexRegister(indx), _indexNode(NULL), _targetSnippetInstruction(NULL),
_offset(disp), _flags(0), _storageReference(NULL), _fixedSizeForAlignment(0), _leftMostByte(0), _name(NULL),
_incrementedNodesList(cg->comp()->trMemory())
{
_symbolReference = new (cg->trHeapMemory()) TR::SymbolReference(cg->comp()->getSymRefTab());
_originalSymbolReference = _symbolReference;
_listingSymbolReference = TR::MemoryReference::shouldLabelForRAS(_symbolReference, cg)? _symbolReference : NULL;
// Enable a check for the long disp slot in generateBin phase
self()->setupCheckForLongDispFlag(cg);
self()->setupCausesImplicitNullPointerException(cg);
self()->setBaseRegister(cg->getLitPoolRealRegister(), cg);
self()->initSnippetPointers(s, cg);
}
OMR::Z::MemoryReference::MemoryReference(TR::Snippet * s, TR::CodeGenerator * cg, TR::Register * base, TR::Node * node)
: _baseNode(NULL), _baseRegister(NULL), _indexRegister(NULL), _indexNode(NULL), _targetSnippetInstruction(NULL),
_offset(0), _flags(0), _storageReference(NULL), _fixedSizeForAlignment(0), _leftMostByte(0), _name(NULL),
_incrementedNodesList(cg->comp()->trMemory())
{
TR::Compilation *comp = cg->comp();
if (s->getKind() == TR::Snippet::IsConstantData)
_symbolReference = comp->getSymRefTab()->findOrCreateConstantAreaSymbolReference();
else
_symbolReference = new (cg->trHeapMemory()) TR::SymbolReference(comp->getSymRefTab());
_originalSymbolReference = _symbolReference;
_listingSymbolReference = TR::MemoryReference::shouldLabelForRAS(_symbolReference, cg)? _symbolReference : NULL;
// Enable a check for the long disp slot in generateBin phase
self()->setupCheckForLongDispFlag(cg);
self()->setupCausesImplicitNullPointerException(cg);
if (base)
{
self()->setBaseRegister(base, cg);
//TR_ASSERT(cg->supportsOnDemandLiteralPool()==true, "May not be here with Literal Pool On Demand disabled\n");
}
else
{
if (cg->isLiteralPoolOnDemandOn())
{
if (cg->comp()->target().is64Bit())
self()->setBaseRegister(cg->allocateRegister(), cg);
else
self()->setBaseRegister(cg->allocateRegister(), cg);
generateLoadLiteralPoolAddress(cg, node, _baseRegister);
cg->stopUsingRegister(_baseRegister);
}
else
{
self()->setBaseRegister(cg->getLitPoolRealRegister(), cg);
}
}
self()->initSnippetPointers(s, cg);
}
OMR::Z::MemoryReference::MemoryReference(int32_t disp,
TR::CodeGenerator *cg,
bool isConstantDataSnippet) :
_baseRegister(NULL),
_baseNode(NULL),
_indexRegister(NULL),
_indexNode(NULL),
_targetSnippet(NULL),
_targetSnippetInstruction(NULL),
_flags(0),
_storageReference(NULL),
_fixedSizeForAlignment(0),
_leftMostByte(0),
_name(NULL),
_incrementedNodesList(cg->comp()->trMemory())
{
TR::Compilation *comp = cg->comp();
{
_offset = disp;
_symbolReference = new (cg->trHeapMemory()) TR::SymbolReference(comp->getSymRefTab());
_originalSymbolReference = _symbolReference;
_listingSymbolReference = TR::MemoryReference::shouldLabelForRAS(_symbolReference, cg)? _symbolReference : NULL;
self()->setupCausesImplicitNullPointerException(cg);
}
}
OMR::Z::MemoryReference::MemoryReference(TR::CodeGenerator *cg) :
_baseRegister(NULL),
_baseNode(NULL),
_indexRegister(NULL),
_indexNode(NULL),
_targetSnippet(NULL),
_targetSnippetInstruction(NULL),
// this flag is used for 64bit code-gen only under current J9 fat object model
_flags(0),
_storageReference(NULL),
_fixedSizeForAlignment(0),
_leftMostByte(0),
_name(NULL),
_incrementedNodesList(cg->comp()->trMemory())
{
_symbolReference = new (cg->trHeapMemory()) TR::SymbolReference(cg->comp()->getSymRefTab());
_originalSymbolReference = _symbolReference;
_listingSymbolReference = TR::MemoryReference::shouldLabelForRAS(_symbolReference, cg)? _symbolReference : NULL;
_offset = _symbolReference->getOffset();
self()->setupCausesImplicitNullPointerException(cg);
}
OMR::Z::MemoryReference::MemoryReference(TR::Register *br,
int32_t disp,
TR::CodeGenerator *cg,
const char *name) :
_baseRegister(br),
_baseNode(NULL),
_indexRegister(NULL),
_indexNode(NULL),
_targetSnippet(NULL),
_targetSnippetInstruction(NULL),
_offset(disp),
_flags(0),
_storageReference(NULL),
_fixedSizeForAlignment(0),
_leftMostByte(0),
_name(name),
_incrementedNodesList(cg->comp()->trMemory())
{
_symbolReference = new (cg->trHeapMemory()) TR::SymbolReference(cg->comp()->getSymRefTab());
_originalSymbolReference = _symbolReference;
_listingSymbolReference = TR::MemoryReference::shouldLabelForRAS(_symbolReference, cg)? _symbolReference : NULL;
self()->setupCausesImplicitNullPointerException(cg);
}
OMR::Z::MemoryReference::MemoryReference(TR::Register *br,
int32_t disp,
TR::SymbolReference *symRef,
TR::CodeGenerator *cg) :
_baseRegister(br),
_symbolReference(symRef),
_baseNode(NULL),
_indexRegister(NULL),
_indexNode(NULL),
_targetSnippet(NULL),
_targetSnippetInstruction(NULL),
_offset(disp),
_flags(0),
_storageReference(NULL),
_fixedSizeForAlignment(0),
_leftMostByte(0),
_name(NULL),
_incrementedNodesList(cg->comp()->trMemory())
{
_originalSymbolReference = _symbolReference;
_listingSymbolReference = TR::MemoryReference::shouldLabelForRAS(_symbolReference, cg)? _symbolReference : NULL;
self()->setupCausesImplicitNullPointerException(cg);
}
OMR::Z::MemoryReference::MemoryReference(TR::Register *br,
TR::Register *ir,
int32_t disp,
TR::CodeGenerator *cg) :
_baseRegister(br),
_baseNode(NULL),
_indexRegister(ir),
_indexNode(NULL),
_targetSnippet(NULL),
_targetSnippetInstruction(NULL),
_offset(disp),
_flags(0),
_storageReference(NULL),
_fixedSizeForAlignment(0),
_leftMostByte(0),
_name(NULL),
_incrementedNodesList(cg->comp()->trMemory())
{
_symbolReference = new (cg->trHeapMemory()) TR::SymbolReference(cg->comp()->getSymRefTab());
_originalSymbolReference = _symbolReference;
_listingSymbolReference = TR::MemoryReference::shouldLabelForRAS(_symbolReference, cg)? _symbolReference : NULL;
self()->setupCausesImplicitNullPointerException(cg);
}
OMR::Z::MemoryReference::MemoryReference(MemoryReference& mr, int32_t n, TR::CodeGenerator *cg) :