Skip to content

Commit

Permalink
Tail Duplication: Accept explicit threshold for duplicating.
Browse files Browse the repository at this point in the history
This will allow tail duplication and tail merging during layout to have a
shared threshold to make sure that they don't overlap. No observable change
intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278981 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Kyle Butt committed Aug 17, 2016
1 parent af9bcca commit 0a6e4fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion include/llvm/CodeGen/TailDuplicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TailDuplicator {
const MachineModuleInfo *MMI;
MachineRegisterInfo *MRI;
bool PreRegAlloc;
unsigned TailDupSize;

// A list of virtual registers for which to update SSA form.
SmallVector<unsigned, 16> SSAUpdateVRs;
Expand All @@ -45,8 +46,11 @@ class TailDuplicator {
DenseMap<unsigned, AvailableValsTy> SSAUpdateVals;

public:
/// Prepare to run on a specific machine function.
/// @param TailDupSize - Maxmimum size of blocks to tail-duplicate.
void initMF(MachineFunction &MF, const MachineModuleInfo *MMI,
const MachineBranchProbabilityInfo *MBPI);
const MachineBranchProbabilityInfo *MBPI,
unsigned TailDupSize = 0);
bool tailDuplicateBlocks(MachineFunction &MF);
static bool isSimpleBB(MachineBasicBlock *TailBB);
bool shouldTailDuplicate(const MachineFunction &MF, bool IsSimple,
Expand Down
12 changes: 8 additions & 4 deletions lib/CodeGen/TailDuplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ static cl::opt<unsigned> TailDupLimit("tail-dup-limit", cl::init(~0U),
namespace llvm {

void TailDuplicator::initMF(MachineFunction &MF, const MachineModuleInfo *MMIin,
const MachineBranchProbabilityInfo *MBPIin) {
const MachineBranchProbabilityInfo *MBPIin,
unsigned TailDupSizeIn) {
TII = MF.getSubtarget().getInstrInfo();
TRI = MF.getSubtarget().getRegisterInfo();
MRI = &MF.getRegInfo();
MMI = MMIin;
MBPI = MBPIin;
TailDupSize = TailDupSizeIn;

assert(MBPI != nullptr && "Machine Branch Probability Info required");

Expand Down Expand Up @@ -511,12 +513,14 @@ bool TailDuplicator::shouldTailDuplicate(const MachineFunction &MF,
// duplicate only one, because one branch instruction can be eliminated to
// compensate for the duplication.
unsigned MaxDuplicateCount;
if (TailDuplicateSize.getNumOccurrences() == 0 &&
// FIXME: Use Function::optForSize().
if (TailDupSize == 0 &&
TailDuplicateSize.getNumOccurrences() == 0 &&
MF.getFunction()->optForSize())
MaxDuplicateCount = 1;
else
else if (TailDupSize == 0)
MaxDuplicateCount = TailDuplicateSize;
else
MaxDuplicateCount = TailDupSize;

// If the block to be duplicated ends in an unanalyzable fallthrough, don't
// duplicate it.
Expand Down

0 comments on commit 0a6e4fd

Please sign in to comment.