@@ -1805,35 +1805,11 @@ const SCEV *Scop::getRepresentingInvariantLoadSCEV(const SCEV *S) {
1805
1805
return SCEVSensitiveParameterRewriter::rewrite (S, *SE, InvEquivClassVMap);
1806
1806
}
1807
1807
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));
1833
1811
1834
- std::string ParameterName;
1835
-
1836
- ParameterName = " p_" + utostr (IdIter->second );
1812
+ std::string ParameterName = " p_" + std::to_string (getNumParams () - 1 );
1837
1813
1838
1814
if (const SCEVUnknown *ValueParameter = dyn_cast<SCEVUnknown>(Parameter)) {
1839
1815
Value *Val = ValueParameter->getValue ();
@@ -1853,8 +1829,26 @@ __isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) {
1853
1829
}
1854
1830
}
1855
1831
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));
1858
1852
}
1859
1853
1860
1854
__isl_give isl_set *Scop::addNonEmptyDomainConstraints (isl_set *C) const {
@@ -1974,23 +1968,21 @@ void Scop::buildContext() {
1974
1968
}
1975
1969
1976
1970
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);
1983
1975
}
1984
1976
}
1985
1977
1986
1978
void Scop::realignParams () {
1987
1979
// Add all parameters into a common model.
1988
1980
isl_space *Space = isl_space_params_alloc (getIslCtx (), ParameterIds.size ());
1989
1981
1990
- for ( const auto &ParamID : ParameterIds) {
1991
- const SCEV *Parameter = ParamID. first ;
1982
+ unsigned PDim = 0 ;
1983
+ for ( const auto *Parameter : Parameters) {
1992
1984
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);
1994
1986
}
1995
1987
1996
1988
// Align the parameters of all data structures to the model.
@@ -3088,6 +3080,9 @@ Scop::~Scop() {
3088
3080
isl_set_free (InvalidContext);
3089
3081
isl_schedule_free (Schedule);
3090
3082
3083
+ for (auto &It : ParameterIds)
3084
+ isl_id_free (It.second );
3085
+
3091
3086
for (auto It : DomainMap)
3092
3087
isl_set_free (It.second );
3093
3088
@@ -3639,10 +3634,9 @@ void Scop::printContext(raw_ostream &OS) const {
3639
3634
OS.indent (4 ) << " Invalid Context:\n " ;
3640
3635
OS.indent (4 ) << InvalidContext << " \n " ;
3641
3636
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 " ;
3646
3640
}
3647
3641
3648
3642
void Scop::printAliasAssumptions (raw_ostream &OS) const {
0 commit comments