mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Remove trailing spaces.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172489 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -27,7 +27,7 @@ namespace llvm {
|
|||||||
class DbgDeclareInst;
|
class DbgDeclareInst;
|
||||||
class MemIntrinsic;
|
class MemIntrinsic;
|
||||||
class MemSetInst;
|
class MemSetInst;
|
||||||
|
|
||||||
/// SelectPatternFlavor - We can match a variety of different patterns for
|
/// SelectPatternFlavor - We can match a variety of different patterns for
|
||||||
/// select operations.
|
/// select operations.
|
||||||
enum SelectPatternFlavor {
|
enum SelectPatternFlavor {
|
||||||
@@ -36,7 +36,7 @@ enum SelectPatternFlavor {
|
|||||||
SPF_SMAX, SPF_UMAX
|
SPF_SMAX, SPF_UMAX
|
||||||
//SPF_ABS - TODO.
|
//SPF_ABS - TODO.
|
||||||
};
|
};
|
||||||
|
|
||||||
/// getComplexity: Assign a complexity or rank value to LLVM Values...
|
/// getComplexity: Assign a complexity or rank value to LLVM Values...
|
||||||
/// 0 -> undef, 1 -> Const, 2 -> Other, 3 -> Arg, 3 -> Unary, 4 -> OtherInst
|
/// 0 -> undef, 1 -> Const, 2 -> Other, 3 -> Arg, 3 -> Unary, 4 -> OtherInst
|
||||||
static inline unsigned getComplexity(Value *V) {
|
static inline unsigned getComplexity(Value *V) {
|
||||||
@@ -51,23 +51,23 @@ static inline unsigned getComplexity(Value *V) {
|
|||||||
return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2;
|
return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// InstCombineIRInserter - This is an IRBuilder insertion helper that works
|
/// InstCombineIRInserter - This is an IRBuilder insertion helper that works
|
||||||
/// just like the normal insertion helper, but also adds any new instructions
|
/// just like the normal insertion helper, but also adds any new instructions
|
||||||
/// to the instcombine worklist.
|
/// to the instcombine worklist.
|
||||||
class LLVM_LIBRARY_VISIBILITY InstCombineIRInserter
|
class LLVM_LIBRARY_VISIBILITY InstCombineIRInserter
|
||||||
: public IRBuilderDefaultInserter<true> {
|
: public IRBuilderDefaultInserter<true> {
|
||||||
InstCombineWorklist &Worklist;
|
InstCombineWorklist &Worklist;
|
||||||
public:
|
public:
|
||||||
InstCombineIRInserter(InstCombineWorklist &WL) : Worklist(WL) {}
|
InstCombineIRInserter(InstCombineWorklist &WL) : Worklist(WL) {}
|
||||||
|
|
||||||
void InsertHelper(Instruction *I, const Twine &Name,
|
void InsertHelper(Instruction *I, const Twine &Name,
|
||||||
BasicBlock *BB, BasicBlock::iterator InsertPt) const {
|
BasicBlock *BB, BasicBlock::iterator InsertPt) const {
|
||||||
IRBuilderDefaultInserter<true>::InsertHelper(I, Name, BB, InsertPt);
|
IRBuilderDefaultInserter<true>::InsertHelper(I, Name, BB, InsertPt);
|
||||||
Worklist.Add(I);
|
Worklist.Add(I);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// InstCombiner - The -instcombine pass.
|
/// InstCombiner - The -instcombine pass.
|
||||||
class LLVM_LIBRARY_VISIBILITY InstCombiner
|
class LLVM_LIBRARY_VISIBILITY InstCombiner
|
||||||
: public FunctionPass,
|
: public FunctionPass,
|
||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
/// instructions into the worklist when they are created.
|
/// instructions into the worklist when they are created.
|
||||||
typedef IRBuilder<true, TargetFolder, InstCombineIRInserter> BuilderTy;
|
typedef IRBuilder<true, TargetFolder, InstCombineIRInserter> BuilderTy;
|
||||||
BuilderTy *Builder;
|
BuilderTy *Builder;
|
||||||
|
|
||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
InstCombiner() : FunctionPass(ID), TD(0), Builder(0) {
|
InstCombiner() : FunctionPass(ID), TD(0), Builder(0) {
|
||||||
MinimizeSize = false;
|
MinimizeSize = false;
|
||||||
@@ -94,7 +94,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool runOnFunction(Function &F);
|
virtual bool runOnFunction(Function &F);
|
||||||
|
|
||||||
bool DoOneIteration(Function &F, unsigned ItNum);
|
bool DoOneIteration(Function &F, unsigned ItNum);
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
||||||
@@ -212,10 +212,10 @@ private:
|
|||||||
bool ShouldChangeType(Type *From, Type *To) const;
|
bool ShouldChangeType(Type *From, Type *To) const;
|
||||||
Value *dyn_castNegVal(Value *V) const;
|
Value *dyn_castNegVal(Value *V) const;
|
||||||
Value *dyn_castFNegVal(Value *V, bool NoSignedZero=false) const;
|
Value *dyn_castFNegVal(Value *V, bool NoSignedZero=false) const;
|
||||||
Type *FindElementAtOffset(Type *Ty, int64_t Offset,
|
Type *FindElementAtOffset(Type *Ty, int64_t Offset,
|
||||||
SmallVectorImpl<Value*> &NewIndices);
|
SmallVectorImpl<Value*> &NewIndices);
|
||||||
Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI);
|
Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI);
|
||||||
|
|
||||||
/// ShouldOptimizeCast - Return true if the cast from "V to Ty" actually
|
/// ShouldOptimizeCast - Return true if the cast from "V to Ty" actually
|
||||||
/// results in any code being generated and is interesting to optimize out. If
|
/// results in any code being generated and is interesting to optimize out. If
|
||||||
/// the cast can be eliminated by some other simple transformation, we prefer
|
/// the cast can be eliminated by some other simple transformation, we prefer
|
||||||
@@ -247,7 +247,7 @@ public:
|
|||||||
return New;
|
return New;
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertNewInstWith - same as InsertNewInstBefore, but also sets the
|
// InsertNewInstWith - same as InsertNewInstBefore, but also sets the
|
||||||
// debug loc.
|
// debug loc.
|
||||||
//
|
//
|
||||||
Instruction *InsertNewInstWith(Instruction *New, Instruction &Old) {
|
Instruction *InsertNewInstWith(Instruction *New, Instruction &Old) {
|
||||||
@@ -263,10 +263,10 @@ public:
|
|||||||
//
|
//
|
||||||
Instruction *ReplaceInstUsesWith(Instruction &I, Value *V) {
|
Instruction *ReplaceInstUsesWith(Instruction &I, Value *V) {
|
||||||
Worklist.AddUsersToWorkList(I); // Add all modified instrs to worklist.
|
Worklist.AddUsersToWorkList(I); // Add all modified instrs to worklist.
|
||||||
|
|
||||||
// If we are replacing the instruction with itself, this must be in a
|
// If we are replacing the instruction with itself, this must be in a
|
||||||
// segment of unreachable code, so just clobber the instruction.
|
// segment of unreachable code, so just clobber the instruction.
|
||||||
if (&I == V)
|
if (&I == V)
|
||||||
V = UndefValue::get(I.getType());
|
V = UndefValue::get(I.getType());
|
||||||
|
|
||||||
DEBUG(errs() << "IC: Replacing " << I << "\n"
|
DEBUG(errs() << "IC: Replacing " << I << "\n"
|
||||||
@@ -296,13 +296,13 @@ public:
|
|||||||
MadeIRChange = true;
|
MadeIRChange = true;
|
||||||
return 0; // Don't do anything with FI
|
return 0; // Don't do anything with FI
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeMaskedBits(Value *V, APInt &KnownZero,
|
void ComputeMaskedBits(Value *V, APInt &KnownZero,
|
||||||
APInt &KnownOne, unsigned Depth = 0) const {
|
APInt &KnownOne, unsigned Depth = 0) const {
|
||||||
return llvm::ComputeMaskedBits(V, KnownZero, KnownOne, TD, Depth);
|
return llvm::ComputeMaskedBits(V, KnownZero, KnownOne, TD, Depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaskedValueIsZero(Value *V, const APInt &Mask,
|
bool MaskedValueIsZero(Value *V, const APInt &Mask,
|
||||||
unsigned Depth = 0) const {
|
unsigned Depth = 0) const {
|
||||||
return llvm::MaskedValueIsZero(V, Mask, TD, Depth);
|
return llvm::MaskedValueIsZero(V, Mask, TD, Depth);
|
||||||
}
|
}
|
||||||
@@ -325,10 +325,10 @@ private:
|
|||||||
|
|
||||||
/// SimplifyDemandedUseBits - Attempts to replace V with a simpler value
|
/// SimplifyDemandedUseBits - Attempts to replace V with a simpler value
|
||||||
/// based on the demanded bits.
|
/// based on the demanded bits.
|
||||||
Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
|
Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
|
||||||
APInt& KnownZero, APInt& KnownOne,
|
APInt& KnownZero, APInt& KnownOne,
|
||||||
unsigned Depth);
|
unsigned Depth);
|
||||||
bool SimplifyDemandedBits(Use &U, APInt DemandedMask,
|
bool SimplifyDemandedBits(Use &U, APInt DemandedMask,
|
||||||
APInt& KnownZero, APInt& KnownOne,
|
APInt& KnownZero, APInt& KnownOne,
|
||||||
unsigned Depth=0);
|
unsigned Depth=0);
|
||||||
/// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded
|
/// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded
|
||||||
@@ -336,15 +336,15 @@ private:
|
|||||||
Value *SimplifyShrShlDemandedBits(Instruction *Lsr, Instruction *Sftl,
|
Value *SimplifyShrShlDemandedBits(Instruction *Lsr, Instruction *Sftl,
|
||||||
APInt DemandedMask, APInt &KnownZero,
|
APInt DemandedMask, APInt &KnownZero,
|
||||||
APInt &KnownOne);
|
APInt &KnownOne);
|
||||||
|
|
||||||
/// SimplifyDemandedInstructionBits - Inst is an integer instruction that
|
/// SimplifyDemandedInstructionBits - Inst is an integer instruction that
|
||||||
/// SimplifyDemandedBits knows about. See if the instruction has any
|
/// SimplifyDemandedBits knows about. See if the instruction has any
|
||||||
/// properties that allow us to simplify its operands.
|
/// properties that allow us to simplify its operands.
|
||||||
bool SimplifyDemandedInstructionBits(Instruction &Inst);
|
bool SimplifyDemandedInstructionBits(Instruction &Inst);
|
||||||
|
|
||||||
Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
|
Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
|
||||||
APInt& UndefElts, unsigned Depth = 0);
|
APInt& UndefElts, unsigned Depth = 0);
|
||||||
|
|
||||||
// FoldOpIntoPhi - Given a binary operator, cast instruction, or select
|
// FoldOpIntoPhi - Given a binary operator, cast instruction, or select
|
||||||
// which has a PHI node as operand #0, see if we can fold the instruction
|
// which has a PHI node as operand #0, see if we can fold the instruction
|
||||||
// into the PHI (which is only possible if all operands to the PHI are
|
// into the PHI (which is only possible if all operands to the PHI are
|
||||||
@@ -360,10 +360,10 @@ private:
|
|||||||
Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN);
|
Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN);
|
||||||
Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN);
|
Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN);
|
||||||
|
|
||||||
|
|
||||||
Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
|
Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
|
||||||
ConstantInt *AndRHS, BinaryOperator &TheAnd);
|
ConstantInt *AndRHS, BinaryOperator &TheAnd);
|
||||||
|
|
||||||
Value *FoldLogicalPlusAnd(Value *LHS, Value *RHS, ConstantInt *Mask,
|
Value *FoldLogicalPlusAnd(Value *LHS, Value *RHS, ConstantInt *Mask,
|
||||||
bool isSub, Instruction &I);
|
bool isSub, Instruction &I);
|
||||||
Value *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
|
Value *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
|
||||||
@@ -382,8 +382,8 @@ private:
|
|||||||
Value *Descale(Value *Val, APInt Scale, bool &NoSignedWrap);
|
Value *Descale(Value *Val, APInt Scale, bool &NoSignedWrap);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // end namespace llvm.
|
} // end namespace llvm.
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -19,20 +19,20 @@
|
|||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
/// InstCombineWorklist - This is the worklist management logic for
|
/// InstCombineWorklist - This is the worklist management logic for
|
||||||
/// InstCombine.
|
/// InstCombine.
|
||||||
class LLVM_LIBRARY_VISIBILITY InstCombineWorklist {
|
class LLVM_LIBRARY_VISIBILITY InstCombineWorklist {
|
||||||
SmallVector<Instruction*, 256> Worklist;
|
SmallVector<Instruction*, 256> Worklist;
|
||||||
DenseMap<Instruction*, unsigned> WorklistMap;
|
DenseMap<Instruction*, unsigned> WorklistMap;
|
||||||
|
|
||||||
void operator=(const InstCombineWorklist&RHS) LLVM_DELETED_FUNCTION;
|
void operator=(const InstCombineWorklist&RHS) LLVM_DELETED_FUNCTION;
|
||||||
InstCombineWorklist(const InstCombineWorklist&) LLVM_DELETED_FUNCTION;
|
InstCombineWorklist(const InstCombineWorklist&) LLVM_DELETED_FUNCTION;
|
||||||
public:
|
public:
|
||||||
InstCombineWorklist() {}
|
InstCombineWorklist() {}
|
||||||
|
|
||||||
bool isEmpty() const { return Worklist.empty(); }
|
bool isEmpty() const { return Worklist.empty(); }
|
||||||
|
|
||||||
/// Add - Add the specified instruction to the worklist if it isn't already
|
/// Add - Add the specified instruction to the worklist if it isn't already
|
||||||
/// in it.
|
/// in it.
|
||||||
void Add(Instruction *I) {
|
void Add(Instruction *I) {
|
||||||
@@ -41,12 +41,12 @@ public:
|
|||||||
Worklist.push_back(I);
|
Worklist.push_back(I);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddValue(Value *V) {
|
void AddValue(Value *V) {
|
||||||
if (Instruction *I = dyn_cast<Instruction>(V))
|
if (Instruction *I = dyn_cast<Instruction>(V))
|
||||||
Add(I);
|
Add(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AddInitialGroup - Add the specified batch of stuff in reverse order.
|
/// AddInitialGroup - Add the specified batch of stuff in reverse order.
|
||||||
/// which should only be done when the worklist is empty and when the group
|
/// which should only be done when the worklist is empty and when the group
|
||||||
/// has no duplicates.
|
/// has no duplicates.
|
||||||
@@ -61,25 +61,25 @@ public:
|
|||||||
Worklist.push_back(I);
|
Worklist.push_back(I);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove - remove I from the worklist if it exists.
|
// Remove - remove I from the worklist if it exists.
|
||||||
void Remove(Instruction *I) {
|
void Remove(Instruction *I) {
|
||||||
DenseMap<Instruction*, unsigned>::iterator It = WorklistMap.find(I);
|
DenseMap<Instruction*, unsigned>::iterator It = WorklistMap.find(I);
|
||||||
if (It == WorklistMap.end()) return; // Not in worklist.
|
if (It == WorklistMap.end()) return; // Not in worklist.
|
||||||
|
|
||||||
// Don't bother moving everything down, just null out the slot.
|
// Don't bother moving everything down, just null out the slot.
|
||||||
Worklist[It->second] = 0;
|
Worklist[It->second] = 0;
|
||||||
|
|
||||||
WorklistMap.erase(It);
|
WorklistMap.erase(It);
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction *RemoveOne() {
|
Instruction *RemoveOne() {
|
||||||
Instruction *I = Worklist.back();
|
Instruction *I = Worklist.back();
|
||||||
Worklist.pop_back();
|
Worklist.pop_back();
|
||||||
WorklistMap.erase(I);
|
WorklistMap.erase(I);
|
||||||
return I;
|
return I;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AddUsersToWorkList - When an instruction is simplified, add all users of
|
/// AddUsersToWorkList - When an instruction is simplified, add all users of
|
||||||
/// the instruction to the work lists because they might get more simplified
|
/// the instruction to the work lists because they might get more simplified
|
||||||
/// now.
|
/// now.
|
||||||
@@ -89,18 +89,18 @@ public:
|
|||||||
UI != UE; ++UI)
|
UI != UE; ++UI)
|
||||||
Add(cast<Instruction>(*UI));
|
Add(cast<Instruction>(*UI));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Zap - check that the worklist is empty and nuke the backing store for
|
/// Zap - check that the worklist is empty and nuke the backing store for
|
||||||
/// the map if it is large.
|
/// the map if it is large.
|
||||||
void Zap() {
|
void Zap() {
|
||||||
assert(WorklistMap.empty() && "Worklist empty, but map not?");
|
assert(WorklistMap.empty() && "Worklist empty, but map not?");
|
||||||
|
|
||||||
// Do an explicit clear, this shrinks the map if needed.
|
// Do an explicit clear, this shrinks the map if needed.
|
||||||
WorklistMap.clear();
|
WorklistMap.clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace llvm.
|
} // end namespace llvm.
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -37,12 +37,12 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
|
|||||||
// Can delete self loop.
|
// Can delete self loop.
|
||||||
BB->getSinglePredecessor() == BB) && "Block is not dead!");
|
BB->getSinglePredecessor() == BB) && "Block is not dead!");
|
||||||
TerminatorInst *BBTerm = BB->getTerminator();
|
TerminatorInst *BBTerm = BB->getTerminator();
|
||||||
|
|
||||||
// Loop through all of our successors and make sure they know that one
|
// Loop through all of our successors and make sure they know that one
|
||||||
// of their predecessors is going away.
|
// of their predecessors is going away.
|
||||||
for (unsigned i = 0, e = BBTerm->getNumSuccessors(); i != e; ++i)
|
for (unsigned i = 0, e = BBTerm->getNumSuccessors(); i != e; ++i)
|
||||||
BBTerm->getSuccessor(i)->removePredecessor(BB);
|
BBTerm->getSuccessor(i)->removePredecessor(BB);
|
||||||
|
|
||||||
// Zap all the instructions in the block.
|
// Zap all the instructions in the block.
|
||||||
while (!BB->empty()) {
|
while (!BB->empty()) {
|
||||||
Instruction &I = BB->back();
|
Instruction &I = BB->back();
|
||||||
@@ -55,7 +55,7 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
|
|||||||
I.replaceAllUsesWith(UndefValue::get(I.getType()));
|
I.replaceAllUsesWith(UndefValue::get(I.getType()));
|
||||||
BB->getInstList().pop_back();
|
BB->getInstList().pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zap the block!
|
// Zap the block!
|
||||||
BB->eraseFromParent();
|
BB->eraseFromParent();
|
||||||
}
|
}
|
||||||
@@ -66,25 +66,25 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
|
|||||||
/// when the block has exactly one predecessor.
|
/// when the block has exactly one predecessor.
|
||||||
void llvm::FoldSingleEntryPHINodes(BasicBlock *BB, Pass *P) {
|
void llvm::FoldSingleEntryPHINodes(BasicBlock *BB, Pass *P) {
|
||||||
if (!isa<PHINode>(BB->begin())) return;
|
if (!isa<PHINode>(BB->begin())) return;
|
||||||
|
|
||||||
AliasAnalysis *AA = 0;
|
AliasAnalysis *AA = 0;
|
||||||
MemoryDependenceAnalysis *MemDep = 0;
|
MemoryDependenceAnalysis *MemDep = 0;
|
||||||
if (P) {
|
if (P) {
|
||||||
AA = P->getAnalysisIfAvailable<AliasAnalysis>();
|
AA = P->getAnalysisIfAvailable<AliasAnalysis>();
|
||||||
MemDep = P->getAnalysisIfAvailable<MemoryDependenceAnalysis>();
|
MemDep = P->getAnalysisIfAvailable<MemoryDependenceAnalysis>();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
|
while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
|
||||||
if (PN->getIncomingValue(0) != PN)
|
if (PN->getIncomingValue(0) != PN)
|
||||||
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
||||||
else
|
else
|
||||||
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
|
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
|
||||||
|
|
||||||
if (MemDep)
|
if (MemDep)
|
||||||
MemDep->removeInstruction(PN); // Memdep updates AA itself.
|
MemDep->removeInstruction(PN); // Memdep updates AA itself.
|
||||||
else if (AA && isa<PointerType>(PN->getType()))
|
else if (AA && isa<PointerType>(PN->getType()))
|
||||||
AA->deleteValue(PN);
|
AA->deleteValue(PN);
|
||||||
|
|
||||||
PN->eraseFromParent();
|
PN->eraseFromParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI) {
|
|||||||
bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
||||||
// Don't merge away blocks who have their address taken.
|
// Don't merge away blocks who have their address taken.
|
||||||
if (BB->hasAddressTaken()) return false;
|
if (BB->hasAddressTaken()) return false;
|
||||||
|
|
||||||
// Can't merge if there are multiple predecessors, or no predecessors.
|
// Can't merge if there are multiple predecessors, or no predecessors.
|
||||||
BasicBlock *PredBB = BB->getUniquePredecessor();
|
BasicBlock *PredBB = BB->getUniquePredecessor();
|
||||||
if (!PredBB) return false;
|
if (!PredBB) return false;
|
||||||
@@ -124,7 +124,7 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
|||||||
if (PredBB == BB) return false;
|
if (PredBB == BB) return false;
|
||||||
// Don't break invokes.
|
// Don't break invokes.
|
||||||
if (isa<InvokeInst>(PredBB->getTerminator())) return false;
|
if (isa<InvokeInst>(PredBB->getTerminator())) return false;
|
||||||
|
|
||||||
succ_iterator SI(succ_begin(PredBB)), SE(succ_end(PredBB));
|
succ_iterator SI(succ_begin(PredBB)), SE(succ_end(PredBB));
|
||||||
BasicBlock *OnlySucc = BB;
|
BasicBlock *OnlySucc = BB;
|
||||||
for (; SI != SE; ++SI)
|
for (; SI != SE; ++SI)
|
||||||
@@ -132,7 +132,7 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
|||||||
OnlySucc = 0; // There are multiple distinct successors!
|
OnlySucc = 0; // There are multiple distinct successors!
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't merge if there are multiple successors.
|
// Can't merge if there are multiple successors.
|
||||||
if (!OnlySucc) return false;
|
if (!OnlySucc) return false;
|
||||||
|
|
||||||
@@ -149,21 +149,21 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
|||||||
// Begin by getting rid of unneeded PHIs.
|
// Begin by getting rid of unneeded PHIs.
|
||||||
if (isa<PHINode>(BB->front()))
|
if (isa<PHINode>(BB->front()))
|
||||||
FoldSingleEntryPHINodes(BB, P);
|
FoldSingleEntryPHINodes(BB, P);
|
||||||
|
|
||||||
// Delete the unconditional branch from the predecessor...
|
// Delete the unconditional branch from the predecessor...
|
||||||
PredBB->getInstList().pop_back();
|
PredBB->getInstList().pop_back();
|
||||||
|
|
||||||
// Make all PHI nodes that referred to BB now refer to Pred as their
|
// Make all PHI nodes that referred to BB now refer to Pred as their
|
||||||
// source...
|
// source...
|
||||||
BB->replaceAllUsesWith(PredBB);
|
BB->replaceAllUsesWith(PredBB);
|
||||||
|
|
||||||
// Move all definitions in the successor to the predecessor...
|
// Move all definitions in the successor to the predecessor...
|
||||||
PredBB->getInstList().splice(PredBB->end(), BB->getInstList());
|
PredBB->getInstList().splice(PredBB->end(), BB->getInstList());
|
||||||
|
|
||||||
// Inherit predecessors name if it exists.
|
// Inherit predecessors name if it exists.
|
||||||
if (!PredBB->hasName())
|
if (!PredBB->hasName())
|
||||||
PredBB->takeName(BB);
|
PredBB->takeName(BB);
|
||||||
|
|
||||||
// Finally, erase the old block and update dominator info.
|
// Finally, erase the old block and update dominator info.
|
||||||
if (P) {
|
if (P) {
|
||||||
if (DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>()) {
|
if (DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>()) {
|
||||||
@@ -176,16 +176,16 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
|||||||
|
|
||||||
DT->eraseNode(BB);
|
DT->eraseNode(BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>())
|
if (LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>())
|
||||||
LI->removeBlock(BB);
|
LI->removeBlock(BB);
|
||||||
|
|
||||||
if (MemoryDependenceAnalysis *MD =
|
if (MemoryDependenceAnalysis *MD =
|
||||||
P->getAnalysisIfAvailable<MemoryDependenceAnalysis>())
|
P->getAnalysisIfAvailable<MemoryDependenceAnalysis>())
|
||||||
MD->invalidateCachedPredecessors();
|
MD->invalidateCachedPredecessors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BB->eraseFromParent();
|
BB->eraseFromParent();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -251,11 +251,11 @@ unsigned llvm::GetSuccessorNumber(BasicBlock *BB, BasicBlock *Succ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SplitEdge - Split the edge connecting specified block. Pass P must
|
/// SplitEdge - Split the edge connecting specified block. Pass P must
|
||||||
/// not be NULL.
|
/// not be NULL.
|
||||||
BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, Pass *P) {
|
BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, Pass *P) {
|
||||||
unsigned SuccNum = GetSuccessorNumber(BB, Succ);
|
unsigned SuccNum = GetSuccessorNumber(BB, Succ);
|
||||||
|
|
||||||
// If this is a critical edge, let SplitCriticalEdge do it.
|
// If this is a critical edge, let SplitCriticalEdge do it.
|
||||||
TerminatorInst *LatchTerm = BB->getTerminator();
|
TerminatorInst *LatchTerm = BB->getTerminator();
|
||||||
if (SplitCriticalEdge(LatchTerm, SuccNum, P))
|
if (SplitCriticalEdge(LatchTerm, SuccNum, P))
|
||||||
@@ -271,11 +271,11 @@ BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, Pass *P) {
|
|||||||
SP = NULL;
|
SP = NULL;
|
||||||
return SplitBlock(Succ, Succ->begin(), P);
|
return SplitBlock(Succ, Succ->begin(), P);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, if BB has a single successor, split it at the bottom of the
|
// Otherwise, if BB has a single successor, split it at the bottom of the
|
||||||
// block.
|
// block.
|
||||||
assert(BB->getTerminator()->getNumSuccessors() == 1 &&
|
assert(BB->getTerminator()->getNumSuccessors() == 1 &&
|
||||||
"Should have a single succ!");
|
"Should have a single succ!");
|
||||||
return SplitBlock(BB, BB->getTerminator(), P);
|
return SplitBlock(BB, BB->getTerminator(), P);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,12 +301,12 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, Instruction *SplitPt, Pass *P) {
|
|||||||
if (DomTreeNode *OldNode = DT->getNode(Old)) {
|
if (DomTreeNode *OldNode = DT->getNode(Old)) {
|
||||||
std::vector<DomTreeNode *> Children;
|
std::vector<DomTreeNode *> Children;
|
||||||
for (DomTreeNode::iterator I = OldNode->begin(), E = OldNode->end();
|
for (DomTreeNode::iterator I = OldNode->begin(), E = OldNode->end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
Children.push_back(*I);
|
Children.push_back(*I);
|
||||||
|
|
||||||
DomTreeNode *NewNode = DT->addNewBlock(New,Old);
|
DomTreeNode *NewNode = DT->addNewBlock(New,Old);
|
||||||
for (std::vector<DomTreeNode *>::iterator I = Children.begin(),
|
for (std::vector<DomTreeNode *>::iterator I = Children.begin(),
|
||||||
E = Children.end(); I != E; ++I)
|
E = Children.end(); I != E; ++I)
|
||||||
DT->changeImmediateDominator(*I, NewNode);
|
DT->changeImmediateDominator(*I, NewNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -424,7 +424,7 @@ static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,
|
|||||||
PHINode *NewPHI =
|
PHINode *NewPHI =
|
||||||
PHINode::Create(PN->getType(), Preds.size(), PN->getName() + ".ph", BI);
|
PHINode::Create(PN->getType(), Preds.size(), PN->getName() + ".ph", BI);
|
||||||
if (AA) AA->copyValue(PN, NewPHI);
|
if (AA) AA->copyValue(PN, NewPHI);
|
||||||
|
|
||||||
// Move all of the PHI values for 'Preds' to the new PHI.
|
// Move all of the PHI values for 'Preds' to the new PHI.
|
||||||
for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
|
||||||
Value *V = PN->removeIncomingValue(Preds[i], false);
|
Value *V = PN->removeIncomingValue(Preds[i], false);
|
||||||
@@ -451,16 +451,16 @@ static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,
|
|||||||
/// preserve LoopSimplify (because it's complicated to handle the case where one
|
/// preserve LoopSimplify (because it's complicated to handle the case where one
|
||||||
/// of the edges being split is an exit of a loop with other exits).
|
/// of the edges being split is an exit of a loop with other exits).
|
||||||
///
|
///
|
||||||
BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
|
BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
|
||||||
ArrayRef<BasicBlock*> Preds,
|
ArrayRef<BasicBlock*> Preds,
|
||||||
const char *Suffix, Pass *P) {
|
const char *Suffix, Pass *P) {
|
||||||
// Create new basic block, insert right before the original block.
|
// Create new basic block, insert right before the original block.
|
||||||
BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), BB->getName()+Suffix,
|
BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), BB->getName()+Suffix,
|
||||||
BB->getParent(), BB);
|
BB->getParent(), BB);
|
||||||
|
|
||||||
// The new block unconditionally branches to the old block.
|
// The new block unconditionally branches to the old block.
|
||||||
BranchInst *BI = BranchInst::Create(BB, NewBB);
|
BranchInst *BI = BranchInst::Create(BB, NewBB);
|
||||||
|
|
||||||
// Move the edges from Preds to point to NewBB instead of BB.
|
// Move the edges from Preds to point to NewBB instead of BB.
|
||||||
for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
|
||||||
// This is slightly more strict than necessary; the minimum requirement
|
// This is slightly more strict than necessary; the minimum requirement
|
||||||
@@ -497,13 +497,13 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
|
|||||||
/// block gets the remaining predecessors of OrigBB. The landingpad instruction
|
/// block gets the remaining predecessors of OrigBB. The landingpad instruction
|
||||||
/// OrigBB is clone into both of the new basic blocks. The new blocks are given
|
/// OrigBB is clone into both of the new basic blocks. The new blocks are given
|
||||||
/// the suffixes 'Suffix1' and 'Suffix2', and are returned in the NewBBs vector.
|
/// the suffixes 'Suffix1' and 'Suffix2', and are returned in the NewBBs vector.
|
||||||
///
|
///
|
||||||
/// This currently updates the LLVM IR, AliasAnalysis, DominatorTree,
|
/// This currently updates the LLVM IR, AliasAnalysis, DominatorTree,
|
||||||
/// DominanceFrontier, LoopInfo, and LCCSA but no other analyses. In particular,
|
/// DominanceFrontier, LoopInfo, and LCCSA but no other analyses. In particular,
|
||||||
/// it does not preserve LoopSimplify (because it's complicated to handle the
|
/// it does not preserve LoopSimplify (because it's complicated to handle the
|
||||||
/// case where one of the edges being split is an exit of a loop with other
|
/// case where one of the edges being split is an exit of a loop with other
|
||||||
/// exits).
|
/// exits).
|
||||||
///
|
///
|
||||||
void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB,
|
void llvm::SplitLandingPadPredecessors(BasicBlock *OrigBB,
|
||||||
ArrayRef<BasicBlock*> Preds,
|
ArrayRef<BasicBlock*> Preds,
|
||||||
const char *Suffix1, const char *Suffix2,
|
const char *Suffix1, const char *Suffix2,
|
||||||
@@ -608,11 +608,11 @@ void llvm::FindFunctionBackedges(const Function &F,
|
|||||||
const BasicBlock *BB = &F.getEntryBlock();
|
const BasicBlock *BB = &F.getEntryBlock();
|
||||||
if (succ_begin(BB) == succ_end(BB))
|
if (succ_begin(BB) == succ_end(BB))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SmallPtrSet<const BasicBlock*, 8> Visited;
|
SmallPtrSet<const BasicBlock*, 8> Visited;
|
||||||
SmallVector<std::pair<const BasicBlock*, succ_const_iterator>, 8> VisitStack;
|
SmallVector<std::pair<const BasicBlock*, succ_const_iterator>, 8> VisitStack;
|
||||||
SmallPtrSet<const BasicBlock*, 8> InStack;
|
SmallPtrSet<const BasicBlock*, 8> InStack;
|
||||||
|
|
||||||
Visited.insert(BB);
|
Visited.insert(BB);
|
||||||
VisitStack.push_back(std::make_pair(BB, succ_begin(BB)));
|
VisitStack.push_back(std::make_pair(BB, succ_begin(BB)));
|
||||||
InStack.insert(BB);
|
InStack.insert(BB);
|
||||||
@@ -620,7 +620,7 @@ void llvm::FindFunctionBackedges(const Function &F,
|
|||||||
std::pair<const BasicBlock*, succ_const_iterator> &Top = VisitStack.back();
|
std::pair<const BasicBlock*, succ_const_iterator> &Top = VisitStack.back();
|
||||||
const BasicBlock *ParentBB = Top.first;
|
const BasicBlock *ParentBB = Top.first;
|
||||||
succ_const_iterator &I = Top.second;
|
succ_const_iterator &I = Top.second;
|
||||||
|
|
||||||
bool FoundNew = false;
|
bool FoundNew = false;
|
||||||
while (I != succ_end(ParentBB)) {
|
while (I != succ_end(ParentBB)) {
|
||||||
BB = *I++;
|
BB = *I++;
|
||||||
@@ -632,7 +632,7 @@ void llvm::FindFunctionBackedges(const Function &F,
|
|||||||
if (InStack.count(BB))
|
if (InStack.count(BB))
|
||||||
Result.push_back(std::make_pair(ParentBB, BB));
|
Result.push_back(std::make_pair(ParentBB, BB));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FoundNew) {
|
if (FoundNew) {
|
||||||
// Go down one level if there is a unvisited successor.
|
// Go down one level if there is a unvisited successor.
|
||||||
InStack.insert(BB);
|
InStack.insert(BB);
|
||||||
@@ -641,7 +641,7 @@ void llvm::FindFunctionBackedges(const Function &F,
|
|||||||
// Go up one level.
|
// Go up one level.
|
||||||
InStack.erase(VisitStack.pop_back_val().first);
|
InStack.erase(VisitStack.pop_back_val().first);
|
||||||
}
|
}
|
||||||
} while (!VisitStack.empty());
|
} while (!VisitStack.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FoldReturnIntoUncondBranch - This method duplicates the specified return
|
/// FoldReturnIntoUncondBranch - This method duplicates the specified return
|
||||||
@@ -655,7 +655,7 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
|
|||||||
// Clone the return and add it to the end of the predecessor.
|
// Clone the return and add it to the end of the predecessor.
|
||||||
Instruction *NewRet = RI->clone();
|
Instruction *NewRet = RI->clone();
|
||||||
Pred->getInstList().push_back(NewRet);
|
Pred->getInstList().push_back(NewRet);
|
||||||
|
|
||||||
// If the return instruction returns a value, and if the value was a
|
// If the return instruction returns a value, and if the value was a
|
||||||
// PHI node in "BB", propagate the right value into the return.
|
// PHI node in "BB", propagate the right value into the return.
|
||||||
for (User::op_iterator i = NewRet->op_begin(), e = NewRet->op_end();
|
for (User::op_iterator i = NewRet->op_begin(), e = NewRet->op_end();
|
||||||
@@ -679,7 +679,7 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update any PHI nodes in the returning block to realize that we no
|
// Update any PHI nodes in the returning block to realize that we no
|
||||||
// longer branch to them.
|
// longer branch to them.
|
||||||
BB->removePredecessor(Pred);
|
BB->removePredecessor(Pred);
|
||||||
|
Reference in New Issue
Block a user