LLVM  8.0.1
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 /// \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 
20 #include "llvm/CodeGen/Passes.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  TailDuplicateBase(char &PassID, bool PreRegAlloc)
35  : MachineFunctionPass(PassID), PreRegAlloc(PreRegAlloc) {}
36 
37  bool runOnMachineFunction(MachineFunction &MF) override;
38 
39  void getAnalysisUsage(AnalysisUsage &AU) const override {
42  }
43 };
44 
45 class TailDuplicate : public TailDuplicateBase {
46 public:
47  static char ID;
48  TailDuplicate() : TailDuplicateBase(ID, false) {
50  }
51 };
52 
53 class EarlyTailDuplicate : public TailDuplicateBase {
54 public:
55  static char ID;
56  EarlyTailDuplicate() : TailDuplicateBase(ID, true) {
58  }
59 };
60 
61 } // end anonymous namespace
62 
65 
68 
69 INITIALIZE_PASS(TailDuplicate, DEBUG_TYPE, "Tail Duplication", false, false)
70 INITIALIZE_PASS(EarlyTailDuplicate, "early-tailduplication",
71  "Early Tail Duplication", false, false)
72 
73 bool TailDuplicateBase::runOnMachineFunction(MachineFunction &MF) {
74  if (skipFunction(MF.getFunction()))
75  return false;
76 
77  auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
78  Duplicator.initMF(MF, PreRegAlloc, MBPI, /*LayoutMode=*/false);
79 
80  bool MadeChange = false;
81  while (Duplicator.tailDuplicateBlocks())
82  MadeChange = true;
83 
84  return MadeChange;
85 }
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void initializeEarlyTailDuplicatePass(PassRegistry &)
AnalysisUsage & addRequired()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
char & EarlyTailDuplicateID
Duplicate blocks with unconditional branches into tails of their predecessors.
INITIALIZE_PASS(EarlyTailDuplicate, "early-tailduplication", "Early Tail Duplication", false, false) bool TailDuplicateBase
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
TargetPassConfig.
char & TailDuplicateID
TailDuplicate - Duplicate blocks with unconditional branches into tails of their predecessors.
#define DEBUG_TYPE
void initializeTailDuplicatePass(PassRegistry &)
Utility class to perform tail duplication.