LLVM 22.0.0git
BoundsChecking.cpp File Reference

Go to the source code of this file.

Classes

class  BuilderTy

Macros

#define DEBUG_TYPE   "bounds-checking"

Functions

 STATISTIC (ChecksAdded, "Bounds checks added")
 STATISTIC (ChecksSkipped, "Bounds checks skipped")
 STATISTIC (ChecksUnable, "Bounds checks unable to add")
static ValuegetBoundsCheckCond (Value *Ptr, Value *InstVal, const DataLayout &DL, TargetLibraryInfo &TLI, ObjectSizeOffsetEvaluator &ObjSizeEval, BuilderTy &IRB, ScalarEvolution &SE)
 Gets the conditions under which memory accessing instructions will overflow.
static CallInstInsertTrap (BuilderTy &IRB, bool DebugTrapBB, std::optional< int8_t > GuardKind)
static CallInstInsertCall (BuilderTy &IRB, bool MayReturn, StringRef Name)
template<typename GetTrapBBT>
static void insertBoundsCheck (Value *Or, BuilderTy &IRB, GetTrapBBT GetTrapBB)
 Adds run-time bounds checks to memory accessing instructions.
static std::string getRuntimeCallName (const BoundsCheckingPass::Options::Runtime &Opts)
static bool addBoundsChecking (Function &F, TargetLibraryInfo &TLI, ScalarEvolution &SE, const BoundsCheckingPass::Options &Opts)

Variables

static cl::opt< boolSingleTrapBB ("bounds-checking-single-trap", cl::desc("Use one trap block per function"))

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "bounds-checking"

Definition at line 35 of file BoundsChecking.cpp.

Function Documentation

◆ addBoundsChecking()

◆ getBoundsCheckCond()

Value * getBoundsCheckCond ( Value * Ptr,
Value * InstVal,
const DataLayout & DL,
TargetLibraryInfo & TLI,
ObjectSizeOffsetEvaluator & ObjSizeEval,
BuilderTy & IRB,
ScalarEvolution & SE )
static

Gets the conditions under which memory accessing instructions will overflow.

Ptr is the pointer that will be read/written, and InstVal is either the result from the load or the value being stored. It is used to determine the size of memory block that is touched.

Returns the condition under which the access will overflow.

Definition at line 59 of file BoundsChecking.cpp.

References llvm::SizeOffsetType< T, C >::bothKnown(), llvm::ObjectSizeOffsetEvaluator::compute(), llvm::IRBuilderBase::CreateICmpSLT(), llvm::IRBuilderBase::CreateICmpULT(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateSub(), llvm::IRBuilderBase::CreateTypeSize(), llvm::dbgs(), DL, llvm::dyn_cast(), llvm::ConstantInt::getFalse(), llvm::ScalarEvolution::getSCEV(), llvm::Value::getType(), llvm::ScalarEvolution::getUnsignedRange(), llvm::ConstantInt::getValue(), LLVM_DEBUG, llvm::Offset, llvm::SizeOffsetType< T, C >::Offset, Ptr, Size, llvm::SizeOffsetType< T, C >::Size, and llvm::APInt::slt().

Referenced by addBoundsChecking().

◆ getRuntimeCallName()

◆ insertBoundsCheck()

template<typename GetTrapBBT>
void insertBoundsCheck ( Value * Or,
BuilderTy & IRB,
GetTrapBBT GetTrapBB )
static

Adds run-time bounds checks to memory accessing instructions.

Or is the condition that should guard the trap.

GetTrapBB is a callable that returns the trap BB to use on failure.

Definition at line 144 of file BoundsChecking.cpp.

References llvm::CallingConv::C, llvm::BranchInst::Create(), llvm::dyn_cast_or_null(), llvm::Instruction::eraseFromParent(), llvm::IRBuilderBase::GetInsertPoint(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), and llvm::BasicBlock::splitBasicBlock().

Referenced by addBoundsChecking().

◆ InsertCall()

◆ InsertTrap()

CallInst * InsertTrap ( BuilderTy & IRB,
bool DebugTrapBB,
std::optional< int8_t > GuardKind )
static

◆ STATISTIC() [1/3]

STATISTIC ( ChecksAdded ,
"Bounds checks added"  )

◆ STATISTIC() [2/3]

STATISTIC ( ChecksSkipped ,
"Bounds checks skipped"  )

◆ STATISTIC() [3/3]

STATISTIC ( ChecksUnable ,
"Bounds checks unable to add"  )

Variable Documentation

◆ SingleTrapBB

cl::opt< bool > SingleTrapBB("bounds-checking-single-trap", cl::desc("Use one trap block per function")) ( "bounds-checking-single-trap" ,
cl::desc("Use one trap block per function")  )
static

Referenced by addBoundsChecking().