Remove use of std::iterator, which is gone in C++20.

These changes remove use in the most straightforward way possible, which
is just to add the iterator type aliases instead.  Upstream LLVM trunk
has also fixed these cases, but not always in the same way.

This also std::-qualifies one call to find() that was only working
before due to ADL on the iterator type.

Bug: chromium:1284275
Change-Id: I64445fbadada8f04c7d03738613308578f7eff4c
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/65588
Tested-by: Peter Kasting <pkasting@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Commit-Queue: Peter Kasting <pkasting@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
diff --git a/third_party/llvm-10.0/llvm/include/llvm/ADT/DepthFirstIterator.h b/third_party/llvm-10.0/llvm/include/llvm/ADT/DepthFirstIterator.h
index 11967f5..0083f78 100644
--- a/third_party/llvm-10.0/llvm/include/llvm/ADT/DepthFirstIterator.h
+++ b/third_party/llvm-10.0/llvm/include/llvm/ADT/DepthFirstIterator.h
@@ -83,9 +83,7 @@
               df_iterator_default_set<typename GraphTraits<GraphT>::NodeRef>,
           bool ExtStorage = false, class GT = GraphTraits<GraphT>>
 class df_iterator
-    : public std::iterator<std::forward_iterator_tag, typename GT::NodeRef>,
-      public df_iterator_storage<SetType, ExtStorage> {
-  using super = std::iterator<std::forward_iterator_tag, typename GT::NodeRef>;
+    : public df_iterator_storage<SetType, ExtStorage> {
   using NodeRef = typename GT::NodeRef;
   using ChildItTy = typename GT::ChildIteratorType;
 
@@ -144,7 +142,11 @@
   }
 
 public:
-  using pointer = typename super::pointer;
+  using iterator_category = std::forward_iterator_tag;
+  using value_type = typename GT::NodeRef;
+  using difference_type = std::ptrdiff_t;
+  using pointer = typename GT::NodeRef*;
+  using reference = typename GT::NodeRef&;
 
   // Provide static begin and end methods as our public "constructors"
   static df_iterator begin(const GraphT &G) {
diff --git a/third_party/llvm-10.0/llvm/include/llvm/ADT/iterator.h b/third_party/llvm-10.0/llvm/include/llvm/ADT/iterator.h
index 8fd5c11..21948f5 100644
--- a/third_party/llvm-10.0/llvm/include/llvm/ADT/iterator.h
+++ b/third_party/llvm-10.0/llvm/include/llvm/ADT/iterator.h
@@ -64,9 +64,7 @@
 template <typename DerivedT, typename IteratorCategoryT, typename T,
           typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *,
           typename ReferenceT = T &>
-class iterator_facade_base
-    : public std::iterator<IteratorCategoryT, T, DifferenceTypeT, PointerT,
-                           ReferenceT> {
+class iterator_facade_base {
 protected:
   enum {
     IsRandomAccess = std::is_base_of<std::random_access_iterator_tag,
@@ -92,6 +90,12 @@
   };
 
 public:
+  using iterator_category = IteratorCategoryT;
+  using value_type = T;
+  using difference_type = DifferenceTypeT;
+  using pointer = PointerT;
+  using reference = ReferenceT;
+
   DerivedT operator+(DifferenceTypeT n) const {
     static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,
                   "Must pass the derived type to this template!");
diff --git a/third_party/llvm-10.0/llvm/include/llvm/Analysis/MemorySSA.h b/third_party/llvm-10.0/llvm/include/llvm/Analysis/MemorySSA.h
index 9b393c9..1df3bc9 100644
--- a/third_party/llvm-10.0/llvm/include/llvm/Analysis/MemorySSA.h
+++ b/third_party/llvm-10.0/llvm/include/llvm/Analysis/MemorySSA.h
@@ -1103,7 +1103,7 @@
     return MP->getIncomingBlock(ArgNo);
   }
 
-  typename BaseT::iterator::pointer operator*() const {
+  typename BaseT::pointer operator*() const {
     assert(Access && "Tried to access past the end of our iterator");
     // Go to the first argument for phis, and the defining access for everything
     // else.
@@ -1197,7 +1197,7 @@
     return DefIterator == Other.DefIterator;
   }
 
-  BaseT::iterator::reference operator*() const {
+  BaseT::reference operator*() const {
     assert(DefIterator != OriginalAccess->defs_end() &&
            "Tried to access past the end of our iterator");
     return CurrentPair;
diff --git a/third_party/llvm-10.0/llvm/include/llvm/IR/CFG.h b/third_party/llvm-10.0/llvm/include/llvm/IR/CFG.h
index 55aff71..f9dc638 100644
--- a/third_party/llvm-10.0/llvm/include/llvm/IR/CFG.h
+++ b/third_party/llvm-10.0/llvm/include/llvm/IR/CFG.h
@@ -39,10 +39,7 @@
 //===----------------------------------------------------------------------===//
 
 template <class Ptr, class USE_iterator> // Predecessor Iterator
-class PredIterator : public std::iterator<std::forward_iterator_tag,
-                                          Ptr, ptrdiff_t, Ptr*, Ptr*> {
-  using super =
-      std::iterator<std::forward_iterator_tag, Ptr, ptrdiff_t, Ptr*, Ptr*>;
+class PredIterator {
   using Self = PredIterator<Ptr, USE_iterator>;
   USE_iterator It;
 
@@ -58,8 +55,11 @@
   }
 
 public:
-  using pointer = typename super::pointer;
-  using reference = typename super::reference;
+  using iterator_category = std::forward_iterator_tag;
+  using value_type = Ptr;
+  using difference_type = ptrdiff_t;
+  using pointer = Ptr*;
+  using reference = Ptr*;
 
   PredIterator() = default;
   explicit inline PredIterator(Ptr *bb) : It(bb->user_begin()) {
diff --git a/third_party/llvm-10.0/llvm/include/llvm/IR/Metadata.h b/third_party/llvm-10.0/llvm/include/llvm/IR/Metadata.h
index dda939b..9af5619 100644
--- a/third_party/llvm-10.0/llvm/include/llvm/IR/Metadata.h
+++ b/third_party/llvm-10.0/llvm/include/llvm/IR/Metadata.h
@@ -1344,8 +1344,7 @@
   explicit NamedMDNode(const Twine &N);
 
   template<class T1, class T2>
-  class op_iterator_impl :
-      public std::iterator<std::bidirectional_iterator_tag, T2> {
+  class op_iterator_impl {
     friend class NamedMDNode;
 
     const NamedMDNode *Node = nullptr;
@@ -1354,6 +1353,12 @@
     op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) {}
 
   public:
+    using iterator_category = std::bidirectional_iterator_tag;
+    using value_type = T2;
+    using difference_type = std::ptrdiff_t;
+    using pointer = T2*;
+    using reference = T2&;
+
     op_iterator_impl() = default;
 
     bool operator==(const op_iterator_impl &o) const { return Idx == o.Idx; }
diff --git a/third_party/llvm-10.0/llvm/include/llvm/IR/Module.h b/third_party/llvm-10.0/llvm/include/llvm/IR/Module.h
index 68cd583..b091723 100644
--- a/third_party/llvm-10.0/llvm/include/llvm/IR/Module.h
+++ b/third_party/llvm-10.0/llvm/include/llvm/IR/Module.h
@@ -698,14 +698,19 @@
   }
 
   /// An iterator for DICompileUnits that skips those marked NoDebug.
-  class debug_compile_units_iterator
-      : public std::iterator<std::input_iterator_tag, DICompileUnit *> {
+  class debug_compile_units_iterator {
     NamedMDNode *CUs;
     unsigned Idx;
 
     void SkipNoDebugCUs();
 
   public:
+    using iterator_category = std::input_iterator_tag;
+    using value_type = DICompileUnit *;
+    using difference_type = std::ptrdiff_t;
+    using pointer = DICompileUnit **;
+    using reference = DICompileUnit *&;
+
     explicit debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
         : CUs(CUs), Idx(Idx) {
       SkipNoDebugCUs();
diff --git a/third_party/llvm-10.0/llvm/include/llvm/IR/Value.h b/third_party/llvm-10.0/llvm/include/llvm/IR/Value.h
index f2c4b3b..b28fee6 100644
--- a/third_party/llvm-10.0/llvm/include/llvm/IR/Value.h
+++ b/third_party/llvm-10.0/llvm/include/llvm/IR/Value.h
@@ -123,8 +123,7 @@
 
 private:
   template <typename UseT> // UseT == 'Use' or 'const Use'
-  class use_iterator_impl
-      : public std::iterator<std::forward_iterator_tag, UseT *> {
+  class use_iterator_impl {
     friend class Value;
 
     UseT *U;
@@ -132,6 +131,12 @@
     explicit use_iterator_impl(UseT *u) : U(u) {}
 
   public:
+    using iterator_category = std::forward_iterator_tag;
+    using value_type = UseT *;
+    using difference_type = std::ptrdiff_t;
+    using pointer = UseT **;
+    using reference = UseT *&;
+
     use_iterator_impl() : U() {}
 
     bool operator==(const use_iterator_impl &x) const { return U == x.U; }
@@ -162,13 +167,18 @@
   };
 
   template <typename UserTy> // UserTy == 'User' or 'const User'
-  class user_iterator_impl
-      : public std::iterator<std::forward_iterator_tag, UserTy *> {
+  class user_iterator_impl {
     use_iterator_impl<Use> UI;
     explicit user_iterator_impl(Use *U) : UI(U) {}
     friend class Value;
 
   public:
+    using iterator_category = std::forward_iterator_tag;
+    using value_type = UserTy *;
+    using difference_type = std::ptrdiff_t;
+    using pointer = UserTy **;
+    using reference = UserTy *&;
+
     user_iterator_impl() = default;
 
     bool operator==(const user_iterator_impl &x) const { return UI == x.UI; }
diff --git a/third_party/llvm-10.0/llvm/include/llvm/Object/SymbolicFile.h b/third_party/llvm-10.0/llvm/include/llvm/Object/SymbolicFile.h
index 1398fa1..3a7e49f 100644
--- a/third_party/llvm-10.0/llvm/include/llvm/Object/SymbolicFile.h
+++ b/third_party/llvm-10.0/llvm/include/llvm/Object/SymbolicFile.h
@@ -66,11 +66,16 @@
 }
 
 template <class content_type>
-class content_iterator
-    : public std::iterator<std::forward_iterator_tag, content_type> {
+class content_iterator {
   content_type Current;
 
 public:
+  using iterator_category = std::forward_iterator_tag;
+  using value_type = content_type;
+  using difference_type = std::ptrdiff_t;
+  using pointer = content_type*;
+  using reference = content_type&;
+
   content_iterator(content_type symb) : Current(std::move(symb)) {}
 
   const content_type *operator->() const { return &Current; }
diff --git a/third_party/llvm-10.0/llvm/include/llvm/Support/YAMLParser.h b/third_party/llvm-10.0/llvm/include/llvm/Support/YAMLParser.h
index 3570119..02676e2 100644
--- a/third_party/llvm-10.0/llvm/include/llvm/Support/YAMLParser.h
+++ b/third_party/llvm-10.0/llvm/include/llvm/Support/YAMLParser.h
@@ -320,9 +320,14 @@
 /// BaseT must have a ValueT* member named CurrentEntry and a member function
 /// increment() which must set CurrentEntry to 0 to create an end iterator.
 template <class BaseT, class ValueT>
-class basic_collection_iterator
-    : public std::iterator<std::input_iterator_tag, ValueT> {
+class basic_collection_iterator {
 public:
+  using iterator_category = std::input_iterator_tag;
+  using value_type = ValueT;
+  using difference_type = std::ptrdiff_t;
+  using pointer = ValueT*;
+  using reference = ValueT&;
+
   basic_collection_iterator() = default;
   basic_collection_iterator(BaseT *B) : Base(B) {}
 
diff --git a/third_party/llvm-10.0/llvm/lib/IR/BasicBlock.cpp b/third_party/llvm-10.0/llvm/lib/IR/BasicBlock.cpp
index bdee699..844ba04 100644
--- a/third_party/llvm-10.0/llvm/lib/IR/BasicBlock.cpp
+++ b/third_party/llvm-10.0/llvm/lib/IR/BasicBlock.cpp
@@ -308,7 +308,7 @@
 void BasicBlock::removePredecessor(BasicBlock *Pred,
                                    bool KeepOneInputPHIs) {
   assert((hasNUsesOrMore(16)||// Reduce cost of this assertion for complex CFGs.
-          find(pred_begin(this), pred_end(this), Pred) != pred_end(this)) &&
+          std::find(pred_begin(this), pred_end(this), Pred) != pred_end(this)) &&
          "removePredecessor: BB is not a predecessor!");
 
   if (InstList.empty()) return;