LLVM: lib/Transforms/Scalar/ConstraintElimination.cpp File Reference (original) (raw)
Go to the source code of this file.
Macros | |
---|---|
#define | DEBUG_TYPE "constraint-elimination" |
Functions | |
---|---|
STATISTIC (NumCondsRemoved, "Number of instructions removed") | |
DEBUG_COUNTER (EliminatedCounter, "conds-eliminated", "Controls which conditions are eliminated") | |
static int64_t | multiplyWithOverflow (int64_t A, int64_t B) |
static int64_t | addWithOverflow (int64_t A, int64_t B) |
static Instruction * | getContextInstForUse (Use &U) |
static OffsetResult | collectOffsets (GEPOperator &GEP, const DataLayout &DL) |
static Decomposition | decompose (Value *V, SmallVectorImpl< ConditionTy > &Preconditions, bool IsSigned, const DataLayout &DL) |
static bool | canUseSExt (ConstantInt *CI) |
static Decomposition | decomposeGEP (GEPOperator &GEP, SmallVectorImpl< ConditionTy > &Preconditions, bool IsSigned, const DataLayout &DL) |
static void | dumpConstraint (ArrayRef< int64_t > C, const DenseMap< Value *, unsigned > &Value2Index) |
static void | dumpUnpackedICmp (raw_ostream &OS, ICmpInst::Predicate Pred, Value *LHS, Value *RHS) |
static void | generateReproducer (CmpInst *Cond, Module *M, ArrayRef< ReproducerEntry > Stack, ConstraintInfo &Info, DominatorTree &DT) |
Helper function to generate a reproducer function for simplifying Cond. | |
static std::optional< bool > | checkCondition (CmpInst::Predicate Pred, Value *A, Value *B, Instruction *CheckInst, ConstraintInfo &Info) |
static bool | checkAndReplaceCondition (CmpInst *Cmp, ConstraintInfo &Info, unsigned NumIn, unsigned NumOut, Instruction *ContextInst, Module *ReproducerModule, ArrayRef< ReproducerEntry > ReproducerCondStack, DominatorTree &DT, SmallVectorImpl< Instruction * > &ToRemove) |
static bool | checkAndReplaceMinMax (MinMaxIntrinsic *MinMax, ConstraintInfo &Info, SmallVectorImpl< Instruction * > &ToRemove) |
static bool | checkAndReplaceCmp (CmpIntrinsic *I, ConstraintInfo &Info, SmallVectorImpl< Instruction * > &ToRemove) |
static void | removeEntryFromStack (const StackEntry &E, ConstraintInfo &Info, Module *ReproducerModule, SmallVectorImpl< ReproducerEntry > &ReproducerCondStack, SmallVectorImpl< StackEntry > &DFSInStack) |
static bool | checkOrAndOpImpliedByOther (FactOrCheck &CB, ConstraintInfo &Info, Module *ReproducerModule, SmallVectorImpl< ReproducerEntry > &ReproducerCondStack, SmallVectorImpl< StackEntry > &DFSInStack) |
Check if either the first condition of an AND or OR is implied by the (negated in case of OR) second condition or vice versa. | |
static bool | replaceSubOverflowUses (IntrinsicInst *II, Value *A, Value *B, SmallVectorImpl< Instruction * > &ToRemove) |
static bool | tryToSimplifyOverflowMath (IntrinsicInst *II, ConstraintInfo &Info, SmallVectorImpl< Instruction * > &ToRemove) |
static bool | eliminateConstraints (Function &F, DominatorTree &DT, LoopInfo &LI, ScalarEvolution &SE, OptimizationRemarkEmitter &ORE) |
Variables | |
---|---|
static cl::opt< unsigned > | MaxRows ("constraint-elimination-max-rows", cl::init(500), cl::Hidden, cl::desc("Maximum number of rows to keep in constraint system")) |
static cl::opt< bool > | DumpReproducers ("constraint-elimination-dump-reproducers", cl::init(false), cl::Hidden, cl::desc("Dump IR to reproduce successful transformations.")) |
static int64_t | MaxConstraintValue = std::numeric_limits<int64_t>::max() |
static int64_t | MinSignedConstraintValue = std::numeric_limits<int64_t>::min() |
◆ DEBUG_TYPE
#define DEBUG_TYPE "constraint-elimination"
◆ addWithOverflow()
static int64_t addWithOverflow ( int64_t A, int64_t B ) | static |
---|
◆ canUseSExt()
◆ checkAndReplaceCmp()
◆ checkAndReplaceCondition()
Definition at line 1417 of file ConstraintElimination.cpp.
References checkCondition(), generateReproducer(), llvm::ConstantInt::getBool(), getContextInstForUse(), llvm::DomTreeNodeBase< NodeT >::getDFSNumIn(), llvm::DomTreeNodeBase< NodeT >::getDFSNumOut(), llvm::DominatorTreeBase< NodeT, IsPostDom >::getNode(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), II, Info, llvm::CmpInst::makeCmpResultType(), and ToRemove.
◆ checkAndReplaceMinMax()
◆ checkCondition()
Definition at line 1376 of file ConstraintElimination.cpp.
References A, B, llvm::dbgs(), dumpUnpackedICmp(), llvm::CmpInst::getInversePredicate(), I, Info, LLVM_DEBUG, llvm::make_scope_exit(), and llvm::DebugCounter::shouldExecute().
Referenced by checkAndReplaceCmp(), checkAndReplaceCondition(), checkAndReplaceMinMax(), and checkOrAndOpImpliedByOther().
◆ checkOrAndOpImpliedByOther()
static bool checkOrAndOpImpliedByOther ( FactOrCheck & CB, ConstraintInfo & Info, Module * ReproducerModule, SmallVectorImpl< ReproducerEntry > & ReproducerCondStack, SmallVectorImpl< StackEntry > & DFSInStack ) | static |
---|
Check if either the first condition of an AND or OR is implied by the (negated in case of OR) second condition or vice versa.
Definition at line 1514 of file ConstraintElimination.cpp.
References checkCondition(), llvm::ConstantInt::getBool(), llvm::CmpInst::getInversePredicate(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Value::getType(), Info, LHS, llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::m_Value(), llvm::make_scope_exit(), llvm::PatternMatch::match(), RHS, llvm::User::setOperand(), and llvm::SmallVectorBase< Size_T >::size().
◆ collectOffsets()
◆ DEBUG_COUNTER()
DEBUG_COUNTER | ( | EliminatedCounter | , |
---|---|---|---|
"conds-eliminated" | , | ||
"Controls which conditions are eliminated" | |||
) |
◆ decompose()
Definition at line 478 of file ConstraintElimination.cpp.
References A, assert(), B, canUseSExt(), decompose(), decomposeGEP(), DL, llvm::SmallVectorImpl< T >::emplace_back(), GEP, llvm::Type::getIntegerBitWidth(), llvm::APInt::getLimitedValue(), llvm::Type::getScalarSizeInBits(), llvm::ConstantInt::getSExtValue(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_UGE, llvm::Type::isIntegerTy(), llvm::isKnownNonNegative(), llvm::ConstantInt::isNegative(), llvm::Type::isPointerTy(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_DisjointOr(), llvm::PatternMatch::m_NNegZExt(), llvm::PatternMatch::m_NSWAdd(), llvm::PatternMatch::m_NSWMul(), llvm::PatternMatch::m_NSWShl(), llvm::PatternMatch::m_NSWSub(), llvm::PatternMatch::m_NSWTrunc(), llvm::PatternMatch::m_NUWAdd(), llvm::PatternMatch::m_NUWMul(), llvm::PatternMatch::m_NUWShl(), llvm::PatternMatch::m_NUWSub(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), and MaxConstraintValue.
Referenced by decompose(), and decomposeGEP().
◆ decomposeGEP()
◆ dumpConstraint()
◆ dumpUnpackedICmp()
static void dumpUnpackedICmp ( raw_ostream & OS, ICmpInst::Predicate Pred, Value * LHS, Value * RHS ) | static |
---|
◆ eliminateConstraints()
Definition at line 1702 of file ConstraintElimination.cpp.
References A, B, DumpReproducers, F, llvm::DominatorTreeBase< NodeT, IsPostDom >::getNode(), if(), Info, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::stable_sort(), and llvm::DominatorTreeBase< NodeT, IsPostDom >::updateDFSNumbers().
Referenced by llvm::ConstraintEliminationPass::run().
◆ generateReproducer()
Helper function to generate a reproducer function for simplifying Cond
.
The reproducer function contains a series of @llvm.assume calls, one for each condition in Stack
. For each condition, the operand instruction are cloned until we reach operands that have an entry in Value2Index
. Those will then be added as function arguments. DT
is used to order cloned instructions. The reproducer function will get added to M
, if it is non-null. Otherwise no reproducer function is generated.
Definition at line 1248 of file ConstraintElimination.cpp.
References A, llvm::append_range(), assert(), B, Cond, llvm::Function::Create(), llvm::BasicBlock::Create(), llvm::IRBuilderBase::CreateAssumption(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateRet(), llvm::dbgs(), llvm::DominatorTree::dominates(), llvm::Instruction::dropUnknownNonDebugMetadata(), dumpUnpackedICmp(), llvm::SmallVectorBase< Size_T >::empty(), llvm::ValueMap< KeyT, ValueT, Config >::end(), F, llvm::ValueMap< KeyT, ValueT, Config >::find(), llvm::IRBuilderBase::GetInsertPoint(), getName(), llvm::IRBuilderBase::getTrue(), I, Info, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Instruction::insertBefore(), llvm::CmpInst::isSigned(), LLVM_DEBUG, P, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::remapInstructionsInBlocks(), llvm::Instruction::setDebugLoc(), llvm::IRBuilderBase::SetInsertPoint(), llvm::sort(), and llvm::verifyFunction().
Referenced by checkAndReplaceCondition().
◆ getContextInstForUse()
◆ multiplyWithOverflow()
static int64_t multiplyWithOverflow ( int64_t A, int64_t B ) | static |
---|
◆ removeEntryFromStack()
static void removeEntryFromStack ( const StackEntry & E, ConstraintInfo & Info, Module * ReproducerModule, SmallVectorImpl< ReproducerEntry > & ReproducerCondStack, SmallVectorImpl< StackEntry > & DFSInStack ) | static |
---|
◆ replaceSubOverflowUses()
Definition at line 1642 of file ConstraintElimination.cpp.
References A, B, llvm::IRBuilderBase::CreateSub(), llvm::PoisonValue::get(), llvm::IRBuilderBase::getFalse(), I, II, llvm::PatternMatch::m_Value(), llvm::make_early_inc_range(), llvm::PatternMatch::match(), and ToRemove.
Referenced by tryToSimplifyOverflowMath().
◆ STATISTIC()
STATISTIC | ( | NumCondsRemoved | , |
---|---|---|---|
"Number of instructions removed" | |||
) |
◆ tryToSimplifyOverflowMath()
◆ DumpReproducers
cl::opt< bool > DumpReproducers("constraint-elimination-dump-reproducers", cl::init(false), cl::Hidden, cl::desc("Dump IR to reproduce successful transformations.")) ( "constraint-elimination-dump-reproducers" , cl::init(false) , cl::Hidden , cl::desc("Dump IR to reproduce successful transformations.") ) | static |
---|
◆ MaxConstraintValue
int64_t MaxConstraintValue = std::numeric_limits<int64_t>::max() | static |
---|
◆ MaxRows
cl::opt< unsigned > MaxRows("constraint-elimination-max-rows", cl::init(500), cl::Hidden, cl::desc("Maximum number of rows to keep in constraint system")) ( "constraint-elimination-max-rows" , cl::init(500) , cl::Hidden , cl::desc("Maximum number of rows to keep in constraint system") ) | static |
---|
◆ MinSignedConstraintValue
int64_t MinSignedConstraintValue = std::numeric_limits<int64_t>::min() | static |
---|