From df3ae8e4f042c4aa846a89c71beed336852536d3 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 10 Feb 2014 14:17:30 +0000 Subject: [PATCH] GlobalsModRef: Unify and clean up duplicated pointer analysis code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201087 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/IPA/GlobalsModRef.cpp | 33 +++++++++++------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/lib/Analysis/IPA/GlobalsModRef.cpp b/lib/Analysis/IPA/GlobalsModRef.cpp index 2a8b96da069..cdae975d845 100644 --- a/lib/Analysis/IPA/GlobalsModRef.cpp +++ b/lib/Analysis/IPA/GlobalsModRef.cpp @@ -262,30 +262,21 @@ bool GlobalsModRef::AnalyzeUsesOfPointer(Value *V, } else if (SI->getOperand(1) != OkayStoreDest) { return true; // Storing the pointer } - } else if (GetElementPtrInst *GEP = dyn_cast(U)) { - if (AnalyzeUsesOfPointer(GEP, Readers, Writers)) return true; - } else if (BitCastInst *BCI = dyn_cast(U)) { - if (AnalyzeUsesOfPointer(BCI, Readers, Writers, OkayStoreDest)) + } else if (Operator::getOpcode(U) == Instruction::GetElementPtr) { + if (AnalyzeUsesOfPointer(U, Readers, Writers)) return true; - } else if (isFreeCall(U, TLI)) { - Writers.push_back(cast(U)->getParent()->getParent()); - } else if (CallInst *CI = dyn_cast(U)) { + } else if (Operator::getOpcode(U) == Instruction::BitCast) { + if (AnalyzeUsesOfPointer(U, Readers, Writers, OkayStoreDest)) + return true; + } else if (CallSite CS = U) { // Make sure that this is just the function being called, not that it is // passing into the function. - for (unsigned i = 0, e = CI->getNumArgOperands(); i != e; ++i) - if (CI->getArgOperand(i) == V) return true; - } else if (InvokeInst *II = dyn_cast(U)) { - // Make sure that this is just the function being called, not that it is - // passing into the function. - for (unsigned i = 0, e = II->getNumArgOperands(); i != e; ++i) - if (II->getArgOperand(i) == V) return true; - } else if (ConstantExpr *CE = dyn_cast(U)) { - if (CE->getOpcode() == Instruction::GetElementPtr || - CE->getOpcode() == Instruction::BitCast) { - if (AnalyzeUsesOfPointer(CE, Readers, Writers)) - return true; - } else { - return true; + if (!CS.isCallee(UI)) { + // Detect calls to free. + if (isFreeCall(U, TLI)) + Writers.push_back(CS->getParent()->getParent()); + else + return true; // Argument of an unknown call. } } else if (ICmpInst *ICI = dyn_cast(U)) { if (!isa(ICI->getOperand(1)))