LLVM: lib/FuzzMutate/Operations.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
14
15using namespace llvm;
16using namespace fuzzerop;
17
32
43}
44
51
68}
69
71 std::vectorfuzzerop::OpDescriptor &Ops) {
73}
74
76 std::vectorfuzzerop::OpDescriptor &Ops) {
78}
79
82}
83
86}
87
89 std::vectorfuzzerop::OpDescriptor &Ops) {
92}
93
98}
99
103 };
104 return {Weight,
106 buildOp};
107}
108
112 };
114}
115
120 };
121 switch (Op) {
122 case Instruction::Add:
123 case Instruction::Sub:
124 case Instruction::Mul:
125 case Instruction::SDiv:
126 case Instruction::UDiv:
127 case Instruction::SRem:
128 case Instruction::URem:
129 case Instruction::Shl:
130 case Instruction::LShr:
131 case Instruction::AShr:
132 case Instruction::And:
133 case Instruction::Or:
134 case Instruction::Xor:
136 case Instruction::FAdd:
137 case Instruction::FSub:
138 case Instruction::FMul:
139 case Instruction::FDiv:
140 case Instruction::FRem:
142 case Instruction::BinaryOpsEnd:
144 }
146}
147
153 return CmpInst::Create(CmpOp, Pred, Srcs[0], Srcs[1], "C", InsertPt);
154 };
155
156 switch (CmpOp) {
157 case Instruction::ICmp:
159 case Instruction::FCmp:
161 default:
163 }
164}
165
170 BasicBlock *Next = Block->splitBasicBlock(InsertPt, "BB");
171
172
173 if (Block->isEHPad())
174 return nullptr;
175
176
177
178 if (Block != &Block->getParent()->getEntryBlock()) {
180 Block->getTerminator()->getIterator());
181 Block->getTerminator()->eraseFromParent();
182
183
184
185
188 }
189 return nullptr;
190 };
192 return V->getType()->isIntegerTy(1);
193 },
194 std::nullopt};
195 return {Weight, {isInt1Ty}, buildSplitBlock};
196}
197
200
201
202 Type *Ty = Srcs[1]->getType();
205 };
206
207
208
211 std::nullopt);
213}
214
216 assert(T->isAggregateType() && "Not a struct or array");
217 if (isa(T))
218 return T->getStructNumElements();
219 return T->getArrayNumElements();
220}
221
224 if (auto *CI = dyn_cast(V))
226 return true;
227 return false;
228 };
230 std::vector<Constant *> Result;
233
234 Result.push_back(ConstantInt::get(Int32Ty, 0));
235 if (N > 1)
236 Result.push_back(ConstantInt::get(Int32Ty, N - 1));
237 if (N > 2)
238 Result.push_back(ConstantInt::get(Int32Ty, N / 2));
239 return Result;
240 };
241 return {Pred, Make};
242}
243
247
248 unsigned Idx = cast(Srcs[1])->getZExtValue();
250 };
251
253}
254
257 if (auto *ArrayT = dyn_cast(Cur[0]->getType()))
258 return V->getType() == ArrayT->getElementType();
259
260 auto *STy = cast(Cur[0]->getType());
261 for (int I = 0, E = STy->getNumElements(); I < E; ++I)
262 if (STy->getTypeAtIndex(I) == V->getType())
263 return true;
264 return false;
265 };
267 if (auto *ArrayT = dyn_cast(Cur[0]->getType()))
269
270 std::vector<Constant *> Result;
271 auto *STy = cast(Cur[0]->getType());
272 for (int I = 0, E = STy->getNumElements(); I < E; ++I)
274 return Result;
275 };
276 return {Pred, Make};
277}
278
281 if (auto *CI = dyn_cast(V))
282 if (CI->getBitWidth() == 32) {
284 CI->getZExtValue());
285 return Indexed == Cur[1]->getType();
286 }
287 return false;
288 };
290 std::vector<Constant *> Result;
292 auto *BaseTy = Cur[0]->getType();
293 int I = 0;
296 Result.push_back(ConstantInt::get(Int32Ty, I));
297 ++I;
298 }
299 return Result;
300 };
301 return {Pred, Make};
302}
303
306
307 unsigned Idx = cast(Srcs[2])->getZExtValue();
309 };
310 return {
311 Weight,
313 buildInsert};
314}
315
320 };
321
323}
324
328 };
329
330 return {Weight,
332 buildInsert};
333}
334
338 };
340 auto *FirstTy = cast(Cur[0]->getType());
342
343
344 return std::vector<Constant *>{
345 PoisonValue::get(VectorType::get(Int32Ty, FirstTy->getElementCount()))};
346 };
347 return {Pred, Make};
348}
349
353 return new ShuffleVectorInst(Srcs[0], Srcs[1], Srcs[2], "S", InsertPt);
354 };
355 return {Weight,
357 buildShuffle};
358}
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static SourcePred validShuffleVectorIndex()
static uint64_t getAggregateNumElements(Type *T)
static SourcePred validExtractValueIndex()
static SourcePred matchScalarInAggregate()
static SourcePred validInsertValueIndex()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static SymbolRef::Type getType(const Symbol *Sym)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ FCMP_ULT
1 1 0 0 True if unordered or less than
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ ICMP_ULT
unsigned less than
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
@ ICMP_SGE
signed greater or equal
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
@ ICMP_ULE
unsigned less or equal
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
static CmpInst * Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
This class represents an Operation in the Expression.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, Instruction *MDFrom=nullptr)
This instruction constructs a fixed permutation of two input vectors.
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
The instances of the Type class are immutable: once they are created, they are never changed.
static IntegerType * getInt32Ty(LLVMContext &C)
static UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
LLVM Value Representation.
A matcher/generator for finding suitable values for the next source in an operation's partially compl...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static SourcePred matchFirstLengthWAnyType()
OpDescriptor extractValueDescriptor(unsigned Weight)
OpDescriptor splitBlockDescriptor(unsigned Weight)
static SourcePred anyFloatOrVecFloatType()
static SourcePred sizedPtrType()
OpDescriptor fnegDescriptor(unsigned Weight)
void makeConstantsWithType(Type *T, std::vector< Constant * > &Cs)
OpDescriptor cmpOpDescriptor(unsigned Weight, Instruction::OtherOps CmpOp, CmpInst::Predicate Pred)
static SourcePred anyAggregateType()
OpDescriptor extractElementDescriptor(unsigned Weight)
OpDescriptor insertValueDescriptor(unsigned Weight)
OpDescriptor shuffleVectorDescriptor(unsigned Weight)
static SourcePred anyIntType()
static SourcePred matchScalarOfFirstType()
Match values that have the first source's scalar type.
OpDescriptor selectDescriptor(unsigned Weight)
Descriptors for individual operations.
static SourcePred anyIntOrVecIntType()
static SourcePred anyVectorType()
static SourcePred boolOrVecBoolType()
OpDescriptor insertElementDescriptor(unsigned Weight)
static SourcePred matchFirstType()
Match values that have the same type as the first source.
OpDescriptor binOpDescriptor(unsigned Weight, Instruction::BinaryOps Op)
OpDescriptor gepDescriptor(unsigned Weight)
static SourcePred matchSecondType()
Match values that have the same type as the first source.
This is an optimization pass for GlobalISel generic memory operations.
void describeFuzzerIntOps(std::vector< fuzzerop::OpDescriptor > &Ops)
Getters for the default sets of operations, per general category.
void describeFuzzerOtherOps(std::vector< fuzzerop::OpDescriptor > &Ops)
void describeFuzzerAggregateOps(std::vector< fuzzerop::OpDescriptor > &Ops)
void describeFuzzerUnaryOperations(std::vector< fuzzerop::OpDescriptor > &Ops)
void describeFuzzerVectorOps(std::vector< fuzzerop::OpDescriptor > &Ops)
DWARFExpression::Operation Op
void describeFuzzerFloatOps(std::vector< fuzzerop::OpDescriptor > &Ops)
void describeFuzzerControlFlowOps(std::vector< fuzzerop::OpDescriptor > &Ops)
void describeFuzzerPointerOps(std::vector< fuzzerop::OpDescriptor > &Ops)
A description of some operation we can build while fuzzing IR.