brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 3bb3c2f Raw
83 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// Try to reduce the number of scatter dimension. Useful to make isl_union_map10// schedules more understandable. This is only intended for debugging and11// unittests, not for production use.12//13//===----------------------------------------------------------------------===//14 15#include "polly/FlattenSchedule.h"16#include "polly/FlattenAlgo.h"17#include "polly/Options.h"18#include "polly/ScopInfo.h"19#include "polly/Support/ISLOStream.h"20#include "polly/Support/ISLTools.h"21#include "polly/Support/PollyDebug.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} // namespace42 43void polly::runFlattenSchedulePass(Scop &S) {44  // Keep a reference to isl_ctx to ensure that it is not freed before we free45  // 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}83