[polly] r245175 - Add -polly-context option to provide additional context information

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 16 03:19:31 PDT 2015


Author: grosser
Date: Sun Aug 16 05:19:29 2015
New Revision: 245175

URL: http://llvm.org/viewvc/llvm-project?rev=245175&view=rev
Log:
Add -polly-context option to provide additional context information

This option allows the user to provide additional information about parameter
values as an isl_set. To specify that N has the value 1024, we can provide
the context -polly-context='[N] -> {: N = 1024}'.

Added:
    polly/trunk/test/ScopInfo/user_context.ll
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=245175&r1=245174&r2=245175&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Sun Aug 16 05:19:29 2015
@@ -891,6 +891,9 @@ private:
   /// @brief Build the Context of the Scop.
   void buildContext();
 
+  /// @brief Add user provided parameter constraints to context.
+  void addUserContext();
+
   /// @brief Add the bounds of the parameters to the context.
   void addParameterBounds();
 

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=245175&r1=245174&r2=245175&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Sun Aug 16 05:19:29 2015
@@ -75,6 +75,10 @@ static cl::opt<unsigned> RunTimeChecksMa
     "polly-rtc-max-arrays-per-group",
     cl::desc("The maximal number of arrays to compare in each alias group."),
     cl::Hidden, cl::ZeroOrMore, cl::init(20), cl::cat(PollyCategory));
+static cl::opt<std::string> UserContextStr(
+    "polly-context", cl::value_desc("isl parameter set"),
+    cl::desc("Provide additional constraints on the context parameters"),
+    cl::init(""), cl::cat(PollyCategory));
 
 // Create a sequence of two schedules. Either argument may be null and is
 // interpreted as the empty schedule. Can also return null if both schedules are
@@ -1129,6 +1133,53 @@ __isl_give isl_id *Scop::getIdForParam(c
                       const_cast<void *>((const void *)Parameter));
 }
 
+void Scop::addUserContext() {
+  if (UserContextStr.empty())
+    return;
+
+  isl_set *UserContext = isl_set_read_from_str(IslCtx, UserContextStr.c_str());
+  isl_space *Space = getParamSpace();
+  if (isl_space_dim(Space, isl_dim_param) !=
+      isl_set_dim(UserContext, isl_dim_param)) {
+    auto SpaceStr = isl_space_to_str(Space);
+    errs() << "Error: the context provided in -polly-context has not the same "
+           << "number of dimensions than the computed context. Due to this "
+           << "mismatch, the -polly-context option is ignored. Please provide "
+           << "the context in the parameter space: " << SpaceStr << ".\n";
+    free(SpaceStr);
+    isl_set_free(UserContext);
+    isl_space_free(Space);
+    return;
+  }
+
+  for (unsigned i = 0; i < isl_space_dim(Space, isl_dim_param); i++) {
+    auto NameContext = isl_set_get_dim_name(Context, isl_dim_param, i);
+    auto NameUserContext = isl_set_get_dim_name(UserContext, isl_dim_param, i);
+
+    if (strcmp(NameContext, NameUserContext) != 0) {
+      auto SpaceStr = isl_space_to_str(Space);
+      errs() << "Error: the name of dimension " << i
+             << " provided in -polly-context "
+             << "is '" << NameUserContext << "', but the name in the computed "
+             << "context is '" << NameContext
+             << "'. Due to this name mismatch, "
+             << "the -polly-context option is ignored. Please provide "
+             << "the context in the parameter space: " << SpaceStr << ".\n";
+      free(SpaceStr);
+      isl_set_free(UserContext);
+      isl_space_free(Space);
+      return;
+    }
+
+    UserContext =
+        isl_set_set_dim_id(UserContext, isl_dim_param, i,
+                           isl_space_get_dim_id(Space, isl_dim_param, i));
+  }
+
+  Context = isl_set_intersect(Context, UserContext);
+  isl_space_free(Space);
+}
+
 void Scop::buildContext() {
   isl_space *Space = isl_space_params_alloc(IslCtx, 0);
   Context = isl_set_universe(isl_space_copy(Space));
@@ -1480,6 +1531,7 @@ void Scop::initFromTempScop(TempScop &Te
 
   realignParams();
   addParameterBounds();
+  addUserContext();
   simplifyAssumedContext();
 
   assert(NestLoops.empty() && "NestLoops not empty at top level!");

Added: polly/trunk/test/ScopInfo/user_context.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/user_context.ll?rev=245175&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/user_context.ll (added)
+++ polly/trunk/test/ScopInfo/user_context.ll Sun Aug 16 05:19:29 2015
@@ -0,0 +1,35 @@
+; RUN: opt %loadPolly -polly-detect-unprofitable -polly-scops -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-detect-unprofitable -polly-scops -polly-context='[N] -> {: N = 1024}' -analyze < %s | FileCheck %s --check-prefix=CTX
+; RUN: opt %loadPolly -polly-detect-unprofitable -polly-scops -polly-context='[N,M] -> {: 1 = 0}' -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-detect-unprofitable -polly-scops -polly-context='[] -> {: 1 = 0}' -analyze < %s | FileCheck %s
+
+; void f(int a[], int N) {
+;   int i;
+;   for (i = 0; i < N; ++i)
+;     a[i] = i;
+; }
+
+; CHECK: Context:
+; CHECK:    [N] -> {  : N >= -9223372036854775808 and N <= 9223372036854775807 }
+
+; CTX: Context:
+; CTX:    [N] -> {  : N = 1024 }
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
+
+define void @f(i64* nocapture %a, i64 %N) nounwind {
+entry:
+  br label %bb
+
+bb:                                               ; preds = %bb, %entry
+  %i = phi i64 [ 0, %entry ], [ %i.inc, %bb ]
+  %scevgep = getelementptr i64, i64* %a, i64 %i
+  store i64 %i, i64* %scevgep
+  %i.inc = add nsw i64 %i, 1
+  %exitcond = icmp eq i64 %i.inc, %N
+  br i1 %exitcond, label %return, label %bb
+
+return:                                           ; preds = %bb, %entry
+  ret void
+}
+




More information about the llvm-commits mailing list