[polly] r183635 - Refactor: Move the IRAccess building code to a new function.

Hongbin Zheng etherzhhb at gmail.com
Sun Jun 9 19:52:30 PDT 2013


Author: ether
Date: Sun Jun  9 21:52:30 2013
New Revision: 183635

URL: http://llvm.org/viewvc/llvm-project?rev=183635&view=rev
Log:
Refactor: Move the IRAccess building code to a new function.

Modified:
    polly/trunk/include/polly/TempScopInfo.h
    polly/trunk/lib/Analysis/TempScopInfo.cpp

Modified: polly/trunk/include/polly/TempScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/TempScopInfo.h?rev=183635&r1=183634&r2=183635&view=diff
==============================================================================
--- polly/trunk/include/polly/TempScopInfo.h (original)
+++ polly/trunk/include/polly/TempScopInfo.h Sun Jun  9 21:52:30 2013
@@ -264,6 +264,16 @@ class TempScopInfo : public FunctionPass
   // of Scop.
   TempScop *buildTempScop(Region &R);
 
+  /// @brief Build an instance of IRAccess from the Load/Store instruction.
+  ///
+  /// @param Inst The Load/Store instruction that access the memory
+  /// @param L    The parent loop of the instruction
+  /// @param R    The region on which we are going to build a TempScop
+  ///
+  /// @return     The IRAccess to describe the access function of the
+  ///             instruction.
+  IRAccess buildIRAccess(Instruction *Inst, Loop *L, Region *R);
+
   void buildAccessFunctions(Region &RefRegion, BasicBlock &BB);
 
   void buildLoopBounds(TempScop &Scop);

Modified: polly/trunk/lib/Analysis/TempScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/TempScopInfo.cpp?rev=183635&r1=183634&r2=183635&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/TempScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/TempScopInfo.cpp Sun Jun  9 21:52:30 2013
@@ -73,41 +73,40 @@ void TempScop::printDetail(llvm::raw_ost
                            LoopInfo *LI, const Region *CurR,
                            unsigned ind) const {}
 
+IRAccess TempScopInfo::buildIRAccess(Instruction *Inst, Loop *L, Region *R) {
+  unsigned Size;
+  enum IRAccess::TypeKind Type;
+
+  if (LoadInst *Load = dyn_cast<LoadInst>(Inst)) {
+    Size = TD->getTypeStoreSize(Load->getType());
+    Type = IRAccess::READ;
+  } else {
+    StoreInst *Store = cast<StoreInst>(Inst);
+    Size = TD->getTypeStoreSize(Store->getValueOperand()->getType());
+    Type = IRAccess::WRITE;
+  }
+
+  const SCEV *AccessFunction =
+      SE->getSCEVAtScope(getPointerOperand(*Inst), L);
+  const SCEVUnknown *BasePointer =
+      dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFunction));
+
+  assert(BasePointer && "Could not find base pointer");
+  AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer);
+
+  bool IsAffine = isAffineExpr(R, AccessFunction, *SE, BasePointer->getValue());
+
+  return IRAccess(Type, BasePointer->getValue(), AccessFunction, Size, IsAffine);
+}
+
 void TempScopInfo::buildAccessFunctions(Region &R, BasicBlock &BB) {
   AccFuncSetType Functions;
   Loop *L = LI->getLoopFor(&BB);
 
   for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I) {
-    Instruction &Inst = *I;
-    if (isa<LoadInst>(&Inst) || isa<StoreInst>(&Inst)) {
-      unsigned Size;
-      enum IRAccess::TypeKind Type;
-
-      if (LoadInst *Load = dyn_cast<LoadInst>(&Inst)) {
-        Size = TD->getTypeStoreSize(Load->getType());
-        Type = IRAccess::READ;
-      } else {
-        StoreInst *Store = cast<StoreInst>(&Inst);
-        Size = TD->getTypeStoreSize(Store->getValueOperand()->getType());
-        Type = IRAccess::WRITE;
-      }
-
-      const SCEV *AccessFunction =
-          SE->getSCEVAtScope(getPointerOperand(Inst), L);
-      const SCEVUnknown *BasePointer =
-          dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFunction));
-
-      assert(BasePointer && "Could not find base pointer");
-      AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer);
-
-      bool IsAffine =
-          isAffineExpr(&R, AccessFunction, *SE, BasePointer->getValue());
-
-      Functions.push_back(
-          std::make_pair(IRAccess(Type, BasePointer->getValue(), AccessFunction,
-                                  Size, IsAffine),
-                         &Inst));
-    }
+    Instruction *Inst = I;
+    if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst))
+      Functions.push_back(std::make_pair(buildIRAccess(Inst, L, &R), Inst));
   }
 
   if (Functions.empty())





More information about the llvm-commits mailing list