mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-25 17:20:48 +00:00
Preserve ProfileInfo during CodeGenPrepare.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82034 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -83,7 +83,7 @@ void RecursivelyDeleteDeadPHINode(PHINode *PN);
|
|||||||
/// between them, moving the instructions in the predecessor into BB. This
|
/// between them, moving the instructions in the predecessor into BB. This
|
||||||
/// deletes the predecessor block.
|
/// deletes the predecessor block.
|
||||||
///
|
///
|
||||||
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB);
|
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, Pass *P = 0);
|
||||||
|
|
||||||
|
|
||||||
/// SimplifyCFG - This function is used to do simplification of a CFG. For
|
/// SimplifyCFG - This function is used to do simplification of a CFG. For
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "llvm/IntrinsicInst.h"
|
#include "llvm/IntrinsicInst.h"
|
||||||
#include "llvm/LLVMContext.h"
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
|
#include "llvm/Analysis/ProfileInfo.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Target/TargetLowering.h"
|
#include "llvm/Target/TargetLowering.h"
|
||||||
#include "llvm/Transforms/Utils/AddrModeMatcher.h"
|
#include "llvm/Transforms/Utils/AddrModeMatcher.h"
|
||||||
@@ -48,6 +49,7 @@ namespace {
|
|||||||
/// TLI - Keep a pointer of a TargetLowering to consult for determining
|
/// TLI - Keep a pointer of a TargetLowering to consult for determining
|
||||||
/// transformation profitability.
|
/// transformation profitability.
|
||||||
const TargetLowering *TLI;
|
const TargetLowering *TLI;
|
||||||
|
ProfileInfo *PI;
|
||||||
|
|
||||||
/// BackEdges - Keep a set of all the loop back edges.
|
/// BackEdges - Keep a set of all the loop back edges.
|
||||||
///
|
///
|
||||||
@@ -58,6 +60,10 @@ namespace {
|
|||||||
: FunctionPass(&ID), TLI(tli) {}
|
: FunctionPass(&ID), TLI(tli) {}
|
||||||
bool runOnFunction(Function &F);
|
bool runOnFunction(Function &F);
|
||||||
|
|
||||||
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
|
AU.addPreserved<ProfileInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool EliminateMostlyEmptyBlocks(Function &F);
|
bool EliminateMostlyEmptyBlocks(Function &F);
|
||||||
bool CanMergeBlocks(const BasicBlock *BB, const BasicBlock *DestBB) const;
|
bool CanMergeBlocks(const BasicBlock *BB, const BasicBlock *DestBB) const;
|
||||||
@@ -93,6 +99,7 @@ void CodeGenPrepare::findLoopBackEdges(const Function &F) {
|
|||||||
bool CodeGenPrepare::runOnFunction(Function &F) {
|
bool CodeGenPrepare::runOnFunction(Function &F) {
|
||||||
bool EverMadeChange = false;
|
bool EverMadeChange = false;
|
||||||
|
|
||||||
|
PI = getAnalysisIfAvailable<ProfileInfo>();
|
||||||
// First pass, eliminate blocks that contain only PHI nodes and an
|
// First pass, eliminate blocks that contain only PHI nodes and an
|
||||||
// unconditional branch.
|
// unconditional branch.
|
||||||
EverMadeChange |= EliminateMostlyEmptyBlocks(F);
|
EverMadeChange |= EliminateMostlyEmptyBlocks(F);
|
||||||
@@ -239,7 +246,7 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) {
|
|||||||
// Remember if SinglePred was the entry block of the function. If so, we
|
// Remember if SinglePred was the entry block of the function. If so, we
|
||||||
// will need to move BB back to the entry position.
|
// will need to move BB back to the entry position.
|
||||||
bool isEntry = SinglePred == &SinglePred->getParent()->getEntryBlock();
|
bool isEntry = SinglePred == &SinglePred->getParent()->getEntryBlock();
|
||||||
MergeBasicBlockIntoOnlyPred(DestBB);
|
MergeBasicBlockIntoOnlyPred(DestBB, this);
|
||||||
|
|
||||||
if (isEntry && BB != &BB->getParent()->getEntryBlock())
|
if (isEntry && BB != &BB->getParent()->getEntryBlock())
|
||||||
BB->moveBefore(&BB->getParent()->getEntryBlock());
|
BB->moveBefore(&BB->getParent()->getEntryBlock());
|
||||||
@@ -281,6 +288,10 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) {
|
|||||||
// The PHIs are now updated, change everything that refers to BB to use
|
// The PHIs are now updated, change everything that refers to BB to use
|
||||||
// DestBB and remove BB.
|
// DestBB and remove BB.
|
||||||
BB->replaceAllUsesWith(DestBB);
|
BB->replaceAllUsesWith(DestBB);
|
||||||
|
if (PI) {
|
||||||
|
PI->replaceAllUses(BB, DestBB);
|
||||||
|
PI->removeEdge(ProfileInfo::getEdge(BB, DestBB));
|
||||||
|
}
|
||||||
BB->eraseFromParent();
|
BB->eraseFromParent();
|
||||||
|
|
||||||
DEBUG(errs() << "AFTER:\n" << *DestBB << "\n\n\n");
|
DEBUG(errs() << "AFTER:\n" << *DestBB << "\n\n\n");
|
||||||
@@ -356,6 +367,9 @@ static void SplitEdgeNicely(TerminatorInst *TI, unsigned SuccNum,
|
|||||||
|
|
||||||
// If we found a workable predecessor, change TI to branch to Succ.
|
// If we found a workable predecessor, change TI to branch to Succ.
|
||||||
if (FoundMatch) {
|
if (FoundMatch) {
|
||||||
|
ProfileInfo *PI = P->getAnalysisIfAvailable<ProfileInfo>();
|
||||||
|
if (PI)
|
||||||
|
PI->splitEdge(TIBB, Dest, Pred);
|
||||||
Dest->removePredecessor(TIBB);
|
Dest->removePredecessor(TIBB);
|
||||||
TI->setSuccessor(SuccNum, Pred);
|
TI->setSuccessor(SuccNum, Pred);
|
||||||
return;
|
return;
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#include "llvm/ADT/SmallPtrSet.h"
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/Analysis/ConstantFolding.h"
|
#include "llvm/Analysis/ConstantFolding.h"
|
||||||
#include "llvm/Analysis/DebugInfo.h"
|
#include "llvm/Analysis/DebugInfo.h"
|
||||||
|
#include "llvm/Analysis/ProfileInfo.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
@@ -294,7 +295,7 @@ llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
|
|||||||
/// between them, moving the instructions in the predecessor into DestBB and
|
/// between them, moving the instructions in the predecessor into DestBB and
|
||||||
/// deleting the predecessor block.
|
/// deleting the predecessor block.
|
||||||
///
|
///
|
||||||
void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB) {
|
void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB, Pass *P) {
|
||||||
// If BB has single-entry PHI nodes, fold them.
|
// If BB has single-entry PHI nodes, fold them.
|
||||||
while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
|
while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
|
||||||
Value *NewVal = PN->getIncomingValue(0);
|
Value *NewVal = PN->getIncomingValue(0);
|
||||||
@@ -314,6 +315,13 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB) {
|
|||||||
// Anything that branched to PredBB now branches to DestBB.
|
// Anything that branched to PredBB now branches to DestBB.
|
||||||
PredBB->replaceAllUsesWith(DestBB);
|
PredBB->replaceAllUsesWith(DestBB);
|
||||||
|
|
||||||
|
if (P) {
|
||||||
|
ProfileInfo *PI = P->getAnalysisIfAvailable<ProfileInfo>();
|
||||||
|
if (PI) {
|
||||||
|
PI->replaceAllUses(PredBB, DestBB);
|
||||||
|
PI->removeEdge(ProfileInfo::getEdge(PredBB, DestBB));
|
||||||
|
}
|
||||||
|
}
|
||||||
// Nuke BB.
|
// Nuke BB.
|
||||||
PredBB->eraseFromParent();
|
PredBB->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user