LLVM  9.0.0svn
RandomIRBuilder.h
Go to the documentation of this file.
1 //===- RandomIRBuilder.h - Utils for randomly mutation IR -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Provides the Mutator class, which is used to mutate IR for fuzzing.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_FUZZMUTATE_RANDOMIRBUILDER_H
14 #define LLVM_FUZZMUTATE_RANDOMIRBUILDER_H
15 
16 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/FuzzMutate/Random.h"
19 #include <random>
20 
21 namespace llvm {
22 
23 using RandomEngine = std::mt19937;
24 
28 
30  : Rand(Seed), KnownTypes(AllowedTypes.begin(), AllowedTypes.end()) {}
31 
32  // TODO: Try to make this a bit less of a random mishmash of functions.
33 
34  /// Find a "source" for some operation, which will be used in one of the
35  /// operation's operands. This either selects an instruction in \c Insts or
36  /// returns some new arbitrary Value.
38  /// Find a "source" for some operation, which will be used in one of the
39  /// operation's operands. This either selects an instruction in \c Insts that
40  /// matches \c Pred, or returns some new Value that matches \c Pred. The
41  /// values in \c Srcs should be source operands that have already been
42  /// selected.
45  /// Create some Value suitable as a source for some operation.
48  /// Find a viable user for \c V in \c Insts, which should all be contained in
49  /// \c BB. This may also create some new instruction in \c BB and use that.
51  /// Create a user for \c V in \c BB.
52  void newSink(BasicBlock &BB, ArrayRef<Instruction *> Insts, Value *V);
57 };
58 
59 } // end llvm namespace
60 
61 #endif // LLVM_FUZZMUTATE_RANDOMIRBUILDER_H
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static cl::opt< uint64_t > Seed("rng-seed", cl::value_desc("seed"), cl::Hidden, cl::desc("Seed for the random number generator"), cl::init(0))
Value * findPointer(BasicBlock &BB, ArrayRef< Instruction *> Insts, ArrayRef< Value *> Srcs, fuzzerop::SourcePred Pred)
SmallVector< Type *, 16 > KnownTypes
Value * newSource(BasicBlock &BB, ArrayRef< Instruction *> Insts, ArrayRef< Value *> Srcs, fuzzerop::SourcePred Pred)
Create some Value suitable as a source for some operation.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
RandomIRBuilder(int Seed, ArrayRef< Type *> AllowedTypes)
Value * findOrCreateSource(BasicBlock &BB, ArrayRef< Instruction *> Insts)
Find a "source" for some operation, which will be used in one of the operation&#39;s operands.
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:64
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 &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
Type * chooseType(LLVMContext &Context, ArrayRef< Value *> Srcs, fuzzerop::SourcePred Pred)
A matcher/generator for finding suitable values for the next source in an operation&#39;s partially compl...
Definition: OpDescriptor.h:43
void newSink(BasicBlock &BB, ArrayRef< Instruction *> Insts, Value *V)
Create a user for V in BB.
std::mt19937 RandomEngine
LLVM Value Representation.
Definition: Value.h:72