This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Remove copy constructor of `RTLInfoTy`
ClosedPublic

Authored by tianshilei1992 on Jan 9 2021, 7:54 AM.

Details

Summary

Multiple RTLInfoTy objects are stored in a list AllRTLs. Since
RTLInfoTy contains a std::mutex, it is by default not a copyable object.
In order to support AllRTLs.push_back(...) which is currently used, a customized
copy constructor is provided. Every time we need to add a new data member into
RTLInfoTy, we should keep in mind not forgetting to add corresponding assignment
in the copy constructor. In fact, the only use of the copy constructor is to push
the object into the list, we can of course write it in a way that first emplace
a new object back, and then use the reference to the last element. In this way we
don't need the copy constructor anymore. If the element is invalid, we just need
to pop it, and that's what this patch does.

Diff Detail

Event Timeline

tianshilei1992 created this revision.Jan 9 2021, 7:54 AM
tianshilei1992 requested review of this revision.Jan 9 2021, 7:54 AM
Herald added a project: Restricted Project. · View Herald Transcript
tianshilei1992 added inline comments.Jan 9 2021, 7:59 AM
openmp/libomptarget/src/rtl.cpp
170–171

The exit logic has a minor issue. Will fix it.

Fixed the continue condition

Added a missing plugin interface

JonChesterfield added a comment.EditedJan 9 2021, 8:36 AM

Delighted to see the copy ctor go. That's an easy place to forget to update. It should probably be explicitly = delete.

Does the move constructor do the right thing on a std::mutex? It'll be called by the vector resizing. Will want it = default after the copy ctor is marked delete iirc.

openmp/libomptarget/src/rtl.cpp
98

A plugin missing one of the required functions is an infrequent error.

I think we can drop all the ValidPlugin && statements to get simpler code that runs faster in the normal case, and does a bunch of unnecessary but harmless dlsym on the failing path.

Dropped ValidPlugin &&

tianshilei1992 marked an inline comment as done.EditedJan 9 2021, 8:57 AM

std::mutex is non-copyable and non-movable. Any struct containing it will be marked non-copyable and non-movable implicitly. Actually I'm not sure how compiler handles this struct because if I explicitly add RTLInfoTy(RTLInfoTy &&) = default and RTLInfoTy(const RTLInfoTy &) = delete, the compiler complains "no matching constructor for initialization of 'RTLInfoTy'". However, everything seems all good if I don't do anything...

tianshilei1992 edited the summary of this revision. (Show Details)Jan 9 2021, 9:17 AM

std::mutex is non-copyable and non-movable. Any struct containing it will be marked non-copyable and non-movable implicitly. Actually I'm not sure how compiler handles this struct because if I explicitly add RTLInfoTy(RTLInfoTy &&) = default and RTLInfoTy(const RTLInfoTy &) = delete, the compiler complains "no matching constructor for initialization of 'RTLInfoTy'". However, everything seems all good if I don't do anything...

Well, stupid me. AllRTLs is a std::list...

JonChesterfield accepted this revision.Jan 9 2021, 9:53 AM

LGTM, thanks!

This revision is now accepted and ready to land.Jan 9 2021, 9:53 AM
This revision was automatically updated to reflect the committed changes.