Coverage Report

Created: 2017-06-23 12:40

/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
#include "polly/Support/ISLOStream.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
30
                   int indent) {
33
138
  Schedule.foreach_map([&OS, indent](isl::map Map) -> isl::stat {
34
138
    OS.indent(indent) << Map << "\n";
35
138
    return isl::stat::ok;
36
138
  });
37
30
}
38
39
/// Flatten the schedule stored in an polly::Scop.
40
class FlattenSchedule : public ScopPass {
41
private:
42
  FlattenSchedule(const FlattenSchedule &) = delete;
43
  const FlattenSchedule &operator=(const FlattenSchedule &) = delete;
44
45
  std::shared_ptr<isl_ctx> IslCtx;
46
  isl::union_map OldSchedule;
47
48
public:
49
  static char ID;
50
15
  explicit FlattenSchedule() : ScopPass(ID) {}
51
52
15
  virtual void getAnalysisUsage(AnalysisUsage &AU) const override {
53
15
    AU.addRequiredTransitive<ScopInfoRegionPass>();
54
15
    AU.setPreservesAll();
55
15
  }
56
57
15
  virtual bool runOnScop(Scop &S) override {
58
15
    // Keep a reference to isl_ctx to ensure that it is not freed before we free
59
15
    // OldSchedule.
60
15
    IslCtx = S.getSharedIslCtx();
61
15
62
15
    DEBUG(dbgs() << "Going to flatten old schedule:\n");
63
15
    OldSchedule = give(S.getSchedule());
64
15
    DEBUG(printSchedule(dbgs(), OldSchedule, 2));
65
15
66
15
    auto Domains = give(S.getDomains());
67
15
    auto RestrictedOldSchedule = OldSchedule.intersect_domain(Domains);
68
15
    DEBUG(dbgs() << "Old schedule with domains:\n");
69
15
    DEBUG(printSchedule(dbgs(), RestrictedOldSchedule, 2));
70
15
71
15
    auto NewSchedule = flattenSchedule(RestrictedOldSchedule);
72
15
73
15
    DEBUG(dbgs() << "Flattened new schedule:\n");
74
15
    DEBUG(printSchedule(dbgs(), NewSchedule, 2));
75
15
76
15
    NewSchedule = NewSchedule.gist_domain(Domains);
77
15
    DEBUG(dbgs() << "Gisted, flattened new schedule:\n");
78
15
    DEBUG(printSchedule(dbgs(), NewSchedule, 2));
79
15
80
15
    S.setSchedule(NewSchedule.take());
81
15
    return false;
82
15
  }
83
84
15
  virtual void printScop(raw_ostream &OS, Scop &S) const override {
85
15
    OS << "Schedule before flattening {\n";
86
15
    printSchedule(OS, OldSchedule, 4);
87
15
    OS << "}\n\n";
88
15
89
15
    OS << "Schedule after flattening {\n";
90
15
    printSchedule(OS, give(S.getSchedule()), 4);
91
15
    OS << "}\n";
92
15
  }
93
94
64
  virtual void releaseMemory() override {
95
64
    OldSchedule = nullptr;
96
64
    IslCtx.reset();
97
64
  }
98
};
99
100
char FlattenSchedule::ID;
101
} // anonymous namespace
102
103
0
Pass *polly::createFlattenSchedulePass() { return new FlattenSchedule(); }
104
105
41.0k
INITIALIZE_PASS_BEGIN41.0k
(FlattenSchedule, "polly-flatten-schedule",41.0k
106
41.0k
                      "Polly - Flatten schedule", false, false)
107
41.0k
INITIALIZE_PASS_END(FlattenSchedule, "polly-flatten-schedule",
108
                    "Polly - Flatten schedule", false, false)