Index: include/polly/CodeGen/BlockGenerators.h =================================================================== --- include/polly/CodeGen/BlockGenerators.h +++ include/polly/CodeGen/BlockGenerators.h @@ -19,20 +19,24 @@ #include "polly/CodeGen/IRBuilder.h" #include "polly/Support/ScopHelper.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "isl/map.h" +#include +#include -struct isl_ast_build; struct isl_id_to_ast_expr; namespace llvm { -class Pass; -class Region; + class ScalarEvolution; -} +} // end namespace llvm + namespace polly { + using namespace llvm; + class ScopStmt; class MemoryAccess; class ScopArrayInfo; @@ -162,7 +166,7 @@ void finalizeSCoP(Scop &S); /// @brief An empty destructor - virtual ~BlockGenerator(){}; + virtual ~BlockGenerator() {} BlockGenerator(const BlockGenerator &) = default; @@ -732,7 +736,7 @@ /// @param BlockGen A generator for basic blocks. RegionGenerator(BlockGenerator &BlockGen) : BlockGenerator(BlockGen) {} - virtual ~RegionGenerator(){}; + ~RegionGenerator() override {} /// @brief Copy the region statement @p Stmt. /// @@ -816,8 +820,8 @@ /// their new values (for values recalculated in the new ScoP, /// but not within this basic block) /// @param BBMap A mapping from old values to their new values in this block. - virtual void generateScalarStores(ScopStmt &Stmt, LoopToScevMapT <S, - ValueMapT &BBMAp) override; + void generateScalarStores(ScopStmt &Stmt, LoopToScevMapT <S, + ValueMapT &BBMAp) override; /// @brief Copy a single PHI instruction. /// @@ -829,9 +833,10 @@ /// @param BBMap A mapping from old values to their new values /// (for values recalculated within this basic block). /// @param LTS A map from old loops to new induction variables as SCEVs. - virtual void copyPHIInstruction(ScopStmt &Stmt, PHINode *Inst, - ValueMapT &BBMap, - LoopToScevMapT <S) override; + void copyPHIInstruction(ScopStmt &Stmt, PHINode *Inst, ValueMapT &BBMap, + LoopToScevMapT <S) override; }; -} -#endif + +} // end namespace polly + +#endif // POLLY_BLOCK_GENERATORS_H Index: include/polly/CodeGen/LoopGenerators.h =================================================================== --- include/polly/CodeGen/LoopGenerators.h +++ include/polly/CodeGen/LoopGenerators.h @@ -11,22 +11,27 @@ // as LLVM-IR. // //===----------------------------------------------------------------------===// + #ifndef POLLY_LOOP_GENERATORS_H #define POLLY_LOOP_GENERATORS_H #include "polly/CodeGen/IRBuilder.h" #include "polly/Support/ScopHelper.h" - #include "llvm/ADT/SetVector.h" -#include "llvm/IR/ValueMap.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Type.h" namespace llvm { + +class Pass; class Value; -class Pass; -class BasicBlock; -} +} // end namespace llvm + namespace polly { + using namespace llvm; /// @brief Create a scalar do/for-style loop. @@ -53,7 +58,7 @@ PollyIRBuilder &Builder, Pass *P, LoopInfo &LI, DominatorTree &DT, BasicBlock *&ExitBlock, ICmpInst::Predicate Predicate, - ScopAnnotator *Annotator = NULL, bool Parallel = false, + ScopAnnotator *Annotator = nullptr, bool Parallel = false, bool UseGuard = true); /// @brief The ParallelLoopGenerator allows to create parallelized loops @@ -216,5 +221,7 @@ SetVector UsedValues, ValueMapT &VMap, Function **SubFn); }; + } // end namespace polly -#endif + +#endif // POLLY_LOOP_GENERATORS_H Index: include/polly/ScopDetection.h =================================================================== --- include/polly/ScopDetection.h +++ include/polly/ScopDetection.h @@ -49,31 +49,40 @@ #include "polly/ScopDetectionDiagnostic.h" #include "polly/Support/ScopHelper.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AliasSetTracker.h" #include "llvm/Analysis/RegionInfo.h" #include "llvm/Pass.h" +#include #include #include #include +#include +#include +#include using namespace llvm; namespace llvm { + class LoopInfo; class Loop; class ScalarEvolution; class SCEV; -class SCEVAddRecExpr; class SCEVUnknown; class CallInst; class Instruction; class Value; class IntrinsicInst; -} +} // end namespace llvm + namespace polly { + typedef std::set ParamSetType; // Description of the shape of an array. @@ -568,7 +577,7 @@ /// @brief Verify if all valid Regions in this Function are still valid /// after some transformations. - void verifyAnalysis() const; + void verifyAnalysis() const override; /// @brief Verify if R is still a valid part of Scop after some /// transformations. @@ -578,18 +587,21 @@ /// @name FunctionPass interface //@{ - virtual void getAnalysisUsage(AnalysisUsage &AU) const; - virtual void releaseMemory(); - virtual bool runOnFunction(Function &F); - virtual void print(raw_ostream &OS, const Module *) const; + void getAnalysisUsage(AnalysisUsage &AU) const override; + void releaseMemory() override; + bool runOnFunction(Function &F) override; + void print(raw_ostream &OS, const Module *) const override; //@} }; } // end namespace polly namespace llvm { + class PassRegistry; + void initializeScopDetectionPass(llvm::PassRegistry &); -} -#endif +} // end namespace llvm + +#endif // POLLY_SCOP_DETECTION_H Index: include/polly/ScopDetectionDiagnostic.h =================================================================== --- include/polly/ScopDetectionDiagnostic.h +++ include/polly/ScopDetectionDiagnostic.h @@ -17,30 +17,37 @@ // to diagnose the error and generate a helpful error message. // //===----------------------------------------------------------------------===// + #ifndef POLLY_SCOP_DETECTION_DIAGNOSTIC_H #define POLLY_SCOP_DETECTION_DIAGNOSTIC_H #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/Statistic.h" -#include "llvm/ADT/Twine.h" #include "llvm/Analysis/AliasSetTracker.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Value.h" #include "llvm/Support/Casting.h" +#include #include #include +#include +#include using namespace llvm; namespace llvm { + +class BasicBlock; +class Loop; +class Region; class SCEV; -class BasicBlock; class Value; -class Region; -} +} // end namespace llvm + namespace polly { /// @brief Type to hold region delimitors (entry & exit block). @@ -134,9 +141,7 @@ /// regions amenable to Polly. /// /// @return A short message representing this error. - virtual std::string getEndUserMessage() const { - return "Unspecified error."; - }; + virtual std::string getEndUserMessage() const { return "Unspecified error."; } /// @brief Get the source location of this error. /// @@ -203,8 +208,8 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; + std::string getMessage() const override; + const DebugLoc &getDebugLoc() const override; //@} }; @@ -225,9 +230,9 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual std::string getEndUserMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; + std::string getMessage() const override; + std::string getEndUserMessage() const override; + const DebugLoc &getDebugLoc() const override; //@} }; @@ -252,9 +257,7 @@ /// @name RejectReason interface //@{ - virtual const DebugLoc &getDebugLoc() const override { - return Inst->getDebugLoc(); - }; + const DebugLoc &getDebugLoc() const override { return Inst->getDebugLoc(); } //@} }; @@ -277,7 +280,7 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; + std::string getMessage() const override; //@} }; @@ -302,7 +305,7 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; + std::string getMessage() const override; //@} }; @@ -325,7 +328,7 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; + std::string getMessage() const override; //@} }; @@ -358,7 +361,7 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; + std::string getMessage() const override; //@} }; @@ -377,7 +380,7 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; + std::string getMessage() const override; //@} }; @@ -396,7 +399,7 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; + std::string getMessage() const override; //@} }; @@ -419,8 +422,8 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual std::string getEndUserMessage() const override; + std::string getMessage() const override; + std::string getEndUserMessage() const override; //@} }; @@ -450,8 +453,8 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual std::string getEndUserMessage() const override; + std::string getMessage() const override; + std::string getEndUserMessage() const override; //@} }; @@ -474,8 +477,8 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual std::string getEndUserMessage() const override; + std::string getMessage() const override; + std::string getEndUserMessage() const override; //@} }; @@ -505,9 +508,9 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; - virtual std::string getEndUserMessage() const override; + std::string getMessage() const override; + const DebugLoc &getDebugLoc() const override; + std::string getEndUserMessage() const override; //@} }; @@ -529,9 +532,9 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; - virtual std::string getEndUserMessage() const override; + std::string getMessage() const override; + const DebugLoc &getDebugLoc() const override; + std::string getEndUserMessage() const override; //@} }; @@ -567,9 +570,9 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; - virtual std::string getEndUserMessage() const override; + std::string getMessage() const override; + const DebugLoc &getDebugLoc() const override; + std::string getEndUserMessage() const override; //@} }; @@ -587,7 +590,7 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; + std::string getMessage() const override; //@} }; @@ -609,8 +612,8 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; + std::string getMessage() const override; + const DebugLoc &getDebugLoc() const override; //@} }; @@ -630,8 +633,8 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; + std::string getMessage() const override; + const DebugLoc &getDebugLoc() const override; //@} }; @@ -651,8 +654,8 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; + std::string getMessage() const override; + const DebugLoc &getDebugLoc() const override; //@} }; @@ -672,8 +675,8 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; + std::string getMessage() const override; + const DebugLoc &getDebugLoc() const override; //@} }; @@ -693,9 +696,9 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual std::string getEndUserMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; + std::string getMessage() const override; + std::string getEndUserMessage() const override; + const DebugLoc &getDebugLoc() const override; //@} }; @@ -717,12 +720,12 @@ /// @name RejectReason interface //@{ - virtual std::string getMessage() const override; - virtual const DebugLoc &getDebugLoc() const override; - virtual std::string getEndUserMessage() const override; + std::string getMessage() const override; + const DebugLoc &getDebugLoc() const override; + std::string getEndUserMessage() const override; //@} }; -} // namespace polly +} // end namespace polly #endif // POLLY_SCOP_DETECTION_DIAGNOSTIC_H Index: include/polly/ScopInfo.h =================================================================== --- include/polly/ScopInfo.h +++ include/polly/ScopInfo.h @@ -22,29 +22,49 @@ #include "polly/ScopDetection.h" #include "polly/Support/SCEVAffinator.h" - +#include "polly/Support/ScopHelper.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/MapVector.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Analysis/RegionPass.h" +#include "llvm/Analysis/ScalarEvolutionExpressions.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/ValueHandle.h" #include "isl/aff.h" #include "isl/ctx.h" #include "isl/set.h" - +#include +#include #include #include +#include +#include +#include +#include +#include +#include +#include using namespace llvm; namespace llvm { + class AssumptionCache; class Loop; class LoopInfo; class PHINode; class ScalarEvolution; class SCEV; -class SCEVAddRecExpr; class Type; -} +} // end namespace llvm + struct isl_ctx; struct isl_map; struct isl_basic_map; @@ -54,7 +74,6 @@ struct isl_union_map; struct isl_space; struct isl_ast_build; -struct isl_constraint; struct isl_pw_aff; struct isl_pw_multi_aff; struct isl_schedule; @@ -274,7 +293,7 @@ /// @brief The set of derived indirect SAIs for this origin SAI. const SmallPtrSetImpl &getDerivedSAIs() const { return DerivedSAIs; - }; + } /// @brief Return the number of dimensions. unsigned getNumberOfDimensions() const { @@ -320,7 +339,7 @@ __isl_give isl_id *getBasePtrId() const; /// @brief Is this array info modeling an llvm::Value? - bool isValueKind() const { return Kind == MK_Value; }; + bool isValueKind() const { return Kind == MK_Value; } /// @brief Is this array info modeling special PHI node memory? /// @@ -332,13 +351,13 @@ /// original PHI node as virtual base pointer, we have this additional /// attribute to distinguish the PHI node specific array modeling from the /// normal scalar array modeling. - bool isPHIKind() const { return Kind == MK_PHI; }; + bool isPHIKind() const { return Kind == MK_PHI; } /// @brief Is this array info modeling an MK_ExitPHI? - bool isExitPHIKind() const { return Kind == MK_ExitPHI; }; + bool isExitPHIKind() const { return Kind == MK_ExitPHI; } /// @brief Is this array info modeling an array? - bool isArrayKind() const { return Kind == MK_Array; }; + bool isArrayKind() const { return Kind == MK_Array; } /// @brief Dump a readable representation to stderr. void dump() const; @@ -1755,7 +1774,7 @@ LoopStackElement(Loop *L, __isl_give isl_schedule *S, unsigned NumBlocksProcessed) - : L(L), Schedule(S), NumBlocksProcessed(NumBlocksProcessed){}; + : L(L), Schedule(S), NumBlocksProcessed(NumBlocksProcessed) {} } LoopStackElementTy; /// @brief The loop stack used for schedule construction. @@ -1827,7 +1846,7 @@ /// AccFuncSetType *getAccessFunctions(const BasicBlock *BB) { AccFuncMapType::iterator at = AccFuncMap.find(BB); - return at != AccFuncMap.end() ? &(at->second) : 0; + return at != AccFuncMap.end() ? &(at->second) : nullptr; } ScalarEvolution *getSE() const; @@ -2502,7 +2521,7 @@ static char ID; // Pass identification, replacement for typeid ScopInfoRegionPass() : RegionPass(ID) {} - ~ScopInfoRegionPass() {} + ~ScopInfoRegionPass() override {} /// @brief Build ScopBuilder object, which constructs Polly IR of static /// control part for the current SESE-Region. @@ -2534,8 +2553,11 @@ } // end namespace polly namespace llvm { + class PassRegistry; + void initializeScopInfoRegionPassPass(llvm::PassRegistry &); -} -#endif +} // end namespace llvm + +#endif // POLLY_SCOP_INFO_H Index: include/polly/ScopPass.h =================================================================== --- include/polly/ScopPass.h +++ include/polly/ScopPass.h @@ -23,6 +23,7 @@ using namespace llvm; namespace polly { + class Scop; /// ScopPass - This class adapts the RegionPass interface to allow convenient @@ -32,7 +33,7 @@ Scop *S; protected: - explicit ScopPass(char &ID) : RegionPass(ID), S(0) {} + explicit ScopPass(char &ID) : RegionPass(ID), S(nullptr) {} /// runOnScop - This method must be overloaded to perform the /// desired Polyhedral transformation or analysis. @@ -40,18 +41,18 @@ virtual bool runOnScop(Scop &S) = 0; /// @brief Print method for SCoPs. - virtual void printScop(raw_ostream &OS, Scop &S) const {}; + virtual void printScop(raw_ostream &OS, Scop &S) const {} /// getAnalysisUsage - Subclasses that override getAnalysisUsage /// must call this. /// - virtual void getAnalysisUsage(AnalysisUsage &AU) const override; + void getAnalysisUsage(AnalysisUsage &AU) const override; private: bool runOnRegion(Region *R, RGPassManager &RGM) override; void print(raw_ostream &OS, const Module *) const override; }; -} // End llvm namespace +} // end namespace polly -#endif +#endif // POLLY_SCOP_PASS_H Index: lib/Analysis/ScopDetection.cpp =================================================================== --- lib/Analysis/ScopDetection.cpp +++ lib/Analysis/ScopDetection.cpp @@ -45,7 +45,6 @@ //===----------------------------------------------------------------------===// #include "polly/ScopDetection.h" -#include "polly/CodeGen/CodeGeneration.h" #include "polly/LinkAllPasses.h" #include "polly/Options.h" #include "polly/ScopDetectionDiagnostic.h" @@ -54,18 +53,35 @@ #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/LoopInfo.h" -#include "llvm/Analysis/PostDominators.h" -#include "llvm/Analysis/RegionIterator.h" +#include "llvm/Analysis/MemoryLocation.h" +#include "llvm/Analysis/RegionInfo.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" -#include "llvm/IR/DebugInfo.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" +#include "llvm/IR/Dominators.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Metadata.h" +#include "llvm/PassAnalysisSupport.h" +#include "llvm/PassSupport.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include +#include "llvm/Support/raw_ostream.h" +#include +#include #include +#include +#include using namespace llvm; using namespace polly; @@ -204,7 +220,7 @@ : DiagnosticInfo(PluginDiagnosticKind, DS_Note), F(F), FileName(FileName), EntryLine(EntryLine), ExitLine(ExitLine) {} - virtual void print(DiagnosticPrinter &DP) const; + void print(DiagnosticPrinter &DP) const override; static bool classof(const DiagnosticInfo *DI) { return DI->getKind() == PluginDiagnosticKind; @@ -289,7 +305,6 @@ bool ScopDetection::addOverApproximatedRegion(Region *AR, DetectionContext &Context) const { - // If we already know about Ar we can exit. if (!Context.NonAffineSubRegionSet.insert(AR)) return true; @@ -323,7 +338,6 @@ bool ScopDetection::isAffine(const SCEV *S, Loop *Scope, DetectionContext &Context) const { - InvariantLoadsSetTy AccessILS; if (!isAffineExpr(&Context.CurRegion, Scope, S, *SE, &AccessILS)) return false; @@ -357,7 +371,6 @@ bool ScopDetection::isValidBranch(BasicBlock &BB, BranchInst *BI, Value *Condition, bool IsLoopBranch, DetectionContext &Context) const { - if (BinaryOperator *BinOp = dyn_cast(Condition)) { auto Opcode = BinOp->getOpcode(); if (Opcode == Instruction::And || Opcode == Instruction::Or) { @@ -452,7 +465,7 @@ Function *CalledFunction = CI.getCalledFunction(); // Indirect calls are not supported. - if (CalledFunction == 0) + if (CalledFunction == nullptr) return false; if (AllowModrefCall) { @@ -665,7 +678,7 @@ for (const auto &Pair : Context.Accesses[BasePointer]) { std::vector MaxTerms; SCEVRemoveMax::remove(*SE, Pair.second, &MaxTerms); - if (MaxTerms.size() > 0) { + if (!MaxTerms.empty()) { Terms.insert(Terms.begin(), MaxTerms.begin(), MaxTerms.end()); continue; } @@ -848,7 +861,6 @@ bool ScopDetection::isValidAccess(Instruction *Inst, const SCEV *AF, const SCEVUnknown *BP, DetectionContext &Context) const { - if (!BP) return invalid(Context, /*Assert=*/true, Inst); @@ -1131,6 +1143,7 @@ return LastValidRegion.release(); } + static bool regionWithoutLoops(Region &R, LoopInfo *LI) { for (const BasicBlock *BB : R.blocks()) if (R.contains(LI->getLoopFor(BB)))