2010-05-07 17:40:13 +02:00
|
|
|
//===-- Sink.cpp - Code Sinking -------------------------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01: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
|
2010-05-07 17:40:13 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This pass moves instructions into successor blocks, when possible, so that
|
|
|
|
// they aren't executed on paths where their results aren't needed.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-04-22 21:54:10 +02:00
|
|
|
#include "llvm/Transforms/Scalar/Sink.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2010-05-07 17:40:13 +02:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
2011-12-15 00:49:11 +01:00
|
|
|
#include "llvm/Analysis/ValueTracking.h"
|
2014-03-04 12:45:46 +01:00
|
|
|
#include "llvm/IR/CFG.h"
|
2014-07-10 18:07:11 +02:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-01-13 10:26:24 +01:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
2015-03-04 19:43:29 +01:00
|
|
|
#include "llvm/IR/Module.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-13 22:15:01 +01:00
|
|
|
#include "llvm/InitializePasses.h"
|
2010-05-07 17:40:13 +02:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2016-04-22 21:54:10 +02:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2010-05-07 17:40:13 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 04:55:47 +02:00
|
|
|
#define DEBUG_TYPE "sink"
|
|
|
|
|
2010-05-07 17:40:13 +02:00
|
|
|
STATISTIC(NumSunk, "Number of instructions sunk");
|
2012-05-31 10:09:49 +02:00
|
|
|
STATISTIC(NumSinkIter, "Number of sinking iterations");
|
2010-05-07 17:40:13 +02:00
|
|
|
|
2016-04-22 21:54:10 +02:00
|
|
|
static bool isSafeToMove(Instruction *Inst, AliasAnalysis &AA,
|
2014-08-21 07:55:13 +02:00
|
|
|
SmallPtrSetImpl<Instruction *> &Stores) {
|
2010-05-07 17:40:13 +02:00
|
|
|
|
2011-09-01 23:21:24 +02:00
|
|
|
if (Inst->mayWriteToMemory()) {
|
|
|
|
Stores.insert(Inst);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LoadInst *L = dyn_cast<LoadInst>(Inst)) {
|
2015-06-17 09:18:54 +02:00
|
|
|
MemoryLocation Loc = MemoryLocation::get(L);
|
2014-08-25 01:23:06 +02:00
|
|
|
for (Instruction *S : Stores)
|
2017-12-05 21:12:23 +01:00
|
|
|
if (isModSet(AA.getModRefInfo(S, Loc)))
|
2010-05-07 17:40:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-26 11:51:22 +02:00
|
|
|
if (Inst->isTerminator() || isa<PHINode>(Inst) || Inst->isEHPad() ||
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 06:38:55 +01:00
|
|
|
Inst->mayThrow())
|
2010-11-11 17:20:28 +01:00
|
|
|
return false;
|
|
|
|
|
2019-01-07 06:42:51 +01:00
|
|
|
if (auto *Call = dyn_cast<CallBase>(Inst)) {
|
2016-07-11 16:11:51 +02:00
|
|
|
// Convergent operations cannot be made control-dependent on additional
|
|
|
|
// values.
|
2019-10-28 03:37:45 +01:00
|
|
|
if (Call->isConvergent())
|
2015-06-01 19:20:31 +02:00
|
|
|
return false;
|
2016-07-11 16:11:51 +02:00
|
|
|
|
|
|
|
for (Instruction *S : Stores)
|
2019-01-07 06:42:51 +01:00
|
|
|
if (isModSet(AA.getModRefInfo(S, Call)))
|
2016-07-11 16:11:51 +02:00
|
|
|
return false;
|
2015-06-01 19:20:31 +02:00
|
|
|
}
|
|
|
|
|
2010-11-11 17:20:28 +01:00
|
|
|
return true;
|
2010-05-07 17:40:13 +02:00
|
|
|
}
|
|
|
|
|
2012-05-31 10:09:49 +02:00
|
|
|
/// IsAcceptableTarget - Return true if it is possible to sink the instruction
|
|
|
|
/// in the specified basic block.
|
2016-04-22 21:54:10 +02:00
|
|
|
static bool IsAcceptableTarget(Instruction *Inst, BasicBlock *SuccToSinkTo,
|
|
|
|
DominatorTree &DT, LoopInfo &LI) {
|
2012-05-31 10:09:49 +02:00
|
|
|
assert(Inst && "Instruction to be sunk is null");
|
|
|
|
assert(SuccToSinkTo && "Candidate sink target is null");
|
2012-07-24 12:51:42 +02:00
|
|
|
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 06:38:55 +01:00
|
|
|
// It's never legal to sink an instruction into a block which terminates in an
|
|
|
|
// EH-pad.
|
2018-08-26 10:56:42 +02:00
|
|
|
if (SuccToSinkTo->getTerminator()->isExceptionalTerminator())
|
[IR] Reformulate LLVM's EH funclet IR
While we have successfully implemented a funclet-oriented EH scheme on
top of LLVM IR, our scheme has some notable deficiencies:
- catchendpad and cleanupendpad are necessary in the current design
but they are difficult to explain to others, even to seasoned LLVM
experts.
- catchendpad and cleanupendpad are optimization barriers. They cannot
be split and force all potentially throwing call-sites to be invokes.
This has a noticable effect on the quality of our code generation.
- catchpad, while similar in some aspects to invoke, is fairly awkward.
It is unsplittable, starts a funclet, and has control flow to other
funclets.
- The nesting relationship between funclets is currently a property of
control flow edges. Because of this, we are forced to carefully
analyze the flow graph to see if there might potentially exist illegal
nesting among funclets. While we have logic to clone funclets when
they are illegally nested, it would be nicer if we had a
representation which forbade them upfront.
Let's clean this up a bit by doing the following:
- Instead, make catchpad more like cleanuppad and landingpad: no control
flow, just a bunch of simple operands; catchpad would be splittable.
- Introduce catchswitch, a control flow instruction designed to model
the constraints of funclet oriented EH.
- Make funclet scoping explicit by having funclet instructions consume
the token produced by the funclet which contains them.
- Remove catchendpad and cleanupendpad. Their presence can be inferred
implicitly using coloring information.
N.B. The state numbering code for the CLR has been updated but the
veracity of it's output cannot be spoken for. An expert should take a
look to make sure the results are reasonable.
Reviewers: rnk, JosephTremoulet, andrew.w.kaylor
Differential Revision: http://reviews.llvm.org/D15139
llvm-svn: 255422
2015-12-12 06:38:55 +01:00
|
|
|
return false;
|
|
|
|
|
2012-07-24 12:51:42 +02:00
|
|
|
// If the block has multiple predecessors, this would introduce computation
|
2012-05-31 10:09:49 +02:00
|
|
|
// on different code paths. We could split the critical edge, but for now we
|
|
|
|
// just punt.
|
|
|
|
// FIXME: Split critical edges if not backedges.
|
|
|
|
if (SuccToSinkTo->getUniquePredecessor() != Inst->getParent()) {
|
|
|
|
// We cannot sink a load across a critical edge - there may be stores in
|
|
|
|
// other code paths.
|
2018-01-11 22:28:57 +01:00
|
|
|
if (Inst->mayReadFromMemory())
|
2012-05-31 10:09:49 +02:00
|
|
|
return false;
|
2012-07-24 12:51:42 +02:00
|
|
|
|
2012-05-31 10:09:49 +02:00
|
|
|
// We don't want to sink across a critical edge if we don't dominate the
|
|
|
|
// successor. We could be introducing calculations to new code paths.
|
2016-04-22 21:54:10 +02:00
|
|
|
if (!DT.dominates(Inst->getParent(), SuccToSinkTo))
|
2012-05-31 10:09:49 +02:00
|
|
|
return false;
|
2012-07-24 12:51:42 +02:00
|
|
|
|
2012-05-31 10:09:49 +02:00
|
|
|
// Don't sink instructions into a loop.
|
2016-04-22 21:54:10 +02:00
|
|
|
Loop *succ = LI.getLoopFor(SuccToSinkTo);
|
|
|
|
Loop *cur = LI.getLoopFor(Inst->getParent());
|
2014-04-25 07:29:35 +02:00
|
|
|
if (succ != nullptr && succ != cur)
|
2012-05-31 10:09:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-24 12:51:42 +02:00
|
|
|
|
2020-08-31 07:51:00 +02:00
|
|
|
return true;
|
2012-05-31 10:09:49 +02:00
|
|
|
}
|
|
|
|
|
2010-05-07 17:40:13 +02:00
|
|
|
/// SinkInstruction - Determine whether it is safe to sink the specified machine
|
|
|
|
/// instruction out of its current block into a successor.
|
2016-04-22 21:54:10 +02:00
|
|
|
static bool SinkInstruction(Instruction *Inst,
|
|
|
|
SmallPtrSetImpl<Instruction *> &Stores,
|
|
|
|
DominatorTree &DT, LoopInfo &LI, AAResults &AA) {
|
2014-03-21 16:51:51 +01:00
|
|
|
|
|
|
|
// Don't sink static alloca instructions. CodeGen assumes allocas outside the
|
|
|
|
// entry block are dynamically sized stack objects.
|
|
|
|
if (AllocaInst *AI = dyn_cast<AllocaInst>(Inst))
|
|
|
|
if (AI->isStaticAlloca())
|
|
|
|
return false;
|
|
|
|
|
2010-05-07 17:40:13 +02:00
|
|
|
// Check if it's safe to move the instruction.
|
|
|
|
if (!isSafeToMove(Inst, AA, Stores))
|
|
|
|
return false;
|
2012-07-24 12:51:42 +02:00
|
|
|
|
2010-05-07 17:40:13 +02:00
|
|
|
// FIXME: This should include support for sinking instructions within the
|
|
|
|
// block they are currently in to shorten the live ranges. We often get
|
|
|
|
// instructions sunk into the top of a large block, but it would be better to
|
|
|
|
// also sink them down before their first use in the block. This xform has to
|
|
|
|
// be careful not to *increase* register pressure though, e.g. sinking
|
|
|
|
// "x = y + z" down if it kills y and z would increase the live ranges of y
|
|
|
|
// and z and only shrink the live range of x.
|
2012-07-24 12:51:42 +02:00
|
|
|
|
2010-05-07 17:40:13 +02:00
|
|
|
// SuccToSinkTo - This is the successor to sink this instruction to, once we
|
|
|
|
// decide.
|
2014-04-25 07:29:35 +02:00
|
|
|
BasicBlock *SuccToSinkTo = nullptr;
|
2012-07-24 12:51:42 +02:00
|
|
|
|
2020-08-31 07:51:00 +02:00
|
|
|
// Find the nearest common dominator of all users as the candidate.
|
|
|
|
BasicBlock *BB = Inst->getParent();
|
|
|
|
for (Use &U : Inst->uses()) {
|
|
|
|
Instruction *UseInst = cast<Instruction>(U.getUser());
|
|
|
|
BasicBlock *UseBlock = UseInst->getParent();
|
2020-10-10 01:20:26 +02:00
|
|
|
// Don't worry about dead users.
|
|
|
|
if (!DT.isReachableFromEntry(UseBlock))
|
|
|
|
continue;
|
2020-08-31 07:51:00 +02:00
|
|
|
if (PHINode *PN = dyn_cast<PHINode>(UseInst)) {
|
|
|
|
// PHI nodes use the operand in the predecessor block, not the block with
|
|
|
|
// the PHI.
|
|
|
|
unsigned Num = PHINode::getIncomingValueNumForOperand(U.getOperandNo());
|
|
|
|
UseBlock = PN->getIncomingBlock(Num);
|
|
|
|
}
|
|
|
|
if (SuccToSinkTo)
|
|
|
|
SuccToSinkTo = DT.findNearestCommonDominator(SuccToSinkTo, UseBlock);
|
|
|
|
else
|
|
|
|
SuccToSinkTo = UseBlock;
|
|
|
|
// The current basic block needs to dominate the candidate.
|
|
|
|
if (!DT.dominates(BB, SuccToSinkTo))
|
|
|
|
return false;
|
2012-05-31 10:09:49 +02:00
|
|
|
}
|
|
|
|
|
2020-08-31 07:51:00 +02:00
|
|
|
if (SuccToSinkTo) {
|
|
|
|
// The nearest common dominator may be in a parent loop of BB, which may not
|
|
|
|
// be beneficial. Find an ancestor.
|
|
|
|
while (SuccToSinkTo != BB &&
|
|
|
|
!IsAcceptableTarget(Inst, SuccToSinkTo, DT, LI))
|
|
|
|
SuccToSinkTo = DT.getNode(SuccToSinkTo)->getIDom()->getBlock();
|
|
|
|
if (SuccToSinkTo == BB)
|
|
|
|
SuccToSinkTo = nullptr;
|
2010-05-07 17:40:13 +02:00
|
|
|
}
|
2012-07-24 12:51:42 +02:00
|
|
|
|
2010-05-07 17:40:13 +02:00
|
|
|
// If we couldn't find a block to sink to, ignore this instruction.
|
2014-04-25 07:29:35 +02:00
|
|
|
if (!SuccToSinkTo)
|
2010-05-07 17:40:13 +02:00
|
|
|
return false;
|
2012-07-24 12:51:42 +02:00
|
|
|
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "Sink" << *Inst << " (";
|
|
|
|
Inst->getParent()->printAsOperand(dbgs(), false); dbgs() << " -> ";
|
|
|
|
SuccToSinkTo->printAsOperand(dbgs(), false); dbgs() << ")\n");
|
2012-07-24 12:51:42 +02:00
|
|
|
|
2010-05-07 17:40:13 +02:00
|
|
|
// Move the instruction.
|
2015-10-13 21:26:58 +02:00
|
|
|
Inst->moveBefore(&*SuccToSinkTo->getFirstInsertionPt());
|
2010-05-07 17:40:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-04-22 21:54:04 +02:00
|
|
|
|
2016-04-22 21:54:10 +02:00
|
|
|
static bool ProcessBlock(BasicBlock &BB, DominatorTree &DT, LoopInfo &LI,
|
|
|
|
AAResults &AA) {
|
2016-04-22 21:54:04 +02:00
|
|
|
// Can't sink anything out of a block that has less than two successors.
|
|
|
|
if (BB.getTerminator()->getNumSuccessors() <= 1) return false;
|
|
|
|
|
|
|
|
// Don't bother sinking code out of unreachable blocks. In addition to being
|
|
|
|
// unprofitable, it can also lead to infinite looping, because in an
|
|
|
|
// unreachable loop there may be nowhere to stop.
|
2016-04-22 21:54:10 +02:00
|
|
|
if (!DT.isReachableFromEntry(&BB)) return false;
|
2016-04-22 21:54:04 +02:00
|
|
|
|
|
|
|
bool MadeChange = false;
|
|
|
|
|
|
|
|
// Walk the basic block bottom-up. Remember if we saw a store.
|
|
|
|
BasicBlock::iterator I = BB.end();
|
|
|
|
--I;
|
|
|
|
bool ProcessedBegin = false;
|
|
|
|
SmallPtrSet<Instruction *, 8> Stores;
|
|
|
|
do {
|
|
|
|
Instruction *Inst = &*I; // The instruction to sink.
|
|
|
|
|
|
|
|
// Predecrement I (if it's not begin) so that it isn't invalidated by
|
|
|
|
// sinking.
|
|
|
|
ProcessedBegin = I == BB.begin();
|
|
|
|
if (!ProcessedBegin)
|
|
|
|
--I;
|
|
|
|
|
2021-04-26 18:12:29 +02:00
|
|
|
if (Inst->isDebugOrPseudoInst())
|
2016-04-22 21:54:04 +02:00
|
|
|
continue;
|
|
|
|
|
2016-04-22 21:54:10 +02:00
|
|
|
if (SinkInstruction(Inst, Stores, DT, LI, AA)) {
|
2016-04-22 21:54:04 +02:00
|
|
|
++NumSunk;
|
|
|
|
MadeChange = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we just processed the first instruction in the block, we're done.
|
|
|
|
} while (!ProcessedBegin);
|
|
|
|
|
|
|
|
return MadeChange;
|
|
|
|
}
|
|
|
|
|
2016-04-22 21:54:10 +02:00
|
|
|
static bool iterativelySinkInstructions(Function &F, DominatorTree &DT,
|
|
|
|
LoopInfo &LI, AAResults &AA) {
|
2016-04-22 21:54:04 +02:00
|
|
|
bool MadeChange, EverMadeChange = false;
|
|
|
|
|
|
|
|
do {
|
|
|
|
MadeChange = false;
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "Sinking iteration " << NumSinkIter << "\n");
|
2016-04-22 21:54:04 +02:00
|
|
|
// Process all basic blocks.
|
2016-06-26 14:28:59 +02:00
|
|
|
for (BasicBlock &I : F)
|
|
|
|
MadeChange |= ProcessBlock(I, DT, LI, AA);
|
2016-04-22 21:54:04 +02:00
|
|
|
EverMadeChange |= MadeChange;
|
|
|
|
NumSinkIter++;
|
|
|
|
} while (MadeChange);
|
|
|
|
|
|
|
|
return EverMadeChange;
|
|
|
|
}
|
2016-04-22 21:54:10 +02:00
|
|
|
|
2016-08-09 02:28:15 +02:00
|
|
|
PreservedAnalyses SinkingPass::run(Function &F, FunctionAnalysisManager &AM) {
|
2016-04-22 21:54:10 +02:00
|
|
|
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
|
|
|
|
auto &LI = AM.getResult<LoopAnalysis>(F);
|
|
|
|
auto &AA = AM.getResult<AAManager>(F);
|
|
|
|
|
|
|
|
if (!iterativelySinkInstructions(F, DT, LI, AA))
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
|
2017-01-15 07:32:49 +01:00
|
|
|
PreservedAnalyses PA;
|
|
|
|
PA.preserveSet<CFGAnalyses>();
|
2016-04-22 21:54:10 +02:00
|
|
|
return PA;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class SinkingLegacyPass : public FunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID; // Pass identification
|
|
|
|
SinkingLegacyPass() : FunctionPass(ID) {
|
|
|
|
initializeSinkingLegacyPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnFunction(Function &F) override {
|
|
|
|
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
|
|
|
auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
|
|
|
auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
|
|
|
|
|
|
|
|
return iterativelySinkInstructions(F, DT, LI, AA);
|
|
|
|
}
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesCFG();
|
|
|
|
FunctionPass::getAnalysisUsage(AU);
|
|
|
|
AU.addRequired<AAResultsWrapperPass>();
|
|
|
|
AU.addRequired<DominatorTreeWrapperPass>();
|
|
|
|
AU.addRequired<LoopInfoWrapperPass>();
|
|
|
|
AU.addPreserved<DominatorTreeWrapperPass>();
|
|
|
|
AU.addPreserved<LoopInfoWrapperPass>();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char SinkingLegacyPass::ID = 0;
|
|
|
|
INITIALIZE_PASS_BEGIN(SinkingLegacyPass, "sink", "Code sinking", false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
|
|
|
INITIALIZE_PASS_END(SinkingLegacyPass, "sink", "Code sinking", false, false)
|
|
|
|
|
|
|
|
FunctionPass *llvm::createSinkingPass() { return new SinkingLegacyPass(); }
|