From 2345d71853e75fd56a8ca66d40bf36eba0a9edb6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 22 May 2003 19:48:00 +0000 Subject: [PATCH] * Revert to old behavior of ignoring a module if it doesn't contain a main function and no symbols were explicitly marked to be externalized. * Add new -internalize-public-api-list option that can be used if the symbol list is small, and making a new file is annoying. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6289 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/Internalize.cpp | 31 +++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp index b38b0d0b3f3..aa238c33bfb 100644 --- a/lib/Transforms/IPO/Internalize.cpp +++ b/lib/Transforms/IPO/Internalize.cpp @@ -22,16 +22,21 @@ namespace { // external. cl::opt APIFile("internalize-public-api-file", cl::value_desc("filename"), - cl::desc("A file containing list of globals to not internalize")); - + cl::desc("A file containing list of symbol names to preserve")); + + // APIList - A list of symbols that should not be marked internal. + cl::list + APIList("internalize-public-api-list", cl::value_desc("list"), + cl::desc("A list of symbol names to preserve")); + class InternalizePass : public Pass { std::set ExternalNames; public: InternalizePass() { - if (!APIFile.empty()) + if (!APIFile.empty()) // If a filename is specified, use it LoadFile(APIFile.c_str()); - else - ExternalNames.insert("main"); + else // Else, if a list is specified, use it. + ExternalNames.insert(APIList.begin(), APIList.end()); } void LoadFile(const char *Filename) { @@ -39,7 +44,7 @@ namespace { std::ifstream In(Filename); if (!In.good()) { std::cerr << "WARNING: Internalize couldn't load file '" << Filename - << "'!: Not internalizing.\n"; + << "'!\n"; return; // Do not internalize anything... } while (In) { @@ -51,7 +56,19 @@ namespace { } virtual bool run(Module &M) { - if (ExternalNames.empty()) return false; // Error loading file... + // If no list or file of symbols was specified, check to see if there is a + // "main" symbol defined in the module. If so, use it, otherwise do not + // internalize the module, it must be a library or something. + // + if (ExternalNames.empty()) { + Function *MainFunc = M.getMainFunction(); + if (MainFunc == 0 || MainFunc->isExternal()) + return false; // No main found, must be a library... + + // Preserve main, internalize all else. + ExternalNames.insert(MainFunc->getName()); + } + bool Changed = false; // Found a main function, mark all functions not named main as internal.