mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Factor some code into a new FoldSingleEntryPHINodes method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60501 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -30,6 +30,14 @@ class AliasAnalysis;
|
|||||||
/// predecessors.
|
/// predecessors.
|
||||||
void DeleteDeadBlock(BasicBlock *BB);
|
void DeleteDeadBlock(BasicBlock *BB);
|
||||||
|
|
||||||
|
|
||||||
|
/// FoldSingleEntryPHINodes - We know that BB has one predecessor. If there are
|
||||||
|
/// any single-entry PHI nodes in it, fold them away. This handles the case
|
||||||
|
/// when all entries to the PHI nodes in a block are guaranteed equal, such as
|
||||||
|
/// when the block has exactly one predecessor.
|
||||||
|
void FoldSingleEntryPHINodes(BasicBlock *BB);
|
||||||
|
|
||||||
|
|
||||||
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
|
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
|
||||||
/// if possible. The return value indicates success or failure.
|
/// if possible. The return value indicates success or failure.
|
||||||
bool MergeBlockIntoPredecessor(BasicBlock* BB, Pass* P = 0);
|
bool MergeBlockIntoPredecessor(BasicBlock* BB, Pass* P = 0);
|
||||||
|
@@ -56,7 +56,7 @@ void RecursivelyDeleteTriviallyDeadInstructions(Value *V,
|
|||||||
SmallVectorImpl<Instruction*> *DeadInst = 0);
|
SmallVectorImpl<Instruction*> *DeadInst = 0);
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Control Flow Graph Restructuring...
|
// Control Flow Graph Restructuring.
|
||||||
//
|
//
|
||||||
|
|
||||||
/// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
|
/// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
|
||||||
|
@@ -14,12 +14,13 @@
|
|||||||
|
|
||||||
#define DEBUG_TYPE "condprop"
|
#define DEBUG_TYPE "condprop"
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
@@ -95,13 +96,9 @@ void CondProp::SimplifyBlock(BasicBlock *BB) {
|
|||||||
BB != BI->getSuccessor(0)) {
|
BB != BI->getSuccessor(0)) {
|
||||||
BasicBlock *Succ = BI->getSuccessor(0);
|
BasicBlock *Succ = BI->getSuccessor(0);
|
||||||
|
|
||||||
// If Succ has any PHI nodes, they are all single-entry PHI's.
|
// If Succ has any PHI nodes, they are all single-entry PHI's. Eliminate
|
||||||
while (PHINode *PN = dyn_cast<PHINode>(Succ->begin())) {
|
// them.
|
||||||
assert(PN->getNumIncomingValues() == 1 &&
|
FoldSingleEntryPHINodes(Succ);
|
||||||
"PHI doesn't match parent block");
|
|
||||||
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
|
||||||
PN->eraseFromParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove BI.
|
// Remove BI.
|
||||||
BI->eraseFromParent();
|
BI->eraseFromParent();
|
||||||
@@ -205,11 +202,7 @@ void CondProp::RevectorBlockTo(BasicBlock *FromBB, BasicBlock *ToBB) {
|
|||||||
// OldSucc had multiple successors. If ToBB has multiple predecessors, then
|
// OldSucc had multiple successors. If ToBB has multiple predecessors, then
|
||||||
// the edge between them would be critical, which we already took care of.
|
// the edge between them would be critical, which we already took care of.
|
||||||
// If ToBB has single operand PHI node then take care of it here.
|
// If ToBB has single operand PHI node then take care of it here.
|
||||||
while (PHINode *PN = dyn_cast<PHINode>(ToBB->begin())) {
|
FoldSingleEntryPHINodes(ToBB);
|
||||||
assert(PN->getNumIncomingValues() == 1 && "Critical Edge Found!");
|
|
||||||
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
|
||||||
PN->eraseFromParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update PHI nodes in OldSucc to know that FromBB no longer branches to it.
|
// Update PHI nodes in OldSucc to know that FromBB no longer branches to it.
|
||||||
OldSucc->removePredecessor(FromBB);
|
OldSucc->removePredecessor(FromBB);
|
||||||
|
@@ -54,6 +54,24 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
|
|||||||
BB->eraseFromParent();
|
BB->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// FoldSingleEntryPHINodes - We know that BB has one predecessor. If there are
|
||||||
|
/// any single-entry PHI nodes in it, fold them away. This handles the case
|
||||||
|
/// when all entries to the PHI nodes in a block are guaranteed equal, such as
|
||||||
|
/// when the block has exactly one predecessor.
|
||||||
|
void llvm::FoldSingleEntryPHINodes(BasicBlock *BB) {
|
||||||
|
if (!isa<PHINode>(BB->begin()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
|
||||||
|
if (PN->getIncomingValue(0) != PN)
|
||||||
|
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
||||||
|
else
|
||||||
|
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
|
||||||
|
PN->eraseFromParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
|
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
|
||||||
/// if possible. The return value indicates success or failure.
|
/// if possible. The return value indicates success or failure.
|
||||||
bool llvm::MergeBlockIntoPredecessor(BasicBlock* BB, Pass* P) {
|
bool llvm::MergeBlockIntoPredecessor(BasicBlock* BB, Pass* P) {
|
||||||
|
@@ -1101,10 +1101,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
|
|||||||
|
|
||||||
// Degenerate case of a single entry PHI.
|
// Degenerate case of a single entry PHI.
|
||||||
if (PN->getNumIncomingValues() == 1) {
|
if (PN->getNumIncomingValues() == 1) {
|
||||||
if (PN->getIncomingValue(0) != PN)
|
FoldSingleEntryPHINodes(PN->getParent());
|
||||||
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
|
||||||
else
|
|
||||||
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
|
|
||||||
PN->eraseFromParent();
|
PN->eraseFromParent();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -25,13 +25,14 @@
|
|||||||
#include "llvm/Analysis/ConstantFolding.h"
|
#include "llvm/Analysis/ConstantFolding.h"
|
||||||
#include "llvm/Analysis/LoopPass.h"
|
#include "llvm/Analysis/LoopPass.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
#include "llvm/Transforms/Utils/Cloning.h"
|
#include "llvm/Transforms/Utils/Cloning.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
/* TODO: Should these be here or in LoopUnroll? */
|
// TODO: Should these be here or in LoopUnroll?
|
||||||
STATISTIC(NumCompletelyUnrolled, "Number of loops completely unrolled");
|
STATISTIC(NumCompletelyUnrolled, "Number of loops completely unrolled");
|
||||||
STATISTIC(NumUnrolled, "Number of loops unrolled (completely or otherwise)");
|
STATISTIC(NumUnrolled, "Number of loops unrolled (completely or otherwise)");
|
||||||
|
|
||||||
@@ -68,11 +69,7 @@ static BasicBlock *FoldBlockIntoPredecessor(BasicBlock *BB, LoopInfo* LI) {
|
|||||||
// multiple duplicate (but guaranteed to be equal) entries for the
|
// multiple duplicate (but guaranteed to be equal) entries for the
|
||||||
// incoming edges. This occurs when there are multiple edges from
|
// incoming edges. This occurs when there are multiple edges from
|
||||||
// OnlyPred to OnlySucc.
|
// OnlyPred to OnlySucc.
|
||||||
//
|
FoldSingleEntryPHINodes(BB);
|
||||||
while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
|
|
||||||
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
|
||||||
BB->getInstList().pop_front(); // Delete the phi node...
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the unconditional branch from the predecessor...
|
// Delete the unconditional branch from the predecessor...
|
||||||
OnlyPred->getInstList().pop_back();
|
OnlyPred->getInstList().pop_back();
|
||||||
|
Reference in New Issue
Block a user