Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1 | //===----- ScopDetection.cpp - Detect Scops --------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Detect the maximal Scops of a function. |
| 11 | // |
| 12 | // A static control part (Scop) is a subgraph of the control flow graph (CFG) |
| 13 | // that only has statically known control flow and can therefore be described |
| 14 | // within the polyhedral model. |
| 15 | // |
| 16 | // Every Scop fullfills these restrictions: |
| 17 | // |
| 18 | // * It is a single entry single exit region |
| 19 | // |
| 20 | // * Only affine linear bounds in the loops |
| 21 | // |
| 22 | // Every natural loop in a Scop must have a number of loop iterations that can |
| 23 | // be described as an affine linear function in surrounding loop iterators or |
| 24 | // parameters. (A parameter is a scalar that does not change its value during |
| 25 | // execution of the Scop). |
| 26 | // |
| 27 | // * Only comparisons of affine linear expressions in conditions |
| 28 | // |
| 29 | // * All loops and conditions perfectly nested |
| 30 | // |
| 31 | // The control flow needs to be structured such that it could be written using |
| 32 | // just 'for' and 'if' statements, without the need for any 'goto', 'break' or |
| 33 | // 'continue'. |
| 34 | // |
| 35 | // * Side effect free functions call |
| 36 | // |
| 37 | // Only function calls and intrinsics that do not have side effects are allowed |
| 38 | // (readnone). |
| 39 | // |
| 40 | // The Scop detection finds the largest Scops by checking if the largest |
| 41 | // region is a Scop. If this is not the case, its canonical subregions are |
| 42 | // checked until a region is a Scop. It is now tried to extend this Scop by |
| 43 | // creating a larger non canonical region. |
| 44 | // |
| 45 | //===----------------------------------------------------------------------===// |
| 46 | |
Tobias Grosser | ecfe21b | 2013-03-20 18:03:18 +0000 | [diff] [blame] | 47 | #include "polly/CodeGen/BlockGenerators.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 48 | #include "polly/LinkAllPasses.h" |
Tobias Grosser | 637bd63 | 2013-05-07 07:31:10 +0000 | [diff] [blame] | 49 | #include "polly/Options.h" |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 50 | #include "polly/ScopDetectionDiagnostic.h" |
Tobias Grosser | ecfe21b | 2013-03-20 18:03:18 +0000 | [diff] [blame] | 51 | #include "polly/ScopDetection.h" |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 52 | #include "polly/Support/SCEVValidator.h" |
Tobias Grosser | 8362818 | 2013-05-07 08:11:54 +0000 | [diff] [blame] | 53 | #include "polly/Support/ScopHelper.h" |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 54 | #include "polly/CodeGen/CodeGeneration.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 55 | #include "llvm/ADT/Statistic.h" |
| 56 | #include "llvm/Analysis/AliasAnalysis.h" |
Tobias Grosser | 6e9f25a | 2011-11-09 22:35:00 +0000 | [diff] [blame] | 57 | #include "llvm/Analysis/LoopInfo.h" |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 58 | #include "llvm/Analysis/PostDominators.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 59 | #include "llvm/Analysis/RegionIterator.h" |
Tobias Grosser | 6e9f25a | 2011-11-09 22:35:00 +0000 | [diff] [blame] | 60 | #include "llvm/Analysis/ScalarEvolution.h" |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 61 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
Chandler Carruth | 6b96c24 | 2014-03-06 00:47:27 +0000 | [diff] [blame] | 62 | #include "llvm/IR/DebugInfo.h" |
Johannes Doerfert | 3f500fa | 2015-01-25 18:07:30 +0000 | [diff] [blame] | 63 | #include "llvm/IR/IntrinsicInst.h" |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 64 | #include "llvm/IR/DiagnosticInfo.h" |
| 65 | #include "llvm/IR/DiagnosticPrinter.h" |
Chandler Carruth | 6b96c24 | 2014-03-06 00:47:27 +0000 | [diff] [blame] | 66 | #include "llvm/IR/LLVMContext.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 67 | #include "llvm/Support/Debug.h" |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 68 | #include <set> |
| 69 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 70 | using namespace llvm; |
| 71 | using namespace polly; |
| 72 | |
Chandler Carruth | 95fef94 | 2014-04-22 03:30:19 +0000 | [diff] [blame] | 73 | #define DEBUG_TYPE "polly-detect" |
| 74 | |
Sebastian Pop | 8fe6d11 | 2013-05-30 17:47:32 +0000 | [diff] [blame] | 75 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 76 | DetectScopsWithoutLoops("polly-detect-scops-in-functions-without-loops", |
| 77 | cl::desc("Detect scops in functions without loops"), |
| 78 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 79 | cl::cat(PollyCategory)); |
Sebastian Pop | 8fe6d11 | 2013-05-30 17:47:32 +0000 | [diff] [blame] | 80 | |
Sebastian Pop | 2c9ec2e | 2013-06-03 16:35:37 +0000 | [diff] [blame] | 81 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 82 | DetectRegionsWithoutLoops("polly-detect-scops-in-regions-without-loops", |
| 83 | cl::desc("Detect scops in regions without loops"), |
| 84 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 85 | cl::cat(PollyCategory)); |
Sebastian Pop | 2c9ec2e | 2013-06-03 16:35:37 +0000 | [diff] [blame] | 86 | |
Tobias Grosser | d1e33e7 | 2015-02-19 05:31:07 +0000 | [diff] [blame] | 87 | static cl::opt<bool> DetectUnprofitable("polly-detect-unprofitable", |
| 88 | cl::desc("Detect unprofitable scops"), |
| 89 | cl::Hidden, cl::init(false), |
| 90 | cl::ZeroOrMore, cl::cat(PollyCategory)); |
| 91 | |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 92 | static cl::opt<std::string> OnlyFunction( |
| 93 | "polly-only-func", |
| 94 | cl::desc("Only run on functions that contain a certain string"), |
| 95 | cl::value_desc("string"), cl::ValueRequired, cl::init(""), |
| 96 | cl::cat(PollyCategory)); |
Tobias Grosser | 2ff8723 | 2011-10-23 11:17:06 +0000 | [diff] [blame] | 97 | |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 98 | static cl::opt<std::string> OnlyRegion( |
| 99 | "polly-only-region", |
| 100 | cl::desc("Only run on certain regions (The provided identifier must " |
| 101 | "appear in the name of the region's entry block"), |
| 102 | cl::value_desc("identifier"), cl::ValueRequired, cl::init(""), |
| 103 | cl::cat(PollyCategory)); |
Tobias Grosser | 4449e52 | 2014-01-27 14:24:53 +0000 | [diff] [blame] | 104 | |
Tobias Grosser | 60cd932 | 2011-11-10 12:47:26 +0000 | [diff] [blame] | 105 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 106 | IgnoreAliasing("polly-ignore-aliasing", |
| 107 | cl::desc("Ignore possible aliasing of the array bases"), |
| 108 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 109 | cl::cat(PollyCategory)); |
Tobias Grosser | 2ff8723 | 2011-10-23 11:17:06 +0000 | [diff] [blame] | 110 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 111 | bool polly::PollyUseRuntimeAliasChecks; |
| 112 | static cl::opt<bool, true> XPollyUseRuntimeAliasChecks( |
| 113 | "polly-use-runtime-alias-checks", |
| 114 | cl::desc("Use runtime alias checks to resolve possible aliasing."), |
| 115 | cl::location(PollyUseRuntimeAliasChecks), cl::Hidden, cl::ZeroOrMore, |
| 116 | cl::init(true), cl::cat(PollyCategory)); |
| 117 | |
Tobias Grosser | 637bd63 | 2013-05-07 07:31:10 +0000 | [diff] [blame] | 118 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 119 | ReportLevel("polly-report", |
| 120 | cl::desc("Print information about the activities of Polly"), |
| 121 | cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Tobias Grosser | 531891e | 2012-11-01 16:45:20 +0000 | [diff] [blame] | 122 | |
| 123 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 124 | AllowNonAffine("polly-allow-nonaffine", |
| 125 | cl::desc("Allow non affine access functions in arrays"), |
| 126 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 127 | cl::cat(PollyCategory)); |
Tobias Grosser | a187964 | 2011-12-20 10:43:14 +0000 | [diff] [blame] | 128 | |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 129 | static cl::opt<bool> AllowNonAffineSubRegions( |
| 130 | "polly-allow-nonaffine-branches", |
| 131 | cl::desc("Allow non affine conditions for branches"), cl::Hidden, |
Johannes Doerfert | a36842f | 2015-02-26 11:09:24 +0000 | [diff] [blame] | 132 | cl::init(true), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 133 | |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 134 | static cl::opt<bool> |
| 135 | AllowNonAffineSubLoops("polly-allow-nonaffine-loops", |
| 136 | cl::desc("Allow non affine conditions for loops"), |
| 137 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 138 | cl::cat(PollyCategory)); |
| 139 | |
Tobias Grosser | bfbc369 | 2015-01-09 00:01:33 +0000 | [diff] [blame] | 140 | static cl::opt<bool> AllowUnsigned("polly-allow-unsigned", |
| 141 | cl::desc("Allow unsigned expressions"), |
| 142 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 143 | cl::cat(PollyCategory)); |
| 144 | |
Tobias Grosser | c7d3fc5 | 2013-07-25 03:02:29 +0000 | [diff] [blame] | 145 | static cl::opt<bool, true> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 146 | TrackFailures("polly-detect-track-failures", |
| 147 | cl::desc("Track failure strings in detecting scop regions"), |
| 148 | cl::location(PollyTrackFailures), cl::Hidden, cl::ZeroOrMore, |
Andreas Simbuerger | 3efe40b | 2014-08-17 10:09:03 +0000 | [diff] [blame] | 149 | cl::init(true), cl::cat(PollyCategory)); |
Tobias Grosser | c7d3fc5 | 2013-07-25 03:02:29 +0000 | [diff] [blame] | 150 | |
Andreas Simbuerger | 0447240 | 2014-05-24 09:25:10 +0000 | [diff] [blame] | 151 | static cl::opt<bool> KeepGoing("polly-detect-keep-going", |
| 152 | cl::desc("Do not fail on the first error."), |
| 153 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 154 | cl::cat(PollyCategory)); |
| 155 | |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 156 | static cl::opt<bool, true> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 157 | PollyDelinearizeX("polly-delinearize", |
| 158 | cl::desc("Delinearize array access functions"), |
| 159 | cl::location(PollyDelinearize), cl::Hidden, |
Tobias Grosser | 6973cb6 | 2015-03-08 15:21:18 +0000 | [diff] [blame] | 160 | cl::ZeroOrMore, cl::init(true), cl::cat(PollyCategory)); |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 161 | |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 162 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 163 | VerifyScops("polly-detect-verify", |
| 164 | cl::desc("Verify the detected SCoPs after each transformation"), |
| 165 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 166 | cl::cat(PollyCategory)); |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 167 | |
Johannes Doerfert | 0ff23ec | 2015-02-06 20:13:15 +0000 | [diff] [blame] | 168 | static cl::opt<bool, true> XPollyModelPHINodes( |
| 169 | "polly-model-phi-nodes", |
| 170 | cl::desc("Allow PHI nodes in the input [Unsafe with code-generation!]."), |
| 171 | cl::location(PollyModelPHINodes), cl::Hidden, cl::ZeroOrMore, |
| 172 | cl::init(false), cl::cat(PollyCategory)); |
| 173 | |
| 174 | bool polly::PollyModelPHINodes = false; |
Tobias Grosser | c7d3fc5 | 2013-07-25 03:02:29 +0000 | [diff] [blame] | 175 | bool polly::PollyTrackFailures = false; |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 176 | bool polly::PollyDelinearize = false; |
Johannes Doerfert | 43e1ead | 2014-07-15 21:06:48 +0000 | [diff] [blame] | 177 | StringRef polly::PollySkipFnAttr = "polly.skip.fn"; |
Tobias Grosser | c7d3fc5 | 2013-07-25 03:02:29 +0000 | [diff] [blame] | 178 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 179 | //===----------------------------------------------------------------------===// |
| 180 | // Statistics. |
| 181 | |
| 182 | STATISTIC(ValidRegion, "Number of regions that a valid part of Scop"); |
| 183 | |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 184 | class DiagnosticScopFound : public DiagnosticInfo { |
| 185 | private: |
| 186 | static int PluginDiagnosticKind; |
| 187 | |
| 188 | Function &F; |
| 189 | std::string FileName; |
| 190 | unsigned EntryLine, ExitLine; |
| 191 | |
| 192 | public: |
Tobias Grosser | 1b12f46 | 2013-12-18 11:14:36 +0000 | [diff] [blame] | 193 | DiagnosticScopFound(Function &F, std::string FileName, unsigned EntryLine, |
| 194 | unsigned ExitLine) |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 195 | : DiagnosticInfo(PluginDiagnosticKind, DS_Note), F(F), FileName(FileName), |
Tobias Grosser | 1b12f46 | 2013-12-18 11:14:36 +0000 | [diff] [blame] | 196 | EntryLine(EntryLine), ExitLine(ExitLine) {} |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 197 | |
| 198 | virtual void print(DiagnosticPrinter &DP) const; |
| 199 | |
| 200 | static bool classof(const DiagnosticInfo *DI) { |
| 201 | return DI->getKind() == PluginDiagnosticKind; |
| 202 | } |
| 203 | }; |
| 204 | |
| 205 | int DiagnosticScopFound::PluginDiagnosticKind = 10; |
| 206 | |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 207 | void DiagnosticScopFound::print(DiagnosticPrinter &DP) const { |
Tobias Grosser | 1b12f46 | 2013-12-18 11:14:36 +0000 | [diff] [blame] | 208 | DP << "Polly detected an optimizable loop region (scop) in function '" << F |
| 209 | << "'\n"; |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 210 | |
| 211 | if (FileName.empty()) { |
| 212 | DP << "Scop location is unknown. Compile with debug info " |
| 213 | "(-g) to get more precise information. "; |
Tobias Grosser | 1b12f46 | 2013-12-18 11:14:36 +0000 | [diff] [blame] | 214 | return; |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | DP << FileName << ":" << EntryLine << ": Start of scop\n"; |
| 218 | DP << FileName << ":" << ExitLine << ": End of scop"; |
| 219 | } |
| 220 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 221 | //===----------------------------------------------------------------------===// |
| 222 | // ScopDetection. |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 223 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 224 | ScopDetection::ScopDetection() : FunctionPass(ID) { |
| 225 | if (!PollyUseRuntimeAliasChecks) |
| 226 | return; |
| 227 | |
Johannes Doerfert | 928229f | 2014-09-29 17:06:29 +0000 | [diff] [blame] | 228 | // Disable runtime alias checks if we ignore aliasing all together. |
| 229 | if (IgnoreAliasing) { |
| 230 | PollyUseRuntimeAliasChecks = false; |
| 231 | return; |
| 232 | } |
| 233 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 234 | if (AllowNonAffine) { |
| 235 | DEBUG(errs() << "WARNING: We disable runtime alias checks as non affine " |
| 236 | "accesses are enabled.\n"); |
| 237 | PollyUseRuntimeAliasChecks = false; |
| 238 | } |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 241 | template <class RR, typename... Args> |
| 242 | inline bool ScopDetection::invalid(DetectionContext &Context, bool Assert, |
| 243 | Args &&... Arguments) const { |
| 244 | |
| 245 | if (!Context.Verifying) { |
Andreas Simbuerger | 4870e09 | 2014-05-24 09:25:01 +0000 | [diff] [blame] | 246 | RejectLog &Log = Context.Log; |
| 247 | std::shared_ptr<RR> RejectReason = std::make_shared<RR>(Arguments...); |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 248 | |
Andreas Simbuerger | 8a00c9b | 2014-05-24 09:25:06 +0000 | [diff] [blame] | 249 | if (PollyTrackFailures) |
Andreas Simbuerger | 4870e09 | 2014-05-24 09:25:01 +0000 | [diff] [blame] | 250 | Log.report(RejectReason); |
Andreas Simbuerger | 4870e09 | 2014-05-24 09:25:01 +0000 | [diff] [blame] | 251 | |
| 252 | DEBUG(dbgs() << RejectReason->getMessage()); |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 253 | DEBUG(dbgs() << "\n"); |
| 254 | } else { |
| 255 | assert(!Assert && "Verification of detected scop failed"); |
| 256 | } |
| 257 | |
| 258 | return false; |
| 259 | } |
| 260 | |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 261 | bool ScopDetection::isMaxRegionInScop(const Region &R, bool Verify) const { |
| 262 | if (!ValidRegions.count(&R)) |
| 263 | return false; |
| 264 | |
Johannes Doerfert | 3f1c285 | 2015-02-19 18:11:50 +0000 | [diff] [blame] | 265 | if (Verify) { |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 266 | BoxedLoopsSetTy DummyBoxedLoopsSet; |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 267 | NonAffineSubRegionSetTy DummyNonAffineSubRegionSet; |
| 268 | DetectionContext Context(const_cast<Region &>(R), *AA, |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 269 | DummyNonAffineSubRegionSet, DummyBoxedLoopsSet, |
| 270 | false /*verifying*/); |
Johannes Doerfert | 3f1c285 | 2015-02-19 18:11:50 +0000 | [diff] [blame] | 271 | return isValidRegion(Context); |
| 272 | } |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 273 | |
| 274 | return true; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Tobias Grosser | 4f129a6 | 2011-10-08 00:30:55 +0000 | [diff] [blame] | 277 | std::string ScopDetection::regionIsInvalidBecause(const Region *R) const { |
Andreas Simbuerger | 8a00c9b | 2014-05-24 09:25:06 +0000 | [diff] [blame] | 278 | if (!RejectLogs.count(R)) |
Tobias Grosser | 4f129a6 | 2011-10-08 00:30:55 +0000 | [diff] [blame] | 279 | return ""; |
| 280 | |
Andreas Simbuerger | 8a00c9b | 2014-05-24 09:25:06 +0000 | [diff] [blame] | 281 | // Get the first error we found. Even in keep-going mode, this is the first |
| 282 | // reason that caused the candidate to be rejected. |
| 283 | RejectLog Errors = RejectLogs.at(R); |
Andreas Simbuerger | 83ed861 | 2014-06-12 07:25:08 +0000 | [diff] [blame] | 284 | |
| 285 | // This can happen when we marked a region invalid, but didn't track |
| 286 | // an error for it. |
| 287 | if (Errors.size() == 0) |
| 288 | return ""; |
| 289 | |
| 290 | RejectReasonPtr RR = *Errors.begin(); |
| 291 | return RR->getMessage(); |
Tobias Grosser | 4f129a6 | 2011-10-08 00:30:55 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 294 | bool ScopDetection::addOverApproximatedRegion(Region *AR, |
| 295 | DetectionContext &Context) const { |
| 296 | |
| 297 | // If we already know about Ar we can exit. |
| 298 | if (!Context.NonAffineSubRegionSet.insert(AR)) |
| 299 | return true; |
| 300 | |
| 301 | // All loops in the region have to be overapproximated too if there |
| 302 | // are accesses that depend on the iteration count. |
| 303 | for (BasicBlock *BB : AR->blocks()) { |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 304 | Loop *L = LI->getLoopFor(BB); |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 305 | if (AR->contains(L)) |
| 306 | Context.BoxedLoopsSet.insert(L); |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 307 | } |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 308 | |
| 309 | return (AllowNonAffineSubLoops || Context.BoxedLoopsSet.empty()); |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 312 | bool ScopDetection::isValidCFG(BasicBlock &BB, |
| 313 | DetectionContext &Context) const { |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 314 | Region &CurRegion = Context.CurRegion; |
| 315 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 316 | TerminatorInst *TI = BB.getTerminator(); |
| 317 | |
| 318 | // Return instructions are only valid if the region is the top level region. |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 319 | if (isa<ReturnInst>(TI) && !CurRegion.getExit() && TI->getNumOperands() == 0) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 320 | return true; |
| 321 | |
| 322 | BranchInst *Br = dyn_cast<BranchInst>(TI); |
| 323 | |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 324 | if (!Br) |
| 325 | return invalid<ReportNonBranchTerminator>(Context, /*Assert=*/true, &BB); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 326 | |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 327 | if (Br->isUnconditional()) |
| 328 | return true; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 329 | |
| 330 | Value *Condition = Br->getCondition(); |
| 331 | |
| 332 | // UndefValue is not allowed as condition. |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 333 | if (isa<UndefValue>(Condition)) |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 334 | return invalid<ReportUndefCond>(Context, /*Assert=*/true, Br, &BB); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 335 | |
| 336 | // Only Constant and ICmpInst are allowed as condition. |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 337 | if (!(isa<Constant>(Condition) || isa<ICmpInst>(Condition))) { |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 338 | if (!AllowNonAffineSubRegions || |
| 339 | !addOverApproximatedRegion(RI->getRegionFor(&BB), Context)) |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 340 | return invalid<ReportInvalidCond>(Context, /*Assert=*/true, Br, &BB); |
| 341 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 342 | |
| 343 | // Allow perfectly nested conditions. |
| 344 | assert(Br->getNumSuccessors() == 2 && "Unexpected number of successors"); |
| 345 | |
| 346 | if (ICmpInst *ICmp = dyn_cast<ICmpInst>(Condition)) { |
| 347 | // Unsigned comparisons are not allowed. They trigger overflow problems |
| 348 | // in the code generation. |
| 349 | // |
| 350 | // TODO: This is not sufficient and just hides bugs. However it does pretty |
| 351 | // well. |
Tobias Grosser | bfbc369 | 2015-01-09 00:01:33 +0000 | [diff] [blame] | 352 | if (ICmp->isUnsigned() && !AllowUnsigned) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 353 | return false; |
| 354 | |
| 355 | // Are both operands of the ICmp affine? |
Tobias Grosser | 74394f0 | 2013-01-14 22:40:23 +0000 | [diff] [blame] | 356 | if (isa<UndefValue>(ICmp->getOperand(0)) || |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 357 | isa<UndefValue>(ICmp->getOperand(1))) |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 358 | return invalid<ReportUndefOperand>(Context, /*Assert=*/true, &BB, ICmp); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 359 | |
Sebastian Pop | 9f57c5b | 2013-04-10 04:05:18 +0000 | [diff] [blame] | 360 | Loop *L = LI->getLoopFor(ICmp->getParent()); |
| 361 | const SCEV *LHS = SE->getSCEVAtScope(ICmp->getOperand(0), L); |
| 362 | const SCEV *RHS = SE->getSCEVAtScope(ICmp->getOperand(1), L); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 363 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 364 | if (!isAffineExpr(&CurRegion, LHS, *SE) || |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 365 | !isAffineExpr(&CurRegion, RHS, *SE)) { |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 366 | if (!AllowNonAffineSubRegions || |
| 367 | !addOverApproximatedRegion(RI->getRegionFor(&BB), Context)) |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 368 | return invalid<ReportNonAffBranch>(Context, /*Assert=*/true, &BB, LHS, |
| 369 | RHS, ICmp); |
| 370 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | // Allow loop exit conditions. |
| 374 | Loop *L = LI->getLoopFor(&BB); |
| 375 | if (L && L->getExitingBlock() == &BB) |
| 376 | return true; |
| 377 | |
| 378 | // Allow perfectly nested conditions. |
| 379 | Region *R = RI->getRegionFor(&BB); |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 380 | if (R->getEntry() != &BB) |
| 381 | return invalid<ReportCondition>(Context, /*Assert=*/true, &BB); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 382 | |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | bool ScopDetection::isValidCallInst(CallInst &CI) { |
Johannes Doerfert | 3f500fa | 2015-01-25 18:07:30 +0000 | [diff] [blame] | 387 | if (CI.doesNotReturn()) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 388 | return false; |
| 389 | |
| 390 | if (CI.doesNotAccessMemory()) |
| 391 | return true; |
| 392 | |
| 393 | Function *CalledFunction = CI.getCalledFunction(); |
| 394 | |
| 395 | // Indirect calls are not supported. |
| 396 | if (CalledFunction == 0) |
| 397 | return false; |
| 398 | |
Johannes Doerfert | 3f500fa | 2015-01-25 18:07:30 +0000 | [diff] [blame] | 399 | // Check if we can handle the intrinsic call. |
| 400 | if (auto *IT = dyn_cast<IntrinsicInst>(&CI)) { |
| 401 | switch (IT->getIntrinsicID()) { |
| 402 | // Lifetime markers are supported/ignored. |
| 403 | case llvm::Intrinsic::lifetime_start: |
| 404 | case llvm::Intrinsic::lifetime_end: |
| 405 | // Invariant markers are supported/ignored. |
| 406 | case llvm::Intrinsic::invariant_start: |
| 407 | case llvm::Intrinsic::invariant_end: |
| 408 | // Some misc annotations are supported/ignored. |
| 409 | case llvm::Intrinsic::var_annotation: |
| 410 | case llvm::Intrinsic::ptr_annotation: |
| 411 | case llvm::Intrinsic::annotation: |
| 412 | case llvm::Intrinsic::donothing: |
| 413 | case llvm::Intrinsic::assume: |
| 414 | case llvm::Intrinsic::expect: |
| 415 | return true; |
| 416 | default: |
| 417 | // Other intrinsics which may access the memory are not yet supported. |
| 418 | break; |
| 419 | } |
| 420 | } |
| 421 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 422 | return false; |
| 423 | } |
| 424 | |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 425 | bool ScopDetection::isInvariant(const Value &Val, const Region &Reg) const { |
| 426 | // A reference to function argument or constant value is invariant. |
| 427 | if (isa<Argument>(Val) || isa<Constant>(Val)) |
| 428 | return true; |
| 429 | |
| 430 | const Instruction *I = dyn_cast<Instruction>(&Val); |
| 431 | if (!I) |
| 432 | return false; |
| 433 | |
| 434 | if (!Reg.contains(I)) |
| 435 | return true; |
| 436 | |
| 437 | if (I->mayHaveSideEffects()) |
| 438 | return false; |
| 439 | |
| 440 | // When Val is a Phi node, it is likely not invariant. We do not check whether |
| 441 | // Phi nodes are actually invariant, we assume that Phi nodes are usually not |
| 442 | // invariant. Recursively checking the operators of Phi nodes would lead to |
| 443 | // infinite recursion. |
| 444 | if (isa<PHINode>(*I)) |
| 445 | return false; |
| 446 | |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 447 | for (const Use &Operand : I->operands()) |
Tobias Grosser | 1d19190 | 2014-03-03 13:13:55 +0000 | [diff] [blame] | 448 | if (!isInvariant(*Operand, Reg)) |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 449 | return false; |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 450 | |
| 451 | // When the instruction is a load instruction, check that no write to memory |
| 452 | // in the region aliases with the load. |
| 453 | if (const LoadInst *LI = dyn_cast<LoadInst>(I)) { |
| 454 | AliasAnalysis::Location Loc = AA->getLocation(LI); |
Johannes Doerfert | ca08c44 | 2015-02-21 16:18:28 +0000 | [diff] [blame] | 455 | |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 456 | // Check if any basic block in the region can modify the location pointed to |
| 457 | // by 'Loc'. If so, 'Val' is (likely) not invariant in the region. |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 458 | for (const BasicBlock *BB : Reg.blocks()) |
Tobias Grosser | 1d19190 | 2014-03-03 13:13:55 +0000 | [diff] [blame] | 459 | if (AA->canBasicBlockModify(*BB, Loc)) |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 460 | return false; |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | return true; |
| 464 | } |
| 465 | |
Sebastian Pop | 422e33f | 2014-06-03 18:16:31 +0000 | [diff] [blame] | 466 | MapInsnToMemAcc InsnToMemAcc; |
| 467 | |
Sebastian Pop | b57c099 | 2014-05-12 20:24:26 +0000 | [diff] [blame] | 468 | bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const { |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 469 | Region &CurRegion = Context.CurRegion; |
| 470 | |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 471 | for (const SCEVUnknown *BasePointer : Context.NonAffineAccesses) { |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 472 | Value *BaseValue = BasePointer->getValue(); |
Sebastian Pop | 422e33f | 2014-06-03 18:16:31 +0000 | [diff] [blame] | 473 | ArrayShape *Shape = new ArrayShape(BasePointer); |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 474 | bool BasePtrHasNonAffine = false; |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 475 | |
| 476 | // First step: collect parametric terms in all array references. |
| 477 | SmallVector<const SCEV *, 4> Terms; |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 478 | for (const auto &Pair : Context.Accesses[BasePointer]) { |
| 479 | const SCEVAddRecExpr *AccessFunction = |
| 480 | dyn_cast<SCEVAddRecExpr>(Pair.second); |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 481 | |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 482 | if (AccessFunction) |
| 483 | AccessFunction->collectParametricTerms(*SE, Terms); |
| 484 | } |
Sebastian Pop | e8863b8 | 2014-05-12 19:02:02 +0000 | [diff] [blame] | 485 | |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 486 | // Second step: find array shape. |
Sebastian Pop | 422e33f | 2014-06-03 18:16:31 +0000 | [diff] [blame] | 487 | SE->findArrayDimensions(Terms, Shape->DelinearizedSizes, |
| 488 | Context.ElementSize[BasePointer]); |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 489 | |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 490 | // No array shape derived. |
| 491 | if (Shape->DelinearizedSizes.empty()) { |
| 492 | if (AllowNonAffine) |
| 493 | continue; |
Sebastian Pop | e8863b8 | 2014-05-12 19:02:02 +0000 | [diff] [blame] | 494 | |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 495 | for (const auto &Pair : Context.Accesses[BasePointer]) { |
| 496 | const Instruction *Insn = Pair.first; |
| 497 | const SCEV *AF = Pair.second; |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 498 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 499 | if (!isAffineExpr(&CurRegion, AF, *SE, BaseValue)) { |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 500 | invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF, Insn, |
| 501 | BaseValue); |
| 502 | if (!KeepGoing) |
| 503 | return false; |
| 504 | } |
| 505 | } |
| 506 | continue; |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 507 | } |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 508 | |
| 509 | // Third step: compute the access functions for each subscript. |
| 510 | // |
| 511 | // We first store the resulting memory accesses in TempMemoryAccesses. Only |
| 512 | // if the access functions for all memory accesses have been successfully |
| 513 | // delinearized we continue. Otherwise, we either report a failure or, if |
| 514 | // non-affine accesses are allowed, we drop the information. In case the |
| 515 | // information is dropped the memory accesses need to be overapproximated |
| 516 | // when translated to a polyhedral representation. |
| 517 | MapInsnToMemAcc TempMemoryAccesses; |
| 518 | for (const auto &Pair : Context.Accesses[BasePointer]) { |
| 519 | const Instruction *Insn = Pair.first; |
| 520 | const SCEVAddRecExpr *AF = dyn_cast<SCEVAddRecExpr>(Pair.second); |
| 521 | bool IsNonAffine = false; |
| 522 | MemAcc *Acc = new MemAcc(Insn, Shape); |
| 523 | TempMemoryAccesses.insert({Insn, Acc}); |
| 524 | |
| 525 | if (!AF) { |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 526 | if (isAffineExpr(&CurRegion, Pair.second, *SE, BaseValue)) |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 527 | Acc->DelinearizedSubscripts.push_back(Pair.second); |
| 528 | else |
| 529 | IsNonAffine = true; |
| 530 | } else { |
| 531 | AF->computeAccessFunctions(*SE, Acc->DelinearizedSubscripts, |
| 532 | Shape->DelinearizedSizes); |
| 533 | if (Acc->DelinearizedSubscripts.size() == 0) |
| 534 | IsNonAffine = true; |
| 535 | for (const SCEV *S : Acc->DelinearizedSubscripts) |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 536 | if (!isAffineExpr(&CurRegion, S, *SE, BaseValue)) |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 537 | IsNonAffine = true; |
| 538 | } |
| 539 | |
| 540 | // (Possibly) report non affine access |
| 541 | if (IsNonAffine) { |
| 542 | BasePtrHasNonAffine = true; |
| 543 | if (!AllowNonAffine) |
Tobias Grosser | 021eaef | 2015-01-08 19:03:10 +0000 | [diff] [blame] | 544 | invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, Pair.second, |
| 545 | Insn, BaseValue); |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 546 | if (!KeepGoing && !AllowNonAffine) |
| 547 | return false; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | if (!BasePtrHasNonAffine) |
| 552 | InsnToMemAcc.insert(TempMemoryAccesses.begin(), TempMemoryAccesses.end()); |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 553 | } |
Sebastian Pop | e8863b8 | 2014-05-12 19:02:02 +0000 | [diff] [blame] | 554 | return true; |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 557 | bool ScopDetection::isValidMemoryAccess(Instruction &Inst, |
| 558 | DetectionContext &Context) const { |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 559 | Region &CurRegion = Context.CurRegion; |
| 560 | |
Tobias Grosser | e5e171e | 2011-11-10 12:45:03 +0000 | [diff] [blame] | 561 | Value *Ptr = getPointerOperand(Inst); |
Sebastian Pop | 9f57c5b | 2013-04-10 04:05:18 +0000 | [diff] [blame] | 562 | Loop *L = LI->getLoopFor(Inst.getParent()); |
| 563 | const SCEV *AccessFunction = SE->getSCEVAtScope(Ptr, L); |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 564 | const SCEVUnknown *BasePointer; |
Tobias Grosser | e5e171e | 2011-11-10 12:45:03 +0000 | [diff] [blame] | 565 | Value *BaseValue; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 566 | |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 567 | BasePointer = dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFunction)); |
| 568 | |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 569 | if (!BasePointer) |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 570 | return invalid<ReportNoBasePtr>(Context, /*Assert=*/true, &Inst); |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 571 | |
| 572 | BaseValue = BasePointer->getValue(); |
| 573 | |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 574 | if (isa<UndefValue>(BaseValue)) |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 575 | return invalid<ReportUndefBasePtr>(Context, /*Assert=*/true, &Inst); |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 576 | |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 577 | // Check that the base address of the access is invariant in the current |
| 578 | // region. |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 579 | if (!isInvariant(*BaseValue, CurRegion)) |
Tobias Grosser | ab2227a | 2014-01-28 13:43:24 +0000 | [diff] [blame] | 580 | // Verification of this property is difficult as the independent blocks |
| 581 | // pass may introduce aliasing that we did not have when running the |
| 582 | // scop detection. |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 583 | return invalid<ReportVariantBasePtr>(Context, /*Assert=*/false, BaseValue, |
| 584 | &Inst); |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 585 | |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 586 | AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer); |
| 587 | |
Tobias Grosser | bcd4eff | 2014-09-13 14:47:40 +0000 | [diff] [blame] | 588 | const SCEV *Size = SE->getElementSize(&Inst); |
| 589 | if (Context.ElementSize.count(BasePointer)) { |
| 590 | if (Context.ElementSize[BasePointer] != Size) |
| 591 | return invalid<ReportDifferentArrayElementSize>(Context, /*Assert=*/true, |
| 592 | &Inst, BaseValue); |
| 593 | } else { |
| 594 | Context.ElementSize[BasePointer] = Size; |
| 595 | } |
| 596 | |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 597 | bool isVariantInNonAffineLoop = false; |
| 598 | SetVector<const Loop *> Loops; |
| 599 | findLoops(AccessFunction, Loops); |
| 600 | for (const Loop *L : Loops) |
| 601 | if (Context.BoxedLoopsSet.count(L)) |
| 602 | isVariantInNonAffineLoop = true; |
| 603 | |
| 604 | if (PollyDelinearize && !isVariantInNonAffineLoop) { |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 605 | Context.Accesses[BasePointer].push_back({&Inst, AccessFunction}); |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 606 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 607 | if (!isAffineExpr(&CurRegion, AccessFunction, *SE, BaseValue)) |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 608 | Context.NonAffineAccesses.insert(BasePointer); |
| 609 | } else if (!AllowNonAffine) { |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 610 | if (isVariantInNonAffineLoop || |
| 611 | !isAffineExpr(&CurRegion, AccessFunction, *SE, BaseValue)) |
Sebastian Pop | cd3bb59 | 2014-04-10 16:08:11 +0000 | [diff] [blame] | 612 | return invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, |
Andreas Simbuerger | d46b935 | 2014-08-17 10:09:11 +0000 | [diff] [blame] | 613 | AccessFunction, &Inst, BaseValue); |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 614 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 615 | |
| 616 | // FIXME: Alias Analysis thinks IntToPtrInst aliases with alloca instructions |
| 617 | // created by IndependentBlocks Pass. |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 618 | if (IntToPtrInst *Inst = dyn_cast<IntToPtrInst>(BaseValue)) |
| 619 | return invalid<ReportIntToPtr>(Context, /*Assert=*/true, Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 620 | |
Tobias Grosser | 1eedb67 | 2014-09-24 21:04:29 +0000 | [diff] [blame] | 621 | if (IgnoreAliasing) |
Sebastian Pop | 8c2d753 | 2013-07-03 22:50:36 +0000 | [diff] [blame] | 622 | return true; |
Tobias Grosser | fff5adc | 2011-11-10 13:21:43 +0000 | [diff] [blame] | 623 | |
Sebastian Pop | 8c2d753 | 2013-07-03 22:50:36 +0000 | [diff] [blame] | 624 | // Check if the base pointer of the memory access does alias with |
| 625 | // any other pointer. This cannot be handled at the moment. |
Benjamin Kramer | ae81abf | 2014-10-05 11:58:57 +0000 | [diff] [blame] | 626 | AAMDNodes AATags; |
| 627 | Inst.getAAMetadata(AATags); |
| 628 | AliasSet &AS = Context.AST.getAliasSetForPointer( |
| 629 | BaseValue, AliasAnalysis::UnknownSize, AATags); |
Tobias Grosser | 428b3e4 | 2013-02-04 15:46:25 +0000 | [diff] [blame] | 630 | |
Sebastian Pop | 8c2d753 | 2013-07-03 22:50:36 +0000 | [diff] [blame] | 631 | // INVALID triggers an assertion in verifying mode, if it detects that a |
| 632 | // SCoP was detected by SCoP detection and that this SCoP was invalidated by |
| 633 | // a pass that stated it would preserve the SCoPs. We disable this check as |
| 634 | // the independent blocks pass may create memory references which seem to |
| 635 | // alias, if -basicaa is not available. They actually do not, but as we can |
| 636 | // not proof this without -basicaa we would fail. We disable this check to |
| 637 | // not cause irrelevant verification failures. |
Tobias Grosser | 1eedb67 | 2014-09-24 21:04:29 +0000 | [diff] [blame] | 638 | if (!AS.isMustAlias()) { |
| 639 | if (PollyUseRuntimeAliasChecks) { |
| 640 | bool CanBuildRunTimeCheck = true; |
| 641 | // The run-time alias check places code that involves the base pointer at |
| 642 | // the beginning of the SCoP. This breaks if the base pointer is defined |
| 643 | // inside the scop. Hence, we can only create a run-time check if we are |
| 644 | // sure the base pointer is not an instruction defined inside the scop. |
| 645 | for (const auto &Ptr : AS) { |
| 646 | Instruction *Inst = dyn_cast<Instruction>(Ptr.getValue()); |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 647 | if (Inst && CurRegion.contains(Inst)) { |
Tobias Grosser | 1eedb67 | 2014-09-24 21:04:29 +0000 | [diff] [blame] | 648 | CanBuildRunTimeCheck = false; |
| 649 | break; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | if (CanBuildRunTimeCheck) |
| 654 | return true; |
| 655 | } |
Andreas Simbuerger | e2c9243 | 2014-06-26 10:19:57 +0000 | [diff] [blame] | 656 | return invalid<ReportAlias>(Context, /*Assert=*/false, &Inst, AS); |
Tobias Grosser | 1eedb67 | 2014-09-24 21:04:29 +0000 | [diff] [blame] | 657 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 658 | |
| 659 | return true; |
| 660 | } |
| 661 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 662 | bool ScopDetection::isValidInstruction(Instruction &Inst, |
| 663 | DetectionContext &Context) const { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 664 | if (PHINode *PN = dyn_cast<PHINode>(&Inst)) |
Johannes Doerfert | 0ff23ec | 2015-02-06 20:13:15 +0000 | [diff] [blame] | 665 | if (!PollyModelPHINodes && !canSynthesize(PN, LI, SE, &Context.CurRegion)) { |
Tobias Grosser | 683b8e4 | 2014-11-30 14:33:31 +0000 | [diff] [blame] | 666 | return invalid<ReportPhiNodeRefInRegion>(Context, /*Assert=*/true, &Inst); |
Tobias Grosser | ecfe21b | 2013-03-20 18:03:18 +0000 | [diff] [blame] | 667 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 668 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 669 | // We only check the call instruction but not invoke instruction. |
| 670 | if (CallInst *CI = dyn_cast<CallInst>(&Inst)) { |
| 671 | if (isValidCallInst(*CI)) |
| 672 | return true; |
| 673 | |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 674 | return invalid<ReportFuncCall>(Context, /*Assert=*/true, &Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | if (!Inst.mayWriteToMemory() && !Inst.mayReadFromMemory()) { |
Tobias Grosser | 5b1a7f2 | 2013-07-22 03:50:33 +0000 | [diff] [blame] | 678 | if (!isa<AllocaInst>(Inst)) |
| 679 | return true; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 680 | |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 681 | return invalid<ReportAlloca>(Context, /*Assert=*/true, &Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | // Check the access function. |
Tobias Grosser | d1e33e7 | 2015-02-19 05:31:07 +0000 | [diff] [blame] | 685 | if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst)) { |
| 686 | Context.hasStores |= isa<StoreInst>(Inst); |
| 687 | Context.hasLoads |= isa<LoadInst>(Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 688 | return isValidMemoryAccess(Inst, Context); |
Tobias Grosser | d1e33e7 | 2015-02-19 05:31:07 +0000 | [diff] [blame] | 689 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 690 | |
| 691 | // We do not know this instruction, therefore we assume it is invalid. |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 692 | return invalid<ReportUnknownInst>(Context, /*Assert=*/true, &Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 695 | bool ScopDetection::isValidLoop(Loop *L, DetectionContext &Context) const { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 696 | // Is the loop count affine? |
| 697 | const SCEV *LoopCount = SE->getBackedgeTakenCount(L); |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 698 | if (isAffineExpr(&Context.CurRegion, LoopCount, *SE)) { |
| 699 | Context.hasAffineLoops = true; |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 700 | return true; |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 701 | } |
| 702 | |
| 703 | if (AllowNonAffineSubRegions) { |
| 704 | Region *R = RI->getRegionFor(L->getHeader()); |
| 705 | if (R->contains(L)) |
| 706 | if (addOverApproximatedRegion(R, Context)) |
| 707 | return true; |
| 708 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 709 | |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 710 | return invalid<ReportLoopBound>(Context, /*Assert=*/true, L, LoopCount); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | Region *ScopDetection::expandRegion(Region &R) { |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 714 | // Initial no valid region was found (greater than R) |
Tobias Grosser | 5a56cbf | 2014-04-16 07:33:47 +0000 | [diff] [blame] | 715 | Region *LastValidRegion = nullptr; |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 716 | Region *ExpandedRegion = R.getExpandedRegion(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 717 | |
| 718 | DEBUG(dbgs() << "\tExpanding " << R.getNameStr() << "\n"); |
| 719 | |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 720 | while (ExpandedRegion) { |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 721 | DetectionContext Context( |
| 722 | *ExpandedRegion, *AA, NonAffineSubRegionMap[ExpandedRegion], |
| 723 | BoxedLoopsMap[ExpandedRegion], false /* verifying */); |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 724 | DEBUG(dbgs() << "\t\tTrying " << ExpandedRegion->getNameStr() << "\n"); |
Andreas Simbuerger | b379edb | 2014-06-27 06:21:14 +0000 | [diff] [blame] | 725 | // Only expand when we did not collect errors. |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 726 | |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 727 | // Check the exit first (cheap) |
Andreas Simbuerger | b379edb | 2014-06-27 06:21:14 +0000 | [diff] [blame] | 728 | if (isValidExit(Context) && !Context.Log.hasErrors()) { |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 729 | // If the exit is valid check all blocks |
| 730 | // - if true, a valid region was found => store it + keep expanding |
| 731 | // - if false, .tbd. => stop (should this really end the loop?) |
Andreas Simbuerger | b379edb | 2014-06-27 06:21:14 +0000 | [diff] [blame] | 732 | if (!allBlocksValid(Context) || Context.Log.hasErrors()) |
| 733 | break; |
| 734 | |
| 735 | if (Context.Log.hasErrors()) |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 736 | break; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 737 | |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 738 | // Delete unnecessary regions (allocated by getExpandedRegion) |
| 739 | if (LastValidRegion) |
| 740 | delete LastValidRegion; |
| 741 | |
Tobias Grosser | d7e5864 | 2013-04-10 06:55:45 +0000 | [diff] [blame] | 742 | // Store this region, because it is the greatest valid (encountered so |
| 743 | // far). |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 744 | LastValidRegion = ExpandedRegion; |
| 745 | |
| 746 | // Create and test the next greater region (if any) |
| 747 | ExpandedRegion = ExpandedRegion->getExpandedRegion(); |
| 748 | |
| 749 | } else { |
| 750 | // Create and test the next greater region (if any) |
| 751 | Region *TmpRegion = ExpandedRegion->getExpandedRegion(); |
| 752 | |
| 753 | // Delete unnecessary regions (allocated by getExpandedRegion) |
| 754 | delete ExpandedRegion; |
| 755 | |
| 756 | ExpandedRegion = TmpRegion; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 757 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Tobias Grosser | 378a9f2 | 2013-11-16 19:34:11 +0000 | [diff] [blame] | 760 | DEBUG({ |
| 761 | if (LastValidRegion) |
| 762 | dbgs() << "\tto " << LastValidRegion->getNameStr() << "\n"; |
| 763 | else |
| 764 | dbgs() << "\tExpanding " << R.getNameStr() << " failed\n"; |
| 765 | }); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 766 | |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 767 | return LastValidRegion; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 768 | } |
Sebastian Pop | 2c9ec2e | 2013-06-03 16:35:37 +0000 | [diff] [blame] | 769 | static bool regionWithoutLoops(Region &R, LoopInfo *LI) { |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 770 | for (const BasicBlock *BB : R.blocks()) |
Tobias Grosser | 1d19190 | 2014-03-03 13:13:55 +0000 | [diff] [blame] | 771 | if (R.contains(LI->getLoopFor(BB))) |
Sebastian Pop | 2c9ec2e | 2013-06-03 16:35:37 +0000 | [diff] [blame] | 772 | return false; |
| 773 | |
| 774 | return true; |
| 775 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 776 | |
Tobias Grosser | 28a70c5 | 2014-01-29 19:05:30 +0000 | [diff] [blame] | 777 | // Remove all direct and indirect children of region R from the region set Regs, |
| 778 | // but do not recurse further if the first child has been found. |
| 779 | // |
| 780 | // Return the number of regions erased from Regs. |
David Peixotto | 8da2b93 | 2014-10-22 20:39:07 +0000 | [diff] [blame] | 781 | static unsigned eraseAllChildren(ScopDetection::RegionSet &Regs, |
David Blaikie | b035f6d | 2014-04-15 18:45:27 +0000 | [diff] [blame] | 782 | const Region &R) { |
Tobias Grosser | 28a70c5 | 2014-01-29 19:05:30 +0000 | [diff] [blame] | 783 | unsigned Count = 0; |
David Blaikie | b035f6d | 2014-04-15 18:45:27 +0000 | [diff] [blame] | 784 | for (auto &SubRegion : R) { |
David Peixotto | 8da2b93 | 2014-10-22 20:39:07 +0000 | [diff] [blame] | 785 | if (Regs.count(SubRegion.get())) { |
Tobias Grosser | 28a70c5 | 2014-01-29 19:05:30 +0000 | [diff] [blame] | 786 | ++Count; |
David Peixotto | 8da2b93 | 2014-10-22 20:39:07 +0000 | [diff] [blame] | 787 | Regs.remove(SubRegion.get()); |
Tobias Grosser | 28a70c5 | 2014-01-29 19:05:30 +0000 | [diff] [blame] | 788 | } else { |
David Blaikie | b035f6d | 2014-04-15 18:45:27 +0000 | [diff] [blame] | 789 | Count += eraseAllChildren(Regs, *SubRegion); |
Tobias Grosser | 28a70c5 | 2014-01-29 19:05:30 +0000 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | return Count; |
| 793 | } |
| 794 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 795 | void ScopDetection::findScops(Region &R) { |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 796 | DetectionContext Context(R, *AA, NonAffineSubRegionMap[&R], BoxedLoopsMap[&R], |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 797 | false /*verifying*/); |
Johannes Doerfert | 6a4d81c | 2015-03-08 15:11:50 +0000 | [diff] [blame] | 798 | |
| 799 | bool RegionIsValid = false; |
| 800 | if (!DetectRegionsWithoutLoops && regionWithoutLoops(R, LI)) |
| 801 | invalid<ReportUnprofitable>(Context, /*Assert=*/true, &R); |
| 802 | else |
| 803 | RegionIsValid = isValidRegion(Context); |
| 804 | |
Johannes Doerfert | 3f1c285 | 2015-02-19 18:11:50 +0000 | [diff] [blame] | 805 | bool HasErrors = !RegionIsValid || Context.Log.size() > 0; |
Andreas Simbuerger | 0447240 | 2014-05-24 09:25:10 +0000 | [diff] [blame] | 806 | |
Johannes Doerfert | 3f1c285 | 2015-02-19 18:11:50 +0000 | [diff] [blame] | 807 | if (PollyTrackFailures && HasErrors) |
| 808 | RejectLogs.insert(std::make_pair(&R, Context.Log)); |
| 809 | |
| 810 | if (!HasErrors) { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 811 | ++ValidRegion; |
| 812 | ValidRegions.insert(&R); |
| 813 | return; |
| 814 | } |
| 815 | |
David Blaikie | b035f6d | 2014-04-15 18:45:27 +0000 | [diff] [blame] | 816 | for (auto &SubRegion : R) |
Tobias Grosser | 00dc309 | 2014-03-02 12:02:46 +0000 | [diff] [blame] | 817 | findScops(*SubRegion); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 818 | |
| 819 | // Try to expand regions. |
| 820 | // |
| 821 | // As the region tree normally only contains canonical regions, non canonical |
| 822 | // regions that form a Scop are not found. Therefore, those non canonical |
| 823 | // regions are checked by expanding the canonical ones. |
| 824 | |
Tobias Grosser | 0d1eee3 | 2013-02-05 11:56:05 +0000 | [diff] [blame] | 825 | std::vector<Region *> ToExpand; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 826 | |
David Blaikie | b035f6d | 2014-04-15 18:45:27 +0000 | [diff] [blame] | 827 | for (auto &SubRegion : R) |
| 828 | ToExpand.push_back(SubRegion.get()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 829 | |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 830 | for (Region *CurrentRegion : ToExpand) { |
Andreas Simbuerger | b379edb | 2014-06-27 06:21:14 +0000 | [diff] [blame] | 831 | // Skip regions that had errors. |
| 832 | bool HadErrors = RejectLogs.hasErrors(CurrentRegion); |
| 833 | if (HadErrors) |
| 834 | continue; |
| 835 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 836 | // Skip invalid regions. Regions may become invalid, if they are element of |
| 837 | // an already expanded region. |
David Peixotto | 8da2b93 | 2014-10-22 20:39:07 +0000 | [diff] [blame] | 838 | if (!ValidRegions.count(CurrentRegion)) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 839 | continue; |
| 840 | |
| 841 | Region *ExpandedR = expandRegion(*CurrentRegion); |
| 842 | |
| 843 | if (!ExpandedR) |
| 844 | continue; |
| 845 | |
| 846 | R.addSubRegion(ExpandedR, true); |
| 847 | ValidRegions.insert(ExpandedR); |
David Peixotto | 8da2b93 | 2014-10-22 20:39:07 +0000 | [diff] [blame] | 848 | ValidRegions.remove(CurrentRegion); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 849 | |
Tobias Grosser | 28a70c5 | 2014-01-29 19:05:30 +0000 | [diff] [blame] | 850 | // Erase all (direct and indirect) children of ExpandedR from the valid |
| 851 | // regions and update the number of valid regions. |
David Blaikie | b035f6d | 2014-04-15 18:45:27 +0000 | [diff] [blame] | 852 | ValidRegion -= eraseAllChildren(ValidRegions, *ExpandedR); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | |
| 856 | bool ScopDetection::allBlocksValid(DetectionContext &Context) const { |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 857 | Region &CurRegion = Context.CurRegion; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 858 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 859 | for (const BasicBlock *BB : CurRegion.blocks()) { |
Tobias Grosser | 1d19190 | 2014-03-03 13:13:55 +0000 | [diff] [blame] | 860 | Loop *L = LI->getLoopFor(BB); |
Andreas Simbuerger | 0447240 | 2014-05-24 09:25:10 +0000 | [diff] [blame] | 861 | if (L && L->getHeader() == BB && (!isValidLoop(L, Context) && !KeepGoing)) |
Sebastian Pop | b88ea5e | 2013-06-11 22:20:32 +0000 | [diff] [blame] | 862 | return false; |
| 863 | } |
| 864 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 865 | for (BasicBlock *BB : CurRegion.blocks()) |
Andreas Simbuerger | 0447240 | 2014-05-24 09:25:10 +0000 | [diff] [blame] | 866 | if (!isValidCFG(*BB, Context) && !KeepGoing) |
Sebastian Pop | 9e3d2dd | 2013-06-11 22:20:27 +0000 | [diff] [blame] | 867 | return false; |
| 868 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 869 | for (BasicBlock *BB : CurRegion.blocks()) |
Tobias Grosser | 1d19190 | 2014-03-03 13:13:55 +0000 | [diff] [blame] | 870 | for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; ++I) |
Andreas Simbuerger | 0447240 | 2014-05-24 09:25:10 +0000 | [diff] [blame] | 871 | if (!isValidInstruction(*I, Context) && !KeepGoing) |
Sebastian Pop | 8ca899c | 2013-06-14 20:20:43 +0000 | [diff] [blame] | 872 | return false; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 873 | |
Sebastian Pop | e8863b8 | 2014-05-12 19:02:02 +0000 | [diff] [blame] | 874 | if (!hasAffineMemoryAccesses(Context)) |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 875 | return false; |
| 876 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 877 | return true; |
| 878 | } |
| 879 | |
| 880 | bool ScopDetection::isValidExit(DetectionContext &Context) const { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 881 | |
| 882 | // PHI nodes are not allowed in the exit basic block. |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 883 | if (BasicBlock *Exit = Context.CurRegion.getExit()) { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 884 | BasicBlock::iterator I = Exit->begin(); |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 885 | if (I != Exit->end() && isa<PHINode>(*I)) |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 886 | return invalid<ReportPHIinExit>(Context, /*Assert=*/true, I); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | return true; |
| 890 | } |
| 891 | |
| 892 | bool ScopDetection::isValidRegion(DetectionContext &Context) const { |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 893 | Region &CurRegion = Context.CurRegion; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 894 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 895 | DEBUG(dbgs() << "Checking region: " << CurRegion.getNameStr() << "\n\t"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 896 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 897 | if (CurRegion.isTopLevelRegion()) { |
Tobias Grosser | f084edd | 2014-10-22 23:00:03 +0000 | [diff] [blame] | 898 | DEBUG(dbgs() << "Top level region is invalid\n"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 899 | return false; |
| 900 | } |
| 901 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 902 | if (!CurRegion.getEntry()->getName().count(OnlyRegion)) { |
Tobias Grosser | 4449e52 | 2014-01-27 14:24:53 +0000 | [diff] [blame] | 903 | DEBUG({ |
| 904 | dbgs() << "Region entry does not match -polly-region-only"; |
| 905 | dbgs() << "\n"; |
| 906 | }); |
| 907 | return false; |
| 908 | } |
| 909 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 910 | if (!CurRegion.getEnteringBlock()) { |
| 911 | BasicBlock *entry = CurRegion.getEntry(); |
Sebastian Pop | 9d63234 | 2013-06-11 22:20:40 +0000 | [diff] [blame] | 912 | Loop *L = LI->getLoopFor(entry); |
| 913 | |
| 914 | if (L) { |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 915 | if (!L->isLoopSimplifyForm()) |
| 916 | return invalid<ReportSimpleLoop>(Context, /*Assert=*/true); |
Sebastian Pop | 9d63234 | 2013-06-11 22:20:40 +0000 | [diff] [blame] | 917 | |
| 918 | for (pred_iterator PI = pred_begin(entry), PE = pred_end(entry); PI != PE; |
| 919 | ++PI) { |
| 920 | // Region entering edges come from the same loop but outside the region |
| 921 | // are not allowed. |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 922 | if (L->contains(*PI) && !CurRegion.contains(*PI)) |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 923 | return invalid<ReportIndEdge>(Context, /*Assert=*/true, *PI); |
Sebastian Pop | 9d63234 | 2013-06-11 22:20:40 +0000 | [diff] [blame] | 924 | } |
| 925 | } |
Tobias Grosser | 8edce4e | 2013-04-16 08:04:42 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Tobias Grosser | d654c25 | 2012-04-10 18:12:19 +0000 | [diff] [blame] | 928 | // SCoP cannot contain the entry block of the function, because we need |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 929 | // to insert alloca instruction there when translate scalar to array. |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 930 | if (CurRegion.getEntry() == |
| 931 | &(CurRegion.getEntry()->getParent()->getEntryBlock())) |
| 932 | return invalid<ReportEntry>(Context, /*Assert=*/true, CurRegion.getEntry()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 933 | |
Hongbin Zheng | 94868e6 | 2012-04-07 12:29:17 +0000 | [diff] [blame] | 934 | if (!isValidExit(Context)) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 935 | return false; |
| 936 | |
Hongbin Zheng | 94868e6 | 2012-04-07 12:29:17 +0000 | [diff] [blame] | 937 | if (!allBlocksValid(Context)) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 938 | return false; |
| 939 | |
Tobias Grosser | d1e33e7 | 2015-02-19 05:31:07 +0000 | [diff] [blame] | 940 | // We can probably not do a lot on scops that only write or only read |
| 941 | // data. |
| 942 | if (!DetectUnprofitable && (!Context.hasStores || !Context.hasLoads)) |
Johannes Doerfert | 6a4d81c | 2015-03-08 15:11:50 +0000 | [diff] [blame] | 943 | invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion); |
Tobias Grosser | d1e33e7 | 2015-02-19 05:31:07 +0000 | [diff] [blame] | 944 | |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 945 | // Check if there was at least one non-overapproximated loop in the region or |
| 946 | // we allow regions without loops. |
| 947 | if (!DetectRegionsWithoutLoops && !Context.hasAffineLoops) |
| 948 | invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion); |
| 949 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 950 | DEBUG(dbgs() << "OK\n"); |
| 951 | return true; |
| 952 | } |
| 953 | |
Johannes Doerfert | 43e1ead | 2014-07-15 21:06:48 +0000 | [diff] [blame] | 954 | void ScopDetection::markFunctionAsInvalid(Function *F) const { |
| 955 | F->addFnAttr(PollySkipFnAttr); |
| 956 | } |
| 957 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 958 | bool ScopDetection::isValidFunction(llvm::Function &F) { |
Johannes Doerfert | 43e1ead | 2014-07-15 21:06:48 +0000 | [diff] [blame] | 959 | return !F.hasFnAttribute(PollySkipFnAttr); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Tobias Grosser | b2863ca | 2013-03-04 19:49:51 +0000 | [diff] [blame] | 962 | void ScopDetection::printLocations(llvm::Function &F) { |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 963 | for (const Region *R : *this) { |
Tobias Grosser | 531891e | 2012-11-01 16:45:20 +0000 | [diff] [blame] | 964 | unsigned LineEntry, LineExit; |
| 965 | std::string FileName; |
| 966 | |
Tobias Grosser | 00dc309 | 2014-03-02 12:02:46 +0000 | [diff] [blame] | 967 | getDebugLocation(R, LineEntry, LineExit, FileName); |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 968 | DiagnosticScopFound Diagnostic(F, FileName, LineEntry, LineExit); |
| 969 | F.getContext().diagnose(Diagnostic); |
Tobias Grosser | 531891e | 2012-11-01 16:45:20 +0000 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
Daniel Jasper | 8a1dea0 | 2014-10-27 19:45:31 +0000 | [diff] [blame] | 973 | void ScopDetection::emitMissedRemarksForValidRegions( |
| 974 | const Function &F, const RegionSet &ValidRegions) { |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 975 | for (const Region *R : ValidRegions) { |
| 976 | const Region *Parent = R->getParent(); |
| 977 | if (Parent && !Parent->isTopLevelRegion() && RejectLogs.count(Parent)) |
| 978 | emitRejectionRemarks(F, RejectLogs.at(Parent)); |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | void ScopDetection::emitMissedRemarksForLeaves(const Function &F, |
| 983 | const Region *R) { |
| 984 | for (const std::unique_ptr<Region> &Child : *R) { |
| 985 | bool IsValid = ValidRegions.count(Child.get()); |
| 986 | if (IsValid) |
| 987 | continue; |
| 988 | |
| 989 | bool IsLeaf = Child->begin() == Child->end(); |
| 990 | if (!IsLeaf) |
| 991 | emitMissedRemarksForLeaves(F, Child.get()); |
| 992 | else { |
| 993 | if (RejectLogs.count(Child.get())) { |
| 994 | emitRejectionRemarks(F, RejectLogs.at(Child.get())); |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1000 | bool ScopDetection::runOnFunction(llvm::Function &F) { |
Chandler Carruth | f557987 | 2015-01-17 14:16:56 +0000 | [diff] [blame] | 1001 | LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 1002 | RI = &getAnalysis<RegionInfoPass>().getRegionInfo(); |
Sebastian Pop | 8fe6d11 | 2013-05-30 17:47:32 +0000 | [diff] [blame] | 1003 | if (!DetectScopsWithoutLoops && LI->empty()) |
| 1004 | return false; |
| 1005 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1006 | AA = &getAnalysis<AliasAnalysis>(); |
| 1007 | SE = &getAnalysis<ScalarEvolution>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1008 | Region *TopRegion = RI->getTopLevelRegion(); |
| 1009 | |
Tobias Grosser | 2ff8723 | 2011-10-23 11:17:06 +0000 | [diff] [blame] | 1010 | releaseMemory(); |
| 1011 | |
Tobias Grosser | a3ab27e | 2014-05-07 11:23:32 +0000 | [diff] [blame] | 1012 | if (OnlyFunction != "" && !F.getName().count(OnlyFunction)) |
Tobias Grosser | 2ff8723 | 2011-10-23 11:17:06 +0000 | [diff] [blame] | 1013 | return false; |
| 1014 | |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 1015 | if (!isValidFunction(F)) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1016 | return false; |
| 1017 | |
| 1018 | findScops(*TopRegion); |
Tobias Grosser | 531891e | 2012-11-01 16:45:20 +0000 | [diff] [blame] | 1019 | |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 1020 | // Only makes sense when we tracked errors. |
| 1021 | if (PollyTrackFailures) { |
| 1022 | emitMissedRemarksForValidRegions(F, ValidRegions); |
| 1023 | emitMissedRemarksForLeaves(F, TopRegion); |
| 1024 | } |
| 1025 | |
| 1026 | for (const Region *R : ValidRegions) |
| 1027 | emitValidRemarks(F, R); |
| 1028 | |
Johannes Doerfert | a05214f | 2014-10-15 23:24:28 +0000 | [diff] [blame] | 1029 | if (ReportLevel) |
Tobias Grosser | b2863ca | 2013-03-04 19:49:51 +0000 | [diff] [blame] | 1030 | printLocations(F); |
Tobias Grosser | 531891e | 2012-11-01 16:45:20 +0000 | [diff] [blame] | 1031 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
| 1034 | |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 1035 | bool ScopDetection::isNonAffineSubRegion(const Region *SubR, |
| 1036 | const Region *ScopR) const { |
| 1037 | return NonAffineSubRegionMap.lookup(ScopR).count(SubR); |
| 1038 | } |
| 1039 | |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 1040 | const ScopDetection::BoxedLoopsSetTy * |
| 1041 | ScopDetection::getBoxedLoops(const Region *R) const { |
| 1042 | auto BLMIt = BoxedLoopsMap.find(R); |
| 1043 | if (BLMIt == BoxedLoopsMap.end()) |
| 1044 | return nullptr; |
| 1045 | return &BLMIt->second; |
| 1046 | } |
| 1047 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1048 | void polly::ScopDetection::verifyRegion(const Region &R) const { |
| 1049 | assert(isMaxRegionInScop(R) && "Expect R is a valid region."); |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 1050 | |
| 1051 | BoxedLoopsSetTy DummyBoxedLoopsSet; |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 1052 | NonAffineSubRegionSetTy DummyNonAffineSubRegionSet; |
| 1053 | DetectionContext Context(const_cast<Region &>(R), *AA, |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame^] | 1054 | DummyNonAffineSubRegionSet, DummyBoxedLoopsSet, |
| 1055 | true /*verifying*/); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1056 | isValidRegion(Context); |
| 1057 | } |
| 1058 | |
| 1059 | void polly::ScopDetection::verifyAnalysis() const { |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 1060 | if (!VerifyScops) |
| 1061 | return; |
| 1062 | |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 1063 | for (const Region *R : ValidRegions) |
Tobias Grosser | 00dc309 | 2014-03-02 12:02:46 +0000 | [diff] [blame] | 1064 | verifyRegion(*R); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | void ScopDetection::getAnalysisUsage(AnalysisUsage &AU) const { |
Chandler Carruth | f557987 | 2015-01-17 14:16:56 +0000 | [diff] [blame] | 1068 | AU.addRequired<LoopInfoWrapperPass>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1069 | AU.addRequired<ScalarEvolution>(); |
| 1070 | // We also need AA and RegionInfo when we are verifying analysis. |
| 1071 | AU.addRequiredTransitive<AliasAnalysis>(); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 1072 | AU.addRequiredTransitive<RegionInfoPass>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1073 | AU.setPreservesAll(); |
| 1074 | } |
| 1075 | |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 1076 | void ScopDetection::print(raw_ostream &OS, const Module *) const { |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 1077 | for (const Region *R : ValidRegions) |
Tobias Grosser | 00dc309 | 2014-03-02 12:02:46 +0000 | [diff] [blame] | 1078 | OS << "Valid Region for Scop: " << R->getNameStr() << '\n'; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1079 | |
| 1080 | OS << "\n"; |
| 1081 | } |
| 1082 | |
| 1083 | void ScopDetection::releaseMemory() { |
| 1084 | ValidRegions.clear(); |
Andreas Simbuerger | 4870e09 | 2014-05-24 09:25:01 +0000 | [diff] [blame] | 1085 | RejectLogs.clear(); |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 1086 | NonAffineSubRegionMap.clear(); |
Andreas Simbuerger | 4870e09 | 2014-05-24 09:25:01 +0000 | [diff] [blame] | 1087 | |
Hongbin Zheng | 94c5df1 | 2011-05-06 02:38:20 +0000 | [diff] [blame] | 1088 | // Do not clear the invalid function set. |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | char ScopDetection::ID = 0; |
| 1092 | |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 1093 | Pass *polly::createScopDetectionPass() { return new ScopDetection(); } |
| 1094 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 1095 | INITIALIZE_PASS_BEGIN(ScopDetection, "polly-detect", |
| 1096 | "Polly - Detect static control parts (SCoPs)", false, |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 1097 | false); |
| 1098 | INITIALIZE_AG_DEPENDENCY(AliasAnalysis); |
Chandler Carruth | f557987 | 2015-01-17 14:16:56 +0000 | [diff] [blame] | 1099 | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 1100 | INITIALIZE_PASS_DEPENDENCY(RegionInfoPass); |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 1101 | INITIALIZE_PASS_DEPENDENCY(ScalarEvolution); |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 1102 | INITIALIZE_PASS_END(ScopDetection, "polly-detect", |
| 1103 | "Polly - Detect static control parts (SCoPs)", false, false) |