[Mlir-commits] [mlir] 1333147 - Make OpOperand constructor private (NFC)

Mehdi Amini llvmlistbot at llvm.org
Mon Jun 15 13:28:27 PDT 2020


Author: Mehdi Amini
Date: 2020-06-15T20:28:07Z
New Revision: 13331477c0d1aeb8f3c9f24b3d0487bc6fcaa225

URL: https://github.com/llvm/llvm-project/commit/13331477c0d1aeb8f3c9f24b3d0487bc6fcaa225
DIFF: https://github.com/llvm/llvm-project/commit/13331477c0d1aeb8f3c9f24b3d0487bc6fcaa225.diff

LOG: Make OpOperand constructor private (NFC)

This is intended to avoid programming mistake where a temporary OpOperand is
created, for example:

        for (OpOperand user : result.getUsers()) {

It can be confusing for the user, in particular since in MLIR most classes are intended to
be copied around by value while they have reference semantics.

Differential Revision: https://reviews.llvm.org/D81815

Added: 
    

Modified: 
    mlir/include/mlir/IR/UseDefLists.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/UseDefLists.h b/mlir/include/mlir/IR/UseDefLists.h
index 1a6319d2b2e8..de74b01e1391 100644
--- a/mlir/include/mlir/IR/UseDefLists.h
+++ b/mlir/include/mlir/IR/UseDefLists.h
@@ -249,8 +249,6 @@ class OpaqueValue {
 /// contain a reference to a specific `Value`.
 class OpOperand : public IROperand<OpOperand, detail::OpaqueValue> {
 public:
-  using IROperand<OpOperand, detail::OpaqueValue>::IROperand;
-
   /// Provide the use list that is attached to the given value.
   static IRObjectWithUseList<OpOperand> *getUseList(Value value);
 
@@ -262,6 +260,12 @@ class OpOperand : public IROperand<OpOperand, detail::OpaqueValue> {
 
   /// Return which operand this is in the operand list of the User.
   unsigned getOperandNumber();
+
+private:
+  /// Keep the constructor private and accessible to the OperandStorage class
+  /// only to avoid hard-to-debug typo/programming mistakes.
+  friend class OperandStorage;
+  using IROperand<OpOperand, detail::OpaqueValue>::IROperand;
 };
 
 //===----------------------------------------------------------------------===//


        


More information about the Mlir-commits mailing list