[llvm-commits] annotate known function declarations in SimplifyLibCalls pass
Nick Lewycky
nicholas at mxc.ca
Sun Jan 4 12:09:19 PST 2009
Duncan Sands wrote:
> Hi Nick,
>
>
>> + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
>> + Function &F = *I;
>> + const FunctionType *FTy = F.getFunctionType();
>>
>
> probably you only want to consider function declarations, not those
> with bodies.
>
>
Done.
>> + if (NameLen == 6 && !strcmp(NameStr, "strlen")) {
>> + if (FTy->getNumParams() == 0 ||
>>
>
> Shouldn't this be "FTy->getNumParams() != 1"?
>
>
>> + if (!F.paramHasAttr(1, Attribute::NoCapture)) {
>>
>
> How about adding a "doesNotCapture" convenience method?
>
>
Done.
>> + F.addAttribute(1, Attribute::NoCapture);
>>
>
> How about adding setDoesNotCapture too.
>
>
>> + if (FTy->getNumParams() < 2 ||
>>
>
> Shouldn't this be != 2? OK, I guess some take an extra argument.
> But then shouldn't the type of the extra argument be checked?
>
>
When this pass is run, we're allowed to assume that the functions are
meant to be the well-known ones. The point of the test is to prevent
crashes if somebody forgets their #include and we end up with a .ll like:
declare i32 @strlen(...)
and we'd crash trying to mark the first parameter as nocapture. There's
no need to test any parameters we aren't modifying, so I happily merge
cases where functions have different number of parameters so long as
we're doing the same thing with them.
> Otherwise looks good, except for the lack of a testcase.
>
>
Right! I'll write one and submit.
Thanks!
Nick
More information about the llvm-commits
mailing list