[llvm] r276668 - Don't use iplist in SymbolRewriter. NFC.

Michael Kuperstein via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 11:10:54 PDT 2016


Author: mkuper
Date: Mon Jul 25 13:10:54 2016
New Revision: 276668

URL: http://llvm.org/viewvc/llvm-project?rev=276668&view=rev
Log:
Don't use iplist in SymbolRewriter. NFC.

There didn't appear to be a good reason to use iplist in this case, a regular
list of unique_ptr works just as well.
Change made in preparation to a new PM port (since iplist is not moveable).

Modified:
    llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h
    llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp

Modified: llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h?rev=276668&r1=276667&r2=276668&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h Mon Jul 25 13:10:54 2016
@@ -30,12 +30,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TRANSFORMS_UTILS_SYMBOL_REWRITER_H
-#define LLVM_TRANSFORMS_UTILS_SYMBOL_REWRITER_H
+#ifndef LLVM_TRANSFORMS_UTILS_SYMBOLREWRITER_H
+#define LLVM_TRANSFORMS_UTILS_SYMBOLREWRITER_H
 
-#include "llvm/ADT/ilist.h"
-#include "llvm/ADT/ilist_node.h"
 #include "llvm/IR/Module.h"
+#include <list>
 
 namespace llvm {
 class MemoryBuffer;
@@ -59,7 +58,7 @@ namespace SymbolRewriter {
 /// be rewritten or providing a (posix compatible) regular expression that will
 /// select the symbols to rewrite.  This descriptor list is passed to the
 /// SymbolRewriter pass.
-class RewriteDescriptor : public ilist_node<RewriteDescriptor> {
+class RewriteDescriptor {
   RewriteDescriptor(const RewriteDescriptor &) = delete;
 
   const RewriteDescriptor &
@@ -86,7 +85,7 @@ private:
   const Type Kind;
 };
 
-typedef iplist<RewriteDescriptor> RewriteDescriptorList;
+typedef std::list<std::unique_ptr<RewriteDescriptor>> RewriteDescriptorList;
 
 class RewriteMapParser {
 public:
@@ -110,43 +109,8 @@ private:
 };
 }
 
-template <>
-struct ilist_traits<SymbolRewriter::RewriteDescriptor>
-    : public ilist_default_traits<SymbolRewriter::RewriteDescriptor> {
-  mutable ilist_half_node<SymbolRewriter::RewriteDescriptor> Sentinel;
-
-public:
-  // createSentinel is used to get a reference to a node marking the end of
-  // the list.  Because the sentinel is relative to this instance, use a
-  // non-static method.
-  SymbolRewriter::RewriteDescriptor *createSentinel() const {
-    // since i[p] lists always publicly derive from the corresponding
-    // traits, placing a data member in this class will augment the
-    // i[p]list.  Since the NodeTy is expected to publicly derive from
-    // ilist_node<NodeTy>, there is a legal viable downcast from it to
-    // NodeTy.  We use this trick to superpose i[p]list with a "ghostly"
-    // NodeTy, which becomes the sentinel.  Dereferencing the sentinel is
-    // forbidden (save the ilist_node<NodeTy>) so no one will ever notice
-    // the superposition.
-    return static_cast<SymbolRewriter::RewriteDescriptor *>(&Sentinel);
-  }
-  void destroySentinel(SymbolRewriter::RewriteDescriptor *) {}
-
-  SymbolRewriter::RewriteDescriptor *provideInitialHead() const {
-    return createSentinel();
-  }
-
-  SymbolRewriter::RewriteDescriptor *
-  ensureHead(SymbolRewriter::RewriteDescriptor *&) const {
-    return createSentinel();
-  }
-
-  static void noteHead(SymbolRewriter::RewriteDescriptor *,
-                       SymbolRewriter::RewriteDescriptor *) {}
-};
-
 ModulePass *createRewriteSymbolsPass();
 ModulePass *createRewriteSymbolsPass(SymbolRewriter::RewriteDescriptorList &);
 }
 
-#endif
+#endif //LLVM_TRANSFORMS_UTILS_SYMBOLREWRITER_H

Modified: llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp?rev=276668&r1=276667&r2=276668&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp Mon Jul 25 13:10:54 2016
@@ -361,9 +361,11 @@ parseRewriteFunctionDescriptor(yaml::Str
   // TODO see if there is a more elegant solution to selecting the rewrite
   // descriptor type
   if (!Target.empty())
-    DL->push_back(new ExplicitRewriteFunctionDescriptor(Source, Target, Naked));
+    DL->push_back(
+        make_unique<ExplicitRewriteFunctionDescriptor>(Source, Target, Naked));
   else
-    DL->push_back(new PatternRewriteFunctionDescriptor(Source, Transform));
+    DL->push_back(
+        make_unique<PatternRewriteFunctionDescriptor>(Source, Transform));
 
   return true;
 }
@@ -421,11 +423,12 @@ parseRewriteGlobalVariableDescriptor(yam
   }
 
   if (!Target.empty())
-    DL->push_back(new ExplicitRewriteGlobalVariableDescriptor(Source, Target,
-                                                              /*Naked*/false));
+    DL->push_back(
+        make_unique<ExplicitRewriteGlobalVariableDescriptor>(Source, Target,
+                                                             /*Naked*/ false));
   else
-    DL->push_back(new PatternRewriteGlobalVariableDescriptor(Source,
-                                                             Transform));
+    DL->push_back(
+        make_unique<PatternRewriteGlobalVariableDescriptor>(Source, Transform));
 
   return true;
 }
@@ -483,10 +486,12 @@ parseRewriteGlobalAliasDescriptor(yaml::
   }
 
   if (!Target.empty())
-    DL->push_back(new ExplicitRewriteNamedAliasDescriptor(Source, Target,
-                                                          /*Naked*/false));
+    DL->push_back(
+        make_unique<ExplicitRewriteNamedAliasDescriptor>(Source, Target,
+                                                         /*Naked*/ false));
   else
-    DL->push_back(new PatternRewriteNamedAliasDescriptor(Source, Transform));
+    DL->push_back(
+        make_unique<PatternRewriteNamedAliasDescriptor>(Source, Transform));
 
   return true;
 }
@@ -524,7 +529,7 @@ bool RewriteSymbols::runOnModule(Module
 
   Changed = false;
   for (auto &Descriptor : Descriptors)
-    Changed |= Descriptor.performOnModule(M);
+    Changed |= Descriptor->performOnModule(M);
 
   return Changed;
 }




More information about the llvm-commits mailing list