freebsd-dev/contrib/llvm/lib/CodeGen/TailDuplication.cpp

65 lines
1.9 KiB
C++
Raw Normal View History

2009-12-01 11:07:05 +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
// the tails of their predecessors, using the TailDuplicator utility class.
2009-12-01 11:07:05 +00:00
//
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TailDuplicator.h"
#include "llvm/IR/Function.h"
2009-12-01 11:07:05 +00:00
#include "llvm/Support/Debug.h"
using namespace llvm;
#define DEBUG_TYPE "tailduplication"
2009-12-01 11:07:05 +00:00
namespace {
/// Perform tail duplication. Delegates to TailDuplicator
class TailDuplicatePass : public MachineFunctionPass {
TailDuplicator Duplicator;
2009-12-01 11:07:05 +00:00
public:
static char ID;
explicit TailDuplicatePass() : MachineFunctionPass(ID) {}
2009-12-01 11:07:05 +00:00
bool runOnMachineFunction(MachineFunction &MF) override;
void getAnalysisUsage(AnalysisUsage &AU) const override;
};
2009-12-01 11:07:05 +00:00
char TailDuplicatePass::ID = 0;
}
2009-12-01 11:07:05 +00:00
char &llvm::TailDuplicateID = TailDuplicatePass::ID;
INITIALIZE_PASS(TailDuplicatePass, "tailduplication", "Tail Duplication", false,
false)
2009-12-01 11:07:05 +00:00
bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) {
if (skipFunction(*MF.getFunction()))
return false;
auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
Duplicator.initMF(MF, MBPI, /* LayoutMode */ false);
2009-12-01 11:07:05 +00:00
bool MadeChange = false;
while (Duplicator.tailDuplicateBlocks())
2010-01-23 11:09:33 +00:00
MadeChange = true;
2009-12-01 11:07:05 +00:00
return MadeChange;
}
void TailDuplicatePass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<MachineBranchProbabilityInfo>();
MachineFunctionPass::getAnalysisUsage(AU);
}