40 auto RS = makeSampler<Function *>(IB.
Rand);
42 if (!
F.isDeclaration())
44 mutate(*RS.getSelection(), IB);
57 std::vector<Type *> Types;
58 for (
const auto &Getter : AllowedTypes)
62 auto RS = makeSampler<IRMutationStrategy *>(IB.
Rand);
63 for (
const auto &Strategy : Strategies)
64 RS.sample(Strategy.get(),
65 Strategy->getWeight(CurSize, MaxSize, RS.totalWeight()));
66 auto Strategy = RS.getSelection();
68 Strategy->mutate(M, IB);
86 std::vector<fuzzerop::OpDescriptor> Ops;
99 return Op.SourcePreds[0].matches({}, Src);
111 if (Insts.
size() < 1)
115 size_t IP = uniform<size_t>(IB.
Rand, 0, Insts.
size() - 1);
126 auto OpDesc = chooseOperation(Srcs[0], IB);
131 for (
const auto &Pred :
makeArrayRef(OpDesc->SourcePreds).slice(1))
134 if (
Value *
Op = OpDesc->BuilderFunc(Srcs, Insts[IP])) {
141 uint64_t CurrentWeight) {
143 if (CurrentSize > MaxSize - 200)
144 return CurrentWeight ? CurrentWeight * 100 : 1;
147 int Line = (-2 * CurrentWeight) * (MaxSize - CurrentSize + 1000);
155 auto RS = makeSampler<Instruction *>(IB.
Rand);
158 if (Inst.isTerminator() || Inst.isEHPad() ||
159 Inst.isSwiftError() || isa<PHINode>(Inst))
168 mutate(*RS.getSelection(), IB);
186 auto RS = makeSampler<Value *>(IB.
Rand);
191 if (Pred.matches({}, &*
I))
193 InstsBefore.push_back(&*
I);
196 RS.sample(IB.
newSource(*BB, InstsBefore, {}, Pred), 1);
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void mutate(Function &F, RandomIRBuilder &IB) override
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
Externally visible function.
bool isTerminator() const
void describeFuzzerControlFlowOps(std::vector< fuzzerop::OpDescriptor > &Ops)
Basic Dead Code Elimination pass.
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
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
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
LLVMContext & getContext() const
Get the global data context.
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
void describeFuzzerVectorOps(std::vector< fuzzerop::OpDescriptor > &Ops)
Value * newSource(BasicBlock &BB, ArrayRef< Instruction *> Insts, ArrayRef< Value *> Srcs, fuzzerop::SourcePred Pred)
Create some Value suitable as a source for some operation.
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool isVoidTy() const
Return true if this is 'void'.
Value * findOrCreateSource(BasicBlock &BB, ArrayRef< Instruction *> Insts)
Find a "source" for some operation, which will be used in one of the operation's operands.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
static std::vector< fuzzerop::OpDescriptor > getDefaultOps()
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void describeFuzzerFloatOps(std::vector< fuzzerop::OpDescriptor > &Ops)
ReservoirSampler< ElT, GenT > makeSampler(GenT &RandGen, RangeT &&Items)
static Type * getVoidTy(LLVMContext &C)
static void eliminateDeadCode(Function &F)
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
self_iterator getIterator()
void describeFuzzerPointerOps(std::vector< fuzzerop::OpDescriptor > &Ops)
Pseudo-analysis pass that exposes the PassInstrumentation to pass managers.
void connectToSink(BasicBlock &BB, ArrayRef< Instruction *> Insts, Value *V)
Find a viable user for V in Insts, which should all be contained in BB.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
static SourcePred onlyType(Type *Only)
void describeFuzzerIntOps(std::vector< fuzzerop::OpDescriptor > &Ops)
Getters for the default sets of operations, per general category.
static void createEmptyFunction(Module &M)
virtual void mutate(Module &M, RandomIRBuilder &IB)
void describeFuzzerAggregateOps(std::vector< fuzzerop::OpDescriptor > &Ops)
void mutateModule(Module &M, int Seed, size_t CurSize, size_t MaxSize)
A description of some operation we can build while fuzzing IR.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Analysis pass providing the TargetLibraryInfo.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
static cl::opt< unsigned long long > Seed("rng-seed", cl::value_desc("seed"), cl::Hidden, cl::desc("Seed for the random number generator"), cl::init(0))
inst_range instructions(Function *F)
A container for analyses that lazily runs them and caches their results.
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
const BasicBlock * getParent() const