From 85f86ca2034c370ae7dac5fb8a29e4219be55219 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Tue, 20 Nov 2018 11:07:58 -0800 Subject: [PATCH] Add support for getting the operand number from an IROperandImpl(InstOperand, BasicBlockOperand, StmtOperand). PiperOrigin-RevId: 222274598 --- mlir/include/mlir/IR/UseDefLists.h | 2 +- mlir/lib/IR/Instructions.cpp | 10 ++++++++++ mlir/lib/IR/Statement.cpp | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mlir/include/mlir/IR/UseDefLists.h b/mlir/include/mlir/IR/UseDefLists.h index bf7b34b49a83..0f54beff93eb 100644 --- a/mlir/include/mlir/IR/UseDefLists.h +++ b/mlir/include/mlir/IR/UseDefLists.h @@ -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. diff --git a/mlir/lib/IR/Instructions.cpp b/mlir/lib/IR/Instructions.cpp index 059637b986a9..d1e3aab3d050 100644 --- a/mlir/lib/IR/Instructions.cpp +++ b/mlir/lib/IR/Instructions.cpp @@ -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 //===----------------------------------------------------------------------===// diff --git a/mlir/lib/IR/Statement.cpp b/mlir/lib/IR/Statement.cpp index f79432b5af9b..b7cd48886fef 100644 --- a/mlir/lib/IR/Statement.cpp +++ b/mlir/lib/IR/Statement.cpp @@ -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 //===------------------------------------------------------------------===// -- 2.34.1