-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathStructure.hpp
679 lines (537 loc) · 26.2 KB
/
Structure.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
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
/*******************************************************************************
* Copyright (c) 2000, 2019 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
*******************************************************************************/
#ifndef STRUCTURE_INCL
#define STRUCTURE_INCL
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include "env/FrontEnd.hpp"
#include "compile/Compilation.hpp"
#include "env/TRMemory.hpp"
#include "il/Block.hpp"
#include "il/DataTypes.hpp"
#include "il/Node.hpp"
#include "infra/Assert.hpp"
#include "infra/BitVector.hpp"
#include "infra/Cfg.hpp"
#include "infra/Flags.hpp"
#include "infra/Link.hpp"
#include "infra/List.hpp"
#include "infra/CfgEdge.hpp"
#include "infra/CfgNode.hpp"
#include "infra/vector.hpp"
#include "optimizer/VPConstraint.hpp"
class TR_BasicInductionVariable;
class TR_BlockStructure;
class TR_DataFlowAnalysis;
class TR_LocalTransparency;
class TR_PrimaryInductionVariable;
class TR_RegionStructure;
class TR_RegisterCandidate;
class TR_StructureSubGraphNode;
namespace TR { class VPConstraint; }
namespace TR { class RegisterMappedSymbol; }
namespace TR { class SymbolReference; }
class TR_Structure
{
public:
TR_ALLOC(TR_Memory::Structure)
enum Kind
{
Blank = 0,
Block = 1,
Region = 2
};
TR_Structure(TR::Compilation * c, int32_t index)
: _comp(c), _nodeIndex(index), _parent(NULL), _weight(-1), _versionedStructure(NULL), _trMemory(c->trMemory()), _maxNestingDepth(0), _nestingDepth(0), _analyzedBefore(false), _containsImproperRegion(false)
{
}
TR::Compilation * comp() { return _comp; }
TR::CFG *cfg() { return _comp->getFlowGraph(); }
TR_Memory * trMemory() { return _trMemory; }
TR_StackMemory trStackMemory() { return _trMemory; }
TR_HeapMemory trHeapMemory() { return _trMemory; }
TR_PersistentMemory * trPersistentMemory() { return _trMemory->trPersistentMemory(); }
virtual Kind getKind();
virtual TR_BlockStructure *asBlock() { return NULL; }
virtual TR_RegionStructure *asRegion() { return NULL; }
virtual TR::Block *getEntryBlock() = 0;
// TR_Structure *getParent() {return _parent;}
TR_RegionStructure *getParent() { return _parent; }
TR_RegionStructure *setParent(TR_RegionStructure *b) {return (_parent = b);}
TR_StructureSubGraphNode * getSubGraphNode() {return _graphNode;}
void setSubGraphNode(TR_StructureSubGraphNode * node) {_graphNode = node;}
int32_t getNumber() {return _nodeIndex;}
void setNumber(int32_t n) {_nodeIndex = n;}
// Does this structure contain the other? If the "commonParent" is known it can
// be specified to make the search faster.
//
bool contains(TR_Structure *other, TR_Structure *commonParent = NULL);
TR_RegionStructure *getContainingLoop();
// Finds the common parent of this and other
// note that if A contains B, then the common parent is parent(A)
//
TR_RegionStructure *findCommonParent(TR_Structure *other, TR::CFG *cfg);
// Perform the data flow analysis on the structure.
// Return true if the analysis info has changed as a result of analysis.
//
virtual bool doDataFlowAnalysis(TR_DataFlowAnalysis *, bool checkForChanges) = 0;
virtual bool changeContinueLoopsToNestedLoops(TR_RegionStructure *) = 0;
int32_t getNumberOfLoops();
virtual void checkStructure(TR_BitVector *) = 0;
void mergeBlocks(TR::Block *first, TR::Block *second);
virtual void mergeInto(TR::Block *first, TR::Block *second);
virtual void removeMergedBlock(TR::Block *merged, TR::Block *mergedInto);
virtual void renumber(int32_t num) = 0;
virtual bool renumberRecursively(int32_t origNum, int32_t num) = 0;
virtual void resetVisitCounts(vcount_t) = 0;
// Remove an edge between the given structures. The "to" structure is part
// of this structure; the "from" structure may or may not be.
//
virtual void removeEdge(TR_Structure *from, TR_Structure *to) = 0;
virtual void addEdge(TR::CFGEdge *edge, bool isExceptionEdge);
virtual void addExternalEdge(TR_Structure *from, int32_t toNumber, bool isExceptionEdge) = 0;
// Replace one of the sub-structures of this structure by another.
//
virtual void replacePart(TR_Structure *from, TR_Structure *to) = 0;
// Analysis info can be used by any data flow analysis to store information
// relevant to this structure. It is not necessarily valid at the start of
// an analysis.
//
void *getAnalysisInfo() {return _analysisInfo;}
void setAnalysisInfo(void *newInfo) { _analysisInfo = newInfo; }
virtual void clearAnalysisInfo() = 0;
virtual void resetAnalysisInfo() = 0;
virtual void resetAnalyzedStatus() = 0;
virtual bool markStructuresWithImproperRegions() = 0;
virtual void collectExitBlocks(List<TR::Block> *exitBlocks, List<TR::CFGEdge> *exitEdges = NULL) = 0;
virtual TR_Structure *cloneStructure(TR::Block **, TR_StructureSubGraphNode **, List<TR_Structure> *, List<TR_Structure> *) = 0;
virtual void cloneStructureEdges(TR::Block **) = 0;
virtual void collectCFGEdgesTo(int32_t, List<TR::CFGEdge> *) = 0;
virtual int32_t getMaxNestingDepth(int32_t *, int32_t *);
void setNestingDepths(int32_t *);
void setAnyCyclicRegionNestingDepths(int32_t *);
void calculateFrequencyOfExecution(int32_t *);
void setConditionalityWeight(int32_t *);
void adjustWeightForBranches(TR_StructureSubGraphNode *, TR_StructureSubGraphNode *, int32_t *);
TR_StructureSubGraphNode *findNodeInHierarchy(TR_RegionStructure *, int32_t);
void setWeight(int32_t w) {_weight = w;}
int32_t getWeight() {return _weight;}
// Determine if this region contains improper region
//
virtual bool containsImproperRegion() { return _containsImproperRegion; }
virtual void setContainsImproperRegion(bool b) { _containsImproperRegion = b; }
bool hasBeenAnalyzedBefore() { return _analyzedBefore; }
void setAnalyzedStatus(bool analyzedStatus) { _analyzedBefore = analyzedStatus; }
int32_t getNestingDepth() { return _nestingDepth; }
void setNestingDepth(int16_t f)
{
if (f > SHRT_MAX-1)
{
TR_ASSERT(0, "nesting depth must be less than or equal to SHRT_MAX-1");
comp()->failCompilation<TR::CompilationException>("nesting depth must be less than or equal to SHRT_MAX-1");
}
_nestingDepth = f;
}
int32_t getAnyCyclicRegionNestingDepth() { return _anyCyclicRegionNestingDepth; }
void setAnyCyclicRegionNestingDepth(int16_t f)
{
if (f > SHRT_MAX-1)
{
TR_ASSERT(0, "nesting depth must be less than or equal to SHRT_MAX-1");
comp()->failCompilation<TR::CompilationException>("nesting depth must be less than or equal to SHRT_MAX-1");
}
_anyCyclicRegionNestingDepth = f;
}
int32_t getMaxNestingDepth()
{
return _maxNestingDepth;
}
void setMaxNestingDepth(int16_t f)
{
if (f > SHRT_MAX-1)
{
TR_ASSERT(0, "max nesting depth must be less than or equal to SHRT_MAX-1");
comp()->failCompilation<TR::CompilationException>("max nesting depth must be less than or equal to SHRT_MAX-1");
}
_maxNestingDepth = f;
}
virtual void hoistInvariantsOutOfNestedLoops(TR_LocalTransparency *, TR_BitVector **, bool, TR_BlockStructure *, TR_RegionStructure *, int32_t) = 0;
virtual bool isExpressionTransparentIn(int32_t, TR_LocalTransparency *) = 0;
// Remove an outgoing edge from this structure to another. The "from" structure
// is part of this structure; the "to" structure is not.
// This method should only be called by "removeEdge" methods and by recursion.
// Return value is:
// EDGES_STILL_EXIST if there are still edges from the "from"
// structure to the "to" structure.
// NO_MORE_EDGES_EXIST if there are now no edges from the "from"
// structure to the "to" structure and the edge
// removed was an explicit edge.
//
#define EDGES_STILL_EXIST 0
#define NO_MORE_EDGES_EXIST 1
//
virtual int removeExternalEdgeTo(TR_Structure *from, int32_t toNumber) = 0;
public:
virtual List<TR::Block> *getBlocks(List<TR::Block> *) = 0;
virtual List<TR::Block> *getBlocks(List<TR::Block> *, vcount_t) = 0;
int32_t _nodeIndex;
protected:
TR_Structure *_versionedStructure;
private:
TR::Compilation * _comp;
TR_Memory * _trMemory;
TR_StructureSubGraphNode * _graphNode;
int32_t _weight;
TR_RegionStructure * _parent;
void * _analysisInfo;
bool _containsImproperRegion;
bool _analyzedBefore;
int16_t _nestingDepth;
int16_t _maxNestingDepth;
int16_t _anyCyclicRegionNestingDepth;
};
// **********************************************************************
//
// A node of a region's sub-graph.
// For internal nodes the node references the corresponding child structure.
// For exit nodes only the node number is valid, there is no structure
// referenced from the node.
//
// Pseudo-safe downcast from a CFG node to a TR_StructureSubGraphNode
//
static TR_StructureSubGraphNode *toStructureSubGraphNode(TR::CFGNode *node)
{
#if DEBUG
TR_ASSERT(node->asStructureSubGraphNode() != NULL,"Bad downcast from TR::CFGNode to TR_StructureSubGraphNode");
#endif
return (TR_StructureSubGraphNode *)node;
}
class TR_StructureSubGraphNode : public TR::CFGNode
{
public:
// Create a node for a concrete structure
//
TR_StructureSubGraphNode(TR_Structure *s)
: TR::CFGNode(s->getNumber(), s->cfg()->structureRegion()), _structure(s) {s->setSubGraphNode(this);}
TR_StructureSubGraphNode(int32_t n, TR::Region ®ion)
: TR::CFGNode(n, region), _structure(0) {}
static TR_StructureSubGraphNode *create(int32_t num, TR_RegionStructure *region);
TR_Structure *getStructure() {return _structure;}
void setStructure(TR_Structure *s) {_structure = s; if (s) {setNumber(s->getNumber()); s->setSubGraphNode(this);}}
virtual TR_StructureSubGraphNode *asStructureSubGraphNode();
private:
TR_Structure *_structure;
};
// **********************************************************************
//
// A Basic Block structure. This represents a leaf node of the control
// tree.
//
class TR_BlockStructure : public TR_Structure
{
public:
TR_BlockStructure(TR::Compilation * comp, int32_t index, TR::Block *b);
virtual Kind getKind();
virtual TR_BlockStructure *asBlock() {return this;}
TR::Block *getBlock() {return _block;}
TR::Block *setBlock(TR::Block *b);// {return (_block = b);}
virtual bool doDataFlowAnalysis(TR_DataFlowAnalysis *, bool checkForChanges);
virtual void resetAnalysisInfo();
virtual void resetAnalyzedStatus();
virtual bool markStructuresWithImproperRegions();
virtual void collectExitBlocks(List<TR::Block> *exitBlocks, List<TR::CFGEdge> *exitEdges = NULL);
virtual void checkStructure(TR_BitVector *);
virtual void renumber(int32_t num);
virtual bool renumberRecursively(int32_t origNum, int32_t num);
virtual void resetVisitCounts(vcount_t num);
virtual bool changeContinueLoopsToNestedLoops(TR_RegionStructure *);
virtual void removeEdge(TR_Structure *from, TR_Structure *to);
virtual void addExternalEdge(TR_Structure *from, int32_t toNumber, bool isExceptionEdge);
virtual void replacePart(TR_Structure *from, TR_Structure *to);
virtual int removeExternalEdgeTo(TR_Structure *from, int32_t toNumber);
virtual void clearAnalysisInfo();
virtual void collectCFGEdgesTo(int32_t, List<TR::CFGEdge> *);
virtual TR_Structure *cloneStructure(TR::Block **, TR_StructureSubGraphNode **, List<TR_Structure> *, List<TR_Structure> *);
virtual void cloneStructureEdges(TR::Block **);
virtual void hoistInvariantsOutOfNestedLoops(TR_LocalTransparency *, TR_BitVector **, bool, TR_BlockStructure *, TR_RegionStructure *, int32_t);
virtual bool isExpressionTransparentIn(int32_t, TR_LocalTransparency *);
virtual List<TR::Block> *getBlocks(List<TR::Block> *);
bool isLoopInvariantBlock() { return _block->isLoopInvariantBlock(); }
void setAsLoopInvariantBlock(bool b) { _block->setAsLoopInvariantBlock(b); }
bool isCreatedByVersioning() { return _block->isCreatedByVersioning(); }
void setCreatedByVersioning(bool b) { _block->setCreatedByVersioning(b); }
bool isEntryOfShortRunningLoop() { return _block->isEntryOfShortRunningLoop(); }
void setIsEntryOfShortRunningLoop() { _block->setIsEntryOfShortRunningLoop(); }
bool wasHeaderOfCanonicalizedLoop() { return _block->wasHeaderOfCanonicalizedLoop(); }
void setWasHeaderOfCanonicalizedLoop(bool b) { _block->setWasHeaderOfCanonicalizedLoop(b); }
virtual TR::Block *getEntryBlock() { return getBlock(); }
TR_BlockStructure *getDuplicatedBlock()
{
if (_versionedStructure)
return _versionedStructure->asBlock();
return NULL;
}
void setDuplicatedBlock(TR_BlockStructure *r) {_versionedStructure = r;}
public:
virtual List<TR::Block> *getBlocks(List<TR::Block> *, vcount_t);
private:
TR::Block *_block;
};
// **********************************************************************
//
// Information about an induction variable for a natural loop
//
class TR_InductionVariable : public TR_Link<TR_InductionVariable>
{
public:
TR_InductionVariable() {}
TR_InductionVariable(TR::RegisterMappedSymbol *s, TR::VPConstraint *entry, TR::VPConstraint *exit, TR::VPConstraint *incr, TR_YesNoMaybe isSigned)
: _local(s), _isSigned(isSigned)
{
setEntry(entry);
setExit(exit);
setIncr(incr);
}
TR::RegisterMappedSymbol *getLocal() {return _local;}
void setLocal(TR::RegisterMappedSymbol *s) { _local = s;}
TR::VPConstraint *getEntry() {return _entry;}
TR::VPConstraint *getIncr() {return _incr;}
TR::VPConstraint *getExit() {return _exit;}
void setEntry(TR::VPConstraint *entry) { _entry = entry; }
void setExit(TR::VPConstraint *exit) { _exit = exit; }
void setIncr(TR::VPConstraint *incr) { _incr = incr; }
TR_YesNoMaybe isSigned() { return _isSigned; }
private:
TR::RegisterMappedSymbol *_local;
TR::VPConstraint *_entry;
TR::VPConstraint *_incr;
TR::VPConstraint *_exit;
TR_YesNoMaybe _isSigned; //FIXME// CRITICAL Value Propgation should set this up.. right now this is not being done
};
// **********************************************************************
//
// A Region structure. This represents structures that have sub-graphs.
// There is always a single entry node that dominates the rest of the sub-graph.
//
//
class TR_RegionStructure : public TR_Structure
{
public:
typedef TR::vector<TR_StructureSubGraphNode *, TR::Region&> SubNodeList;
TR_RegionStructure(TR::Compilation * c, int32_t index)
: TR_Structure(c, index), _invariantSymbols(NULL), _blocksAtSameNestingLevel(NULL), _piv(NULL),
_basicIVs(c->getFlowGraph()->structureRegion()), _exitEdges(c->getFlowGraph()->structureRegion()),
_subNodes(c->getFlowGraph()->structureRegion()), _invariantExpressions(NULL)
{
}
virtual Kind getKind();
virtual TR_RegionStructure *asRegion() {return this;}
TR_StructureSubGraphNode *getEntry() {return _entryNode;}
TR_StructureSubGraphNode *setEntry(TR_StructureSubGraphNode *entry)
{
_entryNode = entry;
entry->getStructure()->setParent(this);
TR::Block * entryBlock = getEntryBlock();
if (entryBlock != NULL)
_unrollFactor = getEntryBlock()->getUnrollFactor();
return entry;
}
// add a new exit edge
// (or modify an existing TR::CFGEdge and add it to the list of exit edges)
//
TR::CFGEdge *addExitEdge(TR_StructureSubGraphNode *from, int32_t to, bool isExceptionEdge = false, TR::CFGEdge *origEdge = 0);
List<TR::CFGEdge>& getExitEdges() {return _exitEdges;}
TR_StructureSubGraphNode *findNodeInHierarchy(int32_t num);
virtual bool doDataFlowAnalysis(TR_DataFlowAnalysis *, bool checkForChanges);
virtual void resetAnalysisInfo();
virtual void resetAnalyzedStatus();
virtual bool markStructuresWithImproperRegions();
virtual void collectExitBlocks(List<TR::Block> *exitBlocks, List<TR::CFGEdge> *exitEdges = NULL);
virtual void checkStructure(TR_BitVector *);
virtual void mergeInto(TR::Block *first, TR::Block *second);
virtual void removeMergedBlock(TR::Block *merged, TR::Block *mergedInto);
virtual void renumber(int32_t num);
virtual bool renumberRecursively(int32_t origNum, int32_t num);
virtual void resetVisitCounts(vcount_t num);
virtual bool changeContinueLoopsToNestedLoops(TR_RegionStructure *);
virtual void removeEdge(TR_Structure *from, TR_Structure *to);
virtual void addEdge(TR::CFGEdge *edge, bool isExceptionEdge);
virtual void addExternalEdge(TR_Structure *from, int32_t toNumber, bool isExceptionEdge);
virtual void replacePart(TR_Structure *from, TR_Structure *to);
virtual int removeExternalEdgeTo(TR_Structure *from, int32_t toNumber);
virtual void clearAnalysisInfo();
virtual TR_Structure *cloneStructure(TR::Block **, TR_StructureSubGraphNode **, List<TR_Structure> *, List<TR_Structure> *);
virtual void cloneStructureEdges(TR::Block **);
virtual List<TR::Block> *getBlocks(List<TR::Block> *);
virtual void collectCFGEdgesTo(int32_t, List<TR::CFGEdge> *);
void replaceExitPart(int32_t fromNumber, int32_t toNumber);
static void extractUnconditionalExits(TR::Compilation * const comp, const TR::list<TR::Block*, TR::Region&> &blocks);
// Collapse this region into its parent
//
void collapseIntoParent();
// Determine if this region contains internal cycles
//
bool containsInternalCycles() {return _regionFlags.testAny(_containsInternalCycles);}
void setContainsInternalCycles(bool b) {_regionFlags.set(_containsInternalCycles, b);}
// Determine if this is a natural loop region, i.e a region with back-edges
// to the entry node
//
bool isNaturalLoop() {return !containsInternalCycles() && !_entryNode->getPredecessors().empty();}
TR_RegionStructure *getVersionedLoop()
{
if (_versionedStructure)
return _versionedStructure->asRegion();
return NULL;
}
void setVersionedLoop(TR_RegionStructure *r) {_versionedStructure = r;}
bool containsOnlyAcyclicRegions();
// List of induction variables for a natural loop
//
TR_InductionVariable *getFirstInductionVariable() {return _inductionVariables.getFirst();}
void addInductionVariable(TR_InductionVariable *v) {_inductionVariables.add(v);}
void addAfterInductionVariable(TR_InductionVariable *prev, TR_InductionVariable *v) {_inductionVariables.insertAfter(prev, v);}
void clearInductionVariables() {_inductionVariables.setFirst(NULL);}
TR_InductionVariable* findMatchingIV(TR::SymbolReference *symRef);
TR_PrimaryInductionVariable *getPrimaryInductionVariable() { return _piv; }
void setPrimaryInductionVariable(TR_PrimaryInductionVariable *piv) { _piv = piv; }
void addInductionVariable(TR_BasicInductionVariable *biv) { _basicIVs.add(biv); }
List<TR_BasicInductionVariable> &getBasicInductionVariables() { return _basicIVs; }
bool hasExceptionOutEdges();
// Determine if this is an acyclic region
//
bool isAcyclic() {return !containsInternalCycles() && _entryNode->getPredecessors().empty();}
bool isExitEdge(TR::CFGEdge * exitEdge)
{
TR_StructureSubGraphNode *toNode = exitEdge->getTo()->asStructureSubGraphNode();
if (toNode->getStructure())
return false;
return true;
/*
ListIterator<TR::CFGEdge> ei(&getExitEdges());
for (TR::CFGEdge * edge = ei.getCurrent(); edge; edge = ei.getNext())
if (edge == exitEdge)
return true;
return false;
*/
}
void cleanupAfterEdgeRemoval(TR::CFGNode *);
void cleanupAfterNodeRemoval();
bool isCanonicalizedLoop() {return _regionFlags.testAny(_isCanonicalizedLoop);}
void setAsCanonicalizedLoop(bool b) {_regionFlags.set(_isCanonicalizedLoop, b);}
bool isInvertible() {return _regionFlags.testAny(_isInvertible);}
void setAsInvertible(bool b) {_regionFlags.set(_isInvertible, b);}
void computeInvariantSymbols();
void updateInvariantSymbols(TR::Node *, vcount_t);
void computeInvariantExpressions();
void updateInvariantExpressions(TR::Node *, vcount_t);
void resetInvariance();
bool isExprInvariant(TR::Node *, bool usePrecomputed = true);
bool isExprTreeInvariant(TR::Node *);
bool isSubtreeInvariant(TR::Node *, vcount_t);
TR_BitVector *getInvariantExpressions() { return _invariantExpressions; }
void setExprInvariant(TR::Node *expr) { TR_ASSERT(_invariantExpressions != NULL, "assertion failure"); _invariantExpressions->set(expr->getGlobalIndex());}
void resetExprInvariant(TR::Node *expr) {TR_ASSERT(_invariantExpressions != NULL, "assertion failure"); _invariantExpressions->reset(expr->getGlobalIndex());}
bool isSymbolRefInvariant(TR::SymbolReference *);
void addGlobalRegisterCandidateToExits(TR_RegisterCandidate *);
void addSubNode(TR_StructureSubGraphNode *subNode);
void removeSubNode(TR_StructureSubGraphNode *subNode);
uint32_t numSubNodes() {return _subNodes.size();}
// Find the subnode numbered 'number' in the current region
// Returns null, if none of the subnodes match
//
TR_StructureSubGraphNode *findSubNodeInRegion(int32_t number);
virtual int32_t getMaxNestingDepth(int32_t *, int32_t *);
virtual void hoistInvariantsOutOfNestedLoops(TR_LocalTransparency *, TR_BitVector **, bool, TR_BlockStructure *, TR_RegionStructure *, int32_t);
virtual bool isExpressionTransparentIn(int32_t, TR_LocalTransparency *);
TR_BitVector *getBlocksAtSameNestingLevel() {return _blocksAtSameNestingLevel;}
void setBlocksAtSameNestingLevel(TR_BitVector *blocksInLoop) {_blocksAtSameNestingLevel = blocksInLoop;}
virtual TR::Block *getEntryBlock()
{
TR_RegionStructure *region = _entryNode->getStructure()->asRegion();
if (!region)
return _entryNode->getStructure()->asBlock()->getBlock();
return region->getEntryBlock();
}
float getFrequencyEntryFactor() { return _frequencyEntryFactor; }
void setFrequencyEntryFactor(float factor) { _frequencyEntryFactor = factor; }
uint16_t getUnrollFactor() {return _unrollFactor;}
void setUnrollFactor(int factor) {_unrollFactor = factor;}
bool canBeUnrolled() {return _unrollFactor != 1;}
public:
virtual List<TR::Block> *getBlocks(List<TR::Block> *, vcount_t);
enum // flags
{
_containsInternalCycles = 0x01,
_isCanonicalizedLoop = 0x02,
_isInvertible = 0x04
};
SubNodeList::iterator begin() { return _subNodes.begin(); }
SubNodeList::iterator end() { return _subNodes.end(); }
// The Cursor provides an immutable view of the elements of the region unlike the normal iterators
// above, note that there is a non-trivial cost to this Cursor because it must copy the structure's
// sublist into itself for the purposes of isolation
class Cursor
{
public:
Cursor(TR_RegionStructure & region): _nodes(region._subNodes), _iter(_nodes.begin()) { }
TR_StructureSubGraphNode * getCurrent() { return (_iter != _nodes.end()) ? *_iter : NULL; }
TR_StructureSubGraphNode * getNext() { _iter++; return getCurrent(); }
TR_StructureSubGraphNode * getFirst() { return getCurrent(); }
void reset() { _iter = _nodes.begin(); }
private:
SubNodeList _nodes;
SubNodeList::iterator _iter;
};
friend class Cursor;
private:
friend class TR_RegionAnalysis;
friend class TR_LoopUnroller;
void addExitEdge(TR::CFGEdge *edge)
{
TR_ASSERT(toStructureSubGraphNode(edge->getTo())->getStructure() == NULL,
"Region exit edge must not have structure");
_exitEdges.add(edge);
}
void checkForInternalCycles();
void removeEdge(TR::CFGEdge *edge, bool isExitEdge);
void removeEdgeWithoutCleanup(TR::CFGEdge *edge, bool isExitEdge);
void removeSubNodeWithoutCleanup(TR_StructureSubGraphNode *subNode);
// Find a subnode with the given structure. As a precondition, such a node
// must exist. This method returns non-null.
TR_StructureSubGraphNode *subNodeFromStructure(TR_Structure*);
// Implementation of extractUnconditionalExits(). Class definition is private
// to Structure.cpp
class ExitExtraction;
TR_StructureSubGraphNode *_entryNode;
TR_BitVector *_invariantSymbols;
TR_BitVector *_blocksAtSameNestingLevel;
List<TR::CFGEdge> _exitEdges;
SubNodeList _subNodes;
TR_LinkHead<TR_InductionVariable> _inductionVariables;
TR_PrimaryInductionVariable *_piv;
List<TR_BasicInductionVariable> _basicIVs;
flags8_t _regionFlags;
float _frequencyEntryFactor;
TR_BitVector *_invariantExpressions;
uint16_t _unrollFactor;
};
#endif