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-09-23 13:06:45 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       39623 :   TailDuplicateBase(char &PassID, bool PreRegAlloc)
      35       39623 :     : MachineFunctionPass(PassID), PreRegAlloc(PreRegAlloc) {}
      36             : 
      37             :   bool runOnMachineFunction(MachineFunction &MF) override;
      38             : 
      39       39307 :   void getAnalysisUsage(AnalysisUsage &AU) const override {
      40             :     AU.addRequired<MachineBranchProbabilityInfo>();
      41       39307 :     MachineFunctionPass::getAnalysisUsage(AU);
      42       39307 :   }
      43             : };
      44             : 
      45             : class TailDuplicate : public TailDuplicateBase {
      46             : public:
      47             :   static char ID;
      48       19562 :   TailDuplicate() : TailDuplicateBase(ID, false) {
      49       19562 :     initializeTailDuplicatePass(*PassRegistry::getPassRegistry());
      50       19562 :   }
      51             : };
      52             : 
      53             : class EarlyTailDuplicate : public TailDuplicateBase {
      54             : public:
      55             :   static char ID;
      56       20061 :   EarlyTailDuplicate() : TailDuplicateBase(ID, true) {
      57       20061 :     initializeEarlyTailDuplicatePass(*PassRegistry::getPassRegistry());
      58       20061 :   }
      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      106435 : INITIALIZE_PASS(TailDuplicate, DEBUG_TYPE, "Tail Duplication", false, false)
      70      106934 : INITIALIZE_PASS(EarlyTailDuplicate, "early-tailduplication",
      71             :                 "Early Tail Duplication", false, false)
      72             : 
      73      387406 : bool TailDuplicateBase::runOnMachineFunction(MachineFunction &MF) {
      74      387406 :   if (skipFunction(MF.getFunction()))
      75             :     return false;
      76             : 
      77      387062 :   auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
      78      387062 :   Duplicator.initMF(MF, PreRegAlloc, MBPI, /*LayoutMode=*/false);
      79             : 
      80             :   bool MadeChange = false;
      81      388307 :   while (Duplicator.tailDuplicateBlocks())
      82             :     MadeChange = true;
      83             : 
      84             :   return MadeChange;
      85             : }

Generated by: LCOV version 1.13