This is an archive of the discontinued LLVM Phabricator instance.

[IRBuilder] Delete copy constructor
ClosedPublic

Authored by nikic on Feb 16 2020, 9:27 AM.

Details

Summary

Motivated by D73835, where IRBuilder becomes no longer trivially copyable, but I think this also makes sense independently. Currently, it seems that the IRBuilder copy constructor is usually used by accident, not by intention. In rG7c362b25d7a9 I've fixed a number of cases where functions accepted IRBuilder rather than IRBuilder &, thus performing an unnecessary copy. In rG5f7b92b1b4d6 I've fixed cases where an IRBuilder was copied, while an InsertPointGuard should have been used instead.

The only non-trivial use of the copy constructor is the getIRBForDbgInsertion() helper, for which I separated construction and setting of the insertion point in this patch.

Does this make sense?

Diff Detail

Event Timeline

nikic created this revision.Feb 16 2020, 9:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2020, 9:27 AM
Meinersbur added inline comments.Feb 16 2020, 12:36 PM
llvm/lib/IR/DIBuilder.cpp
907–908

Subclassing does not feel like the right approach for this (we might think about marking IRBuilder as final). It's just preconfiguring an IRBuilder. Standard technique would be to return a unique_ptr<IRBuilder> instead.

However, subclassing is more pragmatic here. Other opinions?

nikic updated this revision to Diff 244895.Feb 16 2020, 12:49 PM
nikic edited the summary of this revision. (Show Details)

Use a separate initialization function instead of subclassing IRBuilder.

nikic marked an inline comment as done.Feb 16 2020, 12:51 PM
nikic added inline comments.
llvm/lib/IR/DIBuilder.cpp
907–908

Agree that the subclassing here was pretty odd. I've changed this to instead split up IRBuilder construction and the setting of insert-point/debug-loc. It's one more line of code at the use-site, but this seems cleaner.

Meinersbur accepted this revision.Feb 16 2020, 6:29 PM

Assuming that D73835 goes in, LGTM.

This revision is now accepted and ready to land.Feb 16 2020, 6:29 PM
This revision was automatically updated to reflect the committed changes.