20using namespace fuzzerop;
32 auto MatchesPred = [&Srcs, &Pred](
Instruction *Inst) {
33 return Pred.
matches(Srcs, Inst);
37 RS.sample(
nullptr, 1);
40 return newSource(BB, Insts, Srcs, Pred, allowConstant);
47 auto RS = makeSampler<Value *>(
Rand);
55 if (
auto *
I = dyn_cast<Instruction>(
Ptr)) {
56 IP = ++
I->getIterator();
57 assert(IP != BB.
end() &&
"guaranteed by the findPointer");
60 Type *AccessTy =
Ptr->getType()->isOpaquePointerTy()
61 ? RS.getSelection()->getType()
62 :
Ptr->getType()->getNonOpaquePointerElementType();
63 auto *NewLoad =
new LoadInst(AccessTy,
Ptr,
"L", &*IP);
66 if (Pred.
matches(Srcs, NewLoad))
67 RS.sample(NewLoad, RS.totalWeight());
69 NewLoad->eraseFromParent();
72 Value *newSrc = RS.getSelection();
76 if (!allowConstant && isa<Constant>(newSrc)) {
88 newSrc =
new LoadInst(Ty, Alloca,
"L", &BB);
95 const Value *Replacement) {
99 switch (
I->getOpcode()) {
100 case Instruction::GetElementPtr:
101 case Instruction::ExtractElement:
102 case Instruction::ExtractValue:
108 case Instruction::InsertValue:
109 case Instruction::InsertElement:
110 case Instruction::ShuffleVector:
117 case Instruction::Switch:
118 case Instruction::Br:
130 auto RS = makeSampler<Use *>(
Rand);
131 for (
auto &
I : Insts) {
132 if (isa<IntrinsicInst>(
I))
137 for (
Use &U :
I->operands())
142 RS.sample(
nullptr, 1);
144 if (
Use *Sink = RS.getSelection()) {
145 User *U = Sink->getUser();
146 unsigned OpNo = Sink->getOperandNo();
147 U->setOperand(OpNo, V);
169 auto IsMatchingPtr = [&Srcs, &Pred](
Instruction *Inst) {
172 if (Inst->isTerminator())
175 if (
auto *PtrTy = dyn_cast<PointerType>(Inst->getType())) {
176 if (PtrTy->isOpaque())
190 return RS.getSelection();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isCompatibleReplacement(const Instruction *I, const Use &Operand, const Value *Replacement)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
an instruction to allocate memory on the stack
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & back() const
back - Get the last element.
LLVM Basic Block Representation.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
A parsed version of the target data layout string in and methods for querying it.
Module * getParent()
Get the module that this global value is contained inside of...
An instruction for reading from memory.
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 storing to memory.
The instances of the Type class are immutable: once they are created, they are never changed.
Type * getNonOpaquePointerElementType() const
Only use this method in code that is not reachable with opaque pointers, or part of deprecated method...
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
unsigned getOperandNo() const
Return the operand # of this use in its User.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
A matcher/generator for finding suitable values for the next source in an operation's partially compl...
bool matches(ArrayRef< Value * > Cur, const Value *New)
Returns true if New is compatible for the argument after Cur.
std::vector< Constant * > generate(ArrayRef< Value * > Cur, ArrayRef< Type * > BaseTypes)
Generates a list of potential values for the argument after Cur.
static SourcePred matchFirstType()
Match values that have the same type as the first source.
static SourcePred anyType()
This is an optimization pass for GlobalISel generic memory operations.
ReservoirSampler< ElT, GenT > makeSampler(GenT &RandGen, RangeT &&Items)
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...
T uniform(GenT &Gen, T Min, T Max)
Return a uniformly distributed random value between Min and Max.
SmallVector< Type *, 16 > KnownTypes
Value * findOrCreateSource(BasicBlock &BB, ArrayRef< Instruction * > Insts)
Find a "source" for some operation, which will be used in one of the operation's operands.
Value * newSource(BasicBlock &BB, ArrayRef< Instruction * > Insts, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred, bool allowConstant=true)
Create some Value suitable as a source for some operation.
void newSink(BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
Create a user for V in BB.
Value * findPointer(BasicBlock &BB, ArrayRef< Instruction * > Insts, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred)
void connectToSink(BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
Find a viable user for V in Insts, which should all be contained in BB.
Type * randomType()
Return a uniformly choosen type from AllowedTypes.