mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 04:38:24 +00:00
[PM] Split the AssumptionTracker immutable pass into two separate APIs:
a cache of assumptions for a single function, and an immutable pass that manages those caches. The motivation for this change is two fold. Immutable analyses are really hacks around the current pass manager design and don't exist in the new design. This is usually OK, but it requires that the core logic of an immutable pass be reasonably partitioned off from the pass logic. This change does precisely that. As a consequence it also paves the way for the *many* utility functions that deal in the assumptions to live in both pass manager worlds by creating an separate non-pass object with its own independent API that they all rely on. Now, the only bits of the system that deal with the actual pass mechanics are those that actually need to deal with the pass mechanics. Once this separation is made, several simplifications become pretty obvious in the assumption cache itself. Rather than using a set and callback value handles, it can just be a vector of weak value handles. The callers can easily skip the handles that are null, and eventually we can wrap all of this up behind a filter iterator. For now, this adds boiler plate to the various passes, but this kind of boiler plate will end up making it possible to port these passes to the new pass manager, and so it will end up factored away pretty reasonably. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225131 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -108,7 +108,7 @@ class SimplifyCFGOpt {
|
||||
const TargetTransformInfo &TTI;
|
||||
unsigned BonusInstThreshold;
|
||||
const DataLayout *const DL;
|
||||
AssumptionTracker *AT;
|
||||
AssumptionCache *AC;
|
||||
Value *isValueEqualityComparison(TerminatorInst *TI);
|
||||
BasicBlock *GetValueEqualityComparisonCases(TerminatorInst *TI,
|
||||
std::vector<ValueEqualityComparisonCase> &Cases);
|
||||
@ -128,8 +128,8 @@ class SimplifyCFGOpt {
|
||||
|
||||
public:
|
||||
SimplifyCFGOpt(const TargetTransformInfo &TTI, unsigned BonusInstThreshold,
|
||||
const DataLayout *DL, AssumptionTracker *AT)
|
||||
: TTI(TTI), BonusInstThreshold(BonusInstThreshold), DL(DL), AT(AT) {}
|
||||
const DataLayout *DL, AssumptionCache *AC)
|
||||
: TTI(TTI), BonusInstThreshold(BonusInstThreshold), DL(DL), AC(AC) {}
|
||||
bool run(BasicBlock *BB);
|
||||
};
|
||||
}
|
||||
@ -2720,7 +2720,7 @@ static bool SimplifyIndirectBrOnSelect(IndirectBrInst *IBI, SelectInst *SI) {
|
||||
/// the PHI, merging the third icmp into the switch.
|
||||
static bool TryToSimplifyUncondBranchWithICmpInIt(
|
||||
ICmpInst *ICI, IRBuilder<> &Builder, const TargetTransformInfo &TTI,
|
||||
unsigned BonusInstThreshold, const DataLayout *DL, AssumptionTracker *AT) {
|
||||
unsigned BonusInstThreshold, const DataLayout *DL, AssumptionCache *AC) {
|
||||
BasicBlock *BB = ICI->getParent();
|
||||
|
||||
// If the block has any PHIs in it or the icmp has multiple uses, it is too
|
||||
@ -2753,7 +2753,7 @@ static bool TryToSimplifyUncondBranchWithICmpInIt(
|
||||
ICI->eraseFromParent();
|
||||
}
|
||||
// BB is now empty, so it is likely to simplify away.
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
}
|
||||
|
||||
// Ok, the block is reachable from the default dest. If the constant we're
|
||||
@ -2769,7 +2769,7 @@ static bool TryToSimplifyUncondBranchWithICmpInIt(
|
||||
ICI->replaceAllUsesWith(V);
|
||||
ICI->eraseFromParent();
|
||||
// BB is now empty, so it is likely to simplify away.
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
}
|
||||
|
||||
// The use of the icmp has to be in the 'end' block, by the only PHI node in
|
||||
@ -3275,11 +3275,11 @@ static bool TurnSwitchRangeIntoICmp(SwitchInst *SI, IRBuilder<> &Builder) {
|
||||
/// EliminateDeadSwitchCases - Compute masked bits for the condition of a switch
|
||||
/// and use it to remove dead cases.
|
||||
static bool EliminateDeadSwitchCases(SwitchInst *SI, const DataLayout *DL,
|
||||
AssumptionTracker *AT) {
|
||||
AssumptionCache *AC) {
|
||||
Value *Cond = SI->getCondition();
|
||||
unsigned Bits = Cond->getType()->getIntegerBitWidth();
|
||||
APInt KnownZero(Bits, 0), KnownOne(Bits, 0);
|
||||
computeKnownBits(Cond, KnownZero, KnownOne, DL, 0, AT, SI);
|
||||
computeKnownBits(Cond, KnownZero, KnownOne, DL, 0, AC, SI);
|
||||
|
||||
// Gather dead cases.
|
||||
SmallVector<ConstantInt*, 8> DeadCases;
|
||||
@ -3657,7 +3657,7 @@ static void RemoveSwitchAfterSelectConversion(SwitchInst *SI, PHINode *PHI,
|
||||
/// phi nodes in a common successor block with only two different
|
||||
/// constant values, replace the switch with select.
|
||||
static bool SwitchToSelect(SwitchInst *SI, IRBuilder<> &Builder,
|
||||
const DataLayout *DL, AssumptionTracker *AT) {
|
||||
const DataLayout *DL, AssumptionCache *AC) {
|
||||
Value *const Cond = SI->getCondition();
|
||||
PHINode *PHI = nullptr;
|
||||
BasicBlock *CommonDest = nullptr;
|
||||
@ -4308,12 +4308,12 @@ bool SimplifyCFGOpt::SimplifySwitch(SwitchInst *SI, IRBuilder<> &Builder) {
|
||||
// see if that predecessor totally determines the outcome of this switch.
|
||||
if (BasicBlock *OnlyPred = BB->getSinglePredecessor())
|
||||
if (SimplifyEqualityComparisonWithOnlyPredecessor(SI, OnlyPred, Builder))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
Value *Cond = SI->getCondition();
|
||||
if (SelectInst *Select = dyn_cast<SelectInst>(Cond))
|
||||
if (SimplifySwitchOnSelect(SI, Select))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
// If the block only contains the switch, see if we can fold the block
|
||||
// away into any preds.
|
||||
@ -4323,25 +4323,25 @@ bool SimplifyCFGOpt::SimplifySwitch(SwitchInst *SI, IRBuilder<> &Builder) {
|
||||
++BBI;
|
||||
if (SI == &*BBI)
|
||||
if (FoldValueComparisonIntoPredecessors(SI, Builder))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
}
|
||||
|
||||
// Try to transform the switch into an icmp and a branch.
|
||||
if (TurnSwitchRangeIntoICmp(SI, Builder))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
// Remove unreachable cases.
|
||||
if (EliminateDeadSwitchCases(SI, DL, AT))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
if (EliminateDeadSwitchCases(SI, DL, AC))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
if (SwitchToSelect(SI, Builder, DL, AT))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
if (SwitchToSelect(SI, Builder, DL, AC))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
if (ForwardSwitchConditionToPHI(SI))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
if (SwitchToLookupTable(SI, Builder, TTI, DL))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -4378,7 +4378,7 @@ bool SimplifyCFGOpt::SimplifyIndirectBr(IndirectBrInst *IBI) {
|
||||
|
||||
if (SelectInst *SI = dyn_cast<SelectInst>(IBI->getAddress())) {
|
||||
if (SimplifyIndirectBrOnSelect(IBI, SI))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
@ -4403,7 +4403,7 @@ bool SimplifyCFGOpt::SimplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder){
|
||||
;
|
||||
if (I->isTerminator() &&
|
||||
TryToSimplifyUncondBranchWithICmpInIt(ICI, Builder, TTI,
|
||||
BonusInstThreshold, DL, AT))
|
||||
BonusInstThreshold, DL, AC))
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -4412,7 +4412,7 @@ bool SimplifyCFGOpt::SimplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder){
|
||||
// predecessor and use logical operations to update the incoming value
|
||||
// for PHI nodes in common successor.
|
||||
if (FoldBranchToCommonDest(BI, DL, BonusInstThreshold))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -4427,7 +4427,7 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
|
||||
// switch.
|
||||
if (BasicBlock *OnlyPred = BB->getSinglePredecessor())
|
||||
if (SimplifyEqualityComparisonWithOnlyPredecessor(BI, OnlyPred, Builder))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
// This block must be empty, except for the setcond inst, if it exists.
|
||||
// Ignore dbg intrinsics.
|
||||
@ -4437,14 +4437,14 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
|
||||
++I;
|
||||
if (&*I == BI) {
|
||||
if (FoldValueComparisonIntoPredecessors(BI, Builder))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
} else if (&*I == cast<Instruction>(BI->getCondition())){
|
||||
++I;
|
||||
// Ignore dbg intrinsics.
|
||||
while (isa<DbgInfoIntrinsic>(I))
|
||||
++I;
|
||||
if (&*I == BI && FoldValueComparisonIntoPredecessors(BI, Builder))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4456,7 +4456,7 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
|
||||
// branches to us and one of our successors, fold the comparison into the
|
||||
// predecessor and use logical operations to pick the right destination.
|
||||
if (FoldBranchToCommonDest(BI, DL, BonusInstThreshold))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
// We have a conditional branch to two blocks that are only reachable
|
||||
// from BI. We know that the condbr dominates the two blocks, so see if
|
||||
@ -4465,7 +4465,7 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
|
||||
if (BI->getSuccessor(0)->getSinglePredecessor()) {
|
||||
if (BI->getSuccessor(1)->getSinglePredecessor()) {
|
||||
if (HoistThenElseCodeToIf(BI, DL))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
} else {
|
||||
// If Successor #1 has multiple preds, we may be able to conditionally
|
||||
// execute Successor #0 if it branches to Successor #1.
|
||||
@ -4473,7 +4473,7 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
|
||||
if (Succ0TI->getNumSuccessors() == 1 &&
|
||||
Succ0TI->getSuccessor(0) == BI->getSuccessor(1))
|
||||
if (SpeculativelyExecuteBB(BI, BI->getSuccessor(0), DL))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
}
|
||||
} else if (BI->getSuccessor(1)->getSinglePredecessor()) {
|
||||
// If Successor #0 has multiple preds, we may be able to conditionally
|
||||
@ -4482,7 +4482,7 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
|
||||
if (Succ1TI->getNumSuccessors() == 1 &&
|
||||
Succ1TI->getSuccessor(0) == BI->getSuccessor(0))
|
||||
if (SpeculativelyExecuteBB(BI, BI->getSuccessor(1), DL))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
}
|
||||
|
||||
// If this is a branch on a phi node in the current block, thread control
|
||||
@ -4490,14 +4490,14 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
|
||||
if (PHINode *PN = dyn_cast<PHINode>(BI->getCondition()))
|
||||
if (PN->getParent() == BI->getParent())
|
||||
if (FoldCondBranchOnPHI(BI, DL))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
// Scan predecessor blocks for conditional branches.
|
||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
||||
if (BranchInst *PBI = dyn_cast<BranchInst>((*PI)->getTerminator()))
|
||||
if (PBI != BI && PBI->isConditional())
|
||||
if (SimplifyCondBranchToCondBranch(PBI, BI))
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AT) | true;
|
||||
return SimplifyCFG(BB, TTI, BonusInstThreshold, DL, AC) | true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -4641,7 +4641,7 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
|
||||
/// of the CFG. It returns true if a modification was made.
|
||||
///
|
||||
bool llvm::SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
|
||||
unsigned BonusInstThreshold,
|
||||
const DataLayout *DL, AssumptionTracker *AT) {
|
||||
return SimplifyCFGOpt(TTI, BonusInstThreshold, DL, AT).run(BB);
|
||||
unsigned BonusInstThreshold, const DataLayout *DL,
|
||||
AssumptionCache *AC) {
|
||||
return SimplifyCFGOpt(TTI, BonusInstThreshold, DL, AC).run(BB);
|
||||
}
|
||||
|
Reference in New Issue
Block a user