Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
ConstraintElimination.cpp File Reference

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 InstructiongetContextInstForUse (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 bool getConstraintFromMemoryAccess (GetElementPtrInst &GEP, uint64_t AccessSize, CmpPredicate &Pred, Value *&A, Value *&B, const DataLayout &DL, const TargetLibraryInfo &TLI)
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< boolcheckCondition (CmpInst::Predicate Pred, Value *A, Value *B, Instruction *CheckInst, ConstraintInfo &Info)
static bool checkAndReplaceCondition (ICmpInst *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, SmallVectorImpl< Instruction * > &ToRemove)
 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, TargetLibraryInfo &TLI)

Variables

static cl::opt< unsignedMaxRows ("constraint-elimination-max-rows", cl::init(500), cl::Hidden, cl::desc("Maximum number of rows to keep in constraint system"))
static cl::opt< boolDumpReproducers ("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()

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "constraint-elimination"

Definition at line 52 of file ConstraintElimination.cpp.

Function Documentation

◆ canUseSExt()

◆ checkAndReplaceCmp()

bool checkAndReplaceCmp ( CmpIntrinsic * I,
ConstraintInfo & Info,
SmallVectorImpl< Instruction * > & ToRemove )
static

◆ checkAndReplaceCondition()

◆ checkAndReplaceMinMax()

bool checkAndReplaceMinMax ( MinMaxIntrinsic * MinMax,
ConstraintInfo & Info,
SmallVectorImpl< Instruction * > & ToRemove )
static

◆ checkCondition()

◆ checkOrAndOpImpliedByOther()

◆ collectOffsets()

◆ DEBUG_COUNTER()

DEBUG_COUNTER ( EliminatedCounter ,
"conds-eliminated" ,
"Controls which conditions are eliminated"  )

◆ decompose()

◆ decomposeGEP()

◆ dumpConstraint()

void dumpConstraint ( ArrayRef< int64_t > C,
const DenseMap< Value *, unsigned > & Value2Index )
static

◆ dumpUnpackedICmp()

void dumpUnpackedICmp ( raw_ostream & OS,
ICmpInst::Predicate Pred,
Value * LHS,
Value * RHS )
static

Definition at line 1338 of file ConstraintElimination.cpp.

References LHS, and RHS.

Referenced by checkCondition(), and generateReproducer().

◆ eliminateConstraints()

◆ generateReproducer()

void generateReproducer ( CmpInst * Cond,
Module * M,
ArrayRef< ReproducerEntry > Stack,
ConstraintInfo & Info,
DominatorTree & DT )
static

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 1369 of file ConstraintElimination.cpp.

References A(), AbstractManglingParser< Derived, Alloc >::Ops, llvm::append_range(), assert(), B(), llvm::CmpInst::BAD_ICMP_PREDICATE, Cond, llvm::BasicBlock::Create(), llvm::Function::Create(), llvm::dbgs(), llvm::DominatorTree::dominates(), llvm::Instruction::dropUnknownNonDebugMetadata(), dumpUnpackedICmp(), llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::ValueMap< KeyT, ValueT, Config >::end(), llvm::GlobalValue::ExternalLinkage, F, llvm::ValueMap< KeyT, ValueT, Config >::find(), llvm::FunctionType::get(), getName(), I, Info, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Instruction::insertBefore(), llvm::isa(), llvm::CmpInst::isSigned(), LLVM_DEBUG, P, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::remapInstructionsInBlocks(), llvm::Instruction::setDebugLoc(), llvm::sort(), and llvm::verifyFunction().

Referenced by checkAndReplaceCondition().

◆ getConstraintFromMemoryAccess()

◆ getContextInstForUse()

Instruction * getContextInstForUse ( Use & U)
static

Definition at line 69 of file ConstraintElimination.cpp.

References llvm::cast(), and llvm::dyn_cast().

Referenced by checkAndReplaceCondition().

◆ removeEntryFromStack()

void removeEntryFromStack ( const StackEntry & E,
ConstraintInfo & Info,
Module * ReproducerModule,
SmallVectorImpl< ReproducerEntry > & ReproducerCondStack,
SmallVectorImpl< StackEntry > & DFSInStack )
static

◆ replaceSubOverflowUses()

◆ STATISTIC()

STATISTIC ( NumCondsRemoved ,
"Number of instructions removed"  )

◆ tryToSimplifyOverflowMath()

bool tryToSimplifyOverflowMath ( IntrinsicInst * II,
ConstraintInfo & Info,
SmallVectorImpl< Instruction * > & ToRemove )
static

Variable Documentation

◆ 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

Referenced by eliminateConstraints().

◆ MaxConstraintValue

int64_t MaxConstraintValue = std::numeric_limits<int64_t>::max()
static

Definition at line 66 of file ConstraintElimination.cpp.

Referenced by canUseSExt(), and decompose().

◆ 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

Definition at line 67 of file ConstraintElimination.cpp.

Referenced by canUseSExt().