[Alignment][NFC] Remove dependency on GlobalObject::setAlignment(unsigned)
[llvm-core.git] / lib / CodeGen / TailDuplication.cpp
blobba348b4a9d41b5e86223a3e36d104b7de61600f6
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.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
16 #include "llvm/CodeGen/MachineFunction.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/CodeGen/MachineRegisterInfo.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/CodeGen/TailDuplicator.h"
21 #include "llvm/Pass.h"
23 using namespace llvm;
25 #define DEBUG_TYPE "tailduplication"
27 namespace {
29 class TailDuplicateBase : public MachineFunctionPass {
30 TailDuplicator Duplicator;
31 bool PreRegAlloc;
32 public:
33 TailDuplicateBase(char &PassID, bool PreRegAlloc)
34 : MachineFunctionPass(PassID), PreRegAlloc(PreRegAlloc) {}
36 bool runOnMachineFunction(MachineFunction &MF) override;
38 void getAnalysisUsage(AnalysisUsage &AU) const override {
39 AU.addRequired<MachineBranchProbabilityInfo>();
40 MachineFunctionPass::getAnalysisUsage(AU);
44 class TailDuplicate : public TailDuplicateBase {
45 public:
46 static char ID;
47 TailDuplicate() : TailDuplicateBase(ID, false) {
48 initializeTailDuplicatePass(*PassRegistry::getPassRegistry());
52 class EarlyTailDuplicate : public TailDuplicateBase {
53 public:
54 static char ID;
55 EarlyTailDuplicate() : TailDuplicateBase(ID, true) {
56 initializeEarlyTailDuplicatePass(*PassRegistry::getPassRegistry());
60 } // end anonymous namespace
62 char TailDuplicate::ID;
63 char EarlyTailDuplicate::ID;
65 char &llvm::TailDuplicateID = TailDuplicate::ID;
66 char &llvm::EarlyTailDuplicateID = EarlyTailDuplicate::ID;
68 INITIALIZE_PASS(TailDuplicate, DEBUG_TYPE, "Tail Duplication", false, false)
69 INITIALIZE_PASS(EarlyTailDuplicate, "early-tailduplication",
70 "Early Tail Duplication", false, false)
72 bool TailDuplicateBase::runOnMachineFunction(MachineFunction &MF) {
73 if (skipFunction(MF.getFunction()))
74 return false;
76 auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
77 Duplicator.initMF(MF, PreRegAlloc, MBPI, /*LayoutMode=*/false);
79 bool MadeChange = false;
80 while (Duplicator.tailDuplicateBlocks())
81 MadeChange = true;
83 return MadeChange;