Coverage Report

Created: 2017-08-21 19:50

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