//
//===----------------------------------------------------------------------===//
-#define DEBUG_TYPE "lcssa"
#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/PredIteratorCache.h"
#include "llvm/Pass.h"
-#include "llvm/Support/PredIteratorCache.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
using namespace llvm;
+#define DEBUG_TYPE "lcssa"
+
STATISTIC(NumLCSSA, "Number of live out of a loop variables");
/// Return true if the specified block is in the list.
BasicBlock *InstBB = Inst.getParent();
- for (Value::use_iterator UI = Inst.use_begin(), E = Inst.use_end(); UI != E;
- ++UI) {
- User *U = *UI;
- BasicBlock *UserBB = cast<Instruction>(U)->getParent();
- if (PHINode *PN = dyn_cast<PHINode>(U))
- UserBB = PN->getIncomingBlock(UI);
+ for (Use &U : Inst.uses()) {
+ Instruction *User = cast<Instruction>(U.getUser());
+ BasicBlock *UserBB = User->getParent();
+ if (PHINode *PN = dyn_cast<PHINode>(User))
+ UserBB = PN->getIncomingBlock(U);
if (InstBB != UserBB && !L.contains(UserBB))
- UsesToRewrite.push_back(&UI.getUse());
+ UsesToRewrite.push_back(&U);
}
// If there are no uses outside the loop, exit with no change.
// Reject two common cases fast: instructions with no uses (like stores)
// and instructions with one use that is in the same block as this.
if (I->use_empty() ||
- (I->hasOneUse() && I->use_back()->getParent() == BB &&
- !isa<PHINode>(I->use_back())))
+ (I->hasOneUse() && I->user_back()->getParent() == BB &&
+ !isa<PHINode>(I->user_back())))
continue;
Changed |= processInstruction(L, *I, DT, ExitBlocks, PredCache);
return Changed;
}
+/// Process a loop nest depth first.
+bool llvm::formLCSSARecursively(Loop &L, DominatorTree &DT,
+ ScalarEvolution *SE) {
+ bool Changed = false;
+
+ // Recurse depth-first through inner loops.
+ for (Loop::iterator LI = L.begin(), LE = L.end(); LI != LE; ++LI)
+ Changed |= formLCSSARecursively(**LI, DT, SE);
+
+ Changed |= formLCSSA(L, DT, SE);
+ return Changed;
+}
+
namespace {
struct LCSSA : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
LoopInfo *LI;
ScalarEvolution *SE;
- virtual bool runOnFunction(Function &F);
+ bool runOnFunction(Function &F) override;
/// This transformation requires natural loop information & requires that
/// loop preheaders be inserted into the CFG. It maintains both of these,
/// as well as the CFG. It also requires dominator information.
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesCFG();
AU.addRequired<DominatorTreeWrapperPass>();
AU.addRequired<LoopInfo>();
AU.addPreservedID(LoopSimplifyID);
+ AU.addPreserved<AliasAnalysis>();
AU.addPreserved<ScalarEvolution>();
}
private:
- bool processLoop(Loop &L);
-
- virtual void verifyAnalysis() const;
+ void verifyAnalysis() const override;
};
}
// Simplify each loop nest in the function.
for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
- Changed |= processLoop(**I);
-
- return Changed;
-}
-
-/// Process a loop nest depth first.
-bool LCSSA::processLoop(Loop &L) {
- bool Changed = false;
-
- // Recurse depth-first through inner loops.
- for (Loop::iterator LI = L.begin(), LE = L.end(); LI != LE; ++LI)
- Changed |= processLoop(**LI);
+ Changed |= formLCSSARecursively(**I, *DT, SE);
- Changed |= formLCSSA(L, *DT, SE);
return Changed;
}