From 80ef110ccaab14f8bdadd01de989dea7139b956c Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Fri, 7 Nov 2014 08:31:31 +0000 Subject: [PATCH] [Refactor][NFC] Generalize the creation of ScopArrayInfo objects. Differential Revision: http://reviews.llvm.org/D6031 llvm-svn: 221512 --- polly/include/polly/ScopInfo.h | 5 +++-- polly/include/polly/Support/ScopHelper.h | 4 ++++ polly/lib/Analysis/ScopInfo.cpp | 18 +++++++++--------- polly/lib/Support/ScopHelper.cpp | 6 ++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h index ece1fefb..38576f1 100644 --- a/polly/include/polly/ScopInfo.h +++ b/polly/include/polly/ScopInfo.h @@ -828,8 +828,9 @@ public: //@} /// @brief Return the (possibly new) ScopArrayInfo object for @p Access. - const ScopArrayInfo *getOrCreateScopArrayInfo(const IRAccess &Access, - Instruction *AccessInst); + const ScopArrayInfo * + getOrCreateScopArrayInfo(Value *BasePtr, Type *AccessType, + const SmallVector &Sizes); /// @brief Return the cached ScopArrayInfo object for @p BasePtr. const ScopArrayInfo *getScopArrayInfo(Value *BasePtr); diff --git a/polly/include/polly/Support/ScopHelper.h b/polly/include/polly/Support/ScopHelper.h index ca30c85..9277c22c 100644 --- a/polly/include/polly/Support/ScopHelper.h +++ b/polly/include/polly/Support/ScopHelper.h @@ -15,6 +15,7 @@ #define POLLY_SUPPORT_IRHELPER_H namespace llvm { +class Type; class Instruction; class LoopInfo; class Loop; @@ -52,6 +53,9 @@ bool hasInvokeEdge(const llvm::PHINode *PN); llvm::Value *getPointerOperand(llvm::Instruction &Inst); llvm::BasicBlock *createSingleExitEdge(llvm::Region *R, llvm::Pass *P); +/// @brief Return the type of the access. +llvm::Type *getAccessInstType(llvm::Instruction *AccInst); + /// @brief Simplify the region in a SCoP to have a single unconditional entry /// edge and a single exit edge. /// diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index b3f0550..be65e29 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -728,8 +728,10 @@ void ScopStmt::buildAccesses(TempScop &tempScop) { const IRAccess &Access = AccessPair.first; Instruction *AccessInst = AccessPair.second; - const ScopArrayInfo *SAI = - getParent()->getOrCreateScopArrayInfo(Access, AccessInst); + Type *AccessType = getAccessInstType(AccessInst)->getPointerTo(); + const ScopArrayInfo *SAI = getParent()->getOrCreateScopArrayInfo( + Access.getBase(), AccessType, Access.Sizes); + MemAccs.push_back(new MemoryAccess(Access, AccessInst, this, SAI)); // We do not track locations for scalar memory accesses at the moment. @@ -1482,14 +1484,12 @@ Scop::~Scop() { } } -const ScopArrayInfo *Scop::getOrCreateScopArrayInfo(const IRAccess &Access, - Instruction *AccessInst) { - Value *BasePtr = Access.getBase(); +const ScopArrayInfo * +Scop::getOrCreateScopArrayInfo(Value *BasePtr, Type *AccessType, + const SmallVector &Sizes) { const ScopArrayInfo *&SAI = ScopArrayInfoMap[BasePtr]; - if (!SAI) { - Type *AccessType = getPointerOperand(*AccessInst)->getType(); - SAI = new ScopArrayInfo(BasePtr, AccessType, getIslCtx(), Access.Sizes); - } + if (!SAI) + SAI = new ScopArrayInfo(BasePtr, AccessType, getIslCtx(), Sizes); return SAI; } diff --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp index 9541c8e..1b7b9a2 100644 --- a/polly/lib/Support/ScopHelper.cpp +++ b/polly/lib/Support/ScopHelper.cpp @@ -66,6 +66,12 @@ Value *polly::getPointerOperand(Instruction &Inst) { return 0; } +Type *polly::getAccessInstType(Instruction *AccInst) { + if (StoreInst *Store = dyn_cast(AccInst)) + return Store->getValueOperand()->getType(); + return AccInst->getType(); +} + bool polly::hasInvokeEdge(const PHINode *PN) { for (unsigned i = 0, e = PN->getNumIncomingValues(); i < e; ++i) if (InvokeInst *II = dyn_cast(PN->getIncomingValue(i))) -- 2.7.4