[LLVMdev] malloc vs malloc
Chris Lattner
clattner at apple.com
Mon Jan 12 20:29:21 PST 2009
On Jan 12, 2009, at 7:45 PM, Nick Lewycky wrote:
>> isa<FreeInst>(X) can be replaced with:
>>
>> bool isFree(Instruction *X) {
>> if (CallInst *CI = dyn_cast<CallInst>(X))
>> if (Function *F = CI->getCalledFunction())
>> if (F->isName("free") && F->hasExternalLinkage())
>
> Surely you mean "llvm.free" or something, right? I don't think we want
> to start assigning meaning to otherwise arbitrary function names.
No, I mean "free". Dan Gohman and I discussed this today. A short
version in no particular order is:
1) in practice, IMO, everyone building for user space has libc in
their address space, even if they are supporting some non-C language
like haskell or ocaml or something.
2) in practice, IMO, if an app is in kernel space or embedded, if they
use a symbol (e.g. printf) it almost certainly does what ansi says it
does.
3) I really think the functionality of simplifylibcalls should be
moved into instcombine someday, so that it is run more than once and
is iterative.
4) we want other passes to be able to optimize libcalls. For example,
the stuff I added in r61918 requires GVN or memcpyopt to optimize
things like strlen.
5) regardless of #1/2, we want to support things like -fno-builtin-
free someday. -ffree-standing would also imply this sort of thing, as
would -fno-builtins etc.
6) there are other routines that we want to make assumptions about,
that are almost certainly true, but are not standard conformant. I'm
thinking things like "operator new is sane and thus the result is
noalias". This specific example should be controlled by something
like -foperator-new-is-sane, and probably default to on.
To me, there are two solutions. One bad solution, for various
reasons, is to create an llvm.foo for every foo function we want to
optimize. IMO, a better solution is to introduce *one* new function
attribute "is normal" or "may not be normal" (name suggestions
welcome, pick your parity) which can be set on a function. All
existing libcall optimization stuff would be predicated on the
function being named the right thing, external, and "normal". This
would allow language independent optimizations like instcombine to do
this stuff.
-Chris
More information about the llvm-dev
mailing list