-
Notifications
You must be signed in to change notification settings - Fork 394
/
OMRBlock.hpp
639 lines (493 loc) · 26.8 KB
/
OMRBlock.hpp
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
/*******************************************************************************
* 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
*******************************************************************************/
#ifndef OMR_BLOCK_INCL
#define OMR_BLOCK_INCL
/*
* The following #define and typedef must appear before any #includes in this file
*/
#ifndef OMR_BLOCK_CONNECTOR
#define OMR_BLOCK_CONNECTOR
namespace OMR { class Block; }
namespace OMR { typedef OMR::Block BlockConnector; }
#endif
#define MIN_PROFILED_FREQUENCY (.75f)
#include "infra/CfgNode.hpp"
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include "compile/Compilation.hpp"
#include "env/TRMemory.hpp"
#include "env/jittypes.h"
#include "il/Node.hpp"
#include "infra/Annotations.hpp"
#include "infra/Assert.hpp"
#include "infra/Cfg.hpp"
#include "infra/Flags.hpp"
#include "infra/Link.hpp"
#include "infra/List.hpp"
#include "optimizer/Optimizer.hpp"
class TR_BitVector;
class TR_BlockStructure;
class TR_Debug;
namespace TR { class GlobalRegister; }
class TR_GlobalRegisterAllocator;
class TR_Memory;
class TR_RegionStructure;
namespace TR { class RegisterCandidate; }
namespace TR { class RegisterCandidates; }
class TR_ResolvedMethod;
namespace TR { class Block; }
namespace TR { class CFGEdge; }
namespace TR { class CFGNode; }
namespace TR { class DebugCounterAggregation; }
namespace TR { class Instruction; }
namespace TR { class Symbol; }
namespace TR { class TreeTop; }
template <class T> class TR_Array;
// Pseudo-safe downcast from a CFG node to a TR::Block
//
static inline TR::Block *toBlock(TR::CFGNode *node)
{
#if DEBUG
if (node != NULL)
{
TR_ASSERT(node->asBlock() != NULL, "Bad downcast from TR::CFGNode to TR::Block");
}
#endif
return (TR::Block *)node;
}
namespace OMR
{
/**
* Order of Blocks:
* There are two types of orders for blocks, CFG and textual order.
* CFG (Control flow graph) orders the block in a control flow manner.
* Textual order is just a linear order of blocks. It does not represent the control flow.
* --> At any given point during compilation, the code compiled is represented by a linked list of treetops, which are broken up into blocks.
* --> And this is the textual order
*
* To traverse blocks in CFG order, use getSuccessors(), getPredecessors()
* To traverse blocks in textual order, use getNextBlock(), getPrevBlock()
*
*/
class OMR_EXTENSIBLE Block : public TR::CFGNode
{
public:
/// Downcast to concrete type
TR::Block * self();
Block(TR_Memory * m);
Block(TR::CFG &cfg);
/// Create a block with the given entry and exit.
Block(TR::TreeTop *entry, TR::TreeTop *exit, TR_Memory * m);
Block(TR::TreeTop *entry, TR::TreeTop *exit, TR::CFG &cfg);
/// Copy Constructor.
///
/// Uses the same memory as `other`
Block(TR::Block &other, TR::TreeTop *entry, TR::TreeTop *exit);
~Block()
{
TR_ASSERT(0,"blocks should not be freed until the destructor is updated to also free the catch block extension");
// Currently blocks are allocated on the heap and we never free them.
// In the future, if we start freeing blocks, we should update
// ensureCatchBlockExtensionExists to allocate the catch block extension
// somewhere other than the heap, and then free _catchBlockExtension here
// if it is not null.
}
virtual const char * getName(TR_Debug *);
static TR::Block * createBlock(TR::TreeTop *entry, TR::TreeTop *exit, TR::CFG &cfg);
static TR::Block * createEmptyBlock(TR::Node *, TR::Compilation *, int32_t frequency = -1, TR::Block *block = NULL);
static TR::Block * createEmptyBlock(TR::Compilation *comp, int32_t frequency = -1, TR::Block *block = NULL);
TR::Block *breakFallThrough(TR::Compilation *comp, TR::Block *faller, TR::Block *fallee);
static void insertBlockAsFallThrough(TR::Compilation *comp, TR::Block *block, TR::Block *newFallThroughBlock);
static void redirectFlowToNewDestination(TR::Compilation *comp, TR::CFGEdge *origEdge, TR::Block *newTo, bool useGotoForFallThrough);
virtual TR::Block *asBlock();
// return the first treetop in the block, skipping past any fences
TR::TreeTop * getFirstRealTreeTop();
// return the treetop before the exit, skipping past any fences
TR::TreeTop * getLastRealTreeTop();
// returns the treetop before any [un]conditional goto, return, etc.
TR::TreeTop * getLastNonControlFlowTreeTop();
int32_t getNumberOfRealTreeTops();
/// getNextBlock and getPrevBlock return the next/previous block in the "textual" orders of blocks
TR::Block * getNextBlock();
TR::Block * getPrevBlock();
TR::Block * getNextExtendedBlock();
// append a node under a treetop and before the bbend
TR::TreeTop *append(TR::TreeTop * tt);
// preppend a node under a treetop immediately after the bbStart
TR::TreeTop * prepend(TR::TreeTop * tt);
TR::Block * split(TR::TreeTop * startOfNewBlock, TR::CFG * cfg, bool fixupCommoning = false, bool copyExceptionSuccessors = true, TR::ResolvedMethodSymbol *methodSymbol = NULL);
TR::Block * splitPostGRA(TR::TreeTop *startOfNewBlock, TR::CFG *cfg, bool copyExceptionSuccessors = true, TR::ResolvedMethodSymbol *methodSymbol = NULL);
TR::Block * splitWithGivenMethodSymbol(TR::ResolvedMethodSymbol *methodSymbol, TR::TreeTop * startOfNewBlock, TR::CFG * cfg, bool fixupCommoning = false, bool copyExceptionSuccessors = true);
TR::Block *createConditionalSideExitBeforeTree(TR::TreeTop *tree,
TR::TreeTop *compareTree,
TR::TreeTop *exitTree,
TR::TreeTop *returnTree,
TR::CFG *cfg,
bool markCold = true);
TR::Block * createConditionalBlocksBeforeTree(TR::TreeTop* tree,
TR::TreeTop* compareTree,
TR::TreeTop* ifTree,
TR::TreeTop* elseTree,
TR::CFG* cfg,
bool changeBlockExtensions = true,
bool markCold = true);
TR::Block * splitEdge(TR::Block *, TR::Block *, TR::Compilation *, TR::TreeTop **lastTreeTop = NULL, bool findOptimalInsertionPoint = true);
virtual void removeFromCFG(TR::Compilation *);
// remove the branch treetop from the block as well as the associated branch edge.
// removeBranch assumes the last nonfence node is a branch.
//
void removeBranch(TR::Compilation *);
void takeGlRegDeps(TR::Compilation *comp, TR::Node *glRegDeps);
TR::Block * findVirtualGuardBlock( TR::CFG *cfg);
TR_RegionStructure *getParentStructureIfExists( TR::CFG *);
TR_RegionStructure *getCommonParentStructureIfExists(TR::Block *, TR::CFG *);
void inheritBlockInfo(TR::Block * org, bool inheritFreq = true);
bool isTargetOfJumpWhoseTargetCanBeChanged(TR::Compilation * comp);
static int32_t getMaxColdFrequency(TR::Block *b1, TR::Block *b2);
static int32_t getMinColdFrequency(TR::Block *b1, TR::Block *b2);
static int32_t getScaledSpecializedFrequency(int32_t fastFrequency);
TR::Block * startOfExtendedBlock();
// change the target of the branch in the block, add an edge to the new block,
// remove the edge from the previous destination block and update any GlRegDep Nodes
//
void changeBranchDestination(TR::TreeTop * newDestination, TR::CFG *cfg, bool callerFixesRegdeps = false);
TR::Node * findFirstReference(TR::Symbol * sym, vcount_t visitCount);
void collectReferencedAutoSymRefsIn(TR::Compilation *comp, TR_BitVector *, vcount_t);
void collectReferencedAutoSymRefsIn(TR::Compilation *comp, TR::Node *, TR_BitVector *, vcount_t);
// Map for which standard exceptions can be caught by this (catch) block
//
enum
{
CanCatchNullCheck = 0x00000001,
CanCatchResolveCheck = 0x00000002,
CanCatchDivCheck = 0x00000004,
CanCatchBoundCheck = 0x00000008,
CanCatchArrayStoreCheck = 0x00000010,
CanCatchCheckCast = 0x00000020,
CanCatchNew = 0x00000040,
CanCatchArrayNew = 0x00000080,
CanCatchMonitorExit = 0x00000100,
CanCatchUserThrows = 0x00000200,
CanCatchOSR = 0x00000400,
CanCatchOverflowCheck = 0x00000800,
CanCatchNewvalue = 0x00001000,
CanCatchEverything = 0x00001FFF, // Mask for all of the above
};
bool canCatchExceptions(uint32_t flags); // uses the above enum
bool canFallThroughToNextBlock();
bool doesNotNeedLabelAtStart();
TR::CFGEdge * getFallThroughEdgeInEBB();
void setByteCodeIndex(int32_t index, TR::Compilation *comp);
bool endsInGoto();
bool isGotoBlock(TR::Compilation * comp, bool allowPrecedingSnapshots=false);
bool endsInBranch();
bool isEmptyBlock();
TR::TreeTop *getExceptingTree();
bool hasExceptionPredecessors();
bool hasExceptionSuccessors();
/**
* Field functions
*/
TR::TreeTop *getEntry() { return _pEntry; }
TR::TreeTop *setEntry(TR::TreeTop *p)
{
if (TR::comp()->getOptimizer() && !TR::comp()->isPeekingMethod())
{
TR::comp()->getOptimizer()->setCachedExtendedBBInfoValid(false);
}
return (_pEntry = p);
}
TR::TreeTop *getExit() { return _pExit; }
TR::TreeTop *setExit(TR::TreeTop *p)
{
if (TR::comp()->getOptimizer() && !TR::comp()->isPeekingMethod())
{
TR::comp()->getOptimizer()->setCachedExtendedBBInfoValid(false);
}
return (_pExit = p);
}
TR_BitVector *getLiveLocals() { return _liveLocals; }
TR_BitVector *setLiveLocals(TR_BitVector* v) { return (_liveLocals = v); }
TR_BlockStructure *getStructureOf() { return _pStructureOf; }
TR_BlockStructure *setStructureOf(TR_BlockStructure *p) { return (_pStructureOf = p); }
int32_t getNestingDepth();
TR_Array<TR::GlobalRegister> & getGlobalRegisters(TR::Compilation *);
void clearGlobalRegisters() { _globalRegisters = NULL; }
struct InstructionBoundaries : TR_Link<InstructionBoundaries>
{
InstructionBoundaries(uint32_t s = UINT_MAX, uint32_t e = UINT_MAX) : _startPC(s), _endPC(e) { }
uint32_t _startPC;
uint32_t _endPC;
};
void setInstructionBoundaries(uint32_t startPC, uint32_t endPC);
InstructionBoundaries & getInstructionBoundaries() { return _instructionBoundaries; }
void addExceptionRangeForSnippet(uint32_t startPC, uint32_t endPC);
InstructionBoundaries * getFirstSnippetBoundaries() { return _snippetBoundaries.getFirst(); }
TR::Instruction *getFirstInstruction() { return _firstInstruction; }
TR::Instruction *setFirstInstruction(TR::Instruction *i) { return (_firstInstruction = i); }
TR::Instruction *getLastInstruction() { return _lastInstruction; }
TR::Instruction *setLastInstruction(TR::Instruction *i) { return (_lastInstruction = i); }
class TR_CatchBlockExtension
{
public:
TR_ALLOC(TR_Memory::CatchBlockExtension)
TR_CatchBlockExtension()
: _exceptionClass(NULL), _exceptionClassNameChars(NULL), _exceptionClassNameLength(0),
_catchType(0), _exceptionsCaught(0), _handlerIndex(0), _inlineDepth(0), _owningMethod(NULL), _isSyntheticHandler(false) {}
TR_CatchBlockExtension(TR_CatchBlockExtension &other)
: _exceptionClass(other._exceptionClass), _exceptionClassNameChars(other._exceptionClassNameChars),
_exceptionClassNameLength(other._exceptionClassNameLength), _catchType(other._catchType),
_exceptionsCaught(other._exceptionsCaught), _handlerIndex(other._handlerIndex),
_inlineDepth(other._inlineDepth), _owningMethod(other._owningMethod), _byteCodeInfo(other._byteCodeInfo), _isSyntheticHandler(other._isSyntheticHandler){}
TR_OpaqueClassBlock * _exceptionClass;
char * _exceptionClassNameChars;
int32_t _exceptionClassNameLength;
uint32_t _exceptionsCaught;
uint32_t _catchType;
TR_ResolvedMethod * _owningMethod;
TR_ByteCodeInfo _byteCodeInfo;
int32_t _handlerIndex;
uint8_t _inlineDepth;
bool _isSyntheticHandler; // indicate whether the exception handler is inserted by the compiler rather than existing in the source code
};
TR_CatchBlockExtension* getCatchBlockExtension() { return _catchBlockExtension; }
void setCatchBlockExtension(TR_CatchBlockExtension *extension) { _catchBlockExtension = extension; }
void setHandlerInfo(uint32_t c, uint8_t d, int32_t i, TR_ResolvedMethod * m, TR::Compilation *comp);
void setHandlerInfoWithOutBCInfo(uint32_t c, uint8_t d, int32_t i, TR_ResolvedMethod * m, TR::Compilation *comp); //also used for estimatecodesize dummy blocks
bool isCatchBlock();
uint32_t getCatchType();
uint8_t getInlineDepth();
int32_t getHandlerIndex();
TR_ByteCodeInfo getByteCodeInfo();
TR_OpaqueClassBlock * getExceptionClass();
char * getExceptionClassNameChars();
int32_t getExceptionClassNameLength();
void setExceptionClassName(char *c, int32_t length, TR::Compilation *comp);
TR_ResolvedMethod * getOwningMethod();
void setUnrollFactor(int factor) { _unrollFactor = factor; }
uint16_t getUnrollFactor() { return _unrollFactor; }
void setBlockSize(int32_t s) { _blockSize = s; }
int32_t getBlockSize() { return _blockSize; }
// TODO: These access members that are only used in J9EstimateCodeSize and
// should be deleted when the members are moved out.
void setBlockBCIndex(int32_t len) { _blockBCIndex = len; }
int32_t getBlockBCIndex() { return _blockBCIndex; }
void setJ9EstimateCodeSizeMethod(TR_ResolvedMethod *m) { _j9EstimateSizeMethod = m; }
TR_ResolvedMethod *getJ9EstimateCodeSizeMethod() { return _j9EstimateSizeMethod; }
TR::DebugCounterAggregation *getDebugCounters() { return _debugCounters; }
void setDebugCounters(TR::DebugCounterAggregation *debugCounters) { _debugCounters = debugCounters; }
// getNormalizedFrequency returns a value between 0 and 100. getGlobalNormalizedFrequency multiplies the
// normalizedfrequency by 10 for hot methods and by 100 for scorching methods.
//
int32_t getNormalizedFrequency(TR::CFG *);
int32_t getGlobalNormalizedFrequency(TR::CFG *);
bool verifyOSRInduceBlock(TR::Compilation *);
/**
* Field functions end
*/
/**
* Flag functions
*/
void setIsExtensionOfPreviousBlock(bool b = true);
bool isExtensionOfPreviousBlock();
void setIsCold(bool b = true) { _flags.set(_isCold, b); }
bool isCold() { return _flags.testAny(_isCold); }
void setIsSuperCold(bool v = true);
bool isSuperCold();
void setDoNotProfile() { _flags.set(_doNotProfile); }
bool doNotProfile() { return _flags.testAny(_doNotProfile); }
void setSpecializedDesyncCatchBlock() { _flags.set(_specializedDesyncCatchBlock); }
bool specializedDesyncCatchBlock() { return _flags.testAny(_specializedDesyncCatchBlock); }
void setFirstBlockInLoop() { _flags.set(_firstBlockInLoop); }
bool firstBlockInLoop() { return _flags.testAny(_firstBlockInLoop); }
void setBranchesBackwards() { _flags.set(_branchingBackwards); }
bool branchesBackwards() { return _flags.testAny(_branchingBackwards); }
void setIsSynchronizedHandler() { _flags.set(_isSynchronizedHandler); }
bool isSynchronizedHandler() { return _flags.testAny(_isSynchronizedHandler); }
void setIsPRECandidate(bool b) { _flags.set(_isPRECandidate, b); }
bool isPRECandidate() { return _flags.testAny(_isPRECandidate); }
void setIsAdded() { _flags.set(_isAdded); }
bool isAdded() { return _flags.testAny(_isAdded); }
void setIsOSRInduceBlock() { _flags.set(_isOSRInduceBlock); }
bool isOSRInduceBlock() { return _flags.testAny(_isOSRInduceBlock); }
void setIsOSRCodeBlock() { _flags.set(_isOSRCodeBlock); }
bool isOSRCodeBlock() { return _flags.testAny(_isOSRCodeBlock); }
void setIsOSRCatchBlock() { _flags.set(_isOSRCatchBlock); }
bool isOSRCatchBlock() { return _flags.testAny(_isOSRCatchBlock); }
void setIsCreatedAtCodeGen(bool b = true) { _flags.set(_createdAtCodeGen, b); }
bool isCreatedAtCodeGen() { return _flags.testAny(_createdAtCodeGen); }
void setHasCalls(bool b) { _flags.set(_hasCalls, b); }
bool hasCalls() { return _flags.testAny(_hasCalls); }
void setHasCallToSuperCold(bool b) { _flags.set(_hasCallToSuperCold, b); }
bool hasCallToSuperCold() { return _flags.testAny(_hasCallToSuperCold); }
void setIsSpecialized(bool b = true) { _flags.set(_isSpecialized, b); }
bool isSpecialized() { return _flags.testAny(_isSpecialized); }
bool isLoopInvariantBlock() { return _flags.testAny(_isLoopInvariantBlock); }
void setAsLoopInvariantBlock(bool b) { _flags.set(_isLoopInvariantBlock, b); }
bool isCreatedByVersioning() { return _flags.testAny(_isCreatedByVersioning); }
void setCreatedByVersioning(bool b) { _flags.set(_isCreatedByVersioning, b); }
bool isEntryOfShortRunningLoop() { return _flags.testAny(_isEntryOfShortRunningLoop); }
void setIsEntryOfShortRunningLoop() { _flags.set(_isEntryOfShortRunningLoop, true); }
bool wasHeaderOfCanonicalizedLoop() { return _flags.testAny(_wasHeaderOfCanonicalizedLoop); }
void setWasHeaderOfCanonicalizedLoop(bool b) { _flags.set(_wasHeaderOfCanonicalizedLoop, b); }
bool isLastWarmBlock() { return _flags.testAny(_isLastWarmBlock); }
void setIsLastWarmBlock(bool b = true) { _flags.set(_isLastWarmBlock, b); }
bool isSyntheticHandler() { return _catchBlockExtension && _catchBlockExtension->_isSyntheticHandler; }
void setIsSyntheticHandler();
enum partialFlags // Stored in lowest 8 bits of _moreflags
{
_unsanitizeable = 0x00000001,
_containsCall = 0x00000002,
_restartBlock = 0x00000004,
_partialInlineBlock = 0x00000008,
_endBlock = 0x00000010,
_difficultBlock = 0x00000020,
// Available = 0x00000040,
// Available = 0x00000080
};
flags16_t getPartialFlags() {return flags16_t(_moreflags.getValue(0xFF));} // J9
void setIsUnsanitizeable(bool b = true) { _moreflags.set(_unsanitizeable,b); } // J9
bool isUnsanitizeable() { return _moreflags.testAny(_unsanitizeable); }
void setContainsCall(bool b = true) { _moreflags.set(_containsCall,b); }
bool containsCall() { return _moreflags.testAny(_containsCall); }
void setRestartBlock(bool b = true) { _moreflags.set(_restartBlock,b); } // J9
bool isRestartBlock() { return _moreflags.testAny(_restartBlock); }
void setPartialInlineBlock(bool b = true) { _moreflags.set(_partialInlineBlock,b); }
bool isPartialInlineBlock() { return _moreflags.testAny(_partialInlineBlock); }
void setIsEndBlock(bool b = true) { _moreflags.set(_endBlock,b); }
bool isEndBlock() { return _moreflags.testAny(_endBlock); }
void setIsDifficultBlock(bool b = true) { _moreflags.set(_difficultBlock,b); }
bool isDifficultBlock() { return _moreflags.testAny(_difficultBlock); }
/**
* Flag functions end
*/
private:
void init(TR::TreeTop *entry, TR::TreeTop *exit);
void uncommonNodesBetweenBlocks(TR::Compilation *, TR::Block *, TR::ResolvedMethodSymbol *methodSymbol = NULL);
TR::Block * splitBlockAndAddConditional(TR::TreeTop *tree,
TR::TreeTop *compareTree,
TR::CFG *cfg,
bool newBlockShouldExtend);
void ensureCatchBlockExtensionExists(TR::Compilation *comp);
struct StandardException
{
int32_t length;
const char *name;
uint32_t exceptions;
};
static StandardException _standardExceptions[];
enum // flag bits for _flags
{
_isExtensionOfPreviousBlock = 0x00000001,
_isCold = 0x00000002,
_isSuperCold = 0x00040000, // User specified cold/hotness by pragma or @ASSERT for PLX
// AVAILABLE = 0x00000080,
_doNotProfile = 0x00000004,
_specializedDesyncCatchBlock = 0x00000008,
_firstBlockInLoop = 0x00000020,
_branchingBackwards = 0x00000040,
_isSynchronizedHandler = 0x00000100,
// Available = 0x00000400,
_isPRECandidate = 0x00000800,
_isAdded = 0x00001000,
_isOSRInduceBlock = 0x00002000,
_isOSRCodeBlock = 0x00004000,
_isOSRCatchBlock = 0x00008000,
_createdAtCodeGen = 0x00080000,
_hasCalls = 0x00200000,
_hasCallToSuperCold = 0x00400000,
_isSpecialized = 0x00800000, // Block has been specialized by loop specializer
_isLoopInvariantBlock = 0x01000000,
_isCreatedByVersioning = 0x02000000,
_isEntryOfShortRunningLoop = 0x04000000,
_wasHeaderOfCanonicalizedLoop = 0x08000000,
_isLastWarmBlock = 0x10000000,
};
TR::TreeTop * _pEntry;
TR::TreeTop * _pExit;
TR_BitVector * _liveLocals;
TR_BlockStructure * _pStructureOf;
// TODO: This member is only used during GRA and should be moved out.
TR_Array<TR::GlobalRegister> * _globalRegisters;
InstructionBoundaries _instructionBoundaries;
TR_LinkHead<InstructionBoundaries> _snippetBoundaries;
TR::Instruction * _firstInstruction;
TR::Instruction * _lastInstruction;
TR_CatchBlockExtension * _catchBlockExtension;
uint16_t _unrollFactor;
// TODO: These members are only used in J9EstimateCodeSize and should be moved out.
int32_t _blockSize;
int32_t _blockBCIndex;
TR_ResolvedMethod * _j9EstimateSizeMethod;
TR::DebugCounterAggregation * _debugCounters;
flags32_t _flags;
flags32_t _moreflags;
};
}
struct BlockMapper : TR_Link<BlockMapper>
{
BlockMapper(TR::Block * f, TR::Block * t) : _from(f), _to(t) { }
TR::Block * _from;
TR::Block * _to;
};
class TR_BlockCloner
{
public:
TR_ALLOC(TR_Memory::BlockCloner)
TR_BlockCloner( TR::CFG * cfg, bool cloneBranchesExactly = false, bool cloneSuccessorsOfLastBlock = false)
: _cfg(cfg),
_cloneBranchesExactly(cloneBranchesExactly),
_cloneSuccessorsOfLastBlock(cloneSuccessorsOfLastBlock)
{ }
TR::Block * cloneBlocks(TR::Block * firstBlock, TR::Block * lastBlock);
TR::Block * cloneBlocks(TR_LinkHeadAndTail<BlockMapper>* bMap);
TR::Block * getLastClonedBlock() { return _lastToBlock; }
TR::Block * getToBlock(TR::Block *);
void replaceTrees(TR::TreeTop *);
private:
TR::Node * cloneNode(TR::Node *);
TR::Block * doBlockClone(TR_LinkHeadAndTail<BlockMapper>* bMap);
TR::CFG * _cfg;
TR::Block * _lastToBlock;
TR_LinkHeadAndTail<BlockMapper> _blockMappings;
TR_NodeMappings _nodeMappings;
bool _cloneBranchesExactly;
bool _cloneSuccessorsOfLastBlock;
};
class TR_ExtendedBlockSuccessorIterator
{
public:
TR_ALLOC(TR_Memory::ExtendedBlockSuccessorIterator)
TR_ExtendedBlockSuccessorIterator(TR::Block * b, TR::CFG *cfg)
: _firstBlock(b), _cfg(cfg)
{ }
TR::Block * getFirst();
TR::Block * getNext();
private:
void setCurrentBlock(TR::Block * b);
TR::Block * _firstBlock;
TR::Block * _nextBlockInExtendedBlock;
TR::CFG * _cfg;
TR::CFGEdgeList::iterator _iterator;
TR::CFGEdgeList* _list;
};
#endif