GCCLD actually does transformations to simplify the linked program now.
authorChris Lattner <sabre@nondot.org>
Mon, 8 Apr 2002 00:14:58 +0000 (00:14 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 8 Apr 2002 00:14:58 +0000 (00:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2155 91177308-0d34-0410-b5e6-96231b3b80d8

tools/gccld/Makefile
tools/gccld/gccld.cpp

index 5d99de30f09927749acf021d7705a0c8c6784686..c4e2987a4bb1a1b55373cd2cd1e6689f32fe684a 100644 (file)
@@ -1,6 +1,6 @@
 LEVEL = ../..
 
 TOOLNAME = gccld
-USEDLIBS = transforms bcreader bcwriter analysis vmcore support
+USEDLIBS = transforms ipo ipa analysis scalaropts target bcreader bcwriter vmcore support
 
 include $(LEVEL)/Makefile.common
index d00687fcec6ffc8a96fbbb9e1aa81c4e60fc0f33..4d369cdeba5a6214dc7b96fa2fef92d0e80677c9 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Transforms/Linker.h"
-#include "llvm/Bytecode/Reader.h"
-#include "llvm/Bytecode/Writer.h"
 #include "llvm/Module.h"
+#include "llvm/PassManager.h"
+#include "llvm/Bytecode/Reader.h"
+#include "llvm/Bytecode/WriteBytecodePass.h"
+#include "llvm/Transforms/CleanupGCCOutput.h"
+#include "llvm/Transforms/ConstantMerge.h"
+#include "llvm/Transforms/IPO/GlobalDCE.h"
 #include "Support/CommandLine.h"
 #include <fstream>
 #include <memory>
@@ -115,29 +119,48 @@ int main(int argc, char **argv) {
     }
   }
 
-  // Now that composite has been compiled, scan through the module, looking for
-  // a main function.  If main is defined, mark all other functions internal.
+  // In addition to just parsing the input from GCC, we also want to spiff it up
+  // a little bit.  Do this now.
   //
+  PassManager Passes;
 
-  // Next run globaldce...
+  // Linking modules together can lead to duplicated global constants, only keep
+  // one copy of each constant...
+  //
+  Passes.add(createConstantMergePass());
 
-  // next ?
+  // Often if the programmer does not specify proper prototypes for the
+  // functions they are calling, they end up calling a vararg version of the
+  // function that does not get a body filled in (the real function has typed
+  // arguments).  This pass merges the two functions, among other things.
+  //
+  Passes.add(createCleanupGCCOutputPass());
 
+  // Now that composite has been compiled, scan through the module, looking for
+  // a main function.  If main is defined, mark all other functions internal.
+  //
+  // TODO:
+
+  // Now that we have optimized the program, discard unreachable functions...
+  //
+  Passes.add(createGlobalDCEPass());
 
+  // Add the pass that writes bytecode to the output file...
   std::ofstream Out((OutputFilename+".bc").c_str());
   if (!Out.good()) {
     cerr << "Error opening '" << OutputFilename << ".bc' for writing!\n";
     return 1;
   }
+  Passes.add(new WriteBytecodePass(&Out));        // Write bytecode to file...
 
-  if (Verbose) cerr << "Writing bytecode...\n";
-  WriteBytecodeToFile(Composite.get(), Out);
+  // Run our queue of passes all at once now, efficiently.
+  Passes.run(Composite.get());
   Out.close();
 
   // Output the script to start the program...
   std::ofstream Out2(OutputFilename.c_str());
   if (!Out2.good()) {
-    cerr << "Error openeing '" << OutputFilename << "' for writing!\n";
+    cerr << "Error opening '" << OutputFilename << "' for writing!\n";
     return 1;
   }
   Out2 << "#!/bin/sh\nlli -q $0.bc $*\n";