Index: polly/trunk/include/polly/TempScopInfo.h =================================================================== --- polly/trunk/include/polly/TempScopInfo.h +++ polly/trunk/include/polly/TempScopInfo.h @@ -206,7 +206,7 @@ /// @brief The Function Pass to extract temporary information for Static control /// part in llvm function. /// -class TempScopInfo : public FunctionPass { +class TempScopInfo : public RegionPass { //===-------------------------------------------------------------------===// TempScopInfo(const TempScopInfo &) = delete; const TempScopInfo &operator=(const TempScopInfo &) = delete; @@ -240,8 +240,8 @@ // zero scev every time when we need it. const SCEV *ZeroOffset; - // Mapping regions to the corresponding Scop in current function. - TempScopMapType TempScops; + // The TempScop for this region. + TempScop *TempScopOfRegion; // Clear the context. void clear(); @@ -308,20 +308,19 @@ public: static char ID; - explicit TempScopInfo() : FunctionPass(ID) {} + explicit TempScopInfo() : RegionPass(ID), TempScopOfRegion(nullptr) {} ~TempScopInfo(); - /// @brief Get the temporay Scop information in LLVM IR represent - /// for Region R. + /// @brief Get the temporay Scop information in LLVM IR for this region. /// /// @return The Scop information in LLVM IR represent. - TempScop *getTempScop(const Region *R) const; + TempScop *getTempScop() const; - /// @name FunctionPass interface + /// @name RegionPass interface //@{ virtual void getAnalysisUsage(AnalysisUsage &AU) const; virtual void releaseMemory() { clear(); } - virtual bool runOnFunction(Function &F); + virtual bool runOnRegion(Region *R, RGPassManager &RGM); virtual void print(raw_ostream &OS, const Module *) const; //@} }; Index: polly/trunk/lib/Analysis/ScopInfo.cpp =================================================================== --- polly/trunk/lib/Analysis/ScopInfo.cpp +++ polly/trunk/lib/Analysis/ScopInfo.cpp @@ -1977,7 +1977,7 @@ ScopDetection &SD = getAnalysis(); ScalarEvolution &SE = getAnalysis(); - TempScop *tempScop = getAnalysis().getTempScop(R); + TempScop *tempScop = getAnalysis().getTempScop(); // This region is no Scop. if (!tempScop) { Index: polly/trunk/lib/Analysis/TempScopInfo.cpp =================================================================== --- polly/trunk/lib/Analysis/TempScopInfo.cpp +++ polly/trunk/lib/Analysis/TempScopInfo.cpp @@ -460,34 +460,30 @@ return TScop; } -TempScop *TempScopInfo::getTempScop(const Region *R) const { - TempScopMapType::const_iterator at = TempScops.find(R); - return at == TempScops.end() ? 0 : at->second; -} +TempScop *TempScopInfo::getTempScop() const { return TempScopOfRegion; } void TempScopInfo::print(raw_ostream &OS, const Module *) const { - for (TempScopMapType::const_iterator I = TempScops.begin(), - E = TempScops.end(); - I != E; ++I) - I->second->print(OS, SE, LI); + if (TempScopOfRegion) + TempScopOfRegion->print(OS, SE, LI); } -bool TempScopInfo::runOnFunction(Function &F) { +bool TempScopInfo::runOnRegion(Region *R, RGPassManager &RGM) { + SD = &getAnalysis(); + + if (!SD->isMaxRegionInScop(*R)) + return false; + + Function *F = R->getEntry()->getParent(); DT = &getAnalysis().getDomTree(); PDT = &getAnalysis(); SE = &getAnalysis(); LI = &getAnalysis().getLoopInfo(); - SD = &getAnalysis(); AA = &getAnalysis(); - TD = &F.getParent()->getDataLayout(); - ZeroOffset = SE->getConstant(TD->getIntPtrType(F.getContext()), 0); + TD = &F->getParent()->getDataLayout(); + ZeroOffset = SE->getConstant(TD->getIntPtrType(F->getContext()), 0); - for (ScopDetection::iterator I = SD->begin(), E = SD->end(); I != E; ++I) { - if (!SD->isMaxRegionInScop(**I)) - continue; - Region *R = const_cast(*I); - TempScops.insert(std::make_pair(R, buildTempScop(*R))); - } + assert(!TempScopOfRegion && "Build the TempScop only once"); + TempScopOfRegion = buildTempScop(*R); return false; } @@ -508,8 +504,9 @@ void TempScopInfo::clear() { BBConds.clear(); AccFuncMap.clear(); - DeleteContainerSeconds(TempScops); - TempScops.clear(); + if (TempScopOfRegion) + delete TempScopOfRegion; + TempScopOfRegion = nullptr; } //===----------------------------------------------------------------------===// Index: polly/trunk/lib/CodeGen/CodeGeneration.cpp =================================================================== --- polly/trunk/lib/CodeGen/CodeGeneration.cpp +++ polly/trunk/lib/CodeGen/CodeGeneration.cpp @@ -30,6 +30,7 @@ #include "llvm/IR/Module.h" #include "llvm/IR/Verifier.h" #include "llvm/Support/Debug.h" +#include "llvm/Analysis/PostDominators.h" using namespace polly; using namespace llvm; @@ -170,6 +171,7 @@ AU.addPreserved(); AU.addPreserved(); + AU.addPreserved(); AU.addPreserved(); AU.addPreserved(); AU.addPreserved();