-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC][Fuzzer] Extract CreateGateBranch method. #117236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFC][Fuzzer] Extract CreateGateBranch method. #117236
Conversation
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-compiler-rt-sanitizer Author: None (thetruestblue) ChangesA Pre-commit for use in adding gated tracing callbacks support to trace-cmp #113227 rdar://135404160 Patch by: Andrea Fioraldi Full diff: https://github.com/llvm/llvm-project/pull/117236.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 34006bfda96c5f..4689cb29236f06 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -244,12 +244,14 @@ class ModuleSanitizerCoverage {
void InjectTraceForSwitch(Function &F,
ArrayRef<Instruction *> SwitchTraceTargets);
bool InjectCoverage(Function &F, ArrayRef<BasicBlock *> AllBlocks,
- bool IsLeafFunc = true);
+ Value *&FunctionGateCmp, bool IsLeafFunc = true);
GlobalVariable *CreateFunctionLocalArrayInSection(size_t NumElements,
Function &F, Type *Ty,
const char *Section);
GlobalVariable *CreatePCArray(Function &F, ArrayRef<BasicBlock *> AllBlocks);
void CreateFunctionLocalArrays(Function &F, ArrayRef<BasicBlock *> AllBlocks);
+ Instruction *CreateGateBranch(Function &F, Value *&FunctionGateCmp,
+ Instruction *I);
Value *CreateFunctionLocalGateCmp(IRBuilder<> &IRB);
void InjectCoverageAtBlock(Function &F, BasicBlock &BB, size_t Idx,
Value *&FunctionGateCmp, bool IsLeafFunc = true);
@@ -723,7 +725,8 @@ void ModuleSanitizerCoverage::instrumentFunction(Function &F) {
if (Options.CollectControlFlow)
createFunctionControlFlow(F);
- InjectCoverage(F, BlocksToInstrument, IsLeafFunc);
+ Value *FunctionGateCmp = nullptr;
+ InjectCoverage(F, BlocksToInstrument, FunctionGateCmp, IsLeafFunc);
InjectCoverageForIndirectCalls(F, IndirCalls);
InjectTraceForCmp(F, CmpTraceTargets);
InjectTraceForSwitch(F, SwitchTraceTargets);
@@ -815,12 +818,30 @@ Value *ModuleSanitizerCoverage::CreateFunctionLocalGateCmp(IRBuilder<> &IRB) {
return Cmp;
}
+Instruction *ModuleSanitizerCoverage::CreateGateBranch(Function &F,
+ Value *&FunctionGateCmp,
+ Instruction *IP) {
+ if (!FunctionGateCmp) {
+ // Create this in the entry block
+ BasicBlock &BB = F.getEntryBlock();
+ BasicBlock::iterator IP = BB.getFirstInsertionPt();
+ IP = PrepareToSplitEntryBlock(BB, IP);
+ IRBuilder<> EntryIRB(&*IP);
+ FunctionGateCmp = CreateFunctionLocalGateCmp(EntryIRB);
+ }
+ // Set the branch weights in order to minimize the price paid when the
+ // gate is turned off, allowing the default enablement of this
+ // instrumentation with as little of a performance cost as possible
+ auto Weights = MDBuilder(*C).createBranchWeights(1, 100000);
+ return SplitBlockAndInsertIfThen(FunctionGateCmp, IP, false, Weights);
+}
+
bool ModuleSanitizerCoverage::InjectCoverage(Function &F,
ArrayRef<BasicBlock *> AllBlocks,
+ Value *&FunctionGateCmp,
bool IsLeafFunc) {
if (AllBlocks.empty()) return false;
CreateFunctionLocalArrays(F, AllBlocks);
- Value *FunctionGateCmp = nullptr;
for (size_t i = 0, N = AllBlocks.size(); i < N; i++)
InjectCoverageAtBlock(F, *AllBlocks[i], i, FunctionGateCmp, IsLeafFunc);
return true;
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
fixup....
79189bc
to
2840c8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM.
The other change Vitaly asked before ( changing to use .createUnlikelyBranchWeights()) should I think go in the followup PR, as having it here would make it not exactly a NFC
A Pre-commit for use in adding gated tracing callbacks support to trace-cmp #113227
rdar://135404160
Patch by: Andrea Fioraldi