[llvm-commits] [llvm] r79306 - /llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
Dan Gohman
gohman at apple.com
Mon Aug 17 18:17:52 PDT 2009
Author: djg
Date: Mon Aug 17 20:17:52 2009
New Revision: 79306
URL: http://llvm.org/viewvc/llvm-project?rev=79306&view=rev
Log:
Make TargetData optional in MemCpyOptimizer.
Modified:
llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp?rev=79306&r1=79305&r2=79306&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp Mon Aug 17 20:17:52 2009
@@ -309,10 +309,8 @@
AU.addRequired<DominatorTree>();
AU.addRequired<MemoryDependenceAnalysis>();
AU.addRequired<AliasAnalysis>();
- AU.addRequired<TargetData>();
AU.addPreserved<AliasAnalysis>();
AU.addPreserved<MemoryDependenceAnalysis>();
- AU.addPreserved<TargetData>();
}
// Helper fuctions
@@ -350,7 +348,8 @@
if (!ByteVal)
return false;
- TargetData &TD = getAnalysis<TargetData>();
+ TargetData *TD = getAnalysisIfAvailable<TargetData>();
+ if (!TD) return false;
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
Module *M = SI->getParent()->getParent()->getParent();
@@ -358,7 +357,7 @@
// all subsequent stores of the same value to offset from the same pointer.
// Join these together into ranges, so we can decide whether contiguous blocks
// are stored.
- MemsetRanges Ranges(TD);
+ MemsetRanges Ranges(*TD);
Value *StartPtr = SI->getPointerOperand();
@@ -392,7 +391,7 @@
// Check to see if this store is to a constant offset from the start ptr.
int64_t Offset;
- if (!IsPointerOffset(StartPtr, NextStore->getPointerOperand(), Offset, TD))
+ if (!IsPointerOffset(StartPtr, NextStore->getPointerOperand(), Offset, *TD))
break;
Ranges.addStore(Offset, NextStore);
@@ -421,7 +420,7 @@
if (Range.TheStores.size() == 1) continue;
// If it is profitable to lower this range to memset, do so now.
- if (!Range.isProfitableToUseMemset(TD))
+ if (!Range.isProfitableToUseMemset(*TD))
continue;
// Otherwise, we do want to transform this! Create a new memset. We put
@@ -511,13 +510,14 @@
return false;
// Check that all of src is copied to dest.
- TargetData& TD = getAnalysis<TargetData>();
+ TargetData* TD = getAnalysisIfAvailable<TargetData>();
+ if (!TD) return false;
ConstantInt* srcArraySize = dyn_cast<ConstantInt>(srcAlloca->getArraySize());
if (!srcArraySize)
return false;
- uint64_t srcSize = TD.getTypeAllocSize(srcAlloca->getAllocatedType()) *
+ uint64_t srcSize = TD->getTypeAllocSize(srcAlloca->getAllocatedType()) *
srcArraySize->getZExtValue();
if (cpyLength->getZExtValue() < srcSize)
@@ -532,7 +532,7 @@
if (!destArraySize)
return false;
- uint64_t destSize = TD.getTypeAllocSize(A->getAllocatedType()) *
+ uint64_t destSize = TD->getTypeAllocSize(A->getAllocatedType()) *
destArraySize->getZExtValue();
if (destSize < srcSize)
@@ -544,7 +544,7 @@
return false;
const Type* StructTy = cast<PointerType>(A->getType())->getElementType();
- uint64_t destSize = TD.getTypeAllocSize(StructTy);
+ uint64_t destSize = TD->getTypeAllocSize(StructTy);
if (destSize < srcSize)
return false;
More information about the llvm-commits
mailing list