[llvm-commits] [polly] r143961 - in /polly/trunk: include/polly/ScopInfo.h lib/Analysis/ScopInfo.cpp

Tobias Grosser grosser at fim.uni-passau.de
Mon Nov 7 04:58:59 PST 2011


Author: grosser
Date: Mon Nov  7 06:58:59 2011
New Revision: 143961

URL: http://llvm.org/viewvc/llvm-project?rev=143961&view=rev
Log:
ScopInfo: Extract function getIdForParam()

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=143961&r1=143960&r2=143961&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Mon Nov  7 06:58:59 2011
@@ -40,6 +40,7 @@
 
 struct isl_map;
 struct isl_basic_map;
+struct isl_id;
 struct isl_set;
 struct isl_space;
 struct isl_constraint;
@@ -454,6 +455,14 @@
   /// @return The set containing the parameters used in this Scop.
   inline const ParamVecType &getParams() const { return Parameters; }
 
+
+  /// @brief Return the isl_id that represents a certain parameter.
+  ///
+  /// @param Parameter A SCEV that was recognized as a Parameter.
+  ///
+  /// @return The corresponding isl_id or NULL otherwise.
+  isl_id *getIdForParam(const SCEV *Parameter) const;
+
   /// @name Parameter Iterators
   ///
   /// These iterators iterate over all parameters of this Scop.

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=143961&r1=143960&r2=143961&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon Nov  7 06:58:59 2011
@@ -87,28 +87,20 @@
   }
 
   isl_pw_aff *visit(const SCEV *scev) {
-    // In case the scev is contained in our list of parameters, we do not
-    // further analyze this expression, but create a new parameter in the
-    // isl_pw_aff. This allows us to treat subexpressions that we cannot
-    // translate into an piecewise affine expression, as constant parameters of
-    // the piecewise affine expression.
-    int i = 0;
-    for (Scop::const_param_iterator PI = scop->param_begin(),
-         PE = scop->param_end(); PI != PE; ++PI) {
-      if (*PI == scev) {
-        isl_id *ID = isl_id_alloc(ctx, ("p" + convertInt(i)).c_str(),
-                                  (void *) scev);
-        isl_space *Space = isl_space_set_alloc(ctx, 1, NbLoopSpaces);
-        Space = isl_space_set_dim_id(Space, isl_dim_param, 0, ID);
-
-        isl_set *Domain = isl_set_universe(isl_space_copy(Space));
-        isl_aff *Affine = isl_aff_zero_on_domain(
-          isl_local_space_from_space(Space));
-        Affine = isl_aff_add_coefficient_si(Affine, isl_dim_param, 0, 1);
+    // In case the scev is a valid parameter, we do not further analyze this
+    // expression, but create a new parameter in the isl_pw_aff. This allows us
+    // to treat subexpressions that we cannot translate into an piecewise affine
+    // expression, as constant parameters of the piecewise affine expression.
+    if (isl_id *Id = scop->getIdForParam(scev)) {
+      isl_space *Space = isl_space_set_alloc(ctx, 1, NbLoopSpaces);
+      Space = isl_space_set_dim_id(Space, isl_dim_param, 0, Id);
+
+      isl_set *Domain = isl_set_universe(isl_space_copy(Space));
+      isl_aff *Affine = isl_aff_zero_on_domain(
+        isl_local_space_from_space(Space));
+      Affine = isl_aff_add_coefficient_si(Affine, isl_dim_param, 0, 1);
 
-        return isl_pw_aff_alloc(Domain, Affine);
-      }
-      i++;
+      return isl_pw_aff_alloc(Domain, Affine);
     }
 
     return SCEVVisitor<SCEVAffinator, isl_pw_aff*>::visit(scev);
@@ -854,6 +846,22 @@
 
 //===----------------------------------------------------------------------===//
 /// Scop class implement
+isl_id *Scop::getIdForParam(const SCEV *Parameter) const {
+  int i = 0;
+
+  for (const_param_iterator PI = param_begin(), PE = param_end(); PI != PE;
+       ++PI) {
+    if (Parameter == *PI) {
+      std::string ParameterName = "p" + convertInt(i);
+      isl_id *id = isl_id_alloc(getIslCtx(), ParameterName.c_str(),
+                                (void *) Parameter);
+      return id;
+    }
+    i++;
+  }
+
+  return NULL;
+}
 
 void Scop::buildContext(isl_ctx *IslCtx, ParamSetType *ParamSet) {
   isl_space *Space = isl_space_params_alloc(IslCtx, ParamSet->size());





More information about the llvm-commits mailing list