-
Notifications
You must be signed in to change notification settings - Fork 747
/
Copy pathDataAccessAccelerator.cpp
2835 lines (2395 loc) · 120 KB
/
DataAccessAccelerator.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/DataAccessAccelerator.hpp"
#include <algorithm>
#include <limits.h>
#include <math.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "codegen/CodeGenerator.hpp"
#include "env/FrontEnd.hpp"
#include "codegen/RecognizedMethods.hpp"
#include "codegen/RegisterConstants.hpp"
#include "compile/Compilation.hpp"
#include "compile/Method.hpp"
#include "compile/ResolvedMethod.hpp"
#include "compile/SymbolReferenceTable.hpp"
#include "control/Options.hpp"
#include "control/Options_inlines.hpp"
#include "control/Recompilation.hpp"
#include "control/RecompilationInfo.hpp"
#include "env/CompilerEnv.hpp"
#include "env/StackMemoryRegion.hpp"
#include "env/TRMemory.hpp"
#include "env/jittypes.h"
#include "env/VMJ9.h"
#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/NodePool.hpp"
#include "il/Node_inlines.hpp"
#include "il/ParameterSymbol.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/Assert.hpp"
#include "infra/Cfg.hpp"
#include "infra/Stack.hpp"
#include "infra/TRCfgEdge.hpp"
#include "infra/TRCfgNode.hpp"
#include "optimizer/Optimization.hpp"
#include "optimizer/Optimization_inlines.hpp"
#include "optimizer/OptimizationManager.hpp"
#include "optimizer/Optimizations.hpp"
#include "optimizer/Optimizer.hpp"
#include "optimizer/OSRGuardRemoval.hpp"
#include "optimizer/Structure.hpp"
#include "optimizer/TransformUtil.hpp"
#include "ras/Debug.hpp"
#define IS_VARIABLE_PD2I(callNode) (!isChildConst(callNode, 2) || !isChildConst(callNode, 3))
TR_DataAccessAccelerator::TR_DataAccessAccelerator(TR::OptimizationManager* manager)
:
TR::Optimization(manager)
{
// Void
}
int32_t TR_DataAccessAccelerator::perform()
{
int32_t result = 0;
/* Disable DAA optimization for non-vectorized paths to unblock off-heap
* enablement while we continue to investigate the bug in non-vectorized
* pdload evaluator.
*
* TODO: Enable non-vectorized paths for off-heap.
* - Issue: https://github.com/eclipse-openj9/openj9/issues/21246
*/
if (!comp()->getOption(TR_DisableIntrinsics) &&
!comp()->getOption(TR_MimicInterpreterFrameShape) &&
// We cannot handle arraylets because hardware intrinsics act on contiguous memory
!comp()->generateArraylets() && !TR::Compiler->om.useHybridArraylets() &&
(!TR::Compiler->om.isOffHeapAllocationEnabled() || comp()->getOption(TR_DisableVectorBCD)))
{
// A vector to keep track of variable packed decimal calls
TR::StackMemoryRegion stackMemoryRegion(*(comp()->trMemory()));
TreeTopContainer variableCallTreeTops(stackMemoryRegion);
for (TR::AllBlockIterator iter(optimizer()->getMethodSymbol()->getFlowGraph(), comp());
iter.currentBlock() != NULL;
++iter)
{
TR::Block* block = iter.currentBlock();
result += performOnBlock(block, &variableCallTreeTops);
}
result += processVariableCalls(&variableCallTreeTops);
}
if (result != 0)
{
optimizer()->setUseDefInfo(NULL);
optimizer()->setValueNumberInfo(NULL);
optimizer()->setAliasSetsAreValid(false);
}
return result;
}
int32_t
TR_DataAccessAccelerator::processVariableCalls(TreeTopContainer* variableCallTreeTops)
{
int32_t result = 0;
// Process variable precision calls after iterating through all the nodes
for(int i = 0; i < variableCallTreeTops->size(); ++i)
{
TR::TreeTop* treeTop = variableCallTreeTops->at(i);
TR::Node* callNode = treeTop->getNode()->getChild(0);
TR::ResolvedMethodSymbol* callSymbol = callNode->getSymbol()->getResolvedMethodSymbol();
if (callSymbol != NULL)
{
if (!comp()->getOption(TR_DisablePackedDecimalIntrinsics))
{
switch (callSymbol->getRecognizedMethod())
{
// DAA Packed Decimal <-> Integer
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToInteger_:
{
if (generatePD2IVariableParameter(treeTop, callNode, true, false))
{
++result;
}
continue;
}
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToInteger_ByteBuffer_:
{
if (generatePD2IVariableParameter(treeTop, callNode, true, true))
{
++result;
}
continue;
}
// DAA Packed Decimal <-> Long
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToLong_:
{
if (generatePD2IVariableParameter(treeTop, callNode, false, false))
{
++result;
}
continue;
}
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToLong_ByteBuffer_:
{
if (generatePD2IVariableParameter(treeTop, callNode, false, true))
{
++result;
}
continue;
}
default:
break;
}
}
}
}
return result;
}
const char *
TR_DataAccessAccelerator::optDetailString() const throw()
{
return "O^O DATA ACCESS ACCELERATOR: ";
}
int32_t TR_DataAccessAccelerator::performOnBlock(TR::Block* block, TreeTopContainer* variableCallTreeTops)
{
int32_t blockResult = 0;
bool requestOSRGuardRemoval = false;
for (TR::TreeTopIterator iter(block->getEntry(), comp()); iter != block->getExit(); ++iter)
{
TR::Node* currentNode = iter.currentNode();
if (currentNode->getOpCodeValue() == TR::treetop)
{
currentNode = currentNode->getChild(0);
}
if (currentNode != NULL && currentNode->getOpCode().isCall())
{
int32_t result = 0;
bool matched = false;
TR::TreeTop* treeTop = iter.currentTree();
TR::Node* callNode = currentNode;
TR::Node* returnNode = NULL;
TR::ResolvedMethodSymbol* callSymbol = callNode->getSymbol()->getResolvedMethodSymbol();
if (callSymbol != NULL)
{
if (!comp()->getOption(TR_DisableMarshallingIntrinsics))
{
switch (callSymbol->getRecognizedMethod())
{
// ByteArray Marshalling methods
case TR::com_ibm_dataaccess_ByteArrayMarshaller_writeShort_:
returnNode = insertIntegerSetIntrinsic(treeTop, callNode, 2, 2);
break;
case TR::com_ibm_dataaccess_ByteArrayMarshaller_writeShortLength_:
returnNode = insertIntegerSetIntrinsic(treeTop, callNode, 2, 0);
break;
case TR::com_ibm_dataaccess_ByteArrayMarshaller_writeInt_:
returnNode = insertIntegerSetIntrinsic(treeTop, callNode, 4, 4);
break;
case TR::com_ibm_dataaccess_ByteArrayMarshaller_writeIntLength_:
returnNode = insertIntegerSetIntrinsic(treeTop, callNode, 4, 0);
break;
case TR::com_ibm_dataaccess_ByteArrayMarshaller_writeLong_:
returnNode = insertIntegerSetIntrinsic(treeTop, callNode, 8, 8);
break;
case TR::com_ibm_dataaccess_ByteArrayMarshaller_writeLongLength_:
returnNode = insertIntegerSetIntrinsic(treeTop, callNode, 8, 0);
break;
case TR::com_ibm_dataaccess_ByteArrayMarshaller_writeFloat_:
returnNode = insertDecimalSetIntrinsic(treeTop, callNode, 4, 4);
break;
case TR::com_ibm_dataaccess_ByteArrayMarshaller_writeDouble_:
returnNode = insertDecimalSetIntrinsic(treeTop, callNode, 8, 8);
break;
// ByteArray Unmarshalling methods
case TR::com_ibm_dataaccess_ByteArrayUnmarshaller_readShort_:
returnNode = insertIntegerGetIntrinsic(treeTop, callNode, 2, 2);
break;
case TR::com_ibm_dataaccess_ByteArrayUnmarshaller_readShortLength_:
returnNode = insertIntegerGetIntrinsic(treeTop, callNode, 0, 2);
break;
case TR::com_ibm_dataaccess_ByteArrayUnmarshaller_readInt_:
returnNode = insertIntegerGetIntrinsic(treeTop, callNode, 4, 4);
break;
case TR::com_ibm_dataaccess_ByteArrayUnmarshaller_readIntLength_:
returnNode = insertIntegerGetIntrinsic(treeTop, callNode, 0, 4);
break;
case TR::com_ibm_dataaccess_ByteArrayUnmarshaller_readLong_:
returnNode = insertIntegerGetIntrinsic(treeTop, callNode, 8, 8);
break;
case TR::com_ibm_dataaccess_ByteArrayUnmarshaller_readLongLength_:
returnNode = insertIntegerGetIntrinsic(treeTop, callNode, 0, 8);
break;
case TR::com_ibm_dataaccess_ByteArrayUnmarshaller_readFloat_:
returnNode = insertDecimalGetIntrinsic(treeTop, callNode, 4, 4);
break;
case TR::com_ibm_dataaccess_ByteArrayUnmarshaller_readDouble_:
returnNode = insertDecimalGetIntrinsic(treeTop, callNode, 8, 8);
break;
default:
break;
}
if (returnNode)
{
result = 1;
matched = true;
printInliningStatus(true, callNode);
for (int i=callNode->getNumChildren();i>0;i--)
callNode->getChild(i-1)->recursivelyDecReferenceCount();
callNode->setNumChildren(returnNode->getNumChildren());
callNode->setSymbolReference(NULL);
TR::Node::recreate(callNode, returnNode->getOpCodeValue());
if (callNode->getOpCode().hasSymbolReference())
callNode->setSymbolReference(returnNode->getSymbolReference());
for (int i=callNode->getNumChildren();i>0;i--)
callNode->setChild(i-1, returnNode->getChild(i-1));
}
}
bool isZLinux = comp()->target().cpu.isZ() && comp()->target().isLinux();
bool isZOS = comp()->target().isZOS();
if (!matched && (isZOS || isZLinux) &&
!comp()->getOption(TR_DisablePackedDecimalIntrinsics))
{
matched = true;
switch (callSymbol->getRecognizedMethod())
{
// DAA Packed Decimal Check
case TR::com_ibm_dataaccess_PackedDecimal_checkPackedDecimal_:
if (inlineCheckPackedDecimal(treeTop, callNode))
{
++result;
}
break;
// DAA Packed Decimal <-> Unicode Decimal
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToUnicodeDecimal_:
if (generatePD2UD(treeTop, callNode, true))
{
++result;
}
break;
case TR::com_ibm_dataaccess_DecimalData_convertUnicodeDecimalToPackedDecimal_:
if (generateUD2PD(treeTop, callNode, true))
{
++result;
}
break;
// DAA Packed Decimal <-> External Decimal
case TR::com_ibm_dataaccess_DecimalData_convertExternalDecimalToPackedDecimal_:
if (generateUD2PD(treeTop, callNode, false))
{
++result;
}
break;
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToExternalDecimal_:
if (generatePD2UD(treeTop, callNode, false))
{
++result;
}
break;
// DAA External Decimal Check
case TR::com_ibm_dataaccess_ExternalDecimal_checkExternalDecimal_:
if (comp()->target().cpu.supportsFeature(OMR_FEATURE_S390_VECTOR_PACKED_DECIMAL_ENHANCEMENT_FACILITY_3)
&& inlineCheckExternalDecimal(treeTop, callNode))
{
++result;
}
break;
default:
matched = false;
break;
}
}
if (!matched && (isZOS || isZLinux) &&
!block->isCold() &&
!comp()->getOption(TR_DisablePackedDecimalIntrinsics))
{
matched = true;
comp()->cg()->setUpStackSizeForCallNode(callNode);
switch (callSymbol->getRecognizedMethod())
{
// DAA Packed Decimal arithmetic methods
case TR::com_ibm_dataaccess_PackedDecimal_addPackedDecimal_:
if (genArithmeticIntrinsic(treeTop, callNode, TR::pdadd))
{
++result;
}
break;
case TR::com_ibm_dataaccess_PackedDecimal_subtractPackedDecimal_:
if (genArithmeticIntrinsic(treeTop, callNode, TR::pdsub))
{
++result;
}
break;
case TR::com_ibm_dataaccess_PackedDecimal_multiplyPackedDecimal_:
if (genArithmeticIntrinsic(treeTop, callNode, TR::pdmul))
{
++result;
}
break;
case TR::com_ibm_dataaccess_PackedDecimal_dividePackedDecimal_:
if (genArithmeticIntrinsic(treeTop, callNode, TR::pddiv))
{
++result;
}
break;
case TR::com_ibm_dataaccess_PackedDecimal_remainderPackedDecimal_:
if (genArithmeticIntrinsic(treeTop, callNode, TR::pdrem))
{
++result;
}
break;
// DAA Packed Decimal shift methods
case TR::com_ibm_dataaccess_PackedDecimal_shiftLeftPackedDecimal_:
if (genShiftLeftIntrinsic(treeTop, callNode))
{
++result;
}
break;
case TR::com_ibm_dataaccess_PackedDecimal_shiftRightPackedDecimal_:
if (genShiftRightIntrinsic(treeTop, callNode))
{
++result;
}
break;
// DAA Packed Decimal comparison methods
case TR::com_ibm_dataaccess_PackedDecimal_lessThanPackedDecimal_:
if (genComparisionIntrinsic(treeTop, callNode, TR::pdcmplt))
{
++result;
}
break;
case TR::com_ibm_dataaccess_PackedDecimal_lessThanOrEqualsPackedDecimal_:
if (genComparisionIntrinsic(treeTop, callNode, TR::pdcmple))
{
++result;
}
break;
case TR::com_ibm_dataaccess_PackedDecimal_greaterThanPackedDecimal_:
if (genComparisionIntrinsic(treeTop, callNode, TR::pdcmpgt))
{
++result;
}
break;
case TR::com_ibm_dataaccess_PackedDecimal_greaterThanOrEqualsPackedDecimal_:
if (genComparisionIntrinsic(treeTop, callNode, TR::pdcmpge))
{
++result;
}
break;
case TR::com_ibm_dataaccess_PackedDecimal_equalsPackedDecimal_:
if (genComparisionIntrinsic(treeTop, callNode, TR::pdcmpeq))
{
++result;
}
break;
// DAA Packed Decimal <-> Integer
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToInteger_:
{
if (IS_VARIABLE_PD2I(callNode))
{
variableCallTreeTops->push_back(treeTop);
}
else
{
if (generatePD2I(treeTop, callNode, true, false))
{
++result;
}
}
break;
}
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToInteger_ByteBuffer_:
{
if (IS_VARIABLE_PD2I(callNode))
{
variableCallTreeTops->push_back(treeTop);
}
else
{
if (generatePD2I(treeTop, callNode, true, true))
{
++result;
}
}
break;
}
case TR::com_ibm_dataaccess_DecimalData_convertIntegerToPackedDecimal_:
if (generateI2PD(treeTop, callNode, true, false))
{
++result;
}
break;
case TR::com_ibm_dataaccess_DecimalData_convertIntegerToPackedDecimal_ByteBuffer_:
if (generateI2PD(treeTop, callNode, true, true))
{
++result;
}
break;
// DAA Packed Decimal <-> Long
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToLong_:
{
if (IS_VARIABLE_PD2I(callNode))
{
variableCallTreeTops->push_back(treeTop);
}
else
{
if (generatePD2I(treeTop, callNode, false, false))
{
++result;
}
}
break;
}
case TR::com_ibm_dataaccess_DecimalData_convertPackedDecimalToLong_ByteBuffer_:
{
if (IS_VARIABLE_PD2I(callNode))
{
variableCallTreeTops->push_back(treeTop);
}
else
{
if (generatePD2I(treeTop, callNode, false, true))
{
++result;
}
}
break;
}
case TR::com_ibm_dataaccess_DecimalData_convertLongToPackedDecimal_:
if (generateI2PD(treeTop, callNode, false, false))
{
++result;
}
break;
case TR::com_ibm_dataaccess_DecimalData_convertLongToPackedDecimal_ByteBuffer_:
if (generateI2PD(treeTop, callNode, false, true))
{
++result;
}
break;
default:
matched = false;
break;
}
}
if (matched && result
&& !requestOSRGuardRemoval
&& TR_OSRGuardRemoval::findMatchingOSRGuard(comp(), treeTop))
requestOSRGuardRemoval = true;
blockResult += result;
}
}
}
// If yields to the VM have been removed, it is possible to remove OSR guards as well
//
if (requestOSRGuardRemoval)
requestOpt(OMR::osrGuardRemoval);
return blockResult;
}
bool TR_DataAccessAccelerator::isChildConst(TR::Node* node, int32_t child)
{
return node->getChild(child)->getOpCode().isLoadConst();
}
TR::Node* TR_DataAccessAccelerator::insertDecimalGetIntrinsic(TR::TreeTop* callTreeTop, TR::Node* callNode, int32_t sourceNumBytes, int32_t targetNumBytes)
{
if (targetNumBytes != 4 && targetNumBytes != 8)
{
printInliningStatus (false, callNode, "targetNumBytes is invalid. Valid targetNumBytes values are 4 or 8.");
return NULL;
}
if (sourceNumBytes != 4 && sourceNumBytes != 8)
{
printInliningStatus (false, callNode, "sourceNumBytes is invalid. Valid sourceNumBytes values are 4 or 8.");
return NULL;
}
if (sourceNumBytes > targetNumBytes)
{
printInliningStatus (false, callNode, "sourceNumBytes is out of bounds.");
return NULL;
}
TR::Node* byteArrayNode = callNode->getChild(0);
TR::Node* offsetNode = callNode->getChild(1);
TR::Node* bigEndianNode = callNode->getChild(2);
if (!bigEndianNode->getOpCode().isLoadConst())
{
printInliningStatus (false, callNode, "bigEndianNode is not constant.");
return NULL;
}
// Determines whether a TR::ByteSwap needs to be inserted before the store to the byteArray
bool requiresByteSwap = comp()->target().cpu.isBigEndian() != static_cast <bool> (bigEndianNode->getInt());
if (requiresByteSwap && !comp()->cg()->supportsByteswap())
{
printInliningStatus (false, callNode, "Unmarshalling is not supported because ByteSwap IL evaluators are not implemented.");
return NULL;
}
if (performTransformation(comp(), "O^O TR_DataAccessAccelerator: insertDecimalGetIntrinsic on callNode %p\n", callNode))
{
insertByteArrayNULLCHK(callTreeTop, callNode, byteArrayNode);
insertByteArrayBNDCHK(callTreeTop, callNode, byteArrayNode, offsetNode, 0);
insertByteArrayBNDCHK(callTreeTop, callNode, byteArrayNode, offsetNode, sourceNumBytes - 1);
TR::DataType sourceDataType = TR::NoType;
TR::DataType targetDataType = TR::NoType;
// Default case is impossible due to previous checks
switch (sourceNumBytes)
{
case 4: sourceDataType = TR::Float; break;
case 8: sourceDataType = TR::Double; break;
}
TR::ILOpCodes op = TR::BadILOp;
// Default case is impossible due to previous checks
switch (sourceNumBytes)
{
case 4: op = requiresByteSwap ? TR::iloadi : TR::floadi; break;
case 8: op = requiresByteSwap ? TR::lloadi : TR::dloadi; break;
}
// Default case is impossible due to previous checks
switch (targetNumBytes)
{
case 4: targetDataType = TR::Float; break;
case 8: targetDataType = TR::Double; break;
}
TR::Node* valueNode = TR::Node::createWithSymRef(op, 1, 1, constructAddressNode(callNode, byteArrayNode, offsetNode), comp()->getSymRefTab()->findOrCreateGenericIntShadowSymbolReference(0));
if (requiresByteSwap)
{
// Default case is impossible due to previous checks
switch (sourceNumBytes)
{
case 4: valueNode = TR::Node::create(TR::ibits2f, 1, TR::Node::create(TR::ibyteswap, 1, valueNode)); break;
case 8: valueNode = TR::Node::create(TR::lbits2d, 1, TR::Node::create(TR::lbyteswap, 1, valueNode)); break;
}
}
if (sourceNumBytes != targetNumBytes)
{
valueNode = TR::Node::create(TR::ILOpCode::getProperConversion(sourceDataType, targetDataType, false), 1, valueNode);
}
return valueNode;
}
return NULL;
}
TR::Node* TR_DataAccessAccelerator::insertDecimalSetIntrinsic(TR::TreeTop* callTreeTop, TR::Node* callNode, int32_t sourceNumBytes, int32_t targetNumBytes)
{
if (sourceNumBytes != 4 && sourceNumBytes != 8)
{
printInliningStatus (false, callNode, "sourceNumBytes is invalid. Valid sourceNumBytes values are 4 or 8.");
return NULL;
}
if (targetNumBytes != 4 && targetNumBytes != 8)
{
printInliningStatus (false, callNode, "targetNumBytes is invalid. Valid targetNumBytes values are 4 or 8.");
return NULL;
}
if (targetNumBytes > sourceNumBytes)
{
printInliningStatus (false, callNode, "targetNumBytes is out of bounds.");
return NULL;
}
TR::Node* valueNode = callNode->getChild(0);
TR::Node* byteArrayNode = callNode->getChild(1);
TR::Node* offsetNode = callNode->getChild(2);
TR::Node* bigEndianNode = callNode->getChild(3);
if (!bigEndianNode->getOpCode().isLoadConst())
{
printInliningStatus (false, callNode, "bigEndianNode is not constant.");
return NULL;
}
// Determines whether a TR::ByteSwap needs to be inserted before the store to the byteArray
bool requiresByteSwap = comp()->target().cpu.isBigEndian() != static_cast <bool> (bigEndianNode->getInt());
if (requiresByteSwap && !comp()->cg()->supportsByteswap())
{
printInliningStatus (false, callNode, "Unmarshalling is not supported because ByteSwap IL evaluators are not implemented.");
return NULL;
}
if (performTransformation(comp(), "O^O TR_DataAccessAccelerator: insertDecimalSetIntrinsic on callNode %p\n", callNode))
{
insertByteArrayNULLCHK(callTreeTop, callNode, byteArrayNode);
insertByteArrayBNDCHK(callTreeTop, callNode, byteArrayNode, offsetNode, 0);
insertByteArrayBNDCHK(callTreeTop, callNode, byteArrayNode, offsetNode, targetNumBytes - 1);
TR::DataType sourceDataType = TR::NoType;
TR::DataType targetDataType = TR::NoType;
// Default case is impossible due to previous checks
switch (sourceNumBytes)
{
case 4: sourceDataType = TR::Float; break;
case 8: sourceDataType = TR::Double; break;
}
// Default case is impossible due to previous checks
switch (targetNumBytes)
{
case 4: targetDataType = TR::Float; break;
case 8: targetDataType = TR::Double; break;
}
TR::ILOpCodes op = TR::BadILOp;
// Default case is impossible due to previous checks
switch (targetNumBytes)
{
case 4: op = requiresByteSwap ? TR::istorei : TR::fstorei; break;
case 8: op = requiresByteSwap ? TR::lstorei : TR::dstorei; break;
}
// Create the proper conversion if the source and target sizes are different
if (sourceNumBytes != targetNumBytes)
{
valueNode = TR::Node::create(TR::ILOpCode::getProperConversion(sourceDataType, targetDataType, false), 1, valueNode);
}
if (requiresByteSwap)
{
// Default case is impossible due to previous checks
switch (targetNumBytes)
{
case 4: valueNode = TR::Node::create(TR::ibyteswap, 1, TR::Node::create(TR::fbits2i, 1, valueNode)); break;
case 8: valueNode = TR::Node::create(TR::lbyteswap, 1, TR::Node::create(TR::dbits2l, 1, valueNode)); break;
}
}
return TR::Node::createWithSymRef(op, 2, 2, constructAddressNode(callNode, byteArrayNode, offsetNode), valueNode, comp()->getSymRefTab()->findOrCreateGenericIntShadowSymbolReference(0));
}
return NULL;
}
bool TR_DataAccessAccelerator::inlineCheckPackedDecimal(TR::TreeTop *callTreeTop, TR::Node *callNode)
{
TR::Node *byteArrayNode = callNode->getChild(0);
TR::Node *offsetNode = callNode->getChild(1);
TR::Node *precisionNode = callNode->getChild(2);
TR::Node *ignoreHighNibbleForEvenPrecisionNode = callNode->getChild(3);
TR::Node *canOverwriteHighNibbleForEvenPrecisionNode = callNode->getChild(4);
int32_t precision = precisionNode->getInt();
const char *failMsg = NULL;
if (!precisionNode->getOpCode().isLoadConst())
failMsg = "precisionNode is not constant.";
else if(precision < 1 || precision > 31)
failMsg = "precisionNode is out of bounds.";
else if (!ignoreHighNibbleForEvenPrecisionNode->getOpCode().isLoadConst())
failMsg = "ignoreHighNibbleForEvenPrecisionNode is not constant.";
else if (!canOverwriteHighNibbleForEvenPrecisionNode->getOpCode().isLoadConst())
failMsg = "canOverwriteHighNibbleForEvenPrecisionNode is not constant.";
if (failMsg)
{
TR::DebugCounter::incStaticDebugCounter(comp(),
TR::DebugCounter::debugCounterName(comp(),
"DAA/rejected/chkPacked"));
return printInliningStatus (false, callNode, failMsg);
}
if (performTransformation(comp(), "O^O TR_DataAccessAccelerator: inlineCheckPackedDecimal on callNode %p\n", callNode))
{
TR::DebugCounter::incStaticDebugCounter(comp(),
TR::DebugCounter::debugCounterName(comp(),
"DAA/inlined/chkPacked"));
insertByteArrayNULLCHK(callTreeTop, callNode, byteArrayNode);
int32_t precisionSizeInNumberOfBytes = TR::DataType::getSizeFromBCDPrecision(TR::PackedDecimal, precision);
insertByteArrayBNDCHK(callTreeTop, callNode, byteArrayNode, offsetNode, 0);
insertByteArrayBNDCHK(callTreeTop, callNode, byteArrayNode, offsetNode, precisionSizeInNumberOfBytes - 1);
TR::SymbolReference *packedDecimalSymbolReference = comp()->getSymRefTab()->findOrCreateArrayShadowSymbolRef(TR::PackedDecimal, NULL, precisionSizeInNumberOfBytes, fe());
TR::Node *pdchkChild0Node = TR::Node::createWithSymRef(TR::pdloadi, 1, 1, constructAddressNode(callNode, byteArrayNode, offsetNode), packedDecimalSymbolReference);
// The size argument passed to create an array shadow symbol reference is the size in number of bytes that this PackedDecimal represents.
// Unfortunately when a Node is constructed with this symbol reference we extract the size from the symbol reference and convert it to a
// precision via a helper function. Because this conversion is not injective we may not get back the original precision we calculated
// above. This is why we must explicitly set the precision on the Node after creation.
pdchkChild0Node->setDecimalPrecision(precision);
if (precision % 2 == 0)
{
const bool ignoreHighNibbleForEvenPrecision = static_cast <bool> (ignoreHighNibbleForEvenPrecisionNode->getInt());
const bool canOverwriteHighNibbleForEvenPrecision = static_cast <bool> (canOverwriteHighNibbleForEvenPrecisionNode->getInt());
if (ignoreHighNibbleForEvenPrecision || canOverwriteHighNibbleForEvenPrecision)
{
// Increase the precision of the pdload by 1 to pretend that we have an extra digit, then create a new parent on top of the pdload
// which will truncate Packed Decimal by modifying its precision to the desired value. This has the effect of creating a new temporary
// Packed Decimal value which properly ignores the high nibble if the precision is even, and more over it has a value of 0 in the high nibble.
pdchkChild0Node->setDecimalPrecision(precision + 1);
pdchkChild0Node = TR::Node::create(TR::pdModifyPrecision, 1, pdchkChild0Node);
pdchkChild0Node->setDecimalPrecision(precision);
// If we are allowed to overwrite the high nibble if the precision is even then we need to store temporary Packed Decimal we just
// created back into the original byte array. We once again pretend that we have an extra digit when doing this store because we also want to
// store out the extra 0 digit which is guaranteed to be present due to the above computation.
if (canOverwriteHighNibbleForEvenPrecision)
{
int32_t precisionSizeInNumberOfBytes = TR::DataType::getSizeFromBCDPrecision(TR::PackedDecimal, precision + 1);
TR::SymbolReference* packedDecimalSymbolReference = comp()->getSymRefTab()->findOrCreateArrayShadowSymbolRef(TR::PackedDecimal, NULL, precisionSizeInNumberOfBytes, fe());
//this node should be inserted after callNode
TR::Node * pdstoreNode = TR::Node::createWithSymRef(TR::pdstorei, 2, 2, constructAddressNode(callNode, byteArrayNode, offsetNode), pdchkChild0Node, packedDecimalSymbolReference);
pdstoreNode->setDecimalPrecision(precision + 1);
callTreeTop->insertAfter(TR::TreeTop::create(comp(), pdstoreNode));
}
}
}
// We will be recreating the callNode so decrement the reference count of all it's children
for (auto i = 0; i < callNode->getNumChildren(); ++i)
{
callNode->getChild(i)->decReferenceCount();
}
TR::Node::recreateWithoutProperties(callNode, TR::pdchk, 1, pdchkChild0Node);
return true;
}
return false;
}
bool TR_DataAccessAccelerator::inlineCheckExternalDecimal(TR::TreeTop *callTreeTop, TR::Node *callNode)
{
TR::Node *byteArrayNode = callNode->getChild(0);
TR::Node *offsetNode = callNode->getChild(1);
TR::Node *precisionNode = callNode->getChild(2);
TR::Node *typeNode = callNode->getChild(3);
TR::Node *bytesWithSpacesNode = callNode->getChild(4);
int32_t precision = precisionNode->getInt();
int32_t bytesWithSpaces = bytesWithSpacesNode->getInt();
int32_t type = typeNode->getInt();
const char *failMsg = NULL;
/* Hardware expects both, precision and bytesWithSpaces to be
* 5 bit unsigned binary integer. However, 0 is valid only for
* bytesWithSpaces. This is why precision must be within [1-31]
* range and bytesWithSpaces must be within [0-31] range.
*/
// TODO: Add support for non-constant arguments
if (!isChildConst(callNode, 2))
failMsg = "Precision is not constant";
else if (precision < 1 || precision > 31)
failMsg = "Precision value is not in valid range [1-31]";
else if (!isChildConst(callNode, 3))
failMsg = "Decimal type node is not constant";
else if (type < 1 || type > 4)
failMsg = "Invalid decimal type. Supported types are (1|2|3|4)";
else if (!isChildConst(callNode, 4))
failMsg = "bytesWithSpaces node is not constant";
else if (bytesWithSpaces < 0 || bytesWithSpaces > 31)
failMsg = "bytesWithSpaces value not in valid range [0-31]";
if (failMsg)
{
TR::DebugCounter::incStaticDebugCounter(comp(),
TR::DebugCounter::debugCounterName(comp(),
"DAA/rejected/chkZonedDecimal"));
return printInliningStatus (false, callNode, failMsg);
}
if (performTransformation(comp(), "O^O TR_DataAccessAccelerator: inlineCheckZonedDecimal on callNode %p\n", callNode))
{
TR::DebugCounter::incStaticDebugCounter(comp(),
TR::DebugCounter::debugCounterName(comp(),
"DAA/inlined/chkZonedDecimal"));
insertByteArrayNULLCHK(callTreeTop, callNode, byteArrayNode);
TR::DataType decimalType = TR::DataTypes::NoType;
TR::ILOpCodes loadOpCode = TR::BadILOp;
if (type == 1)
{
decimalType = TR::ZonedDecimal;
loadOpCode = TR::zdloadi;
}
else if (type == 2)
{
decimalType = TR::ZonedDecimalSignLeadingEmbedded;
loadOpCode = TR::zdsleLoadi;
}
else if (type == 3)
{
decimalType = TR::ZonedDecimalSignTrailingSeparate;
loadOpCode = TR::zdstsLoadi;
}
else if (type == 4)
{
decimalType = TR::ZonedDecimalSignLeadingSeparate;
loadOpCode = TR::zdslsLoadi;
}
int32_t precisionSizeInNumberOfBytes = TR::DataType::getSizeFromBCDPrecision(decimalType, precision);
insertByteArrayBNDCHK(callTreeTop, callNode, byteArrayNode, offsetNode, 0);
insertByteArrayBNDCHK(callTreeTop, callNode, byteArrayNode, offsetNode, precisionSizeInNumberOfBytes - 1);
TR::SymbolReference* zonedDecimalSymbolReference = comp()->getSymRefTab()->findOrCreateArrayShadowSymbolRef(decimalType, NULL, precisionSizeInNumberOfBytes, fe());
TR::Node* zdchkChild0Node = TR::Node::createWithSymRef(loadOpCode, 1, 1, constructAddressNode(callNode, byteArrayNode, offsetNode), zonedDecimalSymbolReference);
zdchkChild0Node->setDecimalPrecision(precision);
byteArrayNode->decReferenceCount();
offsetNode->decReferenceCount();
precisionNode->decReferenceCount();
typeNode->decReferenceCount();
TR::Node* bytesWithSpacesConstNode = TR::Node::bconst(static_cast<uint8_t>(bytesWithSpaces));
TR::Node::recreateWithoutProperties(callNode, TR::zdchk, 2, zdchkChild0Node, bytesWithSpacesConstNode);
return true;
}
return false;
}
TR::Node* TR_DataAccessAccelerator::insertIntegerGetIntrinsic(TR::TreeTop* callTreeTop, TR::Node* callNode, int32_t sourceNumBytes, int32_t targetNumBytes)
{
if (targetNumBytes != 1 && targetNumBytes != 2 && targetNumBytes != 4 && targetNumBytes != 8)
{
printInliningStatus (false, callNode, "targetNumBytes is invalid. Valid targetNumBytes values are 1, 2, 4, or 8.");
return NULL;
}
TR::Node* byteArrayNode = callNode->getChild(0);
TR::Node* offsetNode = callNode->getChild(1);
TR::Node* bigEndianNode = callNode->getChild(2);
TR::Node* numBytesNode = NULL;
TR::Node* signExtendNode = NULL;
if (!bigEndianNode->getOpCode().isLoadConst())
{
printInliningStatus (false, callNode, "bigEndianNode is not constant.");
return NULL;
}
bool needUnsignedConversion = false;
// This check indicates that the sourceNumBytes value is specified on the callNode, so we must extract it
if (sourceNumBytes == 0)
{
numBytesNode = callNode->getChild(3);
if (!numBytesNode->getOpCode().isLoadConst())
{
printInliningStatus (false, callNode, "numBytesNode is not constant.");
return NULL;
}
sourceNumBytes = numBytesNode->getInt();
if (sourceNumBytes != 1 && sourceNumBytes != 2 && sourceNumBytes != 4 && sourceNumBytes != 8)
{
printInliningStatus (false, callNode, "sourceNumBytes is invalid. Valid targetNumBytes values are 1, 2, 4, or 8.");
return NULL;
}
if (sourceNumBytes > targetNumBytes)
{