LLVM  4.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 
16 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/Support/Debug.h"
20 using namespace llvm;
21 
22 #define DEBUG_TYPE "tailduplication"
23 
24 namespace {
25 /// Perform tail duplication. Delegates to TailDuplicator
26 class TailDuplicatePass : public MachineFunctionPass {
27  TailDuplicator Duplicator;
28 
29 public:
30  static char ID;
31  explicit TailDuplicatePass() : MachineFunctionPass(ID) {}
32 
33  bool runOnMachineFunction(MachineFunction &MF) override;
34 
35  void getAnalysisUsage(AnalysisUsage &AU) const override;
36 };
37 
38 char TailDuplicatePass::ID = 0;
39 }
40 
42 
43 INITIALIZE_PASS(TailDuplicatePass, "tailduplication", "Tail Duplication", false,
44  false)
45 
46 bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) {
47  if (skipFunction(*MF.getFunction()))
48  return false;
49 
50  auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
51 
52  Duplicator.initMF(MF, MBPI, /* LayoutMode */ false);
53 
54  bool MadeChange = false;
55  while (Duplicator.tailDuplicateBlocks())
56  MadeChange = true;
57 
58  return MadeChange;
59 }
60 
61 void TailDuplicatePass::getAnalysisUsage(AnalysisUsage &AU) const {
64 }
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.
char & TailDuplicateID
TailDuplicate - Duplicate blocks with unconditional branches into tails of their predecessors.
INITIALIZE_PASS(TailDuplicatePass,"tailduplication","Tail Duplication", false, false) bool TailDuplicatePass
Utility class to perform tail duplication.