[llvm-commits] [llvm] r85936 - in /llvm/trunk/lib: Analysis/MemoryBuiltins.cpp VMCore/Instruction.cpp
Victor Hernandez
vhernandez at apple.com
Tue Nov 3 12:39:35 PST 2009
Author: hernande
Date: Tue Nov 3 14:39:35 2009
New Revision: 85936
URL: http://llvm.org/viewvc/llvm-project?rev=85936&view=rev
Log:
Changes requested (avoid getFunction(), avoid Type creation via isVoidTy(), and avoid redundant isFreeCall cases) in feedback to r85176
Modified:
llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
llvm/trunk/lib/VMCore/Instruction.cpp
Modified: llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryBuiltins.cpp?rev=85936&r1=85935&r2=85936&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryBuiltins.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryBuiltins.cpp Tue Nov 3 14:39:35 2009
@@ -33,16 +33,14 @@
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 @@
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;
Modified: llvm/trunk/lib/VMCore/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instruction.cpp?rev=85936&r1=85935&r2=85936&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Instruction.cpp (original)
+++ llvm/trunk/lib/VMCore/Instruction.cpp Tue Nov 3 14:39:35 2009
@@ -303,32 +303,6 @@
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 @@
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 @@
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 @@
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())) {
More information about the llvm-commits
mailing list