[PATCH] D153387: [FuzzMutate] Allow subclass of InsertFunctionStrategy to select function
Zhenkai Weng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 20 17:13:21 PDT 2023
oakrc created this revision.
oakrc added a reviewer: Peter.
Herald added a subscriber: hiraditya.
Herald added a project: All.
oakrc requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This revision allows subclasses to customize which function is used in
`InsertFunctionStrategy::mutate()`. This is useful for new custom strategies
that may insert a specific kind of function (e.g. intrinsics) but don't
otherwise need to modify how the function is called. Now instead of rewriting
`mutate()`, such new strategy only needs to override `chooseFunction()`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153387
Files:
llvm/include/llvm/FuzzMutate/IRMutator.h
llvm/lib/FuzzMutate/IRMutator.cpp
Index: llvm/lib/FuzzMutate/IRMutator.cpp
===================================================================
--- llvm/lib/FuzzMutate/IRMutator.cpp
+++ llvm/lib/FuzzMutate/IRMutator.cpp
@@ -356,16 +356,19 @@
return tmp;
}
-void InsertFunctionStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
- Module *M = BB.getParent()->getParent();
+Function *InsertFunctionStrategy::chooseFunction(Module *M, RandomIRBuilder &IB) {
// If nullptr is selected, we will create a new function declaration.
SmallVector<Function *, 32> Functions({nullptr});
for (Function &F : M->functions()) {
Functions.push_back(&F);
}
-
auto RS = makeSampler(IB.Rand, Functions);
- Function *F = RS.getSelection();
+ return RS.getSelection();
+}
+
+void InsertFunctionStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
+ Module *M = BB.getParent()->getParent();
+ Function *F = chooseFunction(M, IB);
// Some functions accept metadata type or token type as arguments.
// We don't call those functions for now.
// For example, `@llvm.dbg.declare(metadata, metadata, metadata)`
Index: llvm/include/llvm/FuzzMutate/IRMutator.h
===================================================================
--- llvm/include/llvm/FuzzMutate/IRMutator.h
+++ llvm/include/llvm/FuzzMutate/IRMutator.h
@@ -143,6 +143,14 @@
using IRMutationStrategy::mutate;
void mutate(BasicBlock &BB, RandomIRBuilder &IB) override;
+
+protected:
+ /// @brief Chooses a function to call from the given module
+ /// @param M module from which a function is selected
+ /// @param IB random IR builder
+ /// @return the function to call, or nullptr to create a new function
+ /// declaration
+ virtual Function *chooseFunction(Module *M, RandomIRBuilder &IB);
};
/// Strategy to split a random block and insert a random CFG in between.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153387.533083.patch
Type: text/x-patch
Size: 1832 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230621/9c671f15/attachment.bin>
More information about the llvm-commits
mailing list