- 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);
+ // If the -s or -S command line options were specified, strip the symbols out
+ // of the resulting program to make it smaller. -s and -S are GNU ld options
+ // that we are supporting; they alias -strip-all and -strip-debug.
+ if (Strip || StripDebug)
+ addPass(Passes, createStripSymbolsPass(StripDebug && !Strip));
+
+ // 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())
+ addPass(Passes, Opt->getNormalCtor()());
+ 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, createDeadCodeEliminationPass());
+ addPass(Passes, createGlobalDCEPass());