2016-04-08 22:35:01 +02:00
|
|
|
//===-- llvm/CodeGen/TailDuplicator.h ---------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the TailDuplicator class. Used by the
|
|
|
|
// TailDuplication pass, and MachineBlockPlacement.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_TAILDUPLICATOR_H
|
|
|
|
#define LLVM_CODEGEN_TAILDUPLICATOR_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineSSAUpdater.h"
|
|
|
|
#include "llvm/CodeGen/RegisterScavenging.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// Utility class to perform tail duplication.
|
|
|
|
class TailDuplicator {
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
const MachineBranchProbabilityInfo *MBPI;
|
|
|
|
const MachineModuleInfo *MMI;
|
|
|
|
MachineRegisterInfo *MRI;
|
|
|
|
bool PreRegAlloc;
|
2016-08-17 23:07:35 +02:00
|
|
|
unsigned TailDupSize;
|
2016-04-08 22:35:01 +02:00
|
|
|
|
|
|
|
// A list of virtual registers for which to update SSA form.
|
|
|
|
SmallVector<unsigned, 16> SSAUpdateVRs;
|
|
|
|
|
|
|
|
// For each virtual register in SSAUpdateVals keep a list of source virtual
|
|
|
|
// registers.
|
|
|
|
typedef std::vector<std::pair<MachineBasicBlock *, unsigned>> AvailableValsTy;
|
|
|
|
|
|
|
|
DenseMap<unsigned, AvailableValsTy> SSAUpdateVals;
|
|
|
|
|
|
|
|
public:
|
2016-08-17 23:07:35 +02:00
|
|
|
/// Prepare to run on a specific machine function.
|
|
|
|
/// @param TailDupSize - Maxmimum size of blocks to tail-duplicate.
|
2016-04-08 22:35:01 +02:00
|
|
|
void initMF(MachineFunction &MF, const MachineModuleInfo *MMI,
|
2016-08-17 23:07:35 +02:00
|
|
|
const MachineBranchProbabilityInfo *MBPI,
|
|
|
|
unsigned TailDupSize = 0);
|
2016-04-08 22:35:01 +02:00
|
|
|
bool tailDuplicateBlocks(MachineFunction &MF);
|
|
|
|
static bool isSimpleBB(MachineBasicBlock *TailBB);
|
|
|
|
bool shouldTailDuplicate(const MachineFunction &MF, bool IsSimple,
|
|
|
|
MachineBasicBlock &TailBB);
|
2016-07-20 01:54:21 +02:00
|
|
|
/// Returns true if TailBB can successfully be duplicated into PredBB
|
|
|
|
bool canTailDuplicate(MachineBasicBlock *TailBB, MachineBasicBlock *PredBB);
|
2016-04-08 22:35:01 +02:00
|
|
|
bool tailDuplicateAndUpdate(MachineFunction &MF, bool IsSimple,
|
|
|
|
MachineBasicBlock *MBB);
|
|
|
|
|
|
|
|
private:
|
2016-04-26 20:36:34 +02:00
|
|
|
typedef TargetInstrInfo::RegSubRegPair RegSubRegPair;
|
|
|
|
|
2016-04-08 22:35:01 +02:00
|
|
|
void addSSAUpdateEntry(unsigned OrigReg, unsigned NewReg,
|
|
|
|
MachineBasicBlock *BB);
|
|
|
|
void processPHI(MachineInstr *MI, MachineBasicBlock *TailBB,
|
|
|
|
MachineBasicBlock *PredBB,
|
2016-04-26 20:36:34 +02:00
|
|
|
DenseMap<unsigned, RegSubRegPair> &LocalVRMap,
|
|
|
|
SmallVectorImpl<std::pair<unsigned, RegSubRegPair>> &Copies,
|
2016-04-08 22:35:01 +02:00
|
|
|
const DenseSet<unsigned> &UsedByPhi, bool Remove);
|
|
|
|
void duplicateInstruction(MachineInstr *MI, MachineBasicBlock *TailBB,
|
|
|
|
MachineBasicBlock *PredBB, MachineFunction &MF,
|
2016-04-26 20:36:34 +02:00
|
|
|
DenseMap<unsigned, RegSubRegPair> &LocalVRMap,
|
2016-04-08 22:35:01 +02:00
|
|
|
const DenseSet<unsigned> &UsedByPhi);
|
|
|
|
void updateSuccessorsPHIs(MachineBasicBlock *FromBB, bool isDead,
|
|
|
|
SmallVectorImpl<MachineBasicBlock *> &TDBBs,
|
|
|
|
SmallSetVector<MachineBasicBlock *, 8> &Succs);
|
|
|
|
bool canCompletelyDuplicateBB(MachineBasicBlock &BB);
|
|
|
|
bool duplicateSimpleBB(MachineBasicBlock *TailBB,
|
|
|
|
SmallVectorImpl<MachineBasicBlock *> &TDBBs,
|
|
|
|
const DenseSet<unsigned> &RegsUsedByPhi,
|
|
|
|
SmallVectorImpl<MachineInstr *> &Copies);
|
|
|
|
bool tailDuplicate(MachineFunction &MF, bool IsSimple,
|
|
|
|
MachineBasicBlock *TailBB,
|
|
|
|
SmallVectorImpl<MachineBasicBlock *> &TDBBs,
|
|
|
|
SmallVectorImpl<MachineInstr *> &Copies);
|
2016-04-26 20:36:34 +02:00
|
|
|
void appendCopies(MachineBasicBlock *MBB,
|
|
|
|
SmallVectorImpl<std::pair<unsigned,RegSubRegPair>> &CopyInfos,
|
|
|
|
SmallVectorImpl<MachineInstr *> &Copies);
|
2016-04-08 22:35:01 +02:00
|
|
|
|
|
|
|
void removeDeadBlock(MachineBasicBlock *MBB);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|