This is an archive of the discontinued LLVM Phabricator instance.

Change setDiagnosticsOutputFile to take a unique_ptr from a raw pointer (NFC)
ClosedPublic

Authored by mehdi_amini on Nov 18 2016, 8:41 PM.

Event Timeline

mehdi_amini retitled this revision from to Change setDiagnosticsOutputFile to take a unique_ptr from a raw pointer (NFC).
mehdi_amini updated this object.
mehdi_amini added a reviewer: anemet.
mehdi_amini added a subscriber: llvm-commits.
malcolm.parsons added inline comments.
llvm/include/llvm/IR/LLVMContext.h
197

Pass by value if always moving doesn't apply to move-only types. Use && to avoid a temporary.

This revision was automatically updated to reflect the committed changes.

Pushed inadvertently with D26886, I'll address the review as post-commit.

llvm/include/llvm/IR/LLVMContext.h
197

Sorry I don't understand this comment?

llvm/include/llvm/IR/LLVMContext.h
197

Functions that accept a parameter by value do so to allow the caller to choose whether to supply an lvalue that is copied or an rvalue that is moved without having to write overloads for both.
For a move-only type there is no choice, so the function should accept an rvalue.
This might avoid the construction and destruction of a temporary.

mehdi_amini added inline comments.Nov 19 2016, 12:44 PM
llvm/include/llvm/IR/LLVMContext.h
197

I see. It does not really sound idiomatic to me to have any unique_ptr passed by rvalue, you should try to submit a patch to the developer guide.

(I'm not really convinced by the "avoid the construction and destruction of a temporary" here, I don't expect the codegen to be any different)

llvm/include/llvm/IR/LLVMContext.h
197

There are a few places where unique_ptrs are passed by rvalue:

llvm/Transforms/Utils/MemorySSA.h
681:    Result(std::unique_ptr<MemorySSA> &&MSSA) : MSSA(std::move(MSSA)) {}

llvm/Support/TargetRegistry.h
77:                                 std::unique_ptr<MCRelocationInfo> &&RelInfo);
112:      TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
157:      std::unique_ptr<MCRelocationInfo> &&RelInfo);
396:                               std::unique_ptr<MCStreamer> &&Streamer) const {
531:                     std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
1125:                               std::unique_ptr<MCStreamer> &&Streamer) {

llvm/Bitcode/BitcodeReader.h
92:  getOwningLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,

but there are lots of places it's passed by value.

There's usually no difference in codegen, but not always:
https://godbolt.org/g/8GoljO
https://godbolt.org/g/CNZzsS

mehdi_amini added inline comments.Nov 28 2016, 2:56 PM
llvm/include/llvm/IR/LLVMContext.h
197

Did you end up submitting a patch for the dev guide for move-only type?

llvm/include/llvm/IR/LLVMContext.h
197
mehdi_amini added inline comments.Nov 29 2016, 9:51 AM
llvm/include/llvm/IR/LLVMContext.h
197

We could still add a guideline for "move-only types other than unique_ptr", however it might not be frequent enough that it is worth codifying it.