OSDN Git Service

Use a StringSet in Internalize, and allow to create the pass from an existing one...
authorMehdi Amini <mehdi.amini@apple.com>
Wed, 10 Feb 2016 23:24:31 +0000 (23:24 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Wed, 10 Feb 2016 23:24:31 +0000 (23:24 +0000)
There is not reason to pass an array of "char *" to rebuild a set if
the client already has one.

From: Mehdi Amini <mehdi.amini@apple.com>

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

include/llvm/Transforms/IPO.h
lib/Transforms/IPO/Internalize.cpp

index 7c76453..6d0f9ea 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 
 namespace llvm {
 
@@ -126,7 +127,11 @@ Pass *createPruneEHPass();
 ///
 /// Note that commandline options that are used with the above function are not
 /// used now!
+ModulePass *createInternalizePass(StringSet<> ExportList);
+
+/// Same as above, but with an exportList created for an array.
 ModulePass *createInternalizePass(ArrayRef<const char *> ExportList);
+
 /// createInternalizePass - Same as above, but with an empty exportList.
 ModulePass *createInternalizePass();
 
index 21bb5d0..a57176f 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/Transforms/IPO.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
@@ -54,11 +55,13 @@ APIList("internalize-public-api-list", cl::value_desc("list"),
 
 namespace {
   class InternalizePass : public ModulePass {
-    std::set<std::string> ExternalNames;
+    StringSet<> ExternalNames;
+
   public:
     static char ID; // Pass identification, replacement for typeid
     explicit InternalizePass();
     explicit InternalizePass(ArrayRef<const char *> ExportList);
+    explicit InternalizePass(StringSet<> ExportList);
     void LoadFile(const char *Filename);
     bool maybeInternalize(GlobalValue &GV,
                           const std::set<const Comdat *> &ExternalComdats);
@@ -93,6 +96,9 @@ InternalizePass::InternalizePass(ArrayRef<const char *> ExportList)
   }
 }
 
+InternalizePass::InternalizePass(StringSet<> ExportList)
+    : ModulePass(ID), ExternalNames(std::move(ExportList)) {}
+
 void InternalizePass::LoadFile(const char *Filename) {
   // Load the APIFile...
   std::ifstream In(Filename);
@@ -110,7 +116,7 @@ void InternalizePass::LoadFile(const char *Filename) {
 }
 
 static bool isExternallyVisible(const GlobalValue &GV,
-                                const std::set<std::string> &ExternalNames) {
+                                const StringSet<> &ExternalNames) {
   // Function must be defined here
   if (GV.isDeclaration())
     return true;
@@ -267,3 +273,7 @@ ModulePass *llvm::createInternalizePass() { return new InternalizePass(); }
 ModulePass *llvm::createInternalizePass(ArrayRef<const char *> ExportList) {
   return new InternalizePass(ExportList);
 }
+
+ModulePass *llvm::createInternalizePass(StringSet<> ExportList) {
+  return new InternalizePass(std::move(ExportList));
+}