[polly] r267423 - Refactor Scop parameter handling
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 25 09:15:17 PDT 2016
Author: jdoerfert
Date: Mon Apr 25 11:15:13 2016
New Revision: 267423
URL: http://llvm.org/viewvc/llvm-project?rev=267423&view=rev
Log:
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.
Modified:
polly/trunk/include/polly/ScopInfo.h
polly/trunk/lib/Analysis/ScopInfo.cpp
Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=267423&r1=267422&r2=267423&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Mon Apr 25 11:15:13 2016
@@ -1357,13 +1357,11 @@ private:
/// The statements in this Scop.
StmtSet Stmts;
- /// Parameters of this Scop
- typedef SmallVector<const SCEV *, 8> ParamVecType;
- ParamVecType Parameters;
-
- /// The isl_ids that are used to represent the parameters
- typedef std::map<const SCEV *, int> ParamIdType;
- ParamIdType ParameterIds;
+ /// @brief Parameters of this Scop
+ ParameterSetTy Parameters;
+
+ /// @brief Mapping from parameters to their ids.
+ DenseMap<const SCEV *, isl_id *> ParameterIds;
/// Isl context.
///
@@ -1702,6 +1700,9 @@ private:
/// @brief Add invariant loads listed in @p InvMAs with the domain of @p Stmt.
void addInvariantLoads(ScopStmt &Stmt, MemoryAccessList &InvMAs);
+ /// @brief Create an id for @p Param and store it in the ParameterIds map.
+ void createParameterId(const SCEV *Param);
+
/// @brief Build the Context of the Scop.
void buildContext();
@@ -1853,14 +1854,7 @@ public:
/// @brief Get the count of parameters used in this Scop.
///
/// @return The count of parameters used in this Scop.
- inline ParamVecType::size_type getNumParams() const {
- return Parameters.size();
- }
-
- /// @brief Get a set containing the parameters used in this Scop
- ///
- /// @return The set containing the parameters used in this Scop.
- inline const ParamVecType &getParams() const { return Parameters; }
+ size_t getNumParams() const { return Parameters.size(); }
/// @brief Take a list of parameters and add the new ones to the scop.
void addParams(const ParameterSetTy &NewParameters);
Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=267423&r1=267422&r2=267423&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon Apr 25 11:15:13 2016
@@ -1805,35 +1805,11 @@ const SCEV *Scop::getRepresentingInvaria
return SCEVSensitiveParameterRewriter::rewrite(S, *SE, InvEquivClassVMap);
}
-void Scop::addParams(const ParameterSetTy &NewParameters) {
- for (const SCEV *Parameter : NewParameters) {
- Parameter = extractConstantFactor(Parameter, *SE).second;
-
- // Normalize the SCEV to get the representing element for an invariant load.
- Parameter = getRepresentingInvariantLoadSCEV(Parameter);
-
- if (ParameterIds.find(Parameter) != ParameterIds.end())
- continue;
-
- int dimension = Parameters.size();
-
- Parameters.push_back(Parameter);
- ParameterIds[Parameter] = dimension;
- }
-}
-
-__isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) {
- // Normalize the SCEV to get the representing element for an invariant load.
- Parameter = getRepresentingInvariantLoadSCEV(Parameter);
-
- ParamIdType::const_iterator IdIter = ParameterIds.find(Parameter);
-
- if (IdIter == ParameterIds.end())
- return nullptr;
+void Scop::createParameterId(const SCEV *Parameter) {
+ assert(Parameters.count(Parameter));
+ assert(!ParameterIds.count(Parameter));
- std::string ParameterName;
-
- ParameterName = "p_" + utostr(IdIter->second);
+ std::string ParameterName = "p_" + std::to_string(getNumParams() - 1);
if (const SCEVUnknown *ValueParameter = dyn_cast<SCEVUnknown>(Parameter)) {
Value *Val = ValueParameter->getValue();
@@ -1853,8 +1829,26 @@ __isl_give isl_id *Scop::getIdForParam(c
}
}
- return isl_id_alloc(getIslCtx(), ParameterName.c_str(),
- const_cast<void *>((const void *)Parameter));
+ auto *Id = isl_id_alloc(getIslCtx(), ParameterName.c_str(),
+ const_cast<void *>((const void *)Parameter));
+ ParameterIds[Parameter] = Id;
+}
+
+void Scop::addParams(const ParameterSetTy &NewParameters) {
+ for (const SCEV *Parameter : NewParameters) {
+ // Normalize the SCEV to get the representing element for an invariant load.
+ Parameter = extractConstantFactor(Parameter, *SE).second;
+ Parameter = getRepresentingInvariantLoadSCEV(Parameter);
+
+ if (Parameters.insert(Parameter))
+ createParameterId(Parameter);
+ }
+}
+
+__isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) {
+ // Normalize the SCEV to get the representing element for an invariant load.
+ Parameter = getRepresentingInvariantLoadSCEV(Parameter);
+ return isl_id_copy(ParameterIds.lookup(Parameter));
}
__isl_give isl_set *Scop::addNonEmptyDomainConstraints(isl_set *C) const {
@@ -1974,12 +1968,10 @@ void Scop::buildContext() {
}
void Scop::addParameterBounds() {
- for (const auto &ParamID : ParameterIds) {
- int dim = ParamID.second;
-
- ConstantRange SRange = SE->getSignedRange(ParamID.first);
-
- Context = addRangeBoundsToSet(Context, SRange, dim, isl_dim_param);
+ unsigned PDim = 0;
+ for (auto *Parameter : Parameters) {
+ ConstantRange SRange = SE->getSignedRange(Parameter);
+ Context = addRangeBoundsToSet(Context, SRange, PDim++, isl_dim_param);
}
}
@@ -1987,10 +1979,10 @@ void Scop::realignParams() {
// Add all parameters into a common model.
isl_space *Space = isl_space_params_alloc(getIslCtx(), ParameterIds.size());
- for (const auto &ParamID : ParameterIds) {
- const SCEV *Parameter = ParamID.first;
+ unsigned PDim = 0;
+ for (const auto *Parameter : Parameters) {
isl_id *id = getIdForParam(Parameter);
- Space = isl_space_set_dim_id(Space, isl_dim_param, ParamID.second, id);
+ Space = isl_space_set_dim_id(Space, isl_dim_param, PDim++, id);
}
// Align the parameters of all data structures to the model.
@@ -3088,6 +3080,9 @@ Scop::~Scop() {
isl_set_free(InvalidContext);
isl_schedule_free(Schedule);
+ for (auto &It : ParameterIds)
+ isl_id_free(It.second);
+
for (auto It : DomainMap)
isl_set_free(It.second);
@@ -3639,10 +3634,9 @@ void Scop::printContext(raw_ostream &OS)
OS.indent(4) << "Invalid Context:\n";
OS.indent(4) << InvalidContext << "\n";
- for (const SCEV *Parameter : Parameters) {
- int Dim = ParameterIds.find(Parameter)->second;
- OS.indent(4) << "p" << Dim << ": " << *Parameter << "\n";
- }
+ unsigned Dim = 0;
+ for (const SCEV *Parameter : Parameters)
+ OS.indent(4) << "p" << Dim++ << ": " << *Parameter << "\n";
}
void Scop::printAliasAssumptions(raw_ostream &OS) const {
More information about the llvm-commits
mailing list