Skip to content

Commit e84589c

Browse files
committed
Specialize OwningOpRef::operator-> to work with pointers like Operation*
This just simplifies user code. Differential Revision: https://reviews.llvm.org/D151407
1 parent 3b0106f commit e84589c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

mlir/include/mlir/IR/OwningOpRef.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ class OwningOpRef {
4949
/// Allow accessing the internal op.
5050
OpTy get() const { return op; }
5151
OpTy operator*() const { return op; }
52-
OpTy *operator->() { return &op; }
52+
auto operator->() {
53+
// Specialize for the case where OpTy is a pointer, to allow using
54+
// OwningOpRef<Operation*>.
55+
if constexpr (std::is_pointer<OpTy>::value)
56+
return op;
57+
else
58+
return &op;
59+
}
5360
explicit operator bool() const { return op; }
5461

5562
/// Downcast to generic operation.

mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,13 +1322,13 @@ lsp::MLIRServer::convertFromBytecode(const URIForFile &uri) {
13221322
// Extract the top-level op so that aliases get printed.
13231323
// FIXME: We should be able to enable aliases without having to do this!
13241324
OwningOpRef<Operation *> topOp = &parsedBlock.front();
1325-
(*topOp)->remove();
1325+
topOp->remove();
13261326

13271327
AsmState state(*topOp, OpPrintingFlags().enableDebugInfo().assumeVerified(),
13281328
/*locationMap=*/nullptr, &fallbackResourceMap);
13291329

13301330
llvm::raw_string_ostream os(result.output);
1331-
(*topOp)->print(os, state);
1331+
topOp->print(os, state);
13321332
}
13331333
return std::move(result);
13341334
}

0 commit comments

Comments
 (0)