LLVM  5.0.0
TailDuplication.cpp
Go to the documentation of this file.
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 
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  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 
46 
47 INITIALIZE_PASS(TailDuplicatePass, DEBUG_TYPE, "Tail Duplication", false, false)
48 
49 bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) {
50  if (skipFunction(*MF.getFunction()))
51  return false;
52 
53  auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
54 
55  Duplicator.initMF(MF, MBPI, /* LayoutMode */ false);
56 
57  bool MadeChange = false;
58  while (Duplicator.tailDuplicateBlocks())
59  MadeChange = true;
60 
61  return MadeChange;
62 }
63 
64 void TailDuplicatePass::getAnalysisUsage(AnalysisUsage &AU) const {
67 }
AnalysisUsage & addRequired()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
char & TailDuplicateID
TailDuplicate - Duplicate blocks with unconditional branches into tails of their predecessors.
#define DEBUG_TYPE
Utility class to perform tail duplication.