|
| 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/CodeGen/MachineBranchProbabilityInfo.h" |
| 19 | +#include "llvm/CodeGen/MachineModuleInfo.h" |
| 20 | +#include "llvm/CodeGen/MachineRegisterInfo.h" |
| 21 | +#include "llvm/CodeGen/MachineSSAUpdater.h" |
| 22 | +#include "llvm/CodeGen/RegisterScavenging.h" |
| 23 | +#include "llvm/Target/TargetInstrInfo.h" |
| 24 | +#include "llvm/Target/TargetRegisterInfo.h" |
| 25 | +#include "llvm/Target/TargetSubtargetInfo.h" |
| 26 | + |
| 27 | +namespace llvm { |
| 28 | + |
| 29 | +/// Utility class to perform tail duplication. |
| 30 | +class TailDuplicator { |
| 31 | + const TargetInstrInfo *TII; |
| 32 | + const TargetRegisterInfo *TRI; |
| 33 | + const MachineBranchProbabilityInfo *MBPI; |
| 34 | + const MachineModuleInfo *MMI; |
| 35 | + MachineRegisterInfo *MRI; |
| 36 | + std::unique_ptr<RegScavenger> RS; |
| 37 | + bool PreRegAlloc; |
| 38 | + |
| 39 | + // A list of virtual registers for which to update SSA form. |
| 40 | + SmallVector<unsigned, 16> SSAUpdateVRs; |
| 41 | + |
| 42 | + // For each virtual register in SSAUpdateVals keep a list of source virtual |
| 43 | + // registers. |
| 44 | + typedef std::vector<std::pair<MachineBasicBlock *, unsigned>> AvailableValsTy; |
| 45 | + |
| 46 | + DenseMap<unsigned, AvailableValsTy> SSAUpdateVals; |
| 47 | + |
| 48 | +public: |
| 49 | + void initMF(MachineFunction &MF, const MachineModuleInfo *MMI, |
| 50 | + const MachineBranchProbabilityInfo *MBPI); |
| 51 | + bool tailDuplicateBlocks(MachineFunction &MF); |
| 52 | + static bool isSimpleBB(MachineBasicBlock *TailBB); |
| 53 | + bool shouldTailDuplicate(const MachineFunction &MF, bool IsSimple, |
| 54 | + MachineBasicBlock &TailBB); |
| 55 | + bool tailDuplicateAndUpdate(MachineFunction &MF, bool IsSimple, |
| 56 | + MachineBasicBlock *MBB); |
| 57 | + |
| 58 | +private: |
| 59 | + void addSSAUpdateEntry(unsigned OrigReg, unsigned NewReg, |
| 60 | + MachineBasicBlock *BB); |
| 61 | + void processPHI(MachineInstr *MI, MachineBasicBlock *TailBB, |
| 62 | + MachineBasicBlock *PredBB, |
| 63 | + DenseMap<unsigned, unsigned> &LocalVRMap, |
| 64 | + SmallVectorImpl<std::pair<unsigned, unsigned>> &Copies, |
| 65 | + const DenseSet<unsigned> &UsedByPhi, bool Remove); |
| 66 | + void duplicateInstruction(MachineInstr *MI, MachineBasicBlock *TailBB, |
| 67 | + MachineBasicBlock *PredBB, MachineFunction &MF, |
| 68 | + DenseMap<unsigned, unsigned> &LocalVRMap, |
| 69 | + const DenseSet<unsigned> &UsedByPhi); |
| 70 | + void updateSuccessorsPHIs(MachineBasicBlock *FromBB, bool isDead, |
| 71 | + SmallVectorImpl<MachineBasicBlock *> &TDBBs, |
| 72 | + SmallSetVector<MachineBasicBlock *, 8> &Succs); |
| 73 | + bool canCompletelyDuplicateBB(MachineBasicBlock &BB); |
| 74 | + bool duplicateSimpleBB(MachineBasicBlock *TailBB, |
| 75 | + SmallVectorImpl<MachineBasicBlock *> &TDBBs, |
| 76 | + const DenseSet<unsigned> &RegsUsedByPhi, |
| 77 | + SmallVectorImpl<MachineInstr *> &Copies); |
| 78 | + bool tailDuplicate(MachineFunction &MF, bool IsSimple, |
| 79 | + MachineBasicBlock *TailBB, |
| 80 | + SmallVectorImpl<MachineBasicBlock *> &TDBBs, |
| 81 | + SmallVectorImpl<MachineInstr *> &Copies); |
| 82 | + |
| 83 | + void removeDeadBlock(MachineBasicBlock *MBB); |
| 84 | +}; |
| 85 | + |
| 86 | +} // End llvm namespace |
| 87 | + |
| 88 | +#endif |
0 commit comments