mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-13 23:00:33 +00:00
Change LoopInstSimplify back to a LoopPass. It revisits subloops rather than
skipping them, but it should probably use a worklist and only revisit those instructions in subloops that have actually changed. It should probably also use a worklist after the first iteration like instsimplify now does. Regardless, it's only 0.3% of opt -O2 time on 403.gcc if it replaces the instcombine placed in the middle of the loop passes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122868 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
be478819cb
commit
e389ab16f3
@ -12,11 +12,11 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#define DEBUG_TYPE "loop-instsimplify"
|
#define DEBUG_TYPE "loop-instsimplify"
|
||||||
#include "llvm/Function.h"
|
|
||||||
#include "llvm/Pass.h"
|
|
||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
#include "llvm/Analysis/InstructionSimplify.h"
|
#include "llvm/Analysis/InstructionSimplify.h"
|
||||||
#include "llvm/Analysis/LoopInfo.h"
|
#include "llvm/Analysis/LoopInfo.h"
|
||||||
|
#include "llvm/Analysis/LoopPass.h"
|
||||||
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
@ -26,19 +26,19 @@ using namespace llvm;
|
|||||||
STATISTIC(NumSimplified, "Number of redundant instructions simplified");
|
STATISTIC(NumSimplified, "Number of redundant instructions simplified");
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class LoopInstSimplify : public FunctionPass {
|
class LoopInstSimplify : public LoopPass {
|
||||||
public:
|
public:
|
||||||
static char ID; // Pass ID, replacement for typeid
|
static char ID; // Pass ID, replacement for typeid
|
||||||
LoopInstSimplify() : FunctionPass(ID) {
|
LoopInstSimplify() : LoopPass(ID) {
|
||||||
initializeLoopInstSimplifyPass(*PassRegistry::getPassRegistry());
|
initializeLoopInstSimplifyPass(*PassRegistry::getPassRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnFunction(Function &);
|
bool runOnLoop(Loop*, LPPassManager&);
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.setPreservesCFG();
|
AU.setPreservesCFG();
|
||||||
AU.addRequired<LoopInfo>();
|
AU.addRequired<LoopInfo>();
|
||||||
AU.addPreserved<LoopInfo>();
|
AU.addRequiredID(LoopSimplifyID);
|
||||||
AU.addPreservedID(LCSSAID);
|
AU.addPreservedID(LCSSAID);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -57,19 +57,34 @@ Pass* llvm::createLoopInstSimplifyPass() {
|
|||||||
return new LoopInstSimplify();
|
return new LoopInstSimplify();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoopInstSimplify::runOnFunction(Function &F) {
|
bool LoopInstSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>();
|
DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>();
|
||||||
LoopInfo *LI = &getAnalysis<LoopInfo>();
|
LoopInfo *LI = &getAnalysis<LoopInfo>();
|
||||||
const TargetData *TD = getAnalysisIfAvailable<TargetData>();
|
const TargetData *TD = getAnalysisIfAvailable<TargetData>();
|
||||||
|
|
||||||
|
SmallVector<BasicBlock*, 8> ExitBlocks;
|
||||||
|
L->getUniqueExitBlocks(ExitBlocks);
|
||||||
|
array_pod_sort(ExitBlocks.begin(), ExitBlocks.end());
|
||||||
|
|
||||||
|
SmallVector<BasicBlock*, 16> VisitStack;
|
||||||
|
SmallPtrSet<BasicBlock*, 32> Visited;
|
||||||
|
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
bool LocalChanged;
|
bool LocalChanged;
|
||||||
do {
|
do {
|
||||||
LocalChanged = false;
|
LocalChanged = false;
|
||||||
|
|
||||||
for (df_iterator<BasicBlock*> DI = df_begin(&F.getEntryBlock()),
|
VisitStack.clear();
|
||||||
DE = df_end(&F.getEntryBlock()); DI != DE; ++DI)
|
Visited.clear();
|
||||||
for (BasicBlock::iterator BI = DI->begin(), BE = DI->end(); BI != BE;) {
|
|
||||||
|
VisitStack.push_back(L->getHeader());
|
||||||
|
|
||||||
|
while (!VisitStack.empty()) {
|
||||||
|
BasicBlock *BB = VisitStack.back();
|
||||||
|
VisitStack.pop_back();
|
||||||
|
|
||||||
|
// Simplify instructions in the current basic block.
|
||||||
|
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
|
||||||
Instruction *I = BI++;
|
Instruction *I = BI++;
|
||||||
// Don't bother simplifying unused instructions.
|
// Don't bother simplifying unused instructions.
|
||||||
if (!I->use_empty()) {
|
if (!I->use_empty()) {
|
||||||
@ -83,6 +98,17 @@ bool LoopInstSimplify::runOnFunction(Function &F) {
|
|||||||
LocalChanged |= RecursivelyDeleteTriviallyDeadInstructions(I);
|
LocalChanged |= RecursivelyDeleteTriviallyDeadInstructions(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add all successors to the worklist, except for loop exit blocks.
|
||||||
|
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE;
|
||||||
|
++SI) {
|
||||||
|
BasicBlock *SuccBB = *SI;
|
||||||
|
bool IsExitBlock = std::binary_search(ExitBlocks.begin(),
|
||||||
|
ExitBlocks.end(), SuccBB);
|
||||||
|
if (!IsExitBlock && Visited.insert(SuccBB))
|
||||||
|
VisitStack.push_back(SuccBB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Changed |= LocalChanged;
|
Changed |= LocalChanged;
|
||||||
} while (LocalChanged);
|
} while (LocalChanged);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user