LLVM  9.0.0svn
TailDuplication.cpp
Go to the documentation of this file.
1 //===- TailDuplication.cpp - Duplicate blocks into predecessors' tails ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file This pass duplicates basic blocks ending in unconditional branches
10 /// into the tails of their predecessors, using the TailDuplicator utility
11 /// class.
12 //
13 //===----------------------------------------------------------------------===//
14 
19 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Pass.h"
22 
23 using namespace llvm;
24 
25 #define DEBUG_TYPE "tailduplication"
26 
27 namespace {
28 
29 class TailDuplicateBase : public MachineFunctionPass {
30  TailDuplicator Duplicator;
31  bool PreRegAlloc;
32 public:
33  TailDuplicateBase(char &PassID, bool PreRegAlloc)
34  : MachineFunctionPass(PassID), PreRegAlloc(PreRegAlloc) {}
35 
36  bool runOnMachineFunction(MachineFunction &MF) override;
37 
38  void getAnalysisUsage(AnalysisUsage &AU) const override {
41  }
42 };
43 
44 class TailDuplicate : public TailDuplicateBase {
45 public:
46  static char ID;
47  TailDuplicate() : TailDuplicateBase(ID, false) {
49  }
50 };
51 
52 class EarlyTailDuplicate : public TailDuplicateBase {
53 public:
54  static char ID;
55  EarlyTailDuplicate() : TailDuplicateBase(ID, true) {
57  }
58 };
59 
60 } // end anonymous namespace
61 
64 
67 
68 INITIALIZE_PASS(TailDuplicate, DEBUG_TYPE, "Tail Duplication", false, false)
69 INITIALIZE_PASS(EarlyTailDuplicate, "early-tailduplication",
70  "Early Tail Duplication", false, false)
71 
72 bool TailDuplicateBase::runOnMachineFunction(MachineFunction &MF) {
73  if (skipFunction(MF.getFunction()))
74  return false;
75 
76  auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
77  Duplicator.initMF(MF, PreRegAlloc, MBPI, /*LayoutMode=*/false);
78 
79  bool MadeChange = false;
80  while (Duplicator.tailDuplicateBlocks())
81  MadeChange = true;
82 
83  return MadeChange;
84 }
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:23
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.