Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/CodeGen/TailDuplication.cpp
Line
Count
Source
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
// This pass duplicates basic blocks ending in unconditional branches into
11
// the tails of their predecessors, using the TailDuplicator utility class.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
16
#include "llvm/CodeGen/MachineFunction.h"
17
#include "llvm/CodeGen/MachineFunctionPass.h"
18
#include "llvm/CodeGen/TailDuplicator.h"
19
#include "llvm/Pass.h"
20
21
using namespace llvm;
22
23
#define DEBUG_TYPE "tailduplication"
24
25
namespace {
26
27
/// Perform tail duplication. Delegates to TailDuplicator
28
class TailDuplicatePass : public MachineFunctionPass {
29
  TailDuplicator Duplicator;
30
31
public:
32
  static char ID;
33
34
63.7k
  explicit TailDuplicatePass() : MachineFunctionPass(ID) {}
35
36
  bool runOnMachineFunction(MachineFunction &MF) override;
37
38
  void getAnalysisUsage(AnalysisUsage &AU) const override;
39
};
40
41
} // end anonymous namespace
42
43
char TailDuplicatePass::ID = 0;
44
45
char &llvm::TailDuplicateID = TailDuplicatePass::ID;
46
47
INITIALIZE_PASS(TailDuplicatePass, DEBUG_TYPE, "Tail Duplication", false, false)
48
49
1.17M
bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) {
50
1.17M
  if (skipFunction(*MF.getFunction()))
51
88
    return false;
52
1.17M
53
1.17M
  auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
54
1.17M
55
1.17M
  // TODO: Querying isSSA() to determine pre-/post-regalloc is fragile, better
56
1.17M
  // split this into two passes instead.
57
1.17M
  bool PreRegAlloc = MF.getRegInfo().isSSA();
58
1.17M
  Duplicator.initMF(MF, PreRegAlloc, MBPI, /* LayoutMode */ false);
59
1.17M
60
1.17M
  bool MadeChange = false;
61
1.22M
  while (Duplicator.tailDuplicateBlocks())
62
52.6k
    MadeChange = true;
63
1.17M
64
1.17M
  return MadeChange;
65
1.17M
}
66
67
63.5k
void TailDuplicatePass::getAnalysisUsage(AnalysisUsage &AU) const {
68
63.5k
  AU.addRequired<MachineBranchProbabilityInfo>();
69
63.5k
  MachineFunctionPass::getAnalysisUsage(AU);
70
63.5k
}