Polly 22.0.0git
FlattenSchedule.cpp
Go to the documentation of this file.
1//===------ FlattenSchedule.cpp --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Try to reduce the number of scatter dimension. Useful to make isl_union_map
10// schedules more understandable. This is only intended for debugging and
11// unittests, not for production use.
12//
13//===----------------------------------------------------------------------===//
14
16#include "polly/FlattenAlgo.h"
17#include "polly/Options.h"
18#include "polly/ScopInfo.h"
22#define DEBUG_TYPE "polly-flatten-schedule"
23
24using namespace polly;
25using namespace llvm;
26
27namespace {
28
29static cl::opt<bool> PollyPrintFlattenSchedule("polly-print-flatten-schedule",
30 cl::desc("A polly pass"),
31 cl::cat(PollyCategory));
32
33/// Print a schedule to @p OS.
34///
35/// Prints the schedule for each statements on a new line.
36void printSchedule(raw_ostream &OS, const isl::union_map &Schedule,
37 int indent) {
38 for (isl::map Map : Schedule.get_map_list())
39 OS.indent(indent) << Map << "\n";
40}
41} // namespace
42
44 // Keep a reference to isl_ctx to ensure that it is not freed before we free
45 // OldSchedule.
46 auto IslCtx = S.getSharedIslCtx();
47
48 POLLY_DEBUG(dbgs() << "Going to flatten old schedule:\n");
49 auto OldSchedule = S.getSchedule();
50 POLLY_DEBUG(printSchedule(dbgs(), OldSchedule, 2));
51
52 auto Domains = S.getDomains();
53 auto RestrictedOldSchedule = OldSchedule.intersect_domain(Domains);
54 POLLY_DEBUG(dbgs() << "Old schedule with domains:\n");
55 POLLY_DEBUG(printSchedule(dbgs(), RestrictedOldSchedule, 2));
56
57 auto NewSchedule = flattenSchedule(RestrictedOldSchedule);
58
59 POLLY_DEBUG(dbgs() << "Flattened new schedule:\n");
60 POLLY_DEBUG(printSchedule(dbgs(), NewSchedule, 2));
61
62 NewSchedule = NewSchedule.gist_domain(Domains);
63 POLLY_DEBUG(dbgs() << "Gisted, flattened new schedule:\n");
64 POLLY_DEBUG(printSchedule(dbgs(), NewSchedule, 2));
65
66 S.setSchedule(NewSchedule);
67
68 if (PollyPrintFlattenSchedule) {
69 outs()
70 << "Printing analysis 'Polly - Print flattened schedule' for region: '"
71 << S.getRegion().getNameStr() << "' in function '"
72 << S.getFunction().getName() << "':\n";
73
74 outs() << "Schedule before flattening {\n";
75 printSchedule(outs(), OldSchedule, 4);
76 outs() << "}\n\n";
77
78 outs() << "Schedule after flattening {\n";
79 printSchedule(outs(), S.getSchedule(), 4);
80 outs() << "}\n";
81 }
82}
llvm::cl::OptionCategory PollyCategory
#define POLLY_DEBUG(X)
Definition PollyDebug.h:23
isl::map_list get_map_list() const
Static Control Part.
Definition ScopInfo.h:1625
void runFlattenSchedulePass(Scop &S)
isl::union_map flattenSchedule(isl::union_map Schedule)
Recursively flatten a schedule.