/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/Transform/FlattenSchedule.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===------ FlattenSchedule.cpp --------------------------------*- C++ -*-===// |
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 | | // Try to reduce the number of scatter dimension. Useful to make isl_union_map |
10 | | // schedules more understandable. This is only intended for debugging and |
11 | | // unittests, not for production use. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #include "polly/FlattenSchedule.h" |
16 | | #include "polly/FlattenAlgo.h" |
17 | | #include "polly/ScopInfo.h" |
18 | | #include "polly/ScopPass.h" |
19 | | #include "polly/Support/ISLOStream.h" |
20 | | #include "polly/Support/ISLTools.h" |
21 | | #define DEBUG_TYPE "polly-flatten-schedule" |
22 | | |
23 | | using namespace polly; |
24 | | using namespace llvm; |
25 | | |
26 | | namespace { |
27 | | |
28 | | /// Print a schedule to @p OS. |
29 | | /// |
30 | | /// Prints the schedule for each statements on a new line. |
31 | | void printSchedule(raw_ostream &OS, const isl::union_map &Schedule, |
32 | 36 | int indent) { |
33 | 36 | for (isl::map Map : Schedule.get_map_list()) |
34 | 168 | OS.indent(indent) << Map << "\n"; |
35 | 36 | } |
36 | | |
37 | | /// Flatten the schedule stored in an polly::Scop. |
38 | | class FlattenSchedule : public ScopPass { |
39 | | private: |
40 | | FlattenSchedule(const FlattenSchedule &) = delete; |
41 | | const FlattenSchedule &operator=(const FlattenSchedule &) = delete; |
42 | | |
43 | | std::shared_ptr<isl_ctx> IslCtx; |
44 | | isl::union_map OldSchedule; |
45 | | |
46 | | public: |
47 | | static char ID; |
48 | 18 | explicit FlattenSchedule() : ScopPass(ID) {} |
49 | | |
50 | 18 | virtual void getAnalysisUsage(AnalysisUsage &AU) const override { |
51 | 18 | AU.addRequiredTransitive<ScopInfoRegionPass>(); |
52 | 18 | AU.setPreservesAll(); |
53 | 18 | } |
54 | | |
55 | 18 | virtual bool runOnScop(Scop &S) override { |
56 | 18 | // Keep a reference to isl_ctx to ensure that it is not freed before we free |
57 | 18 | // OldSchedule. |
58 | 18 | IslCtx = S.getSharedIslCtx(); |
59 | 18 | |
60 | 18 | LLVM_DEBUG(dbgs() << "Going to flatten old schedule:\n"); |
61 | 18 | OldSchedule = S.getSchedule(); |
62 | 18 | LLVM_DEBUG(printSchedule(dbgs(), OldSchedule, 2)); |
63 | 18 | |
64 | 18 | auto Domains = S.getDomains(); |
65 | 18 | auto RestrictedOldSchedule = OldSchedule.intersect_domain(Domains); |
66 | 18 | LLVM_DEBUG(dbgs() << "Old schedule with domains:\n"); |
67 | 18 | LLVM_DEBUG(printSchedule(dbgs(), RestrictedOldSchedule, 2)); |
68 | 18 | |
69 | 18 | auto NewSchedule = flattenSchedule(RestrictedOldSchedule); |
70 | 18 | |
71 | 18 | LLVM_DEBUG(dbgs() << "Flattened new schedule:\n"); |
72 | 18 | LLVM_DEBUG(printSchedule(dbgs(), NewSchedule, 2)); |
73 | 18 | |
74 | 18 | NewSchedule = NewSchedule.gist_domain(Domains); |
75 | 18 | LLVM_DEBUG(dbgs() << "Gisted, flattened new schedule:\n"); |
76 | 18 | LLVM_DEBUG(printSchedule(dbgs(), NewSchedule, 2)); |
77 | 18 | |
78 | 18 | S.setSchedule(NewSchedule); |
79 | 18 | return false; |
80 | 18 | } |
81 | | |
82 | 18 | virtual void printScop(raw_ostream &OS, Scop &S) const override { |
83 | 18 | OS << "Schedule before flattening {\n"; |
84 | 18 | printSchedule(OS, OldSchedule, 4); |
85 | 18 | OS << "}\n\n"; |
86 | 18 | |
87 | 18 | OS << "Schedule after flattening {\n"; |
88 | 18 | printSchedule(OS, S.getSchedule(), 4); |
89 | 18 | OS << "}\n"; |
90 | 18 | } |
91 | | |
92 | 77 | virtual void releaseMemory() override { |
93 | 77 | OldSchedule = nullptr; |
94 | 77 | IslCtx.reset(); |
95 | 77 | } |
96 | | }; |
97 | | |
98 | | char FlattenSchedule::ID; |
99 | | } // anonymous namespace |
100 | | |
101 | 0 | Pass *polly::createFlattenSchedulePass() { return new FlattenSchedule(); } |
102 | | |
103 | 48.2k | INITIALIZE_PASS_BEGIN(FlattenSchedule, "polly-flatten-schedule", |
104 | 48.2k | "Polly - Flatten schedule", false, false) |
105 | 48.2k | INITIALIZE_PASS_END(FlattenSchedule, "polly-flatten-schedule", |
106 | | "Polly - Flatten schedule", false, false) |