LLVM  14.0.0git
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 
21 #include "llvm/CodeGen/Passes.h"
23 #include "llvm/InitializePasses.h"
24 #include "llvm/Pass.h"
25 
26 using namespace llvm;
27 
28 #define DEBUG_TYPE "tailduplication"
29 
30 namespace {
31 
32 class TailDuplicateBase : public MachineFunctionPass {
33  TailDuplicator Duplicator;
34  std::unique_ptr<MBFIWrapper> MBFIW;
35  bool PreRegAlloc;
36 public:
37  TailDuplicateBase(char &PassID, bool PreRegAlloc)
38  : MachineFunctionPass(PassID), PreRegAlloc(PreRegAlloc) {}
39 
40  bool runOnMachineFunction(MachineFunction &MF) override;
41 
42  void getAnalysisUsage(AnalysisUsage &AU) const override {
47  }
48 };
49 
50 class TailDuplicate : public TailDuplicateBase {
51 public:
52  static char ID;
53  TailDuplicate() : TailDuplicateBase(ID, false) {
55  }
56 };
57 
58 class EarlyTailDuplicate : public TailDuplicateBase {
59 public:
60  static char ID;
61  EarlyTailDuplicate() : TailDuplicateBase(ID, true) {
63  }
64 
65  MachineFunctionProperties getClearedProperties() const override {
68  }
69 };
70 
71 } // end anonymous namespace
72 
75 
78 
79 INITIALIZE_PASS(TailDuplicate, DEBUG_TYPE, "Tail Duplication", false, false)
80 INITIALIZE_PASS(EarlyTailDuplicate, "early-tailduplication",
81  "Early Tail Duplication", false, false)
82 
83 bool TailDuplicateBase::runOnMachineFunction(MachineFunction &MF) {
84  if (skipFunction(MF.getFunction()))
85  return false;
86 
87  auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
88  auto *PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
89  auto *MBFI = (PSI && PSI->hasProfileSummary()) ?
90  &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI() :
91  nullptr;
92  if (MBFI)
93  MBFIW = std::make_unique<MBFIWrapper>(*MBFI);
94  Duplicator.initMF(MF, PreRegAlloc, MBPI, MBFI ? MBFIW.get() : nullptr, PSI,
95  /*LayoutMode=*/false);
96 
97  bool MadeChange = false;
98  while (Duplicator.tailDuplicateBlocks())
99  MadeChange = true;
100 
101  return MadeChange;
102 }
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Pass.h
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::MachineFunctionProperties
Properties which a MachineFunction may have at a given point in time.
Definition: MachineFunction.h:111
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:102
MachineRegisterInfo.h
llvm::CallingConv::Tail
@ Tail
Tail - This calling convention attemps to make calls as fast as possible while guaranteeing that tail...
Definition: CallingConv.h:81
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::MachineBranchProbabilityInfo
Definition: MachineBranchProbabilityInfo.h:24
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
false
Definition: StackSlotColoring.cpp:142
llvm::MachineFunctionProperties::set
MachineFunctionProperties & set(Property P)
Definition: MachineFunction.h:173
Duplication
http eax xorl edx cl sete al setne dl sall eax sall edx But that requires good bit subreg support this might be better It s an extra but it s one instruction and doesn t stress bit subreg eax eax movl edx edx sall eax sall cl edx bit we should expand to a conditional branch like GCC produces Some isel Duplication
Definition: README.txt:51
llvm::EarlyTailDuplicateID
char & EarlyTailDuplicateID
Duplicate blocks with unconditional branches into tails of their predecessors.
Definition: TailDuplication.cpp:77
Passes.h
LazyMachineBlockFrequencyInfo.h
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
ProfileSummaryInfo.h
llvm::ProfileSummaryInfoWrapperPass
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Definition: ProfileSummaryInfo.h:193
MachineFunctionPass.h
MachineBranchProbabilityInfo.h
llvm::LazyMachineBlockFrequencyInfoPass
This is an alternative analysis pass to MachineBlockFrequencyInfo.
Definition: LazyMachineBlockFrequencyInfo.h:37
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::initializeEarlyTailDuplicatePass
void initializeEarlyTailDuplicatePass(PassRegistry &)
llvm::initializeTailDuplicatePass
void initializeTailDuplicatePass(PassRegistry &)
llvm::MachineFunctionProperties::Property::NoPHIs
@ NoPHIs
llvm::TailDuplicateID
char & TailDuplicateID
TailDuplicate - Duplicate blocks with unconditional branches into tails of their predecessors.
Definition: TailDuplication.cpp:76
INITIALIZE_PASS
INITIALIZE_PASS(EarlyTailDuplicate, "early-tailduplication", "Early Tail Duplication", false, false) bool TailDuplicateBase
Definition: TailDuplication.cpp:80
llvm::TailDuplicator
Utility class to perform tail duplication.
Definition: TailDuplicator.h:39
TailDuplicator.h
early
the custom lowered code happens to be but we shouldn t have to custom lower anything This is probably related to< 2 x i64 > ops being so bad LLVM currently generates stack realignment when it is not necessary needed The problem is that we need to know about stack alignment too early
Definition: README-SSE.txt:486
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
MachineFunction.h
InitializePasses.h
DEBUG_TYPE
#define DEBUG_TYPE
Definition: TailDuplication.cpp:28
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
INITIALIZE_PASS
TargetPassConfig.
Definition: TargetPassConfig.cpp:359