This is an archive of the discontinued LLVM Phabricator instance.

[DIBuilder] Add a more fine-grained finalization method
ClosedPublic

Authored by loladiro on May 30 2017, 5:26 PM.

Details

Summary

Clang wants to clone a function before it is done building the entire
compilation unit. As of now, there is no good way to do that, because
CloneFunction doesn't like dealing with temporary metadata. However,
as long as clang doesn't want to add any variables to this SP, it
should be fine to just prematurely finalize it. Add an API to allow this.

This is done in preparation of a clang commit to fix the assertion that
necessitated the revert of D33655.

Event Timeline

loladiro created this revision.May 30 2017, 5:26 PM
aprantl edited edge metadata.May 31 2017, 9:01 AM

I was a bit scared by the description at first, but this is safe. Will you only invoke it on functions to be cloned in clang or on all subprograms?

include/llvm/IR/DIBuilder.h
91

I wonder if finalizeVariable(DISubprogram *SP) would be a more accurate name?

91

finalizeVariable*s*.

Will you only invoke it on functions to be cloned in clang or on all subprograms?

D33705 is the clang part of this. @dblaikie had some concerns (on the mailing list) - I had it only call it on cloned subprogram, but @dblaikie thought it might be more natural to call it immediately when irgen is done.

As for the name, I don't think finalizeVariables is necessarily a great name, because the semantics I want is that there's no temporary nodes left in that SP. Right now that might only be variables, but in the feature if there are ever others, I'd want this function to finalize those as well. I'm fine either way though.

https://reviews.llvm.org/D33705 is the clang part of this. @dblaikie had some concerns (on the mailing list) - I had it only call it on cloned subprogram, but @dblaikie thought it might be more natural to call it immediately when irgen is done.

I couldn't find the thread — yes that was what I was wondering, too. It looks like AllSubprograms is only used for this purpose and if there is a natural point where to invoke finalize on each SP after IRGen, then this may be better. But it may also complicate all frontends needlessly so I am not sure whether this is a good trade-off. I guess I can be swayed either way.

include/llvm/IR/DIBuilder.h
91

Ok, then how about finalizeSubprogram()?

loladiro updated this revision to Diff 100887.May 31 2017, 10:51 AM

finalizeSP -> finalizeSubprogram

I don't think there's really a natural place in DIBuilder to do this, but
I suspect that most frontends would have one.

aprantl accepted this revision.May 31 2017, 4:21 PM

I'm fine with this change. I'm fine with either expecting the frontends to manually call finalize on each subprogram or with having DIBuilder do it. But let's have that discussion over in https://reviews.llvm.org/D33705.

This revision is now accepted and ready to land.May 31 2017, 4:21 PM
This revision was automatically updated to reflect the committed changes.