From: Chris Lattner Date: Mon, 8 Apr 2002 00:14:58 +0000 (+0000) Subject: GCCLD actually does transformations to simplify the linked program now. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ad202a06204f012ef054e92193d0ade5fd2cea6f;p=oota-llvm.git 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 --- diff --git a/tools/gccld/Makefile b/tools/gccld/Makefile index 5d99de30f09..c4e2987a4bb 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 d00687fcec6..4d369cdeba5 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 #include @@ -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";