summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-04-08 00:14:58 +0000
committerChris Lattner <sabre@nondot.org>2002-04-08 00:14:58 +0000
commitad202a06204f012ef054e92193d0ade5fd2cea6f (patch)
treeffca3c822e7eb41f275958e160de1203438ac75a /tools
parentb579400cd72f274607f4964a9649ea4d38e04c46 (diff)
downloadllvm-ad202a06204f012ef054e92193d0ade5fd2cea6f.tar.gz
llvm-ad202a06204f012ef054e92193d0ade5fd2cea6f.tar.bz2
llvm-ad202a06204f012ef054e92193d0ade5fd2cea6f.tar.xz
GCCLD actually does transformations to simplify the linked program now.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2155 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/gccld/Makefile2
-rw-r--r--tools/gccld/gccld.cpp41
2 files changed, 33 insertions, 10 deletions
diff --git a/tools/gccld/Makefile b/tools/gccld/Makefile
index 5d99de30f0..c4e2987a4b 100644
--- a/tools/gccld/Makefile
+++ b/tools/gccld/Makefile
@@ -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
diff --git a/tools/gccld/gccld.cpp b/tools/gccld/gccld.cpp
index d00687fcec..4d369cdeba 100644
--- a/tools/gccld/gccld.cpp
+++ b/tools/gccld/gccld.cpp
@@ -15,9 +15,13 @@
//===----------------------------------------------------------------------===//
#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";