aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/Internalize.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-05-22 19:48:00 +0000
committerChris Lattner <sabre@nondot.org>2003-05-22 19:48:00 +0000
commit2345d71853e75fd56a8ca66d40bf36eba0a9edb6 (patch)
treecd7a05e51c200971375300f993b76350d7bd5a27 /lib/Transforms/IPO/Internalize.cpp
parentc7a2c7f0c9900c6658bc567211d695f0593484c2 (diff)
* 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
Diffstat (limited to 'lib/Transforms/IPO/Internalize.cpp')
-rw-r--r--lib/Transforms/IPO/Internalize.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp
index b38b0d0b3f..aa238c33bf 100644
--- a/lib/Transforms/IPO/Internalize.cpp
+++ b/lib/Transforms/IPO/Internalize.cpp
@@ -22,16 +22,21 @@ namespace {
// external.
cl::opt<std::string>
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<std::string>
+ APIList("internalize-public-api-list", cl::value_desc("list"),
+ cl::desc("A list of symbol names to preserve"));
+
class InternalizePass : public Pass {
std::set<std::string> 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.