This is an archive of the discontinued LLVM Phabricator instance.

Implement __attribute__((gc_leaf_function)).
AbandonedPublic

Authored by mjacob on Jan 8 2016, 10:37 AM.

Details

Summary

This attribute can be applied to functions, and results in declarations and
calls of the function have the "gc-leaf-function" LLVM IR attribute.

Diff Detail

Event Timeline

mjacob updated this revision to Diff 44337.Jan 8 2016, 10:37 AM
mjacob retitled this revision from to Implement __attribute__((gc_leaf_function))..
mjacob updated this object.
mjacob added reviewers: reames, sanjoy.
reames edited edge metadata.Jan 11 2016, 5:17 PM

Neither Sanjoy or I are qualified to review a clang patch. You'll need to find clang reviewers.

Also, before this gets exposed through Clang, we really should formalize/document the attribute. In practice, it implies the lack of a safepoint poll site inside the called function. Annoyingly, it's not an inferable property since we don't represent the possible insertion of a poll in the IR.

Hm. This makes me wonder... We've moved to a model of inserting safepoints (specifically for deopt info) early, and then rewriting late in our tree. We're not even using the PlaceSafepoints pass any more. It's been left mostly for other users. Would it maybe make sense to fully retire PlaceSafepoints and migrate over to a scheme where safepoints sites are explicit from the beginning? This would allow us to infer "gc-leaf" from FunctionAttrs...

(This high level discussion should probably move to llvm-dev. I can start it if you'd like, otherwise post something and I'll reply.)

This change looks fine modulo the documentation issue.

include/clang/Basic/Attr.td
2177

@aaron.ballman prefers that all attributes we add have some documentation. This documentation would live in AttrDocs.td.

Also, before this gets exposed through Clang, we really should formalize/document the attribute. In practice, it implies the lack of a safepoint poll site inside the called function. Annoyingly, it's not an inferable property since we don't represent the possible insertion of a poll in the IR.

That wouldn't work for my language since it doesn't use polls at all. Instead, a practical definition would be: "a statepoint will not be inserted if the call site or callee has this attribute". My language backend currently relies on this, e.g. if calling printf (currently statepoints don't support vararg callees).

Hm. This makes me wonder... We've moved to a model of inserting safepoints (specifically for deopt info) early, and then rewriting late in our tree. We're not even using the PlaceSafepoints pass any more. It's been left mostly for other users. Would it maybe make sense to fully retire PlaceSafepoints and migrate over to a scheme where safepoints sites are explicit from the beginning? This would allow us to infer "gc-leaf" from FunctionAttrs...

With explicit safepoints and the above-mentioned definition the gc-leaf-funtion attribute wouldn't be necessary at all, because then a function is a GC leaf if and only if no safepoint should be inserted when calling this function.

(This high level discussion should probably move to llvm-dev. I can start it if you'd like, otherwise post something and I'll reply.)

I think it makes more sense if you start the discussion because I'm not familiar with your use cases (I only use a subset of safepoint functionality, e.g. no safepoint polls).

Can you point me to some documentation on what the semantics of this attribute are? For instance, how does it play with other attributes (like naked or dllexport), is there a reason it shouldn't apply to Objective-C methods, etc?

include/clang/Basic/Attr.td
2175

Any particular reason for this to not have a C++11 spelling under the clang namespace, in addition to the GNU-style spelling?

Can you point me to some documentation on what the semantics of this attribute are? For instance, how does it play with other attributes (like naked or dllexport), is there a reason it shouldn't apply to Objective-C methods, etc?

As it was noted earlier in this review, this attribute (as its underlying LLVM attribute) is underspecified. We should discuss the semantics (and whether we want to keep it in the first place) of the LLVM attribute on the mailing list. I'm not sure how we should proceed with this patch in the meantime, probably one of:

  1. Mark this (Clang) attribute as tentative, and remove it in case we remove the LLVM attribute.
  2. Close this revision and create a new patch depending on the outcome of the discussion.
  3. Postpone (but not close) this revision.
include/clang/Basic/Attr.td
2175

I'll add this in case we decide the attribute is the right approach.

Can you point me to some documentation on what the semantics of this attribute are? For instance, how does it play with other attributes (like naked or dllexport), is there a reason it shouldn't apply to Objective-C methods, etc?

As it was noted earlier in this review, this attribute (as its underlying LLVM attribute) is underspecified. We should discuss the semantics (and whether we want to keep it in the first place) of the LLVM attribute on the mailing list. I'm not sure how we should proceed with this patch in the meantime, probably one of:

  1. Mark this (Clang) attribute as tentative, and remove it in case we remove the LLVM attribute.
  2. Close this revision and create a new patch depending on the outcome of the discussion.
  3. Postpone (but not close) this revision.

Given how relatively easy this patch is at this stage, I would recommend #2 if the LLVM side of the discussion is going to take more than a month, and #3 otherwise.

sanjoy resigned from this revision.Feb 10 2016, 9:25 PM
sanjoy removed a reviewer: sanjoy.

Resigning for now to make my "Revisions Waiting on You" queue less noisy. Please don't hesitate to add me back if this or a variant of this change becomes active.

mjacob abandoned this revision.Feb 11 2016, 9:54 AM

I experimented with another approach in the meantime.