<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Fixed in <span class="Apple-style-span" style="font-size: 12px; font-weight: bold; ">r85936.</span><div><b><br></b></div><div><span class="Apple-style-span" style="font-size: 12px; "></span><b>Victor</b></div><div><b><br></b><div><div>On Nov 2, 2009, at 9:36 PM, Chris Lattner wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>On Oct 26, 2009, at 4:43 PM, Victor Hernandez wrote:<br><br><blockquote type="cite">Author: hernande<br></blockquote><blockquote type="cite">Date: Mon Oct 26 18:43:48 2009<br></blockquote><blockquote type="cite">New Revision: 85176<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=85176&view=rev">http://llvm.org/viewvc/llvm-project?rev=85176&view=rev</a><br></blockquote><blockquote type="cite">Log:<br></blockquote><blockquote type="cite">Remove FreeInst.<br></blockquote><blockquote type="cite">Remove LowerAllocations pass.<br></blockquote><blockquote type="cite">Update some more passes to treate free calls just like they were treating FreeInst.<br></blockquote><br>Thanks Victor,<br><br><blockquote type="cite"><br></blockquote><blockquote type="cite">==============================================================================<br></blockquote><blockquote type="cite">--- llvm/trunk/lib/VMCore/Instruction.cpp (original)<br></blockquote><br><blockquote type="cite">+// Code here matches isFreeCall from MallocHelper, which is not in VMCore.<br></blockquote><blockquote type="cite">+static bool isFreeCall(const Value* I) {<br></blockquote><blockquote type="cite">+  const CallInst *CI = dyn_cast<CallInst>(I);<br></blockquote><blockquote type="cite">+  if (!CI)<br></blockquote><blockquote type="cite">+    return false;<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  const Module* M = CI->getParent()->getParent()->getParent();<br></blockquote><blockquote type="cite">+  Function *FreeFunc = M->getFunction("free");<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  if (CI->getOperand(0) != FreeFunc)<br></blockquote><blockquote type="cite">+    return false;<br></blockquote><br>Please use something like this, which would be much more efficient:<br><br>  const CallInst *CI = dyn_cast<CallInst>(I);<br>  if (!CI)<br>    return false;<br>  Function *Callee = CI->getCalledFunction();<br>  if (Callee == 0 || !Callee->isDeclaration() || Callee->getName() != "free")<br>    return false;<br><br><br><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  // Check free prototype.<br></blockquote><blockquote type="cite">+  // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin<br></blockquote><blockquote type="cite">+  // attribute will exist.<br></blockquote><blockquote type="cite">+  const FunctionType *FTy = FreeFunc->getFunctionType();<br></blockquote><blockquote type="cite">+  if (FTy->getReturnType() != Type::getVoidTy(M->getContext()))<br></blockquote><br>Use ->isVoidTy() instead of comparing against a newly constructed type.<br><br><blockquote type="cite">/// mayReadFromMemory - Return true if this instruction may read memory.<br></blockquote><blockquote type="cite">///<br></blockquote><blockquote type="cite">bool Instruction::mayReadFromMemory() const {<br></blockquote><blockquote type="cite">  switch (getOpcode()) {<br></blockquote><blockquote type="cite">  default: return false;<br></blockquote><blockquote type="cite">-  case Instruction::Free:<br></blockquote><blockquote type="cite">  case Instruction::VAArg:<br></blockquote><blockquote type="cite">  case Instruction::Load:<br></blockquote><blockquote type="cite">    return true;<br></blockquote><blockquote type="cite">  case Instruction::Call:<br></blockquote><blockquote type="cite">+    if (isFreeCall(this))<br></blockquote><blockquote type="cite">+      return true;<br></blockquote><blockquote type="cite">    return !cast<CallInst>(this)->doesNotAccessMemory();<br></blockquote><br>This call to isFreeCall isn't needed because the existing code works for it.<br><br><blockquote type="cite">  case Instruction::Invoke:<br></blockquote><blockquote type="cite">    return !cast<InvokeInst>(this)->doesNotAccessMemory();<br></blockquote><blockquote type="cite">@@ -326,11 +352,12 @@<br></blockquote><blockquote type="cite">bool Instruction::mayWriteToMemory() const {<br></blockquote><blockquote type="cite">  switch (getOpcode()) {<br></blockquote><blockquote type="cite">  default: return false;<br></blockquote><blockquote type="cite">-  case Instruction::Free:<br></blockquote><blockquote type="cite">  case Instruction::Store:<br></blockquote><blockquote type="cite">  case Instruction::VAArg:<br></blockquote><blockquote type="cite">    return true;<br></blockquote><blockquote type="cite">  case Instruction::Call:<br></blockquote><blockquote type="cite">+    if (isFreeCall(this))<br></blockquote><blockquote type="cite">+      return true;<br></blockquote><blockquote type="cite">    return !cast<CallInst>(this)->onlyReadsMemory();<br></blockquote><br>Likewise.  I removed some other ones that are not needed.<br><br>-Chris<br></div></blockquote></div><br></div></body></html>