Deduce "nofree" function attribute. A more concise description of "nofree" is on D49165.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Are langref changes missing?
How do these attributes get documented there?
llvm/include/llvm/IR/Attributes.td | ||
---|---|---|
205 | Can this please be more explanatory? | |
llvm/lib/Transforms/IPO/Attributor.cpp | ||
186 | StringRef | |
1089 | Hm, there is no .empty() ? |
Please make this depend on the no-free patch by @hfinkel. We should also see if we extract the definition from there or if he plans to work on that patch further.
Some comments inlined.
I don't know why we would need TLI here but could you split the addition of it so we have it for the future.
llvm/lib/Transforms/IPO/Attributor.cpp | ||
---|---|---|
187 | We want an llvm::StringSwitch here. We could also move the whole bookkeeping into the AbstractAttributes. That might actually be nicer. | |
724 | Please add bool isAssumedNoFree() and bool isKnownNoFree(). | |
759 | You can directly get the AnchorScope | |
771 | I don't see why we'd need this conditional (and the Realloc check). | |
800 | No need for the assert, and if you want one, add a message. | |
801 | You can make safe indention if you continue for nofree call sites. Though, I don't see why we should check the attribute in the first place. The following check is what we want. | |
803 | Please add || !NoFreeAA->isAssumedNoFree() for concistency. Revert the condition for less indented code. | |
810 | There is no fixpoint reached here, at least not if getAAFor was called at least once! Just remove the line and let the framework determine this for you. |
You misunderstood, there is absolutely no need to apologize. I like the patch and it is totally normal that I have comments now.
This is the first patch to a new framework and I have a lot of thoughts in my head how the code should look like/interact with the rest.
The patch is almost ready as far as I can tell, I added some (mostly minor) comments though.
Did you actually run the pass and try it on the test case you have? The changes to the test case should be part of this patch (pretend the test cases are already in tree).
llvm/lib/Transforms/IPO/Attributor.cpp | ||
---|---|---|
717 | If you make it a struct you don't need the public anymore. | |
732 | Comment and new line pls. | |
752 | Comments please. | |
770 | Do we have any intrinsic that might free memory? I would need to double check but I don't think we have one. | |
801 | My other two comments were confusing and I should have explained this better. The idea (I have) is: | |
976 | Please add an assert here to make sure we did not miss any CallBase instruction opcode. |
llvm/lib/Transforms/IPO/Attributor.cpp | ||
---|---|---|
770 | I think so too. However, I have one concern. There are some intrinsic related to GC and I can not be sure whether these intrinsic wouldn't free memory. | |
801 | I have a question about this. declare void @nofree_function() "nofree" define void @call_nofree_function() { tail call void @nofree_function() ret void } |
Almost there, partially because I didn't think certain problems through, see inlined comments.
The test changes are still missing.
llvm/lib/Transforms/IPO/Attributor.cpp | ||
---|---|---|
770 | That is a good point. Let's do the following:
| |
801 | Good point, very good point. Let's agree that I was wrong for now and you add back the ImmutableCallSite attribute check. |
The test changes are still missing.
Oh, I missed it. I'm now writing this but I'm in trouble.
In D62313, you said that it is preferable to write a test like this:
; CHECK: Function Attrs: noinline norecurse nounwind readnone uwtable ; CHECK-NEXT: define double* @ret_undef_arg_undef(i32* readnone %b)
However, I think this format would not work for string attribute, isn't it?
I honestly do not know, if it is not, you need to choose a way that works. If you find that difficult, let me know. (Do not delete the checks but remove the CHECK part or rename it).
Last comments wrt the test cases. I hope D62784 is uncontroversial and we can use the Function Attr: check lines. That is the last change I'd like to see.
llvm/test/Transforms/FunctionAttrs/nofree.ll | ||
---|---|---|
32 ↗ | (On Diff #202553) | Assuming I can land D62784, you can check for "nofree" as you do for the FNATTR attributes. Use -NEXT: for the define lines so you make sure that you check the attributes of that definition. Use -NOT: nofree for the negative test cases to make sure we do not derive it. |
174 ↗ | (On Diff #202553) | Great! |
I hope D62784 is uncontroversial and we can use the Function Attr: check lines.
Thanks. It works.
This depends on three other patches now but once they are in, this one can go in as well. LGTM.
Can you make the test use an enum version, thus nofree not "nofree".
llvm/include/llvm/IR/Attributes.td | ||
---|---|---|
206 | Remove this line please. |
Once the test file is in, rebase this one and make sure ninja check-all works before you commit it. Also, there is a leftover FIXME in the code.
llvm/lib/Transforms/IPO/Attributor.cpp | ||
---|---|---|
455 | Leftover comment. |
Can this please be more explanatory?
I can read this as "free() isn't being called", "all calls here are non-free (as in non-cheap)" etc