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

          Line data    Source code
       1             : //===- TailDuplication.cpp - Duplicate blocks into predecessors' tails ----===//
       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 This pass duplicates basic blocks ending in unconditional branches
      11             : /// into the tails of their predecessors, using the TailDuplicator utility
      12             : /// class.
      13             : //
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
      17             : #include "llvm/CodeGen/MachineFunction.h"
      18             : #include "llvm/CodeGen/MachineFunctionPass.h"
      19             : #include "llvm/CodeGen/MachineRegisterInfo.h"
      20             : #include "llvm/CodeGen/Passes.h"
      21             : #include "llvm/CodeGen/TailDuplicator.h"
      22             : #include "llvm/Pass.h"
      23             : 
      24             : using namespace llvm;
      25             : 
      26             : #define DEBUG_TYPE "tailduplication"
      27             : 
      28             : namespace {
      29             : 
      30             : class TailDuplicateBase : public MachineFunctionPass {
      31             :   TailDuplicator Duplicator;
      32             :   bool PreRegAlloc;
      33             : public:
      34       39913 :   TailDuplicateBase(char &PassID, bool PreRegAlloc)
      35       39913 :     : MachineFunctionPass(PassID), PreRegAlloc(PreRegAlloc) {}
      36             : 
      37             :   bool runOnMachineFunction(MachineFunction &MF) override;
      38             : 
      39       39589 :   void getAnalysisUsage(AnalysisUsage &AU) const override {
      40             :     AU.addRequired<MachineBranchProbabilityInfo>();
      41       39589 :     MachineFunctionPass::getAnalysisUsage(AU);
      42       39589 :   }
      43             : };
      44             : 
      45             : class TailDuplicate : public TailDuplicateBase {
      46             : public:
      47             :   static char ID;
      48       19707 :   TailDuplicate() : TailDuplicateBase(ID, false) {
      49       19707 :     initializeTailDuplicatePass(*PassRegistry::getPassRegistry());
      50       19707 :   }
      51             : };
      52             : 
      53             : class EarlyTailDuplicate : public TailDuplicateBase {
      54             : public:
      55             :   static char ID;
      56       20206 :   EarlyTailDuplicate() : TailDuplicateBase(ID, true) {
      57       20206 :     initializeEarlyTailDuplicatePass(*PassRegistry::getPassRegistry());
      58       20206 :   }
      59             : };
      60             : 
      61             : } // end anonymous namespace
      62             : 
      63             : char TailDuplicate::ID;
      64             : char EarlyTailDuplicate::ID;
      65             : 
      66             : char &llvm::TailDuplicateID = TailDuplicate::ID;
      67             : char &llvm::EarlyTailDuplicateID = EarlyTailDuplicate::ID;
      68             : 
      69      104854 : INITIALIZE_PASS(TailDuplicate, DEBUG_TYPE, "Tail Duplication", false, false)
      70      105353 : INITIALIZE_PASS(EarlyTailDuplicate, "early-tailduplication",
      71             :                 "Early Tail Duplication", false, false)
      72             : 
      73      392280 : bool TailDuplicateBase::runOnMachineFunction(MachineFunction &MF) {
      74      392280 :   if (skipFunction(MF.getFunction()))
      75             :     return false;
      76             : 
      77      391908 :   auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
      78      391908 :   Duplicator.initMF(MF, PreRegAlloc, MBPI, /*LayoutMode=*/false);
      79             : 
      80             :   bool MadeChange = false;
      81      393184 :   while (Duplicator.tailDuplicateBlocks())
      82             :     MadeChange = true;
      83             : 
      84             :   return MadeChange;
      85             : }

Generated by: LCOV version 1.13