Make TargetData optional in GlobalOpt and ArgumentPromotion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78967 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2009-08-14 00:11:03 +00:00
parent fa9ca0f788
commit 7eb28f3786
2 changed files with 16 additions and 15 deletions

View File

@ -61,7 +61,6 @@ namespace {
struct VISIBILITY_HIDDEN ArgPromotion : public CallGraphSCCPass { struct VISIBILITY_HIDDEN ArgPromotion : public CallGraphSCCPass {
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<AliasAnalysis>(); AU.addRequired<AliasAnalysis>();
AU.addRequired<TargetData>();
CallGraphSCCPass::getAnalysisUsage(AU); CallGraphSCCPass::getAnalysisUsage(AU);
} }
@ -433,7 +432,8 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg, bool isByVal) const {
SmallPtrSet<BasicBlock*, 16> TranspBlocks; SmallPtrSet<BasicBlock*, 16> TranspBlocks;
AliasAnalysis &AA = getAnalysis<AliasAnalysis>(); AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
TargetData &TD = getAnalysis<TargetData>(); TargetData *TD = getAnalysisIfAvailable<TargetData>();
if (!TD) return false; // Without TargetData, assume the worst.
for (unsigned i = 0, e = Loads.size(); i != e; ++i) { for (unsigned i = 0, e = Loads.size(); i != e; ++i) {
// Check to see if the load is invalidated from the start of the block to // Check to see if the load is invalidated from the start of the block to
@ -443,7 +443,7 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg, bool isByVal) const {
const PointerType *LoadTy = const PointerType *LoadTy =
cast<PointerType>(Load->getPointerOperand()->getType()); cast<PointerType>(Load->getPointerOperand()->getType());
unsigned LoadSize = (unsigned)TD.getTypeStoreSize(LoadTy->getElementType()); unsigned LoadSize =(unsigned)TD->getTypeStoreSize(LoadTy->getElementType());
if (AA.canInstructionRangeModify(BB->front(), *Load, Arg, LoadSize)) if (AA.canInstructionRangeModify(BB->front(), *Load, Arg, LoadSize))
return false; // Pointer is invalidated! return false; // Pointer is invalidated!

View File

@ -58,7 +58,6 @@ STATISTIC(NumAliasesRemoved, "Number of global aliases eliminated");
namespace { namespace {
struct VISIBILITY_HIDDEN GlobalOpt : public ModulePass { struct VISIBILITY_HIDDEN GlobalOpt : public ModulePass {
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<TargetData>();
} }
static char ID; // Pass identification, replacement for typeid static char ID; // Pass identification, replacement for typeid
GlobalOpt() : ModulePass(&ID) {} GlobalOpt() : ModulePass(&ID) {}
@ -1446,7 +1445,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
MallocInst *MI, MallocInst *MI,
Module::global_iterator &GVI, Module::global_iterator &GVI,
TargetData &TD, TargetData *TD,
LLVMContext &Context) { LLVMContext &Context) {
// If this is a malloc of an abstract type, don't touch it. // If this is a malloc of an abstract type, don't touch it.
if (!MI->getAllocatedType()->isSized()) if (!MI->getAllocatedType()->isSized())
@ -1481,8 +1480,9 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
// Restrict this transformation to only working on small allocations // Restrict this transformation to only working on small allocations
// (2048 bytes currently), as we don't want to introduce a 16M global or // (2048 bytes currently), as we don't want to introduce a 16M global or
// something. // something.
if (NElements->getZExtValue()* if (TD &&
TD.getTypeAllocSize(MI->getAllocatedType()) < 2048) { NElements->getZExtValue()*
TD->getTypeAllocSize(MI->getAllocatedType()) < 2048) {
GVI = OptimizeGlobalAddressOfMalloc(GV, MI, Context); GVI = OptimizeGlobalAddressOfMalloc(GV, MI, Context);
return true; return true;
} }
@ -1532,7 +1532,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
// that only one value (besides its initializer) is ever stored to the global. // that only one value (besides its initializer) is ever stored to the global.
static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
Module::global_iterator &GVI, Module::global_iterator &GVI,
TargetData &TD, LLVMContext &Context) { TargetData *TD, LLVMContext &Context) {
// Ignore no-op GEPs and bitcasts. // Ignore no-op GEPs and bitcasts.
StoredOnceVal = StoredOnceVal->stripPointerCasts(); StoredOnceVal = StoredOnceVal->stripPointerCasts();
@ -1754,8 +1754,8 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
++NumMarked; ++NumMarked;
return true; return true;
} else if (!GV->getInitializer()->getType()->isSingleValueType()) { } else if (!GV->getInitializer()->getType()->isSingleValueType()) {
if (GlobalVariable *FirstNewGV = SRAGlobal(GV, if (TargetData *TD = getAnalysisIfAvailable<TargetData>())
getAnalysis<TargetData>(), if (GlobalVariable *FirstNewGV = SRAGlobal(GV, *TD,
GV->getContext())) { GV->getContext())) {
GVI = FirstNewGV; // Don't skip the newly produced globals! GVI = FirstNewGV; // Don't skip the newly produced globals!
return true; return true;
@ -1789,7 +1789,8 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
// Try to optimize globals based on the knowledge that only one value // Try to optimize globals based on the knowledge that only one value
// (besides its initializer) is ever stored to the global. // (besides its initializer) is ever stored to the global.
if (OptimizeOnceStoredGlobal(GV, GS.StoredOnceValue, GVI, if (OptimizeOnceStoredGlobal(GV, GS.StoredOnceValue, GVI,
getAnalysis<TargetData>(), GV->getContext())) getAnalysisIfAvailable<TargetData>(),
GV->getContext()))
return true; return true;
// Otherwise, if the global was not a boolean, we can shrink it to be a // Otherwise, if the global was not a boolean, we can shrink it to be a