DependenceInfo.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. //===- DependenceInfo.cpp - Calculate dependency information for a Scop. --===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Calculate the data dependency relations for a Scop using ISL.
  10. //
  11. // The integer set library (ISL) from Sven, has a integrated dependency analysis
  12. // to calculate data dependences. This pass takes advantage of this and
  13. // calculate those dependences a Scop.
  14. //
  15. // The dependences in this pass are exact in terms that for a specific read
  16. // statement instance only the last write statement instance is returned. In
  17. // case of may writes a set of possible write instances is returned. This
  18. // analysis will never produce redundant dependences.
  19. //
  20. //===----------------------------------------------------------------------===//
  21. //
  22. #include "polly/DependenceInfo.h"
  23. #include "polly/LinkAllPasses.h"
  24. #include "polly/Options.h"
  25. #include "polly/ScopInfo.h"
  26. #include "polly/Support/GICHelper.h"
  27. #include "polly/Support/ISLTools.h"
  28. #include "llvm/ADT/Sequence.h"
  29. #include "llvm/Support/Debug.h"
  30. #include "isl/aff.h"
  31. #include "isl/ctx.h"
  32. #include "isl/flow.h"
  33. #include "isl/map.h"
  34. #include "isl/schedule.h"
  35. #include "isl/set.h"
  36. #include "isl/union_map.h"
  37. #include "isl/union_set.h"
  38. using namespace polly;
  39. using namespace llvm;
  40. #define DEBUG_TYPE "polly-dependence"
  41. static cl::opt<int> OptComputeOut(
  42. "polly-dependences-computeout",
  43. cl::desc("Bound the dependence analysis by a maximal amount of "
  44. "computational steps (0 means no bound)"),
  45. cl::Hidden, cl::init(500000), cl::cat(PollyCategory));
  46. static cl::opt<bool>
  47. LegalityCheckDisabled("disable-polly-legality",
  48. cl::desc("Disable polly legality check"), cl::Hidden,
  49. cl::cat(PollyCategory));
  50. static cl::opt<bool>
  51. UseReductions("polly-dependences-use-reductions",
  52. cl::desc("Exploit reductions in dependence analysis"),
  53. cl::Hidden, cl::init(true), cl::cat(PollyCategory));
  54. enum AnalysisType { VALUE_BASED_ANALYSIS, MEMORY_BASED_ANALYSIS };
  55. static cl::opt<enum AnalysisType> OptAnalysisType(
  56. "polly-dependences-analysis-type",
  57. cl::desc("The kind of dependence analysis to use"),
  58. cl::values(clEnumValN(VALUE_BASED_ANALYSIS, "value-based",
  59. "Exact dependences without transitive dependences"),
  60. clEnumValN(MEMORY_BASED_ANALYSIS, "memory-based",
  61. "Overapproximation of dependences")),
  62. cl::Hidden, cl::init(VALUE_BASED_ANALYSIS), cl::cat(PollyCategory));
  63. static cl::opt<Dependences::AnalysisLevel> OptAnalysisLevel(
  64. "polly-dependences-analysis-level",
  65. cl::desc("The level of dependence analysis"),
  66. cl::values(clEnumValN(Dependences::AL_Statement, "statement-wise",
  67. "Statement-level analysis"),
  68. clEnumValN(Dependences::AL_Reference, "reference-wise",
  69. "Memory reference level analysis that distinguish"
  70. " accessed references in the same statement"),
  71. clEnumValN(Dependences::AL_Access, "access-wise",
  72. "Memory reference level analysis that distinguish"
  73. " access instructions in the same statement")),
  74. cl::Hidden, cl::init(Dependences::AL_Statement), cl::cat(PollyCategory));
  75. //===----------------------------------------------------------------------===//
  76. /// Tag the @p Relation domain with @p TagId
  77. static __isl_give isl_map *tag(__isl_take isl_map *Relation,
  78. __isl_take isl_id *TagId) {
  79. isl_space *Space = isl_map_get_space(Relation);
  80. Space = isl_space_drop_dims(Space, isl_dim_out, 0,
  81. isl_map_dim(Relation, isl_dim_out));
  82. Space = isl_space_set_tuple_id(Space, isl_dim_out, TagId);
  83. isl_multi_aff *Tag = isl_multi_aff_domain_map(Space);
  84. Relation = isl_map_preimage_domain_multi_aff(Relation, Tag);
  85. return Relation;
  86. }
  87. /// Tag the @p Relation domain with either MA->getArrayId() or
  88. /// MA->getId() based on @p TagLevel
  89. static __isl_give isl_map *tag(__isl_take isl_map *Relation, MemoryAccess *MA,
  90. Dependences::AnalysisLevel TagLevel) {
  91. if (TagLevel == Dependences::AL_Reference)
  92. return tag(Relation, MA->getArrayId().release());
  93. if (TagLevel == Dependences::AL_Access)
  94. return tag(Relation, MA->getId().release());
  95. // No need to tag at the statement level.
  96. return Relation;
  97. }
  98. /// Collect information about the SCoP @p S.
  99. static void collectInfo(Scop &S, isl_union_map *&Read,
  100. isl_union_map *&MustWrite, isl_union_map *&MayWrite,
  101. isl_union_map *&ReductionTagMap,
  102. isl_union_set *&TaggedStmtDomain,
  103. Dependences::AnalysisLevel Level) {
  104. isl_space *Space = S.getParamSpace().release();
  105. Read = isl_union_map_empty(isl_space_copy(Space));
  106. MustWrite = isl_union_map_empty(isl_space_copy(Space));
  107. MayWrite = isl_union_map_empty(isl_space_copy(Space));
  108. ReductionTagMap = isl_union_map_empty(isl_space_copy(Space));
  109. isl_union_map *StmtSchedule = isl_union_map_empty(Space);
  110. SmallPtrSet<const ScopArrayInfo *, 8> ReductionArrays;
  111. if (UseReductions)
  112. for (ScopStmt &Stmt : S)
  113. for (MemoryAccess *MA : Stmt)
  114. if (MA->isReductionLike())
  115. ReductionArrays.insert(MA->getScopArrayInfo());
  116. for (ScopStmt &Stmt : S) {
  117. for (MemoryAccess *MA : Stmt) {
  118. isl_set *domcp = Stmt.getDomain().release();
  119. isl_map *accdom = MA->getAccessRelation().release();
  120. accdom = isl_map_intersect_domain(accdom, domcp);
  121. if (ReductionArrays.count(MA->getScopArrayInfo())) {
  122. // Wrap the access domain and adjust the schedule accordingly.
  123. //
  124. // An access domain like
  125. // Stmt[i0, i1] -> MemAcc_A[i0 + i1]
  126. // will be transformed into
  127. // [Stmt[i0, i1] -> MemAcc_A[i0 + i1]] -> MemAcc_A[i0 + i1]
  128. //
  129. // We collect all the access domains in the ReductionTagMap.
  130. // This is used in Dependences::calculateDependences to create
  131. // a tagged Schedule tree.
  132. ReductionTagMap =
  133. isl_union_map_add_map(ReductionTagMap, isl_map_copy(accdom));
  134. accdom = isl_map_range_map(accdom);
  135. } else {
  136. accdom = tag(accdom, MA, Level);
  137. if (Level > Dependences::AL_Statement) {
  138. isl_map *StmtScheduleMap = Stmt.getSchedule().release();
  139. assert(StmtScheduleMap &&
  140. "Schedules that contain extension nodes require special "
  141. "handling.");
  142. isl_map *Schedule = tag(StmtScheduleMap, MA, Level);
  143. StmtSchedule = isl_union_map_add_map(StmtSchedule, Schedule);
  144. }
  145. }
  146. if (MA->isRead())
  147. Read = isl_union_map_add_map(Read, accdom);
  148. else if (MA->isMayWrite())
  149. MayWrite = isl_union_map_add_map(MayWrite, accdom);
  150. else
  151. MustWrite = isl_union_map_add_map(MustWrite, accdom);
  152. }
  153. if (!ReductionArrays.empty() && Level == Dependences::AL_Statement)
  154. StmtSchedule =
  155. isl_union_map_add_map(StmtSchedule, Stmt.getSchedule().release());
  156. }
  157. StmtSchedule = isl_union_map_intersect_params(
  158. StmtSchedule, S.getAssumedContext().release());
  159. TaggedStmtDomain = isl_union_map_domain(StmtSchedule);
  160. ReductionTagMap = isl_union_map_coalesce(ReductionTagMap);
  161. Read = isl_union_map_coalesce(Read);
  162. MustWrite = isl_union_map_coalesce(MustWrite);
  163. MayWrite = isl_union_map_coalesce(MayWrite);
  164. }
  165. /// Fix all dimension of @p Zero to 0 and add it to @p user
  166. static void fixSetToZero(isl::set Zero, isl::union_set *User) {
  167. for (auto i : rangeIslSize(0, Zero.tuple_dim()))
  168. Zero = Zero.fix_si(isl::dim::set, i, 0);
  169. *User = User->unite(Zero);
  170. }
  171. /// Compute the privatization dependences for a given dependency @p Map
  172. ///
  173. /// Privatization dependences are widened original dependences which originate
  174. /// or end in a reduction access. To compute them we apply the transitive close
  175. /// of the reduction dependences (which maps each iteration of a reduction
  176. /// statement to all following ones) on the RAW/WAR/WAW dependences. The
  177. /// dependences which start or end at a reduction statement will be extended to
  178. /// depend on all following reduction statement iterations as well.
  179. /// Note: "Following" here means according to the reduction dependences.
  180. ///
  181. /// For the input:
  182. ///
  183. /// S0: *sum = 0;
  184. /// for (int i = 0; i < 1024; i++)
  185. /// S1: *sum += i;
  186. /// S2: *sum = *sum * 3;
  187. ///
  188. /// we have the following dependences before we add privatization dependences:
  189. ///
  190. /// RAW:
  191. /// { S0[] -> S1[0]; S1[1023] -> S2[] }
  192. /// WAR:
  193. /// { }
  194. /// WAW:
  195. /// { S0[] -> S1[0]; S1[1024] -> S2[] }
  196. /// RED:
  197. /// { S1[i0] -> S1[1 + i0] : i0 >= 0 and i0 <= 1022 }
  198. ///
  199. /// and afterwards:
  200. ///
  201. /// RAW:
  202. /// { S0[] -> S1[i0] : i0 >= 0 and i0 <= 1023;
  203. /// S1[i0] -> S2[] : i0 >= 0 and i0 <= 1023}
  204. /// WAR:
  205. /// { }
  206. /// WAW:
  207. /// { S0[] -> S1[i0] : i0 >= 0 and i0 <= 1023;
  208. /// S1[i0] -> S2[] : i0 >= 0 and i0 <= 1023}
  209. /// RED:
  210. /// { S1[i0] -> S1[1 + i0] : i0 >= 0 and i0 <= 1022 }
  211. ///
  212. /// Note: This function also computes the (reverse) transitive closure of the
  213. /// reduction dependences.
  214. void Dependences::addPrivatizationDependences() {
  215. isl_union_map *PrivRAW, *PrivWAW, *PrivWAR;
  216. // The transitive closure might be over approximated, thus could lead to
  217. // dependency cycles in the privatization dependences. To make sure this
  218. // will not happen we remove all negative dependences after we computed
  219. // the transitive closure.
  220. TC_RED = isl_union_map_transitive_closure(isl_union_map_copy(RED), nullptr);
  221. // FIXME: Apply the current schedule instead of assuming the identity schedule
  222. // here. The current approach is only valid as long as we compute the
  223. // dependences only with the initial (identity schedule). Any other
  224. // schedule could change "the direction of the backward dependences" we
  225. // want to eliminate here.
  226. isl_union_set *UDeltas = isl_union_map_deltas(isl_union_map_copy(TC_RED));
  227. isl_union_set *Universe = isl_union_set_universe(isl_union_set_copy(UDeltas));
  228. isl::union_set Zero =
  229. isl::manage(isl_union_set_empty(isl_union_set_get_space(Universe)));
  230. for (isl::set Set : isl::manage_copy(Universe).get_set_list())
  231. fixSetToZero(Set, &Zero);
  232. isl_union_map *NonPositive =
  233. isl_union_set_lex_le_union_set(UDeltas, Zero.release());
  234. TC_RED = isl_union_map_subtract(TC_RED, NonPositive);
  235. TC_RED = isl_union_map_union(
  236. TC_RED, isl_union_map_reverse(isl_union_map_copy(TC_RED)));
  237. TC_RED = isl_union_map_coalesce(TC_RED);
  238. isl_union_map **Maps[] = {&RAW, &WAW, &WAR};
  239. isl_union_map **PrivMaps[] = {&PrivRAW, &PrivWAW, &PrivWAR};
  240. for (unsigned u = 0; u < 3; u++) {
  241. isl_union_map **Map = Maps[u], **PrivMap = PrivMaps[u];
  242. *PrivMap = isl_union_map_apply_range(isl_union_map_copy(*Map),
  243. isl_union_map_copy(TC_RED));
  244. *PrivMap = isl_union_map_union(
  245. *PrivMap, isl_union_map_apply_range(isl_union_map_copy(TC_RED),
  246. isl_union_map_copy(*Map)));
  247. *Map = isl_union_map_union(*Map, *PrivMap);
  248. }
  249. isl_union_set_free(Universe);
  250. }
  251. static __isl_give isl_union_flow *buildFlow(__isl_keep isl_union_map *Snk,
  252. __isl_keep isl_union_map *Src,
  253. __isl_keep isl_union_map *MaySrc,
  254. __isl_keep isl_union_map *Kill,
  255. __isl_keep isl_schedule *Schedule) {
  256. isl_union_access_info *AI;
  257. AI = isl_union_access_info_from_sink(isl_union_map_copy(Snk));
  258. if (MaySrc)
  259. AI = isl_union_access_info_set_may_source(AI, isl_union_map_copy(MaySrc));
  260. if (Src)
  261. AI = isl_union_access_info_set_must_source(AI, isl_union_map_copy(Src));
  262. if (Kill)
  263. AI = isl_union_access_info_set_kill(AI, isl_union_map_copy(Kill));
  264. AI = isl_union_access_info_set_schedule(AI, isl_schedule_copy(Schedule));
  265. auto Flow = isl_union_access_info_compute_flow(AI);
  266. LLVM_DEBUG(if (!Flow) dbgs()
  267. << "last error: "
  268. << isl_ctx_last_error(isl_schedule_get_ctx(Schedule))
  269. << '\n';);
  270. return Flow;
  271. }
  272. void Dependences::calculateDependences(Scop &S) {
  273. isl_union_map *Read, *MustWrite, *MayWrite, *ReductionTagMap;
  274. isl_schedule *Schedule;
  275. isl_union_set *TaggedStmtDomain;
  276. LLVM_DEBUG(dbgs() << "Scop: \n" << S << "\n");
  277. collectInfo(S, Read, MustWrite, MayWrite, ReductionTagMap, TaggedStmtDomain,
  278. Level);
  279. bool HasReductions = !isl_union_map_is_empty(ReductionTagMap);
  280. LLVM_DEBUG(dbgs() << "Read: " << Read << '\n';
  281. dbgs() << "MustWrite: " << MustWrite << '\n';
  282. dbgs() << "MayWrite: " << MayWrite << '\n';
  283. dbgs() << "ReductionTagMap: " << ReductionTagMap << '\n';
  284. dbgs() << "TaggedStmtDomain: " << TaggedStmtDomain << '\n';);
  285. Schedule = S.getScheduleTree().release();
  286. if (!HasReductions) {
  287. isl_union_map_free(ReductionTagMap);
  288. // Tag the schedule tree if we want fine-grain dependence info
  289. if (Level > AL_Statement) {
  290. auto TaggedMap =
  291. isl_union_set_unwrap(isl_union_set_copy(TaggedStmtDomain));
  292. auto Tags = isl_union_map_domain_map_union_pw_multi_aff(TaggedMap);
  293. Schedule = isl_schedule_pullback_union_pw_multi_aff(Schedule, Tags);
  294. }
  295. } else {
  296. isl_union_map *IdentityMap;
  297. isl_union_pw_multi_aff *ReductionTags, *IdentityTags, *Tags;
  298. // Extract Reduction tags from the combined access domains in the given
  299. // SCoP. The result is a map that maps each tagged element in the domain to
  300. // the memory location it accesses. ReductionTags = {[Stmt[i] ->
  301. // Array[f(i)]] -> Stmt[i] }
  302. ReductionTags =
  303. isl_union_map_domain_map_union_pw_multi_aff(ReductionTagMap);
  304. // Compute an identity map from each statement in domain to itself.
  305. // IdentityTags = { [Stmt[i] -> Stmt[i] }
  306. IdentityMap = isl_union_set_identity(isl_union_set_copy(TaggedStmtDomain));
  307. IdentityTags = isl_union_pw_multi_aff_from_union_map(IdentityMap);
  308. Tags = isl_union_pw_multi_aff_union_add(ReductionTags, IdentityTags);
  309. // By pulling back Tags from Schedule, we have a schedule tree that can
  310. // be used to compute normal dependences, as well as 'tagged' reduction
  311. // dependences.
  312. Schedule = isl_schedule_pullback_union_pw_multi_aff(Schedule, Tags);
  313. }
  314. LLVM_DEBUG(dbgs() << "Read: " << Read << "\n";
  315. dbgs() << "MustWrite: " << MustWrite << "\n";
  316. dbgs() << "MayWrite: " << MayWrite << "\n";
  317. dbgs() << "Schedule: " << Schedule << "\n");
  318. isl_union_map *StrictWAW = nullptr;
  319. {
  320. IslMaxOperationsGuard MaxOpGuard(IslCtx.get(), OptComputeOut);
  321. RAW = WAW = WAR = RED = nullptr;
  322. isl_union_map *Write = isl_union_map_union(isl_union_map_copy(MustWrite),
  323. isl_union_map_copy(MayWrite));
  324. // We are interested in detecting reductions that do not have intermediate
  325. // computations that are captured by other statements.
  326. //
  327. // Example:
  328. // void f(int *A, int *B) {
  329. // for(int i = 0; i <= 100; i++) {
  330. //
  331. // *-WAR (S0[i] -> S0[i + 1] 0 <= i <= 100)------------*
  332. // | |
  333. // *-WAW (S0[i] -> S0[i + 1] 0 <= i <= 100)------------*
  334. // | |
  335. // v |
  336. // S0: *A += i; >------------------*-----------------------*
  337. // |
  338. // if (i >= 98) { WAR (S0[i] -> S1[i]) 98 <= i <= 100
  339. // |
  340. // S1: *B = *A; <--------------*
  341. // }
  342. // }
  343. // }
  344. //
  345. // S0[0 <= i <= 100] has a reduction. However, the values in
  346. // S0[98 <= i <= 100] is captured in S1[98 <= i <= 100].
  347. // Since we allow free reordering on our reduction dependences, we need to
  348. // remove all instances of a reduction statement that have data dependences
  349. // originating from them.
  350. // In the case of the example, we need to remove S0[98 <= i <= 100] from
  351. // our reduction dependences.
  352. //
  353. // When we build up the WAW dependences that are used to detect reductions,
  354. // we consider only **Writes that have no intermediate Reads**.
  355. //
  356. // `isl_union_flow_get_must_dependence` gives us dependences of the form:
  357. // (sink <- must_source).
  358. //
  359. // It *will not give* dependences of the form:
  360. // 1. (sink <- ... <- may_source <- ... <- must_source)
  361. // 2. (sink <- ... <- must_source <- ... <- must_source)
  362. //
  363. // For a detailed reference on ISL's flow analysis, see:
  364. // "Presburger Formulas and Polyhedral Compilation" - Approximate Dataflow
  365. // Analysis.
  366. //
  367. // Since we set "Write" as a must-source, "Read" as a may-source, and ask
  368. // for must dependences, we get all Writes to Writes that **do not flow
  369. // through a Read**.
  370. //
  371. // ScopInfo::checkForReductions makes sure that if something captures
  372. // the reduction variable in the same basic block, then it is rejected
  373. // before it is even handed here. This makes sure that there is exactly
  374. // one read and one write to a reduction variable in a Statement.
  375. // Example:
  376. // void f(int *sum, int A[N], int B[N]) {
  377. // for (int i = 0; i < N; i++) {
  378. // *sum += A[i]; < the store and the load is not tagged as a
  379. // B[i] = *sum; < reduction-like access due to the overlap.
  380. // }
  381. // }
  382. isl_union_flow *Flow = buildFlow(Write, Write, Read, nullptr, Schedule);
  383. StrictWAW = isl_union_flow_get_must_dependence(Flow);
  384. isl_union_flow_free(Flow);
  385. if (OptAnalysisType == VALUE_BASED_ANALYSIS) {
  386. Flow = buildFlow(Read, MustWrite, MayWrite, nullptr, Schedule);
  387. RAW = isl_union_flow_get_may_dependence(Flow);
  388. isl_union_flow_free(Flow);
  389. Flow = buildFlow(Write, MustWrite, MayWrite, nullptr, Schedule);
  390. WAW = isl_union_flow_get_may_dependence(Flow);
  391. isl_union_flow_free(Flow);
  392. // ISL now supports "kills" in approximate dataflow analysis, we can
  393. // specify the MustWrite as kills, Read as source and Write as sink.
  394. Flow = buildFlow(Write, nullptr, Read, MustWrite, Schedule);
  395. WAR = isl_union_flow_get_may_dependence(Flow);
  396. isl_union_flow_free(Flow);
  397. } else {
  398. Flow = buildFlow(Read, nullptr, Write, nullptr, Schedule);
  399. RAW = isl_union_flow_get_may_dependence(Flow);
  400. isl_union_flow_free(Flow);
  401. Flow = buildFlow(Write, nullptr, Read, nullptr, Schedule);
  402. WAR = isl_union_flow_get_may_dependence(Flow);
  403. isl_union_flow_free(Flow);
  404. Flow = buildFlow(Write, nullptr, Write, nullptr, Schedule);
  405. WAW = isl_union_flow_get_may_dependence(Flow);
  406. isl_union_flow_free(Flow);
  407. }
  408. isl_union_map_free(Write);
  409. isl_union_map_free(MustWrite);
  410. isl_union_map_free(MayWrite);
  411. isl_union_map_free(Read);
  412. isl_schedule_free(Schedule);
  413. RAW = isl_union_map_coalesce(RAW);
  414. WAW = isl_union_map_coalesce(WAW);
  415. WAR = isl_union_map_coalesce(WAR);
  416. // End of max_operations scope.
  417. }
  418. if (isl_ctx_last_error(IslCtx.get()) == isl_error_quota) {
  419. isl_union_map_free(RAW);
  420. isl_union_map_free(WAW);
  421. isl_union_map_free(WAR);
  422. isl_union_map_free(StrictWAW);
  423. RAW = WAW = WAR = StrictWAW = nullptr;
  424. isl_ctx_reset_error(IslCtx.get());
  425. }
  426. // Drop out early, as the remaining computations are only needed for
  427. // reduction dependences or dependences that are finer than statement
  428. // level dependences.
  429. if (!HasReductions && Level == AL_Statement) {
  430. RED = isl_union_map_empty(isl_union_map_get_space(RAW));
  431. TC_RED = isl_union_map_empty(isl_union_set_get_space(TaggedStmtDomain));
  432. isl_union_set_free(TaggedStmtDomain);
  433. isl_union_map_free(StrictWAW);
  434. return;
  435. }
  436. isl_union_map *STMT_RAW, *STMT_WAW, *STMT_WAR;
  437. STMT_RAW = isl_union_map_intersect_domain(
  438. isl_union_map_copy(RAW), isl_union_set_copy(TaggedStmtDomain));
  439. STMT_WAW = isl_union_map_intersect_domain(
  440. isl_union_map_copy(WAW), isl_union_set_copy(TaggedStmtDomain));
  441. STMT_WAR =
  442. isl_union_map_intersect_domain(isl_union_map_copy(WAR), TaggedStmtDomain);
  443. LLVM_DEBUG({
  444. dbgs() << "Wrapped Dependences:\n";
  445. dump();
  446. dbgs() << "\n";
  447. });
  448. // To handle reduction dependences we proceed as follows:
  449. // 1) Aggregate all possible reduction dependences, namely all self
  450. // dependences on reduction like statements.
  451. // 2) Intersect them with the actual RAW & WAW dependences to the get the
  452. // actual reduction dependences. This will ensure the load/store memory
  453. // addresses were __identical__ in the two iterations of the statement.
  454. // 3) Relax the original RAW, WAW and WAR dependences by subtracting the
  455. // actual reduction dependences. Binary reductions (sum += A[i]) cause
  456. // the same, RAW, WAW and WAR dependences.
  457. // 4) Add the privatization dependences which are widened versions of
  458. // already present dependences. They model the effect of manual
  459. // privatization at the outermost possible place (namely after the last
  460. // write and before the first access to a reduction location).
  461. // Step 1)
  462. RED = isl_union_map_empty(isl_union_map_get_space(RAW));
  463. for (ScopStmt &Stmt : S) {
  464. for (MemoryAccess *MA : Stmt) {
  465. if (!MA->isReductionLike())
  466. continue;
  467. isl_set *AccDomW = isl_map_wrap(MA->getAccessRelation().release());
  468. isl_map *Identity =
  469. isl_map_from_domain_and_range(isl_set_copy(AccDomW), AccDomW);
  470. RED = isl_union_map_add_map(RED, Identity);
  471. }
  472. }
  473. // Step 2)
  474. RED = isl_union_map_intersect(RED, isl_union_map_copy(RAW));
  475. RED = isl_union_map_intersect(RED, StrictWAW);
  476. if (!isl_union_map_is_empty(RED)) {
  477. // Step 3)
  478. RAW = isl_union_map_subtract(RAW, isl_union_map_copy(RED));
  479. WAW = isl_union_map_subtract(WAW, isl_union_map_copy(RED));
  480. WAR = isl_union_map_subtract(WAR, isl_union_map_copy(RED));
  481. // Step 4)
  482. addPrivatizationDependences();
  483. } else
  484. TC_RED = isl_union_map_empty(isl_union_map_get_space(RED));
  485. LLVM_DEBUG({
  486. dbgs() << "Final Wrapped Dependences:\n";
  487. dump();
  488. dbgs() << "\n";
  489. });
  490. // RED_SIN is used to collect all reduction dependences again after we
  491. // split them according to the causing memory accesses. The current assumption
  492. // is that our method of splitting will not have any leftovers. In the end
  493. // we validate this assumption until we have more confidence in this method.
  494. isl_union_map *RED_SIN = isl_union_map_empty(isl_union_map_get_space(RAW));
  495. // For each reduction like memory access, check if there are reduction
  496. // dependences with the access relation of the memory access as a domain
  497. // (wrapped space!). If so these dependences are caused by this memory access.
  498. // We then move this portion of reduction dependences back to the statement ->
  499. // statement space and add a mapping from the memory access to these
  500. // dependences.
  501. for (ScopStmt &Stmt : S) {
  502. for (MemoryAccess *MA : Stmt) {
  503. if (!MA->isReductionLike())
  504. continue;
  505. isl_set *AccDomW = isl_map_wrap(MA->getAccessRelation().release());
  506. isl_union_map *AccRedDepU = isl_union_map_intersect_domain(
  507. isl_union_map_copy(TC_RED), isl_union_set_from_set(AccDomW));
  508. if (isl_union_map_is_empty(AccRedDepU)) {
  509. isl_union_map_free(AccRedDepU);
  510. continue;
  511. }
  512. isl_map *AccRedDep = isl_map_from_union_map(AccRedDepU);
  513. RED_SIN = isl_union_map_add_map(RED_SIN, isl_map_copy(AccRedDep));
  514. AccRedDep = isl_map_zip(AccRedDep);
  515. AccRedDep = isl_set_unwrap(isl_map_domain(AccRedDep));
  516. setReductionDependences(MA, AccRedDep);
  517. }
  518. }
  519. assert(isl_union_map_is_equal(RED_SIN, TC_RED) &&
  520. "Intersecting the reduction dependence domain with the wrapped access "
  521. "relation is not enough, we need to loosen the access relation also");
  522. isl_union_map_free(RED_SIN);
  523. RAW = isl_union_map_zip(RAW);
  524. WAW = isl_union_map_zip(WAW);
  525. WAR = isl_union_map_zip(WAR);
  526. RED = isl_union_map_zip(RED);
  527. TC_RED = isl_union_map_zip(TC_RED);
  528. LLVM_DEBUG({
  529. dbgs() << "Zipped Dependences:\n";
  530. dump();
  531. dbgs() << "\n";
  532. });
  533. RAW = isl_union_set_unwrap(isl_union_map_domain(RAW));
  534. WAW = isl_union_set_unwrap(isl_union_map_domain(WAW));
  535. WAR = isl_union_set_unwrap(isl_union_map_domain(WAR));
  536. RED = isl_union_set_unwrap(isl_union_map_domain(RED));
  537. TC_RED = isl_union_set_unwrap(isl_union_map_domain(TC_RED));
  538. LLVM_DEBUG({
  539. dbgs() << "Unwrapped Dependences:\n";
  540. dump();
  541. dbgs() << "\n";
  542. });
  543. RAW = isl_union_map_union(RAW, STMT_RAW);
  544. WAW = isl_union_map_union(WAW, STMT_WAW);
  545. WAR = isl_union_map_union(WAR, STMT_WAR);
  546. RAW = isl_union_map_coalesce(RAW);
  547. WAW = isl_union_map_coalesce(WAW);
  548. WAR = isl_union_map_coalesce(WAR);
  549. RED = isl_union_map_coalesce(RED);
  550. TC_RED = isl_union_map_coalesce(TC_RED);
  551. LLVM_DEBUG(dump());
  552. }
  553. bool Dependences::isValidSchedule(Scop &S, isl::schedule NewSched) const {
  554. // TODO: Also check permutable/coincident flags as well.
  555. StatementToIslMapTy NewSchedules;
  556. for (auto NewMap : NewSched.get_map().get_map_list()) {
  557. auto Stmt = reinterpret_cast<ScopStmt *>(
  558. NewMap.get_tuple_id(isl::dim::in).get_user());
  559. NewSchedules[Stmt] = NewMap;
  560. }
  561. return isValidSchedule(S, NewSchedules);
  562. }
  563. bool Dependences::isValidSchedule(
  564. Scop &S, const StatementToIslMapTy &NewSchedule) const {
  565. if (LegalityCheckDisabled)
  566. return true;
  567. isl::union_map Dependences = getDependences(TYPE_RAW | TYPE_WAW | TYPE_WAR);
  568. isl::union_map Schedule = isl::union_map::empty(S.getIslCtx());
  569. isl::space ScheduleSpace;
  570. for (ScopStmt &Stmt : S) {
  571. isl::map StmtScat;
  572. auto Lookup = NewSchedule.find(&Stmt);
  573. if (Lookup == NewSchedule.end())
  574. StmtScat = Stmt.getSchedule();
  575. else
  576. StmtScat = Lookup->second;
  577. assert(!StmtScat.is_null() &&
  578. "Schedules that contain extension nodes require special handling.");
  579. if (ScheduleSpace.is_null())
  580. ScheduleSpace = StmtScat.get_space().range();
  581. Schedule = Schedule.unite(StmtScat);
  582. }
  583. Dependences = Dependences.apply_domain(Schedule);
  584. Dependences = Dependences.apply_range(Schedule);
  585. isl::set Zero = isl::set::universe(ScheduleSpace);
  586. for (auto i : rangeIslSize(0, Zero.tuple_dim()))
  587. Zero = Zero.fix_si(isl::dim::set, i, 0);
  588. isl::union_set UDeltas = Dependences.deltas();
  589. isl::set Deltas = singleton(UDeltas, ScheduleSpace);
  590. isl::space Space = Deltas.get_space();
  591. isl::map NonPositive = isl::map::universe(Space.map_from_set());
  592. NonPositive =
  593. NonPositive.lex_le_at(isl::multi_pw_aff::identity_on_domain(Space));
  594. NonPositive = NonPositive.intersect_domain(Deltas);
  595. NonPositive = NonPositive.intersect_range(Zero);
  596. return NonPositive.is_empty();
  597. }
  598. // Check if the current scheduling dimension is parallel.
  599. //
  600. // We check for parallelism by verifying that the loop does not carry any
  601. // dependences.
  602. //
  603. // Parallelism test: if the distance is zero in all outer dimensions, then it
  604. // has to be zero in the current dimension as well.
  605. //
  606. // Implementation: first, translate dependences into time space, then force
  607. // outer dimensions to be equal. If the distance is zero in the current
  608. // dimension, then the loop is parallel. The distance is zero in the current
  609. // dimension if it is a subset of a map with equal values for the current
  610. // dimension.
  611. bool Dependences::isParallel(__isl_keep isl_union_map *Schedule,
  612. __isl_take isl_union_map *Deps,
  613. __isl_give isl_pw_aff **MinDistancePtr) const {
  614. isl_set *Deltas, *Distance;
  615. isl_map *ScheduleDeps;
  616. unsigned Dimension;
  617. bool IsParallel;
  618. Deps = isl_union_map_apply_range(Deps, isl_union_map_copy(Schedule));
  619. Deps = isl_union_map_apply_domain(Deps, isl_union_map_copy(Schedule));
  620. if (isl_union_map_is_empty(Deps)) {
  621. isl_union_map_free(Deps);
  622. return true;
  623. }
  624. ScheduleDeps = isl_map_from_union_map(Deps);
  625. Dimension = isl_map_dim(ScheduleDeps, isl_dim_out) - 1;
  626. for (unsigned i = 0; i < Dimension; i++)
  627. ScheduleDeps = isl_map_equate(ScheduleDeps, isl_dim_out, i, isl_dim_in, i);
  628. Deltas = isl_map_deltas(ScheduleDeps);
  629. Distance = isl_set_universe(isl_set_get_space(Deltas));
  630. // [0, ..., 0, +] - All zeros and last dimension larger than zero
  631. for (unsigned i = 0; i < Dimension; i++)
  632. Distance = isl_set_fix_si(Distance, isl_dim_set, i, 0);
  633. Distance = isl_set_lower_bound_si(Distance, isl_dim_set, Dimension, 1);
  634. Distance = isl_set_intersect(Distance, Deltas);
  635. IsParallel = isl_set_is_empty(Distance);
  636. if (IsParallel || !MinDistancePtr) {
  637. isl_set_free(Distance);
  638. return IsParallel;
  639. }
  640. Distance = isl_set_project_out(Distance, isl_dim_set, 0, Dimension);
  641. Distance = isl_set_coalesce(Distance);
  642. // This last step will compute a expression for the minimal value in the
  643. // distance polyhedron Distance with regards to the first (outer most)
  644. // dimension.
  645. *MinDistancePtr = isl_pw_aff_coalesce(isl_set_dim_min(Distance, 0));
  646. return false;
  647. }
  648. static void printDependencyMap(raw_ostream &OS, __isl_keep isl_union_map *DM) {
  649. if (DM)
  650. OS << DM << "\n";
  651. else
  652. OS << "n/a\n";
  653. }
  654. void Dependences::print(raw_ostream &OS) const {
  655. OS << "\tRAW dependences:\n\t\t";
  656. printDependencyMap(OS, RAW);
  657. OS << "\tWAR dependences:\n\t\t";
  658. printDependencyMap(OS, WAR);
  659. OS << "\tWAW dependences:\n\t\t";
  660. printDependencyMap(OS, WAW);
  661. OS << "\tReduction dependences:\n\t\t";
  662. printDependencyMap(OS, RED);
  663. OS << "\tTransitive closure of reduction dependences:\n\t\t";
  664. printDependencyMap(OS, TC_RED);
  665. }
  666. void Dependences::dump() const { print(dbgs()); }
  667. void Dependences::releaseMemory() {
  668. isl_union_map_free(RAW);
  669. isl_union_map_free(WAR);
  670. isl_union_map_free(WAW);
  671. isl_union_map_free(RED);
  672. isl_union_map_free(TC_RED);
  673. RED = RAW = WAR = WAW = TC_RED = nullptr;
  674. for (auto &ReductionDeps : ReductionDependences)
  675. isl_map_free(ReductionDeps.second);
  676. ReductionDependences.clear();
  677. }
  678. isl::union_map Dependences::getDependences(int Kinds) const {
  679. assert(hasValidDependences() && "No valid dependences available");
  680. isl::space Space = isl::manage_copy(RAW).get_space();
  681. isl::union_map Deps = Deps.empty(Space.ctx());
  682. if (Kinds & TYPE_RAW)
  683. Deps = Deps.unite(isl::manage_copy(RAW));
  684. if (Kinds & TYPE_WAR)
  685. Deps = Deps.unite(isl::manage_copy(WAR));
  686. if (Kinds & TYPE_WAW)
  687. Deps = Deps.unite(isl::manage_copy(WAW));
  688. if (Kinds & TYPE_RED)
  689. Deps = Deps.unite(isl::manage_copy(RED));
  690. if (Kinds & TYPE_TC_RED)
  691. Deps = Deps.unite(isl::manage_copy(TC_RED));
  692. Deps = Deps.coalesce();
  693. Deps = Deps.detect_equalities();
  694. return Deps;
  695. }
  696. bool Dependences::hasValidDependences() const {
  697. return (RAW != nullptr) && (WAR != nullptr) && (WAW != nullptr);
  698. }
  699. __isl_give isl_map *
  700. Dependences::getReductionDependences(MemoryAccess *MA) const {
  701. return isl_map_copy(ReductionDependences.lookup(MA));
  702. }
  703. void Dependences::setReductionDependences(MemoryAccess *MA,
  704. __isl_take isl_map *D) {
  705. assert(ReductionDependences.count(MA) == 0 &&
  706. "Reduction dependences set twice!");
  707. ReductionDependences[MA] = D;
  708. }
  709. const Dependences &
  710. DependenceAnalysis::Result::getDependences(Dependences::AnalysisLevel Level) {
  711. if (Dependences *d = D[Level].get())
  712. return *d;
  713. return recomputeDependences(Level);
  714. }
  715. const Dependences &DependenceAnalysis::Result::recomputeDependences(
  716. Dependences::AnalysisLevel Level) {
  717. D[Level].reset(new Dependences(S.getSharedIslCtx(), Level));
  718. D[Level]->calculateDependences(S);
  719. return *D[Level];
  720. }
  721. void DependenceAnalysis::Result::abandonDependences() {
  722. for (std::unique_ptr<Dependences> &Deps : D)
  723. Deps.release();
  724. }
  725. DependenceAnalysis::Result
  726. DependenceAnalysis::run(Scop &S, ScopAnalysisManager &SAM,
  727. ScopStandardAnalysisResults &SAR) {
  728. return {S, {}};
  729. }
  730. AnalysisKey DependenceAnalysis::Key;
  731. PreservedAnalyses
  732. DependenceInfoPrinterPass::run(Scop &S, ScopAnalysisManager &SAM,
  733. ScopStandardAnalysisResults &SAR,
  734. SPMUpdater &U) {
  735. auto &DI = SAM.getResult<DependenceAnalysis>(S, SAR);
  736. if (auto d = DI.D[OptAnalysisLevel].get()) {
  737. d->print(OS);
  738. return PreservedAnalyses::all();
  739. }
  740. // Otherwise create the dependences on-the-fly and print them
  741. Dependences D(S.getSharedIslCtx(), OptAnalysisLevel);
  742. D.calculateDependences(S);
  743. D.print(OS);
  744. return PreservedAnalyses::all();
  745. }
  746. const Dependences &
  747. DependenceInfo::getDependences(Dependences::AnalysisLevel Level) {
  748. if (Dependences *d = D[Level].get())
  749. return *d;
  750. return recomputeDependences(Level);
  751. }
  752. const Dependences &
  753. DependenceInfo::recomputeDependences(Dependences::AnalysisLevel Level) {
  754. D[Level].reset(new Dependences(S->getSharedIslCtx(), Level));
  755. D[Level]->calculateDependences(*S);
  756. return *D[Level];
  757. }
  758. void DependenceInfo::abandonDependences() {
  759. for (std::unique_ptr<Dependences> &Deps : D)
  760. Deps.release();
  761. }
  762. bool DependenceInfo::runOnScop(Scop &ScopVar) {
  763. S = &ScopVar;
  764. return false;
  765. }
  766. /// Print the dependences for the given SCoP to @p OS.
  767. void polly::DependenceInfo::printScop(raw_ostream &OS, Scop &S) const {
  768. if (auto d = D[OptAnalysisLevel].get()) {
  769. d->print(OS);
  770. return;
  771. }
  772. // Otherwise create the dependences on-the-fly and print it
  773. Dependences D(S.getSharedIslCtx(), OptAnalysisLevel);
  774. D.calculateDependences(S);
  775. D.print(OS);
  776. }
  777. void DependenceInfo::getAnalysisUsage(AnalysisUsage &AU) const {
  778. AU.addRequiredTransitive<ScopInfoRegionPass>();
  779. AU.setPreservesAll();
  780. }
  781. char DependenceInfo::ID = 0;
  782. Pass *polly::createDependenceInfoPass() { return new DependenceInfo(); }
  783. INITIALIZE_PASS_BEGIN(DependenceInfo, "polly-dependences",
  784. "Polly - Calculate dependences", false, false);
  785. INITIALIZE_PASS_DEPENDENCY(ScopInfoRegionPass);
  786. INITIALIZE_PASS_END(DependenceInfo, "polly-dependences",
  787. "Polly - Calculate dependences", false, false)
  788. //===----------------------------------------------------------------------===//
  789. namespace {
  790. /// Print result from DependenceAnalysis.
  791. class DependenceInfoPrinterLegacyPass final : public ScopPass {
  792. public:
  793. static char ID;
  794. DependenceInfoPrinterLegacyPass() : DependenceInfoPrinterLegacyPass(outs()) {}
  795. explicit DependenceInfoPrinterLegacyPass(llvm::raw_ostream &OS)
  796. : ScopPass(ID), OS(OS) {}
  797. bool runOnScop(Scop &S) override {
  798. DependenceInfo &P = getAnalysis<DependenceInfo>();
  799. OS << "Printing analysis '" << P.getPassName() << "' for "
  800. << "region: '" << S.getRegion().getNameStr() << "' in function '"
  801. << S.getFunction().getName() << "':\n";
  802. P.printScop(OS, S);
  803. return false;
  804. }
  805. void getAnalysisUsage(AnalysisUsage &AU) const override {
  806. ScopPass::getAnalysisUsage(AU);
  807. AU.addRequired<DependenceInfo>();
  808. AU.setPreservesAll();
  809. }
  810. private:
  811. llvm::raw_ostream &OS;
  812. };
  813. char DependenceInfoPrinterLegacyPass::ID = 0;
  814. } // namespace
  815. Pass *polly::createDependenceInfoPrinterLegacyPass(raw_ostream &OS) {
  816. return new DependenceInfoPrinterLegacyPass(OS);
  817. }
  818. INITIALIZE_PASS_BEGIN(DependenceInfoPrinterLegacyPass,
  819. "polly-print-dependences", "Polly - Print dependences",
  820. false, false);
  821. INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
  822. INITIALIZE_PASS_END(DependenceInfoPrinterLegacyPass, "polly-print-dependences",
  823. "Polly - Print dependences", false, false)
  824. //===----------------------------------------------------------------------===//
  825. const Dependences &
  826. DependenceInfoWrapperPass::getDependences(Scop *S,
  827. Dependences::AnalysisLevel Level) {
  828. auto It = ScopToDepsMap.find(S);
  829. if (It != ScopToDepsMap.end())
  830. if (It->second) {
  831. if (It->second->getDependenceLevel() == Level)
  832. return *It->second.get();
  833. }
  834. return recomputeDependences(S, Level);
  835. }
  836. const Dependences &DependenceInfoWrapperPass::recomputeDependences(
  837. Scop *S, Dependences::AnalysisLevel Level) {
  838. std::unique_ptr<Dependences> D(new Dependences(S->getSharedIslCtx(), Level));
  839. D->calculateDependences(*S);
  840. auto Inserted = ScopToDepsMap.insert(std::make_pair(S, std::move(D)));
  841. return *Inserted.first->second;
  842. }
  843. bool DependenceInfoWrapperPass::runOnFunction(Function &F) {
  844. auto &SI = *getAnalysis<ScopInfoWrapperPass>().getSI();
  845. for (auto &It : SI) {
  846. assert(It.second && "Invalid SCoP object!");
  847. recomputeDependences(It.second.get(), Dependences::AL_Access);
  848. }
  849. return false;
  850. }
  851. void DependenceInfoWrapperPass::print(raw_ostream &OS, const Module *M) const {
  852. for (auto &It : ScopToDepsMap) {
  853. assert((It.first && It.second) && "Invalid Scop or Dependence object!\n");
  854. It.second->print(OS);
  855. }
  856. }
  857. void DependenceInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
  858. AU.addRequiredTransitive<ScopInfoWrapperPass>();
  859. AU.setPreservesAll();
  860. }
  861. char DependenceInfoWrapperPass::ID = 0;
  862. Pass *polly::createDependenceInfoWrapperPassPass() {
  863. return new DependenceInfoWrapperPass();
  864. }
  865. INITIALIZE_PASS_BEGIN(
  866. DependenceInfoWrapperPass, "polly-function-dependences",
  867. "Polly - Calculate dependences for all the SCoPs of a function", false,
  868. false)
  869. INITIALIZE_PASS_DEPENDENCY(ScopInfoWrapperPass);
  870. INITIALIZE_PASS_END(
  871. DependenceInfoWrapperPass, "polly-function-dependences",
  872. "Polly - Calculate dependences for all the SCoPs of a function", false,
  873. false)
  874. //===----------------------------------------------------------------------===//
  875. namespace {
  876. /// Print result from DependenceInfoWrapperPass.
  877. class DependenceInfoPrinterLegacyFunctionPass final : public FunctionPass {
  878. public:
  879. static char ID;
  880. DependenceInfoPrinterLegacyFunctionPass()
  881. : DependenceInfoPrinterLegacyFunctionPass(outs()) {}
  882. explicit DependenceInfoPrinterLegacyFunctionPass(llvm::raw_ostream &OS)
  883. : FunctionPass(ID), OS(OS) {}
  884. bool runOnFunction(Function &F) override {
  885. DependenceInfoWrapperPass &P = getAnalysis<DependenceInfoWrapperPass>();
  886. OS << "Printing analysis '" << P.getPassName() << "' for function '"
  887. << F.getName() << "':\n";
  888. P.print(OS);
  889. return false;
  890. }
  891. void getAnalysisUsage(AnalysisUsage &AU) const override {
  892. FunctionPass::getAnalysisUsage(AU);
  893. AU.addRequired<DependenceInfoWrapperPass>();
  894. AU.setPreservesAll();
  895. }
  896. private:
  897. llvm::raw_ostream &OS;
  898. };
  899. char DependenceInfoPrinterLegacyFunctionPass::ID = 0;
  900. } // namespace
  901. Pass *polly::createDependenceInfoPrinterLegacyFunctionPass(raw_ostream &OS) {
  902. return new DependenceInfoPrinterLegacyFunctionPass(OS);
  903. }
  904. INITIALIZE_PASS_BEGIN(
  905. DependenceInfoPrinterLegacyFunctionPass, "polly-print-function-dependences",
  906. "Polly - Print dependences for all the SCoPs of a function", false, false);
  907. INITIALIZE_PASS_DEPENDENCY(DependenceInfoWrapperPass);
  908. INITIALIZE_PASS_END(DependenceInfoPrinterLegacyFunctionPass,
  909. "polly-print-function-dependences",
  910. "Polly - Print dependences for all the SCoPs of a function",
  911. false, false)