[llvm-commits] [llvm] r85176 - in /llvm/trunk: examples/BrainF/ include/llvm-c/ include/llvm/ include/llvm/Analysis/ include/llvm/Support/ include/llvm/Transforms/ lib/Analysis/ lib/Analysis/IPA/ lib/AsmParser/ lib/Bitcode/Writer/ lib/CodeGen/SelectionDAG/ lib/ExecutionEngine/Interpreter/ lib/Target/CBackend/ lib/Target/CppBackend/ lib/Target/MSIL/ lib/Transforms/Scalar/ lib/Transforms/Utils/ lib/VMCore/
Chris Lattner
clattner at apple.com
Mon Nov 2 21:36:14 PST 2009
On Oct 26, 2009, at 4:43 PM, Victor Hernandez wrote:
> Author: hernande
> Date: Mon Oct 26 18:43:48 2009
> New Revision: 85176
>
> URL: http://llvm.org/viewvc/llvm-project?rev=85176&view=rev
> Log:
> Remove FreeInst.
> Remove LowerAllocations pass.
> Update some more passes to treate free calls just like they were
> treating FreeInst.
Thanks Victor,
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/VMCore/Instruction.cpp (original)
> +// Code here matches isFreeCall from MallocHelper, 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;
Please use something like this, which would be much more efficient:
const CallInst *CI = dyn_cast<CallInst>(I);
if (!CI)
return false;
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()))
Use ->isVoidTy() instead of comparing against a newly constructed type.
> /// mayReadFromMemory - Return true if this instruction may read
> memory.
> ///
> bool Instruction::mayReadFromMemory() const {
> switch (getOpcode()) {
> default: return false;
> - case Instruction::Free:
> case Instruction::VAArg:
> case Instruction::Load:
> return true;
> case Instruction::Call:
> + if (isFreeCall(this))
> + return true;
> return !cast<CallInst>(this)->doesNotAccessMemory();
This call to isFreeCall isn't needed because the existing code works
for it.
> case Instruction::Invoke:
> return !cast<InvokeInst>(this)->doesNotAccessMemory();
> @@ -326,11 +352,12 @@
> bool Instruction::mayWriteToMemory() const {
> switch (getOpcode()) {
> default: return false;
> - case Instruction::Free:
> case Instruction::Store:
> case Instruction::VAArg:
> return true;
> case Instruction::Call:
> + if (isFreeCall(this))
> + return true;
> return !cast<CallInst>(this)->onlyReadsMemory();
Likewise. I removed some other ones that are not needed.
-Chris
More information about the llvm-commits
mailing list