annotate include/llvm/FuzzMutate/RandomIRBuilder.h @ 121:803732b1fca8

LLVM 5.0
author kono
date Fri, 27 Oct 2017 17:07:41 +0900
parents
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===-- Mutator.h - Utils for randomly mutation IR --------------*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 // Provides the Mutator class, which is used to mutate IR for fuzzing.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #ifndef LLVM_FUZZMUTATE_RANDOMIRBUILDER_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #define LLVM_FUZZMUTATE_RANDOMIRBUILDER_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "llvm/ADT/SmallPtrSet.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include "llvm/FuzzMutate/IRMutator.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 #include "llvm/FuzzMutate/Random.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 #include <random>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 namespace llvm {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 using RandomEngine = std::mt19937;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 struct RandomIRBuilder {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 RandomEngine Rand;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 SmallVector<Type *, 16> KnownTypes;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 RandomIRBuilder(int Seed, ArrayRef<Type *> AllowedTypes)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 : Rand(Seed), KnownTypes(AllowedTypes.begin(), AllowedTypes.end()) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 // TODO: Try to make this a bit less of a random mishmash of functions.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 /// Find a "source" for some operation, which will be used in one of the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 /// operation's operands. This either selects an instruction in \c Insts or
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 /// returns some new arbitrary Value.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 Value *findOrCreateSource(BasicBlock &BB, ArrayRef<Instruction *> Insts);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 /// Find a "source" for some operation, which will be used in one of the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 /// operation's operands. This either selects an instruction in \c Insts that
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 /// matches \c Pred, or returns some new Value that matches \c Pred. The
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 /// values in \c Srcs should be source operands that have already been
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 /// selected.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 Value *findOrCreateSource(BasicBlock &BB, ArrayRef<Instruction *> Insts,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 ArrayRef<Value *> Srcs, fuzzerop::SourcePred Pred);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 /// Create some Value suitable as a source for some operation.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 Value *newSource(BasicBlock &BB, ArrayRef<Instruction *> Insts,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 ArrayRef<Value *> Srcs, fuzzerop::SourcePred Pred);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 /// Find a viable user for \c V in \c Insts, which should all be contained in
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 /// \c BB. This may also create some new instruction in \c BB and use that.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 void connectToSink(BasicBlock &BB, ArrayRef<Instruction *> Insts, Value *V);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 /// Create a user for \c V in \c BB.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 void newSink(BasicBlock &BB, ArrayRef<Instruction *> Insts, Value *V);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 Value *findPointer(BasicBlock &BB, ArrayRef<Instruction *> Insts,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 ArrayRef<Value *> Srcs, fuzzerop::SourcePred Pred);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 Type *chooseType(LLVMContext &Context, ArrayRef<Value *> Srcs,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 fuzzerop::SourcePred Pred);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 } // end llvm namespace
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 #endif // LLVM_FUZZMUTATE_RANDOMIRBUILDER_H