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}'.

llvm-svn: 245175
This commit is contained in:
Tobias Grosser 2015-08-16 10:19:29 +00:00
parent ddb83d0f6d
commit 8a9c2353f9
3 changed files with 90 additions and 0 deletions

View File

@ -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();

View File

@ -75,6 +75,10 @@ static cl::opt<unsigned> RunTimeChecksMaxArraysPerGroup(
"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(const SCEV *Parameter) const {
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 &TempScop, LoopInfo &LI,
realignParams();
addParameterBounds();
addUserContext();
simplifyAssumedContext();
assert(NestLoops.empty() && "NestLoops not empty at top level!");

View File

@ -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
}