annotate include/llvm/FuzzMutate/RandomIRBuilder.h @ 147:c2174574ed3a

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