LLVM  8.0.0svn
RandomIRBuilder.h
Go to the documentation of this file.
1 //===-- Mutator.h - Utils for randomly mutation IR --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Provides the Mutator class, which is used to mutate IR for fuzzing.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_FUZZMUTATE_RANDOMIRBUILDER_H
15 #define LLVM_FUZZMUTATE_RANDOMIRBUILDER_H
16 
17 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/FuzzMutate/Random.h"
20 #include <random>
21 
22 namespace llvm {
23 
24 using RandomEngine = std::mt19937;
25 
29 
31  : Rand(Seed), KnownTypes(AllowedTypes.begin(), AllowedTypes.end()) {}
32 
33  // TODO: Try to make this a bit less of a random mishmash of functions.
34 
35  /// Find a "source" for some operation, which will be used in one of the
36  /// operation's operands. This either selects an instruction in \c Insts or
37  /// returns some new arbitrary Value.
39  /// Find a "source" for some operation, which will be used in one of the
40  /// operation's operands. This either selects an instruction in \c Insts that
41  /// matches \c Pred, or returns some new Value that matches \c Pred. The
42  /// values in \c Srcs should be source operands that have already been
43  /// selected.
46  /// Create some Value suitable as a source for some operation.
49  /// Find a viable user for \c V in \c Insts, which should all be contained in
50  /// \c BB. This may also create some new instruction in \c BB and use that.
52  /// Create a user for \c V in \c BB.
53  void newSink(BasicBlock &BB, ArrayRef<Instruction *> Insts, Value *V);
58 };
59 
60 } // end llvm namespace
61 
62 #endif // LLVM_FUZZMUTATE_RANDOMIRBUILDER_H
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:259
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:250
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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:33
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:58
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
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:847
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:44
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:73
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))