From 04b909fccaa4741901cb39c486dda7e9e2345114 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Thu, 21 Jul 2016 13:15:51 +0000 Subject: [PATCH] IslExprBuilder: allow to specify an external isl_id to ScopArrayInfo mapping This is useful for external users using IslExprBuilder, in case they cannot embed ScopArrayInfo data into their isl_ids, because the isl_ids either already carry other information or the isl_ids have been created and their user pointers cannot be updated any more. llvm-svn: 276268 --- polly/include/polly/CodeGen/IslExprBuilder.h | 20 ++++++++++++++++++++ polly/lib/CodeGen/IslExprBuilder.cpp | 13 ++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/polly/include/polly/CodeGen/IslExprBuilder.h b/polly/include/polly/CodeGen/IslExprBuilder.h index 12ed91518ca4..b9e6c38fb9ea 100644 --- a/polly/include/polly/CodeGen/IslExprBuilder.h +++ b/polly/include/polly/CodeGen/IslExprBuilder.h @@ -39,6 +39,7 @@ public: } // namespace llvm namespace polly { +class ScopArrayInfo; /// @brief LLVM-IR generator for isl_ast_expr[essions] /// @@ -92,6 +93,25 @@ public: /// @brief A map from isl_ids to llvm::Values. typedef llvm::MapVector> IDToValueTy; + typedef llvm::MapVector IDToScopArrayInfoTy; + + /// @brief A map from isl_ids to ScopArrayInfo objects. + /// + /// This map is used to obtain ScopArrayInfo objects for isl_ids which do not + /// carry a ScopArrayInfo object in their user pointer. This is useful if the + /// construction of ScopArrayInfo objects happens only after references (e.g. + /// in an AST) to an isl_id are generated and the user pointer of the isl_id + /// can not be changed any more. + /// + /// This is useful for external users who just use the IslExprBuilder for + /// code generation. + IDToScopArrayInfoTy *IDToSAI = nullptr; + + /// @brief Set the isl_id to ScopArrayInfo map. + /// + /// @param NewIDToSAI The new isl_id to ScopArrayInfo map to use. + void setIDToSAI(IDToScopArrayInfoTy *NewIDToSAI) { IDToSAI = NewIDToSAI; } + /// @brief Construct an IslExprBuilder. /// /// @param Builder The IRBuilder used to construct the isl_ast_expr[ession]. diff --git a/polly/lib/CodeGen/IslExprBuilder.cpp b/polly/lib/CodeGen/IslExprBuilder.cpp index e7f8de2ba0df..75e35076ddee 100644 --- a/polly/lib/CodeGen/IslExprBuilder.cpp +++ b/polly/lib/CodeGen/IslExprBuilder.cpp @@ -223,7 +223,18 @@ Value *IslExprBuilder::createAccessAddress(isl_ast_expr *Expr) { BaseId = isl_ast_expr_get_id(BaseExpr); isl_ast_expr_free(BaseExpr); - const ScopArrayInfo *SAI = ScopArrayInfo::getFromId(BaseId); + const ScopArrayInfo *SAI = nullptr; + + if (IDToSAI) + SAI = (*IDToSAI)[BaseId]; + + if (!SAI) + SAI = ScopArrayInfo::getFromId(BaseId); + else + isl_id_free(BaseId); + + assert(SAI && "No ScopArrayInfo found for this isl_id."); + Base = SAI->getBasePtr(); if (auto NewBase = GlobalMap.lookup(Base))