Coverage Report

Created: 2017-11-21 03:47

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