[cleanup] Add a getOperandNo method to the Use class and implement it
authorChandler Carruth <chandlerc@gmail.com>
Tue, 4 Mar 2014 09:19:43 +0000 (09:19 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 4 Mar 2014 09:19:43 +0000 (09:19 +0000)
out-of-line so that it can refer to the methods on User. As
a consequence, this removes the need to define one template method if
value_use_iterator in the extremely strange User.h header (!!!).

This makse Use.h slightly less peculiar. The only remaining real
peculiarity is the definition of Use::set in Value.h

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202805 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Use.h
include/llvm/IR/User.h
lib/IR/Use.cpp

index 62586f5b3d82be8251ff582b3448f1b4f5fe48d6..37967f8c0232f0b30c24e2116ea220ff2f1bffb5 100644 (file)
@@ -116,6 +116,9 @@ public:
 
   Use *getNext() const { return Next; }
 
+  /// \brief Return the operand # of this use in its User.
+  unsigned getOperandNo() const;
+
   /// \brief Initializes the waymarking tags on an array of Uses.
   ///
   /// This sets up the array of Uses such that getUser() can find the User from
@@ -208,9 +211,8 @@ public:
   Use &getUse() const { return *U; }
 
   /// \brief Return the operand # of this use in its User.
-  ///
-  /// Defined in User.h
-  unsigned getOperandNo() const;
+  /// FIXME: Replace all callers with a direct call to Use::getOperandNo.
+  unsigned getOperandNo() const { return U->getOperandNo(); }
 };
 
 // Create wrappers for C Binding types (see CBindingWrapping.h).
index 4f8d1b35df96faa2c33881492f196142e5e4bbc4..d288e1908c2f6581d204eedf0f6bd1fe03a19a96 100644 (file)
@@ -206,12 +206,6 @@ template<> struct simplify_type<User::const_op_iterator> {
   }
 };
 
-// value_use_iterator::getOperandNo - Requires the definition of the User class.
-template<typename UserTy>
-unsigned value_use_iterator<UserTy>::getOperandNo() const {
-  return U - U->getUser()->op_begin();
-}
-
 } // End llvm namespace
 
 #endif
index 5f01e238e04f711e74ac6db6cf9a275dbed5ef21..60a0c5668890fc686c57a320a5ae12588f6b95dd 100644 (file)
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/Use.h"
+#include "llvm/IR/User.h"
 #include "llvm/IR/Value.h"
 #include <new>
 
@@ -44,6 +45,10 @@ User *Use::getUser() const {
                        : reinterpret_cast<User *>(const_cast<Use *>(End));
 }
 
+unsigned Use::getOperandNo() const {
+  return this - getUser()->op_begin();
+}
+
 // Sets up the waymarking algoritm's tags for a series of Uses. See the
 // algorithm details here:
 //