diff options
Diffstat (limited to 'llvm/tools/opt/opt.cpp')
-rw-r--r-- | llvm/tools/opt/opt.cpp | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 15495a511d06..75a6cdc3892b 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "BreakpointPrinter.h" -#include "Debugify.h" #include "NewPMDriver.h" #include "PassPrinters.h" #include "llvm/ADT/Triple.h" @@ -56,6 +55,7 @@ #include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/Utils/Cloning.h" +#include "llvm/Transforms/Utils/Debugify.h" #include <algorithm> #include <memory> using namespace llvm; @@ -193,6 +193,12 @@ static cl::opt<bool> DisableSimplifyLibCalls("disable-simplify-libcalls", cl::desc("Disable simplify-libcalls")); +static cl::list<std::string> +DisableBuiltins("disable-builtin", + cl::desc("Disable specific target library builtin function"), + cl::ZeroOrMore); + + static cl::opt<bool> Quiet("q", cl::desc("Obsolete option"), cl::Hidden); @@ -328,7 +334,7 @@ public: PassKind Kind = P->getPassKind(); StringRef Name = P->getPassName(); - // TODO: Implement Debugify for BasicBlockPass, LoopPass. + // TODO: Implement Debugify for LoopPass. switch (Kind) { case PT_Function: super::add(createDebugifyFunctionPass()); @@ -476,12 +482,32 @@ static TargetMachine* GetTargetMachine(Triple TheTriple, StringRef CPUStr, getCodeModel(), GetCodeGenOptLevel()); } -#ifdef LINK_POLLY_INTO_TOOLS -namespace polly { -void initializePollyPasses(llvm::PassRegistry &Registry); -} +#ifdef BUILD_EXAMPLES +void initializeExampleIRTransforms(llvm::PassRegistry &Registry); #endif + +void exportDebugifyStats(llvm::StringRef Path, const DebugifyStatsMap &Map) { + std::error_code EC; + raw_fd_ostream OS{Path, EC}; + if (EC) { + errs() << "Could not open file: " << EC.message() << ", " << Path << '\n'; + return; + } + + OS << "Pass Name" << ',' << "# of missing debug values" << ',' + << "# of missing locations" << ',' << "Missing/Expected value ratio" << ',' + << "Missing/Expected location ratio" << '\n'; + for (const auto &Entry : Map) { + StringRef Pass = Entry.first; + DebugifyStatistics Stats = Entry.second; + + OS << Pass << ',' << Stats.NumDbgValuesMissing << ',' + << Stats.NumDbgLocsMissing << ',' << Stats.getMissingValueRatio() << ',' + << Stats.getEmptyLocationRatio() << '\n'; + } +} + //===----------------------------------------------------------------------===// // main for opt // @@ -535,9 +561,10 @@ int main(int argc, char **argv) { initializeWasmEHPreparePass(Registry); initializeWriteBitcodePassPass(Registry); initializeHardwareLoopsPass(Registry); + initializeTypePromotionPass(Registry); -#ifdef LINK_POLLY_INTO_TOOLS - polly::initializePollyPasses(Registry); +#ifdef BUILD_EXAMPLES + initializeExampleIRTransforms(Registry); #endif cl::ParseCommandLineOptions(argc, argv, @@ -697,6 +724,19 @@ int main(int argc, char **argv) { // The -disable-simplify-libcalls flag actually disables all builtin optzns. if (DisableSimplifyLibCalls) TLII.disableAllFunctions(); + else { + // Disable individual builtin functions in TargetLibraryInfo. + LibFunc F; + for (auto &FuncName : DisableBuiltins) + if (TLII.getLibFunc(FuncName, F)) + TLII.setUnavailable(F); + else { + errs() << argv[0] << ": cannot disable nonexistent builtin function " + << FuncName << '\n'; + return 1; + } + } + Passes.add(new TargetLibraryInfoWrapperPass(TLII)); // Add internal analysis passes from the target machine. @@ -790,9 +830,6 @@ int main(int argc, char **argv) { if (AnalyzeOnly) { switch (Kind) { - case PT_BasicBlock: - Passes.add(createBasicBlockPassPrinter(PassInf, Out->os(), Quiet)); - break; case PT_Region: Passes.add(createRegionPassPrinter(PassInf, Out->os(), Quiet)); break; @@ -863,8 +900,10 @@ int main(int argc, char **argv) { std::unique_ptr<raw_svector_ostream> BOS; raw_ostream *OS = nullptr; + const bool ShouldEmitOutput = !NoOutput && !AnalyzeOnly; + // Write bitcode or assembly to the output as the last step... - if (!NoOutput && !AnalyzeOnly) { + if (ShouldEmitOutput || RunTwice) { assert(Out); OS = &Out->os(); if (RunTwice) { @@ -912,13 +951,16 @@ int main(int argc, char **argv) { "Writing the result of the second run to the specified output.\n" "To generate the one-run comparison binary, just run without\n" "the compile-twice option\n"; - Out->os() << BOS->str(); - Out->keep(); + if (ShouldEmitOutput) { + Out->os() << BOS->str(); + Out->keep(); + } if (RemarksFile) RemarksFile->keep(); return 1; } - Out->os() << BOS->str(); + if (ShouldEmitOutput) + Out->os() << BOS->str(); } if (DebugifyEach && !DebugifyExport.empty()) |