From: Owen Anderson Date: Tue, 24 Jul 2007 00:08:38 +0000 (+0000) Subject: Rename FastDLE as RedundantLoadElimination. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=e2a1624da3614859bc81a7ca81168680dd579342;p=oota-llvm.git Rename FastDLE as RedundantLoadElimination. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40456 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/FastDLE.cpp b/lib/Transforms/Scalar/FastDLE.cpp deleted file mode 100644 index 74712ad83fe..00000000000 --- a/lib/Transforms/Scalar/FastDLE.cpp +++ /dev/null @@ -1,134 +0,0 @@ -//===- FastDLE.cpp - Fast Dead Load Elimination ---------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by Owen Anderson and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements a trivial dead load elimination that only considers -// basic-block local redundant load. -// -// FIXME: This should eventually be extended to be a post-dominator tree -// traversal. Doing so would be pretty trivial. -// -//===----------------------------------------------------------------------===// - -#define DEBUG_TYPE "fdle" -#include "llvm/Transforms/Scalar.h" -#include "llvm/Function.h" -#include "llvm/Instructions.h" -#include "llvm/Pass.h" -#include "llvm/ADT/SmallPtrSet.h" -#include "llvm/ADT/Statistic.h" -#include "llvm/Analysis/MemoryDependenceAnalysis.h" -#include "llvm/Transforms/Utils/Local.h" -#include "llvm/Support/Compiler.h" -using namespace llvm; - -STATISTIC(NumFastLoads, "Number of loads deleted"); - -namespace { - struct VISIBILITY_HIDDEN FDLE : public FunctionPass { - static char ID; // Pass identification, replacement for typeid - FDLE() : FunctionPass((intptr_t)&ID) {} - - virtual bool runOnFunction(Function &F) { - bool Changed = false; - for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) - Changed |= runOnBasicBlock(*I); - return Changed; - } - - bool runOnBasicBlock(BasicBlock &BB); - - // getAnalysisUsage - We require post dominance frontiers (aka Control - // Dependence Graph) - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesCFG(); - AU.addRequired(); - AU.addPreserved(); - } - }; - char FDLE::ID = 0; - RegisterPass X("fdle", "Fast Dead Load Elimination"); -} - -FunctionPass *llvm::createFastDeadLoadEliminationPass() { return new FDLE(); } - -bool FDLE::runOnBasicBlock(BasicBlock &BB) { - MemoryDependenceAnalysis& MD = getAnalysis(); - - // Record the last-seen load from this pointer - DenseMap lastLoad; - - bool MadeChange = false; - - // Do a top-down walk on the BB - for (BasicBlock::iterator BBI = BB.begin(), BBE = BB.end(); BBI != BBE; ++BBI) { - // If we find a store or a free... - if (LoadInst* L = dyn_cast(BBI)) { - // We can't delete volatile loads - if (L->isVolatile()) { - lastLoad[L->getPointerOperand()] = L; - continue; - } - - Value* pointer = L->getPointerOperand(); - LoadInst*& last = lastLoad[pointer]; - - // ... to a pointer that has been loaded from before... - Instruction* dep = MD.getDependency(BBI); - bool deletedLoad = false; - - while (dep != MemoryDependenceAnalysis::None && - dep != MemoryDependenceAnalysis::NonLocal && - (isa(dep) || isa(dep))) { - // ... that depends on a store ... - if (StoreInst* S = dyn_cast(dep)) { - if (S->getPointerOperand() == pointer) { - // Remove it! - MD.removeInstruction(BBI); - - BBI--; - L->replaceAllUsesWith(S->getOperand(0)); - L->eraseFromParent(); - NumFastLoads++; - deletedLoad = true; - MadeChange = true; - } - - // Whether we removed it or not, we can't - // go any further - break; - } else if (!last) { - // If we don't depend on a store, and we haven't - // been loaded before, bail. - break; - } else if (dep == last) { - // Remove it! - MD.removeInstruction(BBI); - - BBI--; - L->replaceAllUsesWith(last); - L->eraseFromParent(); - deletedLoad = true; - NumFastLoads++; - MadeChange = true; - - break; - } else { - dep = MD.getDependency(BBI, dep); - } - } - - if (!deletedLoad) - last = L; - } - } - - return MadeChange; -} - - diff --git a/lib/Transforms/Scalar/RedundantLoadElimination.cpp b/lib/Transforms/Scalar/RedundantLoadElimination.cpp new file mode 100644 index 00000000000..74712ad83fe --- /dev/null +++ b/lib/Transforms/Scalar/RedundantLoadElimination.cpp @@ -0,0 +1,134 @@ +//===- FastDLE.cpp - Fast Dead Load Elimination ---------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Owen Anderson and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements a trivial dead load elimination that only considers +// basic-block local redundant load. +// +// FIXME: This should eventually be extended to be a post-dominator tree +// traversal. Doing so would be pretty trivial. +// +//===----------------------------------------------------------------------===// + +#define DEBUG_TYPE "fdle" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Function.h" +#include "llvm/Instructions.h" +#include "llvm/Pass.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/Analysis/MemoryDependenceAnalysis.h" +#include "llvm/Transforms/Utils/Local.h" +#include "llvm/Support/Compiler.h" +using namespace llvm; + +STATISTIC(NumFastLoads, "Number of loads deleted"); + +namespace { + struct VISIBILITY_HIDDEN FDLE : public FunctionPass { + static char ID; // Pass identification, replacement for typeid + FDLE() : FunctionPass((intptr_t)&ID) {} + + virtual bool runOnFunction(Function &F) { + bool Changed = false; + for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) + Changed |= runOnBasicBlock(*I); + return Changed; + } + + bool runOnBasicBlock(BasicBlock &BB); + + // getAnalysisUsage - We require post dominance frontiers (aka Control + // Dependence Graph) + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesCFG(); + AU.addRequired(); + AU.addPreserved(); + } + }; + char FDLE::ID = 0; + RegisterPass X("fdle", "Fast Dead Load Elimination"); +} + +FunctionPass *llvm::createFastDeadLoadEliminationPass() { return new FDLE(); } + +bool FDLE::runOnBasicBlock(BasicBlock &BB) { + MemoryDependenceAnalysis& MD = getAnalysis(); + + // Record the last-seen load from this pointer + DenseMap lastLoad; + + bool MadeChange = false; + + // Do a top-down walk on the BB + for (BasicBlock::iterator BBI = BB.begin(), BBE = BB.end(); BBI != BBE; ++BBI) { + // If we find a store or a free... + if (LoadInst* L = dyn_cast(BBI)) { + // We can't delete volatile loads + if (L->isVolatile()) { + lastLoad[L->getPointerOperand()] = L; + continue; + } + + Value* pointer = L->getPointerOperand(); + LoadInst*& last = lastLoad[pointer]; + + // ... to a pointer that has been loaded from before... + Instruction* dep = MD.getDependency(BBI); + bool deletedLoad = false; + + while (dep != MemoryDependenceAnalysis::None && + dep != MemoryDependenceAnalysis::NonLocal && + (isa(dep) || isa(dep))) { + // ... that depends on a store ... + if (StoreInst* S = dyn_cast(dep)) { + if (S->getPointerOperand() == pointer) { + // Remove it! + MD.removeInstruction(BBI); + + BBI--; + L->replaceAllUsesWith(S->getOperand(0)); + L->eraseFromParent(); + NumFastLoads++; + deletedLoad = true; + MadeChange = true; + } + + // Whether we removed it or not, we can't + // go any further + break; + } else if (!last) { + // If we don't depend on a store, and we haven't + // been loaded before, bail. + break; + } else if (dep == last) { + // Remove it! + MD.removeInstruction(BBI); + + BBI--; + L->replaceAllUsesWith(last); + L->eraseFromParent(); + deletedLoad = true; + NumFastLoads++; + MadeChange = true; + + break; + } else { + dep = MD.getDependency(BBI, dep); + } + } + + if (!deletedLoad) + last = L; + } + } + + return MadeChange; +} + +