summaryrefslogtreecommitdiff
path: root/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-06-21 15:45:28 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-06-21 15:45:28 +0000
commit9e72a79ef4a9fcda482ce0b0e1f0bd6a4f16cffd (patch)
tree8861b7712018795653a7eace205bdaa6d10f2c70 /lib/Analysis/BasicAliasAnalysis.cpp
parent2114a8aaba99e901735e69818bb789757ed05cfd (diff)
downloadllvm-9e72a79ef4a9fcda482ce0b0e1f0bd6a4f16cffd.tar.gz
llvm-9e72a79ef4a9fcda482ce0b0e1f0bd6a4f16cffd.tar.bz2
llvm-9e72a79ef4a9fcda482ce0b0e1f0bd6a4f16cffd.tar.xz
refactor the MemoryBuiltin analysis:
- provide more extensive set of functions to detect library allocation functions (e.g., malloc, calloc, strdup, etc) - provide an API to compute the size and offset of an object pointed by Move a few clients (GVN, AA, instcombine, ...) to the new API. This implementation is a lot more aggressive than each of the custom implementations being replaced. Patch reviewed by Nick Lewycky and Chandler Carruth, thanks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158919 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp45
1 files changed, 4 insertions, 41 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index 20ecfd26a9..1d028c27b8 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -86,47 +86,10 @@ static bool isEscapeSource(const Value *V) {
/// UnknownSize if unknown.
static uint64_t getObjectSize(const Value *V, const TargetData &TD,
bool RoundToAlign = false) {
- Type *AccessTy;
- unsigned Align;
- if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
- if (!GV->hasDefinitiveInitializer())
- return AliasAnalysis::UnknownSize;
- AccessTy = GV->getType()->getElementType();
- Align = GV->getAlignment();
- } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
- if (!AI->isArrayAllocation())
- AccessTy = AI->getType()->getElementType();
- else
- return AliasAnalysis::UnknownSize;
- Align = AI->getAlignment();
- } else if (const CallInst* CI = extractMallocCall(V)) {
- if (!RoundToAlign && !isArrayMalloc(V, &TD))
- // The size is the argument to the malloc call.
- if (const ConstantInt* C = dyn_cast<ConstantInt>(CI->getArgOperand(0)))
- return C->getZExtValue();
- return AliasAnalysis::UnknownSize;
- } else if (const Argument *A = dyn_cast<Argument>(V)) {
- if (A->hasByValAttr()) {
- AccessTy = cast<PointerType>(A->getType())->getElementType();
- Align = A->getParamAlignment();
- } else {
- return AliasAnalysis::UnknownSize;
- }
- } else {
- return AliasAnalysis::UnknownSize;
- }
-
- if (!AccessTy->isSized())
- return AliasAnalysis::UnknownSize;
-
- uint64_t Size = TD.getTypeAllocSize(AccessTy);
- // If there is an explicitly specified alignment, and we need to
- // take alignment into account, round up the size. (If the alignment
- // is implicit, getTypeAllocSize is sufficient.)
- if (RoundToAlign && Align)
- Size = RoundUpToAlignment(Size, Align);
-
- return Size;
+ uint64_t Size;
+ if (getObjectSize(V, Size, &TD, RoundToAlign))
+ return Size;
+ return AliasAnalysis::UnknownSize;
}
/// isObjectSmallerThan - Return true if we can prove that the object specified