Skip to content

Commit 69365ae

Browse files
committed
[RandomIRBuilder] Remove use of getNonOpaquePointerElementType() (NFC)
1 parent 2cc79ba commit 69365ae

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

llvm/include/llvm/FuzzMutate/RandomIRBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ struct RandomIRBuilder {
9696
Value *V);
9797
/// Create a user for \c V in \c BB.
9898
Instruction *newSink(BasicBlock &BB, ArrayRef<Instruction *> Insts, Value *V);
99-
Value *findPointer(BasicBlock &BB, ArrayRef<Instruction *> Insts,
100-
ArrayRef<Value *> Srcs, fuzzerop::SourcePred Pred);
99+
Value *findPointer(BasicBlock &BB, ArrayRef<Instruction *> Insts);
101100
/// Return a uniformly choosen type from \c AllowedTypes
102101
Type *randomType();
103102
Function *createFunctionDeclaration(Module &M, uint64_t ArgNum);

llvm/lib/FuzzMutate/RandomIRBuilder.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Value *RandomIRBuilder::newSource(BasicBlock &BB, ArrayRef<Instruction *> Insts,
203203
RS.sample(Pred.generate(Srcs, KnownTypes));
204204

205205
// If we can find a pointer to load from, use it half the time.
206-
Value *Ptr = findPointer(BB, Insts, Srcs, Pred);
206+
Value *Ptr = findPointer(BB, Insts);
207207
if (Ptr) {
208208
// Create load from the chosen pointer
209209
auto IP = BB.getFirstInsertionPt();
@@ -363,7 +363,7 @@ Instruction *RandomIRBuilder::connectToSink(BasicBlock &BB,
363363

364364
Instruction *RandomIRBuilder::newSink(BasicBlock &BB,
365365
ArrayRef<Instruction *> Insts, Value *V) {
366-
Value *Ptr = findPointer(BB, Insts, {V}, matchFirstType());
366+
Value *Ptr = findPointer(BB, Insts);
367367
if (!Ptr) {
368368
if (uniform(Rand, 0, 1)) {
369369
Type *Ty = V->getType();
@@ -377,27 +377,14 @@ Instruction *RandomIRBuilder::newSink(BasicBlock &BB,
377377
}
378378

379379
Value *RandomIRBuilder::findPointer(BasicBlock &BB,
380-
ArrayRef<Instruction *> Insts,
381-
ArrayRef<Value *> Srcs, SourcePred Pred) {
382-
auto IsMatchingPtr = [&Srcs, &Pred](Instruction *Inst) {
380+
ArrayRef<Instruction *> Insts) {
381+
auto IsMatchingPtr = [](Instruction *Inst) {
383382
// Invoke instructions sometimes produce valid pointers but currently
384383
// we can't insert loads or stores from them
385384
if (Inst->isTerminator())
386385
return false;
387386

388-
if (auto *PtrTy = dyn_cast<PointerType>(Inst->getType())) {
389-
if (PtrTy->isOpaque())
390-
return true;
391-
392-
// We can never generate loads from non first class or non sized types
393-
Type *ElemTy = PtrTy->getNonOpaquePointerElementType();
394-
if (!ElemTy->isSized() || !ElemTy->isFirstClassType())
395-
return false;
396-
397-
// TODO: Check if this is horribly expensive.
398-
return Pred.matches(Srcs, UndefValue::get(ElemTy));
399-
}
400-
return false;
387+
return Inst->getType()->isPointerTy();
401388
};
402389
if (auto RS = makeSampler(Rand, make_filter_range(Insts, IsMatchingPtr)))
403390
return RS.getSelection();

0 commit comments

Comments
 (0)