[llvm] 4a0aff1 - MCAssembler: Clean up iterator types for Symbols

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 5 15:15:07 PDT 2024


Author: Fangrui Song
Date: 2024-07-05T15:15:01-07:00
New Revision: 4a0aff199bda8abf04a59e4c0bdcedaac7d19841

URL: https://github.com/llvm/llvm-project/commit/4a0aff199bda8abf04a59e4c0bdcedaac7d19841
DIFF: https://github.com/llvm/llvm-project/commit/4a0aff199bda8abf04a59e4c0bdcedaac7d19841.diff

LOG: MCAssembler: Clean up iterator types for Symbols

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCAssembler.h
    llvm/lib/MC/MCAssembler.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h
index 3a6d6105f20aa..8a8f0d4c1ea08 100644
--- a/llvm/include/llvm/MC/MCAssembler.h
+++ b/llvm/include/llvm/MC/MCAssembler.h
@@ -11,6 +11,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator.h"
 #include "llvm/ADT/iterator_range.h"
@@ -56,18 +57,10 @@ class MCValue;
 class MCAssembler {
 public:
   using SectionListType = std::vector<MCSection *>;
-  using SymbolDataListType = std::vector<const MCSymbol *>;
 
   using const_iterator = pointee_iterator<SectionListType::const_iterator>;
   using iterator = pointee_iterator<SectionListType::iterator>;
 
-  using const_symbol_iterator =
-      pointee_iterator<SymbolDataListType::const_iterator>;
-  using symbol_iterator = pointee_iterator<SymbolDataListType::iterator>;
-
-  using symbol_range = iterator_range<symbol_iterator>;
-  using const_symbol_range = iterator_range<const_symbol_iterator>;
-
   /// MachO specific deployment target version info.
   // A Major version of 0 indicates that no version information was supplied
   // and so the corresponding load command should not be emitted.
@@ -98,7 +91,7 @@ class MCAssembler {
 
   SectionListType Sections;
 
-  SymbolDataListType Symbols;
+  SmallVector<const MCSymbol *, 0> Symbols;
 
   /// The list of linker options to propagate into the object file.
   std::vector<std::vector<std::string>> LinkerOptions;
@@ -344,22 +337,12 @@ class MCAssembler {
 
   size_t size() const { return Sections.size(); }
 
-  /// @}
-  /// \name Symbol List Access
-  /// @{
-  symbol_iterator symbol_begin() { return Symbols.begin(); }
-  const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
-
-  symbol_iterator symbol_end() { return Symbols.end(); }
-  const_symbol_iterator symbol_end() const { return Symbols.end(); }
-
-  symbol_range symbols() { return make_range(symbol_begin(), symbol_end()); }
-  const_symbol_range symbols() const {
-    return make_range(symbol_begin(), symbol_end());
+  iterator_range<pointee_iterator<
+      typename SmallVector<const MCSymbol *, 0>::const_iterator>>
+  symbols() const {
+    return make_pointee_range(Symbols);
   }
 
-  size_t symbol_size() const { return Symbols.size(); }
-
   /// @}
   /// \name Linker Option List Access
   /// @{

diff  --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index bab941b8e1ea8..3c777791472bf 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -1346,11 +1346,15 @@ LLVM_DUMP_METHOD void MCAssembler::dump() const{
   OS << "],\n";
   OS << "  Symbols:[";
 
-  for (const_symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
-    if (it != symbol_begin()) OS << ",\n           ";
+  bool First = true;
+  for (const MCSymbol &Sym : symbols()) {
+    if (First)
+      First = false;
+    else
+      OS << ",\n           ";
     OS << "(";
-    it->dump();
-    OS << ", Index:" << it->getIndex() << ", ";
+    Sym.dump();
+    OS << ", Index:" << Sym.getIndex() << ", ";
     OS << ")";
   }
   OS << "]>\n";


        


More information about the llvm-commits mailing list