2011-04-29 14:27:02 +08:00
|
|
|
//===---- CodePreparation.cpp - Code preparation for Scop Detection -------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
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
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "polly/LinkAllPasses.h"
|
2015-05-09 17:13:42 +08:00
|
|
|
#include "polly/ScopDetection.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#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"
|
|
|
|
#include "llvm/Transforms/Utils/Local.h"
|
|
|
|
|
|
|
|
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
|
|
|
|
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) {
|
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);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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)
|