18#ifndef LLVM_FUZZMUTATE_IRMUTATOR_H
19#define LLVM_FUZZMUTATE_IRMUTATOR_H
31struct RandomIRBuilder;
64 std::vector<TypeGetter> AllowedTypes;
65 std::vector<std::unique_ptr<IRMutationStrategy>> Strategies;
69 std::vector<std::unique_ptr<IRMutationStrategy>> &&Strategies)
70 : AllowedTypes(
std::
move(AllowedTypes)),
71 Strategies(
std::
move(Strategies)) {}
90 std::vector<fuzzerop::OpDescriptor> Operations;
92 std::optional<fuzzerop::OpDescriptor> chooseOperation(
Value *Src,
98 : Operations(
std::
move(Operations)) {}
103 return Operations.size();
152 enum CFGToSink { Return, DirectSink, SinkOrSelfLoop, EndOfCFGToLink };
210 LLVMContext &Context);
225 LLVMContext &Context);
DenseMap< Block *, BlockRelaxAux > Blocks
Machine Check Debug Module
static ManagedStatic< cl::opt< uint64_t >, CreateSeed > Seed
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
Base class for describing how to mutate a module.
virtual void mutate(Instruction &I, RandomIRBuilder &IB)
virtual uint64_t getWeight(size_t CurrentSize, size_t MaxSize, uint64_t CurrentWeight)=0
Provide a weight to bias towards choosing this strategy for a mutation.
virtual ~IRMutationStrategy()=default
virtual void mutate(Module &M, RandomIRBuilder &IB)
Entry point for configuring and running IR mutations.
IRMutator(std::vector< TypeGetter > &&AllowedTypes, std::vector< std::unique_ptr< IRMutationStrategy > > &&Strategies)
void mutateModule(Module &M, int Seed, size_t MaxSize)
Mutate given module.
static size_t getModuleSize(const Module &M)
Calculate the size of module as the number of objects in it, i.e.
Strategy that injects operations into the function.
static std::vector< fuzzerop::OpDescriptor > getDefaultOps()
uint64_t getWeight(size_t CurrentSize, size_t MaxSize, uint64_t CurrentWeight) override
Provide a weight to bias towards choosing this strategy for a mutation.
void mutate(Function &F, RandomIRBuilder &IB) override
InjectorIRStrategy(std::vector< fuzzerop::OpDescriptor > &&Operations)
Strategy to split a random block and insert a random CFG in between.
void mutate(BasicBlock &BB, RandomIRBuilder &IB) override
uint64_t getWeight(size_t CurrentSize, size_t MaxSize, uint64_t CurrentWeight) override
Provide a weight to bias towards choosing this strategy for a mutation.
InsertCFGStrategy(uint64_t MNC=8)
Strategy that generates new function calls and inserts function signatures to the modules.
uint64_t getWeight(size_t CurrentSize, size_t MaxSize, uint64_t CurrentWeight) override
Provide a weight to bias towards choosing this strategy for a mutation.
void mutate(BasicBlock &BB, RandomIRBuilder &IB) override
Strategy to insert PHI Nodes at the head of each basic block.
uint64_t getWeight(size_t CurrentSize, size_t MaxSize, uint64_t CurrentWeight) override
Provide a weight to bias towards choosing this strategy for a mutation.
void mutate(BasicBlock &BB, RandomIRBuilder &IB) override
Strategy that deletes instructions when the Module is too large.
uint64_t getWeight(size_t CurrentSize, size_t MaxSize, uint64_t CurrentWeight) override
Provide a weight to bias towards choosing this strategy for a mutation.
void mutate(Function &F, RandomIRBuilder &IB) override
Strategy that modifies instruction attributes and operands.
void mutate(Instruction &Inst, RandomIRBuilder &IB) override
uint64_t getWeight(size_t CurrentSize, size_t MaxSize, uint64_t CurrentWeight) override
Provide a weight to bias towards choosing this strategy for a mutation.
This is an important class for using LLVM in a threaded context.
A Module instance is used to store all the information related to an LLVM module.
Strategy to randomly select a block and shuffle the operations without affecting data dependency.
uint64_t getWeight(size_t CurrentSize, size_t MaxSize, uint64_t CurrentWeight) override
Provide a weight to bias towards choosing this strategy for a mutation.
void mutate(BasicBlock &BB, RandomIRBuilder &IB) override
Strategy to select a random instruction and add a new sink (user) to it to increate data dependency.
void mutate(Function &F, RandomIRBuilder &IB) override
uint64_t getWeight(size_t CurrentSize, size_t MaxSize, uint64_t CurrentWeight) override
Provide a weight to bias towards choosing this strategy for a mutation.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
std::unique_ptr< Module > parseAndVerify(const uint8_t *Data, size_t Size, LLVMContext &Context)
Try to parse module and verify it.
std::function< Type *(LLVMContext &)> TypeGetter
std::unique_ptr< Module > parseModule(const uint8_t *Data, size_t Size, LLVMContext &Context)
Fuzzer friendly interface for the llvm bitcode parser.
size_t writeModule(const Module &M, uint8_t *Dest, size_t MaxSize)
Fuzzer friendly interface for the llvm bitcode printer.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.