[PATCH] D133650: [BOLT] Stop using std::iterator (NFC)

Kazu Hirata via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 10 13:39:29 PDT 2022


kazu created this revision.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a project: All.
kazu requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

With this patch, I get warnings like:

  bolt/include/bolt/Core/BinaryContext.h:108:19: error:
  'iterator<std::bidirectional_iterator_tag,
  llvm::bolt::BinarySection>' is deprecated
  [-Werror,-Wdeprecated-declarations]

This patch fixes those warnings by defining iterator_category,
value_type, etc.

This patch intentionally leaves duplicate types like FilterIterator::T
and FilterIterator::PointerT intact to avoid mixing the fix and the
cleanup.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133650

Files:
  bolt/include/bolt/Core/BinaryContext.h
  bolt/include/bolt/Core/MCPlusBuilder.h
  bolt/include/bolt/Passes/DataflowAnalysis.h


Index: bolt/include/bolt/Passes/DataflowAnalysis.h
===================================================================
--- bolt/include/bolt/Passes/DataflowAnalysis.h
+++ bolt/include/bolt/Passes/DataflowAnalysis.h
@@ -439,13 +439,18 @@
 /// Define an iterator for navigating the expressions calculated by a
 /// dataflow analysis at each program point, when they are backed by a
 /// BitVector.
-class ExprIterator
-    : public std::iterator<std::forward_iterator_tag, const MCInst *> {
+class ExprIterator {
   const BitVector *BV;
   const std::vector<MCInst *> &Expressions;
   int Idx;
 
 public:
+  using iterator_category = std::forward_iterator_tag;
+  using value_type = const MCInst *;
+  using difference_type = std::ptrdiff_t;
+  using pointer = value_type *;
+  using reference = value_type &;
+
   ExprIterator &operator++() {
     assert(Idx != -1 && "Iterator already at the end");
     Idx = BV->find_next(Idx);
Index: bolt/include/bolt/Core/MCPlusBuilder.h
===================================================================
--- bolt/include/bolt/Core/MCPlusBuilder.h
+++ bolt/include/bolt/Core/MCPlusBuilder.h
@@ -164,9 +164,14 @@
   void setTailCall(MCInst &Inst);
 
 public:
-  class InstructionIterator
-      : public std::iterator<std::bidirectional_iterator_tag, MCInst> {
+  class InstructionIterator {
   public:
+    using iterator_category = std::bidirectional_iterator_tag;
+    using value_type = MCInst;
+    using difference_type = std::ptrdiff_t;
+    using pointer = value_type *;
+    using reference = value_type &;
+
     class Impl {
     public:
       virtual Impl *Copy() const = 0;
Index: bolt/include/bolt/Core/BinaryContext.h
===================================================================
--- bolt/include/bolt/Core/BinaryContext.h
+++ bolt/include/bolt/Core/BinaryContext.h
@@ -104,9 +104,8 @@
 /// Filter iterator.
 template <typename ItrType,
           typename PredType = std::function<bool(const ItrType &)>>
-class FilterIterator
-    : public std::iterator<std::bidirectional_iterator_tag,
-                           typename std::iterator_traits<ItrType>::value_type> {
+class FilterIterator {
+  using inner_traits = std::iterator_traits<ItrType>;
   using Iterator = FilterIterator;
   using T = typename std::iterator_traits<ItrType>::reference;
   using PointerT = typename std::iterator_traits<ItrType>::pointer;
@@ -128,6 +127,12 @@
   }
 
 public:
+  using iterator_category = std::bidirectional_iterator_tag;
+  using value_type = typename inner_traits::value_type;
+  using difference_type = typename inner_traits::difference_type;
+  using pointer = typename inner_traits::pointer;
+  using reference = typename inner_traits::reference;
+
   Iterator &operator++() { next(); return *this; }
   Iterator &operator--() { prev(); return *this; }
   Iterator operator++(int) { auto Tmp(Itr); next(); return Tmp; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133650.459310.patch
Type: text/x-patch
Size: 2881 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220910/064bfbf2/attachment.bin>


More information about the llvm-commits mailing list