mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
abb4b9d9ee
The tail duplication pass uses an assumed layout when making duplication decisions. This is fine, but passes up duplication opportunities that may arise when blocks are outlined. Because we want the updated CFG to affect subsequent placement decisions, this change must occur during placement. In order to achieve this goal, TailDuplicationPass is split into a utility class, TailDuplicator, and the pass itself. The pass delegates nearly everything to the TailDuplicator object, except for looping over the blocks in a function. This allows the same code to be used for tail duplication in both places. This change, in concert with outlining optional branches, allows triangle shaped code to perform much better, esepecially when the taken/untaken branches are correlated, as it creates a second spine when the tests are small enough. Issue from previous rollback fixed, and a new test was added for that case as well. Issue was worklist/scheduling/taildup issue in layout. Issue from 2nd rollback fixed, with 2 additional tests. Issue was tail merging/loop info/tail-duplication causing issue with loops that share a header block. Issue with early tail-duplication of blocks that branch to a fallthrough predecessor fixed with test case: tail-dup-branch-to-fallthrough.ll Differential revision: https://reviews.llvm.org/D18226 llvm-svn: 283934
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
//===-- TailDuplication.cpp - Duplicate blocks into predecessors' tails ---===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This pass duplicates basic blocks ending in unconditional branches into
|
|
// the tails of their predecessors, using the TailDuplicator utility class.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
#include "llvm/CodeGen/Passes.h"
|
|
#include "llvm/CodeGen/TailDuplicator.h"
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/Support/Debug.h"
|
|
using namespace llvm;
|
|
|
|
#define DEBUG_TYPE "tailduplication"
|
|
|
|
namespace {
|
|
/// Perform tail duplication. Delegates to TailDuplicator
|
|
class TailDuplicatePass : public MachineFunctionPass {
|
|
TailDuplicator Duplicator;
|
|
|
|
public:
|
|
static char ID;
|
|
explicit TailDuplicatePass() : MachineFunctionPass(ID) {}
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
};
|
|
|
|
char TailDuplicatePass::ID = 0;
|
|
}
|
|
|
|
char &llvm::TailDuplicateID = TailDuplicatePass::ID;
|
|
|
|
INITIALIZE_PASS(TailDuplicatePass, "tailduplication", "Tail Duplication", false,
|
|
false)
|
|
|
|
bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) {
|
|
if (skipFunction(*MF.getFunction()))
|
|
return false;
|
|
|
|
auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
|
|
|
|
Duplicator.initMF(MF, MBPI, /* LayoutMode */ false);
|
|
|
|
bool MadeChange = false;
|
|
while (Duplicator.tailDuplicateBlocks())
|
|
MadeChange = true;
|
|
|
|
return MadeChange;
|
|
}
|
|
|
|
void TailDuplicatePass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
AU.addRequired<MachineBranchProbabilityInfo>();
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
}
|