Convert several more passes to use getAnalysisIfAvailable<TargetData>()

instead of getAnalysis<TargetData>().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76982 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2009-07-24 18:13:53 +00:00
parent 6b118a2122
commit 02a436c48e
5 changed files with 33 additions and 32 deletions

View File

@ -19,11 +19,11 @@
#include "llvm/CallGraphSCCPass.h" #include "llvm/CallGraphSCCPass.h"
#include "llvm/Transforms/Utils/InlineCost.h" #include "llvm/Transforms/Utils/InlineCost.h"
#include "llvm/Target/TargetData.h"
namespace llvm { namespace llvm {
class CallSite; class CallSite;
class TargetData;
/// Inliner - This class contains all of the helper code which is used to /// Inliner - This class contains all of the helper code which is used to
/// perform the inlining operations that do not depend on the policy. /// perform the inlining operations that do not depend on the policy.
@ -48,7 +48,7 @@ struct Inliner : public CallGraphSCCPass {
// InlineCallIfPossible // InlineCallIfPossible
bool InlineCallIfPossible(CallSite CS, CallGraph &CG, bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
const SmallPtrSet<Function*, 8> &SCCFunctions, const SmallPtrSet<Function*, 8> &SCCFunctions,
const TargetData &TD); const TargetData *TD);
/// This method returns the value specified by the -inline-threshold value, /// This method returns the value specified by the -inline-threshold value,
/// specified on the command line. This is typically not directly needed. /// specified on the command line. This is typically not directly needed.

View File

@ -45,7 +45,6 @@ Inliner::Inliner(void *ID, int Threshold)
/// the call graph. If the derived class implements this method, it should /// the call graph. If the derived class implements this method, it should
/// always explicitly call the implementation here. /// always explicitly call the implementation here.
void Inliner::getAnalysisUsage(AnalysisUsage &Info) const { void Inliner::getAnalysisUsage(AnalysisUsage &Info) const {
Info.addRequired<TargetData>();
CallGraphSCCPass::getAnalysisUsage(Info); CallGraphSCCPass::getAnalysisUsage(Info);
} }
@ -53,11 +52,11 @@ void Inliner::getAnalysisUsage(AnalysisUsage &Info) const {
// do so and update the CallGraph for this operation. // do so and update the CallGraph for this operation.
bool Inliner::InlineCallIfPossible(CallSite CS, CallGraph &CG, bool Inliner::InlineCallIfPossible(CallSite CS, CallGraph &CG,
const SmallPtrSet<Function*, 8> &SCCFunctions, const SmallPtrSet<Function*, 8> &SCCFunctions,
const TargetData &TD) { const TargetData *TD) {
Function *Callee = CS.getCalledFunction(); Function *Callee = CS.getCalledFunction();
Function *Caller = CS.getCaller(); Function *Caller = CS.getCaller();
if (!InlineFunction(CS, &CG, &TD)) return false; if (!InlineFunction(CS, &CG, TD)) return false;
// If the inlined function had a higher stack protection level than the // If the inlined function had a higher stack protection level than the
// calling function, then bump up the caller's stack protection level. // calling function, then bump up the caller's stack protection level.
@ -127,7 +126,7 @@ bool Inliner::shouldInline(CallSite CS) {
bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) { bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
CallGraph &CG = getAnalysis<CallGraph>(); CallGraph &CG = getAnalysis<CallGraph>();
TargetData &TD = getAnalysis<TargetData>(); const TargetData *TD = getAnalysisIfAvailable<TargetData>();
SmallPtrSet<Function*, 8> SCCFunctions; SmallPtrSet<Function*, 8> SCCFunctions;
DOUT << "Inliner visiting SCC:"; DOUT << "Inliner visiting SCC:";

View File

@ -37,6 +37,8 @@ STATISTIC(NumFastOther , "Number of other instrs removed");
namespace { namespace {
struct VISIBILITY_HIDDEN DSE : public FunctionPass { struct VISIBILITY_HIDDEN DSE : public FunctionPass {
TargetData *TD;
static char ID; // Pass identification, replacement for typeid static char ID; // Pass identification, replacement for typeid
DSE() : FunctionPass(&ID) {} DSE() : FunctionPass(&ID) {}
@ -62,7 +64,6 @@ namespace {
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG(); AU.setPreservesCFG();
AU.addRequired<DominatorTree>(); AU.addRequired<DominatorTree>();
AU.addRequired<TargetData>();
AU.addRequired<AliasAnalysis>(); AU.addRequired<AliasAnalysis>();
AU.addRequired<MemoryDependenceAnalysis>(); AU.addRequired<MemoryDependenceAnalysis>();
AU.addPreserved<DominatorTree>(); AU.addPreserved<DominatorTree>();
@ -79,7 +80,7 @@ FunctionPass *llvm::createDeadStoreEliminationPass() { return new DSE(); }
bool DSE::runOnBasicBlock(BasicBlock &BB) { bool DSE::runOnBasicBlock(BasicBlock &BB) {
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>(); MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
TargetData &TD = getAnalysis<TargetData>(); TD = getAnalysisIfAvailable<TargetData>();
bool MadeChange = false; bool MadeChange = false;
@ -87,7 +88,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
for (BasicBlock::iterator BBI = BB.begin(), BBE = BB.end(); BBI != BBE; ) { for (BasicBlock::iterator BBI = BB.begin(), BBE = BB.end(); BBI != BBE; ) {
Instruction *Inst = BBI++; Instruction *Inst = BBI++;
// If we find a store or a free, get it's memory dependence. // If we find a store or a free, get its memory dependence.
if (!isa<StoreInst>(Inst) && !isa<FreeInst>(Inst)) if (!isa<StoreInst>(Inst) && !isa<FreeInst>(Inst))
continue; continue;
@ -117,8 +118,9 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
// If this is a store-store dependence, then the previous store is dead so // If this is a store-store dependence, then the previous store is dead so
// long as this store is at least as big as it. // long as this store is at least as big as it.
if (StoreInst *DepStore = dyn_cast<StoreInst>(InstDep.getInst())) if (StoreInst *DepStore = dyn_cast<StoreInst>(InstDep.getInst()))
if (TD.getTypeStoreSize(DepStore->getOperand(0)->getType()) <= if (!TD ||
TD.getTypeStoreSize(SI->getOperand(0)->getType())) { TD->getTypeStoreSize(DepStore->getOperand(0)->getType()) <=
TD->getTypeStoreSize(SI->getOperand(0)->getType())) {
// Delete the store and now-dead instructions that feed it. // Delete the store and now-dead instructions that feed it.
DeleteDeadInstruction(DepStore); DeleteDeadInstruction(DepStore);
NumFastStores++; NumFastStores++;
@ -181,7 +183,6 @@ bool DSE::handleFreeWithNonTrivialDependency(FreeInst *F, MemDepResult Dep) {
/// store i32 1, i32* %A /// store i32 1, i32* %A
/// ret void /// ret void
bool DSE::handleEndBlock(BasicBlock &BB) { bool DSE::handleEndBlock(BasicBlock &BB) {
TargetData &TD = getAnalysis<TargetData>();
AliasAnalysis &AA = getAnalysis<AliasAnalysis>(); AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
bool MadeChange = false; bool MadeChange = false;
@ -302,14 +303,16 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
// Get size information for the alloca // Get size information for the alloca
unsigned pointerSize = ~0U; unsigned pointerSize = ~0U;
if (AllocaInst* A = dyn_cast<AllocaInst>(*I)) { if (TD) {
if (ConstantInt* C = dyn_cast<ConstantInt>(A->getArraySize())) if (AllocaInst* A = dyn_cast<AllocaInst>(*I)) {
pointerSize = C->getZExtValue() * if (ConstantInt* C = dyn_cast<ConstantInt>(A->getArraySize()))
TD.getTypeAllocSize(A->getAllocatedType()); pointerSize = C->getZExtValue() *
} else { TD->getTypeAllocSize(A->getAllocatedType());
const PointerType* PT = cast<PointerType>( } else {
cast<Argument>(*I)->getType()); const PointerType* PT = cast<PointerType>(
pointerSize = TD.getTypeAllocSize(PT->getElementType()); cast<Argument>(*I)->getType());
pointerSize = TD->getTypeAllocSize(PT->getElementType());
}
} }
// See if the call site touches it // See if the call site touches it
@ -357,7 +360,6 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
bool DSE::RemoveUndeadPointers(Value* killPointer, uint64_t killPointerSize, bool DSE::RemoveUndeadPointers(Value* killPointer, uint64_t killPointerSize,
BasicBlock::iterator &BBI, BasicBlock::iterator &BBI,
SmallPtrSet<Value*, 64>& deadPointers) { SmallPtrSet<Value*, 64>& deadPointers) {
TargetData &TD = getAnalysis<TargetData>();
AliasAnalysis &AA = getAnalysis<AliasAnalysis>(); AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
// If the kill pointer can be easily reduced to an alloca, // If the kill pointer can be easily reduced to an alloca,
@ -379,13 +381,15 @@ bool DSE::RemoveUndeadPointers(Value* killPointer, uint64_t killPointerSize,
E = deadPointers.end(); I != E; ++I) { E = deadPointers.end(); I != E; ++I) {
// Get size information for the alloca. // Get size information for the alloca.
unsigned pointerSize = ~0U; unsigned pointerSize = ~0U;
if (AllocaInst* A = dyn_cast<AllocaInst>(*I)) { if (TD) {
if (ConstantInt* C = dyn_cast<ConstantInt>(A->getArraySize())) if (AllocaInst* A = dyn_cast<AllocaInst>(*I)) {
pointerSize = C->getZExtValue() * if (ConstantInt* C = dyn_cast<ConstantInt>(A->getArraySize()))
TD.getTypeAllocSize(A->getAllocatedType()); pointerSize = C->getZExtValue() *
} else { TD->getTypeAllocSize(A->getAllocatedType());
const PointerType* PT = cast<PointerType>(cast<Argument>(*I)->getType()); } else {
pointerSize = TD.getTypeAllocSize(PT->getElementType()); const PointerType* PT = cast<PointerType>(cast<Argument>(*I)->getType());
pointerSize = TD->getTypeAllocSize(PT->getElementType());
}
} }
// See if this pointer could alias it // See if this pointer could alias it

View File

@ -68,7 +68,6 @@ namespace {
JumpThreading() : FunctionPass(&ID) {} JumpThreading() : FunctionPass(&ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<TargetData>();
} }
bool runOnFunction(Function &F); bool runOnFunction(Function &F);
@ -100,7 +99,7 @@ FunctionPass *llvm::createJumpThreadingPass() { return new JumpThreading(); }
/// ///
bool JumpThreading::runOnFunction(Function &F) { bool JumpThreading::runOnFunction(Function &F) {
DOUT << "Jump threading on function '" << F.getNameStart() << "'\n"; DOUT << "Jump threading on function '" << F.getNameStart() << "'\n";
TD = &getAnalysis<TargetData>(); TD = getAnalysisIfAvailable<TargetData>();
FindLoopHeaders(F); FindLoopHeaders(F);

View File

@ -39,7 +39,6 @@ namespace {
bool runOnFunction(Function &F); bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<TargetData>();
} }
Instruction * Instruction *
@ -123,7 +122,7 @@ SimplifyHalfPowrLibCalls::InlineHalfPowrs(const std::vector<Instruction *> &Half
/// runOnFunction - Top level algorithm. /// runOnFunction - Top level algorithm.
/// ///
bool SimplifyHalfPowrLibCalls::runOnFunction(Function &F) { bool SimplifyHalfPowrLibCalls::runOnFunction(Function &F) {
TD = &getAnalysis<TargetData>(); TD = getAnalysisIfAvailable<TargetData>();
bool Changed = false; bool Changed = false;
std::vector<Instruction *> HalfPowrs; std::vector<Instruction *> HalfPowrs;