LLVM  14.0.0git
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.
57 };
58 
59 } // end llvm namespace
60 
61 #endif // LLVM_FUZZMUTATE_RANDOMIRBUILDER_H
IRMutator.h
llvm::RandomIRBuilder::findOrCreateSource
Value * findOrCreateSource(BasicBlock &BB, ArrayRef< Instruction * > Insts)
Find a "source" for some operation, which will be used in one of the operation's operands.
Definition: RandomIRBuilder.cpp:21
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::RandomIRBuilder::chooseType
Type * chooseType(LLVMContext &Context, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred)
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::RandomIRBuilder::findPointer
Value * findPointer(BasicBlock &BB, ArrayRef< Instruction * > Insts, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred)
Definition: RandomIRBuilder.cpp:133
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:235
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:226
Context
ManagedStatic< detail::RecordContext > Context
Definition: Record.cpp:96
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
SmallPtrSet.h
llvm::RandomIRBuilder::KnownTypes
SmallVector< Type *, 16 > KnownTypes
Definition: RandomIRBuilder.h:27
Seed
static ManagedStatic< cl::opt< uint64_t >, CreateSeed > Seed
Definition: RandomNumberGenerator.cpp:40
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::RandomIRBuilder::connectToSink
void connectToSink(BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
Find a viable user for V in Insts, which should all be contained in BB.
Definition: RandomIRBuilder.cpp:95
llvm::RandomIRBuilder::newSink
void newSink(BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
Create a user for V in BB.
Definition: RandomIRBuilder.cpp:120
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::RandomIRBuilder::RandomIRBuilder
RandomIRBuilder(int Seed, ArrayRef< Type * > AllowedTypes)
Definition: RandomIRBuilder.h:29
llvm::RandomIRBuilder
Definition: RandomIRBuilder.h:25
llvm::RandomEngine
std::mt19937 RandomEngine
Definition: RandomIRBuilder.h:23
Random.h
llvm::fuzzerop::SourcePred
A matcher/generator for finding suitable values for the next source in an operation's partially compl...
Definition: OpDescriptor.h:43
llvm::RandomIRBuilder::Rand
RandomEngine Rand
Definition: RandomIRBuilder.h:26
llvm::RandomIRBuilder::newSource
Value * newSource(BasicBlock &BB, ArrayRef< Instruction * > Insts, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred)
Create some Value suitable as a source for some operation.
Definition: RandomIRBuilder.cpp:41
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::Value
LLVM Value Representation.
Definition: Value.h:74