46 #define DEBUG_TYPE "lcssa"
48 STATISTIC(NumLCSSA,
"Number of live out of a loop variables");
53 for (
unsigned i = 0, e = ExitBlocks.
size(); i != e; ++i)
54 if (ExitBlocks[i] == BB)
72 if (
PHINode *PN = dyn_cast<PHINode>(User))
73 UserBB = PN->getIncomingBlock(U);
75 if (InstBB != UserBB && !L.
contains(UserBB))
80 if (UsesToRewrite.
empty())
91 if (
InvokeInst *Inv = dyn_cast<InvokeInst>(&Inst))
92 DomBB = Inv->getNormalDest();
105 BBE = ExitBlocks.
end();
151 for (
unsigned i = 0, e = UsesToRewrite.
size(); i != e; ++i) {
158 if (
PHINode *PN = dyn_cast<PHINode>(User))
159 UserBB = PN->getIncomingBlock(*UsesToRewrite[i]);
161 if (isa<PHINode>(UserBB->begin()) &&
isExitBlock(UserBB, ExitBlocks)) {
163 if (UsesToRewrite[i]->
get()->hasValueHandle())
165 UsesToRewrite[i]->set(UserBB->begin());
175 for (
auto *
I : PostProcessPHIs) {
193 for (
unsigned i = 0, e = AddedPHIs.
size(); i != e; ++i) {
194 if (AddedPHIs[i]->use_empty())
195 AddedPHIs[i]->eraseFromParent();
208 for (
unsigned i = 0, e = ExitBlocks.
size(); i != e; ++i)
217 bool Changed =
false;
223 if (ExitBlocks.
empty())
243 if (
I->use_empty() ||
244 (
I->hasOneUse() &&
I->user_back()->getParent() == BB &&
245 !isa<PHINode>(
I->user_back())))
266 bool Changed =
false;
288 bool runOnFunction(
Function &
F)
override;
317 bool Changed =
false;
318 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
319 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
320 SE = getAnalysisIfAvailable<ScalarEvolution>();
Pass interface - Implemented by all 'passes'.
const Use & getOperandUse(unsigned i) const
void push_back(const T &Elt)
iterator_range< use_iterator > uses()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Helper class for SSA formation on a set of values defined in multiple blocks.
void addIncoming(Value *V, BasicBlock *BB)
addIncoming - Add an incoming value to the end of the PHI list
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
ScalarEvolution - This class is the main scalar evolution driver.
LoopT * getLoopFor(const BlockT *BB) const
getLoopFor - Return the inner most loop that BB lives in.
bool formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution *SE=nullptr)
Put loop into LCSSA form.
StringRef getName() const
Return a constant reference to the value's name.
std::vector< LoopT * >::const_iterator iterator
iterator/begin/end - The interface to the top-level loops in the current function.
iterator begin()
Instruction iterator methods.
static unsigned getOperandNumForIncomingValue(unsigned i)
AnalysisUsage & addRequired()
ArrayRef< BasicBlock * > get(BasicBlock *BB)
#define INITIALIZE_PASS_DEPENDENCY(depName)
A Use represents the edge between a Value definition and its users.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void getExitBlocks(SmallVectorImpl< BlockT * > &ExitBlocks) const
getExitBlocks - Return all of the successor blocks of this loop.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
PredIteratorCache - This class is an extremely trivial cache for predecessor iterator queries...
static bool processInstruction(Loop &L, Instruction &Inst, DominatorTree &DT, const SmallVectorImpl< BasicBlock * > &ExitBlocks, PredIteratorCache &PredCache, LoopInfo *LI)
Given an instruction in the loop, check to see if it has any uses that are outside the current loop...
Base class for the actual dominator tree node.
AnalysisUsage & addPreservedID(const void *ID)
static void ValueIsRAUWd(Value *Old, Value *New)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
LLVM Basic Block Representation.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
bool contains(const LoopT *L) const
contains - Return true if the specified loop is contained within in this loop.
FunctionPass class - This class is used to implement most global optimizations.
bool HasValueForBlock(BasicBlock *BB) const
Return true if the SSAUpdater already has a value for the specified block.
static bool blockDominatesAnExit(BasicBlock *BB, DominatorTree &DT, const SmallVectorImpl< BasicBlock * > &ExitBlocks)
Return true if the specified block dominates at least one of the blocks in the specified list...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
bool isLCSSAForm(DominatorTree &DT) const
isLCSSAForm - Return true if the Loop is in LCSSA form
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
void initializeLCSSAPass(PassRegistry &)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
std::vector< BlockT * >::const_iterator block_iterator
bool formLCSSARecursively(Loop &L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution *SE=nullptr)
Put a loop nest into LCSSA form.
block_iterator block_end() const
void forgetLoop(const Loop *L)
forgetLoop - This method should be called by the client when it has changed a loop in a way that may ...
InvokeInst - Invoke instruction.
block_iterator block_begin() const
The legacy pass manager's analysis pass to compute loop information.
static bool isExitBlock(BasicBlock *BB, const SmallVectorImpl< BasicBlock * > &ExitBlocks)
Return true if the specified block is in the list.
Legacy analysis pass which computes a DominatorTree.
std::vector< LoopT * >::const_iterator iterator
DomTreeNodeBase< NodeT > * getNode(NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
void RewriteUse(Use &U)
Rewrite a use of the symbolic value.
size_t size(BasicBlock *BB)
const BasicBlock * getParent() const