LCOV - code coverage report
Current view: top level - lib/IR - OptBisect.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 35 39 89.7 %
Date: 2017-09-14 15:23:50 Functions: 14 15 93.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/IR/OptBisect/Bisect.cpp - LLVM Bisect support -----------------===//
       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             : //===----------------------------------------------------------------------===//
       9             : //
      10             : /// \file
      11             : /// This file implements support for a bisecting optimizations based on a
      12             : /// command line option.
      13             : //
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #include "llvm/IR/OptBisect.h"
      17             : #include "llvm/ADT/StringRef.h"
      18             : #include "llvm/Analysis/CallGraph.h"
      19             : #include "llvm/Analysis/CallGraphSCCPass.h"
      20             : #include "llvm/Analysis/LoopInfo.h"
      21             : #include "llvm/Analysis/RegionInfo.h"
      22             : #include "llvm/IR/BasicBlock.h"
      23             : #include "llvm/IR/Function.h"
      24             : #include "llvm/IR/Module.h"
      25             : #include "llvm/Pass.h"
      26             : #include "llvm/Support/CommandLine.h"
      27             : #include "llvm/Support/raw_ostream.h"
      28             : #include <cassert>
      29             : #include <limits>
      30             : #include <string>
      31             : 
      32             : using namespace llvm;
      33             : 
      34       72330 : static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
      35      216990 :                                    cl::init(std::numeric_limits<int>::max()),
      36             :                                    cl::Optional,
      37      289320 :                                    cl::desc("Maximum optimization to perform"));
      38             : 
      39       22298 : OptBisect::OptBisect() {
      40       22298 :   BisectEnabled = OptBisectLimit != std::numeric_limits<int>::max();
      41       22298 : }
      42             : 
      43        2483 : static void printPassMessage(const StringRef &Name, int PassNum,
      44             :                              StringRef TargetDesc, bool Running) {
      45        4966 :   StringRef Status = Running ? "" : "NOT ";
      46        2483 :   errs() << "BISECT: " << Status << "running pass "
      47        4966 :          << "(" << PassNum << ") " << Name << " on " << TargetDesc << "\n";
      48        2483 : }
      49             : 
      50          92 : static std::string getDescription(const Module &M) {
      51         368 :   return "module (" + M.getName().str() + ")";
      52             : }
      53             : 
      54        1883 : static std::string getDescription(const Function &F) {
      55        7532 :   return "function (" + F.getName().str() + ")";
      56             : }
      57             : 
      58           0 : static std::string getDescription(const BasicBlock &BB) {
      59           0 :   return "basic block (" + BB.getName().str() + ") in function (" +
      60           0 :          BB.getParent()->getName().str() + ")";
      61             : }
      62             : 
      63             : static std::string getDescription(const Loop &L) {
      64             :   // FIXME: Move into LoopInfo so we can get a better description
      65             :   // (and avoid a circular dependency between IR and Analysis).
      66         260 :   return "loop";
      67             : }
      68             : 
      69             : static std::string getDescription(const Region &R) {
      70             :   // FIXME: Move into RegionInfo so we can get a better description
      71             :   // (and avoid a circular dependency between IR and Analysis).
      72           0 :   return "region";
      73             : }
      74             : 
      75         248 : static std::string getDescription(const CallGraphSCC &SCC) {
      76             :   // FIXME: Move into CallGraphSCCPass to avoid circular dependency between
      77             :   // IR and Analysis.
      78         496 :   std::string Desc = "SCC (";
      79         248 :   bool First = true;
      80        1240 :   for (CallGraphNode *CGN : SCC) {
      81         248 :     if (First)
      82             :       First = false;
      83             :     else
      84             :       Desc += ", ";
      85         248 :     Function *F = CGN->getFunction();
      86         248 :     if (F)
      87         180 :       Desc += F->getName();
      88             :     else
      89             :       Desc += "<<null function>>";
      90             :   }
      91         248 :   Desc += ")";
      92         248 :   return Desc;
      93             : }
      94             : 
      95             : // Force instantiations.
      96             : template bool OptBisect::shouldRunPass(const Pass *, const Module &);
      97             : template bool OptBisect::shouldRunPass(const Pass *, const Function &);
      98             : template bool OptBisect::shouldRunPass(const Pass *, const BasicBlock &);
      99             : template bool OptBisect::shouldRunPass(const Pass *, const Loop &);
     100             : template bool OptBisect::shouldRunPass(const Pass *, const CallGraphSCC &);
     101             : template bool OptBisect::shouldRunPass(const Pass *, const Region &);
     102             : 
     103             : template <class UnitT>
     104     5645565 : bool OptBisect::shouldRunPass(const Pass *P, const UnitT &U) {
     105     5645565 :   if (!BisectEnabled)
     106             :     return true;
     107        7709 :   return checkPass(P->getPassName(), getDescription(U));
     108             : }
     109             : 
     110        2483 : bool OptBisect::checkPass(const StringRef PassName,
     111             :                           const StringRef TargetDesc) {
     112             :   assert(BisectEnabled);
     113             : 
     114        2483 :   int CurBisectNum = ++LastBisectNum;
     115        4947 :   bool ShouldRun = (OptBisectLimit == -1 || CurBisectNum <= OptBisectLimit);
     116        2483 :   printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun);
     117        2483 :   return ShouldRun;
     118      216990 : }

Generated by: LCOV version 1.13