Skip to content

Commit 4e3bb7b

Browse files
author
Johannes Doerfert
committed
Refactor Scop parameter handling
The new handling is consistent with the remaining code, e.g., we do not create a new parameter id for each lookup call but copy an existing one. Additionally, we now use the implicit order defined by the Parameters set instead of an explicit one defined in a map. llvm-svn: 267423
1 parent 0237eda commit 4e3bb7b

File tree

2 files changed

+45
-57
lines changed

2 files changed

+45
-57
lines changed

polly/include/polly/ScopInfo.h

+8-14
Original file line numberDiff line numberDiff line change
@@ -1357,13 +1357,11 @@ class Scop {
13571357
/// The statements in this Scop.
13581358
StmtSet Stmts;
13591359

1360-
/// Parameters of this Scop
1361-
typedef SmallVector<const SCEV *, 8> ParamVecType;
1362-
ParamVecType Parameters;
1360+
/// @brief Parameters of this Scop
1361+
ParameterSetTy Parameters;
13631362

1364-
/// The isl_ids that are used to represent the parameters
1365-
typedef std::map<const SCEV *, int> ParamIdType;
1366-
ParamIdType ParameterIds;
1363+
/// @brief Mapping from parameters to their ids.
1364+
DenseMap<const SCEV *, isl_id *> ParameterIds;
13671365

13681366
/// Isl context.
13691367
///
@@ -1702,6 +1700,9 @@ class Scop {
17021700
/// @brief Add invariant loads listed in @p InvMAs with the domain of @p Stmt.
17031701
void addInvariantLoads(ScopStmt &Stmt, MemoryAccessList &InvMAs);
17041702

1703+
/// @brief Create an id for @p Param and store it in the ParameterIds map.
1704+
void createParameterId(const SCEV *Param);
1705+
17051706
/// @brief Build the Context of the Scop.
17061707
void buildContext();
17071708

@@ -1853,14 +1854,7 @@ class Scop {
18531854
/// @brief Get the count of parameters used in this Scop.
18541855
///
18551856
/// @return The count of parameters used in this Scop.
1856-
inline ParamVecType::size_type getNumParams() const {
1857-
return Parameters.size();
1858-
}
1859-
1860-
/// @brief Get a set containing the parameters used in this Scop
1861-
///
1862-
/// @return The set containing the parameters used in this Scop.
1863-
inline const ParamVecType &getParams() const { return Parameters; }
1857+
size_t getNumParams() const { return Parameters.size(); }
18641858

18651859
/// @brief Take a list of parameters and add the new ones to the scop.
18661860
void addParams(const ParameterSetTy &NewParameters);

polly/lib/Analysis/ScopInfo.cpp

+37-43
Original file line numberDiff line numberDiff line change
@@ -1805,35 +1805,11 @@ const SCEV *Scop::getRepresentingInvariantLoadSCEV(const SCEV *S) {
18051805
return SCEVSensitiveParameterRewriter::rewrite(S, *SE, InvEquivClassVMap);
18061806
}
18071807

1808-
void Scop::addParams(const ParameterSetTy &NewParameters) {
1809-
for (const SCEV *Parameter : NewParameters) {
1810-
Parameter = extractConstantFactor(Parameter, *SE).second;
1811-
1812-
// Normalize the SCEV to get the representing element for an invariant load.
1813-
Parameter = getRepresentingInvariantLoadSCEV(Parameter);
1814-
1815-
if (ParameterIds.find(Parameter) != ParameterIds.end())
1816-
continue;
1817-
1818-
int dimension = Parameters.size();
1819-
1820-
Parameters.push_back(Parameter);
1821-
ParameterIds[Parameter] = dimension;
1822-
}
1823-
}
1824-
1825-
__isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) {
1826-
// Normalize the SCEV to get the representing element for an invariant load.
1827-
Parameter = getRepresentingInvariantLoadSCEV(Parameter);
1828-
1829-
ParamIdType::const_iterator IdIter = ParameterIds.find(Parameter);
1830-
1831-
if (IdIter == ParameterIds.end())
1832-
return nullptr;
1808+
void Scop::createParameterId(const SCEV *Parameter) {
1809+
assert(Parameters.count(Parameter));
1810+
assert(!ParameterIds.count(Parameter));
18331811

1834-
std::string ParameterName;
1835-
1836-
ParameterName = "p_" + utostr(IdIter->second);
1812+
std::string ParameterName = "p_" + std::to_string(getNumParams() - 1);
18371813

18381814
if (const SCEVUnknown *ValueParameter = dyn_cast<SCEVUnknown>(Parameter)) {
18391815
Value *Val = ValueParameter->getValue();
@@ -1853,8 +1829,26 @@ __isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) {
18531829
}
18541830
}
18551831

1856-
return isl_id_alloc(getIslCtx(), ParameterName.c_str(),
1857-
const_cast<void *>((const void *)Parameter));
1832+
auto *Id = isl_id_alloc(getIslCtx(), ParameterName.c_str(),
1833+
const_cast<void *>((const void *)Parameter));
1834+
ParameterIds[Parameter] = Id;
1835+
}
1836+
1837+
void Scop::addParams(const ParameterSetTy &NewParameters) {
1838+
for (const SCEV *Parameter : NewParameters) {
1839+
// Normalize the SCEV to get the representing element for an invariant load.
1840+
Parameter = extractConstantFactor(Parameter, *SE).second;
1841+
Parameter = getRepresentingInvariantLoadSCEV(Parameter);
1842+
1843+
if (Parameters.insert(Parameter))
1844+
createParameterId(Parameter);
1845+
}
1846+
}
1847+
1848+
__isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) {
1849+
// Normalize the SCEV to get the representing element for an invariant load.
1850+
Parameter = getRepresentingInvariantLoadSCEV(Parameter);
1851+
return isl_id_copy(ParameterIds.lookup(Parameter));
18581852
}
18591853

18601854
__isl_give isl_set *Scop::addNonEmptyDomainConstraints(isl_set *C) const {
@@ -1974,23 +1968,21 @@ void Scop::buildContext() {
19741968
}
19751969

19761970
void Scop::addParameterBounds() {
1977-
for (const auto &ParamID : ParameterIds) {
1978-
int dim = ParamID.second;
1979-
1980-
ConstantRange SRange = SE->getSignedRange(ParamID.first);
1981-
1982-
Context = addRangeBoundsToSet(Context, SRange, dim, isl_dim_param);
1971+
unsigned PDim = 0;
1972+
for (auto *Parameter : Parameters) {
1973+
ConstantRange SRange = SE->getSignedRange(Parameter);
1974+
Context = addRangeBoundsToSet(Context, SRange, PDim++, isl_dim_param);
19831975
}
19841976
}
19851977

19861978
void Scop::realignParams() {
19871979
// Add all parameters into a common model.
19881980
isl_space *Space = isl_space_params_alloc(getIslCtx(), ParameterIds.size());
19891981

1990-
for (const auto &ParamID : ParameterIds) {
1991-
const SCEV *Parameter = ParamID.first;
1982+
unsigned PDim = 0;
1983+
for (const auto *Parameter : Parameters) {
19921984
isl_id *id = getIdForParam(Parameter);
1993-
Space = isl_space_set_dim_id(Space, isl_dim_param, ParamID.second, id);
1985+
Space = isl_space_set_dim_id(Space, isl_dim_param, PDim++, id);
19941986
}
19951987

19961988
// Align the parameters of all data structures to the model.
@@ -3088,6 +3080,9 @@ Scop::~Scop() {
30883080
isl_set_free(InvalidContext);
30893081
isl_schedule_free(Schedule);
30903082

3083+
for (auto &It : ParameterIds)
3084+
isl_id_free(It.second);
3085+
30913086
for (auto It : DomainMap)
30923087
isl_set_free(It.second);
30933088

@@ -3639,10 +3634,9 @@ void Scop::printContext(raw_ostream &OS) const {
36393634
OS.indent(4) << "Invalid Context:\n";
36403635
OS.indent(4) << InvalidContext << "\n";
36413636

3642-
for (const SCEV *Parameter : Parameters) {
3643-
int Dim = ParameterIds.find(Parameter)->second;
3644-
OS.indent(4) << "p" << Dim << ": " << *Parameter << "\n";
3645-
}
3637+
unsigned Dim = 0;
3638+
for (const SCEV *Parameter : Parameters)
3639+
OS.indent(4) << "p" << Dim++ << ": " << *Parameter << "\n";
36463640
}
36473641

36483642
void Scop::printAliasAssumptions(raw_ostream &OS) const {

0 commit comments

Comments
 (0)