Coverage Report

Created: 2018-12-13 20:48

/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
//                     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
#include "polly/Support/ISLTools.h"
22
#define DEBUG_TYPE "polly-flatten-schedule"
23
24
using namespace polly;
25
using namespace llvm;
26
27
namespace {
28
29
/// Print a schedule to @p OS.
30
///
31
/// Prints the schedule for each statements on a new line.
32
void printSchedule(raw_ostream &OS, const isl::union_map &Schedule,
33
36
                   int indent) {
34
36
  for (isl::map Map : Schedule.get_map_list())
35
168
    OS.indent(indent) << Map << "\n";
36
36
}
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
18
  explicit FlattenSchedule() : ScopPass(ID) {}
50
51
18
  virtual void getAnalysisUsage(AnalysisUsage &AU) const override {
52
18
    AU.addRequiredTransitive<ScopInfoRegionPass>();
53
18
    AU.setPreservesAll();
54
18
  }
55
56
18
  virtual bool runOnScop(Scop &S) override {
57
18
    // Keep a reference to isl_ctx to ensure that it is not freed before we free
58
18
    // OldSchedule.
59
18
    IslCtx = S.getSharedIslCtx();
60
18
61
18
    LLVM_DEBUG(dbgs() << "Going to flatten old schedule:\n");
62
18
    OldSchedule = S.getSchedule();
63
18
    LLVM_DEBUG(printSchedule(dbgs(), OldSchedule, 2));
64
18
65
18
    auto Domains = S.getDomains();
66
18
    auto RestrictedOldSchedule = OldSchedule.intersect_domain(Domains);
67
18
    LLVM_DEBUG(dbgs() << "Old schedule with domains:\n");
68
18
    LLVM_DEBUG(printSchedule(dbgs(), RestrictedOldSchedule, 2));
69
18
70
18
    auto NewSchedule = flattenSchedule(RestrictedOldSchedule);
71
18
72
18
    LLVM_DEBUG(dbgs() << "Flattened new schedule:\n");
73
18
    LLVM_DEBUG(printSchedule(dbgs(), NewSchedule, 2));
74
18
75
18
    NewSchedule = NewSchedule.gist_domain(Domains);
76
18
    LLVM_DEBUG(dbgs() << "Gisted, flattened new schedule:\n");
77
18
    LLVM_DEBUG(printSchedule(dbgs(), NewSchedule, 2));
78
18
79
18
    S.setSchedule(NewSchedule);
80
18
    return false;
81
18
  }
82
83
18
  virtual void printScop(raw_ostream &OS, Scop &S) const override {
84
18
    OS << "Schedule before flattening {\n";
85
18
    printSchedule(OS, OldSchedule, 4);
86
18
    OS << "}\n\n";
87
18
88
18
    OS << "Schedule after flattening {\n";
89
18
    printSchedule(OS, S.getSchedule(), 4);
90
18
    OS << "}\n";
91
18
  }
92
93
77
  virtual void releaseMemory() override {
94
77
    OldSchedule = nullptr;
95
77
    IslCtx.reset();
96
77
  }
97
};
98
99
char FlattenSchedule::ID;
100
} // anonymous namespace
101
102
0
Pass *polly::createFlattenSchedulePass() { return new FlattenSchedule(); }
103
104
45.6k
INITIALIZE_PASS_BEGIN(FlattenSchedule, "polly-flatten-schedule",
105
45.6k
                      "Polly - Flatten schedule", false, false)
106
45.6k
INITIALIZE_PASS_END(FlattenSchedule, "polly-flatten-schedule",
107
                    "Polly - Flatten schedule", false, false)