aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-ld
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-08-20 19:18:36 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-08-20 19:18:36 +0000
commit8e33fae0ed53d91ce86c1764bcce445ebb98f8cb (patch)
tree00b49558e3be765ea7df5d3ae746157d9d0bcccc /tools/llvm-ld
parent3717ca965bcfb6c66d7e9016566be842a9cc5629 (diff)
downloadexternal_llvm-8e33fae0ed53d91ce86c1764bcce445ebb98f8cb.zip
external_llvm-8e33fae0ed53d91ce86c1764bcce445ebb98f8cb.tar.gz
external_llvm-8e33fae0ed53d91ce86c1764bcce445ebb98f8cb.tar.bz2
Convert llvm-ld to use the PluginLoader like opt instead of having its
one-off (and broken) RunOptimizations function. Also, run some cleanup passes after the user's loaded passes run. This make sure to clean up any cruft left around by thos passes. This patch was inspired by a patch submitted by Bram Adams. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29781 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-ld')
-rw-r--r--tools/llvm-ld/Optimize.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/tools/llvm-ld/Optimize.cpp b/tools/llvm-ld/Optimize.cpp
index b61e8ef..1e391d6 100644
--- a/tools/llvm-ld/Optimize.cpp
+++ b/tools/llvm-ld/Optimize.cpp
@@ -19,12 +19,19 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/System/DynamicLibrary.h"
#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Scalar.h"
+#include "llvm/Support/PassNameParser.h"
+#include "llvm/Support/PluginLoader.h"
using namespace llvm;
-// Optimization Options
+// Pass Name Options as generated by the PassNameParser
+static cl::list<const PassInfo*, bool,
+ FilteredPassNameParser<PassInfo::Optimization> >
+ OptimizationList(cl::desc("Optimizations available:"));
+// Optimization Enumeration
enum OptimizationLevels {
OPT_FAST_COMPILE = 1,
OPT_SIMPLE = 2,
@@ -33,6 +40,7 @@ enum OptimizationLevels {
OPT_AGGRESSIVE_LINK_TIME = 5
};
+// Optimization Options
static cl::opt<OptimizationLevels> OptLevel(
cl::desc("Choose level of optimization to apply:"),
cl::init(OPT_FAST_COMPILE), cl::values(
@@ -72,10 +80,6 @@ static cl::alias ExportDynamic("export-dynamic",
cl::aliasopt(DisableInternalize),
cl::desc("Alias for -disable-internalize"));
-static cl::list<std::string> LoadableModules("load",
- cl::value_desc("path"),
- cl::desc("Load an optimization module and run it"));
-
// A utility function that adds a pass to the pass manager but will also add
// a verifier pass after if we're supposed to verify.
static inline void addPass(PassManager &PM, Pass *P) {
@@ -150,9 +154,8 @@ void Optimize(Module* M) {
addPass(Passes, createScalarReplAggregatesPass()); // Break up allocas
- // Run a few AA driven optimizations here and now, to cleanup the code.
+ // Run a few AA driven optimizations, to cleanup the code.
addPass(Passes, createGlobalsModRefPass()); // IP alias analysis
-
addPass(Passes, createLICMPass()); // Hoist loop invariants
addPass(Passes, createLoadValueNumberingPass()); // GVN for load instrs
addPass(Passes, createGCSEPass()); // Remove common subexprs
@@ -168,18 +171,27 @@ void Optimize(Module* M) {
addPass(Passes, createGlobalDCEPass());
}
- std::vector<std::string> plugins = LoadableModules;
- for (std::vector<std::string>::iterator I = plugins.begin(),
- E = plugins.end(); I != E; ++I) {
- sys::DynamicLibrary dll(I->c_str());
- typedef void (*OptimizeFunc)(PassManager&,int);
- OptimizeFunc OF = OptimizeFunc(
- (intptr_t)dll.GetAddressOfSymbol("RunOptimizations"));
- if (OF == 0) {
- throw std::string("Optimization Module '") + *I +
- "' is missing the RunOptimizations symbol";
- }
- (*OF)(Passes,OptLevel);
+ // Create a new optimization pass for each one specified on the command line
+ std::auto_ptr<TargetMachine> target;
+ for (unsigned i = 0; i < OptimizationList.size(); ++i) {
+ const PassInfo *Opt = OptimizationList[i];
+
+ if (Opt->getNormalCtor())
+ Passes.add(Opt->getNormalCtor()());
+ else if (Opt->getTargetCtor()) {
+ assert(target.get() && "Could not allocate target machine!");
+ Passes.add(Opt->getTargetCtor()(*target.get()));
+ } else
+ std::cerr << "llvm-ld: cannot create pass: " << Opt->getPassName()
+ << "\n";
+ }
+
+ // The user's passes may leave cruft around. Clean up after them them but
+ // only if we haven't got DisableOptimizations set
+ if (!DisableOptimizations) {
+ addPass(Passes, createInstructionCombiningPass());
+ addPass(Passes, createCFGSimplificationPass());
+ addPass(Passes, createGlobalDCEPass());
}
// Make sure everything is still good.