Use a StringSet in Internalize, and allow to create the pass from an existing one (NFC)

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>
llvm-svn: 260462
This commit is contained in:
Mehdi Amini 2016-02-10 23:24:31 +00:00
parent 0bfaa589f0
commit c87d7d02e1
2 changed files with 17 additions and 2 deletions

View 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();

View 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));
}