-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathOMRNode.cpp
8710 lines (7226 loc) · 257 KB
/
OMRNode.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, 2021 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 "il/Node.hpp"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "codegen/CodeGenerator.hpp"
#include "env/FrontEnd.hpp"
#include "codegen/Linkage.hpp"
#include "codegen/LiveRegister.hpp"
#include "codegen/RecognizedMethods.hpp"
#include "codegen/Register.hpp"
#include "codegen/RegisterPair.hpp"
#include "compile/Compilation.hpp"
#include "compile/Method.hpp"
#include "compile/ResolvedMethod.hpp"
#include "compile/SymbolReferenceTable.hpp"
#include "control/Options.hpp"
#include "cs2/hashtab.h"
#include "env/ClassEnv.hpp"
#include "env/CompilerEnv.hpp"
#include "env/Environment.hpp"
#include "env/IO.hpp"
#include "env/TRMemory.hpp"
#include "env/VMEnv.hpp"
#include "env/defines.h"
#include "il/AliasSetInterface.hpp"
#include "il/AutomaticSymbol.hpp"
#include "il/Block.hpp"
#include "il/DataTypes.hpp"
#include "il/IL.hpp"
#include "il/ILOpCodes.hpp"
#include "il/ILOps.hpp"
#include "il/MethodSymbol.hpp"
#include "il/Node.hpp"
#include "il/NodeExtension.hpp"
#include "il/NodePool.hpp"
#include "il/NodeUtils.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 "ilgen/IlGen.hpp"
#include "infra/Assert.hpp"
#include "infra/BitVector.hpp"
#include "infra/Flags.hpp"
#include "infra/List.hpp"
#include "infra/TRlist.hpp"
#include "infra/Checklist.hpp"
#include "optimizer/LoadExtensions.hpp"
#include "optimizer/Optimizer.hpp"
#include "optimizer/ValueNumberInfo.hpp"
#include "ras/Debug.hpp"
#ifdef J9_PROJECT_SPECIFIC
#ifdef TR_TARGET_S390
#include "z/codegen/S390Register.hpp"
#endif
#endif
/**
* Node constructors and create functions
*/
void *
OMR::Node::operator new(size_t s, TR::NodePool& nodes)
{
return (void *) nodes.allocate();
}
void
OMR::Node::operator delete(void *node, TR::NodePool& nodes)
{
nodes.deallocate((TR::Node *) node);
}
void *
OMR::Node::operator new(size_t s, void *ptr) throw()
{
return ::operator new(s, ptr);
}
void
OMR::Node::operator delete(void *node, void *ptr) throw()
{
::operator delete(node, ptr);
}
OMR::Node::Node()
: _opCode(TR::BadILOp),
_numChildren(0),
//_globalIndex(0),
_flags(0),
_visitCount(0),
_localIndex(0),
_referenceCount(0),
_byteCodeInfo(),
_unionBase(),
_unionPropertyA()
{
}
OMR::Node::~Node()
{
_unionPropertyA = UnionPropertyA();
_opCode.setOpCodeValue(TR::BadILOp);
self()->freeExtensionIfExists();
}
OMR::Node::Node(TR::Node *originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren)
: _opCode(op),
_numChildren(numChildren),
//_globalIndex(0),
_flags(0),
_visitCount(0),
_localIndex(0),
_referenceCount(0),
_byteCodeInfo(),
_unionBase(),
_unionPropertyA()
{
TR::Compilation * comp = TR::comp();
if (!comp->isPeekingMethod() && self()->uses64BitGPRs())
comp->getJittedMethodSymbol()->setMayHaveLongOps(true);
uint16_t numElems = numChildren;
if (numElems > NUM_DEFAULT_CHILDREN)
{
self()->createNodeExtension(numElems);
}
if (op == TR::BBStart)
{
self()->setChild(0, NULL);
self()->setLabel(NULL);
}
else
{
self()->setChild(0, NULL);
self()->setChild(1, NULL);
}
self()->setReferenceCount(0);
self()->setVisitCount(0);
self()->setLocalIndex(0);
memset( &(_unionA), 0, sizeof( _unionA ) );
if (self()->getGlobalIndex() == MAX_NODE_COUNT)
{
TR_ASSERT(0, "getGlobalIndex() == MAX_NODE_COUNT");
comp->failCompilation<TR::ExcessiveComplexity>("Global index equal to max node count");
}
_byteCodeInfo.setInvalidCallerIndex();
_byteCodeInfo.setIsSameReceiver(0);
TR_IlGenerator * ilGen = comp->getCurrentIlGenerator();
if (ilGen)
{
int32_t i = ilGen->currentByteCodeIndex();
_byteCodeInfo.setByteCodeIndex(i >= 0 ? i : 0);
_byteCodeInfo.setCallerIndex(comp->getCurrentInlinedSiteIndex());
if (_byteCodeInfo.getCallerIndex() < 0)
_byteCodeInfo.setCallerIndex(ilGen->currentCallSiteIndex());
TR_ASSERT(_byteCodeInfo.getCallerIndex() < (SHRT_MAX/4), "Caller index too high; cannot set high order bit\n");
_byteCodeInfo.setDoNotProfile(0);
}
else if (originatingByteCodeNode)
{
_byteCodeInfo = originatingByteCodeNode->getByteCodeInfo();
_byteCodeInfo.setDoNotProfile(1);
}
else
{
// Commented out because dummy nodes are created in
// estimate code size to be able to propagate frequencies
//else
// TR_ASSERT(0, "no byte code info");
_byteCodeInfo.setDoNotProfile(1);
}
if(comp->getDebug())
comp->getDebug()->newNode(self());
// check that _unionPropertyA union is disjoint
TR_ASSERT(
self()->hasSymbolReference()
+ self()->hasRegLoadStoreSymbolReference()
+ self()->hasBranchDestinationNode()
+ self()->hasBlock()
+ self()->hasArrayStride()
+ self()->hasPinningArrayPointer()
+ self()->hasDataType() <= 1,
"_unionPropertyA union is not disjoint for this node %s (%p):\n"
" has({SymbolReference, ...}, ..., DataType) = ({%1d,%1d},%1d,%1d,%1d,%1d,%1d)\n",
self()->getOpCode().getName(), this,
self()->hasSymbolReference(),
self()->hasRegLoadStoreSymbolReference(),
self()->hasBranchDestinationNode(),
self()->hasBlock(),
self()->hasArrayStride(),
self()->hasPinningArrayPointer(),
self()->hasDataType());
}
/**
* Copy constructor, must allow for copying more than 2 children.
*/
OMR::Node::Node(TR::Node * from, uint16_t numChildren)
: _opCode(TR::BadILOp),
_numChildren(0),
_globalIndex(0),
_flags(0),
_visitCount(0),
_localIndex(0),
_referenceCount(0),
_byteCodeInfo(),
_unionBase(),
_unionPropertyA()
{
TR::Compilation * comp = TR::comp();
memcpy(self(), from, sizeof(TR::Node));
if (self()->hasDataType())
self()->setDataType(TR::NoType);
self()->copyChildren(from, numChildren, true /* forNodeExtensionOnly */);
if (from->getOpCode().getOpCodeValue() == TR::allocationFence)
self()->setAllocation(NULL);
self()->setGlobalIndex(comp->getNodePool().getLastGlobalIndex());
// a memcpy is used above to copy fields from the argument "node" to "this", but
// opt attributes are separate, and need separate initialization.
self()->setReferenceCount(from->getReferenceCount());
self()->setVisitCount(from->getVisitCount());
self()->setLocalIndex(from->getLocalIndex());
_unionA = from->_unionA;
if (self()->getGlobalIndex() == MAX_NODE_COUNT)
{
TR_ASSERT(0, "getGlobalIndex() == MAX_NODE_COUNT");
comp->failCompilation<TR::ExcessiveComplexity>("Global index equal to max node count");
}
if(comp->getDebug())
comp->getDebug()->newNode(self());
TR_IlGenerator * ilGen = comp->getCurrentIlGenerator();
if (ilGen)
{
_byteCodeInfo.setDoNotProfile(0);
}
else
{
_byteCodeInfo.setDoNotProfile(1);
}
if (from->getOpCode().isBranch() || from->getOpCode().isSwitch())
_byteCodeInfo.setDoNotProfile(1);
if (from->getOpCode().isStoreReg() || from->getOpCode().isLoadReg())
{
if (from->requiresRegisterPair(comp))
{
self()->setLowGlobalRegisterNumber(from->getLowGlobalRegisterNumber());
self()->setHighGlobalRegisterNumber(from->getHighGlobalRegisterNumber());
}
else
{
self()->setGlobalRegisterNumber(from->getGlobalRegisterNumber());
}
}
if (from->hasDataType())
{
self()->setDataType(from->getDataType());
}
}
TR::Node *
OMR::Node::copy(TR::Node * from)
{
TR::Compilation *comp = TR::comp();
int32_t numChildren = from->getNumChildren();
TR::ILOpCode opCode = from->getOpCode();
TR::ILOpCodes opCodeValue = opCode.getOpCodeValue();
if (opCode.isIf() ||
opCodeValue == TR::anewarray ||
opCodeValue == TR::newarray ||
opCodeValue == TR::arraycopy ||
opCodeValue == TR::tstart ||
opCodeValue == TR::arrayset)
++numChildren;
// note arraystorechk node has 1 or 2 children but it allocates spaces for 3 children
// we need to make sure we have room for 3
if (opCodeValue == TR::ArrayStoreCHK)
numChildren = 3;
TR::Node * n = new (comp->getNodePool()) TR::Node(from);
return n;
}
TR::Node *
OMR::Node::copy(TR::Node * from, int32_t numChildren)
{
TR::Compilation *comp = TR::comp();
TR_ASSERT(numChildren >= from->getNumChildren(), "copy must have at least as many children as original");
TR::Node *clone = new (comp->getNodePool()) TR::Node(from, numChildren);
return clone;
}
/**
* Copy the children of from to this node, extending if necessary
*
* If !forNodeExtensionOnly then clone the default children as well, including the _numChildren[Room] fields
*/
void
OMR::Node::copyChildren(TR::Node *from, uint16_t numChildren /* ignored if !forNodeExtensionOnly */, bool forNodeExtensionOnly)
{
if (!forNodeExtensionOnly)
{
_numChildren = numChildren = from->getNumChildren();
}
if (from->hasNodeExtension())
{
// if original node had a node extension, need to copy over those elements
if (numChildren > from->_unionBase._extension.getNumElems())
{
self()->createNodeExtension(numChildren);
for(uint16_t childNum = 0; childNum < from->_unionBase._extension.getNumElems(); childNum++)
self()->setChild(childNum, from->getChild(childNum));
}
else
{
size_t size = from->sizeOfExtension();
self()->copyNodeExtension(from->_unionBase._extension.getExtensionPtr(), from->_unionBase._extension.getNumElems(), size);
}
}
else
{
if (numChildren > NUM_DEFAULT_CHILDREN)
self()->createNodeExtension(numChildren);
if ((numChildren > NUM_DEFAULT_CHILDREN) || !forNodeExtensionOnly)
for(uint16_t childNum = 0 ; childNum < from->getNumChildren(); childNum++)
self()->setChild(childNum, from->getChild(childNum));
}
}
void
OMR::Node::copyValidProperties(TR::Node *fromNode, TR::Node *toNode)
{
// IMPORTANT: Copy UnionPropertyA first
// Some parts of the code rely on getDataType, which can assert if
// toNode's opcode before copying has the HasNoDataType property and
// fromNode's opcode does not have the HasNoDataType property
UnionPropertyA_Type fromUnionPropertyA_Type = fromNode->getUnionPropertyA_Type();
UnionPropertyA_Type toUnionPropertyA_Type = toNode->getUnionPropertyA_Type();
if (fromUnionPropertyA_Type == toUnionPropertyA_Type)
{
switch (fromUnionPropertyA_Type)
{
case HasSymbolReference:
#if !defined(ENABLE_RECREATE_WITH_COPY_VALID_PROPERTIES_COMPLETE)
toNode->_unionPropertyA._symbolReference = fromNode->_unionPropertyA._symbolReference;
#else
toNode->setSymbolReference(fromNode->getSymbolReference());
#endif
break;
case HasRegLoadStoreSymbolReference:
#if !defined(ENABLE_RECREATE_WITH_COPY_VALID_PROPERTIES_COMPLETE)
toNode->_unionPropertyA._regLoadStoreSymbolReference = fromNode->_unionPropertyA._regLoadStoreSymbolReference;
#else
toNode->setRegLoadStoreSymbolReference(fromNode->getRegLoadStoreSymbolReference());
#endif
break;
case HasBranchDestinationNode:
toNode->setBranchDestination(fromNode->getBranchDestination());
break;
case HasBlock:
toNode->setBlock(fromNode->getBlock());
break;
case HasArrayStride:
toNode->setArrayStride(fromNode->getArrayStride());
break;
case HasPinningArrayPointer:
toNode->setPinningArrayPointer(fromNode->getPinningArrayPointer());
break;
case HasDataType:
toNode->setDataType(fromNode->getDataType());
break;
default:
/* HasNoUnionPropertyA */
break;
}
}
TR::ILOpCodes fromOpCode = fromNode->getOpCodeValue();
TR::ILOpCodes toOpCode = toNode->getOpCodeValue();
#if defined(ENABLE_RECREATE_WITH_COPY_VALID_PROPERTIES_COMPLETE)
// _unionBase._unionBase._constValue - presently incomplete
bool fromConst = fromNode->getOpCode().isLoadConst() && (fromNode->getType().isIntegral() || fromNode->getType().isAddress());
bool toConst = toNode->getOpCode().isLoadConst() && (toNode->getType().isIntegral() || toNode->getType().isAddress());
if (fromConst && toConst)
toNode->set64bitIntegralValue(fromNode->get64bitIntegralValue());
// TODO: other properties that need to be completed - see below
#else
// _unionBase
if (toNode->_numChildren == 0 || !toNode->hasNodeExtension())
{
/* if (fromNode->getOpCode().getOpCodeValue() == TR::allocationFence)
self()->setAllocation(NULL); */
{
// may be using other property that is unioned with _unionBase._children but do not know which one
// so have to copy it forward irregardless of whether it is valid or not
toNode->_unionBase = fromNode->_unionBase;
}
}
// nameSymRef & callNodeData, if set on formNode, is already set for toNode (its looked up via globalIndex which is unchanged)
// TODO: check whether properties are valid for the replacement node and remove if invalid
if (toNode->getOpCode().isBranch() || toNode->getOpCode().isSwitch())
toNode->_byteCodeInfo.setDoNotProfile(1);
// _flags
toNode->setFlags(fromNode->getFlags()); // do not clear hasNodeExtension
#endif
toNode->copyChildren(fromNode);
// DONE:
// OMR::Base
// _opCode
// _numChildren - init list
// _globalIndex
// OMR::Node
// _byteCodeInfo
// _unionPropertyB - init list
// _globalRegisterInfo - non-J9
// _optAttributes - init list
// TODO:
// OMR::Base
// // this union still needs to be completed on consts, and _unionBase._unionBase._unionedWithChildren
// _unionBase:
// _children[NUM_DEFAULT_CHILDREN] - cstr body
// _constValue - init list, need to fix users of recreate to NOT set const, THEN do recreate
// _fpConstValue
// _dpConstValue
// _fpConstValueBits
// _extension - done
// _data
// _flags // for future use
// _numElems
// _unionedWithChildren
// union:
// _constData
// _globalRegisterInfo
// _offset
// _relocationInfo
// _caseInfo
// _monitorInfo
//
// CallNodeData
//
// OMR::Node
// _unionPropertyA - needs to be completed for DAA
// _flags
}
TR::Node *
OMR::Node::recreate(TR::Node *originalNode, TR::ILOpCodes op)
{
return TR::Node::recreateAndCopyValidPropertiesImpl(originalNode, op, NULL);
}
TR::Node *
OMR::Node::recreateWithSymRef(TR::Node *originalNode, TR::ILOpCodes op, TR::SymbolReference *newSymRef)
{
return TR::Node::recreateAndCopyValidPropertiesImpl(originalNode, op, newSymRef);
}
/**
* OMR::Node::recreate
*
* creates a new node with a new op, based on the originalNode, reusing the memory occupied by originalNode and returning the
* same address as it.
*
* It will have the same globalIndex, poolIndex, byteCodeInfo, and optAttributes as the originalNode, but properties from
* the originalNode that are valid for the new node only will be copied. All other properties will be reset to their default values.
*/
TR::Node *
OMR::Node::recreateAndCopyValidPropertiesImpl(TR::Node *originalNode, TR::ILOpCodes op, TR::SymbolReference *newSymRef)
{
TR_ASSERT(originalNode != NULL, "trying to recreate node from a NULL originalNode.");
if (originalNode->getOpCodeValue() == op)
{
if (!originalNode->hasSymbolReference() || newSymRef != originalNode->getSymbolReference())
originalNode->_byteCodeInfo.setDoNotProfile(1);
// need to at least set the new symbol reference on the node before returning
if (newSymRef)
originalNode->setSymbolReference(newSymRef);
return originalNode;
}
TR::Compilation * comp = TR::comp();
// // one may consider copy forwarding as a transformation of the old way of doing things to the new way
// // "untransforming" means reverting to setOpCodeValue only. However reverting may in future be a
// // bad thing to do, so disabling this.
// if (!performTransformation(comp, "O^O RECREATE: recreating node %s %p; original opcode %s\n",
// TR::ILOpCode(op).getName(), originalNode, originalNode->getOpCode().getName()))
// {
// originalNode->setOpCodeValue(op);
// return originalNode;
// }
// need to copy the original node so the properties are available later to set on the recreated node
uint16_t numChildren = originalNode->getNumChildren();
TR::Node *originalNodeCopy = TR::Node::copy(originalNode, numChildren);
#if !defined(DISABLE_RECREATE_WITH_TRUE_CLEARING_OF_PROPERTIES)
// we can't delete the node, otherwise we will potentially lose the poolIndex (and other properties), but we do need to deallocate
// any objects it has created. This is one of them. It will be recreated if necessary on createInternal.
// other properties such as nameSymRef & callNodeData, are associated with the _globalIndex
// and are not freed and realloced.
originalNode->freeExtensionIfExists();
// this clears most properties, so copyValidProperties must be complete
TR::Node *node = TR::Node::createInternal(0, op, originalNode->getNumChildren(), originalNode);
#else
// this does not clear properties, but some properties may be invalid for the replacement node,
// but it does not matter if copyValidProperties is complete, though it must be accurate
TR::Node *node = originalNode;
node->setOpCodeValue(op);
#endif
if (newSymRef)
{
if (originalNodeCopy->hasSymbolReference() || originalNodeCopy->hasRegLoadStoreSymbolReference())
originalNodeCopy->setSymbolReference(newSymRef);
else if (node->hasSymbolReference() || node->hasRegLoadStoreSymbolReference())
node->setSymbolReference(newSymRef);
}
// TODO: copyValidProperties is incomplete
TR::Node::copyValidProperties(originalNodeCopy, node);
originalNode->_byteCodeInfo.setDoNotProfile(1);
// add originalNodeCopy back to the node pool
comp->getNodePool().deallocate(originalNodeCopy);
return node;
}
TR::Node *
OMR::Node::createInternal(TR::Node *originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *originalNode)
{
if (!originalNode)
return new (TR::comp()->getNodePool()) TR::Node(originatingByteCodeNode, op, numChildren);
else
{
// Recreate node from originalNode, ignore originatingByteCodeNode
ncount_t globalIndex = originalNode->getGlobalIndex();
vcount_t visitCount = originalNode->getVisitCount();
scount_t localIndex = originalNode->getLocalIndex();
rcount_t referenceCount = originalNode->getReferenceCount();
UnionA unionA = originalNode->_unionA;
const TR_ByteCodeInfo byteCodeInfo = originalNode->getByteCodeInfo(); // copy bytecode info into temporary variable
//TR::Node * node = new (TR::comp()->getNodePool(), poolIndex) TR::Node(0, op, numChildren);
TR::Node *node = new ((void*)originalNode) TR::Node(0, op, numChildren);
node->setGlobalIndex(globalIndex);
node->setByteCodeInfo(byteCodeInfo);
node->setVisitCount(visitCount);
node->setLocalIndex(localIndex);
node->setReferenceCount(referenceCount);
node->_unionA = unionA;
return node;
}
}
TR::Node *
OMR::Node::create(TR::Node * originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
TR::Node * node = TR::Node::createInternal(originatingByteCodeNode, op, numChildren);
return node;
}
TR::Node *
OMR::Node::create(TR::Node * originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren, TR::TreeTop * dest)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
TR::Node *node = TR::Node::createInternal(originatingByteCodeNode, op, numChildren);
if (dest)
node->setBranchDestination(dest);
return node;
}
TR::Node *
OMR::Node::create(TR::Node * originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren, int32_t intValue, TR::TreeTop * dest)
{
TR_ASSERT(op != TR::bconst && op != TR::sconst, "Invalid constructor for 8/16-bit constants");
TR::Node * node = TR::Node::create(originatingByteCodeNode, op, numChildren, dest);
if (op == TR::lconst)
{
node->setConstValue(intValue);
}
else
node->setConstValue((int32_t)intValue);
return node;
}
TR::Node *
OMR::Node::create(TR::Node * originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node* first)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
TR::Node * node = TR::Node::createInternal(originatingByteCodeNode, op, numChildren);
node->setAndIncChild(0, first);
return node;
}
TR::Node *
OMR::Node::create(TR::Node * originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node* first, TR::Node *second)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
TR::Node * node = TR::Node::createInternal(originatingByteCodeNode, op, numChildren);
node->setAndIncChild(0, first);
node->setAndIncChild(1, second);
return node;
}
TR::Node *
OMR::Node::createWithSymRef(TR::Node * originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren, TR::SymbolReference * symRef)
{
TR::Node * node = TR::Node::create(originatingByteCodeNode, op, numChildren);
node->setSymbolReference(symRef);
return node;
}
TR::Node *
OMR::Node::createWithSymRef(TR::Node * originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node* first, TR::SymbolReference * symRef)
{
TR::Node * node = TR::Node::create(originatingByteCodeNode, op, numChildren, first);
node->setSymbolReference(symRef);
return node;
}
TR::Node *
OMR::Node::createOnStack(TR::Node * originatingByteCodeNode, TR::ILOpCodes op, uint16_t numChildren)
{
return TR::Node::createInternal(originatingByteCodeNode, op, numChildren);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::SymbolReference * symRef)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
TR::Node *node = TR::Node::createInternal(0, op, numChildren, originalNode);
if (symRef != NULL || node->hasSymbolReference() || node->hasRegLoadStoreSymbolReference())
{
// don't attempt to set this if the symRef is NULL and the node isn't a symRef type; otherwise attempt to do so
node->setSymbolReference(symRef);
}
return node;
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren)
{
return TR::Node::create(0, op, numChildren);
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, TR::TreeTop * dest)
{
return TR::Node::create(0, op, numChildren, dest);
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, int32_t intValue, TR::TreeTop * dest)
{
return TR::Node::create(0, op, numChildren, intValue, dest);
}
TR::Node *
OMR::Node::createWithSymRef(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, uintptr_t extraChildren, TR::SymbolReference *symRef)
{
uint16_t numChildrenRoom = numChildren + (uint16_t) extraChildren; // explictly cast to avoid warning
TR::Node *node = TR::Node::createWithSymRef(op, numChildrenRoom, 1, first, symRef);
node->_numChildren = numChildren;
return node;
}
TR::Node *
OMR::Node::createWithSymRef(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, uintptr_t extraChildren, TR::SymbolReference *symRef)
{
TR::Node *node = TR::Node::createWithSymRef(op, numChildren, first, extraChildren, symRef); // explictly cast to avoid warning
node->setChild(1, second);
second->incReferenceCount();
return node;
}
TR::Node *
OMR::Node::createWithSymRef(TR::ILOpCodes op, uint16_t numChildren, TR::SymbolReference * symRef)
{
return TR::Node::createWithSymRef(0, op, numChildren, symRef);
}
TR::Node *
OMR::Node::createWithSymRef(TR::ILOpCodes op, uint16_t numChildren, TR::SymbolReference * symRef, uintptr_t extraChildrenForFixup)
{
uint16_t numChildrenRoom = numChildren + (uint16_t) extraChildrenForFixup; // explictly cast to avoid warning
TR::Node * r = TR::Node::createWithSymRef(0, op, numChildrenRoom, symRef);
r->_numChildren = numChildren;
return r;
}
/**
* These are defined for compilers that do not support variadic templates
* Otherwise the definitions are in il/OMRNode_inlines.hpp
*/
#if defined(_MSC_VER) || defined(LINUXPPC)
TR::Node *
OMR::Node::recreateWithoutSymRef_va_args(TR::Node *originalNode, TR::ILOpCodes op,
uint16_t numChildren, uint16_t numChildArgs,
va_list &args)
{
TR_ASSERT(numChildArgs > 0, "must be called with at least one child, but numChildArgs = %d", numChildArgs);
TR::Node *first = va_arg(args, TR::Node *);
TR_ASSERT(first != NULL, "child %d must be non NULL", 0);
TR::Node *node = TR::Node::createInternal(first, op, numChildren, originalNode);
node->setAndIncChild(0, first);
for (uint16_t i = 1; i < numChildArgs; i++)
{
TR::Node *child = va_arg(args, TR::Node *);
TR_ASSERT(child != NULL, "child %d must be non NULL", i);
node->setAndIncChild(i, child);
}
return node;
}
TR::Node *
OMR::Node::createWithoutSymRef(TR::ILOpCodes op, uint16_t numChildren,
uint16_t numChildArgs, ...)
{
va_list args;
va_start(args, numChildArgs);
TR::Node *node = TR::Node::recreateWithoutSymRef_va_args(0, op, numChildren, numChildArgs, args);
va_end(args);
return node;
}
TR::Node *
OMR::Node::recreateWithoutSymRef(TR::Node *originalNode, TR::ILOpCodes op,
uint16_t numChildren, uint16_t numChildArgs,
...)
{
va_list args;
va_start(args, numChildArgs);
TR::Node *node = TR::Node::recreateWithoutSymRef_va_args(originalNode, op, numChildren, numChildArgs, args);
va_end(args);
return node;
}
TR::Node *
OMR::Node::recreateWithSymRefWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op,
uint16_t numChildren, uint16_t numChildArgs,
...)
{
va_list args;
va_start(args, numChildArgs);
TR::Node *node = TR::Node::recreateWithoutSymRef_va_args(originalNode, op, numChildren, numChildArgs, args);
TR::SymbolReference *symRef = va_arg(args, TR::SymbolReference *);
node->setSymbolReference(symRef);
va_end(args);
return node;
}
// only this variadic method is part of the external interface
TR::Node *
OMR::Node::createWithSymRef(TR::ILOpCodes op, uint16_t numChildren,
uint16_t numChildArgs, ...)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
va_list args;
va_start(args, numChildArgs);
TR::Node *node = TR::Node::recreateWithoutSymRef_va_args(0, op, numChildren, numChildArgs, args);
TR::SymbolReference *symRef = va_arg(args, TR::SymbolReference *);
node->setSymbolReference(symRef);
va_end(args);
return node;
}
#else
uint16_t
OMR::Node::addChildrenAndSymRef(uint16_t lastIndex, TR::SymbolReference *symRef)
{
self()->setSymbolReference(symRef);
uint16_t numChildArgs = lastIndex;
return numChildArgs;
}
uint16_t
OMR::Node::addChildrenAndSymRef(uint16_t childIndex, TR::Node *child)
{
TR_ASSERT(child != NULL, "child[%d] must be non NULL", childIndex);
self()->setAndIncChild(childIndex, child);
uint16_t numChildArgs = childIndex + 1;
return numChildArgs;
}
#endif
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::createWithoutSymRef(op, numChildren, 1, first);
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::createWithoutSymRef(op, numChildren, 2, first, second);
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::createWithoutSymRef(op, numChildren, 3, first, second, third);
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::createWithoutSymRef(op, numChildren, 4, first, second, third, fourth);
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth, TR::Node *fifth)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::createWithoutSymRef(op, numChildren, 5, first, second, third, fourth, fifth);
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth, TR::Node *fifth, TR::Node *sixth)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::createWithoutSymRef(op, numChildren, 6, first, second, third, fourth, fifth, sixth);
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth, TR::Node *fifth, TR::Node *sixth, TR::Node *seventh)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::createWithoutSymRef(op, numChildren, 7, first, second, third, fourth, fifth, sixth, seventh);
}
TR::Node *
OMR::Node::create(TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth, TR::Node *fifth, TR::Node *sixth, TR::Node *seventh, TR::Node *eighth)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::createWithoutSymRef(op, numChildren, 8, first, second, third, fourth, fifth, sixth, seventh, eighth);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithoutSymRef(originalNode, op, numChildren, 1, first);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithoutSymRef(originalNode, op, numChildren, 2, first, second);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithoutSymRef(originalNode, op, numChildren, 3, first, second, third);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithoutSymRef(originalNode, op, numChildren, 4, first, second, third, fourth);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth, TR::Node *fifth)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithoutSymRef(originalNode, op, numChildren, 5, first, second, third, fourth, fifth);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth, TR::Node *fifth, TR::Node *sixth)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithoutSymRef(originalNode, op, numChildren, 6, first, second, third, fourth, fifth, sixth);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth, TR::Node *fifth, TR::Node *sixth, TR::Node *seventh)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithoutSymRef(originalNode, op, numChildren, 7, first, second, third, fourth, fifth, sixth, seventh);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth, TR::Node *fifth, TR::Node *sixth, TR::Node *seventh, TR::Node *eighth)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithoutSymRef(originalNode, op, numChildren, 8, first, second, third, fourth, fifth, sixth, seventh, eighth);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::SymbolReference * symRef)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithSymRefWithoutProperties(originalNode, op, numChildren, 1, first, symRef);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::SymbolReference * symRef)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithSymRefWithoutProperties(originalNode, op, numChildren, 2, first, second, symRef);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::SymbolReference * symRef)
{
TR_ASSERT(TR::Node::isLegalCallToCreate(op), "assertion failure");
return TR::Node::recreateWithSymRefWithoutProperties(originalNode, op, numChildren, 3, first, second, third, symRef);
}
TR::Node *
OMR::Node::recreateWithoutProperties(TR::Node *originalNode, TR::ILOpCodes op, uint16_t numChildren, TR::Node *first, TR::Node *second, TR::Node *third, TR::Node *fourth, TR::SymbolReference * symRef)
{