From ed87831113c0edf32eb5c0e4d2e1f5d7d2f3d2a9 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Sun, 3 Aug 2014 01:50:50 +0000 Subject: [PATCH] Allow the IslExprBuilder to generate access operations llvm-svn: 214658 --- polly/include/polly/CodeGen/IslExprBuilder.h | 1 + polly/lib/CodeGen/IslExprBuilder.cpp | 35 +++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/polly/include/polly/CodeGen/IslExprBuilder.h b/polly/include/polly/CodeGen/IslExprBuilder.h index f8eb6fa8d772..c87cd5725e82 100644 --- a/polly/include/polly/CodeGen/IslExprBuilder.h +++ b/polly/include/polly/CodeGen/IslExprBuilder.h @@ -120,6 +120,7 @@ private: llvm::Value *createOp(__isl_take isl_ast_expr *Expr); llvm::Value *createOpUnary(__isl_take isl_ast_expr *Expr); + llvm::Value *createOpAccess(__isl_take isl_ast_expr *Expr); llvm::Value *createOpBin(__isl_take isl_ast_expr *Expr); llvm::Value *createOpNAry(__isl_take isl_ast_expr *Expr); llvm::Value *createOpSelect(__isl_take isl_ast_expr *Expr); diff --git a/polly/lib/CodeGen/IslExprBuilder.cpp b/polly/lib/CodeGen/IslExprBuilder.cpp index 6275c1439d40..8890e4552805 100644 --- a/polly/lib/CodeGen/IslExprBuilder.cpp +++ b/polly/lib/CodeGen/IslExprBuilder.cpp @@ -91,6 +91,38 @@ Value *IslExprBuilder::createOpNAry(__isl_take isl_ast_expr *Expr) { return V; } +Value *IslExprBuilder::createOpAccess(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 && + "not an access isl ast expression"); + assert(isl_ast_expr_get_op_n_arg(Expr) >= 2 && + "We need at least two operands to create a member access."); + + // TODO: Support for multi-dimensional array. + assert(isl_ast_expr_get_op_n_arg(Expr) == 2 && + "Multidimensional access functions are not supported yet"); + + Value *Base = create(isl_ast_expr_get_op_arg(Expr, 0)); + assert(Base->getType()->isPointerTy() && "Access base should be a pointer"); + + Value *Index = create(isl_ast_expr_get_op_arg(Expr, 1)); + assert(Index->getType()->isIntegerTy() && + "Access index should be an integer"); + + // TODO: Change the type of base before we create the GEP. + Type *PtrElTy = Base->getType()->getPointerElementType(); + assert((PtrElTy->isIntOrIntVectorTy() || PtrElTy->isFPOrFPVectorTy()) && + "We do not yet change the type of the access base during code " + "generation."); + + Twine Name = "polly.access." + Base->getName(); + Value *Access = Builder.CreateGEP(Base, Index, Name); + + isl_ast_expr_free(Expr); + return Access; +} + Value *IslExprBuilder::createOpBin(__isl_take isl_ast_expr *Expr) { Value *LHS, *RHS, *Res; Type *MaxType; @@ -303,8 +335,9 @@ 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_access: llvm_unreachable("Unsupported isl ast expression"); + case isl_ast_op_access: + return createOpAccess(Expr); case isl_ast_op_max: case isl_ast_op_min: return createOpNAry(Expr);