Skip to content

Commit ddbb837

Browse files
[NFC][ScopBuilder] Move addRecordedAssumption to ScopBuilder
Scope of changes: 1) Moved addRecordedAssumptions to ScopBuilder. 2) Moved Assumption struct outside Scop class. 3) Refactored addRecordedAssumptions function. Replaced while loop by for range loop. 4) Added function to clear processed Assumptions. Differential Revision: https://reviews.llvm.org/D63572 llvm-svn: 366260
1 parent 12154ee commit ddbb837

File tree

4 files changed

+67
-56
lines changed

4 files changed

+67
-56
lines changed

polly/include/polly/ScopBuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ class ScopBuilder {
327327
BasicBlock *IncomingBlock, Value *IncomingValue,
328328
bool IsExitBlock);
329329

330+
/// Add all recorded assumptions to the assumed context.
331+
void addRecordedAssumptions();
332+
330333
/// Create a MemoryAccess for reading the value of a phi.
331334
///
332335
/// The modeling assumes that all incoming blocks write their incoming value

polly/include/polly/ScopInfo.h

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,24 @@ class ScopStmt {
16241624
/// Print ScopStmt S to raw_ostream OS.
16251625
raw_ostream &operator<<(raw_ostream &OS, const ScopStmt &S);
16261626

1627+
/// Helper struct to remember assumptions.
1628+
struct Assumption {
1629+
/// The kind of the assumption (e.g., WRAPPING).
1630+
AssumptionKind Kind;
1631+
1632+
/// Flag to distinguish assumptions and restrictions.
1633+
AssumptionSign Sign;
1634+
1635+
/// The valid/invalid context if this is an assumption/restriction.
1636+
isl::set Set;
1637+
1638+
/// The location that caused this assumption.
1639+
DebugLoc Loc;
1640+
1641+
/// An optional block whose domain can simplify the assumption.
1642+
BasicBlock *BB;
1643+
};
1644+
16271645
/// Static Control Part
16281646
///
16291647
/// A Scop is the polyhedral representation of a control flow region detected
@@ -1782,24 +1800,7 @@ class Scop {
17821800
/// need to be "false". Otherwise they behave the same.
17831801
isl::set InvalidContext;
17841802

1785-
/// Helper struct to remember assumptions.
1786-
struct Assumption {
1787-
/// The kind of the assumption (e.g., WRAPPING).
1788-
AssumptionKind Kind;
1789-
1790-
/// Flag to distinguish assumptions and restrictions.
1791-
AssumptionSign Sign;
1792-
1793-
/// The valid/invalid context if this is an assumption/restriction.
1794-
isl::set Set;
1795-
1796-
/// The location that caused this assumption.
1797-
DebugLoc Loc;
1798-
1799-
/// An optional block whose domain can simplify the assumption.
1800-
BasicBlock *BB;
1801-
};
1802-
1803+
using RecordedAssumptionsTy = SmallVector<Assumption, 8>;
18031804
/// Collection to hold taken assumptions.
18041805
///
18051806
/// There are two reasons why we want to record assumptions first before we
@@ -1810,7 +1811,7 @@ class Scop {
18101811
/// construction (basically after we know all parameters), thus the user
18111812
/// might see overly complicated assumptions to be taken while they will
18121813
/// only be simplified later on.
1813-
SmallVector<Assumption, 8> RecordedAssumptions;
1814+
RecordedAssumptionsTy RecordedAssumptions;
18141815

18151816
/// The schedule of the SCoP
18161817
///
@@ -2338,6 +2339,12 @@ class Scop {
23382339
InvariantEquivClasses.end());
23392340
}
23402341

2342+
/// Return an iterator range containing hold assumptions.
2343+
iterator_range<RecordedAssumptionsTy::const_iterator>
2344+
recorded_assumptions() const {
2345+
return make_range(RecordedAssumptions.begin(), RecordedAssumptions.end());
2346+
}
2347+
23412348
/// Return whether this scop is empty, i.e. contains no statements that
23422349
/// could be executed.
23432350
bool isEmpty() const { return Stmts.empty(); }
@@ -2494,6 +2501,9 @@ class Scop {
24942501
/// @returns True if the optimized SCoP can be executed.
24952502
bool hasFeasibleRuntimeContext() const;
24962503

2504+
/// Clear assumptions which have been already processed.
2505+
void clearRecordedAssumptions() { return RecordedAssumptions.clear(); }
2506+
24972507
/// Check if the assumption in @p Set is trivial or not.
24982508
///
24992509
/// @param Set The relations between parameters that are assumed to hold.
@@ -2559,9 +2569,6 @@ class Scop {
25592569
void recordAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc,
25602570
AssumptionSign Sign, BasicBlock *BB = nullptr);
25612571

2562-
/// Add all recorded assumptions to the assumed context.
2563-
void addRecordedAssumptions();
2564-
25652572
/// Mark the scop as invalid.
25662573
///
25672574
/// This method adds an assumption to the scop that is always invalid. As a

polly/lib/Analysis/ScopBuilder.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,40 @@ Value *ScopBuilder::findFADAllocationInvisible(MemAccInst Inst) {
385385
return Descriptor;
386386
}
387387

388+
void ScopBuilder::addRecordedAssumptions() {
389+
for (auto &AS : llvm::reverse(scop->recorded_assumptions())) {
390+
391+
if (!AS.BB) {
392+
scop->addAssumption(AS.Kind, AS.Set, AS.Loc, AS.Sign,
393+
nullptr /* BasicBlock */);
394+
continue;
395+
}
396+
397+
// If the domain was deleted the assumptions are void.
398+
isl_set *Dom = scop->getDomainConditions(AS.BB).release();
399+
if (!Dom)
400+
continue;
401+
402+
// If a basic block was given use its domain to simplify the assumption.
403+
// In case of restrictions we know they only have to hold on the domain,
404+
// thus we can intersect them with the domain of the block. However, for
405+
// assumptions the domain has to imply them, thus:
406+
// _ _____
407+
// Dom => S <==> A v B <==> A - B
408+
//
409+
// To avoid the complement we will register A - B as a restriction not an
410+
// assumption.
411+
isl_set *S = AS.Set.copy();
412+
if (AS.Sign == AS_RESTRICTION)
413+
S = isl_set_params(isl_set_intersect(S, Dom));
414+
else /* (AS.Sign == AS_ASSUMPTION) */
415+
S = isl_set_params(isl_set_subtract(Dom, S));
416+
417+
scop->addAssumption(AS.Kind, isl::manage(S), AS.Loc, AS_RESTRICTION, AS.BB);
418+
}
419+
scop->clearRecordedAssumptions();
420+
}
421+
388422
bool ScopBuilder::buildAccessMultiDimFixed(MemAccInst Inst, ScopStmt *Stmt) {
389423
Value *Val = Inst.getValueOperand();
390424
Type *ElementType = Val->getType();
@@ -1972,7 +2006,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC,
19722006
// After the context was fully constructed, thus all our knowledge about
19732007
// the parameters is in there, we add all recorded assumptions to the
19742008
// assumed/invalid context.
1975-
scop->addRecordedAssumptions();
2009+
addRecordedAssumptions();
19762010

19772011
scop->simplifyContexts();
19782012
if (!scop->buildAliasChecks(AA)) {

polly/lib/Analysis/ScopInfo.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,39 +3779,6 @@ void Scop::recordAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc,
37793779
RecordedAssumptions.push_back({Kind, Sign, Set, Loc, BB});
37803780
}
37813781

3782-
void Scop::addRecordedAssumptions() {
3783-
while (!RecordedAssumptions.empty()) {
3784-
Assumption AS = RecordedAssumptions.pop_back_val();
3785-
3786-
if (!AS.BB) {
3787-
addAssumption(AS.Kind, AS.Set, AS.Loc, AS.Sign, nullptr /* BasicBlock */);
3788-
continue;
3789-
}
3790-
3791-
// If the domain was deleted the assumptions are void.
3792-
isl_set *Dom = getDomainConditions(AS.BB).release();
3793-
if (!Dom)
3794-
continue;
3795-
3796-
// If a basic block was given use its domain to simplify the assumption.
3797-
// In case of restrictions we know they only have to hold on the domain,
3798-
// thus we can intersect them with the domain of the block. However, for
3799-
// assumptions the domain has to imply them, thus:
3800-
// _ _____
3801-
// Dom => S <==> A v B <==> A - B
3802-
//
3803-
// To avoid the complement we will register A - B as a restriction not an
3804-
// assumption.
3805-
isl_set *S = AS.Set.copy();
3806-
if (AS.Sign == AS_RESTRICTION)
3807-
S = isl_set_params(isl_set_intersect(S, Dom));
3808-
else /* (AS.Sign == AS_ASSUMPTION) */
3809-
S = isl_set_params(isl_set_subtract(Dom, S));
3810-
3811-
addAssumption(AS.Kind, isl::manage(S), AS.Loc, AS_RESTRICTION, AS.BB);
3812-
}
3813-
}
3814-
38153782
void Scop::invalidate(AssumptionKind Kind, DebugLoc Loc, BasicBlock *BB) {
38163783
LLVM_DEBUG(dbgs() << "Invalidate SCoP because of reason " << Kind << "\n");
38173784
addAssumption(Kind, isl::set::empty(getParamSpace()), Loc, AS_ASSUMPTION, BB);

0 commit comments

Comments
 (0)