[Polly][NFC] Drop uses of BranchInst (#187301)
This commit is contained in:
parent
dd9dd1d2f3
commit
bfedc2aa76
@ -62,7 +62,7 @@ public:
|
||||
/// Last argument is optional, if no value is passed, we don't annotate
|
||||
/// any vectorize metadata.
|
||||
void annotateLoopLatch(
|
||||
llvm::BranchInst *B, bool IsParallel,
|
||||
llvm::CondBrInst *B, bool IsParallel,
|
||||
std::optional<bool> EnableVectorizeMetadata = std::nullopt) const;
|
||||
|
||||
/// Add alternative alias based pointers
|
||||
|
||||
@ -21,7 +21,7 @@ class BasicBlock;
|
||||
class DominatorTree;
|
||||
class RegionInfo;
|
||||
class LoopInfo;
|
||||
class BranchInst;
|
||||
class CondBrInst;
|
||||
} // namespace llvm
|
||||
|
||||
namespace polly {
|
||||
@ -62,10 +62,10 @@ using BBPair = std::pair<llvm::BasicBlock *, llvm::BasicBlock *>;
|
||||
///
|
||||
/// @return An std::pair:
|
||||
/// - The first element is a BBPair of (StartBlock, EndBlock).
|
||||
/// - The second element is the BranchInst which conditionally
|
||||
/// - The second element is the CondBrInst which conditionally
|
||||
/// branches to the SCoP based on the RTC.
|
||||
///
|
||||
std::pair<BBPair, llvm::BranchInst *>
|
||||
std::pair<BBPair, llvm::CondBrInst *>
|
||||
executeScopConditionally(Scop &S, llvm::Value *RTC, llvm::DominatorTree &DT,
|
||||
llvm::RegionInfo &RI, llvm::LoopInfo &LI);
|
||||
} // namespace polly
|
||||
|
||||
@ -61,8 +61,8 @@ using llvm::AnalysisInfoMixin;
|
||||
using llvm::AnalysisKey;
|
||||
using llvm::AnalysisUsage;
|
||||
using llvm::BatchAAResults;
|
||||
using llvm::BranchInst;
|
||||
using llvm::CallInst;
|
||||
using llvm::CondBrInst;
|
||||
using llvm::DenseMap;
|
||||
using llvm::DominatorTree;
|
||||
using llvm::Function;
|
||||
@ -428,7 +428,7 @@ private:
|
||||
/// @param Condition The branch condition.
|
||||
/// @param IsLoopBranch Flag to indicate the branch is a loop exit/latch.
|
||||
/// @param Context The context of scop detection.
|
||||
bool isValidBranch(BasicBlock &BB, BranchInst *BI, Value *Condition,
|
||||
bool isValidBranch(BasicBlock &BB, CondBrInst *BI, Value *Condition,
|
||||
bool IsLoopBranch, DetectionContext &Context);
|
||||
|
||||
/// Check if the SCEV @p S is affine in the current @p Context.
|
||||
|
||||
@ -398,15 +398,6 @@ llvm::Value *expandCodeFor(Scop &S, llvm::ScalarEvolution &SE,
|
||||
llvm::BasicBlock::iterator IP, ValueMapT *VMap,
|
||||
LoopToScevMapT *LoopMap, llvm::BasicBlock *RTCBB);
|
||||
|
||||
/// Return the condition for the terminator @p TI.
|
||||
///
|
||||
/// For unconditional branches the "i1 true" condition will be returned.
|
||||
///
|
||||
/// @param TI The terminator to get the condition from.
|
||||
///
|
||||
/// @return The condition of @p TI and nullptr if none could be extracted.
|
||||
llvm::Value *getConditionFromTerminator(llvm::Instruction *TI);
|
||||
|
||||
/// Get the smallest loop that contains @p S but is not in @p S.
|
||||
llvm::Loop *getLoopSurroundingScop(Scop &S, llvm::LoopInfo &LI);
|
||||
|
||||
|
||||
@ -394,8 +394,7 @@ bool ScopBuilder::buildConditionSets(
|
||||
BasicBlock *BB, SwitchInst *SI, Loop *L, __isl_keep isl_set *Domain,
|
||||
DenseMap<BasicBlock *, isl::set> &InvalidDomainMap,
|
||||
SmallVectorImpl<__isl_give isl_set *> &ConditionSets) {
|
||||
Value *Condition = getConditionFromTerminator(SI);
|
||||
assert(Condition && "No condition for switch");
|
||||
Value *Condition = SI->getCondition();
|
||||
|
||||
isl_pw_aff *LHS, *RHS;
|
||||
LHS = getPwAff(BB, InvalidDomainMap, SE.getSCEVAtScope(Condition, L));
|
||||
@ -572,16 +571,12 @@ bool ScopBuilder::buildConditionSets(
|
||||
return buildConditionSets(BB, SI, L, Domain, InvalidDomainMap,
|
||||
ConditionSets);
|
||||
|
||||
assert(isa<BranchInst>(TI) && "Terminator was neither branch nor switch.");
|
||||
|
||||
if (TI->getNumSuccessors() == 1) {
|
||||
if (isa<UncondBrInst>(TI)) {
|
||||
ConditionSets.push_back(isl_set_copy(Domain));
|
||||
return true;
|
||||
}
|
||||
|
||||
Value *Condition = getConditionFromTerminator(TI);
|
||||
assert(Condition && "No condition for Terminator");
|
||||
|
||||
Value *Condition = cast<CondBrInst>(TI)->getCondition();
|
||||
return buildConditionSets(BB, Condition, TI, L, Domain, InvalidDomainMap,
|
||||
ConditionSets);
|
||||
}
|
||||
@ -755,12 +750,9 @@ bool ScopBuilder::addLoopBoundsToHeaderDomain(
|
||||
isl::set BackedgeCondition;
|
||||
|
||||
Instruction *TI = LatchBB->getTerminator();
|
||||
BranchInst *BI = dyn_cast<BranchInst>(TI);
|
||||
assert(BI && "Only branch instructions allowed in loop latches");
|
||||
|
||||
if (BI->isUnconditional())
|
||||
if (isa<UncondBrInst>(TI))
|
||||
BackedgeCondition = LatchBBDom;
|
||||
else {
|
||||
else if (auto *BI = dyn_cast<CondBrInst>(TI)) {
|
||||
SmallVector<isl_set *, 8> ConditionSets;
|
||||
int idx = BI->getSuccessor(0) != HeaderBB;
|
||||
if (!buildConditionSets(LatchBB, TI, L, LatchBBDom.get(),
|
||||
@ -771,7 +763,8 @@ bool ScopBuilder::addLoopBoundsToHeaderDomain(
|
||||
isl_set_free(ConditionSets[1 - idx]);
|
||||
|
||||
BackedgeCondition = isl::manage(ConditionSets[idx]);
|
||||
}
|
||||
} else
|
||||
llvm_unreachable("Only branch instructions allowed in loop latches");
|
||||
|
||||
int LatchLoopDepth = scop->getRelativeLoopDepth(LI.getLoopFor(LatchBB));
|
||||
assert(LatchLoopDepth >= LoopDepth);
|
||||
|
||||
@ -571,7 +571,7 @@ bool ScopDetection::isValidSwitch(BasicBlock &BB, SwitchInst *SI,
|
||||
ConditionSCEV, ConditionSCEV, SI);
|
||||
}
|
||||
|
||||
bool ScopDetection::isValidBranch(BasicBlock &BB, BranchInst *BI,
|
||||
bool ScopDetection::isValidBranch(BasicBlock &BB, CondBrInst *BI,
|
||||
Value *Condition, bool IsLoopBranch,
|
||||
DetectionContext &Context) {
|
||||
// Constant integer conditions are always affine.
|
||||
@ -665,22 +665,24 @@ bool ScopDetection::isValidCFG(BasicBlock &BB, bool IsLoopBranch,
|
||||
if (isa<ReturnInst>(TI) && CurRegion.isTopLevelRegion())
|
||||
return true;
|
||||
|
||||
Value *Condition = getConditionFromTerminator(TI);
|
||||
if (isa<UncondBrInst>(TI))
|
||||
return true;
|
||||
|
||||
if (!Condition)
|
||||
return invalid<ReportInvalidTerminator>(Context, /*Assert=*/true, &BB);
|
||||
|
||||
// UndefValue is not allowed as condition.
|
||||
if (isa<UndefValue>(Condition))
|
||||
return invalid<ReportUndefCond>(Context, /*Assert=*/true, TI, &BB);
|
||||
|
||||
if (BranchInst *BI = dyn_cast<BranchInst>(TI))
|
||||
if (auto *BI = dyn_cast<CondBrInst>(TI)) {
|
||||
Value *Condition = BI->getCondition();
|
||||
if (isa<UndefValue>(Condition))
|
||||
return invalid<ReportUndefCond>(Context, /*Assert=*/true, TI, &BB);
|
||||
return isValidBranch(BB, BI, Condition, IsLoopBranch, Context);
|
||||
}
|
||||
|
||||
SwitchInst *SI = dyn_cast<SwitchInst>(TI);
|
||||
assert(SI && "Terminator was neither branch nor switch");
|
||||
if (auto *SI = dyn_cast<SwitchInst>(TI)) {
|
||||
Value *Condition = SI->getCondition();
|
||||
if (isa<UndefValue>(Condition))
|
||||
return invalid<ReportUndefCond>(Context, /*Assert=*/true, TI, &BB);
|
||||
return isValidSwitch(BB, SI, Condition, IsLoopBranch, Context);
|
||||
}
|
||||
|
||||
return isValidSwitch(BB, SI, Condition, IsLoopBranch, Context);
|
||||
return invalid<ReportInvalidTerminator>(Context, /*Assert=*/true, &BB);
|
||||
}
|
||||
|
||||
bool ScopDetection::isValidCallInst(CallInst &CI,
|
||||
|
||||
@ -624,7 +624,7 @@ void BlockGenerator::generateConditionalExecution(
|
||||
DomTreeUpdater DTU(GenDT, DomTreeUpdater::UpdateStrategy::Eager);
|
||||
SplitBlockAndInsertIfThen(Cond, Builder.GetInsertPoint(), false, nullptr,
|
||||
&DTU, GenLI);
|
||||
BranchInst *Branch = cast<BranchInst>(HeadBlock->getTerminator());
|
||||
CondBrInst *Branch = cast<CondBrInst>(HeadBlock->getTerminator());
|
||||
BasicBlock *ThenBlock = Branch->getSuccessor(0);
|
||||
BasicBlock *TailBlock = Branch->getSuccessor(1);
|
||||
|
||||
|
||||
@ -146,7 +146,7 @@ void addParallelMetadata(LLVMContext &Ctx, SmallVector<Metadata *, 3> *Args,
|
||||
}
|
||||
|
||||
void ScopAnnotator::annotateLoopLatch(
|
||||
BranchInst *B, bool IsParallel,
|
||||
CondBrInst *B, bool IsParallel,
|
||||
std::optional<bool> EnableVectorizeMetadata) const {
|
||||
LLVMContext &Ctx = SE->getContext();
|
||||
SmallVector<Metadata *, 3> Args;
|
||||
|
||||
@ -163,7 +163,7 @@ Value *polly::createLoop(Value *LB, Value *UB, Value *Stride,
|
||||
Builder.CreateICmp(Predicate, IncrementedIV, UB, "polly.loop_cond");
|
||||
|
||||
// Create the loop latch and annotate it as such.
|
||||
BranchInst *B = Builder.CreateCondBr(LoopCondition, HeaderBB, ExitBB);
|
||||
CondBrInst *B = Builder.CreateCondBr(LoopCondition, HeaderBB, ExitBB);
|
||||
|
||||
// Don't annotate vectorize metadata when both LoopVectDisabled and
|
||||
// PollyVectorizeMetadata are disabled. Annotate vectorize metadata to false
|
||||
|
||||
@ -74,7 +74,7 @@ static BasicBlock *splitEdge(BasicBlock *Prev, BasicBlock *Succ,
|
||||
return MiddleBlock;
|
||||
}
|
||||
|
||||
std::pair<polly::BBPair, BranchInst *>
|
||||
std::pair<polly::BBPair, CondBrInst *>
|
||||
polly::executeScopConditionally(Scop &S, Value *RTC, DominatorTree &DT,
|
||||
RegionInfo &RI, LoopInfo &LI) {
|
||||
Region &R = S.getRegion();
|
||||
@ -146,7 +146,7 @@ polly::executeScopConditionally(Scop &S, Value *RTC, DominatorTree &DT,
|
||||
BasicBlock::Create(F->getContext(), "polly.exiting", F);
|
||||
SplitBlock->getTerminator()->eraseFromParent();
|
||||
Builder.SetInsertPoint(SplitBlock);
|
||||
BranchInst *CondBr = Builder.CreateCondBr(RTC, StartBlock, S.getEntry());
|
||||
CondBrInst *CondBr = Builder.CreateCondBr(RTC, StartBlock, S.getEntry());
|
||||
|
||||
if (Loop *L = LI.getLoopFor(SplitBlock)) {
|
||||
L->addBasicBlockToLoop(StartBlock, LI);
|
||||
|
||||
@ -463,20 +463,6 @@ Value *polly::expandCodeFor(Scop &S, llvm::ScalarEvolution &SE,
|
||||
return Expander.expandCodeFor(E, Ty, IP);
|
||||
}
|
||||
|
||||
Value *polly::getConditionFromTerminator(Instruction *TI) {
|
||||
if (BranchInst *BR = dyn_cast<BranchInst>(TI)) {
|
||||
if (BR->isUnconditional())
|
||||
return ConstantInt::getTrue(Type::getInt1Ty(TI->getContext()));
|
||||
|
||||
return BR->getCondition();
|
||||
}
|
||||
|
||||
if (SwitchInst *SI = dyn_cast<SwitchInst>(TI))
|
||||
return SI->getCondition();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Loop *polly::getLoopSurroundingScop(Scop &S, LoopInfo &LI) {
|
||||
// Start with the smallest loop containing the entry and expand that
|
||||
// loop until it contains all blocks in the region. If there is a loop
|
||||
|
||||
@ -35,8 +35,7 @@ static bool runCodePreprationImpl(Function &F, DominatorTree *DT, LoopInfo *LI,
|
||||
++I;
|
||||
|
||||
// Abort if not necessary to split
|
||||
if (I->isTerminator() && isa<BranchInst>(I) &&
|
||||
cast<BranchInst>(I)->isUnconditional())
|
||||
if (isa<UncondBrInst>(I))
|
||||
return false;
|
||||
|
||||
// splitBlock updates DT, LI and RI.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user