Add support for getting the operand number from an IROperandImpl(InstOperand, BasicBl...
authorRiver Riddle <riverriddle@google.com>
Tue, 20 Nov 2018 19:07:58 +0000 (11:07 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 21:03:05 +0000 (14:03 -0700)
PiperOrigin-RevId: 222274598

mlir/include/mlir/IR/UseDefLists.h
mlir/lib/IR/Instructions.cpp
mlir/lib/IR/Statement.cpp

index bf7b34b49a8388eb0669d105ea3818ba6c37c99b..0f54beff93eb69001ae043a4b00fba9b44f09270 100644 (file)
@@ -215,7 +215,7 @@ public:
   }
 
   /// Return which operand this is in the operand list of the User.
-  // TODO:  unsigned getOperandNumber() const;
+  unsigned getOperandNumber() const;
 
   /// We support a move constructor so IROperand's can be in vectors, but this
   /// shouldn't be used by general clients.
index 059637b986a9225a16980b6d75d134bf808b9046..d1e3aab3d05068e84ebfbeae79ff6e6fb04ee51a 100644 (file)
@@ -37,6 +37,16 @@ unsigned InstResult::getResultNumber() const {
   return this - &getOwner()->getInstResults()[0];
 }
 
+/// Return which operand this is in the operand list.
+template <> unsigned InstOperand::getOperandNumber() const {
+  return this - &getOwner()->getInstOperands()[0];
+}
+
+/// Return which operand this is in the operand list.
+template <> unsigned BasicBlockOperand::getOperandNumber() const {
+  return this - &getOwner()->getBasicBlockOperands()[0];
+}
+
 //===----------------------------------------------------------------------===//
 // Instruction
 //===----------------------------------------------------------------------===//
index f79432b5af9b582e08f6752e772c1c44afe5d279..b7cd48886fefad9c390b00e9b1ccde4799854288 100644 (file)
@@ -38,6 +38,15 @@ unsigned StmtResult::getResultNumber() const {
   return this - &getOwner()->getStmtResults()[0];
 }
 
+//===----------------------------------------------------------------------===//
+// StmtOperand
+//===------------------------------------------------------------------===//
+
+/// Return which operand this is in the operand list.
+template <> unsigned StmtOperand::getOperandNumber() const {
+  return this - &getOwner()->getStmtOperands()[0];
+}
+
 //===----------------------------------------------------------------------===//
 // Statement
 //===------------------------------------------------------------------===//