diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp')
-rw-r--r-- | contrib/libs/llvm12/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/contrib/libs/llvm12/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/contrib/libs/llvm12/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp index 9d3c8d0f37..8318870308 100644 --- a/contrib/libs/llvm12/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/contrib/libs/llvm12/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -26,14 +26,14 @@ #include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/MemorySSA.h" #include "llvm/Analysis/MemorySSAUpdater.h" -#include "llvm/Analysis/MustExecute.h" -#include "llvm/Analysis/ScalarEvolution.h" +#include "llvm/Analysis/MustExecute.h" +#include "llvm/Analysis/ScalarEvolution.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" -#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/IRBuilder.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" @@ -51,7 +51,7 @@ #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/Cloning.h" -#include "llvm/Transforms/Utils/Local.h" +#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/LoopUtils.h" #include "llvm/Transforms/Utils/ValueMapper.h" #include <algorithm> @@ -96,11 +96,11 @@ static cl::opt<bool> UnswitchGuards( "simple-loop-unswitch-guards", cl::init(true), cl::Hidden, cl::desc("If enabled, simple loop unswitching will also consider " "llvm.experimental.guard intrinsics as unswitch candidates.")); -static cl::opt<bool> DropNonTrivialImplicitNullChecks( - "simple-loop-unswitch-drop-non-trivial-implicit-null-checks", - cl::init(false), cl::Hidden, - cl::desc("If enabled, drop make.implicit metadata in unswitched implicit " - "null checks to save time analyzing if we can keep it.")); +static cl::opt<bool> DropNonTrivialImplicitNullChecks( + "simple-loop-unswitch-drop-non-trivial-implicit-null-checks", + cl::init(false), cl::Hidden, + cl::desc("If enabled, drop make.implicit metadata in unswitched implicit " + "null checks to save time analyzing if we can keep it.")); /// Collect all of the loop invariant input values transitively used by the /// homogeneous instruction graph from a given root. @@ -692,9 +692,9 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT, // successor. BasicBlock *CommonSuccBB = nullptr; if (SI.getNumCases() > 0 && - all_of(drop_begin(SI.cases()), [&SI](const SwitchInst::CaseHandle &Case) { - return Case.getCaseSuccessor() == SI.case_begin()->getCaseSuccessor(); - })) + all_of(drop_begin(SI.cases()), [&SI](const SwitchInst::CaseHandle &Case) { + return Case.getCaseSuccessor() == SI.case_begin()->getCaseSuccessor(); + })) CommonSuccBB = SI.case_begin()->getCaseSuccessor(); if (!DefaultExitBB) { // If we're not unswitching the default, we need it to match any cases to @@ -855,11 +855,11 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT, } if (MSSAU) { - MSSAU->applyUpdates(DTUpdates, DT, /*UpdateDT=*/true); + MSSAU->applyUpdates(DTUpdates, DT, /*UpdateDT=*/true); if (VerifyMemorySSA) MSSAU->getMemorySSA()->verifyMemorySSA(); - } else { - DT.applyUpdates(DTUpdates); + } else { + DT.applyUpdates(DTUpdates); } assert(DT.verify(DominatorTree::VerificationLevel::Fast)); @@ -1140,22 +1140,22 @@ static BasicBlock *buildClonedLoopBlocks( // Replace the cloned branch with an unconditional branch to the cloned // unswitched successor. auto *ClonedSuccBB = cast<BasicBlock>(VMap.lookup(UnswitchedSuccBB)); - Instruction *ClonedTerminator = ClonedParentBB->getTerminator(); - // Trivial Simplification. If Terminator is a conditional branch and - // condition becomes dead - erase it. - Value *ClonedConditionToErase = nullptr; - if (auto *BI = dyn_cast<BranchInst>(ClonedTerminator)) - ClonedConditionToErase = BI->getCondition(); - else if (auto *SI = dyn_cast<SwitchInst>(ClonedTerminator)) - ClonedConditionToErase = SI->getCondition(); - - ClonedTerminator->eraseFromParent(); + Instruction *ClonedTerminator = ClonedParentBB->getTerminator(); + // Trivial Simplification. If Terminator is a conditional branch and + // condition becomes dead - erase it. + Value *ClonedConditionToErase = nullptr; + if (auto *BI = dyn_cast<BranchInst>(ClonedTerminator)) + ClonedConditionToErase = BI->getCondition(); + else if (auto *SI = dyn_cast<SwitchInst>(ClonedTerminator)) + ClonedConditionToErase = SI->getCondition(); + + ClonedTerminator->eraseFromParent(); BranchInst::Create(ClonedSuccBB, ClonedParentBB); - if (ClonedConditionToErase) - RecursivelyDeleteTriviallyDeadInstructions(ClonedConditionToErase, nullptr, - MSSAU); - + if (ClonedConditionToErase) + RecursivelyDeleteTriviallyDeadInstructions(ClonedConditionToErase, nullptr, + MSSAU); + // If there are duplicate entries in the PHI nodes because of multiple edges // to the unswitched successor, we need to nuke all but one as we replaced it // with a direct branch. @@ -1214,7 +1214,7 @@ static Loop *cloneLoopNest(Loop &OrigRootL, Loop *RootParentL, LI.addTopLevelLoop(ClonedRootL); AddClonedBlocksToLoop(OrigRootL, *ClonedRootL); - if (OrigRootL.isInnermost()) + if (OrigRootL.isInnermost()) return ClonedRootL; // If we have a nest, we can quickly clone the entire loop nest using an @@ -2090,23 +2090,23 @@ static void unswitchNontrivialInvariants( DominatingSucc, *VMaps.back(), DTUpdates, AC, DT, LI, MSSAU); } - // Drop metadata if we may break its semantics by moving this instr into the - // split block. - if (TI.getMetadata(LLVMContext::MD_make_implicit)) { - if (DropNonTrivialImplicitNullChecks) - // Do not spend time trying to understand if we can keep it, just drop it - // to save compile time. - TI.setMetadata(LLVMContext::MD_make_implicit, nullptr); - else { - // It is only legal to preserve make.implicit metadata if we are - // guaranteed no reach implicit null check after following this branch. - ICFLoopSafetyInfo SafetyInfo; - SafetyInfo.computeLoopSafetyInfo(&L); - if (!SafetyInfo.isGuaranteedToExecute(TI, &DT, &L)) - TI.setMetadata(LLVMContext::MD_make_implicit, nullptr); - } - } - + // Drop metadata if we may break its semantics by moving this instr into the + // split block. + if (TI.getMetadata(LLVMContext::MD_make_implicit)) { + if (DropNonTrivialImplicitNullChecks) + // Do not spend time trying to understand if we can keep it, just drop it + // to save compile time. + TI.setMetadata(LLVMContext::MD_make_implicit, nullptr); + else { + // It is only legal to preserve make.implicit metadata if we are + // guaranteed no reach implicit null check after following this branch. + ICFLoopSafetyInfo SafetyInfo; + SafetyInfo.computeLoopSafetyInfo(&L); + if (!SafetyInfo.isGuaranteedToExecute(TI, &DT, &L)) + TI.setMetadata(LLVMContext::MD_make_implicit, nullptr); + } + } + // The stitching of the branched code back together depends on whether we're // doing full unswitching or not with the exception that we always want to // nuke the initial terminator placed in the split block. @@ -2353,12 +2353,12 @@ static void unswitchNontrivialInvariants( for (Loop *UpdatedL : llvm::concat<Loop *>(NonChildClonedLoops, HoistedLoops)) { UpdateLoop(*UpdatedL); - if (UpdatedL->isOutermost()) + if (UpdatedL->isOutermost()) OuterExitL = nullptr; } if (IsStillLoop) { UpdateLoop(L); - if (L.isOutermost()) + if (L.isOutermost()) OuterExitL = nullptr; } @@ -2706,10 +2706,10 @@ unswitchBestCondition(Loop &L, DominatorTree &DT, LoopInfo &LI, // (convergent, noduplicate, or cross-basic-block tokens). // FIXME: We might be able to safely handle some of these in non-duplicated // regions. - TargetTransformInfo::TargetCostKind CostKind = - L.getHeader()->getParent()->hasMinSize() - ? TargetTransformInfo::TCK_CodeSize - : TargetTransformInfo::TCK_SizeAndLatency; + TargetTransformInfo::TargetCostKind CostKind = + L.getHeader()->getParent()->hasMinSize() + ? TargetTransformInfo::TCK_CodeSize + : TargetTransformInfo::TCK_SizeAndLatency; int LoopCost = 0; for (auto *BB : L.blocks()) { int Cost = 0; @@ -2723,7 +2723,7 @@ unswitchBestCondition(Loop &L, DominatorTree &DT, LoopInfo &LI, if (CB->isConvergent() || CB->cannotDuplicate()) return false; - Cost += TTI.getUserCost(&I, CostKind); + Cost += TTI.getUserCost(&I, CostKind); } assert(Cost >= 0 && "Must not have negative costs!"); LoopCost += Cost; @@ -2904,10 +2904,10 @@ static bool unswitchLoop(Loop &L, DominatorTree &DT, LoopInfo &LI, if (!NonTrivial && !EnableNonTrivialUnswitch) return false; - // Skip non-trivial unswitching for optsize functions. - if (L.getHeader()->getParent()->hasOptSize()) - return false; - + // Skip non-trivial unswitching for optsize functions. + if (L.getHeader()->getParent()->hasOptSize()) + return false; + // For non-trivial unswitching, because it often creates new loops, we rely on // the pass manager to iterate on the loops rather than trying to immediately // reach a fixed point. There is no substantial advantage to iterating @@ -2920,7 +2920,7 @@ static bool unswitchLoop(Loop &L, DominatorTree &DT, LoopInfo &LI, return true; // No other opportunities to unswitch. - return false; + return false; } PreservedAnalyses SimpleLoopUnswitchPass::run(Loop &L, LoopAnalysisManager &AM, |