2012-08-02 15:47:26 +08:00
|
|
|
//===- Pluto.cpp - Calculate an optimized schedule ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Use libpluto to optimize the schedule.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "polly/Config/config.h"
|
|
|
|
|
|
|
|
#ifdef PLUTO_FOUND
|
|
|
|
#include "polly/CodeGen/CodeGeneration.h"
|
|
|
|
#include "polly/Dependences.h"
|
|
|
|
#include "polly/LinkAllPasses.h"
|
2013-05-07 15:31:10 +08:00
|
|
|
#include "polly/Options.h"
|
2012-08-02 15:47:26 +08:00
|
|
|
#include "polly/ScopInfo.h"
|
2012-08-30 19:49:31 +08:00
|
|
|
#include "polly/Support/GICHelper.h"
|
2012-08-02 15:47:26 +08:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "polly-opt-pluto"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
|
|
|
|
#include "pluto/libpluto.h"
|
|
|
|
#include "isl/map.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace polly;
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
static cl::opt<bool> EnableTiling("polly-pluto-tile", cl::desc("Enable tiling"),
|
2014-03-14 07:37:48 +08:00
|
|
|
cl::Hidden, cl::init(false), cl::ZeroOrMore,
|
2013-05-07 15:31:10 +08:00
|
|
|
cl::cat(PollyCategory));
|
2012-08-02 15:47:26 +08:00
|
|
|
|
2014-03-14 07:37:48 +08:00
|
|
|
static cl::opt<bool> EnableIntraTiling("polly-pluto-intratileopt",
|
|
|
|
cl::desc("Enable intratiling"),
|
|
|
|
cl::Hidden, cl::init(true),
|
|
|
|
cl::ZeroOrMore, cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoDebug("polly-pluto-debug",
|
|
|
|
cl::desc("Enable pluto debug"), cl::Hidden,
|
|
|
|
cl::init(false), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoMoreDebug("polly-pluto-moredebug",
|
|
|
|
cl::desc("Enable more pluto debugging"),
|
|
|
|
cl::Hidden, cl::init(false), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoParallel("polly-pluto-parallel",
|
|
|
|
cl::desc("Enable pluto parallel transforms"),
|
|
|
|
cl::Hidden, cl::init(false), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
PlutoInnerParallel("polly-pluto-innerpara",
|
|
|
|
cl::desc("Enable inner parallelism instead of piped."),
|
|
|
|
cl::Hidden, cl::init(false), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
PlutoIdentity("polly-pluto-identity",
|
|
|
|
cl::desc("Enable pluto identity transformation"), cl::Hidden,
|
|
|
|
cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoUnroll("polly-pluto-unroll",
|
|
|
|
cl::desc("Enable pluto unrolling"), cl::Hidden,
|
|
|
|
cl::init(false), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoRar("polly-pluto-rar",
|
|
|
|
cl::desc("Enable pluto rar deps"), cl::Hidden,
|
|
|
|
cl::init(false), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoParaPipe("polly-pluto-multipipe",
|
|
|
|
cl::desc("Enable multipipe parallelism"),
|
|
|
|
cl::Hidden, cl::init(false), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoL2Tile("polly-pluto-l2tile",
|
|
|
|
cl::desc("Enable L2 tiling"), cl::Hidden,
|
|
|
|
cl::init(false), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoPollyUnroll("polly-pluto-pollyunroll",
|
|
|
|
cl::desc("Enable pluto polly unrolling"),
|
|
|
|
cl::Hidden, cl::init(false),
|
|
|
|
cl::ZeroOrMore, cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
PlutoIslDep("polly-pluto-isldep",
|
|
|
|
cl::desc("Enable pluto isl dependency scanning"), cl::Hidden,
|
|
|
|
cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoIslDepCompact(
|
|
|
|
"polly-pluto-isldepcom", cl::desc("Enable pluto isl dependency compaction"),
|
|
|
|
cl::Hidden, cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoIslSolve("polly-pluto-islsolve",
|
|
|
|
cl::desc("Enable pluto isl solver"),
|
|
|
|
cl::Hidden, cl::init(false), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
|
|
|
static cl::opt<bool> PlutoLastWriter("polly-pluto-lastwriter",
|
|
|
|
cl::desc("Enable pluto lastwriter"),
|
|
|
|
cl::Hidden, cl::init(false),
|
|
|
|
cl::ZeroOrMore, cl::cat(PollyCategory));
|
|
|
|
|
2012-08-02 15:47:26 +08:00
|
|
|
namespace {
|
|
|
|
/// Convert an int into a string.
|
2013-03-23 09:05:07 +08:00
|
|
|
static std::string convertInt(int number) {
|
2012-08-02 15:47:26 +08:00
|
|
|
if (number == 0)
|
|
|
|
return "0";
|
|
|
|
std::string temp = "";
|
|
|
|
std::string returnvalue = "";
|
2013-03-23 09:05:07 +08:00
|
|
|
while (number > 0) {
|
2012-08-02 15:47:26 +08:00
|
|
|
temp += number % 10 + 48;
|
|
|
|
number /= 10;
|
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < temp.length(); i++)
|
2013-03-23 09:05:07 +08:00
|
|
|
returnvalue += temp[temp.length() - i - 1];
|
2012-08-02 15:47:26 +08:00
|
|
|
return returnvalue;
|
|
|
|
}
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
class PlutoOptimizer : public ScopPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
explicit PlutoOptimizer() : ScopPass(ID) {}
|
2012-08-02 15:47:26 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
virtual bool runOnScop(Scop &S);
|
|
|
|
void printScop(llvm::raw_ostream &OS) const;
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
static void extendScattering(Scop &S, unsigned NewDimensions);
|
|
|
|
};
|
2012-08-02 15:47:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char PlutoOptimizer::ID = 0;
|
|
|
|
|
|
|
|
static int getSingleMap(__isl_take isl_map *map, void *user) {
|
2013-03-23 09:05:07 +08:00
|
|
|
isl_map **singleMap = (isl_map **)user;
|
2012-08-02 15:47:26 +08:00
|
|
|
*singleMap = map;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlutoOptimizer::extendScattering(Scop &S, unsigned NewDimensions) {
|
|
|
|
for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
|
|
|
|
ScopStmt *Stmt = *SI;
|
|
|
|
unsigned OldDimensions = Stmt->getNumScattering();
|
|
|
|
isl_space *Space;
|
|
|
|
isl_map *Map, *New;
|
|
|
|
|
|
|
|
Space = isl_space_alloc(Stmt->getIslCtx(), 0, OldDimensions, NewDimensions);
|
|
|
|
Map = isl_map_universe(Space);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < OldDimensions; i++)
|
|
|
|
Map = isl_map_equate(Map, isl_dim_in, i, isl_dim_out, i);
|
|
|
|
|
|
|
|
for (unsigned i = OldDimensions; i < NewDimensions; i++)
|
|
|
|
Map = isl_map_fix_si(Map, isl_dim_out, i, 0);
|
|
|
|
|
|
|
|
Map = isl_map_align_params(Map, S.getParamSpace());
|
|
|
|
New = isl_map_apply_range(Stmt->getScattering(), Map);
|
|
|
|
Stmt->setScattering(New);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlutoOptimizer::runOnScop(Scop &S) {
|
|
|
|
isl_union_set *Domain;
|
|
|
|
isl_union_map *Deps, *ToPlutoNames, *Schedule;
|
|
|
|
PlutoOptions *Options;
|
|
|
|
|
|
|
|
Dependences *D = &getAnalysis<Dependences>();
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
int DependencesKinds =
|
|
|
|
Dependences::TYPE_RAW | Dependences::TYPE_WAR | Dependences::TYPE_WAW;
|
2012-08-02 15:47:26 +08:00
|
|
|
|
|
|
|
Deps = D->getDependences(DependencesKinds);
|
|
|
|
Domain = S.getDomains();
|
|
|
|
ToPlutoNames = isl_union_map_empty(S.getParamSpace());
|
|
|
|
|
|
|
|
int counter = 0;
|
|
|
|
for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
|
|
|
|
ScopStmt *Stmt = *SI;
|
|
|
|
std::string Name = "S_" + convertInt(counter);
|
|
|
|
isl_map *Identity = isl_map_identity(isl_space_map_from_domain_and_range(
|
2013-03-23 09:05:07 +08:00
|
|
|
Stmt->getDomainSpace(), Stmt->getDomainSpace()));
|
2012-08-02 15:47:26 +08:00
|
|
|
Identity = isl_map_set_tuple_name(Identity, isl_dim_out, Name.c_str());
|
|
|
|
ToPlutoNames = isl_union_map_add_map(ToPlutoNames, Identity);
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Deps = isl_union_map_apply_domain(Deps, isl_union_map_copy(ToPlutoNames));
|
|
|
|
Deps = isl_union_map_apply_range(Deps, isl_union_map_copy(ToPlutoNames));
|
|
|
|
Domain = isl_union_set_apply(Domain, isl_union_map_copy(ToPlutoNames));
|
|
|
|
|
|
|
|
Options = pluto_options_alloc();
|
2014-03-14 07:37:48 +08:00
|
|
|
Options->debug = PlutoDebug;
|
|
|
|
Options->fuse = 2;
|
|
|
|
Options->identity = PlutoIdentity;
|
|
|
|
Options->innerpar = PlutoInnerParallel;
|
|
|
|
Options->intratileopt = EnableIntraTiling;
|
|
|
|
Options->isldep = PlutoIslDep;
|
|
|
|
Options->isldepcompact = PlutoIslDepCompact;
|
|
|
|
Options->islsolve = PlutoIslSolve;
|
|
|
|
Options->l2tile = PlutoL2Tile;
|
|
|
|
Options->lastwriter = PlutoLastWriter;
|
|
|
|
Options->moredebug = PlutoMoreDebug;
|
|
|
|
Options->multipipe = PlutoParaPipe;
|
|
|
|
Options->parallel = PlutoParallel;
|
|
|
|
Options->polyunroll = PlutoPollyUnroll;
|
|
|
|
Options->rar = PlutoRar;
|
2012-08-02 15:47:26 +08:00
|
|
|
Options->tile = EnableTiling;
|
2014-03-14 07:37:48 +08:00
|
|
|
Options->unroll = PlutoUnroll;
|
2012-08-02 15:47:26 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
DEBUG(dbgs() << "Domain: " << stringFromIslObj(Domain) << "\n";
|
|
|
|
dbgs() << "Dependences: " << stringFromIslObj(Deps) << "\n";);
|
2012-08-02 15:47:26 +08:00
|
|
|
Schedule = pluto_schedule(Domain, Deps, Options);
|
|
|
|
pluto_options_free(Options);
|
|
|
|
|
|
|
|
isl_union_set_free(Domain);
|
|
|
|
isl_union_map_free(Deps);
|
|
|
|
|
2012-09-22 00:24:13 +08:00
|
|
|
if (!Schedule)
|
|
|
|
return false;
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
Schedule =
|
|
|
|
isl_union_map_apply_domain(Schedule, isl_union_map_reverse(ToPlutoNames));
|
2012-08-02 15:47:26 +08:00
|
|
|
|
|
|
|
for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
|
|
|
|
ScopStmt *Stmt = *SI;
|
|
|
|
isl_set *Domain = Stmt->getDomain();
|
|
|
|
isl_union_map *StmtBand;
|
|
|
|
StmtBand = isl_union_map_intersect_domain(isl_union_map_copy(Schedule),
|
2013-03-23 09:05:07 +08:00
|
|
|
isl_union_set_from_set(Domain));
|
2012-08-02 15:47:26 +08:00
|
|
|
isl_map *StmtSchedule;
|
|
|
|
isl_union_map_foreach_map(StmtBand, getSingleMap, &StmtSchedule);
|
|
|
|
Stmt->setScattering(StmtSchedule);
|
|
|
|
isl_union_map_free(StmtBand);
|
|
|
|
}
|
|
|
|
|
|
|
|
isl_union_map_free(Schedule);
|
|
|
|
|
|
|
|
unsigned MaxScatDims = 0;
|
|
|
|
|
|
|
|
for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
|
|
|
|
MaxScatDims = std::max((*SI)->getNumScattering(), MaxScatDims);
|
|
|
|
|
|
|
|
extendScattering(S, MaxScatDims);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
void PlutoOptimizer::printScop(raw_ostream &OS) const {}
|
2012-08-02 15:47:26 +08:00
|
|
|
|
|
|
|
void PlutoOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
ScopPass::getAnalysisUsage(AU);
|
|
|
|
AU.addRequired<Dependences>();
|
|
|
|
}
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
Pass *polly::createPlutoOptimizerPass() { return new PlutoOptimizer(); }
|
|
|
|
|
2012-08-02 15:47:26 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(PlutoOptimizer, "polly-opt-pluto",
|
2013-03-23 09:05:07 +08:00
|
|
|
"Polly - Optimize schedule of SCoP (Pluto)", false,
|
|
|
|
false);
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(Dependences);
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(ScopInfo);
|
2012-08-02 15:47:26 +08:00
|
|
|
INITIALIZE_PASS_END(PlutoOptimizer, "polly-opt-pluto",
|
2013-03-23 09:05:07 +08:00
|
|
|
"Polly - Optimize schedule of SCoP (Pluto)", false, false)
|
2012-08-02 15:47:26 +08:00
|
|
|
|
|
|
|
#endif // PLUTO_FOUND
|