LLVM  15.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/ArrayRef.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include <random>
19 
20 namespace llvm {
21 class BasicBlock;
22 class Instruction;
23 class LLVMContext;
24 class Type;
25 class Value;
26 namespace fuzzerop {
27 class SourcePred;
28 }
29 
30 using RandomEngine = std::mt19937;
31 
35 
37  : Rand(Seed), KnownTypes(AllowedTypes.begin(), AllowedTypes.end()) {}
38 
39  // TODO: Try to make this a bit less of a random mishmash of functions.
40 
41  /// Find a "source" for some operation, which will be used in one of the
42  /// operation's operands. This either selects an instruction in \c Insts or
43  /// returns some new arbitrary Value.
45  /// Find a "source" for some operation, which will be used in one of the
46  /// operation's operands. This either selects an instruction in \c Insts that
47  /// matches \c Pred, or returns some new Value that matches \c Pred. The
48  /// values in \c Srcs should be source operands that have already been
49  /// selected.
52  /// Create some Value suitable as a source for some operation.
55  /// Find a viable user for \c V in \c Insts, which should all be contained in
56  /// \c BB. This may also create some new instruction in \c BB and use that.
58  /// Create a user for \c V in \c BB.
64 };
65 
66 } // end llvm namespace
67 
68 #endif // LLVM_FUZZMUTATE_RANDOMIRBUILDER_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: AddressRanges.h:17
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:1185
llvm::RandomIRBuilder::findPointer
Value * findPointer(BasicBlock &BB, ArrayRef< Instruction * > Insts, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred)
Definition: RandomIRBuilder.cpp:136
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
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::RandomIRBuilder::KnownTypes
SmallVector< Type *, 16 > KnownTypes
Definition: RandomIRBuilder.h:34
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
ArrayRef.h
TemplateParamKind::Type
@ Type
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:98
llvm::RandomIRBuilder::newSink
void newSink(BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
Create a user for V in BB.
Definition: RandomIRBuilder.cpp:123
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
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:36
llvm::RandomIRBuilder
Definition: RandomIRBuilder.h:32
llvm::RandomEngine
std::mt19937 RandomEngine
Definition: RandomIRBuilder.h:30
llvm::fuzzerop::SourcePred
A matcher/generator for finding suitable values for the next source in an operation's partially compl...
Definition: OpDescriptor.h:42
llvm::RandomIRBuilder::Rand
RandomEngine Rand
Definition: RandomIRBuilder.h:33
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
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
SmallVector.h
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