Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1 | // |
| 2 | // The LLVM Compiler Infrastructure |
| 3 | // |
| 4 | // This file is distributed under the University of Illinois Open Source |
| 5 | // License. See LICENSE.TXT for details. |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Detect the maximal Scops of a function. |
| 10 | // |
| 11 | // A static control part (Scop) is a subgraph of the control flow graph (CFG) |
| 12 | // that only has statically known control flow and can therefore be described |
| 13 | // within the polyhedral model. |
| 14 | // |
Michael Kruse | a6d48f5 | 2017-06-08 12:06:15 +0000 | [diff] [blame] | 15 | // Every Scop fulfills these restrictions: |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 16 | // |
| 17 | // * It is a single entry single exit region |
| 18 | // |
| 19 | // * Only affine linear bounds in the loops |
| 20 | // |
| 21 | // Every natural loop in a Scop must have a number of loop iterations that can |
| 22 | // be described as an affine linear function in surrounding loop iterators or |
| 23 | // parameters. (A parameter is a scalar that does not change its value during |
| 24 | // execution of the Scop). |
| 25 | // |
| 26 | // * Only comparisons of affine linear expressions in conditions |
| 27 | // |
| 28 | // * All loops and conditions perfectly nested |
| 29 | // |
| 30 | // The control flow needs to be structured such that it could be written using |
| 31 | // just 'for' and 'if' statements, without the need for any 'goto', 'break' or |
| 32 | // 'continue'. |
| 33 | // |
| 34 | // * Side effect free functions call |
| 35 | // |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 36 | // Function calls and intrinsics that do not have side effects (readnone) |
| 37 | // or memory intrinsics (memset, memcpy, memmove) are allowed. |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 38 | // |
| 39 | // The Scop detection finds the largest Scops by checking if the largest |
| 40 | // region is a Scop. If this is not the case, its canonical subregions are |
| 41 | // checked until a region is a Scop. It is now tried to extend this Scop by |
| 42 | // creating a larger non canonical region. |
| 43 | // |
| 44 | //===----------------------------------------------------------------------===// |
| 45 | |
Tobias Grosser | 5624d3c | 2015-12-21 12:38:56 +0000 | [diff] [blame] | 46 | #include "polly/ScopDetection.h" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 47 | #include "polly/CodeGen/CodeGeneration.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" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 50 | #include "polly/ScopDetectionDiagnostic.h" |
Tobias Grosser | 120db6b | 2011-11-07 12:58:54 +0000 | [diff] [blame] | 51 | #include "polly/Support/SCEVValidator.h" |
Tobias Grosser | a63b7ce | 2015-05-03 05:21:36 +0000 | [diff] [blame] | 52 | #include "polly/Support/ScopLocation.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 53 | #include "llvm/ADT/Statistic.h" |
| 54 | #include "llvm/Analysis/AliasAnalysis.h" |
Tobias Grosser | 8bd7f3c | 2017-03-09 11:36:00 +0000 | [diff] [blame] | 55 | #include "llvm/Analysis/Loads.h" |
Tobias Grosser | 6e9f25a | 2011-11-09 22:35:00 +0000 | [diff] [blame] | 56 | #include "llvm/Analysis/LoopInfo.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 57 | #include "llvm/Analysis/RegionIterator.h" |
Tobias Grosser | 6e9f25a | 2011-11-09 22:35:00 +0000 | [diff] [blame] | 58 | #include "llvm/Analysis/ScalarEvolution.h" |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 59 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
Chandler Carruth | 6b96c24 | 2014-03-06 00:47:27 +0000 | [diff] [blame] | 60 | #include "llvm/IR/DebugInfo.h" |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 61 | #include "llvm/IR/DiagnosticInfo.h" |
| 62 | #include "llvm/IR/DiagnosticPrinter.h" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 63 | #include "llvm/IR/IntrinsicInst.h" |
Chandler Carruth | 6b96c24 | 2014-03-06 00:47:27 +0000 | [diff] [blame] | 64 | #include "llvm/IR/LLVMContext.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 65 | #include "llvm/Support/Debug.h" |
Siddharth Bhat | e2699b5 | 2017-07-24 12:40:52 +0000 | [diff] [blame] | 66 | #include "llvm/Support/Regex.h" |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 67 | #include <set> |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 68 | #include <stack> |
Tobias Grosser | 60b54f1 | 2011-11-08 15:41:28 +0000 | [diff] [blame] | 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 | |
Tobias Grosser | c1a269b | 2015-12-21 21:00:43 +0000 | [diff] [blame] | 75 | // This option is set to a very high value, as analyzing such loops increases |
| 76 | // compile time on several cases. For experiments that enable this option, |
| 77 | // a value of around 40 has been working to avoid run-time regressions with |
| 78 | // Polly while still exposing interesting optimization opportunities. |
| 79 | static cl::opt<int> ProfitabilityMinPerLoopInstructions( |
| 80 | "polly-detect-profitability-min-per-loop-insts", |
| 81 | cl::desc("The minimal number of per-loop instructions before a single loop " |
| 82 | "region is considered profitable"), |
| 83 | cl::Hidden, cl::ValueRequired, cl::init(100000000), cl::cat(PollyCategory)); |
| 84 | |
Tobias Grosser | 575aca8 | 2015-10-06 16:10:29 +0000 | [diff] [blame] | 85 | bool polly::PollyProcessUnprofitable; |
| 86 | static cl::opt<bool, true> XPollyProcessUnprofitable( |
| 87 | "polly-process-unprofitable", |
| 88 | cl::desc( |
| 89 | "Process scops that are unlikely to benefit from Polly optimizations."), |
| 90 | cl::location(PollyProcessUnprofitable), cl::init(false), cl::ZeroOrMore, |
| 91 | cl::cat(PollyCategory)); |
Tobias Grosser | d1e33e7 | 2015-02-19 05:31:07 +0000 | [diff] [blame] | 92 | |
Siddharth Bhat | 286c916 | 2017-06-09 08:23:40 +0000 | [diff] [blame] | 93 | static cl::list<std::string> OnlyFunctions( |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 94 | "polly-only-func", |
Siddharth Bhat | e2699b5 | 2017-07-24 12:40:52 +0000 | [diff] [blame] | 95 | cl::desc("Only run on functions that match a regex. " |
| 96 | "Multiple regexes can be comma separated. " |
| 97 | "Scop detection will run on all functions that match " |
| 98 | "ANY of the regexes provided."), |
Siddharth Bhat | 286c916 | 2017-06-09 08:23:40 +0000 | [diff] [blame] | 99 | cl::ZeroOrMore, cl::CommaSeparated, cl::cat(PollyCategory)); |
Tobias Grosser | 2ff8723 | 2011-10-23 11:17:06 +0000 | [diff] [blame] | 100 | |
Siddharth Bhat | 0a1177b | 2017-07-28 11:47:24 +0000 | [diff] [blame] | 101 | static cl::list<std::string> IgnoredFunctions( |
| 102 | "polly-ignore-func", |
| 103 | cl::desc("Ignore functions that match a regex. " |
| 104 | "Multiple regexes can be comma separated. " |
| 105 | "Scop detection will ignore all functions that match " |
| 106 | "ANY of the regexes provided."), |
| 107 | cl::ZeroOrMore, cl::CommaSeparated, cl::cat(PollyCategory)); |
| 108 | |
Siddharth Bhat | b46847c | 2017-08-17 21:57:23 +0000 | [diff] [blame^] | 109 | bool polly::PollyAllowFullFunction; |
| 110 | static cl::opt<bool, true> |
| 111 | XAllowFullFunction("polly-detect-full-functions", |
| 112 | cl::desc("Allow the detection of full functions"), |
| 113 | cl::location(polly::PollyAllowFullFunction), |
| 114 | cl::init(false), cl::cat(PollyCategory)); |
Tobias Grosser | d8945ba | 2017-05-19 12:13:02 +0000 | [diff] [blame] | 115 | |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 116 | static cl::opt<std::string> OnlyRegion( |
| 117 | "polly-only-region", |
| 118 | cl::desc("Only run on certain regions (The provided identifier must " |
| 119 | "appear in the name of the region's entry block"), |
| 120 | cl::value_desc("identifier"), cl::ValueRequired, cl::init(""), |
| 121 | cl::cat(PollyCategory)); |
Tobias Grosser | 4449e52 | 2014-01-27 14:24:53 +0000 | [diff] [blame] | 122 | |
Tobias Grosser | 60cd932 | 2011-11-10 12:47:26 +0000 | [diff] [blame] | 123 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 124 | IgnoreAliasing("polly-ignore-aliasing", |
| 125 | cl::desc("Ignore possible aliasing of the array bases"), |
| 126 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 127 | cl::cat(PollyCategory)); |
Tobias Grosser | 2ff8723 | 2011-10-23 11:17:06 +0000 | [diff] [blame] | 128 | |
Johannes Doerfert | bda8143 | 2016-12-02 17:55:41 +0000 | [diff] [blame] | 129 | bool polly::PollyAllowUnsignedOperations; |
| 130 | static cl::opt<bool, true> XPollyAllowUnsignedOperations( |
| 131 | "polly-allow-unsigned-operations", |
| 132 | cl::desc("Allow unsigned operations such as comparisons or zero-extends."), |
| 133 | cl::location(PollyAllowUnsignedOperations), cl::Hidden, cl::ZeroOrMore, |
| 134 | cl::init(true), cl::cat(PollyCategory)); |
| 135 | |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 136 | bool polly::PollyUseRuntimeAliasChecks; |
| 137 | static cl::opt<bool, true> XPollyUseRuntimeAliasChecks( |
| 138 | "polly-use-runtime-alias-checks", |
| 139 | cl::desc("Use runtime alias checks to resolve possible aliasing."), |
| 140 | cl::location(PollyUseRuntimeAliasChecks), cl::Hidden, cl::ZeroOrMore, |
| 141 | cl::init(true), cl::cat(PollyCategory)); |
| 142 | |
Tobias Grosser | 637bd63 | 2013-05-07 07:31:10 +0000 | [diff] [blame] | 143 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 144 | ReportLevel("polly-report", |
| 145 | cl::desc("Print information about the activities of Polly"), |
| 146 | cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Tobias Grosser | 531891e | 2012-11-01 16:45:20 +0000 | [diff] [blame] | 147 | |
Tobias Grosser | 8ebdc2d | 2016-02-07 08:48:57 +0000 | [diff] [blame] | 148 | static cl::opt<bool> AllowDifferentTypes( |
| 149 | "polly-allow-differing-element-types", |
| 150 | cl::desc("Allow different element types for array accesses"), cl::Hidden, |
Tobias Grosser | a2ee003 | 2016-02-16 14:37:24 +0000 | [diff] [blame] | 151 | cl::init(true), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Tobias Grosser | 8ebdc2d | 2016-02-07 08:48:57 +0000 | [diff] [blame] | 152 | |
Tobias Grosser | 531891e | 2012-11-01 16:45:20 +0000 | [diff] [blame] | 153 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 154 | AllowNonAffine("polly-allow-nonaffine", |
| 155 | cl::desc("Allow non affine access functions in arrays"), |
| 156 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 157 | cl::cat(PollyCategory)); |
Tobias Grosser | a187964 | 2011-12-20 10:43:14 +0000 | [diff] [blame] | 158 | |
Tobias Grosser | 898a636 | 2016-03-23 06:40:15 +0000 | [diff] [blame] | 159 | static cl::opt<bool> |
| 160 | AllowModrefCall("polly-allow-modref-calls", |
| 161 | cl::desc("Allow functions with known modref behavior"), |
| 162 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 163 | cl::cat(PollyCategory)); |
| 164 | |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 165 | static cl::opt<bool> AllowNonAffineSubRegions( |
| 166 | "polly-allow-nonaffine-branches", |
| 167 | cl::desc("Allow non affine conditions for branches"), cl::Hidden, |
Johannes Doerfert | a36842f | 2015-02-26 11:09:24 +0000 | [diff] [blame] | 168 | cl::init(true), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 169 | |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 170 | static cl::opt<bool> |
| 171 | AllowNonAffineSubLoops("polly-allow-nonaffine-loops", |
| 172 | cl::desc("Allow non affine conditions for loops"), |
| 173 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 174 | cl::cat(PollyCategory)); |
| 175 | |
Tobias Grosser | c7d3fc5 | 2013-07-25 03:02:29 +0000 | [diff] [blame] | 176 | static cl::opt<bool, true> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 177 | TrackFailures("polly-detect-track-failures", |
| 178 | cl::desc("Track failure strings in detecting scop regions"), |
| 179 | cl::location(PollyTrackFailures), cl::Hidden, cl::ZeroOrMore, |
Andreas Simbuerger | 3efe40b | 2014-08-17 10:09:03 +0000 | [diff] [blame] | 180 | cl::init(true), cl::cat(PollyCategory)); |
Tobias Grosser | c7d3fc5 | 2013-07-25 03:02:29 +0000 | [diff] [blame] | 181 | |
Andreas Simbuerger | 0447240 | 2014-05-24 09:25:10 +0000 | [diff] [blame] | 182 | static cl::opt<bool> KeepGoing("polly-detect-keep-going", |
| 183 | cl::desc("Do not fail on the first error."), |
| 184 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 185 | cl::cat(PollyCategory)); |
| 186 | |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 187 | static cl::opt<bool, true> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 188 | PollyDelinearizeX("polly-delinearize", |
| 189 | cl::desc("Delinearize array access functions"), |
| 190 | cl::location(PollyDelinearize), cl::Hidden, |
Tobias Grosser | 6973cb6 | 2015-03-08 15:21:18 +0000 | [diff] [blame] | 191 | cl::ZeroOrMore, cl::init(true), cl::cat(PollyCategory)); |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 192 | |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 193 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 194 | VerifyScops("polly-detect-verify", |
| 195 | cl::desc("Verify the detected SCoPs after each transformation"), |
| 196 | cl::Hidden, cl::init(false), cl::ZeroOrMore, |
| 197 | cl::cat(PollyCategory)); |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 198 | |
Tobias Grosser | 8fa3e4c | 2016-02-26 16:43:35 +0000 | [diff] [blame] | 199 | bool polly::PollyInvariantLoadHoisting; |
| 200 | static cl::opt<bool, true> XPollyInvariantLoadHoisting( |
| 201 | "polly-invariant-load-hoisting", cl::desc("Hoist invariant loads."), |
| 202 | cl::location(PollyInvariantLoadHoisting), cl::Hidden, cl::ZeroOrMore, |
Tobias Grosser | 74814e1 | 2016-08-15 16:43:36 +0000 | [diff] [blame] | 203 | cl::init(false), cl::cat(PollyCategory)); |
Tobias Grosser | 8fa3e4c | 2016-02-26 16:43:35 +0000 | [diff] [blame] | 204 | |
Tobias Grosser | c80d697 | 2016-09-02 06:33:33 +0000 | [diff] [blame] | 205 | /// The minimal trip count under which loops are considered unprofitable. |
Johannes Doerfert | e526de5 | 2015-09-21 19:10:11 +0000 | [diff] [blame] | 206 | static const unsigned MIN_LOOP_TRIP_COUNT = 8; |
| 207 | |
Tobias Grosser | c7d3fc5 | 2013-07-25 03:02:29 +0000 | [diff] [blame] | 208 | bool polly::PollyTrackFailures = false; |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 209 | bool polly::PollyDelinearize = false; |
Johannes Doerfert | 43e1ead | 2014-07-15 21:06:48 +0000 | [diff] [blame] | 210 | StringRef polly::PollySkipFnAttr = "polly.skip.fn"; |
Tobias Grosser | c7d3fc5 | 2013-07-25 03:02:29 +0000 | [diff] [blame] | 211 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 212 | //===----------------------------------------------------------------------===// |
| 213 | // Statistics. |
| 214 | |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 215 | STATISTIC(NumScopRegions, "Number of scops"); |
| 216 | STATISTIC(NumLoopsInScop, "Number of loops in scops"); |
| 217 | STATISTIC(NumScopsDepthOne, "Number of scops with maximal loop depth 1"); |
| 218 | STATISTIC(NumScopsDepthTwo, "Number of scops with maximal loop depth 2"); |
| 219 | STATISTIC(NumScopsDepthThree, "Number of scops with maximal loop depth 3"); |
| 220 | STATISTIC(NumScopsDepthFour, "Number of scops with maximal loop depth 4"); |
| 221 | STATISTIC(NumScopsDepthFive, "Number of scops with maximal loop depth 5"); |
| 222 | STATISTIC(NumScopsDepthLarger, |
| 223 | "Number of scops with maximal loop depth 6 and larger"); |
| 224 | STATISTIC(NumProfScopRegions, "Number of scops (profitable scops only)"); |
| 225 | STATISTIC(NumLoopsInProfScop, |
| 226 | "Number of loops in scops (profitable scops only)"); |
| 227 | STATISTIC(NumLoopsOverall, "Number of total loops"); |
| 228 | STATISTIC(NumProfScopsDepthOne, |
| 229 | "Number of scops with maximal loop depth 1 (profitable scops only)"); |
| 230 | STATISTIC(NumProfScopsDepthTwo, |
| 231 | "Number of scops with maximal loop depth 2 (profitable scops only)"); |
| 232 | STATISTIC(NumProfScopsDepthThree, |
| 233 | "Number of scops with maximal loop depth 3 (profitable scops only)"); |
| 234 | STATISTIC(NumProfScopsDepthFour, |
| 235 | "Number of scops with maximal loop depth 4 (profitable scops only)"); |
| 236 | STATISTIC(NumProfScopsDepthFive, |
| 237 | "Number of scops with maximal loop depth 5 (profitable scops only)"); |
Tobias Grosser | 21a059a | 2017-01-16 14:08:10 +0000 | [diff] [blame] | 238 | STATISTIC(NumProfScopsDepthLarger, |
| 239 | "Number of scops with maximal loop depth 6 and larger " |
| 240 | "(profitable scops only)"); |
Tobias Grosser | 9fe37df | 2017-02-12 10:52:57 +0000 | [diff] [blame] | 241 | STATISTIC(MaxNumLoopsInScop, "Maximal number of loops in scops"); |
| 242 | STATISTIC(MaxNumLoopsInProfScop, |
| 243 | "Maximal number of loops in scops (profitable scops only)"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 244 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 245 | static void updateLoopCountStatistic(ScopDetection::LoopStats Stats, |
| 246 | bool OnlyProfitable); |
| 247 | |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 248 | class DiagnosticScopFound : public DiagnosticInfo { |
| 249 | private: |
| 250 | static int PluginDiagnosticKind; |
| 251 | |
| 252 | Function &F; |
| 253 | std::string FileName; |
| 254 | unsigned EntryLine, ExitLine; |
| 255 | |
| 256 | public: |
Tobias Grosser | 1b12f46 | 2013-12-18 11:14:36 +0000 | [diff] [blame] | 257 | DiagnosticScopFound(Function &F, std::string FileName, unsigned EntryLine, |
| 258 | unsigned ExitLine) |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 259 | : DiagnosticInfo(PluginDiagnosticKind, DS_Note), F(F), FileName(FileName), |
Tobias Grosser | 1b12f46 | 2013-12-18 11:14:36 +0000 | [diff] [blame] | 260 | EntryLine(EntryLine), ExitLine(ExitLine) {} |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 261 | |
| 262 | virtual void print(DiagnosticPrinter &DP) const; |
| 263 | |
| 264 | static bool classof(const DiagnosticInfo *DI) { |
| 265 | return DI->getKind() == PluginDiagnosticKind; |
| 266 | } |
| 267 | }; |
| 268 | |
Tobias Grosser | db6db50 | 2016-04-01 07:15:19 +0000 | [diff] [blame] | 269 | int DiagnosticScopFound::PluginDiagnosticKind = |
| 270 | getNextAvailablePluginDiagnosticKind(); |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 271 | |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 272 | void DiagnosticScopFound::print(DiagnosticPrinter &DP) const { |
Tobias Grosser | 1b12f46 | 2013-12-18 11:14:36 +0000 | [diff] [blame] | 273 | DP << "Polly detected an optimizable loop region (scop) in function '" << F |
| 274 | << "'\n"; |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 275 | |
| 276 | if (FileName.empty()) { |
| 277 | DP << "Scop location is unknown. Compile with debug info " |
| 278 | "(-g) to get more precise information. "; |
Tobias Grosser | 1b12f46 | 2013-12-18 11:14:36 +0000 | [diff] [blame] | 279 | return; |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | DP << FileName << ":" << EntryLine << ": Start of scop\n"; |
| 283 | DP << FileName << ":" << ExitLine << ": End of scop"; |
| 284 | } |
| 285 | |
Siddharth Bhat | 0a1177b | 2017-07-28 11:47:24 +0000 | [diff] [blame] | 286 | /// Check if a string matches any regex in a list of regexes. |
| 287 | /// @param Str the input string to match against. |
| 288 | /// @param RegexList a list of strings that are regular expressions. |
| 289 | static bool doesStringMatchAnyRegex(StringRef Str, |
| 290 | const cl::list<std::string> &RegexList) { |
| 291 | for (auto RegexStr : RegexList) { |
Siddharth Bhat | e2699b5 | 2017-07-24 12:40:52 +0000 | [diff] [blame] | 292 | Regex R(RegexStr); |
| 293 | |
| 294 | std::string Err; |
| 295 | if (!R.isValid(Err)) |
Siddharth Bhat | 0a1177b | 2017-07-28 11:47:24 +0000 | [diff] [blame] | 296 | report_fatal_error("invalid regex given as input to polly: " + Err, true); |
Siddharth Bhat | e2699b5 | 2017-07-24 12:40:52 +0000 | [diff] [blame] | 297 | |
Siddharth Bhat | 0a1177b | 2017-07-28 11:47:24 +0000 | [diff] [blame] | 298 | if (R.match(Str)) |
Siddharth Bhat | 286c916 | 2017-06-09 08:23:40 +0000 | [diff] [blame] | 299 | return true; |
Siddharth Bhat | e2699b5 | 2017-07-24 12:40:52 +0000 | [diff] [blame] | 300 | } |
Siddharth Bhat | 286c916 | 2017-06-09 08:23:40 +0000 | [diff] [blame] | 301 | return false; |
| 302 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 303 | //===----------------------------------------------------------------------===// |
| 304 | // ScopDetection. |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 305 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 306 | ScopDetection::ScopDetection(Function &F, const DominatorTree &DT, |
| 307 | ScalarEvolution &SE, LoopInfo &LI, RegionInfo &RI, |
Eli Friedman | e737fc1 | 2017-07-17 23:58:33 +0000 | [diff] [blame] | 308 | AliasAnalysis &AA, OptimizationRemarkEmitter &ORE) |
| 309 | : DT(DT), SE(SE), LI(LI), RI(RI), AA(AA), ORE(ORE) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 310 | |
| 311 | if (!PollyProcessUnprofitable && LI.empty()) |
| 312 | return; |
| 313 | |
| 314 | Region *TopRegion = RI.getTopLevelRegion(); |
| 315 | |
Siddharth Bhat | 0a1177b | 2017-07-28 11:47:24 +0000 | [diff] [blame] | 316 | if (OnlyFunctions.size() > 0 && |
| 317 | !doesStringMatchAnyRegex(F.getName(), OnlyFunctions)) |
| 318 | return; |
| 319 | |
| 320 | if (doesStringMatchAnyRegex(F.getName(), IgnoredFunctions)) |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 321 | return; |
| 322 | |
| 323 | if (!isValidFunction(F)) |
| 324 | return; |
| 325 | |
| 326 | findScops(*TopRegion); |
| 327 | |
| 328 | NumScopRegions += ValidRegions.size(); |
| 329 | |
| 330 | // Prune non-profitable regions. |
| 331 | for (auto &DIt : DetectionContextMap) { |
| 332 | auto &DC = DIt.getSecond(); |
| 333 | if (DC.Log.hasErrors()) |
| 334 | continue; |
| 335 | if (!ValidRegions.count(&DC.CurRegion)) |
| 336 | continue; |
| 337 | LoopStats Stats = countBeneficialLoops(&DC.CurRegion, SE, LI, 0); |
| 338 | updateLoopCountStatistic(Stats, false /* OnlyProfitable */); |
| 339 | if (isProfitableRegion(DC)) { |
| 340 | updateLoopCountStatistic(Stats, true /* OnlyProfitable */); |
| 341 | continue; |
| 342 | } |
| 343 | |
| 344 | ValidRegions.remove(&DC.CurRegion); |
| 345 | } |
| 346 | |
| 347 | NumProfScopRegions += ValidRegions.size(); |
| 348 | NumLoopsOverall += countBeneficialLoops(TopRegion, SE, LI, 0).NumLoops; |
| 349 | |
| 350 | // Only makes sense when we tracked errors. |
| 351 | if (PollyTrackFailures) |
| 352 | emitMissedRemarks(F); |
| 353 | |
| 354 | if (ReportLevel) |
| 355 | printLocations(F); |
| 356 | |
| 357 | assert(ValidRegions.size() <= DetectionContextMap.size() && |
| 358 | "Cached more results than valid regions"); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 361 | template <class RR, typename... Args> |
| 362 | inline bool ScopDetection::invalid(DetectionContext &Context, bool Assert, |
| 363 | Args &&... Arguments) const { |
| 364 | |
| 365 | if (!Context.Verifying) { |
Andreas Simbuerger | 4870e09 | 2014-05-24 09:25:01 +0000 | [diff] [blame] | 366 | RejectLog &Log = Context.Log; |
| 367 | std::shared_ptr<RR> RejectReason = std::make_shared<RR>(Arguments...); |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 368 | |
Andreas Simbuerger | 8a00c9b | 2014-05-24 09:25:06 +0000 | [diff] [blame] | 369 | if (PollyTrackFailures) |
Andreas Simbuerger | 4870e09 | 2014-05-24 09:25:01 +0000 | [diff] [blame] | 370 | Log.report(RejectReason); |
Andreas Simbuerger | 4870e09 | 2014-05-24 09:25:01 +0000 | [diff] [blame] | 371 | |
| 372 | DEBUG(dbgs() << RejectReason->getMessage()); |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 373 | DEBUG(dbgs() << "\n"); |
| 374 | } else { |
| 375 | assert(!Assert && "Verification of detected scop failed"); |
| 376 | } |
| 377 | |
| 378 | return false; |
| 379 | } |
| 380 | |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 381 | bool ScopDetection::isMaxRegionInScop(const Region &R, bool Verify) const { |
| 382 | if (!ValidRegions.count(&R)) |
| 383 | return false; |
| 384 | |
Johannes Doerfert | 3f1c285 | 2015-02-19 18:11:50 +0000 | [diff] [blame] | 385 | if (Verify) { |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 386 | DetectionContextMap.erase(getBBPairForRegion(&R)); |
| 387 | const auto &It = DetectionContextMap.insert(std::make_pair( |
| 388 | getBBPairForRegion(&R), |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 389 | DetectionContext(const_cast<Region &>(R), AA, false /*verifying*/))); |
Tobias Grosser | 907090c | 2015-10-25 10:55:35 +0000 | [diff] [blame] | 390 | DetectionContext &Context = It.first->second; |
Johannes Doerfert | 3f1c285 | 2015-02-19 18:11:50 +0000 | [diff] [blame] | 391 | return isValidRegion(Context); |
| 392 | } |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 393 | |
| 394 | return true; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Tobias Grosser | 4f129a6 | 2011-10-08 00:30:55 +0000 | [diff] [blame] | 397 | std::string ScopDetection::regionIsInvalidBecause(const Region *R) const { |
Andreas Simbuerger | 8a00c9b | 2014-05-24 09:25:06 +0000 | [diff] [blame] | 398 | // Get the first error we found. Even in keep-going mode, this is the first |
| 399 | // reason that caused the candidate to be rejected. |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 400 | auto *Log = lookupRejectionLog(R); |
Andreas Simbuerger | 83ed861 | 2014-06-12 07:25:08 +0000 | [diff] [blame] | 401 | |
| 402 | // This can happen when we marked a region invalid, but didn't track |
| 403 | // an error for it. |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 404 | if (!Log || !Log->hasErrors()) |
Andreas Simbuerger | 83ed861 | 2014-06-12 07:25:08 +0000 | [diff] [blame] | 405 | return ""; |
| 406 | |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 407 | RejectReasonPtr RR = *Log->begin(); |
Andreas Simbuerger | 83ed861 | 2014-06-12 07:25:08 +0000 | [diff] [blame] | 408 | return RR->getMessage(); |
Tobias Grosser | 4f129a6 | 2011-10-08 00:30:55 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 411 | bool ScopDetection::addOverApproximatedRegion(Region *AR, |
| 412 | DetectionContext &Context) const { |
| 413 | |
| 414 | // If we already know about Ar we can exit. |
| 415 | if (!Context.NonAffineSubRegionSet.insert(AR)) |
| 416 | return true; |
| 417 | |
| 418 | // All loops in the region have to be overapproximated too if there |
| 419 | // are accesses that depend on the iteration count. |
Michael Kruse | 41f046a | 2016-06-27 19:00:49 +0000 | [diff] [blame] | 420 | |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 421 | for (BasicBlock *BB : AR->blocks()) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 422 | Loop *L = LI.getLoopFor(BB); |
Tobias Grosser | 349d1c3 | 2016-09-20 17:05:22 +0000 | [diff] [blame] | 423 | if (AR->contains(L)) |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 424 | Context.BoxedLoopsSet.insert(L); |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 425 | } |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 426 | |
| 427 | return (AllowNonAffineSubLoops || Context.BoxedLoopsSet.empty()); |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Johannes Doerfert | 09e3697 | 2015-10-07 20:17:36 +0000 | [diff] [blame] | 430 | bool ScopDetection::onlyValidRequiredInvariantLoads( |
| 431 | InvariantLoadsSetTy &RequiredILS, DetectionContext &Context) const { |
| 432 | Region &CurRegion = Context.CurRegion; |
Tobias Grosser | 7b5a4df | 2017-04-11 04:59:13 +0000 | [diff] [blame] | 433 | const DataLayout &DL = CurRegion.getEntry()->getModule()->getDataLayout(); |
Johannes Doerfert | 09e3697 | 2015-10-07 20:17:36 +0000 | [diff] [blame] | 434 | |
Tobias Grosser | 8fa3e4c | 2016-02-26 16:43:35 +0000 | [diff] [blame] | 435 | if (!PollyInvariantLoadHoisting && !RequiredILS.empty()) |
| 436 | return false; |
| 437 | |
Tobias Grosser | 1c787e0 | 2017-03-02 12:15:37 +0000 | [diff] [blame] | 438 | for (LoadInst *Load : RequiredILS) { |
Tobias Grosser | 3f25a7e | 2017-05-04 10:16:20 +0000 | [diff] [blame] | 439 | // If we already know a load has been accepted as required invariant, we |
| 440 | // already run the validation below once and consequently don't need to |
| 441 | // run it again. Hence, we return early. For certain test cases (e.g., |
| 442 | // COSMO this avoids us spending 50% of scop-detection time in this |
| 443 | // very function (and its children). |
| 444 | if (Context.RequiredILS.count(Load)) |
| 445 | continue; |
| 446 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 447 | if (!isHoistableLoad(Load, CurRegion, LI, SE, DT)) |
Johannes Doerfert | 09e3697 | 2015-10-07 20:17:36 +0000 | [diff] [blame] | 448 | return false; |
| 449 | |
Tobias Grosser | 8bd7f3c | 2017-03-09 11:36:00 +0000 | [diff] [blame] | 450 | for (auto NonAffineRegion : Context.NonAffineSubRegionSet) { |
| 451 | |
| 452 | if (isSafeToLoadUnconditionally(Load->getPointerOperand(), |
| 453 | Load->getAlignment(), DL)) |
| 454 | continue; |
| 455 | |
Tobias Grosser | 1c787e0 | 2017-03-02 12:15:37 +0000 | [diff] [blame] | 456 | if (NonAffineRegion->contains(Load) && |
| 457 | Load->getParent() != NonAffineRegion->getEntry()) |
| 458 | return false; |
Tobias Grosser | 8bd7f3c | 2017-03-09 11:36:00 +0000 | [diff] [blame] | 459 | } |
Tobias Grosser | 1c787e0 | 2017-03-02 12:15:37 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Johannes Doerfert | 09e3697 | 2015-10-07 20:17:36 +0000 | [diff] [blame] | 462 | Context.RequiredILS.insert(RequiredILS.begin(), RequiredILS.end()); |
| 463 | |
| 464 | return true; |
| 465 | } |
| 466 | |
Johannes Doerfert | a94ae1a | 2016-12-02 17:49:52 +0000 | [diff] [blame] | 467 | bool ScopDetection::involvesMultiplePtrs(const SCEV *S0, const SCEV *S1, |
| 468 | Loop *Scope) const { |
| 469 | SetVector<Value *> Values; |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 470 | findValues(S0, SE, Values); |
Johannes Doerfert | a94ae1a | 2016-12-02 17:49:52 +0000 | [diff] [blame] | 471 | if (S1) |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 472 | findValues(S1, SE, Values); |
Johannes Doerfert | a94ae1a | 2016-12-02 17:49:52 +0000 | [diff] [blame] | 473 | |
| 474 | SmallPtrSet<Value *, 8> PtrVals; |
| 475 | for (auto *V : Values) { |
| 476 | if (auto *P2I = dyn_cast<PtrToIntInst>(V)) |
| 477 | V = P2I->getOperand(0); |
| 478 | |
| 479 | if (!V->getType()->isPointerTy()) |
| 480 | continue; |
| 481 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 482 | auto *PtrSCEV = SE.getSCEVAtScope(V, Scope); |
Johannes Doerfert | a94ae1a | 2016-12-02 17:49:52 +0000 | [diff] [blame] | 483 | if (isa<SCEVConstant>(PtrSCEV)) |
| 484 | continue; |
| 485 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 486 | auto *BasePtr = dyn_cast<SCEVUnknown>(SE.getPointerBase(PtrSCEV)); |
Johannes Doerfert | a94ae1a | 2016-12-02 17:49:52 +0000 | [diff] [blame] | 487 | if (!BasePtr) |
| 488 | return true; |
| 489 | |
| 490 | auto *BasePtrVal = BasePtr->getValue(); |
| 491 | if (PtrVals.insert(BasePtrVal).second) { |
| 492 | for (auto *PtrVal : PtrVals) |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 493 | if (PtrVal != BasePtrVal && !AA.isNoAlias(PtrVal, BasePtrVal)) |
Johannes Doerfert | a94ae1a | 2016-12-02 17:49:52 +0000 | [diff] [blame] | 494 | return true; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | return false; |
| 499 | } |
| 500 | |
Michael Kruse | 09eb445 | 2016-03-03 22:10:47 +0000 | [diff] [blame] | 501 | bool ScopDetection::isAffine(const SCEV *S, Loop *Scope, |
Johannes Doerfert | ec8a217 | 2016-04-25 13:32:36 +0000 | [diff] [blame] | 502 | DetectionContext &Context) const { |
Johannes Doerfert | 09e3697 | 2015-10-07 20:17:36 +0000 | [diff] [blame] | 503 | |
| 504 | InvariantLoadsSetTy AccessILS; |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 505 | if (!isAffineExpr(&Context.CurRegion, Scope, S, SE, &AccessILS)) |
Johannes Doerfert | 09e3697 | 2015-10-07 20:17:36 +0000 | [diff] [blame] | 506 | return false; |
| 507 | |
| 508 | if (!onlyValidRequiredInvariantLoads(AccessILS, Context)) |
| 509 | return false; |
| 510 | |
| 511 | return true; |
| 512 | } |
| 513 | |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 514 | bool ScopDetection::isValidSwitch(BasicBlock &BB, SwitchInst *SI, |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 515 | Value *Condition, bool IsLoopBranch, |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 516 | DetectionContext &Context) const { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 517 | Loop *L = LI.getLoopFor(&BB); |
| 518 | const SCEV *ConditionSCEV = SE.getSCEVAtScope(Condition, L); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 519 | |
Tobias Grosser | bbaeda3 | 2016-11-10 05:20:29 +0000 | [diff] [blame] | 520 | if (IsLoopBranch && L->isLoopLatch(&BB)) |
| 521 | return false; |
| 522 | |
Johannes Doerfert | a94ae1a | 2016-12-02 17:49:52 +0000 | [diff] [blame] | 523 | // Check for invalid usage of different pointers in one expression. |
| 524 | if (involvesMultiplePtrs(ConditionSCEV, nullptr, L)) |
| 525 | return false; |
| 526 | |
Michael Kruse | 09eb445 | 2016-03-03 22:10:47 +0000 | [diff] [blame] | 527 | if (isAffine(ConditionSCEV, L, Context)) |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 528 | return true; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 529 | |
Tobias Grosser | bbaeda3 | 2016-11-10 05:20:29 +0000 | [diff] [blame] | 530 | if (AllowNonAffineSubRegions && |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 531 | addOverApproximatedRegion(RI.getRegionFor(&BB), Context)) |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 532 | return true; |
| 533 | |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 534 | return invalid<ReportNonAffBranch>(Context, /*Assert=*/true, &BB, |
| 535 | ConditionSCEV, ConditionSCEV, SI); |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | bool ScopDetection::isValidBranch(BasicBlock &BB, BranchInst *BI, |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 539 | Value *Condition, bool IsLoopBranch, |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 540 | DetectionContext &Context) const { |
Johannes Doerfert | 9b1f9c8 | 2015-10-11 13:21:03 +0000 | [diff] [blame] | 541 | |
Tobias Grosser | bbaeda3 | 2016-11-10 05:20:29 +0000 | [diff] [blame] | 542 | // Constant integer conditions are always affine. |
| 543 | if (isa<ConstantInt>(Condition)) |
| 544 | return true; |
| 545 | |
Johannes Doerfert | 9b1f9c8 | 2015-10-11 13:21:03 +0000 | [diff] [blame] | 546 | if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(Condition)) { |
| 547 | auto Opcode = BinOp->getOpcode(); |
| 548 | if (Opcode == Instruction::And || Opcode == Instruction::Or) { |
| 549 | Value *Op0 = BinOp->getOperand(0); |
| 550 | Value *Op1 = BinOp->getOperand(1); |
| 551 | return isValidBranch(BB, BI, Op0, IsLoopBranch, Context) && |
| 552 | isValidBranch(BB, BI, Op1, IsLoopBranch, Context); |
| 553 | } |
| 554 | } |
| 555 | |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 556 | // Non constant conditions of branches need to be ICmpInst. |
| 557 | if (!isa<ICmpInst>(Condition)) { |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 558 | if (!IsLoopBranch && AllowNonAffineSubRegions && |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 559 | addOverApproximatedRegion(RI.getRegionFor(&BB), Context)) |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 560 | return true; |
| 561 | return invalid<ReportInvalidCond>(Context, /*Assert=*/true, BI, &BB); |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 562 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 563 | |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 564 | ICmpInst *ICmp = cast<ICmpInst>(Condition); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 565 | |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 566 | // Are both operands of the ICmp affine? |
| 567 | if (isa<UndefValue>(ICmp->getOperand(0)) || |
| 568 | isa<UndefValue>(ICmp->getOperand(1))) |
| 569 | return invalid<ReportUndefOperand>(Context, /*Assert=*/true, &BB, ICmp); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 570 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 571 | Loop *L = LI.getLoopFor(&BB); |
| 572 | const SCEV *LHS = SE.getSCEVAtScope(ICmp->getOperand(0), L); |
| 573 | const SCEV *RHS = SE.getSCEVAtScope(ICmp->getOperand(1), L); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 574 | |
Johannes Doerfert | bda8143 | 2016-12-02 17:55:41 +0000 | [diff] [blame] | 575 | // If unsigned operations are not allowed try to approximate the region. |
| 576 | if (ICmp->isUnsigned() && !PollyAllowUnsignedOperations) |
| 577 | return !IsLoopBranch && AllowNonAffineSubRegions && |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 578 | addOverApproximatedRegion(RI.getRegionFor(&BB), Context); |
Johannes Doerfert | bda8143 | 2016-12-02 17:55:41 +0000 | [diff] [blame] | 579 | |
Johannes Doerfert | a94ae1a | 2016-12-02 17:49:52 +0000 | [diff] [blame] | 580 | // Check for invalid usage of different pointers in one expression. |
| 581 | if (ICmp->isEquality() && involvesMultiplePtrs(LHS, nullptr, L) && |
| 582 | involvesMultiplePtrs(RHS, nullptr, L)) |
| 583 | return false; |
| 584 | |
| 585 | // Check for invalid usage of different pointers in a relational comparison. |
| 586 | if (ICmp->isRelational() && involvesMultiplePtrs(LHS, RHS, L)) |
| 587 | return false; |
| 588 | |
Michael Kruse | 09eb445 | 2016-03-03 22:10:47 +0000 | [diff] [blame] | 589 | if (isAffine(LHS, L, Context) && isAffine(RHS, L, Context)) |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 590 | return true; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 591 | |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 592 | if (!IsLoopBranch && AllowNonAffineSubRegions && |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 593 | addOverApproximatedRegion(RI.getRegionFor(&BB), Context)) |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 594 | return true; |
| 595 | |
| 596 | if (IsLoopBranch) |
| 597 | return false; |
| 598 | |
| 599 | return invalid<ReportNonAffBranch>(Context, /*Assert=*/true, &BB, LHS, RHS, |
| 600 | ICmp); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 603 | bool ScopDetection::isValidCFG(BasicBlock &BB, bool IsLoopBranch, |
Tobias Grosser | b76cd3c | 2015-11-11 08:42:20 +0000 | [diff] [blame] | 604 | bool AllowUnreachable, |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 605 | DetectionContext &Context) const { |
| 606 | Region &CurRegion = Context.CurRegion; |
| 607 | |
| 608 | TerminatorInst *TI = BB.getTerminator(); |
| 609 | |
Tobias Grosser | b76cd3c | 2015-11-11 08:42:20 +0000 | [diff] [blame] | 610 | if (AllowUnreachable && isa<UnreachableInst>(TI)) |
| 611 | return true; |
| 612 | |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 613 | // Return instructions are only valid if the region is the top level region. |
Philip Pfaffe | 1a0128f | 2017-05-24 18:39:39 +0000 | [diff] [blame] | 614 | if (isa<ReturnInst>(TI) && CurRegion.isTopLevelRegion()) |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 615 | return true; |
| 616 | |
| 617 | Value *Condition = getConditionFromTerminator(TI); |
| 618 | |
| 619 | if (!Condition) |
| 620 | return invalid<ReportInvalidTerminator>(Context, /*Assert=*/true, &BB); |
| 621 | |
| 622 | // UndefValue is not allowed as condition. |
| 623 | if (isa<UndefValue>(Condition)) |
| 624 | return invalid<ReportUndefCond>(Context, /*Assert=*/true, TI, &BB); |
| 625 | |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 626 | if (BranchInst *BI = dyn_cast<BranchInst>(TI)) |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 627 | return isValidBranch(BB, BI, Condition, IsLoopBranch, Context); |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 628 | |
| 629 | SwitchInst *SI = dyn_cast<SwitchInst>(TI); |
| 630 | assert(SI && "Terminator was neither branch nor switch"); |
| 631 | |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 632 | return isValidSwitch(BB, SI, Condition, IsLoopBranch, Context); |
Johannes Doerfert | 9a132f3 | 2015-09-28 09:33:22 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 635 | bool ScopDetection::isValidCallInst(CallInst &CI, |
| 636 | DetectionContext &Context) const { |
Johannes Doerfert | 3f500fa | 2015-01-25 18:07:30 +0000 | [diff] [blame] | 637 | if (CI.doesNotReturn()) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 638 | return false; |
| 639 | |
| 640 | if (CI.doesNotAccessMemory()) |
| 641 | return true; |
| 642 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 643 | if (auto *II = dyn_cast<IntrinsicInst>(&CI)) |
Johannes Doerfert | a792098 | 2016-02-25 14:08:48 +0000 | [diff] [blame] | 644 | if (isValidIntrinsicInst(*II, Context)) |
| 645 | return true; |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 646 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 647 | Function *CalledFunction = CI.getCalledFunction(); |
| 648 | |
| 649 | // Indirect calls are not supported. |
Tobias Grosser | 8dd653d | 2016-06-22 16:22:00 +0000 | [diff] [blame] | 650 | if (CalledFunction == nullptr) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 651 | return false; |
| 652 | |
Tobias Grosser | 898a636 | 2016-03-23 06:40:15 +0000 | [diff] [blame] | 653 | if (AllowModrefCall) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 654 | switch (AA.getModRefBehavior(CalledFunction)) { |
Tobias Grosser | b94e9b3 | 2016-11-21 09:04:45 +0000 | [diff] [blame] | 655 | case FMRB_UnknownModRefBehavior: |
Tobias Grosser | 898a636 | 2016-03-23 06:40:15 +0000 | [diff] [blame] | 656 | return false; |
Tobias Grosser | b94e9b3 | 2016-11-21 09:04:45 +0000 | [diff] [blame] | 657 | case FMRB_DoesNotAccessMemory: |
| 658 | case FMRB_OnlyReadsMemory: |
Johannes Doerfert | a792098 | 2016-02-25 14:08:48 +0000 | [diff] [blame] | 659 | // Implicitly disable delinearization since we have an unknown |
| 660 | // accesses with an unknown access function. |
| 661 | Context.HasUnknownAccess = true; |
Tobias Grosser | 898a636 | 2016-03-23 06:40:15 +0000 | [diff] [blame] | 662 | Context.AST.add(&CI); |
| 663 | return true; |
Tobias Grosser | b94e9b3 | 2016-11-21 09:04:45 +0000 | [diff] [blame] | 664 | case FMRB_OnlyReadsArgumentPointees: |
| 665 | case FMRB_OnlyAccessesArgumentPointees: |
Tobias Grosser | 898a636 | 2016-03-23 06:40:15 +0000 | [diff] [blame] | 666 | for (const auto &Arg : CI.arg_operands()) { |
| 667 | if (!Arg->getType()->isPointerTy()) |
| 668 | continue; |
Johannes Doerfert | a792098 | 2016-02-25 14:08:48 +0000 | [diff] [blame] | 669 | |
Tobias Grosser | 898a636 | 2016-03-23 06:40:15 +0000 | [diff] [blame] | 670 | // Bail if a pointer argument has a base address not known to |
| 671 | // ScalarEvolution. Note that a zero pointer is acceptable. |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 672 | auto *ArgSCEV = SE.getSCEVAtScope(Arg, LI.getLoopFor(CI.getParent())); |
Tobias Grosser | 898a636 | 2016-03-23 06:40:15 +0000 | [diff] [blame] | 673 | if (ArgSCEV->isZero()) |
| 674 | continue; |
| 675 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 676 | auto *BP = dyn_cast<SCEVUnknown>(SE.getPointerBase(ArgSCEV)); |
Tobias Grosser | 898a636 | 2016-03-23 06:40:15 +0000 | [diff] [blame] | 677 | if (!BP) |
| 678 | return false; |
| 679 | |
| 680 | // Implicitly disable delinearization since we have an unknown |
| 681 | // accesses with an unknown access function. |
| 682 | Context.HasUnknownAccess = true; |
| 683 | } |
| 684 | |
| 685 | Context.AST.add(&CI); |
| 686 | return true; |
Weiming Zhao | 7614e17 | 2016-07-11 18:27:52 +0000 | [diff] [blame] | 687 | case FMRB_DoesNotReadMemory: |
Tobias Grosser | 70d2709 | 2016-11-13 19:27:24 +0000 | [diff] [blame] | 688 | case FMRB_OnlyAccessesInaccessibleMem: |
| 689 | case FMRB_OnlyAccessesInaccessibleOrArgMem: |
Weiming Zhao | 7614e17 | 2016-07-11 18:27:52 +0000 | [diff] [blame] | 690 | return false; |
Tobias Grosser | 898a636 | 2016-03-23 06:40:15 +0000 | [diff] [blame] | 691 | } |
Johannes Doerfert | a792098 | 2016-02-25 14:08:48 +0000 | [diff] [blame] | 692 | } |
| 693 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | |
| 697 | bool ScopDetection::isValidIntrinsicInst(IntrinsicInst &II, |
| 698 | DetectionContext &Context) const { |
| 699 | if (isIgnoredIntrinsic(&II)) |
Tobias Grosser | 9c0ffe3 | 2015-08-30 16:57:15 +0000 | [diff] [blame] | 700 | return true; |
Johannes Doerfert | 3f500fa | 2015-01-25 18:07:30 +0000 | [diff] [blame] | 701 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 702 | // The closest loop surrounding the call instruction. |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 703 | Loop *L = LI.getLoopFor(II.getParent()); |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 704 | |
| 705 | // The access function and base pointer for memory intrinsics. |
| 706 | const SCEV *AF; |
| 707 | const SCEVUnknown *BP; |
| 708 | |
| 709 | switch (II.getIntrinsicID()) { |
| 710 | // Memory intrinsics that can be represented are supported. |
| 711 | case llvm::Intrinsic::memmove: |
| 712 | case llvm::Intrinsic::memcpy: |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 713 | AF = SE.getSCEVAtScope(cast<MemTransferInst>(II).getSource(), L); |
Johannes Doerfert | 733ea34 | 2016-03-24 13:50:04 +0000 | [diff] [blame] | 714 | if (!AF->isZero()) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 715 | BP = dyn_cast<SCEVUnknown>(SE.getPointerBase(AF)); |
Johannes Doerfert | 733ea34 | 2016-03-24 13:50:04 +0000 | [diff] [blame] | 716 | // Bail if the source pointer is not valid. |
| 717 | if (!isValidAccess(&II, AF, BP, Context)) |
| 718 | return false; |
| 719 | } |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 720 | // Fall through |
| 721 | case llvm::Intrinsic::memset: |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 722 | AF = SE.getSCEVAtScope(cast<MemIntrinsic>(II).getDest(), L); |
Johannes Doerfert | 733ea34 | 2016-03-24 13:50:04 +0000 | [diff] [blame] | 723 | if (!AF->isZero()) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 724 | BP = dyn_cast<SCEVUnknown>(SE.getPointerBase(AF)); |
Johannes Doerfert | 733ea34 | 2016-03-24 13:50:04 +0000 | [diff] [blame] | 725 | // Bail if the destination pointer is not valid. |
| 726 | if (!isValidAccess(&II, AF, BP, Context)) |
| 727 | return false; |
| 728 | } |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 729 | |
| 730 | // Bail if the length is not affine. |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 731 | if (!isAffine(SE.getSCEVAtScope(cast<MemIntrinsic>(II).getLength(), L), L, |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 732 | Context)) |
| 733 | return false; |
| 734 | |
| 735 | return true; |
| 736 | default: |
| 737 | break; |
| 738 | } |
| 739 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 740 | return false; |
| 741 | } |
| 742 | |
Michael Kruse | 5a4ec5c | 2017-03-07 20:28:43 +0000 | [diff] [blame] | 743 | bool ScopDetection::isInvariant(Value &Val, const Region &Reg, |
| 744 | DetectionContext &Ctx) const { |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 745 | // A reference to function argument or constant value is invariant. |
| 746 | if (isa<Argument>(Val) || isa<Constant>(Val)) |
| 747 | return true; |
| 748 | |
Michael Kruse | 5a4ec5c | 2017-03-07 20:28:43 +0000 | [diff] [blame] | 749 | Instruction *I = dyn_cast<Instruction>(&Val); |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 750 | if (!I) |
| 751 | return false; |
| 752 | |
| 753 | if (!Reg.contains(I)) |
| 754 | return true; |
| 755 | |
Michael Kruse | 5a4ec5c | 2017-03-07 20:28:43 +0000 | [diff] [blame] | 756 | // Loads within the SCoP may read arbitrary values, need to hoist them. If it |
| 757 | // is not hoistable, it will be rejected later, but here we assume it is and |
| 758 | // that makes the value invariant. |
| 759 | if (auto LI = dyn_cast<LoadInst>(I)) { |
| 760 | Ctx.RequiredILS.insert(LI); |
| 761 | return true; |
| 762 | } |
| 763 | |
Michael Kruse | 6744efa8d | 2017-03-08 15:14:46 +0000 | [diff] [blame] | 764 | return false; |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Tobias Grosser | c80d697 | 2016-09-02 06:33:33 +0000 | [diff] [blame] | 767 | /// Remove smax of smax(0, size) expressions from a SCEV expression and |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 768 | /// register the '...' components. |
| 769 | /// |
Michael Kruse | a6d48f5 | 2017-06-08 12:06:15 +0000 | [diff] [blame] | 770 | /// Array access expressions as they are generated by GFortran contain smax(0, |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 771 | /// size) expressions that confuse the 'normal' delinearization algorithm. |
| 772 | /// However, if we extract such expressions before the normal delinearization |
| 773 | /// takes place they can actually help to identify array size expressions in |
Michael Kruse | a6d48f5 | 2017-06-08 12:06:15 +0000 | [diff] [blame] | 774 | /// Fortran accesses. For the subsequently following delinearization the smax(0, |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 775 | /// size) component can be replaced by just 'size'. This is correct as we will |
| 776 | /// always add and verify the assumption that for all subscript expressions |
| 777 | /// 'exp' the inequality 0 <= exp < size holds. Hence, we will also verify |
| 778 | /// that 0 <= size, which means smax(0, size) == size. |
Tobias Grosser | ebb626e | 2016-10-29 06:19:34 +0000 | [diff] [blame] | 779 | class SCEVRemoveMax : public SCEVRewriteVisitor<SCEVRemoveMax> { |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 780 | public: |
Tobias Grosser | ebb626e | 2016-10-29 06:19:34 +0000 | [diff] [blame] | 781 | static const SCEV *rewrite(const SCEV *Scev, ScalarEvolution &SE, |
| 782 | std::vector<const SCEV *> *Terms = nullptr) { |
| 783 | SCEVRemoveMax Rewriter(SE, Terms); |
| 784 | return Rewriter.visit(Scev); |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | SCEVRemoveMax(ScalarEvolution &SE, std::vector<const SCEV *> *Terms) |
Tobias Grosser | ebb626e | 2016-10-29 06:19:34 +0000 | [diff] [blame] | 788 | : SCEVRewriteVisitor(SE), Terms(Terms) {} |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 789 | |
| 790 | const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) { |
Michael Kruse | 8fc2896 | 2015-12-20 14:42:32 +0000 | [diff] [blame] | 791 | if ((Expr->getNumOperands() == 2) && Expr->getOperand(0)->isZero()) { |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 792 | auto Res = visit(Expr->getOperand(1)); |
| 793 | if (Terms) |
| 794 | (*Terms).push_back(Res); |
| 795 | return Res; |
| 796 | } |
| 797 | |
| 798 | return Expr; |
| 799 | } |
| 800 | |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 801 | private: |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 802 | std::vector<const SCEV *> *Terms; |
| 803 | }; |
| 804 | |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 805 | SmallVector<const SCEV *, 4> |
| 806 | ScopDetection::getDelinearizationTerms(DetectionContext &Context, |
| 807 | const SCEVUnknown *BasePointer) const { |
| 808 | SmallVector<const SCEV *, 4> Terms; |
| 809 | for (const auto &Pair : Context.Accesses[BasePointer]) { |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 810 | std::vector<const SCEV *> MaxTerms; |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 811 | SCEVRemoveMax::rewrite(Pair.second, SE, &MaxTerms); |
Tobias Grosser | 2f8e43d | 2015-11-24 17:06:38 +0000 | [diff] [blame] | 812 | if (MaxTerms.size() > 0) { |
| 813 | Terms.insert(Terms.begin(), MaxTerms.begin(), MaxTerms.end()); |
| 814 | continue; |
| 815 | } |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 816 | // In case the outermost expression is a plain add, we check if any of its |
| 817 | // terms has the form 4 * %inst * %param * %param ..., aka a term that |
| 818 | // contains a product between a parameter and an instruction that is |
| 819 | // inside the scop. Such instructions, if allowed at all, are instructions |
| 820 | // SCEV can not represent, but Polly is still looking through. As a |
| 821 | // result, these instructions can depend on induction variables and are |
| 822 | // most likely no array sizes. However, terms that are multiplied with |
| 823 | // them are likely candidates for array sizes. |
| 824 | if (auto *AF = dyn_cast<SCEVAddExpr>(Pair.second)) { |
| 825 | for (auto Op : AF->operands()) { |
| 826 | if (auto *AF2 = dyn_cast<SCEVAddRecExpr>(Op)) |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 827 | SE.collectParametricTerms(AF2, Terms); |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 828 | if (auto *AF2 = dyn_cast<SCEVMulExpr>(Op)) { |
| 829 | SmallVector<const SCEV *, 0> Operands; |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 830 | |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 831 | for (auto *MulOp : AF2->operands()) { |
| 832 | if (auto *Const = dyn_cast<SCEVConstant>(MulOp)) |
| 833 | Operands.push_back(Const); |
| 834 | if (auto *Unknown = dyn_cast<SCEVUnknown>(MulOp)) { |
| 835 | if (auto *Inst = dyn_cast<Instruction>(Unknown->getValue())) { |
| 836 | if (!Context.CurRegion.contains(Inst)) |
Tobias Grosser | 1b13dde | 2015-06-29 14:44:22 +0000 | [diff] [blame] | 837 | Operands.push_back(MulOp); |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 838 | |
| 839 | } else { |
| 840 | Operands.push_back(MulOp); |
Tobias Grosser | 1b13dde | 2015-06-29 14:44:22 +0000 | [diff] [blame] | 841 | } |
| 842 | } |
Tobias Grosser | 1b13dde | 2015-06-29 14:44:22 +0000 | [diff] [blame] | 843 | } |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 844 | if (Operands.size()) |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 845 | Terms.push_back(SE.getMulExpr(Operands)); |
Tobias Grosser | 1b13dde | 2015-06-29 14:44:22 +0000 | [diff] [blame] | 846 | } |
| 847 | } |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 848 | } |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 849 | if (Terms.empty()) |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 850 | SE.collectParametricTerms(Pair.second, Terms); |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 851 | } |
| 852 | return Terms; |
| 853 | } |
Sebastian Pop | e8863b8 | 2014-05-12 19:02:02 +0000 | [diff] [blame] | 854 | |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 855 | bool ScopDetection::hasValidArraySizes(DetectionContext &Context, |
| 856 | SmallVectorImpl<const SCEV *> &Sizes, |
Michael Kruse | c7e0d9c | 2016-03-01 21:44:06 +0000 | [diff] [blame] | 857 | const SCEVUnknown *BasePointer, |
| 858 | Loop *Scope) const { |
Tobias Grosser | 1e55db3 | 2017-05-27 15:18:53 +0000 | [diff] [blame] | 859 | // If no sizes were found, all sizes are trivially valid. We allow this case |
| 860 | // to make it possible to pass known-affine accesses to the delinearization to |
| 861 | // try to recover some interesting multi-dimensional accesses, but to still |
| 862 | // allow the already known to be affine access in case the delinearization |
| 863 | // fails. In such situations, the delinearization will just return a Sizes |
| 864 | // array of size zero. |
| 865 | if (Sizes.size() == 0) |
| 866 | return true; |
| 867 | |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 868 | Value *BaseValue = BasePointer->getValue(); |
| 869 | Region &CurRegion = Context.CurRegion; |
| 870 | for (const SCEV *DelinearizedSize : Sizes) { |
Johannes Doerfert | ec8a217 | 2016-04-25 13:32:36 +0000 | [diff] [blame] | 871 | if (!isAffine(DelinearizedSize, Scope, Context)) { |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 872 | Sizes.clear(); |
| 873 | break; |
Tobias Grosser | 5528dcd | 2015-10-25 08:40:38 +0000 | [diff] [blame] | 874 | } |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 875 | if (auto *Unknown = dyn_cast<SCEVUnknown>(DelinearizedSize)) { |
| 876 | auto *V = dyn_cast<Value>(Unknown->getValue()); |
| 877 | if (auto *Load = dyn_cast<LoadInst>(V)) { |
| 878 | if (Context.CurRegion.contains(Load) && |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 879 | isHoistableLoad(Load, CurRegion, LI, SE, DT)) |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 880 | Context.RequiredILS.insert(Load); |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 881 | continue; |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 882 | } |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 883 | } |
Siddharth Bhat | a1b2086 | 2017-07-13 12:18:56 +0000 | [diff] [blame] | 884 | if (hasScalarDepsInsideRegion(DelinearizedSize, &CurRegion, Scope, false, |
| 885 | Context.RequiredILS)) |
Tobias Grosser | bfaf1ae | 2015-12-21 09:09:39 +0000 | [diff] [blame] | 886 | return invalid<ReportNonAffineAccess>( |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 887 | Context, /*Assert=*/true, DelinearizedSize, |
| 888 | Context.Accesses[BasePointer].front().first, BaseValue); |
| 889 | } |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 890 | |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 891 | // No array shape derived. |
| 892 | if (Sizes.empty()) { |
| 893 | if (AllowNonAffine) |
| 894 | return true; |
| 895 | |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 896 | for (const auto &Pair : Context.Accesses[BasePointer]) { |
| 897 | const Instruction *Insn = Pair.first; |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 898 | const SCEV *AF = Pair.second; |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 899 | |
Johannes Doerfert | ec8a217 | 2016-04-25 13:32:36 +0000 | [diff] [blame] | 900 | if (!isAffine(AF, Scope, Context)) { |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 901 | invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF, Insn, |
| 902 | BaseValue); |
| 903 | if (!KeepGoing) |
Tobias Grosser | 230acc4 | 2014-09-13 14:47:55 +0000 | [diff] [blame] | 904 | return false; |
| 905 | } |
| 906 | } |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 907 | return false; |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 908 | } |
Sebastian Pop | e8863b8 | 2014-05-12 19:02:02 +0000 | [diff] [blame] | 909 | return true; |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 912 | // We first store the resulting memory accesses in TempMemoryAccesses. Only |
| 913 | // if the access functions for all memory accesses have been successfully |
| 914 | // delinearized we continue. Otherwise, we either report a failure or, if |
| 915 | // non-affine accesses are allowed, we drop the information. In case the |
| 916 | // information is dropped the memory accesses need to be overapproximated |
| 917 | // when translated to a polyhedral representation. |
| 918 | bool ScopDetection::computeAccessFunctions( |
| 919 | DetectionContext &Context, const SCEVUnknown *BasePointer, |
| 920 | std::shared_ptr<ArrayShape> Shape) const { |
| 921 | Value *BaseValue = BasePointer->getValue(); |
| 922 | bool BasePtrHasNonAffine = false; |
| 923 | MapInsnToMemAcc TempMemoryAccesses; |
| 924 | for (const auto &Pair : Context.Accesses[BasePointer]) { |
| 925 | const Instruction *Insn = Pair.first; |
| 926 | auto *AF = Pair.second; |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 927 | AF = SCEVRemoveMax::rewrite(AF, SE); |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 928 | bool IsNonAffine = false; |
| 929 | TempMemoryAccesses.insert(std::make_pair(Insn, MemAcc(Insn, Shape))); |
| 930 | MemAcc *Acc = &TempMemoryAccesses.find(Insn)->second; |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 931 | auto *Scope = LI.getLoopFor(Insn->getParent()); |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 932 | |
| 933 | if (!AF) { |
Johannes Doerfert | ec8a217 | 2016-04-25 13:32:36 +0000 | [diff] [blame] | 934 | if (isAffine(Pair.second, Scope, Context)) |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 935 | Acc->DelinearizedSubscripts.push_back(Pair.second); |
| 936 | else |
| 937 | IsNonAffine = true; |
| 938 | } else { |
Tobias Grosser | 1e55db3 | 2017-05-27 15:18:53 +0000 | [diff] [blame] | 939 | if (Shape->DelinearizedSizes.size() == 0) { |
| 940 | Acc->DelinearizedSubscripts.push_back(AF); |
| 941 | } else { |
| 942 | SE.computeAccessFunctions(AF, Acc->DelinearizedSubscripts, |
| 943 | Shape->DelinearizedSizes); |
| 944 | if (Acc->DelinearizedSubscripts.size() == 0) |
| 945 | IsNonAffine = true; |
| 946 | } |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 947 | for (const SCEV *S : Acc->DelinearizedSubscripts) |
Johannes Doerfert | ec8a217 | 2016-04-25 13:32:36 +0000 | [diff] [blame] | 948 | if (!isAffine(S, Scope, Context)) |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 949 | IsNonAffine = true; |
| 950 | } |
| 951 | |
| 952 | // (Possibly) report non affine access |
| 953 | if (IsNonAffine) { |
| 954 | BasePtrHasNonAffine = true; |
| 955 | if (!AllowNonAffine) |
| 956 | invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, Pair.second, |
| 957 | Insn, BaseValue); |
| 958 | if (!KeepGoing && !AllowNonAffine) |
| 959 | return false; |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | if (!BasePtrHasNonAffine) |
Hongbin Zheng | 2262320 | 2016-02-15 00:20:58 +0000 | [diff] [blame] | 964 | Context.InsnToMemAcc.insert(TempMemoryAccesses.begin(), |
| 965 | TempMemoryAccesses.end()); |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 966 | |
| 967 | return true; |
| 968 | } |
| 969 | |
Michael Kruse | c7e0d9c | 2016-03-01 21:44:06 +0000 | [diff] [blame] | 970 | bool ScopDetection::hasBaseAffineAccesses(DetectionContext &Context, |
| 971 | const SCEVUnknown *BasePointer, |
| 972 | Loop *Scope) const { |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 973 | auto Shape = std::shared_ptr<ArrayShape>(new ArrayShape(BasePointer)); |
| 974 | |
| 975 | auto Terms = getDelinearizationTerms(Context, BasePointer); |
| 976 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 977 | SE.findArrayDimensions(Terms, Shape->DelinearizedSizes, |
| 978 | Context.ElementSize[BasePointer]); |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 979 | |
Michael Kruse | c7e0d9c | 2016-03-01 21:44:06 +0000 | [diff] [blame] | 980 | if (!hasValidArraySizes(Context, Shape->DelinearizedSizes, BasePointer, |
| 981 | Scope)) |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 982 | return false; |
| 983 | |
| 984 | return computeAccessFunctions(Context, BasePointer, Shape); |
| 985 | } |
| 986 | |
| 987 | bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const { |
Johannes Doerfert | a792098 | 2016-02-25 14:08:48 +0000 | [diff] [blame] | 988 | // TODO: If we have an unknown access and other non-affine accesses we do |
| 989 | // not try to delinearize them for now. |
| 990 | if (Context.HasUnknownAccess && !Context.NonAffineAccesses.empty()) |
| 991 | return AllowNonAffine; |
| 992 | |
Michael Kruse | c7e0d9c | 2016-03-01 21:44:06 +0000 | [diff] [blame] | 993 | for (auto &Pair : Context.NonAffineAccesses) { |
| 994 | auto *BasePointer = Pair.first; |
| 995 | auto *Scope = Pair.second; |
| 996 | if (!hasBaseAffineAccesses(Context, BasePointer, Scope)) { |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 997 | if (KeepGoing) |
| 998 | continue; |
| 999 | else |
| 1000 | return false; |
| 1001 | } |
Michael Kruse | c7e0d9c | 2016-03-01 21:44:06 +0000 | [diff] [blame] | 1002 | } |
Tobias Grosser | d68ba42 | 2015-11-24 05:00:36 +0000 | [diff] [blame] | 1003 | return true; |
| 1004 | } |
| 1005 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1006 | bool ScopDetection::isValidAccess(Instruction *Inst, const SCEV *AF, |
| 1007 | const SCEVUnknown *BP, |
| 1008 | DetectionContext &Context) const { |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 1009 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1010 | if (!BP) |
Michael Kruse | 70131d3 | 2016-01-27 17:09:17 +0000 | [diff] [blame] | 1011 | return invalid<ReportNoBasePtr>(Context, /*Assert=*/true, Inst); |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 1012 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1013 | auto *BV = BP->getValue(); |
| 1014 | if (isa<UndefValue>(BV)) |
Michael Kruse | 70131d3 | 2016-01-27 17:09:17 +0000 | [diff] [blame] | 1015 | return invalid<ReportUndefBasePtr>(Context, /*Assert=*/true, Inst); |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 1016 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1017 | // FIXME: Think about allowing IntToPtrInst |
| 1018 | if (IntToPtrInst *Inst = dyn_cast<IntToPtrInst>(BV)) |
| 1019 | return invalid<ReportIntToPtr>(Context, /*Assert=*/true, Inst); |
| 1020 | |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 1021 | // Check that the base address of the access is invariant in the current |
| 1022 | // region. |
Michael Kruse | 5a4ec5c | 2017-03-07 20:28:43 +0000 | [diff] [blame] | 1023 | if (!isInvariant(*BV, Context.CurRegion, Context)) |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1024 | return invalid<ReportVariantBasePtr>(Context, /*Assert=*/true, BV, Inst); |
Tobias Grosser | 458fb78 | 2014-01-28 12:58:58 +0000 | [diff] [blame] | 1025 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1026 | AF = SE.getMinusSCEV(AF, BP); |
Tobias Grosser | b8710b5 | 2011-11-10 12:44:50 +0000 | [diff] [blame] | 1027 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1028 | const SCEV *Size; |
| 1029 | if (!isa<MemIntrinsic>(Inst)) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1030 | Size = SE.getElementSize(Inst); |
Tobias Grosser | 8ebdc2d | 2016-02-07 08:48:57 +0000 | [diff] [blame] | 1031 | } else { |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1032 | auto *SizeTy = |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1033 | SE.getEffectiveSCEVType(PointerType::getInt8PtrTy(SE.getContext())); |
| 1034 | Size = SE.getConstant(SizeTy, 8); |
Tobias Grosser | 8ebdc2d | 2016-02-07 08:48:57 +0000 | [diff] [blame] | 1035 | } |
Tobias Grosser | bcd4eff | 2014-09-13 14:47:40 +0000 | [diff] [blame] | 1036 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1037 | if (Context.ElementSize[BP]) { |
| 1038 | if (!AllowDifferentTypes && Context.ElementSize[BP] != Size) |
| 1039 | return invalid<ReportDifferentArrayElementSize>(Context, /*Assert=*/true, |
| 1040 | Inst, BV); |
| 1041 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1042 | Context.ElementSize[BP] = SE.getSMinExpr(Size, Context.ElementSize[BP]); |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1043 | } else { |
| 1044 | Context.ElementSize[BP] = Size; |
| 1045 | } |
| 1046 | |
| 1047 | bool IsVariantInNonAffineLoop = false; |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 1048 | SetVector<const Loop *> Loops; |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1049 | findLoops(AF, Loops); |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 1050 | for (const Loop *L : Loops) |
| 1051 | if (Context.BoxedLoopsSet.count(L)) |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1052 | IsVariantInNonAffineLoop = true; |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 1053 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1054 | auto *Scope = LI.getLoopFor(Inst->getParent()); |
Johannes Doerfert | ec8a217 | 2016-04-25 13:32:36 +0000 | [diff] [blame] | 1055 | bool IsAffine = !IsVariantInNonAffineLoop && isAffine(AF, Scope, Context); |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1056 | // Do not try to delinearize memory intrinsics and force them to be affine. |
| 1057 | if (isa<MemIntrinsic>(Inst) && !IsAffine) { |
| 1058 | return invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF, Inst, |
| 1059 | BV); |
| 1060 | } else if (PollyDelinearize && !IsVariantInNonAffineLoop) { |
| 1061 | Context.Accesses[BP].push_back({Inst, AF}); |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 1062 | |
Tobias Grosser | 1e55db3 | 2017-05-27 15:18:53 +0000 | [diff] [blame] | 1063 | if (!IsAffine || hasIVParams(AF)) |
Michael Kruse | c7e0d9c | 2016-03-01 21:44:06 +0000 | [diff] [blame] | 1064 | Context.NonAffineAccesses.insert( |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1065 | std::make_pair(BP, LI.getLoopFor(Inst->getParent()))); |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1066 | } else if (!AllowNonAffine && !IsAffine) { |
| 1067 | return invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF, Inst, |
| 1068 | BV); |
Sebastian Pop | 1801668 | 2014-04-08 21:20:44 +0000 | [diff] [blame] | 1069 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1070 | |
Tobias Grosser | 1eedb67 | 2014-09-24 21:04:29 +0000 | [diff] [blame] | 1071 | if (IgnoreAliasing) |
Sebastian Pop | 8c2d753 | 2013-07-03 22:50:36 +0000 | [diff] [blame] | 1072 | return true; |
Tobias Grosser | fff5adc | 2011-11-10 13:21:43 +0000 | [diff] [blame] | 1073 | |
Sebastian Pop | 8c2d753 | 2013-07-03 22:50:36 +0000 | [diff] [blame] | 1074 | // Check if the base pointer of the memory access does alias with |
| 1075 | // any other pointer. This cannot be handled at the moment. |
Benjamin Kramer | ae81abf | 2014-10-05 11:58:57 +0000 | [diff] [blame] | 1076 | AAMDNodes AATags; |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1077 | Inst->getAAMetadata(AATags); |
Benjamin Kramer | ae81abf | 2014-10-05 11:58:57 +0000 | [diff] [blame] | 1078 | AliasSet &AS = Context.AST.getAliasSetForPointer( |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1079 | BP->getValue(), MemoryLocation::UnknownSize, AATags); |
Tobias Grosser | 428b3e4 | 2013-02-04 15:46:25 +0000 | [diff] [blame] | 1080 | |
Tobias Grosser | 1eedb67 | 2014-09-24 21:04:29 +0000 | [diff] [blame] | 1081 | if (!AS.isMustAlias()) { |
| 1082 | if (PollyUseRuntimeAliasChecks) { |
| 1083 | bool CanBuildRunTimeCheck = true; |
| 1084 | // The run-time alias check places code that involves the base pointer at |
| 1085 | // the beginning of the SCoP. This breaks if the base pointer is defined |
| 1086 | // inside the scop. Hence, we can only create a run-time check if we are |
| 1087 | // sure the base pointer is not an instruction defined inside the scop. |
Johannes Doerfert | 09e3697 | 2015-10-07 20:17:36 +0000 | [diff] [blame] | 1088 | // However, we can ignore loads that will be hoisted. |
Tobias Grosser | 1eedb67 | 2014-09-24 21:04:29 +0000 | [diff] [blame] | 1089 | for (const auto &Ptr : AS) { |
| 1090 | Instruction *Inst = dyn_cast<Instruction>(Ptr.getValue()); |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1091 | if (Inst && Context.CurRegion.contains(Inst)) { |
Johannes Doerfert | 09e3697 | 2015-10-07 20:17:36 +0000 | [diff] [blame] | 1092 | auto *Load = dyn_cast<LoadInst>(Inst); |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1093 | if (Load && isHoistableLoad(Load, Context.CurRegion, LI, SE, DT)) { |
Johannes Doerfert | 09e3697 | 2015-10-07 20:17:36 +0000 | [diff] [blame] | 1094 | Context.RequiredILS.insert(Load); |
| 1095 | continue; |
| 1096 | } |
| 1097 | |
Tobias Grosser | 1eedb67 | 2014-09-24 21:04:29 +0000 | [diff] [blame] | 1098 | CanBuildRunTimeCheck = false; |
| 1099 | break; |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | if (CanBuildRunTimeCheck) |
| 1104 | return true; |
| 1105 | } |
Michael Kruse | 70131d3 | 2016-01-27 17:09:17 +0000 | [diff] [blame] | 1106 | return invalid<ReportAlias>(Context, /*Assert=*/true, Inst, AS); |
Tobias Grosser | 1eedb67 | 2014-09-24 21:04:29 +0000 | [diff] [blame] | 1107 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1108 | |
| 1109 | return true; |
| 1110 | } |
| 1111 | |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1112 | bool ScopDetection::isValidMemoryAccess(MemAccInst Inst, |
| 1113 | DetectionContext &Context) const { |
| 1114 | Value *Ptr = Inst.getPointerOperand(); |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1115 | Loop *L = LI.getLoopFor(Inst->getParent()); |
| 1116 | const SCEV *AccessFunction = SE.getSCEVAtScope(Ptr, L); |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1117 | const SCEVUnknown *BasePointer; |
| 1118 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1119 | BasePointer = dyn_cast<SCEVUnknown>(SE.getPointerBase(AccessFunction)); |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1120 | |
| 1121 | return isValidAccess(Inst, AccessFunction, BasePointer, Context); |
| 1122 | } |
| 1123 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1124 | bool ScopDetection::isValidInstruction(Instruction &Inst, |
| 1125 | DetectionContext &Context) const { |
Tobias Grosser | b12b006 | 2015-11-11 12:44:18 +0000 | [diff] [blame] | 1126 | for (auto &Op : Inst.operands()) { |
| 1127 | auto *OpInst = dyn_cast<Instruction>(&Op); |
| 1128 | |
| 1129 | if (!OpInst) |
| 1130 | continue; |
| 1131 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1132 | if (isErrorBlock(*OpInst->getParent(), Context.CurRegion, LI, DT)) |
Tobias Grosser | b12b006 | 2015-11-11 12:44:18 +0000 | [diff] [blame] | 1133 | return false; |
| 1134 | } |
| 1135 | |
Johannes Doerfert | 81c41b9 | 2016-04-09 21:55:58 +0000 | [diff] [blame] | 1136 | if (isa<LandingPadInst>(&Inst) || isa<ResumeInst>(&Inst)) |
| 1137 | return false; |
| 1138 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1139 | // We only check the call instruction but not invoke instruction. |
| 1140 | if (CallInst *CI = dyn_cast<CallInst>(&Inst)) { |
Johannes Doerfert | cea6193 | 2016-02-21 19:13:19 +0000 | [diff] [blame] | 1141 | if (isValidCallInst(*CI, Context)) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1142 | return true; |
| 1143 | |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 1144 | return invalid<ReportFuncCall>(Context, /*Assert=*/true, &Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Tobias Grosser | 1f0236d | 2016-11-21 09:07:30 +0000 | [diff] [blame] | 1147 | if (!Inst.mayReadOrWriteMemory()) { |
Tobias Grosser | 5b1a7f2 | 2013-07-22 03:50:33 +0000 | [diff] [blame] | 1148 | if (!isa<AllocaInst>(Inst)) |
| 1149 | return true; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1150 | |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 1151 | return invalid<ReportAlloca>(Context, /*Assert=*/true, &Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | // Check the access function. |
Michael Kruse | 70131d3 | 2016-01-27 17:09:17 +0000 | [diff] [blame] | 1155 | if (auto MemInst = MemAccInst::dyn_cast(Inst)) { |
Hongbin Zheng | 8efb22e | 2016-02-27 01:49:58 +0000 | [diff] [blame] | 1156 | Context.hasStores |= isa<StoreInst>(MemInst); |
| 1157 | Context.hasLoads |= isa<LoadInst>(MemInst); |
Michael Kruse | 70131d3 | 2016-01-27 17:09:17 +0000 | [diff] [blame] | 1158 | if (!MemInst.isSimple()) |
| 1159 | return invalid<ReportNonSimpleMemoryAccess>(Context, /*Assert=*/true, |
| 1160 | &Inst); |
Tobias Grosser | bf45e74 | 2015-10-25 13:48:40 +0000 | [diff] [blame] | 1161 | |
Michael Kruse | 70131d3 | 2016-01-27 17:09:17 +0000 | [diff] [blame] | 1162 | return isValidMemoryAccess(MemInst, Context); |
Tobias Grosser | d1e33e7 | 2015-02-19 05:31:07 +0000 | [diff] [blame] | 1163 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1164 | |
| 1165 | // We do not know this instruction, therefore we assume it is invalid. |
Andreas Simbuerger | 01a37a0 | 2014-04-02 11:54:01 +0000 | [diff] [blame] | 1166 | return invalid<ReportUnknownInst>(Context, /*Assert=*/true, &Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
Tobias Grosser | 349d1c3 | 2016-09-20 17:05:22 +0000 | [diff] [blame] | 1169 | /// Check whether @p L has exiting blocks. |
| 1170 | /// |
| 1171 | /// @param L The loop of interest |
| 1172 | /// |
| 1173 | /// @return True if the loop has exiting blocks, false otherwise. |
| 1174 | static bool hasExitingBlocks(Loop *L) { |
| 1175 | SmallVector<BasicBlock *, 4> ExitingBlocks; |
| 1176 | L->getExitingBlocks(ExitingBlocks); |
| 1177 | return !ExitingBlocks.empty(); |
| 1178 | } |
| 1179 | |
Johannes Doerfert | d020b77 | 2015-08-27 06:53:52 +0000 | [diff] [blame] | 1180 | bool ScopDetection::canUseISLTripCount(Loop *L, |
| 1181 | DetectionContext &Context) const { |
Johannes Doerfert | 30ffb6f | 2015-10-04 14:53:18 +0000 | [diff] [blame] | 1182 | // Ensure the loop has valid exiting blocks as well as latches, otherwise we |
| 1183 | // need to overapproximate it as a boxed loop. |
| 1184 | SmallVector<BasicBlock *, 4> LoopControlBlocks; |
Tobias Grosser | 151ae32 | 2016-04-03 19:36:52 +0000 | [diff] [blame] | 1185 | L->getExitingBlocks(LoopControlBlocks); |
Johannes Doerfert | d5edbd6 | 2016-04-03 23:09:06 +0000 | [diff] [blame] | 1186 | L->getLoopLatches(LoopControlBlocks); |
Johannes Doerfert | 30ffb6f | 2015-10-04 14:53:18 +0000 | [diff] [blame] | 1187 | for (BasicBlock *ControlBB : LoopControlBlocks) { |
Tobias Grosser | b76cd3c | 2015-11-11 08:42:20 +0000 | [diff] [blame] | 1188 | if (!isValidCFG(*ControlBB, true, false, Context)) |
Johannes Doerfert | d020b77 | 2015-08-27 06:53:52 +0000 | [diff] [blame] | 1189 | return false; |
| 1190 | } |
| 1191 | |
Johannes Doerfert | d020b77 | 2015-08-27 06:53:52 +0000 | [diff] [blame] | 1192 | // We can use ISL to compute the trip count of L. |
| 1193 | return true; |
| 1194 | } |
| 1195 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1196 | bool ScopDetection::isValidLoop(Loop *L, DetectionContext &Context) const { |
Tobias Grosser | 349d1c3 | 2016-09-20 17:05:22 +0000 | [diff] [blame] | 1197 | // Loops that contain part but not all of the blocks of a region cannot be |
| 1198 | // handled by the schedule generation. Such loop constructs can happen |
| 1199 | // because a region can contain BBs that have no path to the exit block |
| 1200 | // (Infinite loops, UnreachableInst), but such blocks are never part of a |
| 1201 | // loop. |
| 1202 | // |
| 1203 | // _______________ |
| 1204 | // | Loop Header | <-----------. |
| 1205 | // --------------- | |
| 1206 | // | | |
| 1207 | // _______________ ______________ |
| 1208 | // | RegionEntry |-----> | RegionExit |-----> |
| 1209 | // --------------- -------------- |
| 1210 | // | |
| 1211 | // _______________ |
| 1212 | // | EndlessLoop | <--. |
| 1213 | // --------------- | |
| 1214 | // | | |
| 1215 | // \------------/ |
| 1216 | // |
| 1217 | // In the example above, the loop (LoopHeader,RegionEntry,RegionExit) is |
| 1218 | // neither entirely contained in the region RegionEntry->RegionExit |
| 1219 | // (containing RegionEntry,EndlessLoop) nor is the region entirely contained |
| 1220 | // in the loop. |
| 1221 | // The block EndlessLoop is contained in the region because Region::contains |
| 1222 | // tests whether it is not dominated by RegionExit. This is probably to not |
| 1223 | // having to query the PostdominatorTree. Instead of an endless loop, a dead |
| 1224 | // end can also be formed by an UnreachableInst. This case is already caught |
| 1225 | // by isErrorBlock(). We hence only have to reject endless loops here. |
| 1226 | if (!hasExitingBlocks(L)) |
| 1227 | return invalid<ReportLoopHasNoExit>(Context, /*Assert=*/true, L); |
| 1228 | |
Johannes Doerfert | f61df69 | 2015-10-04 14:56:08 +0000 | [diff] [blame] | 1229 | if (canUseISLTripCount(L, Context)) |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 1230 | return true; |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 1231 | |
Johannes Doerfert | b68cffb | 2015-09-10 15:27:46 +0000 | [diff] [blame] | 1232 | if (AllowNonAffineSubLoops && AllowNonAffineSubRegions) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1233 | Region *R = RI.getRegionFor(L->getHeader()); |
Johannes Doerfert | 757a32b | 2015-10-04 14:54:27 +0000 | [diff] [blame] | 1234 | while (R != &Context.CurRegion && !R->contains(L)) |
| 1235 | R = R->getParent(); |
| 1236 | |
| 1237 | if (addOverApproximatedRegion(R, Context)) |
| 1238 | return true; |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 1239 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1240 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1241 | const SCEV *LoopCount = SE.getBackedgeTakenCount(L); |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 1242 | return invalid<ReportLoopBound>(Context, /*Assert=*/true, L, LoopCount); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
Tobias Grosser | c80d697 | 2016-09-02 06:33:33 +0000 | [diff] [blame] | 1245 | /// Return the number of loops in @p L (incl. @p L) that have a trip |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1246 | /// count that is not known to be less than @MinProfitableTrips. |
| 1247 | ScopDetection::LoopStats |
| 1248 | ScopDetection::countBeneficialSubLoops(Loop *L, ScalarEvolution &SE, |
Tobias Grosser | cd01a36 | 2017-02-17 08:12:36 +0000 | [diff] [blame] | 1249 | unsigned MinProfitableTrips) { |
Johannes Doerfert | 7175bdf | 2015-09-20 14:56:54 +0000 | [diff] [blame] | 1250 | auto *TripCount = SE.getBackedgeTakenCount(L); |
| 1251 | |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1252 | int NumLoops = 1; |
| 1253 | int MaxLoopDepth = 1; |
Johannes Doerfert | 7175bdf | 2015-09-20 14:56:54 +0000 | [diff] [blame] | 1254 | if (auto *TripCountC = dyn_cast<SCEVConstant>(TripCount)) |
Johannes Doerfert | f61df69 | 2015-10-04 14:56:08 +0000 | [diff] [blame] | 1255 | if (TripCountC->getType()->getScalarSizeInBits() <= 64) |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1256 | if (TripCountC->getValue()->getZExtValue() <= MinProfitableTrips) |
| 1257 | NumLoops -= 1; |
Johannes Doerfert | 7175bdf | 2015-09-20 14:56:54 +0000 | [diff] [blame] | 1258 | |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1259 | for (auto &SubLoop : *L) { |
| 1260 | LoopStats Stats = countBeneficialSubLoops(SubLoop, SE, MinProfitableTrips); |
| 1261 | NumLoops += Stats.NumLoops; |
Tobias Grosser | 65ce936 | 2017-02-17 08:08:54 +0000 | [diff] [blame] | 1262 | MaxLoopDepth = std::max(MaxLoopDepth, Stats.MaxDepth + 1); |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1263 | } |
Johannes Doerfert | 7175bdf | 2015-09-20 14:56:54 +0000 | [diff] [blame] | 1264 | |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1265 | return {NumLoops, MaxLoopDepth}; |
Johannes Doerfert | 7175bdf | 2015-09-20 14:56:54 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1268 | ScopDetection::LoopStats |
Tobias Grosser | cd01a36 | 2017-02-17 08:12:36 +0000 | [diff] [blame] | 1269 | ScopDetection::countBeneficialLoops(Region *R, ScalarEvolution &SE, |
| 1270 | LoopInfo &LI, unsigned MinProfitableTrips) { |
Johannes Doerfert | f61df69 | 2015-10-04 14:56:08 +0000 | [diff] [blame] | 1271 | int LoopNum = 0; |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1272 | int MaxLoopDepth = 0; |
Tobias Grosser | ed21a1f | 2015-08-27 16:55:18 +0000 | [diff] [blame] | 1273 | |
Tobias Grosser | cd01a36 | 2017-02-17 08:12:36 +0000 | [diff] [blame] | 1274 | auto L = LI.getLoopFor(R->getEntry()); |
Tobias Grosser | 050e0cb | 2015-08-31 12:08:11 +0000 | [diff] [blame] | 1275 | L = L ? R->outermostLoopInRegion(L) : nullptr; |
| 1276 | L = L ? L->getParentLoop() : nullptr; |
Tobias Grosser | ed21a1f | 2015-08-27 16:55:18 +0000 | [diff] [blame] | 1277 | |
Tobias Grosser | 050e0cb | 2015-08-31 12:08:11 +0000 | [diff] [blame] | 1278 | auto SubLoops = |
Tobias Grosser | cd01a36 | 2017-02-17 08:12:36 +0000 | [diff] [blame] | 1279 | L ? L->getSubLoopsVector() : std::vector<Loop *>(LI.begin(), LI.end()); |
Tobias Grosser | 050e0cb | 2015-08-31 12:08:11 +0000 | [diff] [blame] | 1280 | |
| 1281 | for (auto &SubLoop : SubLoops) |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1282 | if (R->contains(SubLoop)) { |
| 1283 | LoopStats Stats = |
Tobias Grosser | cd01a36 | 2017-02-17 08:12:36 +0000 | [diff] [blame] | 1284 | countBeneficialSubLoops(SubLoop, SE, MinProfitableTrips); |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1285 | LoopNum += Stats.NumLoops; |
| 1286 | MaxLoopDepth = std::max(MaxLoopDepth, Stats.MaxDepth); |
| 1287 | } |
Tobias Grosser | 050e0cb | 2015-08-31 12:08:11 +0000 | [diff] [blame] | 1288 | |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1289 | return {LoopNum, MaxLoopDepth}; |
Tobias Grosser | ed21a1f | 2015-08-27 16:55:18 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1292 | Region *ScopDetection::expandRegion(Region &R) { |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 1293 | // Initial no valid region was found (greater than R) |
Tobias Grosser | d5d93ec | 2015-06-04 17:59:54 +0000 | [diff] [blame] | 1294 | std::unique_ptr<Region> LastValidRegion; |
| 1295 | auto ExpandedRegion = std::unique_ptr<Region>(R.getExpandedRegion()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1296 | |
| 1297 | DEBUG(dbgs() << "\tExpanding " << R.getNameStr() << "\n"); |
| 1298 | |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 1299 | while (ExpandedRegion) { |
Johannes Doerfert | c06b7d6 | 2015-10-07 20:46:06 +0000 | [diff] [blame] | 1300 | const auto &It = DetectionContextMap.insert(std::make_pair( |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 1301 | getBBPairForRegion(ExpandedRegion.get()), |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1302 | DetectionContext(*ExpandedRegion, AA, false /*verifying*/))); |
Johannes Doerfert | c06b7d6 | 2015-10-07 20:46:06 +0000 | [diff] [blame] | 1303 | DetectionContext &Context = It.first->second; |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 1304 | DEBUG(dbgs() << "\t\tTrying " << ExpandedRegion->getNameStr() << "\n"); |
Andreas Simbuerger | b379edb | 2014-06-27 06:21:14 +0000 | [diff] [blame] | 1305 | // Only expand when we did not collect errors. |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1306 | |
Johannes Doerfert | 717b866 | 2015-09-08 21:44:27 +0000 | [diff] [blame] | 1307 | if (!Context.Log.hasErrors()) { |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 1308 | // If the exit is valid check all blocks |
| 1309 | // - if true, a valid region was found => store it + keep expanding |
| 1310 | // - if false, .tbd. => stop (should this really end the loop?) |
Johannes Doerfert | e46925f | 2015-10-01 10:59:14 +0000 | [diff] [blame] | 1311 | if (!allBlocksValid(Context) || Context.Log.hasErrors()) { |
| 1312 | removeCachedResults(*ExpandedRegion); |
Michael Kruse | a6cc0d3 | 2016-08-08 22:39:32 +0000 | [diff] [blame] | 1313 | DetectionContextMap.erase(It.first); |
Andreas Simbuerger | b379edb | 2014-06-27 06:21:14 +0000 | [diff] [blame] | 1314 | break; |
Johannes Doerfert | e46925f | 2015-10-01 10:59:14 +0000 | [diff] [blame] | 1315 | } |
Andreas Simbuerger | b379edb | 2014-06-27 06:21:14 +0000 | [diff] [blame] | 1316 | |
Tobias Grosser | d7e5864 | 2013-04-10 06:55:45 +0000 | [diff] [blame] | 1317 | // Store this region, because it is the greatest valid (encountered so |
| 1318 | // far). |
Michael Kruse | a6cc0d3 | 2016-08-08 22:39:32 +0000 | [diff] [blame] | 1319 | if (LastValidRegion) { |
| 1320 | removeCachedResults(*LastValidRegion); |
| 1321 | DetectionContextMap.erase(getBBPairForRegion(LastValidRegion.get())); |
| 1322 | } |
Tobias Grosser | d5d93ec | 2015-06-04 17:59:54 +0000 | [diff] [blame] | 1323 | LastValidRegion = std::move(ExpandedRegion); |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 1324 | |
| 1325 | // Create and test the next greater region (if any) |
Tobias Grosser | d5d93ec | 2015-06-04 17:59:54 +0000 | [diff] [blame] | 1326 | ExpandedRegion = |
| 1327 | std::unique_ptr<Region>(LastValidRegion->getExpandedRegion()); |
Hongbin Zheng | ed986ab | 2012-04-07 15:14:28 +0000 | [diff] [blame] | 1328 | |
| 1329 | } else { |
| 1330 | // Create and test the next greater region (if any) |
Johannes Doerfert | c06b7d6 | 2015-10-07 20:46:06 +0000 | [diff] [blame] | 1331 | removeCachedResults(*ExpandedRegion); |
Michael Kruse | a6cc0d3 | 2016-08-08 22:39:32 +0000 | [diff] [blame] | 1332 | DetectionContextMap.erase(It.first); |
Tobias Grosser | d5d93ec | 2015-06-04 17:59:54 +0000 | [diff] [blame] | 1333 | ExpandedRegion = |
| 1334 | std::unique_ptr<Region>(ExpandedRegion->getExpandedRegion()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1335 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
Tobias Grosser | 378a9f2 | 2013-11-16 19:34:11 +0000 | [diff] [blame] | 1338 | DEBUG({ |
| 1339 | if (LastValidRegion) |
| 1340 | dbgs() << "\tto " << LastValidRegion->getNameStr() << "\n"; |
| 1341 | else |
| 1342 | dbgs() << "\tExpanding " << R.getNameStr() << " failed\n"; |
| 1343 | }); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1344 | |
Tobias Grosser | d5d93ec | 2015-06-04 17:59:54 +0000 | [diff] [blame] | 1345 | return LastValidRegion.release(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1346 | } |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1347 | static bool regionWithoutLoops(Region &R, LoopInfo &LI) { |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 1348 | for (const BasicBlock *BB : R.blocks()) |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1349 | if (R.contains(LI.getLoopFor(BB))) |
Sebastian Pop | 2c9ec2e | 2013-06-03 16:35:37 +0000 | [diff] [blame] | 1350 | return false; |
| 1351 | |
| 1352 | return true; |
| 1353 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1354 | |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1355 | void ScopDetection::removeCachedResultsRecursively(const Region &R) { |
David Blaikie | b035f6d | 2014-04-15 18:45:27 +0000 | [diff] [blame] | 1356 | for (auto &SubRegion : R) { |
Johannes Doerfert | e46925f | 2015-10-01 10:59:14 +0000 | [diff] [blame] | 1357 | if (ValidRegions.count(SubRegion.get())) { |
| 1358 | removeCachedResults(*SubRegion.get()); |
Johannes Doerfert | e46925f | 2015-10-01 10:59:14 +0000 | [diff] [blame] | 1359 | } else |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1360 | removeCachedResultsRecursively(*SubRegion); |
Tobias Grosser | 28a70c5 | 2014-01-29 19:05:30 +0000 | [diff] [blame] | 1361 | } |
Tobias Grosser | 28a70c5 | 2014-01-29 19:05:30 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
Johannes Doerfert | e46925f | 2015-10-01 10:59:14 +0000 | [diff] [blame] | 1364 | void ScopDetection::removeCachedResults(const Region &R) { |
| 1365 | ValidRegions.remove(&R); |
Johannes Doerfert | e46925f | 2015-10-01 10:59:14 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1368 | void ScopDetection::findScops(Region &R) { |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 1369 | const auto &It = DetectionContextMap.insert(std::make_pair( |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1370 | getBBPairForRegion(&R), DetectionContext(R, AA, false /*verifying*/))); |
Johannes Doerfert | c06b7d6 | 2015-10-07 20:46:06 +0000 | [diff] [blame] | 1371 | DetectionContext &Context = It.first->second; |
Johannes Doerfert | 6a4d81c | 2015-03-08 15:11:50 +0000 | [diff] [blame] | 1372 | |
| 1373 | bool RegionIsValid = false; |
Michael Kruse | 0b56681 | 2016-02-29 16:54:18 +0000 | [diff] [blame] | 1374 | if (!PollyProcessUnprofitable && regionWithoutLoops(R, LI)) |
Johannes Doerfert | 6a4d81c | 2015-03-08 15:11:50 +0000 | [diff] [blame] | 1375 | invalid<ReportUnprofitable>(Context, /*Assert=*/true, &R); |
Michael Kruse | 0b56681 | 2016-02-29 16:54:18 +0000 | [diff] [blame] | 1376 | else |
Johannes Doerfert | 6a4d81c | 2015-03-08 15:11:50 +0000 | [diff] [blame] | 1377 | RegionIsValid = isValidRegion(Context); |
| 1378 | |
Johannes Doerfert | 3f1c285 | 2015-02-19 18:11:50 +0000 | [diff] [blame] | 1379 | bool HasErrors = !RegionIsValid || Context.Log.size() > 0; |
Andreas Simbuerger | 0447240 | 2014-05-24 09:25:10 +0000 | [diff] [blame] | 1380 | |
Johannes Doerfert | e46925f | 2015-10-01 10:59:14 +0000 | [diff] [blame] | 1381 | if (HasErrors) { |
| 1382 | removeCachedResults(R); |
| 1383 | } else { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1384 | ValidRegions.insert(&R); |
| 1385 | return; |
| 1386 | } |
| 1387 | |
David Blaikie | b035f6d | 2014-04-15 18:45:27 +0000 | [diff] [blame] | 1388 | for (auto &SubRegion : R) |
Tobias Grosser | 00dc309 | 2014-03-02 12:02:46 +0000 | [diff] [blame] | 1389 | findScops(*SubRegion); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1390 | |
| 1391 | // Try to expand regions. |
| 1392 | // |
| 1393 | // As the region tree normally only contains canonical regions, non canonical |
| 1394 | // regions that form a Scop are not found. Therefore, those non canonical |
| 1395 | // regions are checked by expanding the canonical ones. |
| 1396 | |
Tobias Grosser | 0d1eee3 | 2013-02-05 11:56:05 +0000 | [diff] [blame] | 1397 | std::vector<Region *> ToExpand; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1398 | |
David Blaikie | b035f6d | 2014-04-15 18:45:27 +0000 | [diff] [blame] | 1399 | for (auto &SubRegion : R) |
| 1400 | ToExpand.push_back(SubRegion.get()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1401 | |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 1402 | for (Region *CurrentRegion : ToExpand) { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1403 | // Skip invalid regions. Regions may become invalid, if they are element of |
| 1404 | // an already expanded region. |
David Peixotto | 8da2b93 | 2014-10-22 20:39:07 +0000 | [diff] [blame] | 1405 | if (!ValidRegions.count(CurrentRegion)) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1406 | continue; |
| 1407 | |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 1408 | // Skip regions that had errors. |
| 1409 | bool HadErrors = lookupRejectionLog(CurrentRegion)->hasErrors(); |
| 1410 | if (HadErrors) |
| 1411 | continue; |
| 1412 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1413 | Region *ExpandedR = expandRegion(*CurrentRegion); |
| 1414 | |
| 1415 | if (!ExpandedR) |
| 1416 | continue; |
| 1417 | |
| 1418 | R.addSubRegion(ExpandedR, true); |
| 1419 | ValidRegions.insert(ExpandedR); |
Johannes Doerfert | e46925f | 2015-10-01 10:59:14 +0000 | [diff] [blame] | 1420 | removeCachedResults(*CurrentRegion); |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1421 | removeCachedResultsRecursively(*ExpandedR); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | bool ScopDetection::allBlocksValid(DetectionContext &Context) const { |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 1426 | Region &CurRegion = Context.CurRegion; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1427 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 1428 | for (const BasicBlock *BB : CurRegion.blocks()) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1429 | Loop *L = LI.getLoopFor(BB); |
Tobias Grosser | a3aa423 | 2017-07-15 22:42:17 +0000 | [diff] [blame] | 1430 | if (L && L->getHeader() == BB) { |
| 1431 | if (CurRegion.contains(L)) { |
| 1432 | if (!isValidLoop(L, Context) && !KeepGoing) |
| 1433 | return false; |
| 1434 | } else { |
| 1435 | SmallVector<BasicBlock *, 1> Latches; |
| 1436 | L->getLoopLatches(Latches); |
| 1437 | for (BasicBlock *Latch : Latches) |
| 1438 | if (CurRegion.contains(Latch)) |
| 1439 | return invalid<ReportLoopOnlySomeLatches>(Context, /*Assert=*/true, |
| 1440 | L); |
| 1441 | } |
| 1442 | } |
Sebastian Pop | b88ea5e | 2013-06-11 22:20:32 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
Johannes Doerfert | 90db75e | 2015-09-10 17:51:27 +0000 | [diff] [blame] | 1445 | for (BasicBlock *BB : CurRegion.blocks()) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1446 | bool IsErrorBlock = isErrorBlock(*BB, CurRegion, LI, DT); |
Tobias Grosser | b76cd3c | 2015-11-11 08:42:20 +0000 | [diff] [blame] | 1447 | |
| 1448 | // Also check exception blocks (and possibly register them as non-affine |
| 1449 | // regions). Even though exception blocks are not modeled, we use them |
| 1450 | // to forward-propagate domain constraints during ScopInfo construction. |
| 1451 | if (!isValidCFG(*BB, false, IsErrorBlock, Context) && !KeepGoing) |
| 1452 | return false; |
| 1453 | |
| 1454 | if (IsErrorBlock) |
Johannes Doerfert | 90db75e | 2015-09-10 17:51:27 +0000 | [diff] [blame] | 1455 | continue; |
| 1456 | |
Tobias Grosser | 1d19190 | 2014-03-03 13:13:55 +0000 | [diff] [blame] | 1457 | for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; ++I) |
Andreas Simbuerger | 0447240 | 2014-05-24 09:25:10 +0000 | [diff] [blame] | 1458 | if (!isValidInstruction(*I, Context) && !KeepGoing) |
Sebastian Pop | 8ca899c | 2013-06-14 20:20:43 +0000 | [diff] [blame] | 1459 | return false; |
Johannes Doerfert | 90db75e | 2015-09-10 17:51:27 +0000 | [diff] [blame] | 1460 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1461 | |
Sebastian Pop | e8863b8 | 2014-05-12 19:02:02 +0000 | [diff] [blame] | 1462 | if (!hasAffineMemoryAccesses(Context)) |
Sebastian Pop | 46e1ecd | 2014-05-09 22:45:15 +0000 | [diff] [blame] | 1463 | return false; |
| 1464 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1465 | return true; |
| 1466 | } |
| 1467 | |
Tobias Grosser | c1a269b | 2015-12-21 21:00:43 +0000 | [diff] [blame] | 1468 | bool ScopDetection::hasSufficientCompute(DetectionContext &Context, |
| 1469 | int NumLoops) const { |
| 1470 | int InstCount = 0; |
| 1471 | |
Tobias Grosser | b316dc1 | 2016-09-08 14:08:05 +0000 | [diff] [blame] | 1472 | if (NumLoops == 0) |
| 1473 | return false; |
| 1474 | |
Tobias Grosser | c1a269b | 2015-12-21 21:00:43 +0000 | [diff] [blame] | 1475 | for (auto *BB : Context.CurRegion.blocks()) |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1476 | if (Context.CurRegion.contains(LI.getLoopFor(BB))) |
Tobias Grosser | c6424ae | 2015-12-22 17:38:59 +0000 | [diff] [blame] | 1477 | InstCount += BB->size(); |
Tobias Grosser | c1a269b | 2015-12-21 21:00:43 +0000 | [diff] [blame] | 1478 | |
| 1479 | InstCount = InstCount / NumLoops; |
| 1480 | |
| 1481 | return InstCount >= ProfitabilityMinPerLoopInstructions; |
| 1482 | } |
| 1483 | |
Johannes Doerfert | bf9473b | 2016-05-10 14:42:30 +0000 | [diff] [blame] | 1484 | bool ScopDetection::hasPossiblyDistributableLoop( |
| 1485 | DetectionContext &Context) const { |
| 1486 | for (auto *BB : Context.CurRegion.blocks()) { |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1487 | auto *L = LI.getLoopFor(BB); |
Johannes Doerfert | bf9473b | 2016-05-10 14:42:30 +0000 | [diff] [blame] | 1488 | if (!Context.CurRegion.contains(L)) |
| 1489 | continue; |
| 1490 | if (Context.BoxedLoopsSet.count(L)) |
| 1491 | continue; |
| 1492 | unsigned StmtsWithStoresInLoops = 0; |
| 1493 | for (auto *LBB : L->blocks()) { |
| 1494 | bool MemStore = false; |
| 1495 | for (auto &I : *LBB) |
| 1496 | MemStore |= isa<StoreInst>(&I); |
| 1497 | StmtsWithStoresInLoops += MemStore; |
| 1498 | } |
| 1499 | return (StmtsWithStoresInLoops > 1); |
| 1500 | } |
| 1501 | return false; |
| 1502 | } |
| 1503 | |
Tobias Grosser | 97fc5bb | 2015-12-21 12:14:48 +0000 | [diff] [blame] | 1504 | bool ScopDetection::isProfitableRegion(DetectionContext &Context) const { |
| 1505 | Region &CurRegion = Context.CurRegion; |
| 1506 | |
| 1507 | if (PollyProcessUnprofitable) |
| 1508 | return true; |
| 1509 | |
| 1510 | // We can probably not do a lot on scops that only write or only read |
| 1511 | // data. |
| 1512 | if (!Context.hasStores || !Context.hasLoads) |
| 1513 | return invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion); |
| 1514 | |
Tobias Grosser | cd01a36 | 2017-02-17 08:12:36 +0000 | [diff] [blame] | 1515 | int NumLoops = |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1516 | countBeneficialLoops(&CurRegion, SE, LI, MIN_LOOP_TRIP_COUNT).NumLoops; |
Tobias Grosser | 97fc5bb | 2015-12-21 12:14:48 +0000 | [diff] [blame] | 1517 | int NumAffineLoops = NumLoops - Context.BoxedLoopsSet.size(); |
Tobias Grosser | 97fc5bb | 2015-12-21 12:14:48 +0000 | [diff] [blame] | 1518 | |
Tobias Grosser | c1a269b | 2015-12-21 21:00:43 +0000 | [diff] [blame] | 1519 | // Scops with at least two loops may allow either loop fusion or tiling and |
| 1520 | // are consequently interesting to look at. |
| 1521 | if (NumAffineLoops >= 2) |
| 1522 | return true; |
| 1523 | |
Michael Kruse | a6d48f5 | 2017-06-08 12:06:15 +0000 | [diff] [blame] | 1524 | // A loop with multiple non-trivial blocks might be amendable to distribution. |
Johannes Doerfert | bf9473b | 2016-05-10 14:42:30 +0000 | [diff] [blame] | 1525 | if (NumAffineLoops == 1 && hasPossiblyDistributableLoop(Context)) |
| 1526 | return true; |
| 1527 | |
Tobias Grosser | c1a269b | 2015-12-21 21:00:43 +0000 | [diff] [blame] | 1528 | // Scops that contain a loop with a non-trivial amount of computation per |
| 1529 | // loop-iteration are interesting as we may be able to parallelize such |
| 1530 | // loops. Individual loops that have only a small amount of computation |
| 1531 | // per-iteration are performance-wise very fragile as any change to the |
| 1532 | // loop induction variables may affect performance. To not cause spurious |
| 1533 | // performance regressions, we do not consider such loops. |
| 1534 | if (NumAffineLoops == 1 && hasSufficientCompute(Context, NumLoops)) |
| 1535 | return true; |
| 1536 | |
| 1537 | return invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion); |
Tobias Grosser | 97fc5bb | 2015-12-21 12:14:48 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1540 | bool ScopDetection::isValidRegion(DetectionContext &Context) const { |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 1541 | Region &CurRegion = Context.CurRegion; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1542 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 1543 | DEBUG(dbgs() << "Checking region: " << CurRegion.getNameStr() << "\n\t"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1544 | |
Siddharth Bhat | b46847c | 2017-08-17 21:57:23 +0000 | [diff] [blame^] | 1545 | if (!PollyAllowFullFunction && CurRegion.isTopLevelRegion()) { |
Tobias Grosser | f084edd | 2014-10-22 23:00:03 +0000 | [diff] [blame] | 1546 | DEBUG(dbgs() << "Top level region is invalid\n"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1547 | return false; |
| 1548 | } |
| 1549 | |
Tobias Grosser | 134a572 | 2017-03-07 15:50:43 +0000 | [diff] [blame] | 1550 | DebugLoc DbgLoc; |
Philip Pfaffe | 1a0128f | 2017-05-24 18:39:39 +0000 | [diff] [blame] | 1551 | if (CurRegion.getExit() && |
| 1552 | isa<UnreachableInst>(CurRegion.getExit()->getTerminator())) { |
Tobias Grosser | 134a572 | 2017-03-07 15:50:43 +0000 | [diff] [blame] | 1553 | DEBUG(dbgs() << "Unreachable in exit\n"); |
| 1554 | return invalid<ReportUnreachableInExit>(Context, /*Assert=*/true, |
| 1555 | CurRegion.getExit(), DbgLoc); |
| 1556 | } |
| 1557 | |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 1558 | if (!CurRegion.getEntry()->getName().count(OnlyRegion)) { |
Tobias Grosser | 4449e52 | 2014-01-27 14:24:53 +0000 | [diff] [blame] | 1559 | DEBUG({ |
| 1560 | dbgs() << "Region entry does not match -polly-region-only"; |
| 1561 | dbgs() << "\n"; |
| 1562 | }); |
| 1563 | return false; |
| 1564 | } |
| 1565 | |
Tobias Grosser | d654c25 | 2012-04-10 18:12:19 +0000 | [diff] [blame] | 1566 | // SCoP cannot contain the entry block of the function, because we need |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1567 | // to insert alloca instruction there when translate scalar to array. |
Siddharth Bhat | b46847c | 2017-08-17 21:57:23 +0000 | [diff] [blame^] | 1568 | if (!PollyAllowFullFunction && |
Tobias Grosser | d8945ba | 2017-05-19 12:13:02 +0000 | [diff] [blame] | 1569 | CurRegion.getEntry() == |
| 1570 | &(CurRegion.getEntry()->getParent()->getEntryBlock())) |
Johannes Doerfert | fb79a96 | 2015-02-23 14:18:28 +0000 | [diff] [blame] | 1571 | return invalid<ReportEntry>(Context, /*Assert=*/true, CurRegion.getEntry()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1572 | |
Hongbin Zheng | 94868e6 | 2012-04-07 12:29:17 +0000 | [diff] [blame] | 1573 | if (!allBlocksValid(Context)) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1574 | return false; |
| 1575 | |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1576 | if (!isReducibleRegion(CurRegion, DbgLoc)) |
| 1577 | return invalid<ReportIrreducibleRegion>(Context, /*Assert=*/true, |
| 1578 | &CurRegion, DbgLoc); |
| 1579 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1580 | DEBUG(dbgs() << "OK\n"); |
| 1581 | return true; |
| 1582 | } |
| 1583 | |
Tobias Grosser | 629109b | 2016-08-03 12:00:07 +0000 | [diff] [blame] | 1584 | void ScopDetection::markFunctionAsInvalid(Function *F) { |
Johannes Doerfert | 43e1ead | 2014-07-15 21:06:48 +0000 | [diff] [blame] | 1585 | F->addFnAttr(PollySkipFnAttr); |
| 1586 | } |
| 1587 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1588 | bool ScopDetection::isValidFunction(llvm::Function &F) { |
Johannes Doerfert | 43e1ead | 2014-07-15 21:06:48 +0000 | [diff] [blame] | 1589 | return !F.hasFnAttribute(PollySkipFnAttr); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Tobias Grosser | b2863ca | 2013-03-04 19:49:51 +0000 | [diff] [blame] | 1592 | void ScopDetection::printLocations(llvm::Function &F) { |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 1593 | for (const Region *R : *this) { |
Tobias Grosser | 531891e | 2012-11-01 16:45:20 +0000 | [diff] [blame] | 1594 | unsigned LineEntry, LineExit; |
| 1595 | std::string FileName; |
| 1596 | |
Tobias Grosser | 00dc309 | 2014-03-02 12:02:46 +0000 | [diff] [blame] | 1597 | getDebugLocation(R, LineEntry, LineExit, FileName); |
Tobias Grosser | 8519f89 | 2013-12-18 10:49:53 +0000 | [diff] [blame] | 1598 | DiagnosticScopFound Diagnostic(F, FileName, LineEntry, LineExit); |
| 1599 | F.getContext().diagnose(Diagnostic); |
Tobias Grosser | 531891e | 2012-11-01 16:45:20 +0000 | [diff] [blame] | 1600 | } |
| 1601 | } |
| 1602 | |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 1603 | void ScopDetection::emitMissedRemarks(const Function &F) { |
| 1604 | for (auto &DIt : DetectionContextMap) { |
| 1605 | auto &DC = DIt.getSecond(); |
| 1606 | if (DC.Log.hasErrors()) |
Eli Friedman | e737fc1 | 2017-07-17 23:58:33 +0000 | [diff] [blame] | 1607 | emitRejectionRemarks(DIt.getFirst(), DC.Log, ORE); |
Andreas Simbuerger | 5569bf3 | 2014-06-26 10:06:40 +0000 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1611 | bool ScopDetection::isReducibleRegion(Region &R, DebugLoc &DbgLoc) const { |
Tobias Grosser | c80d697 | 2016-09-02 06:33:33 +0000 | [diff] [blame] | 1612 | /// Enum for coloring BBs in Region. |
Tobias Grosser | ef6ae70 | 2016-06-11 09:00:37 +0000 | [diff] [blame] | 1613 | /// |
| 1614 | /// WHITE - Unvisited BB in DFS walk. |
| 1615 | /// GREY - BBs which are currently on the DFS stack for processing. |
| 1616 | /// BLACK - Visited and completely processed BB. |
| 1617 | enum Color { WHITE, GREY, BLACK }; |
| 1618 | |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1619 | BasicBlock *REntry = R.getEntry(); |
| 1620 | BasicBlock *RExit = R.getExit(); |
| 1621 | // Map to match the color of a BasicBlock during the DFS walk. |
| 1622 | DenseMap<const BasicBlock *, Color> BBColorMap; |
| 1623 | // Stack keeping track of current BB and index of next child to be processed. |
| 1624 | std::stack<std::pair<BasicBlock *, unsigned>> DFSStack; |
| 1625 | |
| 1626 | unsigned AdjacentBlockIndex = 0; |
| 1627 | BasicBlock *CurrBB, *SuccBB; |
| 1628 | CurrBB = REntry; |
| 1629 | |
| 1630 | // Initialize the map for all BB with WHITE color. |
| 1631 | for (auto *BB : R.blocks()) |
Johannes Doerfert | 469db6a | 2016-05-19 12:36:43 +0000 | [diff] [blame] | 1632 | BBColorMap[BB] = WHITE; |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1633 | |
| 1634 | // Process the entry block of the Region. |
Johannes Doerfert | 469db6a | 2016-05-19 12:36:43 +0000 | [diff] [blame] | 1635 | BBColorMap[CurrBB] = GREY; |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1636 | DFSStack.push(std::make_pair(CurrBB, 0)); |
| 1637 | |
| 1638 | while (!DFSStack.empty()) { |
| 1639 | // Get next BB on stack to be processed. |
| 1640 | CurrBB = DFSStack.top().first; |
| 1641 | AdjacentBlockIndex = DFSStack.top().second; |
| 1642 | DFSStack.pop(); |
| 1643 | |
| 1644 | // Loop to iterate over the successors of current BB. |
| 1645 | const TerminatorInst *TInst = CurrBB->getTerminator(); |
| 1646 | unsigned NSucc = TInst->getNumSuccessors(); |
| 1647 | for (unsigned I = AdjacentBlockIndex; I < NSucc; |
| 1648 | ++I, ++AdjacentBlockIndex) { |
| 1649 | SuccBB = TInst->getSuccessor(I); |
| 1650 | |
| 1651 | // Checks for region exit block and self-loops in BB. |
| 1652 | if (SuccBB == RExit || SuccBB == CurrBB) |
| 1653 | continue; |
| 1654 | |
| 1655 | // WHITE indicates an unvisited BB in DFS walk. |
Johannes Doerfert | 469db6a | 2016-05-19 12:36:43 +0000 | [diff] [blame] | 1656 | if (BBColorMap[SuccBB] == WHITE) { |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1657 | // Push the current BB and the index of the next child to be visited. |
| 1658 | DFSStack.push(std::make_pair(CurrBB, I + 1)); |
| 1659 | // Push the next BB to be processed. |
| 1660 | DFSStack.push(std::make_pair(SuccBB, 0)); |
| 1661 | // First time the BB is being processed. |
Johannes Doerfert | 469db6a | 2016-05-19 12:36:43 +0000 | [diff] [blame] | 1662 | BBColorMap[SuccBB] = GREY; |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1663 | break; |
Johannes Doerfert | 469db6a | 2016-05-19 12:36:43 +0000 | [diff] [blame] | 1664 | } else if (BBColorMap[SuccBB] == GREY) { |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1665 | // GREY indicates a loop in the control flow. |
| 1666 | // If the destination dominates the source, it is a natural loop |
| 1667 | // else, an irreducible control flow in the region is detected. |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1668 | if (!DT.dominates(SuccBB, CurrBB)) { |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1669 | // Get debug info of instruction which causes irregular control flow. |
| 1670 | DbgLoc = TInst->getDebugLoc(); |
| 1671 | return false; |
| 1672 | } |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | // If all children of current BB have been processed, |
| 1677 | // then mark that BB as fully processed. |
| 1678 | if (AdjacentBlockIndex == NSucc) |
Johannes Doerfert | 469db6a | 2016-05-19 12:36:43 +0000 | [diff] [blame] | 1679 | BBColorMap[CurrBB] = BLACK; |
Tobias Grosser | 1c3a6d7 | 2016-01-22 09:44:37 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | return true; |
| 1683 | } |
| 1684 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1685 | static void updateLoopCountStatistic(ScopDetection::LoopStats Stats, |
| 1686 | bool OnlyProfitable) { |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1687 | if (!OnlyProfitable) { |
| 1688 | NumLoopsInScop += Stats.NumLoops; |
Tobias Grosser | 9fe37df | 2017-02-12 10:52:57 +0000 | [diff] [blame] | 1689 | MaxNumLoopsInScop = |
| 1690 | std::max(MaxNumLoopsInScop.getValue(), (unsigned)Stats.NumLoops); |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1691 | if (Stats.MaxDepth == 1) |
| 1692 | NumScopsDepthOne++; |
| 1693 | else if (Stats.MaxDepth == 2) |
| 1694 | NumScopsDepthTwo++; |
| 1695 | else if (Stats.MaxDepth == 3) |
| 1696 | NumScopsDepthThree++; |
| 1697 | else if (Stats.MaxDepth == 4) |
| 1698 | NumScopsDepthFour++; |
| 1699 | else if (Stats.MaxDepth == 5) |
| 1700 | NumScopsDepthFive++; |
| 1701 | else |
| 1702 | NumScopsDepthLarger++; |
| 1703 | } else { |
| 1704 | NumLoopsInProfScop += Stats.NumLoops; |
Tobias Grosser | 9fe37df | 2017-02-12 10:52:57 +0000 | [diff] [blame] | 1705 | MaxNumLoopsInProfScop = |
| 1706 | std::max(MaxNumLoopsInProfScop.getValue(), (unsigned)Stats.NumLoops); |
Tobias Grosser | b45ae56 | 2016-11-26 07:37:46 +0000 | [diff] [blame] | 1707 | if (Stats.MaxDepth == 1) |
| 1708 | NumProfScopsDepthOne++; |
| 1709 | else if (Stats.MaxDepth == 2) |
| 1710 | NumProfScopsDepthTwo++; |
| 1711 | else if (Stats.MaxDepth == 3) |
| 1712 | NumProfScopsDepthThree++; |
| 1713 | else if (Stats.MaxDepth == 4) |
| 1714 | NumProfScopsDepthFour++; |
| 1715 | else if (Stats.MaxDepth == 5) |
| 1716 | NumProfScopsDepthFive++; |
| 1717 | else |
| 1718 | NumProfScopsDepthLarger++; |
| 1719 | } |
| 1720 | } |
| 1721 | |
Johannes Doerfert | 1dafea4 | 2016-05-23 09:07:08 +0000 | [diff] [blame] | 1722 | ScopDetection::DetectionContext * |
Johannes Doerfert | c06b7d6 | 2015-10-07 20:46:06 +0000 | [diff] [blame] | 1723 | ScopDetection::getDetectionContext(const Region *R) const { |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 1724 | auto DCMIt = DetectionContextMap.find(getBBPairForRegion(R)); |
Johannes Doerfert | c06b7d6 | 2015-10-07 20:46:06 +0000 | [diff] [blame] | 1725 | if (DCMIt == DetectionContextMap.end()) |
| 1726 | return nullptr; |
| 1727 | return &DCMIt->second; |
Johannes Doerfert | ba65c16 | 2015-02-24 11:45:21 +0000 | [diff] [blame] | 1728 | } |
| 1729 | |
Johannes Doerfert | 6c7639b | 2016-05-12 18:50:01 +0000 | [diff] [blame] | 1730 | const RejectLog *ScopDetection::lookupRejectionLog(const Region *R) const { |
| 1731 | const DetectionContext *DC = getDetectionContext(R); |
| 1732 | return DC ? &DC->Log : nullptr; |
| 1733 | } |
| 1734 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1735 | void polly::ScopDetection::verifyRegion(const Region &R) const { |
| 1736 | assert(isMaxRegionInScop(R) && "Expect R is a valid region."); |
Johannes Doerfert | f3e98f4 | 2015-04-12 22:52:20 +0000 | [diff] [blame] | 1737 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1738 | DetectionContext Context(const_cast<Region &>(R), AA, true /*verifying*/); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1739 | isValidRegion(Context); |
| 1740 | } |
| 1741 | |
| 1742 | void polly::ScopDetection::verifyAnalysis() const { |
Tobias Grosser | a168993 | 2014-02-18 18:49:49 +0000 | [diff] [blame] | 1743 | if (!VerifyScops) |
| 1744 | return; |
| 1745 | |
Tobias Grosser | 2610889 | 2014-04-02 20:18:19 +0000 | [diff] [blame] | 1746 | for (const Region *R : ValidRegions) |
Tobias Grosser | 00dc309 | 2014-03-02 12:02:46 +0000 | [diff] [blame] | 1747 | verifyRegion(*R); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1750 | bool ScopDetectionWrapperPass::runOnFunction(llvm::Function &F) { |
| 1751 | auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
| 1752 | auto &RI = getAnalysis<RegionInfoPass>().getRegionInfo(); |
| 1753 | auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults(); |
| 1754 | auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE(); |
| 1755 | auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
Eli Friedman | e737fc1 | 2017-07-17 23:58:33 +0000 | [diff] [blame] | 1756 | auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE(); |
| 1757 | Result.reset(new ScopDetection(F, DT, SE, LI, RI, AA, ORE)); |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1758 | return false; |
| 1759 | } |
| 1760 | |
| 1761 | void ScopDetectionWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { |
Chandler Carruth | f557987 | 2015-01-17 14:16:56 +0000 | [diff] [blame] | 1762 | AU.addRequired<LoopInfoWrapperPass>(); |
Michael Kruse | 6a19d59 | 2016-10-17 13:29:20 +0000 | [diff] [blame] | 1763 | AU.addRequiredTransitive<ScalarEvolutionWrapperPass>(); |
Johannes Doerfert | 08d90a3 | 2015-10-07 20:32:43 +0000 | [diff] [blame] | 1764 | AU.addRequired<DominatorTreeWrapperPass>(); |
Eli Friedman | e737fc1 | 2017-07-17 23:58:33 +0000 | [diff] [blame] | 1765 | AU.addRequired<OptimizationRemarkEmitterWrapperPass>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1766 | // We also need AA and RegionInfo when we are verifying analysis. |
Chandler Carruth | 66ef16b | 2015-09-09 22:13:56 +0000 | [diff] [blame] | 1767 | AU.addRequiredTransitive<AAResultsWrapperPass>(); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 1768 | AU.addRequiredTransitive<RegionInfoPass>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1769 | AU.setPreservesAll(); |
| 1770 | } |
| 1771 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1772 | void ScopDetectionWrapperPass::print(raw_ostream &OS, const Module *) const { |
| 1773 | for (const Region *R : Result->ValidRegions) |
Tobias Grosser | 00dc309 | 2014-03-02 12:02:46 +0000 | [diff] [blame] | 1774 | OS << "Valid Region for Scop: " << R->getNameStr() << '\n'; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1775 | |
| 1776 | OS << "\n"; |
| 1777 | } |
| 1778 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1779 | ScopDetectionWrapperPass::ScopDetectionWrapperPass() : FunctionPass(ID) { |
| 1780 | // Disable runtime alias checks if we ignore aliasing all together. |
| 1781 | if (IgnoreAliasing) |
| 1782 | PollyUseRuntimeAliasChecks = false; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1783 | } |
Philip Pfaffe | f5a4394 | 2017-08-02 11:08:01 +0000 | [diff] [blame] | 1784 | ScopAnalysis::ScopAnalysis() { |
| 1785 | // Disable runtime alias checks if we ignore aliasing all together. |
| 1786 | if (IgnoreAliasing) |
| 1787 | PollyUseRuntimeAliasChecks = false; |
| 1788 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1789 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1790 | void ScopDetectionWrapperPass::releaseMemory() { Result.reset(); } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1791 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1792 | char ScopDetectionWrapperPass::ID; |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 1793 | |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1794 | AnalysisKey ScopAnalysis::Key; |
| 1795 | |
| 1796 | ScopDetection ScopAnalysis::run(Function &F, FunctionAnalysisManager &FAM) { |
| 1797 | auto &LI = FAM.getResult<LoopAnalysis>(F); |
| 1798 | auto &RI = FAM.getResult<RegionInfoAnalysis>(F); |
| 1799 | auto &AA = FAM.getResult<AAManager>(F); |
| 1800 | auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(F); |
| 1801 | auto &DT = FAM.getResult<DominatorTreeAnalysis>(F); |
Eli Friedman | e737fc1 | 2017-07-17 23:58:33 +0000 | [diff] [blame] | 1802 | auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F); |
| 1803 | return {F, DT, SE, LI, RI, AA, ORE}; |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | PreservedAnalyses ScopAnalysisPrinterPass::run(Function &F, |
| 1807 | FunctionAnalysisManager &FAM) { |
Philip Pfaffe | 96d2143 | 2017-08-04 11:28:51 +0000 | [diff] [blame] | 1808 | Stream << "Detected Scops in Function " << F.getName() << "\n"; |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1809 | auto &SD = FAM.getResult<ScopAnalysis>(F); |
| 1810 | for (const Region *R : SD.ValidRegions) |
| 1811 | Stream << "Valid Region for Scop: " << R->getNameStr() << '\n'; |
| 1812 | |
| 1813 | Stream << "\n"; |
| 1814 | return PreservedAnalyses::all(); |
| 1815 | } |
| 1816 | |
| 1817 | Pass *polly::createScopDetectionWrapperPassPass() { |
| 1818 | return new ScopDetectionWrapperPass(); |
| 1819 | } |
| 1820 | |
| 1821 | INITIALIZE_PASS_BEGIN(ScopDetectionWrapperPass, "polly-detect", |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 1822 | "Polly - Detect static control parts (SCoPs)", false, |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 1823 | false); |
Chandler Carruth | 66ef16b | 2015-09-09 22:13:56 +0000 | [diff] [blame] | 1824 | INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass); |
Chandler Carruth | f557987 | 2015-01-17 14:16:56 +0000 | [diff] [blame] | 1825 | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 1826 | INITIALIZE_PASS_DEPENDENCY(RegionInfoPass); |
Johannes Doerfert | 08d90a3 | 2015-10-07 20:32:43 +0000 | [diff] [blame] | 1827 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass); |
Tobias Grosser | c5bcf24 | 2015-08-17 10:57:08 +0000 | [diff] [blame] | 1828 | INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass); |
Eli Friedman | e737fc1 | 2017-07-17 23:58:33 +0000 | [diff] [blame] | 1829 | INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass); |
Philip Pfaffe | 5cc87e3 | 2017-05-12 14:37:29 +0000 | [diff] [blame] | 1830 | INITIALIZE_PASS_END(ScopDetectionWrapperPass, "polly-detect", |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 1831 | "Polly - Detect static control parts (SCoPs)", false, false) |