LLVM  4.0.0
TailDuplicator.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/TailDuplicator.h ---------------------------*- C++ -*-===//
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 file defines the TailDuplicator class. Used by the
11 // TailDuplication pass, and MachineBlockPlacement.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_TAILDUPLICATOR_H
16 #define LLVM_CODEGEN_TAILDUPLICATOR_H
17 
18 #include "llvm/ADT/STLExtras.h"
27 
28 namespace llvm {
29 
30 extern cl::opt<unsigned> TailDupIndirectBranchSize;
31 
32 /// Utility class to perform tail duplication.
34  const TargetInstrInfo *TII;
35  const TargetRegisterInfo *TRI;
36  const MachineBranchProbabilityInfo *MBPI;
37  const MachineModuleInfo *MMI;
39  MachineFunction *MF;
40  bool PreRegAlloc;
41  bool LayoutMode;
42  unsigned TailDupSize;
43 
44  // A list of virtual registers for which to update SSA form.
45  SmallVector<unsigned, 16> SSAUpdateVRs;
46 
47  // For each virtual register in SSAUpdateVals keep a list of source virtual
48  // registers.
49  typedef std::vector<std::pair<MachineBasicBlock *, unsigned>> AvailableValsTy;
50 
52 
53 public:
54  /// Prepare to run on a specific machine function.
55  /// @param MF - Function that will be processed
56  /// @param MBPI - Branch Probability Info. Used to propagate correct
57  /// probabilities when modifying the CFG.
58  /// @param LayoutMode - When true, don't use the existing layout to make
59  /// decisions.
60  /// @param TailDupSize - Maxmimum size of blocks to tail-duplicate. Zero
61  /// default implies using the command line value TailDupSize.
62  void initMF(MachineFunction &MF,
63  const MachineBranchProbabilityInfo *MBPI,
64  bool LayoutMode, unsigned TailDupSize = 0);
65  bool tailDuplicateBlocks();
66  static bool isSimpleBB(MachineBasicBlock *TailBB);
67  bool shouldTailDuplicate(bool IsSimple, MachineBasicBlock &TailBB);
68  /// Returns true if TailBB can successfully be duplicated into PredBB
70  /// Tail duplicate a single basic block into its predecessors, and then clean
71  /// up.
72  /// If \p DuplicatePreds is not null, it will be updated to contain the list
73  /// of predecessors that received a copy of \p MBB.
74  /// If \p RemovalCallback is non-null. It will be called before MBB is
75  /// deleted.
77  bool IsSimple, MachineBasicBlock *MBB,
78  MachineBasicBlock *ForcedLayoutPred,
79  SmallVectorImpl<MachineBasicBlock*> *DuplicatedPreds = nullptr,
80  llvm::function_ref<void(MachineBasicBlock *)> *RemovalCallback = nullptr);
81 
82 private:
84 
85  void addSSAUpdateEntry(unsigned OrigReg, unsigned NewReg,
86  MachineBasicBlock *BB);
87  void processPHI(MachineInstr *MI, MachineBasicBlock *TailBB,
88  MachineBasicBlock *PredBB,
90  SmallVectorImpl<std::pair<unsigned, RegSubRegPair>> &Copies,
91  const DenseSet<unsigned> &UsedByPhi, bool Remove);
92  void duplicateInstruction(MachineInstr *MI, MachineBasicBlock *TailBB,
93  MachineBasicBlock *PredBB,
95  const DenseSet<unsigned> &UsedByPhi);
96  void updateSuccessorsPHIs(MachineBasicBlock *FromBB, bool isDead,
99  bool canCompletelyDuplicateBB(MachineBasicBlock &BB);
100  bool duplicateSimpleBB(MachineBasicBlock *TailBB,
102  const DenseSet<unsigned> &RegsUsedByPhi,
104  bool tailDuplicate(bool IsSimple,
105  MachineBasicBlock *TailBB,
106  MachineBasicBlock *ForcedLayoutPred,
109  void appendCopies(MachineBasicBlock *MBB,
110  SmallVectorImpl<std::pair<unsigned,RegSubRegPair>> &CopyInfos,
112 
113  void removeDeadBlock(
114  MachineBasicBlock *MBB,
115  llvm::function_ref<void(MachineBasicBlock *)> *RemovalCallback = nullptr);
116 };
117 
118 } // End llvm namespace
119 
120 #endif
Implements a dense probed hash-table based set.
Definition: DenseSet.h:202
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:83
static bool isSimpleBB(MachineBasicBlock *TailBB)
True if this BB has only one unconditional jump.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:32
void initMF(MachineFunction &MF, const MachineBranchProbabilityInfo *MBPI, bool LayoutMode, unsigned TailDupSize=0)
Prepare to run on a specific machine function.
MachineBasicBlock * MBB
TargetInstrInfo - Interface to description of machine instruction set.
This file declares the machine register scavenger class.
bool shouldTailDuplicate(bool IsSimple, MachineBasicBlock &TailBB)
Determine if it is profitable to duplicate this block.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool canTailDuplicate(MachineBasicBlock *TailBB, MachineBasicBlock *PredBB)
Returns true if TailBB can successfully be duplicated into PredBB.
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:292
bool tailDuplicateAndUpdate(bool IsSimple, MachineBasicBlock *MBB, MachineBasicBlock *ForcedLayoutPred, SmallVectorImpl< MachineBasicBlock * > *DuplicatedPreds=nullptr, llvm::function_ref< void(MachineBasicBlock *)> *RemovalCallback=nullptr)
Tail duplicate a single basic block into its predecessors, and then clean up.
A pair composed of a register and a sub-register index.
cl::opt< unsigned > TailDupIndirectBranchSize
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:52
bool tailDuplicateBlocks()
Look for small blocks that are unconditionally branched to and do not fall through.
IRTranslator LLVM IR MI
Utility class to perform tail duplication.
This class contains meta information specific to a module.