#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/Dominators.h"
DominatorTree *DT;
std::vector<BasicBlock*> LoopBlocks;
PredIteratorCache PredCache;
+ Loop *L;
virtual bool runOnLoop(Loop *L, LPPassManager &LPM);
AU.setPreservesCFG();
AU.addRequiredID(LoopSimplifyID);
AU.addPreservedID(LoopSimplifyID);
- AU.addRequired<LoopInfo>();
+ AU.addRequiredTransitive<LoopInfo>();
AU.addPreserved<LoopInfo>();
- AU.addRequired<DominatorTree>();
+ AU.addRequiredTransitive<DominatorTree>();
AU.addPreserved<ScalarEvolution>();
AU.addPreserved<DominatorTree>();
AU.addPreserved<DominanceFrontier>();
}
private:
+
+ /// verifyAnalysis() - Verify loop nest.
+ virtual void verifyAnalysis() const {
+ // Check the special guarantees that LCSSA makes.
+ assert(L->isLCSSAForm() && "LCSSA form not preserved!");
+ }
+
void getLoopValuesUsedOutsideLoop(Loop *L,
SetVector<Instruction*> &AffectedValues,
const SmallVector<BasicBlock*, 8>& exitBlocks);
const PassInfo *const llvm::LCSSAID = &X;
/// runOnFunction - Process all loops in the function, inner-most out.
-bool LCSSA::runOnLoop(Loop *L, LPPassManager &LPM) {
+bool LCSSA::runOnLoop(Loop *l, LPPassManager &LPM) {
+ L = l;
PredCache.clear();
LI = &LPM.getAnalysis<LoopInfo>();
// Keep track of the blocks that have the value available already.
DenseMap<DomTreeNode*, Value*> Phis;
- DomTreeNode *InstrNode = DT->getNode(Instr->getParent());
+ BasicBlock *DomBB = Instr->getParent();
+
+ // Invoke instructions are special in that their result value is not available
+ // along their unwind edge. The code below tests to see whether DomBB dominates
+ // the value, so adjust DomBB to the normal destination block, which is
+ // effectively where the value is first usable.
+ if (InvokeInst *Inv = dyn_cast<InvokeInst>(Instr))
+ DomBB = Inv->getNormalDest();
+
+ DomTreeNode *DomNode = DT->getNode(DomBB);
// Insert the LCSSA phi's into the exit blocks (dominated by the value), and
// add them to the Phi's map.
BasicBlock *BB = *BBI;
DomTreeNode *ExitBBNode = DT->getNode(BB);
Value *&Phi = Phis[ExitBBNode];
- if (!Phi && DT->dominates(InstrNode, ExitBBNode)) {
+ if (!Phi && DT->dominates(DomNode, ExitBBNode)) {
PHINode *PN = PHINode::Create(Instr->getType(), Instr->getName()+".lcssa",
BB->begin());
PN->reserveOperandSpace(PredCache.GetNumPreds(BB));