Coverage Report

Created: 2017-04-29 12:21

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