[llvm-commits] CVS: llvm/lib/Transforms/IPO/Internalize.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu May 22 14:49:02 PDT 2003


Changes in directory llvm/lib/Transforms/IPO:

Internalize.cpp updated: 1.14 -> 1.15

---
Log message:

* 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.


---
Diffs of the changes:

Index: llvm/lib/Transforms/IPO/Internalize.cpp
diff -u llvm/lib/Transforms/IPO/Internalize.cpp:1.14 llvm/lib/Transforms/IPO/Internalize.cpp:1.15
--- llvm/lib/Transforms/IPO/Internalize.cpp:1.14	Thu May 22 14:34:49 2003
+++ llvm/lib/Transforms/IPO/Internalize.cpp	Thu May 22 14:48:00 2003
@@ -22,16 +22,21 @@
   // 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 @@
       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 @@
     }
 
     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.





More information about the llvm-commits mailing list