From dcb5f1dcf602f8d2951fe834a1a49f787dfea95b Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Thu, 18 Sep 2014 11:14:30 +0000 Subject: [PATCH] Allow the IslExprBuilder to build address of expressions llvm-svn: 218045 --- polly/include/polly/CodeGen/IslExprBuilder.h | 2 ++ polly/lib/CodeGen/BlockGenerators.cpp | 1 + polly/lib/CodeGen/IslExprBuilder.cpp | 29 ++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/polly/include/polly/CodeGen/IslExprBuilder.h b/polly/include/polly/CodeGen/IslExprBuilder.h index 1232a4f6b158..99991fd28c26 100644 --- a/polly/include/polly/CodeGen/IslExprBuilder.h +++ b/polly/include/polly/CodeGen/IslExprBuilder.h @@ -130,6 +130,8 @@ private: llvm::Value *createOpBoolean(__isl_take isl_ast_expr *Expr); llvm::Value *createId(__isl_take isl_ast_expr *Expr); llvm::Value *createInt(__isl_take isl_ast_expr *Expr); + llvm::Value *createOpAddressOf(__isl_take isl_ast_expr *Expr); + llvm::Value *createAccessAddress(__isl_take isl_ast_expr *Expr); }; } diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 52c8ce02bc7b..e2ddfab4834c 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -186,6 +186,7 @@ Value *BlockGenerator::getNewAccessOperand(const MemoryAccess &MA) { PWAccRel = isl_pw_multi_aff_pullback_pw_multi_aff(PWAccRel, PWSchedule); Expr = isl_ast_build_access_from_pw_multi_aff(Build, PWAccRel); + Expr = isl_ast_expr_address_of(Expr); return ExprBuilder->create(Expr); } diff --git a/polly/lib/CodeGen/IslExprBuilder.cpp b/polly/lib/CodeGen/IslExprBuilder.cpp index 28c1444f415a..fe4be5dc2a80 100644 --- a/polly/lib/CodeGen/IslExprBuilder.cpp +++ b/polly/lib/CodeGen/IslExprBuilder.cpp @@ -91,7 +91,7 @@ Value *IslExprBuilder::createOpNAry(__isl_take isl_ast_expr *Expr) { return V; } -Value *IslExprBuilder::createOpAccess(isl_ast_expr *Expr) { +Value *IslExprBuilder::createAccessAddress(isl_ast_expr *Expr) { assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op && "isl ast expression not of type isl_ast_op"); assert(isl_ast_expr_get_op_type(Expr) == isl_ast_op_access && @@ -140,6 +140,12 @@ Value *IslExprBuilder::createOpAccess(isl_ast_expr *Expr) { return Access; } +Value *IslExprBuilder::createOpAccess(isl_ast_expr *Expr) { + Value *Addr = createAccessAddress(Expr); + assert(Addr && "Could not create op access address"); + return Builder.CreateLoad(Addr, Addr->getName() + ".load"); +} + Value *IslExprBuilder::createOpBin(__isl_take isl_ast_expr *Expr) { Value *LHS, *RHS, *Res; Type *MaxType; @@ -355,7 +361,6 @@ Value *IslExprBuilder::createOp(__isl_take isl_ast_expr *Expr) { case isl_ast_op_or_else: case isl_ast_op_call: case isl_ast_op_member: - case isl_ast_op_address_of: llvm_unreachable("Unsupported isl ast expression"); case isl_ast_op_access: return createOpAccess(Expr); @@ -383,11 +388,31 @@ Value *IslExprBuilder::createOp(__isl_take isl_ast_expr *Expr) { case isl_ast_op_ge: case isl_ast_op_gt: return createOpICmp(Expr); + case isl_ast_op_address_of: + return createOpAddressOf(Expr); } llvm_unreachable("Unsupported isl_ast_expr_op kind."); } +Value *IslExprBuilder::createOpAddressOf(__isl_take isl_ast_expr *Expr) { + assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op && + "Expected an isl_ast_expr_op expression."); + assert(isl_ast_expr_get_op_n_arg(Expr) == 1 && "Address of should be unary."); + + isl_ast_expr *Op = isl_ast_expr_get_op_arg(Expr, 0); + assert(isl_ast_expr_get_type(Op) == isl_ast_expr_op && + "Expected address of operator to be an isl_ast_expr_op expression."); + assert(isl_ast_expr_get_op_type(Op) == isl_ast_op_access && + "Expected address of operator to be an access expression."); + + Value *V = createAccessAddress(Op); + + isl_ast_expr_free(Expr); + + return V; +} + Value *IslExprBuilder::createId(__isl_take isl_ast_expr *Expr) { assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_id && "Expression not of type isl_ast_expr_ident");