LLVM 22.0.0git
|
#include "llvm/Transforms/Scalar/GuardWidening.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/GuardUtils.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/GuardUtils.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include <functional>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "guard-widening" |
Functions | |
STATISTIC (GuardsEliminated, "Number of eliminated guards") | |
STATISTIC (CondBranchEliminated, "Number of eliminated conditional branches") | |
STATISTIC (FreezeAdded, "Number of freeze instruction introduced") | |
static Value * | getCondition (Instruction *I) |
static void | setCondition (Instruction *I, Value *NewCond) |
static void | eliminateGuard (Instruction *GuardInst, MemorySSAUpdater *MSSAU) |
static std::optional< BasicBlock::iterator > | findInsertionPointForWideCondition (Instruction *WCOrGuard) |
Find a point at which the widened condition of Guard should be inserted. | |
static bool | isSupportedGuardInstruction (const Instruction *Insn) |
static std::optional< BasicBlock::iterator > | getFreezeInsertPt (Value *V, const DominatorTree &DT) |
Variables | |
static cl::opt< bool > | WidenBranchGuards ("guard-widening-widen-branch-guards", cl::Hidden, cl::desc("Whether or not we should widen guards " "expressed as branches by widenable conditions"), cl::init(true)) |
#define DEBUG_TYPE "guard-widening" |
Definition at line 66 of file GuardWidening.cpp.
|
static |
Definition at line 106 of file GuardWidening.cpp.
References llvm::Instruction::eraseFromParent(), and llvm::MemorySSAUpdater::removeMemoryAccess().
|
static |
Find a point at which the widened condition of Guard
should be inserted.
When it is represented as intrinsic call, we can do it right before the call instruction. However, when we are dealing with widenable branch, we must account for the following situation: widening should not turn a loop-invariant condition into a loop-variant. It means that if widenable.condition() call is invariant (w.r.t. any loop), the new wide condition should stay invariant. Otherwise there can be a miscompile, like the one described at https://github.com/llvm/llvm-project/issues/60234. The safest way to do it is to expand the new condition at WC's block.
Definition at line 123 of file GuardWidening.cpp.
References llvm::cast(), llvm::extractWidenableCondition(), llvm::ilist_node_impl< OptionsT >::getIterator(), and llvm::isGuard().
|
static |
Definition at line 79 of file GuardWidening.cpp.
References assert(), llvm::cast(), Cond, llvm::dyn_cast(), I, and llvm::parseWidenableBranch().
Referenced by foldICmpWithDominatingICmp(), handleGuaranteedWellDefinedOps(), llvm::AArch64TTIImpl::isProfitableToSinkOperands(), LLVMGetCondition(), negateICmpIfUsedByBranchOrSelectOnly(), llvm::PredicateSwitch::PredicateSwitch(), shouldInsertFreeze(), and SimplifyCondBranchToCondBranch().
|
static |
Definition at line 604 of file GuardWidening.cpp.
References llvm::any_of(), llvm::DominatorTree::dominates(), llvm::dyn_cast(), llvm::BasicBlock::getFirstNonPHIOrDbgOrAlloca(), llvm::DominatorTreeBase< NodeT, IsPostDom >::getRoot(), and I.
|
static |
Definition at line 333 of file GuardWidening.cpp.
References llvm::isGuard(), llvm::isGuardAsWidenableBranch(), and WidenBranchGuards.
|
static |
Definition at line 95 of file GuardWidening.cpp.
References assert(), llvm::cast(), llvm::dyn_cast(), and I.
STATISTIC | ( | CondBranchEliminated | , |
"Number of eliminated conditional branches" | ) |
STATISTIC | ( | FreezeAdded | , |
"Number of freeze instruction introduced" | ) |
STATISTIC | ( | GuardsEliminated | , |
"Number of eliminated guards" | ) |
|
static |
Referenced by isSupportedGuardInstruction().