Deleted Added
full compact
opt.cpp (218885) opt.cpp (221337)
1//===- opt.cpp - The LLVM Modular Optimizer -------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 12 unchanged lines hidden (view full) ---

21#include "llvm/Analysis/DebugInfo.h"
22#include "llvm/Analysis/Verifier.h"
23#include "llvm/Analysis/LoopPass.h"
24#include "llvm/Analysis/RegionPass.h"
25#include "llvm/Analysis/CallGraph.h"
26#include "llvm/Target/TargetData.h"
27#include "llvm/Target/TargetLibraryInfo.h"
28#include "llvm/Target/TargetMachine.h"
1//===- opt.cpp - The LLVM Modular Optimizer -------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 12 unchanged lines hidden (view full) ---

21#include "llvm/Analysis/DebugInfo.h"
22#include "llvm/Analysis/Verifier.h"
23#include "llvm/Analysis/LoopPass.h"
24#include "llvm/Analysis/RegionPass.h"
25#include "llvm/Analysis/CallGraph.h"
26#include "llvm/Target/TargetData.h"
27#include "llvm/Target/TargetLibraryInfo.h"
28#include "llvm/Target/TargetMachine.h"
29#include "llvm/ADT/StringSet.h"
29#include "llvm/ADT/Triple.h"
30#include "llvm/Support/PassNameParser.h"
31#include "llvm/Support/Signals.h"
32#include "llvm/Support/Debug.h"
33#include "llvm/Support/IRReader.h"
34#include "llvm/Support/ManagedStatic.h"
35#include "llvm/Support/PluginLoader.h"
36#include "llvm/Support/PrettyStackTrace.h"

--- 90 unchanged lines hidden (view full) ---

127
128static cl::alias
129QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
130
131static cl::opt<bool>
132AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
133
134static cl::opt<bool>
30#include "llvm/ADT/Triple.h"
31#include "llvm/Support/PassNameParser.h"
32#include "llvm/Support/Signals.h"
33#include "llvm/Support/Debug.h"
34#include "llvm/Support/IRReader.h"
35#include "llvm/Support/ManagedStatic.h"
36#include "llvm/Support/PluginLoader.h"
37#include "llvm/Support/PrettyStackTrace.h"

--- 90 unchanged lines hidden (view full) ---

128
129static cl::alias
130QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
131
132static cl::opt<bool>
133AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
134
135static cl::opt<bool>
135PrintBreakpoints("print-breakpoints-for-testing",
136PrintBreakpoints("print-breakpoints-for-testing",
136 cl::desc("Print select breakpoints location for testing"));
137
138static cl::opt<std::string>
137 cl::desc("Print select breakpoints location for testing"));
138
139static cl::opt<std::string>
139DefaultDataLayout("default-data-layout",
140DefaultDataLayout("default-data-layout",
140 cl::desc("data layout string to use if not specified by module"),
141 cl::value_desc("layout-string"), cl::init(""));
142
143// ---------- Define Printers for module and function passes ------------
144namespace {
145
146struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
147 static char ID;

--- 174 unchanged lines hidden (view full) ---

322 }
323
324 virtual bool runOnBasicBlock(BasicBlock &BB) {
325 if (!Quiet)
326 Out << "Printing Analysis info for BasicBlock '" << BB.getName()
327 << "': Pass " << PassToPrint->getPassName() << ":\n";
328
329 // Get and print pass...
141 cl::desc("data layout string to use if not specified by module"),
142 cl::value_desc("layout-string"), cl::init(""));
143
144// ---------- Define Printers for module and function passes ------------
145namespace {
146
147struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
148 static char ID;

--- 174 unchanged lines hidden (view full) ---

323 }
324
325 virtual bool runOnBasicBlock(BasicBlock &BB) {
326 if (!Quiet)
327 Out << "Printing Analysis info for BasicBlock '" << BB.getName()
328 << "': Pass " << PassToPrint->getPassName() << ":\n";
329
330 // Get and print pass...
330 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
331 getAnalysisID(PassToPrint->getTypeInfo()).print(Out,
331 BB.getParent()->getParent());
332 return false;
333 }
334
335 virtual const char *getPassName() const { return PassName.c_str(); }
336
337 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
338 AU.addRequiredID(PassToPrint->getTypeInfo());
339 AU.setPreservesAll();
340 }
341};
342
343char BasicBlockPassPrinter::ID = 0;
344
332 BB.getParent()->getParent());
333 return false;
334 }
335
336 virtual const char *getPassName() const { return PassName.c_str(); }
337
338 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
339 AU.addRequiredID(PassToPrint->getTypeInfo());
340 AU.setPreservesAll();
341 }
342};
343
344char BasicBlockPassPrinter::ID = 0;
345
345struct BreakpointPrinter : public FunctionPass {
346struct BreakpointPrinter : public ModulePass {
346 raw_ostream &Out;
347 static char ID;
348
349 BreakpointPrinter(raw_ostream &out)
347 raw_ostream &Out;
348 static char ID;
349
350 BreakpointPrinter(raw_ostream &out)
350 : FunctionPass(ID), Out(out) {
351 : ModulePass(ID), Out(out) {
351 }
352
352 }
353
353 virtual bool runOnFunction(Function &F) {
354 BasicBlock &EntryBB = F.getEntryBlock();
355 BasicBlock::const_iterator BI = EntryBB.end();
356 --BI;
357 do {
358 const Instruction *In = BI;
359 const DebugLoc DL = In->getDebugLoc();
360 if (!DL.isUnknown()) {
361 DIScope S(DL.getScope(getGlobalContext()));
362 Out << S.getFilename() << " " << DL.getLine() << "\n";
363 break;
354 void getContextName(DIDescriptor Context, std::string &N) {
355 if (Context.isNameSpace()) {
356 DINameSpace NS(Context);
357 if (!NS.getName().empty()) {
358 getContextName(NS.getContext(), N);
359 N = N + NS.getName().str() + "::";
364 }
360 }
365 --BI;
366 } while (BI != EntryBB.begin());
361 } else if (Context.isType()) {
362 DIType TY(Context);
363 if (!TY.getName().empty()) {
364 getContextName(TY.getContext(), N);
365 N = N + TY.getName().str() + "::";
366 }
367 }
368 }
369
370 virtual bool runOnModule(Module &M) {
371 StringSet<> Processed;
372 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
373 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
374 std::string Name;
375 DISubprogram SP(NMD->getOperand(i));
376 if (SP.Verify())
377 getContextName(SP.getContext(), Name);
378 Name = Name + SP.getDisplayName().str();
379 if (!Name.empty() && Processed.insert(Name)) {
380 Out << Name << "\n";
381 }
382 }
367 return false;
368 }
369
370 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
371 AU.setPreservesAll();
372 }
373};
374

--- 83 unchanged lines hidden (view full) ---

458 sys::PrintStackTraceOnErrorSignal();
459 llvm::PrettyStackTraceProgram X(argc, argv);
460
461 // Enable debug stream buffering.
462 EnableDebugBuffering = true;
463
464 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
465 LLVMContext &Context = getGlobalContext();
383 return false;
384 }
385
386 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
387 AU.setPreservesAll();
388 }
389};
390

--- 83 unchanged lines hidden (view full) ---

474 sys::PrintStackTraceOnErrorSignal();
475 llvm::PrettyStackTraceProgram X(argc, argv);
476
477 // Enable debug stream buffering.
478 EnableDebugBuffering = true;
479
480 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
481 LLVMContext &Context = getGlobalContext();
466
482
467 // Initialize passes
468 PassRegistry &Registry = *PassRegistry::getPassRegistry();
469 initializeCore(Registry);
470 initializeScalarOpts(Registry);
471 initializeIPO(Registry);
472 initializeAnalysis(Registry);
473 initializeIPA(Registry);
474 initializeTransformUtils(Registry);
475 initializeInstCombine(Registry);
476 initializeInstrumentation(Registry);
477 initializeTarget(Registry);
483 // Initialize passes
484 PassRegistry &Registry = *PassRegistry::getPassRegistry();
485 initializeCore(Registry);
486 initializeScalarOpts(Registry);
487 initializeIPO(Registry);
488 initializeAnalysis(Registry);
489 initializeIPA(Registry);
490 initializeTransformUtils(Registry);
491 initializeInstCombine(Registry);
492 initializeInstrumentation(Registry);
493 initializeTarget(Registry);
478
494
479 cl::ParseCommandLineOptions(argc, argv,
480 "llvm .bc -> .bc modular optimizer and analysis printer\n");
481
482 if (AnalyzeOnly && NoOutput) {
483 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
484 return 1;
485 }
486

--- 41 unchanged lines hidden (view full) ---

528
529 // Create a PassManager to hold and optimize the collection of passes we are
530 // about to build.
531 //
532 PassManager Passes;
533
534 // Add an appropriate TargetLibraryInfo pass for the module's triple.
535 TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
495 cl::ParseCommandLineOptions(argc, argv,
496 "llvm .bc -> .bc modular optimizer and analysis printer\n");
497
498 if (AnalyzeOnly && NoOutput) {
499 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
500 return 1;
501 }
502

--- 41 unchanged lines hidden (view full) ---

544
545 // Create a PassManager to hold and optimize the collection of passes we are
546 // about to build.
547 //
548 PassManager Passes;
549
550 // Add an appropriate TargetLibraryInfo pass for the module's triple.
551 TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
536
552
537 // The -disable-simplify-libcalls flag actually disables all builtin optzns.
538 if (DisableSimplifyLibCalls)
539 TLI->disableAllFunctions();
540 Passes.add(TLI);
553 // The -disable-simplify-libcalls flag actually disables all builtin optzns.
554 if (DisableSimplifyLibCalls)
555 TLI->disableAllFunctions();
556 Passes.add(TLI);
541
557
542 // Add an appropriate TargetData instance for this module.
543 TargetData *TD = 0;
544 const std::string &ModuleDataLayout = M.get()->getDataLayout();
545 if (!ModuleDataLayout.empty())
546 TD = new TargetData(ModuleDataLayout);
547 else if (!DefaultDataLayout.empty())
548 TD = new TargetData(DefaultDataLayout);
549

--- 7 unchanged lines hidden (view full) ---

557 FPasses->add(new TargetData(*TD));
558 }
559
560 if (PrintBreakpoints) {
561 // Default to standard output.
562 if (!Out) {
563 if (OutputFilename.empty())
564 OutputFilename = "-";
558 // Add an appropriate TargetData instance for this module.
559 TargetData *TD = 0;
560 const std::string &ModuleDataLayout = M.get()->getDataLayout();
561 if (!ModuleDataLayout.empty())
562 TD = new TargetData(ModuleDataLayout);
563 else if (!DefaultDataLayout.empty())
564 TD = new TargetData(DefaultDataLayout);
565

--- 7 unchanged lines hidden (view full) ---

573 FPasses->add(new TargetData(*TD));
574 }
575
576 if (PrintBreakpoints) {
577 // Default to standard output.
578 if (!Out) {
579 if (OutputFilename.empty())
580 OutputFilename = "-";
565
581
566 std::string ErrorInfo;
567 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
568 raw_fd_ostream::F_Binary));
569 if (!ErrorInfo.empty()) {
570 errs() << ErrorInfo << '\n';
571 return 1;
572 }
573 }

--- 106 unchanged lines hidden (view full) ---

680 // Write bitcode or assembly to the output as the last step...
681 if (!NoOutput && !AnalyzeOnly) {
682 if (OutputAssembly)
683 Passes.add(createPrintModulePass(&Out->os()));
684 else
685 Passes.add(createBitcodeWriterPass(Out->os()));
686 }
687
582 std::string ErrorInfo;
583 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
584 raw_fd_ostream::F_Binary));
585 if (!ErrorInfo.empty()) {
586 errs() << ErrorInfo << '\n';
587 return 1;
588 }
589 }

--- 106 unchanged lines hidden (view full) ---

696 // Write bitcode or assembly to the output as the last step...
697 if (!NoOutput && !AnalyzeOnly) {
698 if (OutputAssembly)
699 Passes.add(createPrintModulePass(&Out->os()));
700 else
701 Passes.add(createBitcodeWriterPass(Out->os()));
702 }
703
704 // Before executing passes, print the final values of the LLVM options.
705 cl::PrintOptionValues();
706
688 // Now that we have all of the passes ready, run them.
689 Passes.run(*M.get());
690
691 // Declare success.
692 if (!NoOutput || PrintBreakpoints)
693 Out->keep();
694
695 return 0;
696}
707 // Now that we have all of the passes ready, run them.
708 Passes.run(*M.get());
709
710 // Declare success.
711 if (!NoOutput || PrintBreakpoints)
712 Out->keep();
713
714 return 0;
715}