2011-04-29 14:27:02 +08:00
|
|
|
//===---- CodePreparation.cpp - Code preparation for Scop Detection -------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-04-29 14:27:02 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2015-06-26 15:31:18 +08:00
|
|
|
// The Polly code preparation pass is executed before SCoP detection. Its
|
|
|
|
// currently only splits the entry block of the SCoP to make room for alloc
|
|
|
|
// instructions as they are generated during code generation.
|
2013-03-23 08:13:39 +08:00
|
|
|
//
|
|
|
|
// XXX: In the future, we should remove the need for this pass entirely and
|
2015-06-26 15:31:18 +08:00
|
|
|
// instead add this spitting to the code generation pass.
|
2011-04-29 14:27:02 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-03-23 08:13:39 +08:00
|
|
|
|
[Polly][PM][WIP] Polly pass registration
Summary:
This patch is a first attempt at registering Polly passes with the LLVM tools. Tool plugins are still unsupported, but this registration is usable from the tools if Polly is linked into them (albeit requiring minimal patches to those tools). Registration requires a small amount of machinery (the owning analysis proxies), necessary for injecting ScopAnalysisManager objects into the calling tools.
This patch is marked WIP because the registration is incomplete. Parsing manual pipelines is fully supported, but default pass injection into the O3 pipeline is lacking, mostly because there is opportunity for some redesign here, I believe. The first point of order would be insertion points. I think it makes sense to run before the vectorizers. Running Polly Early, however, is weird. Mostly because it actually is the default (which to me is unexpected), and because Polly runs it's own O1 pipeline. Why not instead insert it at an appropriate place somewhere after simplification happend? Running after the loop optimizers seems intuitive, but it also seems wasteful, since multiple consecutive loops might well be a single scop, and we don't need to run for all of them.
My second request for comments would be regarding all those smallish helper passes we have, like PollyViewer, PollyPrinter, PollyImportJScop. Right now these are controlled by command line options, deciding whether they should be part of the Polly pipeline. What is your opinion on treating them like real passes, and have the user write an appropriate pipeline if they want to use any of them?
Reviewers: grosser, Meinersbur, bollu
Reviewed By: grosser
Subscribers: llvm-commits, pollydev
Tags: #polly
Differential Revision: https://reviews.llvm.org/D35458
llvm-svn: 309826
2017-08-02 23:52:25 +08:00
|
|
|
#include "polly/CodePreparation.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "polly/LinkAllPasses.h"
|
|
|
|
#include "polly/Support/ScopHelper.h"
|
2014-07-20 02:40:17 +08:00
|
|
|
#include "llvm/Analysis/DominanceFrontier.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
|
|
#include "llvm/Analysis/RegionInfo.h"
|
|
|
|
#include "llvm/Analysis/ScalarEvolution.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace polly;
|
|
|
|
|
|
|
|
namespace {
|
2014-04-02 00:01:33 +08:00
|
|
|
|
2016-09-02 14:33:33 +08:00
|
|
|
/// Prepare the IR for the scop detection.
|
2011-04-29 14:27:02 +08:00
|
|
|
///
|
2011-10-08 08:30:40 +08:00
|
|
|
class CodePreparation : public FunctionPass {
|
2015-02-16 07:40:18 +08:00
|
|
|
CodePreparation(const CodePreparation &) = delete;
|
2015-02-16 14:40:23 +08:00
|
|
|
const CodePreparation &operator=(const CodePreparation &) = delete;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
LoopInfo *LI;
|
2013-03-21 06:41:53 +08:00
|
|
|
ScalarEvolution *SE;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
explicit CodePreparation() : FunctionPass(ID) {}
|
|
|
|
~CodePreparation();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
/// @name FunctionPass interface.
|
|
|
|
//@{
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
virtual void releaseMemory();
|
|
|
|
virtual bool runOnFunction(Function &F);
|
|
|
|
virtual void print(raw_ostream &OS, const Module *) const;
|
|
|
|
//@}
|
|
|
|
};
|
2016-06-24 06:17:27 +08:00
|
|
|
} // namespace
|
2011-04-29 14:27:02 +08:00
|
|
|
|
[Polly][PM][WIP] Polly pass registration
Summary:
This patch is a first attempt at registering Polly passes with the LLVM tools. Tool plugins are still unsupported, but this registration is usable from the tools if Polly is linked into them (albeit requiring minimal patches to those tools). Registration requires a small amount of machinery (the owning analysis proxies), necessary for injecting ScopAnalysisManager objects into the calling tools.
This patch is marked WIP because the registration is incomplete. Parsing manual pipelines is fully supported, but default pass injection into the O3 pipeline is lacking, mostly because there is opportunity for some redesign here, I believe. The first point of order would be insertion points. I think it makes sense to run before the vectorizers. Running Polly Early, however, is weird. Mostly because it actually is the default (which to me is unexpected), and because Polly runs it's own O1 pipeline. Why not instead insert it at an appropriate place somewhere after simplification happend? Running after the loop optimizers seems intuitive, but it also seems wasteful, since multiple consecutive loops might well be a single scop, and we don't need to run for all of them.
My second request for comments would be regarding all those smallish helper passes we have, like PollyViewer, PollyPrinter, PollyImportJScop. Right now these are controlled by command line options, deciding whether they should be part of the Polly pipeline. What is your opinion on treating them like real passes, and have the user write an appropriate pipeline if they want to use any of them?
Reviewers: grosser, Meinersbur, bollu
Reviewed By: grosser
Subscribers: llvm-commits, pollydev
Tags: #polly
Differential Revision: https://reviews.llvm.org/D35458
llvm-svn: 309826
2017-08-02 23:52:25 +08:00
|
|
|
PreservedAnalyses CodePreparationPass::run(Function &F,
|
|
|
|
FunctionAnalysisManager &FAM) {
|
|
|
|
|
|
|
|
// Find first non-alloca instruction. Every basic block has a non-alloca
|
|
|
|
// instruction, as every well formed basic block has a terminator.
|
|
|
|
auto &EntryBlock = F.getEntryBlock();
|
|
|
|
BasicBlock::iterator I = EntryBlock.begin();
|
|
|
|
while (isa<AllocaInst>(I))
|
|
|
|
++I;
|
|
|
|
|
|
|
|
auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
|
|
|
|
auto &LI = FAM.getResult<LoopAnalysis>(F);
|
|
|
|
|
|
|
|
// splitBlock updates DT, LI and RI.
|
|
|
|
splitEntryBlockForAlloca(&EntryBlock, &DT, &LI, nullptr);
|
|
|
|
|
|
|
|
PreservedAnalyses PA;
|
|
|
|
PA.preserve<DominatorTreeAnalysis>();
|
|
|
|
PA.preserve<LoopAnalysis>();
|
|
|
|
return PA;
|
|
|
|
}
|
|
|
|
|
2013-03-23 08:13:39 +08:00
|
|
|
void CodePreparation::clear() {}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-03-23 08:13:39 +08:00
|
|
|
CodePreparation::~CodePreparation() { clear(); }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const {
|
2015-01-17 22:16:56 +08:00
|
|
|
AU.addRequired<LoopInfoWrapperPass>();
|
2015-08-17 18:57:08 +08:00
|
|
|
AU.addRequired<ScalarEvolutionWrapperPass>();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-01-17 22:16:56 +08:00
|
|
|
AU.addPreserved<LoopInfoWrapperPass>();
|
2014-07-20 02:40:17 +08:00
|
|
|
AU.addPreserved<RegionInfoPass>();
|
2014-01-14 06:29:56 +08:00
|
|
|
AU.addPreserved<DominatorTreeWrapperPass>();
|
2016-02-26 01:54:42 +08:00
|
|
|
AU.addPreserved<DominanceFrontierWrapperPass>();
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
bool CodePreparation::runOnFunction(Function &F) {
|
2017-06-02 05:29:05 +08:00
|
|
|
if (skipFunction(F))
|
|
|
|
return false;
|
|
|
|
|
2015-01-17 22:16:56 +08:00
|
|
|
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
2015-08-17 18:57:08 +08:00
|
|
|
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
splitEntryBlockForAlloca(&F.getEntryBlock(), this);
|
|
|
|
|
2017-06-02 05:29:05 +08:00
|
|
|
return true;
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-03-23 08:13:39 +08:00
|
|
|
void CodePreparation::releaseMemory() { clear(); }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-03-23 08:13:39 +08:00
|
|
|
void CodePreparation::print(raw_ostream &OS, const Module *) const {}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
char CodePreparation::ID = 0;
|
|
|
|
char &polly::CodePreparationID = CodePreparation::ID;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-03-23 08:13:39 +08:00
|
|
|
Pass *polly::createCodePreparationPass() { return new CodePreparation(); }
|
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(CodePreparation, "polly-prepare",
|
2013-04-10 14:55:45 +08:00
|
|
|
"Polly - Prepare code for polly", false, false)
|
2015-01-17 22:16:56 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
2011-10-08 08:30:40 +08:00
|
|
|
INITIALIZE_PASS_END(CodePreparation, "polly-prepare",
|
2013-03-23 08:13:39 +08:00
|
|
|
"Polly - Prepare code for polly", false, false)
|