Skip to content

Commit a043830

Browse files
[NFC][ScopBuilder] Move buildDomains and its callees to ScopBuilder.
Scope of changes: 1) Moved buildDomains function to ScopBuilder class. 2) Moved buildDomainsWithBranchConstraints function to ScopBuilder class. 3) Moved propagateDomainConstraints to ScopBuilder class. 4) Moved propagateDomainConstraintsToRegionExit to ScopBuilder class. 5) Moved propagateInvalidStmtDomains to ScopBuilder class. 6) Moved getPredecessorDomainConstraints function to ScopBuilder class. 7) Moved addLoopBoundsToHeaderDomain function to ScopBuilder class. 8) Moved getPwAff function to ScopBuilder class. 9) Moved buildConditionSets functions to ScopBuilder class. 10) Added updateMaxLoopDepth, notifyErrorBlock, getOrInitEmptyDomain, isDomainDefined, setDomain functions to Scop class. They are used by ScopBuilder. 11) Moved helper functions: getRegionNodeBasicBlock, getRegionNodeSuccessor, containsErrorBlock, createNextIterationMap, collectBoundedParts, partitionSetParts, buildConditionSet to ScopBuilder.cpp file. Differential Revision: https://reviews.llvm.org/D65729 llvm-svn: 368100
1 parent 75e557c commit a043830

File tree

4 files changed

+1094
-1038
lines changed

4 files changed

+1094
-1038
lines changed

polly/include/polly/ScopBuilder.h

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,172 @@ class ScopBuilder {
123123
// Build the SCoP for Region @p R.
124124
void buildScop(Region &R, AssumptionCache &AC);
125125

126+
/// Adjust the dimensions of @p Dom that was constructed for @p OldL
127+
/// to be compatible to domains constructed for loop @p NewL.
128+
///
129+
/// This function assumes @p NewL and @p OldL are equal or there is a CFG
130+
/// edge from @p OldL to @p NewL.
131+
isl::set adjustDomainDimensions(isl::set Dom, Loop *OldL, Loop *NewL);
132+
133+
/// Compute the domain for each basic block in @p R.
134+
///
135+
/// @param R The region we currently traverse.
136+
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
137+
/// region.
138+
///
139+
/// @returns True if there was no problem and false otherwise.
140+
bool buildDomains(Region *R,
141+
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
142+
143+
/// Compute the branching constraints for each basic block in @p R.
144+
///
145+
/// @param R The region we currently build branching conditions
146+
/// for.
147+
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
148+
/// region.
149+
///
150+
/// @returns True if there was no problem and false otherwise.
151+
bool buildDomainsWithBranchConstraints(
152+
Region *R, DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
153+
154+
/// Build the conditions sets for the terminator @p TI in the @p Domain.
155+
///
156+
/// This will fill @p ConditionSets with the conditions under which control
157+
/// will be moved from @p TI to its successors. Hence, @p ConditionSets will
158+
/// have as many elements as @p TI has successors.
159+
bool buildConditionSets(BasicBlock *BB, Instruction *TI, Loop *L,
160+
__isl_keep isl_set *Domain,
161+
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap,
162+
SmallVectorImpl<__isl_give isl_set *> &ConditionSets);
163+
164+
/// Build the conditions sets for the branch condition @p Condition in
165+
/// the @p Domain.
166+
///
167+
/// This will fill @p ConditionSets with the conditions under which control
168+
/// will be moved from @p TI to its successors. Hence, @p ConditionSets will
169+
/// have as many elements as @p TI has successors. If @p TI is nullptr the
170+
/// context under which @p Condition is true/false will be returned as the
171+
/// new elements of @p ConditionSets.
172+
bool buildConditionSets(BasicBlock *BB, Value *Condition, Instruction *TI,
173+
Loop *L, __isl_keep isl_set *Domain,
174+
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap,
175+
SmallVectorImpl<__isl_give isl_set *> &ConditionSets);
176+
177+
/// Build the conditions sets for the switch @p SI in the @p Domain.
178+
///
179+
/// This will fill @p ConditionSets with the conditions under which control
180+
/// will be moved from @p SI to its successors. Hence, @p ConditionSets will
181+
/// have as many elements as @p SI has successors.
182+
bool buildConditionSets(BasicBlock *BB, SwitchInst *SI, Loop *L,
183+
__isl_keep isl_set *Domain,
184+
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap,
185+
SmallVectorImpl<__isl_give isl_set *> &ConditionSets);
186+
187+
/// Build condition sets for unsigned ICmpInst(s).
188+
/// Special handling is required for unsigned operands to ensure that if
189+
/// MSB (aka the Sign bit) is set for an operands in an unsigned ICmpInst
190+
/// it should wrap around.
191+
///
192+
/// @param IsStrictUpperBound holds information on the predicate relation
193+
/// between TestVal and UpperBound, i.e,
194+
/// TestVal < UpperBound OR TestVal <= UpperBound
195+
__isl_give isl_set *buildUnsignedConditionSets(
196+
BasicBlock *BB, Value *Condition, __isl_keep isl_set *Domain,
197+
const SCEV *SCEV_TestVal, const SCEV *SCEV_UpperBound,
198+
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap,
199+
bool IsStrictUpperBound);
200+
201+
/// Propagate the domain constraints through the region @p R.
202+
///
203+
/// @param R The region we currently build branching
204+
/// conditions for.
205+
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
206+
/// region.
207+
///
208+
/// @returns True if there was no problem and false otherwise.
209+
bool propagateDomainConstraints(
210+
Region *R, DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
211+
212+
/// Propagate domains that are known due to graph properties.
213+
///
214+
/// As a CFG is mostly structured we use the graph properties to propagate
215+
/// domains without the need to compute all path conditions. In particular,
216+
/// if a block A dominates a block B and B post-dominates A we know that the
217+
/// domain of B is a superset of the domain of A. As we do not have
218+
/// post-dominator information available here we use the less precise region
219+
/// information. Given a region R, we know that the exit is always executed
220+
/// if the entry was executed, thus the domain of the exit is a superset of
221+
/// the domain of the entry. In case the exit can only be reached from
222+
/// within the region the domains are in fact equal. This function will use
223+
/// this property to avoid the generation of condition constraints that
224+
/// determine when a branch is taken. If @p BB is a region entry block we
225+
/// will propagate its domain to the region exit block. Additionally, we put
226+
/// the region exit block in the @p FinishedExitBlocks set so we can later
227+
/// skip edges from within the region to that block.
228+
///
229+
/// @param BB The block for which the domain is currently
230+
/// propagated.
231+
/// @param BBLoop The innermost affine loop surrounding @p BB.
232+
/// @param FinishedExitBlocks Set of region exits the domain was set for.
233+
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
234+
/// region.
235+
void propagateDomainConstraintsToRegionExit(
236+
BasicBlock *BB, Loop *BBLoop,
237+
SmallPtrSetImpl<BasicBlock *> &FinishedExitBlocks,
238+
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
239+
240+
/// Propagate invalid domains of statements through @p R.
241+
///
242+
/// This method will propagate invalid statement domains through @p R and at
243+
/// the same time add error block domains to them. Additionally, the domains
244+
/// of error statements and those only reachable via error statements will
245+
/// be replaced by an empty set. Later those will be removed completely.
246+
///
247+
/// @param R The currently traversed region.
248+
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
249+
/// region.
250+
//
251+
/// @returns True if there was no problem and false otherwise.
252+
bool propagateInvalidStmtDomains(
253+
Region *R, DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
254+
255+
/// Compute the union of predecessor domains for @p BB.
256+
///
257+
/// To compute the union of all domains of predecessors of @p BB this
258+
/// function applies similar reasoning on the CFG structure as described for
259+
/// @see propagateDomainConstraintsToRegionExit
260+
///
261+
/// @param BB The block for which the predecessor domains are collected.
262+
/// @param Domain The domain under which BB is executed.
263+
///
264+
/// @returns The domain under which @p BB is executed.
265+
isl::set getPredecessorDomainConstraints(BasicBlock *BB, isl::set Domain);
266+
267+
/// Add loop carried constraints to the header block of the loop @p L.
268+
///
269+
/// @param L The loop to process.
270+
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
271+
/// region.
272+
///
273+
/// @returns True if there was no problem and false otherwise.
274+
bool addLoopBoundsToHeaderDomain(
275+
Loop *L, DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
276+
277+
/// Compute the isl representation for the SCEV @p E in this BB.
278+
///
279+
/// @param BB The BB for which isl representation is to be
280+
/// computed.
281+
/// @param InvalidDomainMap A map of BB to their invalid domains.
282+
/// @param E The SCEV that should be translated.
283+
/// @param NonNegative Flag to indicate the @p E has to be
284+
/// non-negative.
285+
///
286+
/// Note that this function will also adjust the invalid context
287+
/// accordingly.
288+
__isl_give isl_pw_aff *
289+
getPwAff(BasicBlock *BB, DenseMap<BasicBlock *, isl::set> &InvalidDomainMap,
290+
const SCEV *E, bool NonNegative = false);
291+
126292
/// Create equivalence classes for required invariant accesses.
127293
///
128294
/// These classes will consolidate multiple required invariant loads from the

polly/include/polly/ScopInfo.h

Lines changed: 22 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,120 +1952,6 @@ class Scop {
19521952
void init(AliasAnalysis &AA, AssumptionCache &AC, DominatorTree &DT,
19531953
LoopInfo &LI);
19541954

1955-
/// Propagate domains that are known due to graph properties.
1956-
///
1957-
/// As a CFG is mostly structured we use the graph properties to propagate
1958-
/// domains without the need to compute all path conditions. In particular, if
1959-
/// a block A dominates a block B and B post-dominates A we know that the
1960-
/// domain of B is a superset of the domain of A. As we do not have
1961-
/// post-dominator information available here we use the less precise region
1962-
/// information. Given a region R, we know that the exit is always executed if
1963-
/// the entry was executed, thus the domain of the exit is a superset of the
1964-
/// domain of the entry. In case the exit can only be reached from within the
1965-
/// region the domains are in fact equal. This function will use this property
1966-
/// to avoid the generation of condition constraints that determine when a
1967-
/// branch is taken. If @p BB is a region entry block we will propagate its
1968-
/// domain to the region exit block. Additionally, we put the region exit
1969-
/// block in the @p FinishedExitBlocks set so we can later skip edges from
1970-
/// within the region to that block.
1971-
///
1972-
/// @param BB The block for which the domain is currently
1973-
/// propagated.
1974-
/// @param BBLoop The innermost affine loop surrounding @p BB.
1975-
/// @param FinishedExitBlocks Set of region exits the domain was set for.
1976-
/// @param LI The LoopInfo for the current function.
1977-
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
1978-
/// region.
1979-
void propagateDomainConstraintsToRegionExit(
1980-
BasicBlock *BB, Loop *BBLoop,
1981-
SmallPtrSetImpl<BasicBlock *> &FinishedExitBlocks, LoopInfo &LI,
1982-
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
1983-
1984-
/// Compute the union of predecessor domains for @p BB.
1985-
///
1986-
/// To compute the union of all domains of predecessors of @p BB this
1987-
/// function applies similar reasoning on the CFG structure as described for
1988-
/// @see propagateDomainConstraintsToRegionExit
1989-
///
1990-
/// @param BB The block for which the predecessor domains are collected.
1991-
/// @param Domain The domain under which BB is executed.
1992-
/// @param DT The DominatorTree for the current function.
1993-
/// @param LI The LoopInfo for the current function.
1994-
///
1995-
/// @returns The domain under which @p BB is executed.
1996-
isl::set getPredecessorDomainConstraints(BasicBlock *BB, isl::set Domain,
1997-
DominatorTree &DT, LoopInfo &LI);
1998-
1999-
/// Add loop carried constraints to the header block of the loop @p L.
2000-
///
2001-
/// @param L The loop to process.
2002-
/// @param LI The LoopInfo for the current function.
2003-
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
2004-
/// region.
2005-
///
2006-
/// @returns True if there was no problem and false otherwise.
2007-
bool addLoopBoundsToHeaderDomain(
2008-
Loop *L, LoopInfo &LI,
2009-
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
2010-
2011-
/// Compute the branching constraints for each basic block in @p R.
2012-
///
2013-
/// @param R The region we currently build branching conditions
2014-
/// for.
2015-
/// @param DT The DominatorTree for the current function.
2016-
/// @param LI The LoopInfo for the current function.
2017-
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
2018-
/// region.
2019-
///
2020-
/// @returns True if there was no problem and false otherwise.
2021-
bool buildDomainsWithBranchConstraints(
2022-
Region *R, DominatorTree &DT, LoopInfo &LI,
2023-
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
2024-
2025-
/// Propagate the domain constraints through the region @p R.
2026-
///
2027-
/// @param R The region we currently build branching conditions
2028-
/// for.
2029-
/// @param DT The DominatorTree for the current function.
2030-
/// @param LI The LoopInfo for the current function.
2031-
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
2032-
/// region.
2033-
///
2034-
/// @returns True if there was no problem and false otherwise.
2035-
bool propagateDomainConstraints(
2036-
Region *R, DominatorTree &DT, LoopInfo &LI,
2037-
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
2038-
2039-
/// Propagate invalid domains of statements through @p R.
2040-
///
2041-
/// This method will propagate invalid statement domains through @p R and at
2042-
/// the same time add error block domains to them. Additionally, the domains
2043-
/// of error statements and those only reachable via error statements will be
2044-
/// replaced by an empty set. Later those will be removed completely.
2045-
///
2046-
/// @param R The currently traversed region.
2047-
/// @param DT The DominatorTree for the current function.
2048-
/// @param LI The LoopInfo for the current function.
2049-
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
2050-
/// region.
2051-
//
2052-
/// @returns True if there was no problem and false otherwise.
2053-
bool propagateInvalidStmtDomains(
2054-
Region *R, DominatorTree &DT, LoopInfo &LI,
2055-
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
2056-
2057-
/// Compute the domain for each basic block in @p R.
2058-
///
2059-
/// @param R The region we currently traverse.
2060-
/// @param DT The DominatorTree for the current function.
2061-
/// @param LI The LoopInfo for the current function.
2062-
/// @param InvalidDomainMap BB to InvalidDomain map for the BB of current
2063-
/// region.
2064-
///
2065-
/// @returns True if there was no problem and false otherwise.
2066-
bool buildDomains(Region *R, DominatorTree &DT, LoopInfo &LI,
2067-
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap);
2068-
20691955
/// Add parameter constraints to @p C that imply a non-empty domain.
20701956
isl::set addNonEmptyDomainConstraints(isl::set C) const;
20711957

@@ -2641,8 +2527,15 @@ class Scop {
26412527
ScopArrayInfoMap.erase(It);
26422528
}
26432529

2530+
/// Set new isl context.
26442531
void setContext(isl::set NewContext);
26452532

2533+
/// Update maximal loop depth. If @p Depth is smaller than current value,
2534+
/// then maximal loop depth is not updated.
2535+
void updateMaxLoopDepth(unsigned Depth) {
2536+
MaxLoopDepth = std::max(MaxLoopDepth, Depth);
2537+
}
2538+
26462539
/// Align the parameters in the statement to the scop context
26472540
void realignParams();
26482541

@@ -2657,6 +2550,9 @@ class Scop {
26572550
/// Return true if the SCoP contained at least one error block.
26582551
bool hasErrorBlock() const { return HasErrorBlock; }
26592552

2553+
/// Notify SCoP that it contains an error block
2554+
void notifyErrorBlock() { HasErrorBlock = true; }
2555+
26602556
/// Return true if the underlying region has a single exiting block.
26612557
bool hasSingleExitEdge() const { return HasSingleExitEdge; }
26622558

@@ -2701,6 +2597,9 @@ class Scop {
27012597
/// domain part associated with the piecewise affine function.
27022598
isl::pw_aff getPwAffOnly(const SCEV *E, BasicBlock *BB = nullptr);
27032599

2600+
/// Check if an <nsw> AddRec for the loop L is cached.
2601+
bool hasNSWAddRecForLoop(Loop *L) { return Affinator.hasNSWAddRecForLoop(L); }
2602+
27042603
/// Return the domain of @p Stmt.
27052604
///
27062605
/// @param Stmt The statement for which the conditions should be returned.
@@ -2711,6 +2610,15 @@ class Scop {
27112610
/// @param BB The block for which the conditions should be returned.
27122611
isl::set getDomainConditions(BasicBlock *BB) const;
27132612

2613+
/// Return the domain of @p BB. If it does not exist, create an empty one.
2614+
isl::set &getOrInitEmptyDomain(BasicBlock *BB) { return DomainMap[BB]; }
2615+
2616+
/// Check if domain is determined for @p BB.
2617+
bool isDomainDefined(BasicBlock *BB) const { return DomainMap.count(BB) > 0; }
2618+
2619+
/// Set domain for @p BB.
2620+
void setDomain(BasicBlock *BB, isl::set &Domain) { DomainMap[BB] = Domain; }
2621+
27142622
/// Get a union set containing the iteration domains of all statements.
27152623
isl::union_set getDomains() const;
27162624

0 commit comments

Comments
 (0)