comparison lib/CodeGen/TailDuplication.cpp @ 121:803732b1fca8

LLVM 5.0
author kono
date Fri, 27 Oct 2017 17:07:41 +0900
parents 1172e4bd9c6f
children 3a76565eade5
comparison
equal deleted inserted replaced
120:1172e4bd9c6f 121:803732b1fca8
1 //===-- TailDuplication.cpp - Duplicate blocks into predecessors' tails ---===// 1 //===- TailDuplication.cpp - Duplicate blocks into predecessors' tails ----===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
10 // This pass duplicates basic blocks ending in unconditional branches into 10 // This pass duplicates basic blocks ending in unconditional branches into
11 // the tails of their predecessors, using the TailDuplicator utility class. 11 // the tails of their predecessors, using the TailDuplicator utility class.
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
16 #include "llvm/CodeGen/MachineFunction.h"
15 #include "llvm/CodeGen/MachineFunctionPass.h" 17 #include "llvm/CodeGen/MachineFunctionPass.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/CodeGen/TailDuplicator.h" 18 #include "llvm/CodeGen/TailDuplicator.h"
18 #include "llvm/IR/Function.h" 19 #include "llvm/Pass.h"
19 #include "llvm/Support/Debug.h" 20
20 using namespace llvm; 21 using namespace llvm;
21 22
22 #define DEBUG_TYPE "tailduplication" 23 #define DEBUG_TYPE "tailduplication"
23 24
24 namespace { 25 namespace {
26
25 /// Perform tail duplication. Delegates to TailDuplicator 27 /// Perform tail duplication. Delegates to TailDuplicator
26 class TailDuplicatePass : public MachineFunctionPass { 28 class TailDuplicatePass : public MachineFunctionPass {
27 TailDuplicator Duplicator; 29 TailDuplicator Duplicator;
28 30
29 public: 31 public:
30 static char ID; 32 static char ID;
33
31 explicit TailDuplicatePass() : MachineFunctionPass(ID) {} 34 explicit TailDuplicatePass() : MachineFunctionPass(ID) {}
32 35
33 bool runOnMachineFunction(MachineFunction &MF) override; 36 bool runOnMachineFunction(MachineFunction &MF) override;
34 37
35 void getAnalysisUsage(AnalysisUsage &AU) const override; 38 void getAnalysisUsage(AnalysisUsage &AU) const override;
36 }; 39 };
37 40
41 } // end anonymous namespace
42
38 char TailDuplicatePass::ID = 0; 43 char TailDuplicatePass::ID = 0;
39 }
40 44
41 char &llvm::TailDuplicateID = TailDuplicatePass::ID; 45 char &llvm::TailDuplicateID = TailDuplicatePass::ID;
42 46
43 INITIALIZE_PASS(TailDuplicatePass, "tailduplication", "Tail Duplication", false, 47 INITIALIZE_PASS(TailDuplicatePass, DEBUG_TYPE, "Tail Duplication", false, false)
44 false)
45 48
46 bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) { 49 bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) {
47 if (skipFunction(*MF.getFunction())) 50 if (skipFunction(*MF.getFunction()))
48 return false; 51 return false;
49 52
50 auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>(); 53 auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
51 54
52 Duplicator.initMF(MF, MBPI, /* LayoutMode */ false); 55 // TODO: Querying isSSA() to determine pre-/post-regalloc is fragile, better
56 // split this into two passes instead.
57 bool PreRegAlloc = MF.getRegInfo().isSSA();
58 Duplicator.initMF(MF, PreRegAlloc, MBPI, /* LayoutMode */ false);
53 59
54 bool MadeChange = false; 60 bool MadeChange = false;
55 while (Duplicator.tailDuplicateBlocks()) 61 while (Duplicator.tailDuplicateBlocks())
56 MadeChange = true; 62 MadeChange = true;
57 63