X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fopt%2Fopt.cpp;h=92b63bd830350cb8bc6b1f0841b4c95a42a061b6;hb=a5ced5ed37b3a742e958506ce133387b3313fe3a;hp=48f748a636ecc5a7586a6be3e38c6cfa6bf1dda1;hpb=446991dc348a1b6c12666d52449d2ca7a2e39a1a;p=oota-llvm.git diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 48f748a636e..92b63bd8303 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/LLVMContext.h" +#include "NewPMDriver.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/Triple.h" #include "llvm/Analysis/CallGraph.h" @@ -20,23 +20,25 @@ #include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/RegionPass.h" #include "llvm/Analysis/Verifier.h" -#include "llvm/Assembly/PrintModulePass.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/CodeGen/CommandFlags.h" #include "llvm/DebugInfo.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/IRPrintingPasses.h" +#include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" -#include "llvm/LinkAllPasses.h" +#include "llvm/IRReader/IRReader.h" #include "llvm/LinkAllIR.h" +#include "llvm/LinkAllPasses.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/PassManager.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/IRReader.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/PassNameParser.h" #include "llvm/Support/PluginLoader.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/SourceMgr.h" #include "llvm/Support/SystemUtils.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" @@ -54,6 +56,15 @@ using namespace llvm; static cl::list PassList(cl::desc("Optimizations available:")); +// This flag specifies a textual description of the optimization pass pipeline +// to run over the module. This flag switches opt to use the new pass manager +// infrastructure, completely disabling all of the flags specific to the old +// pass management. +static cl::opt PassPipeline( + "passes", + cl::desc("A textual description of the pass pipeline for optimizing"), + cl::Hidden); + // Other command line options... // static cl::opt @@ -134,6 +145,21 @@ UnitAtATime("funit-at-a-time", cl::desc("Enable IPO. This is same as llvm-gcc's -funit-at-a-time"), cl::init(true)); +static cl::opt +DisableLoopUnrolling("disable-loop-unrolling", + cl::desc("Disable loop unrolling in all relevant passes"), + cl::init(false)); +static cl::opt +DisableLoopVectorization("disable-loop-vectorization", + cl::desc("Disable the loop vectorization pass"), + cl::init(false)); + +static cl::opt +DisableSLPVectorization("disable-slp-vectorization", + cl::desc("Disable the slp vectorization pass"), + cl::init(false)); + + static cl::opt DisableSimplifyLibCalls("disable-simplify-libcalls", cl::desc("Disable simplify-libcalls")); @@ -361,6 +387,7 @@ char BasicBlockPassPrinter::ID = 0; struct BreakpointPrinter : public ModulePass { raw_ostream &Out; static char ID; + DITypeIdentifierMap TypeIdentifierMap; BreakpointPrinter(raw_ostream &out) : ModulePass(ID), Out(out) { @@ -376,20 +403,28 @@ struct BreakpointPrinter : public ModulePass { } else if (Context.isType()) { DIType TY(Context); if (!TY.getName().empty()) { - getContextName(TY.getContext(), N); + getContextName(TY.getContext().resolve(TypeIdentifierMap), N); N = N + TY.getName().str() + "::"; } } } virtual bool runOnModule(Module &M) { + TypeIdentifierMap.clear(); + NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu"); + if (CU_Nodes) + TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes); + StringSet<> Processed; if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp")) for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { std::string Name; DISubprogram SP(NMD->getOperand(i)); - if (SP.Verify()) - getContextName(SP.getContext(), Name); + assert((!SP || SP.isSubprogram()) && + "A MDNode in llvm.dbg.sp should be null or a DISubprogram."); + if (!SP) + continue; + getContextName(SP.getContext().resolve(TypeIdentifierMap), Name); Name = Name + SP.getDisplayName().str(); if (!Name.empty() && Processed.insert(Name)) { Out << Name << "\n"; @@ -402,7 +437,7 @@ struct BreakpointPrinter : public ModulePass { AU.setPreservesAll(); } }; - + } // anonymous namespace char BreakpointPrinter::ID = 0; @@ -443,9 +478,20 @@ static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM, Builder.Inliner = createAlwaysInlinerPass(); } Builder.DisableUnitAtATime = !UnitAtATime; - Builder.DisableUnrollLoops = OptLevel == 0; - Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls; - + Builder.DisableUnrollLoops = (DisableLoopUnrolling.getNumOccurrences() > 0) ? + DisableLoopUnrolling : OptLevel == 0; + + // This is final, unless there is a #pragma vectorize enable + if (DisableLoopVectorization) + Builder.LoopVectorize = false; + // If option wasn't forced via cmd line (-vectorize-loops, -loop-vectorize) + else if (!Builder.LoopVectorize) + Builder.LoopVectorize = OptLevel > 1 && SizeLevel < 2; + + // When #pragma vectorize is on for SLP, do the same as above + Builder.SLPVectorize = + DisableSLPVectorization ? false : OptLevel > 1 && SizeLevel < 2; + Builder.populateFunctionPassManager(FPM); Builder.populateModulePassManager(MPM); } @@ -464,7 +510,6 @@ static void AddStandardCompilePasses(PassManagerBase &PM) { if (!DisableInline) Builder.Inliner = createFunctionInliningPass(); Builder.OptLevel = 3; - Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls; Builder.populateModulePassManager(PM); } @@ -489,7 +534,6 @@ static TargetOptions GetTargetOptions() { TargetOptions Options; Options.LessPreciseFPMADOption = EnableFPMAD; Options.NoFramePointerElim = DisableFPElim; - Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf; Options.AllowFPOpFusion = FuseFPOps; Options.UnsafeFPMath = EnableUnsafeFPMath; Options.NoInfsFPMath = EnableNoInfsFPMath; @@ -503,12 +547,10 @@ static TargetOptions GetTargetOptions() { Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt; Options.DisableTailCalls = DisableTailCalls; Options.StackAlignmentOverride = OverrideStackAlignment; - Options.RealignStack = EnableRealignStack; Options.TrapFuncName = TrapFuncName; Options.PositionIndependentExecutable = EnablePIE; Options.EnableSegmentedStacks = SegmentedStacks; Options.UseInitArray = UseInitArray; - Options.SSPBufferSize = SSPBufferSize; return Options; } @@ -566,7 +608,9 @@ int main(int argc, char **argv) { // Initialize passes PassRegistry &Registry = *PassRegistry::getPassRegistry(); initializeCore(Registry); + initializeDebugIRPass(Registry); initializeScalarOpts(Registry); + initializeObjCARCOpts(Registry); initializeVectorization(Registry); initializeIPO(Registry); initializeAnalysis(Registry); @@ -587,7 +631,7 @@ int main(int argc, char **argv) { SMDiagnostic Err; // Load the input module... - std::auto_ptr M; + OwningPtr M; M.reset(ParseIRFile(InputFilename, Err, Context)); if (M.get() == 0) { @@ -612,7 +656,7 @@ int main(int argc, char **argv) { std::string ErrorInfo; Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo, - raw_fd_ostream::F_Binary)); + sys::fs::F_Binary)); if (!ErrorInfo.empty()) { errs() << ErrorInfo << '\n'; return 1; @@ -626,6 +670,15 @@ int main(int argc, char **argv) { if (CheckBitcodeOutputToConsole(Out->os(), !Quiet)) NoOutput = true; + if (PassPipeline.getNumOccurrences() > 0) + // The user has asked to use the new pass manager and provided a pipeline + // string. Hand off the rest of the functionality to the new code for that + // layer. + return runPassPipeline(argv[0], Context, *M.get(), Out.get(), PassPipeline, + NoOutput) + ? 0 + : 1; + // Create a PassManager to hold and optimize the collection of passes we are // about to build. // @@ -654,7 +707,7 @@ int main(int argc, char **argv) { TargetMachine *Machine = 0; if (ModuleTriple.getArch()) Machine = GetTargetMachine(Triple(ModuleTriple)); - std::auto_ptr TM(Machine); + OwningPtr TM(Machine); // Add internal analysis passes from the target machine. if (TM.get()) @@ -665,6 +718,9 @@ int main(int argc, char **argv) { FPasses.reset(new FunctionPassManager(M.get())); if (TD) FPasses->add(new DataLayout(*TD)); + if (TM.get()) + TM->addAnalysisPasses(*FPasses); + } if (PrintBreakpoints) { @@ -675,7 +731,7 @@ int main(int argc, char **argv) { std::string ErrorInfo; Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo, - raw_fd_ostream::F_Binary)); + sys::fs::F_Binary)); if (!ErrorInfo.empty()) { errs() << ErrorInfo << '\n'; return 1; @@ -767,7 +823,7 @@ int main(int argc, char **argv) { } if (PrintEachXForm) - Passes.add(createPrintModulePass(&errs())); + Passes.add(createPrintModulePass(errs())); } // If -std-compile-opts was specified at the end of the pass list, add them. @@ -810,7 +866,7 @@ int main(int argc, char **argv) { // Write bitcode or assembly to the output as the last step... if (!NoOutput && !AnalyzeOnly) { if (OutputAssembly) - Passes.add(createPrintModulePass(&Out->os())); + Passes.add(createPrintModulePass(Out->os())); else Passes.add(createBitcodeWriterPass(Out->os())); }