aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVictor Hernandez <vhernandez@apple.com>2009-11-03 20:39:35 +0000
committerVictor Hernandez <vhernandez@apple.com>2009-11-03 20:39:35 +0000
commit3ad70d5d61f3f86fb5bc167e157680fc107a1173 (patch)
treec0abf43548aaf93987feaa96e76695ffff7aa121 /lib
parenta9e610768bad77f400bc763a0011e77aee19053e (diff)
downloadexternal_llvm-3ad70d5d61f3f86fb5bc167e157680fc107a1173.zip
external_llvm-3ad70d5d61f3f86fb5bc167e157680fc107a1173.tar.gz
external_llvm-3ad70d5d61f3f86fb5bc167e157680fc107a1173.tar.bz2
Changes requested (avoid getFunction(), avoid Type creation via isVoidTy(), and avoid redundant isFreeCall cases) in feedback to r85176
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85936 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/MemoryBuiltins.cpp21
-rw-r--r--lib/VMCore/Instruction.cpp42
2 files changed, 13 insertions, 50 deletions
diff --git a/lib/Analysis/MemoryBuiltins.cpp b/lib/Analysis/MemoryBuiltins.cpp
index 47a70d1..e710350 100644
--- a/lib/Analysis/MemoryBuiltins.cpp
+++ b/lib/Analysis/MemoryBuiltins.cpp
@@ -33,16 +33,14 @@ static bool isMallocCall(const CallInst *CI) {
if (!CI)
return false;
- const Module *M = CI->getParent()->getParent()->getParent();
- Function *MallocFunc = M->getFunction("malloc");
-
- if (CI->getOperand(0) != MallocFunc)
+ Function *Callee = CI->getCalledFunction();
+ if (Callee == 0 || !Callee->isDeclaration() || Callee->getName() != "malloc")
return false;
// Check malloc prototype.
// FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
// attribute will exist.
- const FunctionType *FTy = MallocFunc->getFunctionType();
+ const FunctionType *FTy = Callee->getFunctionType();
if (FTy->getNumParams() != 1)
return false;
if (IntegerType *ITy = dyn_cast<IntegerType>(FTy->param_begin()->get())) {
@@ -260,22 +258,19 @@ bool llvm::isFreeCall(const Value *I) {
const CallInst *CI = dyn_cast<CallInst>(I);
if (!CI)
return false;
-
- const Module *M = CI->getParent()->getParent()->getParent();
- Function *FreeFunc = M->getFunction("free");
-
- if (CI->getOperand(0) != FreeFunc)
+ Function *Callee = CI->getCalledFunction();
+ if (Callee == 0 || !Callee->isDeclaration() || Callee->getName() != "free")
return false;
// Check free prototype.
// FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
// attribute will exist.
- const FunctionType *FTy = FreeFunc->getFunctionType();
- if (FTy->getReturnType() != Type::getVoidTy(M->getContext()))
+ const FunctionType *FTy = Callee->getFunctionType();
+ if (!FTy->getReturnType()->isVoidTy())
return false;
if (FTy->getNumParams() != 1)
return false;
- if (FTy->param_begin()->get() != Type::getInt8PtrTy(M->getContext()))
+ if (FTy->param_begin()->get() != Type::getInt8PtrTy(Callee->getContext()))
return false;
return true;
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp
index 879c073..ce253d6 100644
--- a/lib/VMCore/Instruction.cpp
+++ b/lib/VMCore/Instruction.cpp
@@ -303,32 +303,6 @@ bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const {
return false;
}
-// Code here matches isFreeCall from MemoryBuiltins, which is not in VMCore.
-static bool isFreeCall(const Value* I) {
- const CallInst *CI = dyn_cast<CallInst>(I);
- if (!CI)
- return false;
-
- const Module* M = CI->getParent()->getParent()->getParent();
- Function *FreeFunc = M->getFunction("free");
-
- if (CI->getOperand(0) != FreeFunc)
- return false;
-
- // Check free prototype.
- // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
- // attribute will exist.
- const FunctionType *FTy = FreeFunc->getFunctionType();
- if (FTy->getReturnType() != Type::getVoidTy(M->getContext()))
- return false;
- if (FTy->getNumParams() != 1)
- return false;
- if (FTy->param_begin()->get() != Type::getInt8PtrTy(M->getContext()))
- return false;
-
- return true;
-}
-
/// mayReadFromMemory - Return true if this instruction may read memory.
///
bool Instruction::mayReadFromMemory() const {
@@ -338,8 +312,6 @@ bool Instruction::mayReadFromMemory() const {
case Instruction::Load:
return true;
case Instruction::Call:
- if (isFreeCall(this))
- return true;
return !cast<CallInst>(this)->doesNotAccessMemory();
case Instruction::Invoke:
return !cast<InvokeInst>(this)->doesNotAccessMemory();
@@ -357,8 +329,6 @@ bool Instruction::mayWriteToMemory() const {
case Instruction::VAArg:
return true;
case Instruction::Call:
- if (isFreeCall(this))
- return true;
return !cast<CallInst>(this)->onlyReadsMemory();
case Instruction::Invoke:
return !cast<InvokeInst>(this)->onlyReadsMemory();
@@ -418,18 +388,16 @@ static bool isMalloc(const Value* I) {
CI = dyn_cast<CallInst>(BCI->getOperand(0));
}
- if (!CI) return false;
-
- const Module* M = CI->getParent()->getParent()->getParent();
- Constant *MallocFunc = M->getFunction("malloc");
-
- if (CI->getOperand(0) != MallocFunc)
+ if (!CI)
+ return false;
+ Function *Callee = CI->getCalledFunction();
+ if (Callee == 0 || !Callee->isDeclaration() || Callee->getName() != "malloc")
return false;
// Check malloc prototype.
// FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
// attribute will exist.
- const FunctionType *FTy = cast<Function>(MallocFunc)->getFunctionType();
+ const FunctionType *FTy = Callee->getFunctionType();
if (FTy->getNumParams() != 1)
return false;
if (IntegerType *ITy = dyn_cast<IntegerType>(FTy->param_begin()->get())) {