summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2015-01-08 19:26:53 +0000
committerTobias Grosser <tobias@grosser.es>2015-01-08 19:26:53 +0000
commit55bc4c076706b6410a6bae84210ab32b95f272c9 (patch)
tree6e15ec7ae54c3d8df2ed495e323a3982d87f5064
parent20c321caf83c3c10c992756eea7a04de582aa0db (diff)
downloadbcm5719-llvm-55bc4c076706b6410a6bae84210ab32b95f272c9.tar.gz
bcm5719-llvm-55bc4c076706b6410a6bae84210ab32b95f272c9.zip
Add support for pointer types in expressions
llvm-svn: 225464
-rw-r--r--polly/lib/Analysis/ScopInfo.cpp10
-rw-r--r--polly/lib/CodeGen/IslCodeGeneration.cpp3
-rw-r--r--polly/lib/CodeGen/IslExprBuilder.cpp9
-rw-r--r--polly/lib/Support/SCEVValidator.cpp4
-rw-r--r--polly/test/Isl/CodeGen/pointer-type-expressions.ll47
-rw-r--r--polly/test/ScopInfo/pointer-type-expressions.ll49
6 files changed, 112 insertions, 10 deletions
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index 73c7fec7bec..d43f26401d9 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -1168,14 +1168,18 @@ void Scop::addParameterBounds() {
isl_id *Id;
const SCEV *Scev;
const IntegerType *T;
+ int Width;
Id = isl_set_get_dim_id(Context, isl_dim_param, i);
Scev = (const SCEV *)isl_id_get_user(Id);
- T = dyn_cast<IntegerType>(Scev->getType());
isl_id_free(Id);
- assert(T && "Not an integer type");
- int Width = T->getBitWidth();
+ T = dyn_cast<IntegerType>(Scev->getType());
+
+ if (!T)
+ continue;
+
+ Width = T->getBitWidth();
V = isl_val_int_from_si(IslCtx, Width - 1);
V = isl_val_2exp(V);
diff --git a/polly/lib/CodeGen/IslCodeGeneration.cpp b/polly/lib/CodeGen/IslCodeGeneration.cpp
index 34043782e9b..9fc101db6e3 100644
--- a/polly/lib/CodeGen/IslCodeGeneration.cpp
+++ b/polly/lib/CodeGen/IslCodeGeneration.cpp
@@ -871,8 +871,7 @@ void IslNodeBuilder::addParameters(__isl_take isl_set *Context) {
Value *IslNodeBuilder::generateSCEV(const SCEV *Expr) {
Instruction *InsertLocation = --(Builder.GetInsertBlock()->end());
- return Rewriter->expandCodeFor(Expr, cast<IntegerType>(Expr->getType()),
- InsertLocation);
+ return Rewriter->expandCodeFor(Expr, Expr->getType(), InsertLocation);
}
namespace {
diff --git a/polly/lib/CodeGen/IslExprBuilder.cpp b/polly/lib/CodeGen/IslExprBuilder.cpp
index 7b5b8e005e4..d1e4e9667b1 100644
--- a/polly/lib/CodeGen/IslExprBuilder.cpp
+++ b/polly/lib/CodeGen/IslExprBuilder.cpp
@@ -280,13 +280,16 @@ Value *IslExprBuilder::createOpICmp(__isl_take isl_ast_expr *Expr) {
LHS = create(isl_ast_expr_get_op_arg(Expr, 0));
RHS = create(isl_ast_expr_get_op_arg(Expr, 1));
- bool IsPtrType = LHS->getType()->isPointerTy();
- assert((!IsPtrType || RHS->getType()->isPointerTy()) &&
- "Both ICmp operators should be pointer types or none of them");
+ bool IsPtrType =
+ LHS->getType()->isPointerTy() || RHS->getType()->isPointerTy();
if (LHS->getType() != RHS->getType()) {
if (IsPtrType) {
Type *I8PtrTy = Builder.getInt8PtrTy();
+ if (!LHS->getType()->isPointerTy())
+ LHS = Builder.CreateIntToPtr(LHS, I8PtrTy);
+ if (!RHS->getType()->isPointerTy())
+ RHS = Builder.CreateIntToPtr(RHS, I8PtrTy);
if (LHS->getType() != I8PtrTy)
LHS = Builder.CreateBitCast(LHS, I8PtrTy);
if (RHS->getType() != I8PtrTy)
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index 40f1d91388b..67c9e0eb1ee 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -336,8 +336,8 @@ public:
// A[i] = 1;
//
// See test/CodeGen/20120316-InvalidCast.ll
- if (!Expr->getType()->isIntegerTy()) {
- DEBUG(dbgs() << "INVALID: UnknownExpr is not an integer type");
+ if (!(Expr->getType()->isIntegerTy() || Expr->getType()->isPointerTy())) {
+ DEBUG(dbgs() << "INVALID: UnknownExpr is not an integer or pointer type");
return ValidatorResult(SCEVType::INVALID);
}
diff --git a/polly/test/Isl/CodeGen/pointer-type-expressions.ll b/polly/test/Isl/CodeGen/pointer-type-expressions.ll
new file mode 100644
index 00000000000..1e941cdb3a0
--- /dev/null
+++ b/polly/test/Isl/CodeGen/pointer-type-expressions.ll
@@ -0,0 +1,47 @@
+; RUN: opt %loadPolly -polly-ast -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-codegen-isl -S < %s | FileCheck %s -check-prefix=CODEGEN
+
+; void f(int a[], int N, float *P) {
+; int i;
+; for (i = 0; i < N; ++i)
+; if (*P != 0)
+; a[i] = i;
+; }
+
+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"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @f(i64* nocapture %a, i64 %N, float * %P) nounwind {
+entry:
+ br label %bb
+
+bb:
+ %i = phi i64 [ 0, %entry ], [ %i.inc, %bb.backedge ]
+ %brcond = icmp ne float* %P, null
+ br i1 %brcond, label %store, label %bb.backedge
+
+store:
+ %scevgep = getelementptr i64* %a, i64 %i
+ store i64 %i, i64* %scevgep
+ br label %bb.backedge
+
+bb.backedge:
+ %i.inc = add nsw i64 %i, 1
+ %exitcond = icmp eq i64 %i.inc, %N
+ br i1 %exitcond, label %return, label %bb
+
+return:
+ ret void
+}
+
+; CHECK: if (P <= -1) {
+; CHECK: for (int c0 = 0; c0 < N; c0 += 1)
+; CHECK: Stmt_store(c0);
+; CHECK: } else if (P >= 1)
+; CHECK: for (int c0 = 0; c0 < N; c0 += 1)
+; CHECK: Stmt_store(c0);
+; CHECK: }
+
+; CODEGEN: %0 = bitcast float* %P to i8*
+; CODEGEN: %1 = icmp ule i8* %0, inttoptr (i64 -1 to i8*)
+
diff --git a/polly/test/ScopInfo/pointer-type-expressions.ll b/polly/test/ScopInfo/pointer-type-expressions.ll
new file mode 100644
index 00000000000..5392b9417f1
--- /dev/null
+++ b/polly/test/ScopInfo/pointer-type-expressions.ll
@@ -0,0 +1,49 @@
+; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s
+
+; void f(int a[], int N, float *P) {
+; int i;
+; for (i = 0; i < N; ++i)
+; if (*P != 0)
+; a[i] = i;
+; }
+
+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"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @f(i64* nocapture %a, i64 %N, float * %P) nounwind {
+entry:
+ br label %bb
+
+bb:
+ %i = phi i64 [ 0, %entry ], [ %i.inc, %bb.backedge ]
+ %brcond = icmp ne float* %P, null
+ br i1 %brcond, label %store, label %bb.backedge
+
+store:
+ %scevgep = getelementptr i64* %a, i64 %i
+ store i64 %i, i64* %scevgep
+ br label %bb.backedge
+
+bb.backedge:
+ %i.inc = add nsw i64 %i, 1
+ %exitcond = icmp eq i64 %i.inc, %N
+ br i1 %exitcond, label %return, label %bb
+
+return:
+ ret void
+}
+
+; CHECK: Assumed Context:
+; CHECK: { : }
+
+; CHECK: Stmt_store
+; CHECK: Domain :=
+; CHECK: [N, P] -> { Stmt_store[i0] :
+; CHECK: (P <= -1 and i0 >= 0 and i0 <= -1 + N)
+; CHECK: or
+; CHECK: (P >= 1 and i0 >= 0 and i0 <= -1 + N)
+; CHECK: };
+; CHECK: Scattering :=
+; CHECK: [N, P] -> { Stmt_store[i0] -> scattering[i0] };
+; CHECK: MustWriteAccess := [Reduction Type: NONE]
+; CHECK: [N, P] -> { Stmt_store[i0] -> MemRef_a[i0] };
OpenPOWER on IntegriCloud