mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[IR] Add BasicBlock::isEntryBlock() (NFC)
This is a recurring and somewhat awkward pattern. Add a helper method for it.
This commit is contained in:
parent
4c98aa53c1
commit
d8b6f240a9
@ -480,6 +480,10 @@ public:
|
||||
/// Return true if it is legal to hoist instructions into this block.
|
||||
bool isLegalToHoistInto() const;
|
||||
|
||||
/// Return true if this is the entry block of the containing function.
|
||||
/// This method can only be used on blocks that have a parent function.
|
||||
bool isEntryBlock() const;
|
||||
|
||||
Optional<uint64_t> getIrrLoopHeaderWeight() const;
|
||||
|
||||
/// Returns true if the Order field of child Instructions is valid.
|
||||
|
@ -248,7 +248,7 @@ bool llvm::isPotentiallyReachable(
|
||||
|
||||
// Can't be in a loop if it's the entry block -- the entry block may not
|
||||
// have predecessors.
|
||||
if (BB == &BB->getParent()->getEntryBlock())
|
||||
if (BB->isEntryBlock())
|
||||
return false;
|
||||
|
||||
// Otherwise, continue doing the normal per-BB CFG walk.
|
||||
@ -267,10 +267,10 @@ bool llvm::isPotentiallyReachable(
|
||||
!DT->isReachableFromEntry(B->getParent()))
|
||||
return false;
|
||||
if (!ExclusionSet || ExclusionSet->empty()) {
|
||||
if (A->getParent() == &A->getParent()->getParent()->getEntryBlock() &&
|
||||
if (A->getParent()->isEntryBlock() &&
|
||||
DT->isReachableFromEntry(B->getParent()))
|
||||
return true;
|
||||
if (B->getParent() == &A->getParent()->getParent()->getEntryBlock() &&
|
||||
if (B->getParent()->isEntryBlock() &&
|
||||
DT->isReachableFromEntry(A->getParent()))
|
||||
return false;
|
||||
}
|
||||
|
@ -134,8 +134,7 @@ namespace {
|
||||
//
|
||||
// (1) BB is an entry block or have no successors.
|
||||
// (2) There's no path coming back through BB successors.
|
||||
if (BB == &BB->getParent()->getEntryBlock() ||
|
||||
!BB->getTerminator()->getNumSuccessors())
|
||||
if (BB->isEntryBlock() || !BB->getTerminator()->getNumSuccessors())
|
||||
return true;
|
||||
|
||||
SmallVector<BasicBlock*, 32> Worklist;
|
||||
|
@ -224,8 +224,8 @@ static bool valueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT) {
|
||||
|
||||
// Otherwise, if the instruction is in the entry block and is not an invoke,
|
||||
// then it obviously dominates all phi nodes.
|
||||
if (I->getParent() == &I->getFunction()->getEntryBlock() &&
|
||||
!isa<InvokeInst>(I) && !isa<CallBrInst>(I))
|
||||
if (I->getParent()->isEntryBlock() && !isa<InvokeInst>(I) &&
|
||||
!isa<CallBrInst>(I))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -673,7 +673,7 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueNonLocal(
|
||||
|
||||
// If this is the entry block, we must be asking about an argument. The
|
||||
// value is overdefined.
|
||||
if (BB == &BB->getParent()->getEntryBlock()) {
|
||||
if (BB->isEntryBlock()) {
|
||||
assert(isa<Argument>(Val) && "Unknown live-in to the entry block");
|
||||
return ValueLatticeElement::getOverdefined();
|
||||
}
|
||||
|
@ -2553,9 +2553,8 @@ bool upward_defs_iterator::IsGuaranteedLoopInvariant(Value *Ptr) const {
|
||||
|
||||
Ptr = Ptr->stripPointerCasts();
|
||||
if (auto *I = dyn_cast<Instruction>(Ptr)) {
|
||||
if (I->getParent() == &I->getFunction()->getEntryBlock()) {
|
||||
if (I->getParent()->isEntryBlock())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
|
||||
return IsGuaranteedLoopInvariantBase(GEP->getPointerOperand()) &&
|
||||
|
@ -2072,7 +2072,7 @@ bool SelectionDAGBuilder::isExportableFromCurrentBlock(const Value *V,
|
||||
// If this is an argument, we can export it if the BB is the entry block or
|
||||
// if it is already exported.
|
||||
if (isa<Argument>(V)) {
|
||||
if (FromBB == &FromBB->getParent()->getEntryBlock())
|
||||
if (FromBB->isEntryBlock())
|
||||
return true;
|
||||
|
||||
// Otherwise, can only export this if it is already exported.
|
||||
|
@ -3858,7 +3858,7 @@ void AssemblyWriter::printArgument(const Argument *Arg, AttributeSet Attrs) {
|
||||
/// printBasicBlock - This member is called for each basic block in a method.
|
||||
void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
|
||||
assert(BB && BB->getParent() && "block without parent!");
|
||||
bool IsEntryBlock = BB == &BB->getParent()->getEntryBlock();
|
||||
bool IsEntryBlock = BB->isEntryBlock();
|
||||
if (BB->hasName()) { // Print out the label if it exists...
|
||||
Out << "\n";
|
||||
PrintLLVMName(Out, BB->getName(), LabelPrefix);
|
||||
|
@ -372,6 +372,12 @@ bool BasicBlock::isLegalToHoistInto() const {
|
||||
return !Term->isExceptionalTerminator();
|
||||
}
|
||||
|
||||
bool BasicBlock::isEntryBlock() const {
|
||||
const Function *F = getParent();
|
||||
assert(F && "Block must have a parent function to use this API");
|
||||
return this == &F->getEntryBlock();
|
||||
}
|
||||
|
||||
BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName,
|
||||
bool Before) {
|
||||
if (Before)
|
||||
|
@ -970,7 +970,7 @@ static void printBBName(raw_ostream &out, const BasicBlock *BB) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (BB == &BB->getParent()->getEntryBlock()) {
|
||||
if (BB->isEntryBlock()) {
|
||||
out << "entry"
|
||||
<< "<" << BB << ">";
|
||||
return;
|
||||
|
@ -1270,9 +1270,8 @@ struct DSEState {
|
||||
|
||||
Ptr = Ptr->stripPointerCasts();
|
||||
if (auto *I = dyn_cast<Instruction>(Ptr)) {
|
||||
if (I->getParent() == &I->getFunction()->getEntryBlock()) {
|
||||
if (I->getParent()->isEntryBlock())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
|
||||
return IsGuaranteedLoopInvariantBase(GEP->getPointerOperand()) &&
|
||||
|
@ -114,7 +114,7 @@ static bool isLoopNeverExecuted(Loop *L) {
|
||||
// predecessor.
|
||||
assert(Preheader && "Needs preheader!");
|
||||
|
||||
if (Preheader == &Preheader->getParent()->getEntryBlock())
|
||||
if (Preheader->isEntryBlock())
|
||||
return false;
|
||||
// All predecessors of the preheader should have a constant conditional
|
||||
// branch, with the loop's preheader as not-taken.
|
||||
|
@ -732,8 +732,7 @@ bool BCECmpChain::simplify(const TargetLibraryInfo &TLI, AliasAnalysis &AA,
|
||||
|
||||
// If the old cmp chain was the function entry, we need to update the function
|
||||
// entry.
|
||||
const bool ChainEntryIsFnEntry =
|
||||
(EntryBlock_ == &EntryBlock_->getParent()->getEntryBlock());
|
||||
const bool ChainEntryIsFnEntry = EntryBlock_->isEntryBlock();
|
||||
if (ChainEntryIsFnEntry && DTU.hasDomTree()) {
|
||||
LLVM_DEBUG(dbgs() << "Changing function entry from "
|
||||
<< EntryBlock_->getName() << " to "
|
||||
|
@ -887,7 +887,7 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
|
||||
if (DTU) {
|
||||
// Recalculation of DomTree is needed when updating a forward DomTree and
|
||||
// the Entry BB is replaced.
|
||||
if (NewBB == &NewBB->getParent()->getEntryBlock() && DTU->hasDomTree()) {
|
||||
if (NewBB->isEntryBlock() && DTU->hasDomTree()) {
|
||||
// The entry block was removed and there is no external interface for
|
||||
// the dominator tree to be notified of this change. In this corner-case
|
||||
// we recalculate the entire tree.
|
||||
@ -906,7 +906,7 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
|
||||
}
|
||||
} else if (DT) {
|
||||
if (OldBB == DT->getRootNode()->getBlock()) {
|
||||
assert(NewBB == &NewBB->getParent()->getEntryBlock());
|
||||
assert(NewBB->isEntryBlock());
|
||||
DT->setNewRoot(NewBB);
|
||||
} else {
|
||||
// Split block expects NewBB to have a non-empty set of predecessors.
|
||||
|
@ -738,9 +738,7 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB,
|
||||
BasicBlock *PredBB = DestBB->getSinglePredecessor();
|
||||
assert(PredBB && "Block doesn't have a single predecessor!");
|
||||
|
||||
bool ReplaceEntryBB = false;
|
||||
if (PredBB == &DestBB->getParent()->getEntryBlock())
|
||||
ReplaceEntryBB = true;
|
||||
bool ReplaceEntryBB = PredBB->isEntryBlock();
|
||||
|
||||
// DTU updates: Collect all the edges that enter
|
||||
// PredBB. These dominator edges will be redirected to DestBB.
|
||||
|
Loading…
Reference in New Issue
Block a user