20 using namespace fuzzerop;
24 return findOrCreateSource(BB, Insts, {},
anyType());
31 auto MatchesPred = [&Srcs, &Pred](
Instruction *Inst) {
32 return Pred.
matches(Srcs, Inst);
36 RS.sample(
nullptr, 1);
39 return newSource(BB, Insts, Srcs, Pred);
45 auto RS = makeSampler<Value *>(Rand);
46 RS.sample(Pred.
generate(Srcs, KnownTypes));
49 Value *Ptr = findPointer(BB, Insts, Srcs, Pred);
53 if (
auto *
I = dyn_cast<Instruction>(Ptr)) {
54 IP = ++
I->getIterator();
55 assert(IP != BB.
end() &&
"guaranteed by the findPointer");
57 auto *NewLoad =
new LoadInst(Ptr,
"L", &*IP);
60 if (Pred.
matches(Srcs, NewLoad))
61 RS.sample(NewLoad, RS.totalWeight());
63 NewLoad->eraseFromParent();
66 assert(!RS.isEmpty() &&
"Failed to generate sources");
67 return RS.getSelection();
71 const Value *Replacement) {
75 case Instruction::GetElementPtr:
76 case Instruction::ExtractElement:
77 case Instruction::ExtractValue:
83 case Instruction::InsertValue:
84 case Instruction::InsertElement:
85 case Instruction::ShuffleVector:
97 auto RS = makeSampler<Use *>(Rand);
98 for (
auto &
I : Insts) {
99 if (isa<IntrinsicInst>(
I))
104 for (
Use &U :
I->operands())
109 RS.sample(
nullptr, 1);
111 if (
Use *
Sink = RS.getSelection()) {
113 unsigned OpNo =
Sink->getOperandNo();
117 newSink(BB, Insts, V);
136 auto IsMatchingPtr = [&Srcs, &Pred](
Instruction *Inst) {
139 if (Inst->isTerminator())
142 if (
auto PtrTy = dyn_cast<PointerType>(Inst->getType())) {
144 if (!PtrTy->getElementType()->isSized() ||
145 !PtrTy->getElementType()->isFirstClassType())
154 return RS.getSelection();
const T & back() const
back - Get the last element.
This class represents lattice values for constants.
Value * findPointer(BasicBlock &BB, ArrayRef< Instruction *> Insts, ArrayRef< Value *> Srcs, fuzzerop::SourcePred Pred)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
An instruction for reading from memory.
A Use represents the edge between a Value definition and its users.
T uniform(GenT &Gen, T Min, T Max)
Return a uniformly distributed random value between Min and Max.
static SourcePred matchFirstType()
Match values that have the same type as the first source.
Value * newSource(BasicBlock &BB, ArrayRef< Instruction *> Insts, ArrayRef< Value *> Srcs, fuzzerop::SourcePred Pred)
Create some Value suitable as a source for some operation.
Type * getType() const
All values are typed, get the type of this value.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static SourcePred anyType()
An instruction for storing to memory.
unsigned getOperandNo() const
Return the operand # of this use in its User.
static bool isCompatibleReplacement(const Instruction *I, const Use &Operand, const Value *Replacement)
Value * findOrCreateSource(BasicBlock &BB, ArrayRef< Instruction *> Insts)
Find a "source" for some operation, which will be used in one of the operation's operands.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM Basic Block Representation.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ReservoirSampler< ElT, GenT > makeSampler(GenT &RandGen, RangeT &&Items)
bool matches(ArrayRef< Value *> Cur, const Value *New)
Returns true if New is compatible for the argument after Cur.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
void connectToSink(BasicBlock &BB, ArrayRef< Instruction *> Insts, Value *V)
Find a viable user for V in Insts, which should all be contained in BB.
std::vector< Constant * > generate(ArrayRef< Value *> Cur, ArrayRef< Type *> BaseTypes)
Generates a list of potential values for the argument after Cur.
A matcher/generator for finding suitable values for the next source in an operation's partially compl...
void setOperand(unsigned i, Value *Val)
void newSink(BasicBlock &BB, ArrayRef< Instruction *> Insts, Value *V)
Create a user for V in BB.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
an instruction to allocate memory on the stack