@@ -98,25 +98,25 @@ void llvm::describeFuzzerVectorOps(std::vector<fuzzerop::OpDescriptor> &Ops) {
98
98
}
99
99
100
100
OpDescriptor llvm::fuzzerop::selectDescriptor (unsigned Weight) {
101
- auto buildOp = [](ArrayRef<Value *> Srcs, Instruction *Inst ) {
102
- return SelectInst::Create (Srcs[0 ], Srcs[1 ], Srcs[2 ], " S" , Inst );
101
+ auto buildOp = [](ArrayRef<Value *> Srcs, BasicBlock::iterator InsertPt ) {
102
+ return SelectInst::Create (Srcs[0 ], Srcs[1 ], Srcs[2 ], " S" , InsertPt );
103
103
};
104
104
return {Weight,
105
105
{boolOrVecBoolType (), matchFirstLengthWAnyType (), matchSecondType ()},
106
106
buildOp};
107
107
}
108
108
109
109
OpDescriptor llvm::fuzzerop::fnegDescriptor (unsigned Weight) {
110
- auto buildOp = [](ArrayRef<Value *> Srcs, Instruction *Inst ) {
111
- return UnaryOperator::Create (Instruction::FNeg, Srcs[0 ], " F" , Inst );
110
+ auto buildOp = [](ArrayRef<Value *> Srcs, BasicBlock::iterator InsertPt ) {
111
+ return UnaryOperator::Create (Instruction::FNeg, Srcs[0 ], " F" , InsertPt );
112
112
};
113
113
return {Weight, {anyFloatOrVecFloatType ()}, buildOp};
114
114
}
115
115
116
116
OpDescriptor llvm::fuzzerop::binOpDescriptor (unsigned Weight,
117
117
Instruction::BinaryOps Op) {
118
- auto buildOp = [Op](ArrayRef<Value *> Srcs, Instruction *Inst ) {
119
- return BinaryOperator::Create (Op, Srcs[0 ], Srcs[1 ], " B" , Inst );
118
+ auto buildOp = [Op](ArrayRef<Value *> Srcs, BasicBlock::iterator InsertPt ) {
119
+ return BinaryOperator::Create (Op, Srcs[0 ], Srcs[1 ], " B" , InsertPt );
120
120
};
121
121
switch (Op) {
122
122
case Instruction::Add:
@@ -148,8 +148,9 @@ OpDescriptor llvm::fuzzerop::binOpDescriptor(unsigned Weight,
148
148
OpDescriptor llvm::fuzzerop::cmpOpDescriptor (unsigned Weight,
149
149
Instruction::OtherOps CmpOp,
150
150
CmpInst::Predicate Pred) {
151
- auto buildOp = [CmpOp, Pred](ArrayRef<Value *> Srcs, Instruction *Inst) {
152
- return CmpInst::Create (CmpOp, Pred, Srcs[0 ], Srcs[1 ], " C" , Inst);
151
+ auto buildOp = [CmpOp, Pred](ArrayRef<Value *> Srcs,
152
+ BasicBlock::iterator InsertPt) {
153
+ return CmpInst::Create (CmpOp, Pred, Srcs[0 ], Srcs[1 ], " C" , InsertPt);
153
154
};
154
155
155
156
switch (CmpOp) {
@@ -163,9 +164,10 @@ OpDescriptor llvm::fuzzerop::cmpOpDescriptor(unsigned Weight,
163
164
}
164
165
165
166
OpDescriptor llvm::fuzzerop::splitBlockDescriptor (unsigned Weight) {
166
- auto buildSplitBlock = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
167
- BasicBlock *Block = Inst->getParent ();
168
- BasicBlock *Next = Block->splitBasicBlock (Inst, " BB" );
167
+ auto buildSplitBlock = [](ArrayRef<Value *> Srcs,
168
+ BasicBlock::iterator InsertPt) {
169
+ BasicBlock *Block = InsertPt->getParent ();
170
+ BasicBlock *Next = Block->splitBasicBlock (InsertPt, " BB" );
169
171
170
172
// If it was an exception handling block, we are done.
171
173
if (Block->isEHPad ())
@@ -174,7 +176,8 @@ OpDescriptor llvm::fuzzerop::splitBlockDescriptor(unsigned Weight) {
174
176
// Loop back on this block by replacing the unconditional forward branch
175
177
// with a conditional with a backedge.
176
178
if (Block != &Block->getParent ()->getEntryBlock ()) {
177
- BranchInst::Create (Block, Next, Srcs[0 ], Block->getTerminator ());
179
+ BranchInst::Create (Block, Next, Srcs[0 ],
180
+ Block->getTerminator ()->getIterator ());
178
181
Block->getTerminator ()->eraseFromParent ();
179
182
180
183
// We need values for each phi in the block. Since there isn't a good way
@@ -193,12 +196,12 @@ OpDescriptor llvm::fuzzerop::splitBlockDescriptor(unsigned Weight) {
193
196
}
194
197
195
198
OpDescriptor llvm::fuzzerop::gepDescriptor (unsigned Weight) {
196
- auto buildGEP = [](ArrayRef<Value *> Srcs, Instruction *Inst ) {
199
+ auto buildGEP = [](ArrayRef<Value *> Srcs, BasicBlock::iterator InsertPt ) {
197
200
// TODO: It would be better to generate a random type here, rather than
198
201
// generating a random value and picking its type.
199
202
Type *Ty = Srcs[1 ]->getType ();
200
203
auto Indices = ArrayRef (Srcs).drop_front (2 );
201
- return GetElementPtrInst::Create (Ty, Srcs[0 ], Indices, " G" , Inst );
204
+ return GetElementPtrInst::Create (Ty, Srcs[0 ], Indices, " G" , InsertPt );
202
205
};
203
206
// TODO: Handle aggregates and vectors
204
207
// TODO: Support multiple indices.
@@ -239,10 +242,11 @@ static SourcePred validExtractValueIndex() {
239
242
}
240
243
241
244
OpDescriptor llvm::fuzzerop::extractValueDescriptor (unsigned Weight) {
242
- auto buildExtract = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
245
+ auto buildExtract = [](ArrayRef<Value *> Srcs,
246
+ BasicBlock::iterator InsertPt) {
243
247
// TODO: It's pretty inefficient to shuffle this all through constants.
244
248
unsigned Idx = cast<ConstantInt>(Srcs[1 ])->getZExtValue ();
245
- return ExtractValueInst::Create (Srcs[0 ], {Idx}, " E" , Inst );
249
+ return ExtractValueInst::Create (Srcs[0 ], {Idx}, " E" , InsertPt );
246
250
};
247
251
// TODO: Should we handle multiple indices?
248
252
return {Weight, {anyAggregateType (), validExtractValueIndex ()}, buildExtract};
@@ -298,10 +302,10 @@ static SourcePred validInsertValueIndex() {
298
302
}
299
303
300
304
OpDescriptor llvm::fuzzerop::insertValueDescriptor (unsigned Weight) {
301
- auto buildInsert = [](ArrayRef<Value *> Srcs, Instruction *Inst ) {
305
+ auto buildInsert = [](ArrayRef<Value *> Srcs, BasicBlock::iterator InsertPt ) {
302
306
// TODO: It's pretty inefficient to shuffle this all through constants.
303
307
unsigned Idx = cast<ConstantInt>(Srcs[2 ])->getZExtValue ();
304
- return InsertValueInst::Create (Srcs[0 ], Srcs[1 ], {Idx}, " I" , Inst );
308
+ return InsertValueInst::Create (Srcs[0 ], Srcs[1 ], {Idx}, " I" , InsertPt );
305
309
};
306
310
return {
307
311
Weight,
@@ -310,16 +314,17 @@ OpDescriptor llvm::fuzzerop::insertValueDescriptor(unsigned Weight) {
310
314
}
311
315
312
316
OpDescriptor llvm::fuzzerop::extractElementDescriptor (unsigned Weight) {
313
- auto buildExtract = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
314
- return ExtractElementInst::Create (Srcs[0 ], Srcs[1 ], " E" , Inst);
317
+ auto buildExtract = [](ArrayRef<Value *> Srcs,
318
+ BasicBlock::iterator InsertPt) {
319
+ return ExtractElementInst::Create (Srcs[0 ], Srcs[1 ], " E" , InsertPt);
315
320
};
316
321
// TODO: Try to avoid undefined accesses.
317
322
return {Weight, {anyVectorType (), anyIntType ()}, buildExtract};
318
323
}
319
324
320
325
OpDescriptor llvm::fuzzerop::insertElementDescriptor (unsigned Weight) {
321
- auto buildInsert = [](ArrayRef<Value *> Srcs, Instruction *Inst ) {
322
- return InsertElementInst::Create (Srcs[0 ], Srcs[1 ], Srcs[2 ], " I" , Inst );
326
+ auto buildInsert = [](ArrayRef<Value *> Srcs, BasicBlock::iterator InsertPt ) {
327
+ return InsertElementInst::Create (Srcs[0 ], Srcs[1 ], Srcs[2 ], " I" , InsertPt );
323
328
};
324
329
// TODO: Try to avoid undefined accesses.
325
330
return {Weight,
@@ -343,8 +348,9 @@ static SourcePred validShuffleVectorIndex() {
343
348
}
344
349
345
350
OpDescriptor llvm::fuzzerop::shuffleVectorDescriptor (unsigned Weight) {
346
- auto buildShuffle = [](ArrayRef<Value *> Srcs, Instruction *Inst) {
347
- return new ShuffleVectorInst (Srcs[0 ], Srcs[1 ], Srcs[2 ], " S" , Inst);
351
+ auto buildShuffle = [](ArrayRef<Value *> Srcs,
352
+ BasicBlock::iterator InsertPt) {
353
+ return new ShuffleVectorInst (Srcs[0 ], Srcs[1 ], Srcs[2 ], " S" , InsertPt);
348
354
};
349
355
return {Weight,
350
356
{anyVectorType (), matchFirstType (), validShuffleVectorIndex ()},
0 commit comments