LCOV - code coverage report
Current view: top level - lib/CodeGen - MachineFunctionPass.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 18 18 100.0 %
Date: 2018-10-20 13:21:21 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- MachineFunctionPass.cpp -------------------------------------------===//
       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             : // This file contains the definitions of the MachineFunctionPass members.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/CodeGen/MachineFunctionPass.h"
      15             : #include "llvm/Analysis/AliasAnalysis.h"
      16             : #include "llvm/Analysis/BasicAliasAnalysis.h"
      17             : #include "llvm/Analysis/DominanceFrontier.h"
      18             : #include "llvm/Analysis/GlobalsModRef.h"
      19             : #include "llvm/Analysis/IVUsers.h"
      20             : #include "llvm/Analysis/LoopInfo.h"
      21             : #include "llvm/Analysis/MemoryDependenceAnalysis.h"
      22             : #include "llvm/Analysis/ScalarEvolution.h"
      23             : #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
      24             : #include "llvm/CodeGen/MachineFunction.h"
      25             : #include "llvm/CodeGen/MachineModuleInfo.h"
      26             : #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
      27             : #include "llvm/CodeGen/Passes.h"
      28             : #include "llvm/IR/Dominators.h"
      29             : #include "llvm/IR/Function.h"
      30             : 
      31             : using namespace llvm;
      32             : using namespace ore;
      33             : 
      34         274 : Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
      35             :                                              const std::string &Banner) const {
      36         274 :   return createMachineFunctionPrinterPass(O, Banner);
      37             : }
      38             : 
      39    28256189 : bool MachineFunctionPass::runOnFunction(Function &F) {
      40             :   // Do not codegen any 'available_externally' functions at all, they have
      41             :   // definitions outside the translation unit.
      42    28256189 :   if (F.hasAvailableExternallyLinkage())
      43             :     return false;
      44             : 
      45    28254049 :   MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
      46    28254048 :   MachineFunction &MF = MMI.getOrCreateMachineFunction(F);
      47             : 
      48             :   MachineFunctionProperties &MFProps = MF.getProperties();
      49             : 
      50             : #ifndef NDEBUG
      51             :   if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
      52             :     errs() << "MachineFunctionProperties required by " << getPassName()
      53             :            << " pass are not met by function " << F.getName() << ".\n"
      54             :            << "Required properties: ";
      55             :     RequiredProperties.print(errs());
      56             :     errs() << "\nCurrent properties: ";
      57             :     MFProps.print(errs());
      58             :     errs() << "\n";
      59             :     llvm_unreachable("MachineFunctionProperties check failed");
      60             :   }
      61             : #endif
      62             :   // Collect the MI count of the function before the pass.
      63             :   unsigned CountBefore, CountAfter;
      64             : 
      65             :   // Check if the user asked for size remarks.
      66             :   bool ShouldEmitSizeRemarks =
      67    28254048 :       F.getParent()->shouldEmitInstrCountChangedRemark();
      68             : 
      69             :   // If we want size remarks, collect the number of MachineInstrs in our
      70             :   // MachineFunction before the pass runs.
      71    28254048 :   if (ShouldEmitSizeRemarks)
      72         110 :     CountBefore = MF.getInstructionCount();
      73             : 
      74    28254048 :   bool RV = runOnMachineFunction(MF);
      75             : 
      76    28253932 :   if (ShouldEmitSizeRemarks) {
      77             :     // We wanted size remarks. Check if there was a change to the number of
      78             :     // MachineInstrs in the module. Emit a remark if there was a change.
      79         110 :     CountAfter = MF.getInstructionCount();
      80         110 :     if (CountBefore != CountAfter) {
      81             :       MachineOptimizationRemarkEmitter MORE(MF, nullptr);
      82           3 :       MORE.emit([&]() {
      83             :         int64_t Delta = static_cast<int64_t>(CountAfter) -
      84             :                         static_cast<int64_t>(CountBefore);
      85             :         MachineOptimizationRemarkAnalysis R("size-info", "FunctionMISizeChange",
      86             :                                             MF.getFunction().getSubprogram(),
      87             :                                             &MF.front());
      88             :         R << NV("Pass", getPassName())
      89             :           << ": Function: " << NV("Function", F.getName()) << ": "
      90             :           << "MI Instruction count changed from "
      91             :           << NV("MIInstrsBefore", CountBefore) << " to "
      92             :           << NV("MIInstrsAfter", CountAfter)
      93             :           << "; Delta: " << NV("Delta", Delta);
      94             :         return R;
      95             :       });
      96             :     }
      97             :   }
      98             : 
      99             :   MFProps.set(SetProperties);
     100             :   MFProps.reset(ClearedProperties);
     101    28253942 :   return RV;
     102             : }
     103             : 
     104     2347614 : void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const {
     105             :   AU.addRequired<MachineModuleInfo>();
     106             :   AU.addPreserved<MachineModuleInfo>();
     107             : 
     108             :   // MachineFunctionPass preserves all LLVM IR passes, but there's no
     109             :   // high-level way to express this. Instead, just list a bunch of
     110             :   // passes explicitly. This does not include setPreservesCFG,
     111             :   // because CodeGen overloads that to mean preserving the MachineBasicBlock
     112             :   // CFG in addition to the LLVM IR CFG.
     113             :   AU.addPreserved<BasicAAWrapperPass>();
     114             :   AU.addPreserved<DominanceFrontierWrapperPass>();
     115             :   AU.addPreserved<DominatorTreeWrapperPass>();
     116             :   AU.addPreserved<AAResultsWrapperPass>();
     117             :   AU.addPreserved<GlobalsAAWrapperPass>();
     118             :   AU.addPreserved<IVUsersWrapperPass>();
     119             :   AU.addPreserved<LoopInfoWrapperPass>();
     120             :   AU.addPreserved<MemoryDependenceWrapperPass>();
     121             :   AU.addPreserved<ScalarEvolutionWrapperPass>();
     122             :   AU.addPreserved<SCEVAAWrapperPass>();
     123             : 
     124     2347615 :   FunctionPass::getAnalysisUsage(AU);
     125     2347615 : }

Generated by: LCOV version 1.13