mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-06 05:33:28 +00:00
don't repeat function names in comments; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240591 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
45dc32257e
commit
473e5d658e
@ -48,8 +48,8 @@ UserBonusInstThreshold("bonus-inst-threshold", cl::Hidden, cl::init(1),
|
|||||||
|
|
||||||
STATISTIC(NumSimpl, "Number of blocks simplified");
|
STATISTIC(NumSimpl, "Number of blocks simplified");
|
||||||
|
|
||||||
/// mergeEmptyReturnBlocks - If we have more than one empty (other than phi
|
/// If we have more than one empty (other than phi node) return blocks,
|
||||||
/// node) return blocks, merge them together to promote recursive block merging.
|
/// merge them together to promote recursive block merging.
|
||||||
static bool mergeEmptyReturnBlocks(Function &F) {
|
static bool mergeEmptyReturnBlocks(Function &F) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ static bool mergeEmptyReturnBlocks(Function &F) {
|
|||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// iterativelySimplifyCFG - Call SimplifyCFG on all the blocks in the function,
|
/// Call SimplifyCFG on all the blocks in the function,
|
||||||
/// iterating until no more changes are made.
|
/// iterating until no more changes are made.
|
||||||
static bool iterativelySimplifyCFG(Function &F, const TargetTransformInfo &TTI,
|
static bool iterativelySimplifyCFG(Function &F, const TargetTransformInfo &TTI,
|
||||||
AssumptionCache *AC,
|
AssumptionCache *AC,
|
||||||
|
@ -138,9 +138,8 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SafeToMergeTerminators - Return true if it is safe to merge these two
|
/// Return true if it is safe to merge these two
|
||||||
/// terminator instructions together.
|
/// terminator instructions together.
|
||||||
///
|
|
||||||
static bool SafeToMergeTerminators(TerminatorInst *SI1, TerminatorInst *SI2) {
|
static bool SafeToMergeTerminators(TerminatorInst *SI1, TerminatorInst *SI2) {
|
||||||
if (SI1 == SI2) return false; // Can't merge with self!
|
if (SI1 == SI2) return false; // Can't merge with self!
|
||||||
|
|
||||||
@ -164,11 +163,9 @@ static bool SafeToMergeTerminators(TerminatorInst *SI1, TerminatorInst *SI2) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isProfitableToFoldUnconditional - Return true if it is safe and profitable
|
/// Return true if it is safe and profitable to merge these two terminator
|
||||||
/// to merge these two terminator instructions together, where SI1 is an
|
/// instructions together, where SI1 is an unconditional branch. PhiNodes will
|
||||||
/// unconditional branch. PhiNodes will store all PHI nodes in common
|
/// store all PHI nodes in common successors.
|
||||||
/// successors.
|
|
||||||
///
|
|
||||||
static bool isProfitableToFoldUnconditional(BranchInst *SI1,
|
static bool isProfitableToFoldUnconditional(BranchInst *SI1,
|
||||||
BranchInst *SI2,
|
BranchInst *SI2,
|
||||||
Instruction *Cond,
|
Instruction *Cond,
|
||||||
@ -205,10 +202,10 @@ static bool isProfitableToFoldUnconditional(BranchInst *SI1,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AddPredecessorToBlock - Update PHI nodes in Succ to indicate that there will
|
/// Update PHI nodes in Succ to indicate that there will now be entries in it
|
||||||
/// now be entries in it from the 'NewPred' block. The values that will be
|
/// from the 'NewPred' block. The values that will be flowing into the PHI nodes
|
||||||
/// flowing into the PHI nodes will be the same as those coming in from
|
/// will be the same as those coming in from ExistPred, an existing predecessor
|
||||||
/// ExistPred, an existing predecessor of Succ.
|
/// of Succ.
|
||||||
static void AddPredecessorToBlock(BasicBlock *Succ, BasicBlock *NewPred,
|
static void AddPredecessorToBlock(BasicBlock *Succ, BasicBlock *NewPred,
|
||||||
BasicBlock *ExistPred) {
|
BasicBlock *ExistPred) {
|
||||||
if (!isa<PHINode>(Succ->begin())) return; // Quick exit if nothing to do
|
if (!isa<PHINode>(Succ->begin())) return; // Quick exit if nothing to do
|
||||||
@ -219,9 +216,9 @@ static void AddPredecessorToBlock(BasicBlock *Succ, BasicBlock *NewPred,
|
|||||||
PN->addIncoming(PN->getIncomingValueForBlock(ExistPred), NewPred);
|
PN->addIncoming(PN->getIncomingValueForBlock(ExistPred), NewPred);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ComputeSpeculationCost - Compute an abstract "cost" of speculating the
|
/// Compute an abstract "cost" of speculating the given instruction,
|
||||||
/// given instruction, which is assumed to be safe to speculate. TCC_Free means
|
/// which is assumed to be safe to speculate. TCC_Free means cheap,
|
||||||
/// cheap, TCC_Basic means less cheap, and TCC_Expensive means prohibitively
|
/// TCC_Basic means less cheap, and TCC_Expensive means prohibitively
|
||||||
/// expensive.
|
/// expensive.
|
||||||
static unsigned ComputeSpeculationCost(const User *I,
|
static unsigned ComputeSpeculationCost(const User *I,
|
||||||
const TargetTransformInfo &TTI) {
|
const TargetTransformInfo &TTI) {
|
||||||
@ -229,8 +226,8 @@ static unsigned ComputeSpeculationCost(const User *I,
|
|||||||
"Instruction is not safe to speculatively execute!");
|
"Instruction is not safe to speculatively execute!");
|
||||||
return TTI.getUserCost(I);
|
return TTI.getUserCost(I);
|
||||||
}
|
}
|
||||||
/// DominatesMergePoint - If we have a merge point of an "if condition" as
|
/// If we have a merge point of an "if condition" as accepted above,
|
||||||
/// accepted above, return true if the specified value dominates the block. We
|
/// return true if the specified value dominates the block. We
|
||||||
/// don't handle the true generality of domination here, just a special case
|
/// don't handle the true generality of domination here, just a special case
|
||||||
/// which works well enough for us.
|
/// which works well enough for us.
|
||||||
///
|
///
|
||||||
@ -302,7 +299,7 @@ static bool DominatesMergePoint(Value *V, BasicBlock *BB,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetConstantInt - Extract ConstantInt from value, looking through IntToPtr
|
/// Extract ConstantInt from value, looking through IntToPtr
|
||||||
/// and PointerNullValue. Return NULL if value is not a constant int.
|
/// and PointerNullValue. Return NULL if value is not a constant int.
|
||||||
static ConstantInt *GetConstantInt(Value *V, const DataLayout &DL) {
|
static ConstantInt *GetConstantInt(Value *V, const DataLayout &DL) {
|
||||||
// Normal constant int.
|
// Normal constant int.
|
||||||
@ -456,7 +453,7 @@ private:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// gather - Given a potentially 'or'd or 'and'd together collection of icmp
|
/// Given a potentially 'or'd or 'and'd together collection of icmp
|
||||||
/// eq/ne/lt/gt instructions that compare a value against a constant, extract
|
/// eq/ne/lt/gt instructions that compare a value against a constant, extract
|
||||||
/// the value being compared, and stick the list constants into the Vals
|
/// the value being compared, and stick the list constants into the Vals
|
||||||
/// vector.
|
/// vector.
|
||||||
@ -519,7 +516,7 @@ static void EraseTerminatorInstAndDCECond(TerminatorInst *TI) {
|
|||||||
if (Cond) RecursivelyDeleteTriviallyDeadInstructions(Cond);
|
if (Cond) RecursivelyDeleteTriviallyDeadInstructions(Cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isValueEqualityComparison - Return true if the specified terminator checks
|
/// Return true if the specified terminator checks
|
||||||
/// to see if a value is equal to constant integer value.
|
/// to see if a value is equal to constant integer value.
|
||||||
Value *SimplifyCFGOpt::isValueEqualityComparison(TerminatorInst *TI) {
|
Value *SimplifyCFGOpt::isValueEqualityComparison(TerminatorInst *TI) {
|
||||||
Value *CV = nullptr;
|
Value *CV = nullptr;
|
||||||
@ -547,7 +544,7 @@ Value *SimplifyCFGOpt::isValueEqualityComparison(TerminatorInst *TI) {
|
|||||||
return CV;
|
return CV;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetValueEqualityComparisonCases - Given a value comparison instruction,
|
/// Given a value comparison instruction,
|
||||||
/// decode all of the 'cases' that it represents and return the 'default' block.
|
/// decode all of the 'cases' that it represents and return the 'default' block.
|
||||||
BasicBlock *SimplifyCFGOpt::
|
BasicBlock *SimplifyCFGOpt::
|
||||||
GetValueEqualityComparisonCases(TerminatorInst *TI,
|
GetValueEqualityComparisonCases(TerminatorInst *TI,
|
||||||
@ -571,15 +568,14 @@ GetValueEqualityComparisonCases(TerminatorInst *TI,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// EliminateBlockCases - Given a vector of bb/value pairs, remove any entries
|
/// Given a vector of bb/value pairs, remove any entries
|
||||||
/// in the list that match the specified block.
|
/// in the list that match the specified block.
|
||||||
static void EliminateBlockCases(BasicBlock *BB,
|
static void EliminateBlockCases(BasicBlock *BB,
|
||||||
std::vector<ValueEqualityComparisonCase> &Cases) {
|
std::vector<ValueEqualityComparisonCase> &Cases) {
|
||||||
Cases.erase(std::remove(Cases.begin(), Cases.end(), BB), Cases.end());
|
Cases.erase(std::remove(Cases.begin(), Cases.end(), BB), Cases.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ValuesOverlap - Return true if there are any keys in C1 that exist in C2 as
|
/// Return true if there are any keys in C1 that exist in C2 as well.
|
||||||
/// well.
|
|
||||||
static bool
|
static bool
|
||||||
ValuesOverlap(std::vector<ValueEqualityComparisonCase> &C1,
|
ValuesOverlap(std::vector<ValueEqualityComparisonCase> &C1,
|
||||||
std::vector<ValueEqualityComparisonCase > &C2) {
|
std::vector<ValueEqualityComparisonCase > &C2) {
|
||||||
@ -613,12 +609,11 @@ ValuesOverlap(std::vector<ValueEqualityComparisonCase> &C1,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SimplifyEqualityComparisonWithOnlyPredecessor - If TI is known to be a
|
/// If TI is known to be a terminator instruction and its block is known to
|
||||||
/// terminator instruction and its block is known to only have a single
|
/// only have a single predecessor block, check to see if that predecessor is
|
||||||
/// predecessor block, check to see if that predecessor is also a value
|
/// also a value comparison with the same value, and if that comparison
|
||||||
/// comparison with the same value, and if that comparison determines the
|
/// determines the outcome of this comparison. If so, simplify TI. This does a
|
||||||
/// outcome of this comparison. If so, simplify TI. This does a very limited
|
/// very limited form of jump threading.
|
||||||
/// form of jump threading.
|
|
||||||
bool SimplifyCFGOpt::
|
bool SimplifyCFGOpt::
|
||||||
SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI,
|
SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI,
|
||||||
BasicBlock *Pred,
|
BasicBlock *Pred,
|
||||||
@ -754,7 +749,7 @@ SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI,
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/// ConstantIntOrdering - This class implements a stable ordering of constant
|
/// This class implements a stable ordering of constant
|
||||||
/// integers that does not depend on their address. This is important for
|
/// integers that does not depend on their address. This is important for
|
||||||
/// applications that sort ConstantInt's to ensure uniqueness.
|
/// applications that sort ConstantInt's to ensure uniqueness.
|
||||||
struct ConstantIntOrdering {
|
struct ConstantIntOrdering {
|
||||||
@ -817,8 +812,8 @@ static void FitWeights(MutableArrayRef<uint64_t> Weights) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FoldValueComparisonIntoPredecessors - The specified terminator is a value
|
/// The specified terminator is a value equality comparison instruction
|
||||||
/// equality comparison instruction (either a switch or a branch on "X == c").
|
/// (either a switch or a branch on "X == c").
|
||||||
/// See if any of the predecessors of the terminator block are value comparisons
|
/// See if any of the predecessors of the terminator block are value comparisons
|
||||||
/// on the same value. If so, and if safe to do so, fold them together.
|
/// on the same value. If so, and if safe to do so, fold them together.
|
||||||
bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(TerminatorInst *TI,
|
bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(TerminatorInst *TI,
|
||||||
@ -1027,10 +1022,9 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(TerminatorInst *TI,
|
|||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// isSafeToHoistInvoke - If we would need to insert a select that uses the
|
// If we would need to insert a select that uses the value of this invoke
|
||||||
// value of this invoke (comments in HoistThenElseCodeToIf explain why we
|
// (comments in HoistThenElseCodeToIf explain why we would need to do this), we
|
||||||
// would need to do this), we can't hoist the invoke, as there is nowhere
|
// can't hoist the invoke, as there is nowhere to put the select in this case.
|
||||||
// to put the select in this case.
|
|
||||||
static bool isSafeToHoistInvoke(BasicBlock *BB1, BasicBlock *BB2,
|
static bool isSafeToHoistInvoke(BasicBlock *BB1, BasicBlock *BB2,
|
||||||
Instruction *I1, Instruction *I2) {
|
Instruction *I1, Instruction *I2) {
|
||||||
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
|
for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
|
||||||
@ -1049,9 +1043,9 @@ static bool isSafeToHoistInvoke(BasicBlock *BB1, BasicBlock *BB2,
|
|||||||
|
|
||||||
static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I);
|
static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I);
|
||||||
|
|
||||||
/// HoistThenElseCodeToIf - Given a conditional branch that goes to BB1 and
|
/// Given a conditional branch that goes to BB1 and BB2, hoist any common code
|
||||||
/// BB2, hoist any common code in the two blocks up into the branch block. The
|
/// in the two blocks up into the branch block. The caller of this function
|
||||||
/// caller of this function guarantees that BI's block dominates BB1 and BB2.
|
/// guarantees that BI's block dominates BB1 and BB2.
|
||||||
static bool HoistThenElseCodeToIf(BranchInst *BI,
|
static bool HoistThenElseCodeToIf(BranchInst *BI,
|
||||||
const TargetTransformInfo &TTI) {
|
const TargetTransformInfo &TTI) {
|
||||||
// This does very trivial matching, with limited scanning, to find identical
|
// This does very trivial matching, with limited scanning, to find identical
|
||||||
@ -1197,7 +1191,7 @@ HoistTerminator:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SinkThenElseCodeToEnd - Given an unconditional branch that goes to BBEnd,
|
/// Given an unconditional branch that goes to BBEnd,
|
||||||
/// check whether BBEnd has only two predecessors and the other predecessor
|
/// check whether BBEnd has only two predecessors and the other predecessor
|
||||||
/// ends with an unconditional branch. If it is true, sink any common code
|
/// ends with an unconditional branch. If it is true, sink any common code
|
||||||
/// in the two predecessors to BBEnd.
|
/// in the two predecessors to BBEnd.
|
||||||
@ -1656,8 +1650,7 @@ static bool HasNoDuplicateCall(const BasicBlock *BB) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// BlockIsSimpleEnoughToThreadThrough - Return true if we can thread a branch
|
/// Return true if we can thread a branch across this block.
|
||||||
/// across this block.
|
|
||||||
static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
|
static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
|
||||||
BranchInst *BI = cast<BranchInst>(BB->getTerminator());
|
BranchInst *BI = cast<BranchInst>(BB->getTerminator());
|
||||||
unsigned Size = 0;
|
unsigned Size = 0;
|
||||||
@ -1681,10 +1674,9 @@ static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FoldCondBranchOnPHI - If we have a conditional branch on a PHI node value
|
/// If we have a conditional branch on a PHI node value that is defined in the
|
||||||
/// that is defined in the same block as the branch and if any PHI entries are
|
/// same block as the branch and if any PHI entries are constants, thread edges
|
||||||
/// constants, thread edges corresponding to that entry to be branches to their
|
/// corresponding to that entry to be branches to their ultimate destination.
|
||||||
/// ultimate destination.
|
|
||||||
static bool FoldCondBranchOnPHI(BranchInst *BI, const DataLayout &DL) {
|
static bool FoldCondBranchOnPHI(BranchInst *BI, const DataLayout &DL) {
|
||||||
BasicBlock *BB = BI->getParent();
|
BasicBlock *BB = BI->getParent();
|
||||||
PHINode *PN = dyn_cast<PHINode>(BI->getCondition());
|
PHINode *PN = dyn_cast<PHINode>(BI->getCondition());
|
||||||
@ -1781,8 +1773,8 @@ static bool FoldCondBranchOnPHI(BranchInst *BI, const DataLayout &DL) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FoldTwoEntryPHINode - Given a BB that starts with the specified two-entry
|
/// Given a BB that starts with the specified two-entry PHI node,
|
||||||
/// PHI node, see if we can eliminate it.
|
/// see if we can eliminate it.
|
||||||
static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
|
static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
|
||||||
const DataLayout &DL) {
|
const DataLayout &DL) {
|
||||||
// Ok, this is a two entry PHI node. Check to see if this is a simple "if
|
// Ok, this is a two entry PHI node. Check to see if this is a simple "if
|
||||||
@ -1920,8 +1912,8 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SimplifyCondBranchToTwoReturns - If we found a conditional branch that goes
|
/// If we found a conditional branch that goes to two returning blocks,
|
||||||
/// to two returning blocks, try to merge them together into one return,
|
/// try to merge them together into one return,
|
||||||
/// introducing a select if the return values disagree.
|
/// introducing a select if the return values disagree.
|
||||||
static bool SimplifyCondBranchToTwoReturns(BranchInst *BI,
|
static bool SimplifyCondBranchToTwoReturns(BranchInst *BI,
|
||||||
IRBuilder<> &Builder) {
|
IRBuilder<> &Builder) {
|
||||||
@ -2008,10 +2000,9 @@ static bool SimplifyCondBranchToTwoReturns(BranchInst *BI,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ExtractBranchMetadata - Given a conditional BranchInstruction, retrieve the
|
/// Given a conditional BranchInstruction, retrieve the probabilities of the
|
||||||
/// probabilities of the branch taking each edge. Fills in the two APInt
|
/// branch taking each edge. Fills in the two APInt parameters and returns true,
|
||||||
/// parameters and return true, or returns false if no or invalid metadata was
|
/// or returns false if no or invalid metadata was found.
|
||||||
/// found.
|
|
||||||
static bool ExtractBranchMetadata(BranchInst *BI,
|
static bool ExtractBranchMetadata(BranchInst *BI,
|
||||||
uint64_t &ProbTrue, uint64_t &ProbFalse) {
|
uint64_t &ProbTrue, uint64_t &ProbFalse) {
|
||||||
assert(BI->isConditional() &&
|
assert(BI->isConditional() &&
|
||||||
@ -2028,9 +2019,8 @@ static bool ExtractBranchMetadata(BranchInst *BI,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// checkCSEInPredecessor - Return true if the given instruction is available
|
/// Return true if the given instruction is available
|
||||||
/// in its predecessor block. If yes, the instruction will be removed.
|
/// in its predecessor block. If yes, the instruction will be removed.
|
||||||
///
|
|
||||||
static bool checkCSEInPredecessor(Instruction *Inst, BasicBlock *PB) {
|
static bool checkCSEInPredecessor(Instruction *Inst, BasicBlock *PB) {
|
||||||
if (!isa<BinaryOperator>(Inst) && !isa<CmpInst>(Inst))
|
if (!isa<BinaryOperator>(Inst) && !isa<CmpInst>(Inst))
|
||||||
return false;
|
return false;
|
||||||
@ -2046,9 +2036,9 @@ static bool checkCSEInPredecessor(Instruction *Inst, BasicBlock *PB) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FoldBranchToCommonDest - If this basic block is simple enough, and if a
|
/// If this basic block is simple enough, and if a predecessor branches to us
|
||||||
/// predecessor branches to us and one of our successors, fold the block into
|
/// and one of our successors, fold the block into the predecessor and use
|
||||||
/// the predecessor and use logical operations to pick the right destination.
|
/// logical operations to pick the right destination.
|
||||||
bool llvm::FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold) {
|
bool llvm::FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold) {
|
||||||
BasicBlock *BB = BI->getParent();
|
BasicBlock *BB = BI->getParent();
|
||||||
|
|
||||||
@ -2342,8 +2332,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SimplifyCondBranchToCondBranch - If we have a conditional branch as a
|
/// If we have a conditional branch as a predecessor of another block,
|
||||||
/// predecessor of another block, this function tries to simplify it. We know
|
/// this function tries to simplify it. We know
|
||||||
/// that PBI and BI are both conditional branches, and BI is in one of the
|
/// that PBI and BI are both conditional branches, and BI is in one of the
|
||||||
/// successor blocks of PBI - PBI branches to BI.
|
/// successor blocks of PBI - PBI branches to BI.
|
||||||
static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
||||||
@ -2558,8 +2548,8 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimplifyTerminatorOnSelect - Simplifies a terminator by replacing it with a
|
// Simplifies a terminator by replacing it with a branch to TrueBB if Cond is
|
||||||
// branch to TrueBB if Cond is true or to FalseBB if Cond is false.
|
// true or to FalseBB if Cond is false.
|
||||||
// Takes care of updating the successors and removing the old terminator.
|
// Takes care of updating the successors and removing the old terminator.
|
||||||
// Also makes sure not to introduce new successors by assuming that edges to
|
// Also makes sure not to introduce new successors by assuming that edges to
|
||||||
// non-successor TrueBBs and FalseBBs aren't reachable.
|
// non-successor TrueBBs and FalseBBs aren't reachable.
|
||||||
@ -2624,7 +2614,7 @@ static bool SimplifyTerminatorOnSelect(TerminatorInst *OldTerm, Value *Cond,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimplifySwitchOnSelect - Replaces
|
// Replaces
|
||||||
// (switch (select cond, X, Y)) on constant X, Y
|
// (switch (select cond, X, Y)) on constant X, Y
|
||||||
// with a branch - conditional if X and Y lead to distinct BBs,
|
// with a branch - conditional if X and Y lead to distinct BBs,
|
||||||
// unconditional otherwise.
|
// unconditional otherwise.
|
||||||
@ -2659,7 +2649,7 @@ static bool SimplifySwitchOnSelect(SwitchInst *SI, SelectInst *Select) {
|
|||||||
TrueWeight, FalseWeight);
|
TrueWeight, FalseWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimplifyIndirectBrOnSelect - Replaces
|
// Replaces
|
||||||
// (indirectbr (select cond, blockaddress(@fn, BlockA),
|
// (indirectbr (select cond, blockaddress(@fn, BlockA),
|
||||||
// blockaddress(@fn, BlockB)))
|
// blockaddress(@fn, BlockB)))
|
||||||
// with
|
// with
|
||||||
@ -2680,8 +2670,8 @@ static bool SimplifyIndirectBrOnSelect(IndirectBrInst *IBI, SelectInst *SI) {
|
|||||||
0, 0);
|
0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TryToSimplifyUncondBranchWithICmpInIt - This is called when we find an icmp
|
/// This is called when we find an icmp instruction
|
||||||
/// instruction (a seteq/setne with a constant) as the only instruction in a
|
/// (a seteq/setne with a constant) as the only instruction in a
|
||||||
/// block that ends with an uncond branch. We are looking for a very specific
|
/// block that ends with an uncond branch. We are looking for a very specific
|
||||||
/// pattern that occurs when "A == 1 || A == 2 || A == 3" gets simplified. In
|
/// pattern that occurs when "A == 1 || A == 2 || A == 3" gets simplified. In
|
||||||
/// this case, we merge the first two "or's of icmp" into a switch, but then the
|
/// this case, we merge the first two "or's of icmp" into a switch, but then the
|
||||||
@ -2802,7 +2792,7 @@ static bool TryToSimplifyUncondBranchWithICmpInIt(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SimplifyBranchOnICmpChain - The specified branch is a conditional branch.
|
/// The specified branch is a conditional branch.
|
||||||
/// Check to see if it is branching on an or/and chain of icmp instructions, and
|
/// Check to see if it is branching on an or/and chain of icmp instructions, and
|
||||||
/// fold it into a switch instruction if so.
|
/// fold it into a switch instruction if so.
|
||||||
static bool SimplifyBranchOnICmpChain(BranchInst *BI, IRBuilder<> &Builder,
|
static bool SimplifyBranchOnICmpChain(BranchInst *BI, IRBuilder<> &Builder,
|
||||||
@ -3239,7 +3229,7 @@ static bool TurnSwitchRangeIntoICmp(SwitchInst *SI, IRBuilder<> &Builder) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EliminateDeadSwitchCases - Compute masked bits for the condition of a switch
|
/// Compute masked bits for the condition of a switch
|
||||||
/// and use it to remove dead cases.
|
/// and use it to remove dead cases.
|
||||||
static bool EliminateDeadSwitchCases(SwitchInst *SI, AssumptionCache *AC,
|
static bool EliminateDeadSwitchCases(SwitchInst *SI, AssumptionCache *AC,
|
||||||
const DataLayout &DL) {
|
const DataLayout &DL) {
|
||||||
@ -3290,8 +3280,8 @@ static bool EliminateDeadSwitchCases(SwitchInst *SI, AssumptionCache *AC,
|
|||||||
return !DeadCases.empty();
|
return !DeadCases.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FindPHIForConditionForwarding - If BB would be eligible for simplification
|
/// If BB would be eligible for simplification by
|
||||||
/// by TryToSimplifyUncondBranchFromEmptyBlock (i.e. it is empty and terminated
|
/// TryToSimplifyUncondBranchFromEmptyBlock (i.e. it is empty and terminated
|
||||||
/// by an unconditional branch), look at the phi node for BB in the successor
|
/// by an unconditional branch), look at the phi node for BB in the successor
|
||||||
/// block and see if the incoming value is equal to CaseValue. If so, return
|
/// block and see if the incoming value is equal to CaseValue. If so, return
|
||||||
/// the phi node, and set PhiIndex to BB's index in the phi node.
|
/// the phi node, and set PhiIndex to BB's index in the phi node.
|
||||||
@ -3324,9 +3314,9 @@ static PHINode *FindPHIForConditionForwarding(ConstantInt *CaseValue,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ForwardSwitchConditionToPHI - Try to forward the condition of a switch
|
/// Try to forward the condition of a switch instruction to a phi node
|
||||||
/// instruction to a phi node dominated by the switch, if that would mean that
|
/// dominated by the switch, if that would mean that some of the destination
|
||||||
/// some of the destination blocks of the switch can be folded away.
|
/// blocks of the switch can be folded away.
|
||||||
/// Returns true if a change is made.
|
/// Returns true if a change is made.
|
||||||
static bool ForwardSwitchConditionToPHI(SwitchInst *SI) {
|
static bool ForwardSwitchConditionToPHI(SwitchInst *SI) {
|
||||||
typedef DenseMap<PHINode*, SmallVector<int,4> > ForwardingNodesMap;
|
typedef DenseMap<PHINode*, SmallVector<int,4> > ForwardingNodesMap;
|
||||||
@ -3361,7 +3351,7 @@ static bool ForwardSwitchConditionToPHI(SwitchInst *SI) {
|
|||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ValidLookupTableConstant - Return true if the backend will be able to handle
|
/// Return true if the backend will be able to handle
|
||||||
/// initializing an array of constants like C.
|
/// initializing an array of constants like C.
|
||||||
static bool ValidLookupTableConstant(Constant *C) {
|
static bool ValidLookupTableConstant(Constant *C) {
|
||||||
if (C->isThreadDependent())
|
if (C->isThreadDependent())
|
||||||
@ -3379,7 +3369,7 @@ static bool ValidLookupTableConstant(Constant *C) {
|
|||||||
isa<UndefValue>(C);
|
isa<UndefValue>(C);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// LookupConstant - If V is a Constant, return it. Otherwise, try to look up
|
/// If V is a Constant, return it. Otherwise, try to look up
|
||||||
/// its constant value in ConstantPool, returning 0 if it's not there.
|
/// its constant value in ConstantPool, returning 0 if it's not there.
|
||||||
static Constant *LookupConstant(Value *V,
|
static Constant *LookupConstant(Value *V,
|
||||||
const SmallDenseMap<Value*, Constant*>& ConstantPool) {
|
const SmallDenseMap<Value*, Constant*>& ConstantPool) {
|
||||||
@ -3388,7 +3378,7 @@ static Constant *LookupConstant(Value *V,
|
|||||||
return ConstantPool.lookup(V);
|
return ConstantPool.lookup(V);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ConstantFold - Try to fold instruction I into a constant. This works for
|
/// Try to fold instruction I into a constant. This works for
|
||||||
/// simple instructions such as binary operations where both operands are
|
/// simple instructions such as binary operations where both operands are
|
||||||
/// constant or can be replaced by constants from the ConstantPool. Returns the
|
/// constant or can be replaced by constants from the ConstantPool. Returns the
|
||||||
/// resulting constant on success, 0 otherwise.
|
/// resulting constant on success, 0 otherwise.
|
||||||
@ -3422,7 +3412,7 @@ ConstantFold(Instruction *I, const DataLayout &DL,
|
|||||||
return ConstantFoldInstOperands(I->getOpcode(), I->getType(), COps, DL);
|
return ConstantFoldInstOperands(I->getOpcode(), I->getType(), COps, DL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetCaseResults - Try to determine the resulting constant values in phi nodes
|
/// Try to determine the resulting constant values in phi nodes
|
||||||
/// at the common destination basic block, *CommonDest, for one of the case
|
/// at the common destination basic block, *CommonDest, for one of the case
|
||||||
/// destionations CaseDest corresponding to value CaseVal (0 for the default
|
/// destionations CaseDest corresponding to value CaseVal (0 for the default
|
||||||
/// case), of a switch instruction SI.
|
/// case), of a switch instruction SI.
|
||||||
@ -3501,8 +3491,8 @@ GetCaseResults(SwitchInst *SI, ConstantInt *CaseVal, BasicBlock *CaseDest,
|
|||||||
return Res.size() > 0;
|
return Res.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MapCaseToResult - Helper function used to
|
// Helper function used to add CaseVal to the list of cases that generate
|
||||||
// add CaseVal to the list of cases that generate Result.
|
// Result.
|
||||||
static void MapCaseToResult(ConstantInt *CaseVal,
|
static void MapCaseToResult(ConstantInt *CaseVal,
|
||||||
SwitchCaseResultVectorTy &UniqueResults,
|
SwitchCaseResultVectorTy &UniqueResults,
|
||||||
Constant *Result) {
|
Constant *Result) {
|
||||||
@ -3516,7 +3506,7 @@ static void MapCaseToResult(ConstantInt *CaseVal,
|
|||||||
SmallVector<ConstantInt*, 4>(1, CaseVal)));
|
SmallVector<ConstantInt*, 4>(1, CaseVal)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializeUniqueCases - Helper function that initializes a map containing
|
// Helper function that initializes a map containing
|
||||||
// results for the PHI node of the common destination block for a switch
|
// results for the PHI node of the common destination block for a switch
|
||||||
// instruction. Returns false if multiple PHI nodes have been found or if
|
// instruction. Returns false if multiple PHI nodes have been found or if
|
||||||
// there is not a common destination block for the switch.
|
// there is not a common destination block for the switch.
|
||||||
@ -3561,9 +3551,8 @@ static bool InitializeUniqueCases(SwitchInst *SI, PHINode *&PHI,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvertTwoCaseSwitch - Helper function that checks if it is possible to
|
// Helper function that checks if it is possible to transform a switch with only
|
||||||
// transform a switch with only two cases (or two cases + default)
|
// two cases (or two cases + default) that produces a result into a select.
|
||||||
// that produces a result into a value select.
|
|
||||||
// Example:
|
// Example:
|
||||||
// switch (a) {
|
// switch (a) {
|
||||||
// case 10: %0 = icmp eq i32 %a, 10
|
// case 10: %0 = icmp eq i32 %a, 10
|
||||||
@ -3603,9 +3592,8 @@ ConvertTwoCaseSwitch(const SwitchCaseResultVectorTy &ResultVector,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveSwitchAfterSelectConversion - Helper function to cleanup a switch
|
// Helper function to cleanup a switch instruction that has been converted into
|
||||||
// instruction that has been converted into a select, fixing up PHI nodes and
|
// a select, fixing up PHI nodes and basic blocks.
|
||||||
// basic blocks.
|
|
||||||
static void RemoveSwitchAfterSelectConversion(SwitchInst *SI, PHINode *PHI,
|
static void RemoveSwitchAfterSelectConversion(SwitchInst *SI, PHINode *PHI,
|
||||||
Value *SelectValue,
|
Value *SelectValue,
|
||||||
IRBuilder<> &Builder) {
|
IRBuilder<> &Builder) {
|
||||||
@ -3627,7 +3615,7 @@ static void RemoveSwitchAfterSelectConversion(SwitchInst *SI, PHINode *PHI,
|
|||||||
SI->eraseFromParent();
|
SI->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SwitchToSelect - If the switch is only used to initialize one or more
|
/// If the switch is only used to initialize one or more
|
||||||
/// phi nodes in a common successor block with only two different
|
/// phi nodes in a common successor block with only two different
|
||||||
/// constant values, replace the switch with select.
|
/// constant values, replace the switch with select.
|
||||||
static bool SwitchToSelect(SwitchInst *SI, IRBuilder<> &Builder,
|
static bool SwitchToSelect(SwitchInst *SI, IRBuilder<> &Builder,
|
||||||
@ -3659,23 +3647,21 @@ static bool SwitchToSelect(SwitchInst *SI, IRBuilder<> &Builder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/// SwitchLookupTable - This class represents a lookup table that can be used
|
/// This class represents a lookup table that can be used to replace a switch.
|
||||||
/// to replace a switch.
|
|
||||||
class SwitchLookupTable {
|
class SwitchLookupTable {
|
||||||
public:
|
public:
|
||||||
/// SwitchLookupTable - Create a lookup table to use as a switch replacement
|
/// Create a lookup table to use as a switch replacement with the contents
|
||||||
/// with the contents of Values, using DefaultValue to fill any holes in the
|
/// of Values, using DefaultValue to fill any holes in the table.
|
||||||
/// table.
|
|
||||||
SwitchLookupTable(
|
SwitchLookupTable(
|
||||||
Module &M, uint64_t TableSize, ConstantInt *Offset,
|
Module &M, uint64_t TableSize, ConstantInt *Offset,
|
||||||
const SmallVectorImpl<std::pair<ConstantInt *, Constant *>> &Values,
|
const SmallVectorImpl<std::pair<ConstantInt *, Constant *>> &Values,
|
||||||
Constant *DefaultValue, const DataLayout &DL);
|
Constant *DefaultValue, const DataLayout &DL);
|
||||||
|
|
||||||
/// BuildLookup - Build instructions with Builder to retrieve the value at
|
/// Build instructions with Builder to retrieve the value at
|
||||||
/// the position given by Index in the lookup table.
|
/// the position given by Index in the lookup table.
|
||||||
Value *BuildLookup(Value *Index, IRBuilder<> &Builder);
|
Value *BuildLookup(Value *Index, IRBuilder<> &Builder);
|
||||||
|
|
||||||
/// WouldFitInRegister - Return true if a table with TableSize elements of
|
/// Return true if a table with TableSize elements of
|
||||||
/// type ElementType would fit in a target-legal register.
|
/// type ElementType would fit in a target-legal register.
|
||||||
static bool WouldFitInRegister(const DataLayout &DL, uint64_t TableSize,
|
static bool WouldFitInRegister(const DataLayout &DL, uint64_t TableSize,
|
||||||
const Type *ElementType);
|
const Type *ElementType);
|
||||||
@ -3907,9 +3893,8 @@ bool SwitchLookupTable::WouldFitInRegister(const DataLayout &DL,
|
|||||||
return DL.fitsInLegalInteger(TableSize * IT->getBitWidth());
|
return DL.fitsInLegalInteger(TableSize * IT->getBitWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ShouldBuildLookupTable - Determine whether a lookup table should be built
|
/// Determine whether a lookup table should be built for this switch, based on
|
||||||
/// for this switch, based on the number of cases, size of the table and the
|
/// the number of cases, size of the table, and the types of the results.
|
||||||
/// types of the results.
|
|
||||||
static bool
|
static bool
|
||||||
ShouldBuildLookupTable(SwitchInst *SI, uint64_t TableSize,
|
ShouldBuildLookupTable(SwitchInst *SI, uint64_t TableSize,
|
||||||
const TargetTransformInfo &TTI, const DataLayout &DL,
|
const TargetTransformInfo &TTI, const DataLayout &DL,
|
||||||
@ -4033,9 +4018,9 @@ static void reuseTableCompare(User *PhiUser, BasicBlock *PhiBlock,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SwitchToLookupTable - If the switch is only used to initialize one or more
|
/// If the switch is only used to initialize one or more phi nodes in a common
|
||||||
/// phi nodes in a common successor block with different constant values,
|
/// successor block with different constant values, replace the switch with
|
||||||
/// replace the switch with lookup tables.
|
/// lookup tables.
|
||||||
static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
|
static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
|
||||||
const DataLayout &DL,
|
const DataLayout &DL,
|
||||||
const TargetTransformInfo &TTI) {
|
const TargetTransformInfo &TTI) {
|
||||||
@ -4691,8 +4676,8 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
|
|||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SimplifyCFG - This function is used to do simplification of a CFG. For
|
/// This function is used to do simplification of a CFG.
|
||||||
/// example, it adjusts branches to branches to eliminate the extra hop, it
|
/// For example, it adjusts branches to branches to eliminate the extra hop,
|
||||||
/// eliminates unreachable basic blocks, and does other "peephole" optimization
|
/// eliminates unreachable basic blocks, and does other "peephole" optimization
|
||||||
/// of the CFG. It returns true if a modification was made.
|
/// of the CFG. It returns true if a modification was made.
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user