2009-11-26 00:32:21 +00:00
|
|
|
//===-- 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
|
2016-04-08 20:35:01 +00:00
|
|
|
// the tails of their predecessors, using the TailDuplicator utility class.
|
2009-11-26 00:32:21 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2016-04-08 20:35:01 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
|
|
|
#include "llvm/CodeGen/TailDuplicator.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
2009-11-26 00:32:21 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 02:02:50 +00:00
|
|
|
#define DEBUG_TYPE "tailduplication"
|
|
|
|
|
2009-11-26 00:32:21 +00:00
|
|
|
namespace {
|
2016-04-08 20:35:01 +00:00
|
|
|
/// Perform tail duplication. Delegates to TailDuplicator
|
|
|
|
class TailDuplicatePass : public MachineFunctionPass {
|
|
|
|
TailDuplicator Duplicator;
|
2009-11-26 00:32:21 +00:00
|
|
|
|
2016-04-08 20:35:01 +00:00
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
explicit TailDuplicatePass() : MachineFunctionPass(ID) {}
|
2009-11-26 00:32:21 +00:00
|
|
|
|
2016-04-08 20:35:01 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2009-11-26 00:32:21 +00:00
|
|
|
|
2016-04-08 20:35:01 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
|
|
};
|
2014-02-12 18:09:18 +00:00
|
|
|
|
2016-04-08 20:35:01 +00:00
|
|
|
char TailDuplicatePass::ID = 0;
|
2015-06-23 09:49:53 +00:00
|
|
|
}
|
2009-11-26 00:32:21 +00:00
|
|
|
|
2012-02-08 21:23:13 +00:00
|
|
|
char &llvm::TailDuplicateID = TailDuplicatePass::ID;
|
|
|
|
|
2016-04-08 20:35:01 +00:00
|
|
|
INITIALIZE_PASS(TailDuplicatePass, "tailduplication", "Tail Duplication", false,
|
|
|
|
false)
|
2009-11-26 00:32:21 +00:00
|
|
|
|
2009-11-26 21:38:41 +00:00
|
|
|
bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) {
|
2016-04-22 22:06:11 +00:00
|
|
|
if (skipFunction(*MF.getFunction()))
|
2014-03-31 17:43:35 +00:00
|
|
|
return false;
|
|
|
|
|
2016-04-08 20:35:01 +00:00
|
|
|
auto MMI = getAnalysisIfAvailable<MachineModuleInfo>();
|
|
|
|
auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
|
2014-02-12 18:09:18 +00:00
|
|
|
|
2016-04-08 20:35:01 +00:00
|
|
|
Duplicator.initMF(MF, MMI, MBPI);
|
2009-11-26 00:32:21 +00:00
|
|
|
|
|
|
|
bool MadeChange = false;
|
2016-04-08 20:35:01 +00:00
|
|
|
while (Duplicator.tailDuplicateBlocks(MF))
|
2010-01-15 19:59:57 +00:00
|
|
|
MadeChange = true;
|
2009-11-26 00:32:21 +00:00
|
|
|
|
|
|
|
return MadeChange;
|
|
|
|
}
|
|
|
|
|
2014-02-12 18:09:18 +00:00
|
|
|
void TailDuplicatePass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequired<MachineBranchProbabilityInfo>();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|