2016-06-23 00:29:33 +08:00
|
|
|
//===---- Canonicalization.cpp - Run canonicalization passes --------------===//
|
2014-01-03 07:39:18 +08:00
|
|
|
//
|
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
|
2014-01-03 07:39:18 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Run the set of default canonicalization passes.
|
|
|
|
//
|
|
|
|
// This pass is mainly used for debugging.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "polly/Canonicalization.h"
|
2015-12-21 20:38:56 +08:00
|
|
|
#include "polly/LinkAllPasses.h"
|
2015-10-15 20:17:36 +08:00
|
|
|
#include "polly/Options.h"
|
2019-03-29 04:19:49 +08:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
2015-10-13 04:03:44 +08:00
|
|
|
#include "llvm/Transforms/IPO.h"
|
2018-04-24 10:23:41 +08:00
|
|
|
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
2015-10-15 20:17:36 +08:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2018-03-29 03:56:26 +08:00
|
|
|
#include "llvm/Transforms/Utils.h"
|
2014-01-03 07:39:18 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace polly;
|
|
|
|
|
2015-10-13 04:03:44 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
PollyInliner("polly-run-inliner",
|
|
|
|
cl::desc("Run an early inliner pass before Polly"), cl::Hidden,
|
|
|
|
cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
|
|
|
|
|
2015-02-13 17:51:50 +08:00
|
|
|
void polly::registerCanonicalicationPasses(llvm::legacy::PassManagerBase &PM) {
|
2017-08-19 16:44:46 +08:00
|
|
|
bool UseMemSSA = true;
|
Add rewrite by-reference parameter pass
Summary:
This pass detangles induction variables from functions, which take variables by
reference. Most fortran functions compiled with gfortran pass variables by
reference. Unfortunately a common pattern, printf calls of induction variables,
prevent in this situation the promotion of the induction variable to a register,
which again inhibits any kind of loop analysis. To work around this issue
we developed a specialized pass which introduces separate alloca slots for
known-read-only references, which indicate the mem2reg pass that the induction
variables can be promoted to registers and consquently enable SCEV to work.
We currently hardcode the information that a function
_gfortran_transfer_integer_write does not read its second parameter, as
dragonegg does not add the right annotations and we cannot change old dragonegg
releases. Hopefully flang will produce the right annotations.
Reviewers: Meinersbur, bollu, singam-sanjay
Reviewed By: bollu
Subscribers: mgorny, pollydev, llvm-commits
Tags: #polly
Differential Revision: https://reviews.llvm.org/D36800
llvm-svn: 311066
2017-08-17 13:25:08 +08:00
|
|
|
PM.add(polly::createRewriteByrefParamsPass());
|
2014-01-03 07:39:18 +08:00
|
|
|
PM.add(llvm::createPromoteMemoryToRegisterPass());
|
2017-08-19 16:44:46 +08:00
|
|
|
PM.add(llvm::createEarlyCSEPass(UseMemSSA));
|
2014-01-03 07:39:18 +08:00
|
|
|
PM.add(llvm::createInstructionCombiningPass());
|
|
|
|
PM.add(llvm::createCFGSimplificationPass());
|
|
|
|
PM.add(llvm::createTailCallEliminationPass());
|
|
|
|
PM.add(llvm::createCFGSimplificationPass());
|
|
|
|
PM.add(llvm::createReassociatePass());
|
|
|
|
PM.add(llvm::createLoopRotatePass());
|
2015-10-13 04:03:44 +08:00
|
|
|
if (PollyInliner) {
|
|
|
|
PM.add(llvm::createFunctionInliningPass(200));
|
2016-12-03 01:43:57 +08:00
|
|
|
PM.add(llvm::createPromoteMemoryToRegisterPass());
|
2015-10-13 04:03:44 +08:00
|
|
|
PM.add(llvm::createCFGSimplificationPass());
|
|
|
|
PM.add(llvm::createInstructionCombiningPass());
|
|
|
|
PM.add(createBarrierNoopPass());
|
|
|
|
}
|
2014-01-03 07:39:18 +08:00
|
|
|
PM.add(llvm::createInstructionCombiningPass());
|
2015-05-30 14:16:41 +08:00
|
|
|
PM.add(llvm::createIndVarSimplifyPass());
|
2014-01-03 07:39:18 +08:00
|
|
|
PM.add(polly::createCodePreparationPass());
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class PollyCanonicalize : public ModulePass {
|
2015-02-16 07:40:18 +08:00
|
|
|
PollyCanonicalize(const PollyCanonicalize &) = delete;
|
2015-02-16 14:40:23 +08:00
|
|
|
const PollyCanonicalize &operator=(const PollyCanonicalize &) = delete;
|
2014-01-03 07:39:18 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
explicit PollyCanonicalize() : ModulePass(ID) {}
|
|
|
|
~PollyCanonicalize();
|
|
|
|
|
|
|
|
/// @name FunctionPass interface.
|
|
|
|
//@{
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
virtual void releaseMemory();
|
|
|
|
virtual bool runOnModule(Module &M);
|
|
|
|
virtual void print(raw_ostream &OS, const Module *) const;
|
|
|
|
//@}
|
|
|
|
};
|
2016-06-24 06:17:27 +08:00
|
|
|
} // namespace
|
2014-01-03 07:39:18 +08:00
|
|
|
|
|
|
|
PollyCanonicalize::~PollyCanonicalize() {}
|
|
|
|
|
|
|
|
void PollyCanonicalize::getAnalysisUsage(AnalysisUsage &AU) const {}
|
|
|
|
|
|
|
|
void PollyCanonicalize::releaseMemory() {}
|
|
|
|
|
|
|
|
bool PollyCanonicalize::runOnModule(Module &M) {
|
2015-02-13 17:51:50 +08:00
|
|
|
legacy::PassManager PM;
|
2014-01-03 07:39:18 +08:00
|
|
|
registerCanonicalicationPasses(PM);
|
|
|
|
PM.run(M);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PollyCanonicalize::print(raw_ostream &OS, const Module *) const {}
|
|
|
|
|
|
|
|
char PollyCanonicalize::ID = 0;
|
|
|
|
|
|
|
|
Pass *polly::createPollyCanonicalizePass() { return new PollyCanonicalize(); }
|
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(PollyCanonicalize, "polly-canonicalize",
|
|
|
|
"Polly - Run canonicalization passes", false, false)
|
|
|
|
INITIALIZE_PASS_END(PollyCanonicalize, "polly-canonicalize",
|
|
|
|
"Polly - Run canonicalization passes", false, false)
|