34#define DEBUG_TYPE "lower-allow-check"
37STATISTIC(NumChecksRemoved,
"Number of removed checks");
44 :
Kind(
"Kind",
II->getArgOperand(0)),
55 <<
"Removed check: Kind=" << Info.Kind <<
" F=" << Info.F
62 <<
"Allowed check: Kind=" << Info.Kind <<
" F=" << Info.F
70 const InstrumentationOptions &CLOpts = InstrumentationOptions::Global;
78 auto GetPSI = [&AM, &
F, PSI = std::optional<ProfileSummaryInfo *>()]()
mutable
80 if (!PSI.has_value()) {
95 std::unique_ptr<RandomNumberGenerator> Rng;
99 Rng =
F.getParent()->createRNG(
F.getName());
104 if (CLOpts.lower_allow_check_percentile_cutoff_hot)
105 return *CLOpts.lower_allow_check_percentile_cutoff_hot;
106 else if (
II->getIntrinsicID() == Intrinsic::allow_ubsan_check) {
108 if (Kind->getZExtValue() < Opts.
cutoffs.size())
109 return Opts.
cutoffs[Kind->getZExtValue()];
110 }
else if (
II->getIntrinsicID() == Intrinsic::allow_runtime_check) {
117 auto ShouldRemoveHot = [&](
const BasicBlock &BB,
unsigned int cutoff) {
118 if (cutoff == 1000000)
122 cutoff, GetBFI().getBlockProfileCount(&BB).value_or(0));
125 auto ShouldRemoveRandom = [&]() {
126 return CLOpts.lower_allow_check_random_rate &&
127 !std::bernoulli_distribution(*CLOpts.lower_allow_check_random_rate)(
132 unsigned int cutoff = GetCutoff(
II);
133 return ShouldRemoveRandom() || ShouldRemoveHot(*(
II->getParent()), cutoff);
140 auto ID =
II->getIntrinsicID();
142 case Intrinsic::allow_ubsan_check:
143 case Intrinsic::allow_runtime_check: {
153 case Intrinsic::allow_sanitize_address:
155 {
II,
F.hasFnAttribute(Attribute::SanitizeAddress)});
157 case Intrinsic::allow_sanitize_thread:
159 {
II,
F.hasFnAttribute(Attribute::SanitizeThread)});
161 case Intrinsic::allow_sanitize_memory:
163 {
II,
F.hasFnAttribute(Attribute::SanitizeMemory)});
165 case Intrinsic::allow_sanitize_hwaddress:
167 {
II,
F.hasFnAttribute(Attribute::SanitizeHWAddress)});
174 for (
auto [
I, V] : ReplaceWithValue) {
179 I->eraseFromParent();
182 return !ReplaceWithValue.
empty();
187 if (
F.isDeclaration())
198 const InstrumentationOptions &CLOpts = InstrumentationOptions::Global;
199 return CLOpts.lower_allow_check_random_rate ||
200 CLOpts.lower_allow_check_percentile_cutoff_hot;
205 static_cast<PassInfoMixin<LowerAllowCheckPass> *
>(
this)->
printPipeline(
206 OS, MapClassName2PassName);
217 for (
unsigned int cutoff : Opts.cutoffs) {
219 OS << LS <<
"cutoffs[" << i <<
"]=" << cutoff;
222 if (Opts.runtime_check)
223 OS << LS <<
"runtime_check=" << Opts.runtime_check;
ReachingDefInfo InstSet & ToRemove
Expand Atomic instructions
static const Function * getParent(const Value *V)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
static void emitRemark(IntrinsicInst *II, OptimizationRemarkEmitter &ORE, bool Removed)
static bool lowerAllowChecks(Function &F, FunctionAnalysisManager &AM, const LowerAllowCheckPass::Options &Opts)
This file provides the interface for the pass responsible for removing expensive ubsan checks.
uint64_t IntrinsicInst * II
static StringRef getName(Value *V)
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Represents analyses that only rely on functions' control flow.
static LLVM_ABI ConstantInt * getBool(LLVMContext &Context, bool V)
A wrapper class for inspecting calls to intrinsic functions.
A helper class to return the specified delimiter string after the first invocation of operator String...
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
static LLVM_ABI bool IsRequested()
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Analysis providing profile information.
LLVM_ABI bool isHotCountNthPercentile(int PercentileCutoff, uint64_t C) const
Returns true if count C is considered hot with regard to a given hot percentile cutoff value.
A random number generator.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
unsigned int runtime_check
std::vector< unsigned int > cutoffs