2017-08-25 05:22:41 +08:00
|
|
|
//===- CodeGeneration.cpp - Code generate the Scops using ISL. ---------======//
|
2012-05-08 00:20:07 +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
|
2012-05-08 00:20:07 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2015-05-12 15:45:52 +08:00
|
|
|
// The CodeGeneration pass takes a Scop created by ScopInfo and translates it
|
2012-05-08 00:20:07 +08:00
|
|
|
// back to LLVM-IR using the ISL code generator.
|
|
|
|
//
|
2017-06-08 20:06:15 +08:00
|
|
|
// The Scop describes the high level memory behavior of a control flow region.
|
2012-05-08 00:20:07 +08:00
|
|
|
// Transformation passes can update the schedule (execution order) of statements
|
|
|
|
// in the Scop. ISL is used to generate an abstract syntax tree that reflects
|
|
|
|
// the updated execution order. This clast is used to create new LLVM-IR that is
|
|
|
|
// computationally equivalent to the original control flow region, but executes
|
2015-04-21 19:37:25 +08:00
|
|
|
// its code in the new execution order defined by the changed schedule.
|
2012-05-08 00:20:07 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-04-27 20:17:22 +08:00
|
|
|
|
2017-05-23 18:18:12 +08:00
|
|
|
#include "polly/CodeGen/CodeGeneration.h"
|
2017-08-25 05:22:41 +08:00
|
|
|
#include "polly/CodeGen/IRBuilder.h"
|
2013-05-07 16:11:54 +08:00
|
|
|
#include "polly/CodeGen/IslAst.h"
|
2015-12-21 20:38:56 +08:00
|
|
|
#include "polly/CodeGen/IslNodeBuilder.h"
|
2017-04-03 22:55:37 +08:00
|
|
|
#include "polly/CodeGen/PerfMonitor.h"
|
2012-10-03 03:50:43 +08:00
|
|
|
#include "polly/CodeGen/Utils.h"
|
2015-03-05 06:43:40 +08:00
|
|
|
#include "polly/DependenceInfo.h"
|
2013-05-07 16:11:54 +08:00
|
|
|
#include "polly/LinkAllPasses.h"
|
2016-02-19 19:07:12 +08:00
|
|
|
#include "polly/Options.h"
|
2013-05-07 16:11:54 +08:00
|
|
|
#include "polly/ScopInfo.h"
|
2013-04-10 14:55:31 +08:00
|
|
|
#include "polly/Support/ScopHelper.h"
|
2017-08-25 05:22:41 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2017-05-23 18:18:12 +08:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
2017-08-25 05:22:41 +08:00
|
|
|
#include "llvm/Analysis/RegionInfo.h"
|
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
|
|
#include "llvm/IR/Dominators.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2017-05-23 18:18:12 +08:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2015-09-25 17:49:19 +08:00
|
|
|
#include "llvm/IR/Verifier.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"
|
2015-09-25 17:49:19 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2017-08-25 05:22:41 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "isl/ast.h"
|
|
|
|
#include <cassert>
|
2012-10-03 03:50:43 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
2017-08-25 05:22:41 +08:00
|
|
|
using namespace polly;
|
2012-10-03 03:50:43 +08:00
|
|
|
|
2015-05-12 15:45:52 +08:00
|
|
|
#define DEBUG_TYPE "polly-codegen"
|
2014-04-22 11:30:19 +08:00
|
|
|
|
2016-02-19 19:07:12 +08:00
|
|
|
static cl::opt<bool> Verify("polly-codegen-verify",
|
|
|
|
cl::desc("Verify the function generated by Polly"),
|
2017-04-29 03:15:28 +08:00
|
|
|
cl::Hidden, cl::init(false), cl::ZeroOrMore,
|
2016-02-19 19:07:12 +08:00
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
2017-08-21 19:44:01 +08:00
|
|
|
bool polly::PerfMonitoring;
|
2017-08-25 05:22:41 +08:00
|
|
|
|
2017-08-21 19:44:01 +08:00
|
|
|
static cl::opt<bool, true>
|
|
|
|
XPerfMonitoring("polly-codegen-perf-monitoring",
|
|
|
|
cl::desc("Add run-time performance monitoring"), cl::Hidden,
|
|
|
|
cl::location(polly::PerfMonitoring), cl::init(false),
|
|
|
|
cl::ZeroOrMore, cl::cat(PollyCategory));
|
2017-04-03 22:55:37 +08:00
|
|
|
|
2017-08-23 21:50:30 +08:00
|
|
|
STATISTIC(ScopsProcessed, "Number of SCoP processed");
|
|
|
|
STATISTIC(CodegenedScops, "Number of successfully generated SCoPs");
|
|
|
|
STATISTIC(CodegenedAffineLoops,
|
|
|
|
"Number of original affine loops in SCoPs that have been generated");
|
|
|
|
STATISTIC(CodegenedBoxedLoops,
|
|
|
|
"Number of original boxed loops in SCoPs that have been generated");
|
|
|
|
|
2017-08-08 20:00:59 +08:00
|
|
|
namespace polly {
|
2017-08-25 05:22:41 +08:00
|
|
|
|
2017-08-08 20:00:59 +08:00
|
|
|
/// Mark a basic block unreachable.
|
|
|
|
///
|
|
|
|
/// Marks the basic block @p Block unreachable by equipping it with an
|
|
|
|
/// UnreachableInst.
|
|
|
|
void markBlockUnreachable(BasicBlock &Block, PollyIRBuilder &Builder) {
|
|
|
|
auto *OrigTerminator = Block.getTerminator();
|
|
|
|
Builder.SetInsertPoint(OrigTerminator);
|
|
|
|
Builder.CreateUnreachable();
|
|
|
|
OrigTerminator->eraseFromParent();
|
|
|
|
}
|
|
|
|
} // namespace polly
|
|
|
|
|
2017-05-23 18:18:12 +08:00
|
|
|
static void verifyGeneratedFunction(Scop &S, Function &F, IslAstInfo &AI) {
|
|
|
|
if (!Verify || !verifyFunction(F, &errs()))
|
|
|
|
return;
|
|
|
|
|
2018-05-15 21:37:17 +08:00
|
|
|
LLVM_DEBUG({
|
2017-05-23 18:18:12 +08:00
|
|
|
errs() << "== ISL Codegen created an invalid function ==\n\n== The "
|
|
|
|
"SCoP ==\n";
|
2017-07-21 23:35:53 +08:00
|
|
|
errs() << S;
|
2017-05-23 18:18:12 +08:00
|
|
|
errs() << "\n== The isl AST ==\n";
|
|
|
|
AI.print(errs());
|
|
|
|
errs() << "\n== The invalid function ==\n";
|
|
|
|
F.print(errs());
|
|
|
|
});
|
|
|
|
|
|
|
|
llvm_unreachable("Polly generated function could not be verified. Add "
|
|
|
|
"-polly-codegen-verify=false to disable this assertion.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// CodeGeneration adds a lot of BBs without updating the RegionInfo
|
|
|
|
// We make all created BBs belong to the scop's parent region without any
|
|
|
|
// nested structure to keep the RegionInfo verifier happy.
|
|
|
|
static void fixRegionInfo(Function &F, Region &ParentRegion, RegionInfo &RI) {
|
|
|
|
for (BasicBlock &BB : F) {
|
|
|
|
if (RI.getRegionFor(&BB))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
RI.setRegionFor(&BB, &ParentRegion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Remove all lifetime markers (llvm.lifetime.start, llvm.lifetime.end) from
|
|
|
|
/// @R.
|
|
|
|
///
|
|
|
|
/// CodeGeneration does not copy lifetime markers into the optimized SCoP,
|
|
|
|
/// which would leave the them only in the original path. This can transform
|
|
|
|
/// code such as
|
|
|
|
///
|
|
|
|
/// llvm.lifetime.start(%p)
|
|
|
|
/// llvm.lifetime.end(%p)
|
|
|
|
///
|
|
|
|
/// into
|
|
|
|
///
|
|
|
|
/// if (RTC) {
|
|
|
|
/// // generated code
|
|
|
|
/// } else {
|
|
|
|
/// // original code
|
|
|
|
/// llvm.lifetime.start(%p)
|
|
|
|
/// }
|
|
|
|
/// llvm.lifetime.end(%p)
|
|
|
|
///
|
|
|
|
/// The current StackColoring algorithm cannot handle if some, but not all,
|
|
|
|
/// paths from the end marker to the entry block cross the start marker. Same
|
|
|
|
/// for start markers that do not always cross the end markers. We avoid any
|
|
|
|
/// issues by removing all lifetime markers, even from the original code.
|
|
|
|
///
|
|
|
|
/// A better solution could be to hoist all llvm.lifetime.start to the split
|
|
|
|
/// node and all llvm.lifetime.end to the merge node, which should be
|
|
|
|
/// conservatively correct.
|
|
|
|
static void removeLifetimeMarkers(Region *R) {
|
|
|
|
for (auto *BB : R->blocks()) {
|
|
|
|
auto InstIt = BB->begin();
|
|
|
|
auto InstEnd = BB->end();
|
|
|
|
|
|
|
|
while (InstIt != InstEnd) {
|
|
|
|
auto NextIt = InstIt;
|
|
|
|
++NextIt;
|
|
|
|
|
|
|
|
if (auto *IT = dyn_cast<IntrinsicInst>(&*InstIt)) {
|
|
|
|
switch (IT->getIntrinsicID()) {
|
2017-08-25 05:22:41 +08:00
|
|
|
case Intrinsic::lifetime_start:
|
|
|
|
case Intrinsic::lifetime_end:
|
2017-05-23 18:18:12 +08:00
|
|
|
BB->getInstList().erase(InstIt);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InstIt = NextIt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-14 01:39:23 +08:00
|
|
|
static bool generateCode(Scop &S, IslAstInfo &AI, LoopInfo &LI,
|
|
|
|
DominatorTree &DT, ScalarEvolution &SE,
|
|
|
|
RegionInfo &RI) {
|
2017-09-21 08:01:13 +08:00
|
|
|
// Check whether IslAstInfo uses the same isl_ctx. Since -polly-codegen
|
|
|
|
// reports itself to preserve DependenceInfo and IslAstInfo, we might get
|
|
|
|
// those analysis that were computed by a different ScopInfo for a different
|
|
|
|
// Scop structure. When the ScopInfo/Scop object is freed, there is a high
|
|
|
|
// probability that the new ScopInfo/Scop object will be created at the same
|
|
|
|
// heap position with the same address. Comparing whether the Scop or ScopInfo
|
|
|
|
// address is the expected therefore is unreliable.
|
|
|
|
// Instead, we compare the address of the isl_ctx object. Both, DependenceInfo
|
|
|
|
// and IslAstInfo must hold a reference to the isl_ctx object to ensure it is
|
|
|
|
// not freed before the destruction of those analyses which might happen after
|
|
|
|
// the destruction of the Scop/ScopInfo they refer to. Hence, the isl_ctx
|
|
|
|
// will not be freed and its space not reused as long there is a
|
|
|
|
// DependenceInfo or IslAstInfo around.
|
|
|
|
IslAst &Ast = AI.getIslAst();
|
|
|
|
if (Ast.getSharedIslCtx() != S.getSharedIslCtx()) {
|
2018-05-15 21:37:17 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Got an IstAst for a different Scop/isl_ctx\n");
|
2017-09-21 08:01:13 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:18:12 +08:00
|
|
|
// Check if we created an isl_ast root node, otherwise exit.
|
2021-04-16 12:34:57 +08:00
|
|
|
isl::ast_node AstRoot = Ast.getAst();
|
|
|
|
if (AstRoot.is_null())
|
2017-05-23 18:18:12 +08:00
|
|
|
return false;
|
|
|
|
|
2017-08-23 21:50:30 +08:00
|
|
|
// Collect statistics. Do it before we modify the IR to avoid having it any
|
|
|
|
// influence on the result.
|
|
|
|
auto ScopStats = S.getStatistics();
|
|
|
|
ScopsProcessed++;
|
|
|
|
|
2017-05-23 18:18:12 +08:00
|
|
|
auto &DL = S.getFunction().getParent()->getDataLayout();
|
|
|
|
Region *R = &S.getRegion();
|
|
|
|
assert(!R->isTopLevelRegion() && "Top level regions are not supported");
|
|
|
|
|
|
|
|
ScopAnnotator Annotator;
|
|
|
|
|
|
|
|
simplifyRegion(R, &DT, &LI, &RI);
|
|
|
|
assert(R->isSimple());
|
|
|
|
BasicBlock *EnteringBB = S.getEnteringBlock();
|
|
|
|
assert(EnteringBB);
|
2020-02-18 02:01:18 +08:00
|
|
|
PollyIRBuilder Builder(EnteringBB->getContext(), ConstantFolder(),
|
|
|
|
IRInserter(Annotator));
|
|
|
|
Builder.SetInsertPoint(EnteringBB->getTerminator());
|
2017-05-23 18:18:12 +08:00
|
|
|
|
|
|
|
// Only build the run-time condition and parameters _after_ having
|
|
|
|
// introduced the conditional branch. This is important as the conditional
|
|
|
|
// branch will guard the original scop from new induction variables that
|
|
|
|
// the SCEVExpander may introduce while code generating the parameters and
|
|
|
|
// which may introduce scalar dependences that prevent us from correctly
|
|
|
|
// code generating this scop.
|
2017-06-26 20:17:11 +08:00
|
|
|
BBPair StartExitBlocks =
|
2017-07-14 18:00:25 +08:00
|
|
|
std::get<0>(executeScopConditionally(S, Builder.getTrue(), DT, RI, LI));
|
2017-06-26 20:17:11 +08:00
|
|
|
BasicBlock *StartBlock = std::get<0>(StartExitBlocks);
|
2017-06-27 19:33:22 +08:00
|
|
|
BasicBlock *ExitBlock = std::get<1>(StartExitBlocks);
|
2017-06-26 20:17:11 +08:00
|
|
|
|
2017-05-23 18:18:12 +08:00
|
|
|
removeLifetimeMarkers(R);
|
|
|
|
auto *SplitBlock = StartBlock->getSinglePredecessor();
|
|
|
|
|
|
|
|
IslNodeBuilder NodeBuilder(Builder, Annotator, DL, LI, SE, DT, S, StartBlock);
|
|
|
|
|
2017-06-19 18:19:29 +08:00
|
|
|
// All arrays must have their base pointers known before
|
|
|
|
// ScopAnnotator::buildAliasScopes.
|
2017-06-28 21:02:43 +08:00
|
|
|
NodeBuilder.allocateNewArrays(StartExitBlocks);
|
2017-06-19 18:19:29 +08:00
|
|
|
Annotator.buildAliasScopes(S);
|
|
|
|
|
2017-05-23 18:18:12 +08:00
|
|
|
if (PerfMonitoring) {
|
2017-06-02 16:01:22 +08:00
|
|
|
PerfMonitor P(S, EnteringBB->getParent()->getParent());
|
2017-05-23 18:18:12 +08:00
|
|
|
P.initialize();
|
|
|
|
P.insertRegionStart(SplitBlock->getTerminator());
|
|
|
|
|
2017-06-27 19:33:22 +08:00
|
|
|
BasicBlock *MergeBlock = ExitBlock->getUniqueSuccessor();
|
2017-05-23 18:18:12 +08:00
|
|
|
P.insertRegionEnd(MergeBlock->getTerminator());
|
|
|
|
}
|
|
|
|
|
|
|
|
// First generate code for the hoisted invariant loads and transitively the
|
|
|
|
// parameters they reference. Afterwards, for the remaining parameters that
|
|
|
|
// might reference the hoisted loads. Finally, build the runtime check
|
|
|
|
// that might reference both hoisted loads as well as parameters.
|
|
|
|
// If the hoisting fails we have to bail and execute the original code.
|
|
|
|
Builder.SetInsertPoint(SplitBlock->getTerminator());
|
|
|
|
if (!NodeBuilder.preloadInvariantLoads()) {
|
|
|
|
// Patch the introduced branch condition to ensure that we always execute
|
|
|
|
// the original SCoP.
|
|
|
|
auto *FalseI1 = Builder.getFalse();
|
|
|
|
auto *SplitBBTerm = Builder.GetInsertBlock()->getTerminator();
|
|
|
|
SplitBBTerm->setOperand(0, FalseI1);
|
|
|
|
|
|
|
|
// Since the other branch is hence ignored we mark it as unreachable and
|
|
|
|
// adjust the dominator tree accordingly.
|
|
|
|
auto *ExitingBlock = StartBlock->getUniqueSuccessor();
|
|
|
|
assert(ExitingBlock);
|
|
|
|
auto *MergeBlock = ExitingBlock->getUniqueSuccessor();
|
|
|
|
assert(MergeBlock);
|
|
|
|
markBlockUnreachable(*StartBlock, Builder);
|
|
|
|
markBlockUnreachable(*ExitingBlock, Builder);
|
|
|
|
auto *ExitingBB = S.getExitingBlock();
|
|
|
|
assert(ExitingBB);
|
|
|
|
DT.changeImmediateDominator(MergeBlock, ExitingBB);
|
|
|
|
DT.eraseNode(ExitingBlock);
|
|
|
|
} else {
|
2017-08-07 03:52:38 +08:00
|
|
|
NodeBuilder.addParameters(S.getContext().release());
|
2021-04-16 12:34:57 +08:00
|
|
|
Value *RTC = NodeBuilder.createRTC(AI.getRunCondition().release());
|
2017-05-23 18:18:12 +08:00
|
|
|
|
|
|
|
Builder.GetInsertBlock()->getTerminator()->setOperand(0, RTC);
|
2017-06-28 21:02:43 +08:00
|
|
|
|
|
|
|
// Explicitly set the insert point to the end of the block to avoid that a
|
|
|
|
// split at the builder's current
|
|
|
|
// insert position would move the malloc calls to the wrong BasicBlock.
|
|
|
|
// Ideally we would just split the block during allocation of the new
|
|
|
|
// arrays, but this would break the assumption that there are no blocks
|
|
|
|
// between polly.start and polly.exiting (at this point).
|
|
|
|
Builder.SetInsertPoint(StartBlock->getTerminator());
|
2017-05-23 18:18:12 +08:00
|
|
|
|
2021-04-16 12:34:57 +08:00
|
|
|
NodeBuilder.create(AstRoot.release());
|
2017-05-23 18:18:12 +08:00
|
|
|
NodeBuilder.finalize();
|
|
|
|
fixRegionInfo(*EnteringBB->getParent(), *R->getParent(), RI);
|
2017-08-23 21:50:30 +08:00
|
|
|
|
|
|
|
CodegenedScops++;
|
|
|
|
CodegenedAffineLoops += ScopStats.NumAffineLoops;
|
|
|
|
CodegenedBoxedLoops += ScopStats.NumBoxedLoops;
|
2017-05-23 18:18:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Function *F = EnteringBB->getParent();
|
|
|
|
verifyGeneratedFunction(S, *F, AI);
|
|
|
|
for (auto *SubF : NodeBuilder.getParallelSubfunctions())
|
|
|
|
verifyGeneratedFunction(S, *SubF, AI);
|
|
|
|
|
|
|
|
// Mark the function such that we run additional cleanup passes on this
|
|
|
|
// function (e.g. mem2reg to rediscover phi nodes).
|
|
|
|
F->addFnAttr("polly-optimized");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-25 05:22:41 +08:00
|
|
|
namespace {
|
|
|
|
|
2015-05-12 15:45:52 +08:00
|
|
|
class CodeGeneration : public ScopPass {
|
2012-12-30 07:47:38 +08:00
|
|
|
public:
|
2012-10-03 03:50:43 +08:00
|
|
|
static char ID;
|
|
|
|
|
2017-06-08 20:06:15 +08:00
|
|
|
/// The data layout used.
|
2014-11-16 05:32:53 +08:00
|
|
|
const DataLayout *DL;
|
|
|
|
|
2014-09-10 22:50:23 +08:00
|
|
|
/// @name The analysis passes we need to generate code.
|
|
|
|
///
|
|
|
|
///{
|
|
|
|
LoopInfo *LI;
|
|
|
|
IslAstInfo *AI;
|
|
|
|
DominatorTree *DT;
|
|
|
|
ScalarEvolution *SE;
|
2015-08-11 22:39:21 +08:00
|
|
|
RegionInfo *RI;
|
2014-09-10 22:50:23 +08:00
|
|
|
///}
|
|
|
|
|
2017-08-25 05:22:41 +08:00
|
|
|
CodeGeneration() : ScopPass(ID) {}
|
|
|
|
|
2016-09-02 14:33:33 +08:00
|
|
|
/// Generate LLVM-IR for the SCoP @p S.
|
2015-03-02 02:42:08 +08:00
|
|
|
bool runOnScop(Scop &S) override {
|
2017-07-01 03:42:21 +08:00
|
|
|
// Skip SCoPs in case they're already code-generated by PPCGCodeGeneration.
|
|
|
|
if (S.isToBeSkipped())
|
|
|
|
return false;
|
|
|
|
|
2017-05-23 18:12:56 +08:00
|
|
|
AI = &getAnalysis<IslAstInfoWrapperPass>().getAI();
|
2015-02-12 01:25:09 +08:00
|
|
|
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
2014-09-10 22:50:23 +08:00
|
|
|
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
2015-08-17 18:57:08 +08:00
|
|
|
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
2016-05-23 20:38:05 +08:00
|
|
|
DL = &S.getFunction().getParent()->getDataLayout();
|
2015-08-11 22:39:21 +08:00
|
|
|
RI = &getAnalysis<RegionInfoPass>().getRegionInfo();
|
2021-08-14 01:39:23 +08:00
|
|
|
return generateCode(S, *AI, *LI, *DT, *SE, *RI);
|
2012-10-03 03:50:43 +08:00
|
|
|
}
|
|
|
|
|
2016-09-02 14:33:33 +08:00
|
|
|
/// Register all analyses and transformation required.
|
2015-03-02 02:42:08 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2017-08-28 22:07:33 +08:00
|
|
|
ScopPass::getAnalysisUsage(AU);
|
|
|
|
|
2014-01-14 06:29:56 +08:00
|
|
|
AU.addRequired<DominatorTreeWrapperPass>();
|
2017-05-23 18:12:56 +08:00
|
|
|
AU.addRequired<IslAstInfoWrapperPass>();
|
2014-07-20 02:40:17 +08:00
|
|
|
AU.addRequired<RegionInfoPass>();
|
2015-08-17 18:57:08 +08:00
|
|
|
AU.addRequired<ScalarEvolutionWrapperPass>();
|
2017-05-12 22:37:29 +08:00
|
|
|
AU.addRequired<ScopDetectionWrapperPass>();
|
2016-05-31 17:41:04 +08:00
|
|
|
AU.addRequired<ScopInfoRegionPass>();
|
2015-01-17 22:16:56 +08:00
|
|
|
AU.addRequired<LoopInfoWrapperPass>();
|
2012-10-03 03:50:43 +08:00
|
|
|
|
2015-03-05 06:43:40 +08:00
|
|
|
AU.addPreserved<DependenceInfo>();
|
2017-05-23 18:12:56 +08:00
|
|
|
AU.addPreserved<IslAstInfoWrapperPass>();
|
2012-10-03 03:50:43 +08:00
|
|
|
|
|
|
|
// FIXME: We do not yet add regions for the newly generated code to the
|
|
|
|
// region tree.
|
|
|
|
}
|
|
|
|
};
|
2016-06-24 06:17:27 +08:00
|
|
|
} // namespace
|
2012-10-03 03:50:43 +08:00
|
|
|
|
2017-08-25 05:22:41 +08:00
|
|
|
PreservedAnalyses CodeGenerationPass::run(Scop &S, ScopAnalysisManager &SAM,
|
|
|
|
ScopStandardAnalysisResults &AR,
|
|
|
|
SPMUpdater &U) {
|
2017-05-23 18:18:12 +08:00
|
|
|
auto &AI = SAM.getResult<IslAstAnalysis>(S, AR);
|
2021-08-14 01:39:23 +08:00
|
|
|
if (generateCode(S, AI, AR.LI, AR.DT, AR.SE, AR.RI)) {
|
2017-08-10 15:43:46 +08:00
|
|
|
U.invalidateScop(S);
|
2017-05-23 18:18:12 +08:00
|
|
|
return PreservedAnalyses::none();
|
2017-08-10 15:43:46 +08:00
|
|
|
}
|
2017-05-23 18:18:12 +08:00
|
|
|
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|
|
|
|
|
2015-05-12 15:45:52 +08:00
|
|
|
char CodeGeneration::ID = 1;
|
2012-10-03 03:50:43 +08:00
|
|
|
|
2015-05-12 15:45:52 +08:00
|
|
|
Pass *polly::createCodeGenerationPass() { return new CodeGeneration(); }
|
2013-02-22 16:07:06 +08:00
|
|
|
|
2015-05-12 15:45:52 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(CodeGeneration, "polly-codegen",
|
2013-02-22 16:07:06 +08:00
|
|
|
"Polly - Create LLVM-IR from SCoPs", false, false);
|
2015-03-05 06:43:40 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
|
2014-01-14 06:29:56 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass);
|
2015-01-17 22:16:56 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
|
2014-07-20 02:40:17 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
|
2015-08-17 18:57:08 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass);
|
2017-05-12 22:37:29 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(ScopDetectionWrapperPass);
|
2015-05-12 15:45:52 +08:00
|
|
|
INITIALIZE_PASS_END(CodeGeneration, "polly-codegen",
|
2013-02-22 16:07:06 +08:00
|
|
|
"Polly - Create LLVM-IR from SCoPs", false, false)
|