LLVM 22.0.0git
llvm::RandomIRBuilder Struct Reference

#include "llvm/FuzzMutate/RandomIRBuilder.h"

Public Types

enum  SourceType {
  SrcFromInstInCurBlock , FunctionArgument , InstInDominator , SrcFromGlobalVariable ,
  NewConstOrStack , EndOfValueSource
}
enum  SinkType {
  SinkToInstInCurBlock , PointersInDominator , InstInDominatee , NewStore ,
  SinkToGlobalVariable , EndOfValueSink
}

Public Member Functions

 RandomIRBuilder (int Seed, ArrayRef< Type * > AllowedTypes)
LLVM_ABI AllocaInstcreateStackMemory (Function *F, Type *Ty, Value *Init=nullptr)
 Create a stack memory at the head of the function, store Init to the memory if provided.
LLVM_ABI std::pair< GlobalVariable *, boolfindOrCreateGlobalVariable (Module *M, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred)
 Find or create a global variable.
LLVM_ABI ValuefindOrCreateSource (BasicBlock &BB, ArrayRef< Instruction * > Insts)
 Find a "source" for some operation, which will be used in one of the operation's operands.
LLVM_ABI ValuefindOrCreateSource (BasicBlock &BB, ArrayRef< Instruction * > Insts, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred, bool allowConstant=true)
 Find a "source" for some operation, which will be used in one of the operation's operands.
LLVM_ABI ValuenewSource (BasicBlock &BB, ArrayRef< Instruction * > Insts, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred, bool allowConstant=true)
 Create some Value suitable as a source for some operation.
LLVM_ABI InstructionconnectToSink (BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
 Find a viable user for V in Insts, which should all be contained in BB.
LLVM_ABI InstructionnewSink (BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
 Create a user for V in BB.
LLVM_ABI ValuefindPointer (BasicBlock &BB, ArrayRef< Instruction * > Insts)
LLVM_ABI TyperandomType ()
 Return a uniformly choosen type from AllowedTypes.
LLVM_ABI FunctioncreateFunctionDeclaration (Module &M, uint64_t ArgNum)
LLVM_ABI FunctioncreateFunctionDeclaration (Module &M)
LLVM_ABI FunctioncreateFunctionDefinition (Module &M, uint64_t ArgNum)
LLVM_ABI FunctioncreateFunctionDefinition (Module &M)

Public Attributes

RandomEngine Rand
SmallVector< Type *, 16 > KnownTypes
uint64_t MinArgNum = 0
uint64_t MaxArgNum = 5
uint64_t MinFunctionNum = 1

Detailed Description

Definition at line 38 of file RandomIRBuilder.h.

Member Enumeration Documentation

◆ SinkType

Enumerator
SinkToInstInCurBlock 

TODO: Also consider pointers in function argument.

PointersInDominator 
InstInDominatee 
NewStore 
SinkToGlobalVariable 
EndOfValueSink 

Definition at line 89 of file RandomIRBuilder.h.

◆ SourceType

Enumerator
SrcFromInstInCurBlock 
FunctionArgument 
InstInDominator 
SrcFromGlobalVariable 
NewConstOrStack 
EndOfValueSource 

Definition at line 61 of file RandomIRBuilder.h.

Constructor & Destructor Documentation

◆ RandomIRBuilder()

llvm::RandomIRBuilder::RandomIRBuilder ( int Seed,
ArrayRef< Type * > AllowedTypes )
inline

Definition at line 46 of file RandomIRBuilder.h.

References KnownTypes, Rand, and Seed.

Member Function Documentation

◆ connectToSink()

◆ createFunctionDeclaration() [1/2]

Function * RandomIRBuilder::createFunctionDeclaration ( Module & M)

◆ createFunctionDeclaration() [2/2]

Function * RandomIRBuilder::createFunctionDeclaration ( Module & M,
uint64_t ArgNum )

◆ createFunctionDefinition() [1/2]

Function * RandomIRBuilder::createFunctionDefinition ( Module & M)

◆ createFunctionDefinition() [2/2]

Function * RandomIRBuilder::createFunctionDefinition ( Module & M,
uint64_t ArgNum )

◆ createStackMemory()

AllocaInst * RandomIRBuilder::createStackMemory ( Function * F,
Type * Ty,
Value * Init = nullptr )

Create a stack memory at the head of the function, store Init to the memory if provided.

TODO: For all Allocas, maybe allocate an array.

Definition at line 65 of file RandomIRBuilder.cpp.

References DL, F, llvm::BasicBlock::getFirstInsertionPt(), and llvm::ilist_node_impl< OptionsT >::getIterator().

Referenced by newSink(), and newSource().

◆ findOrCreateGlobalVariable()

std::pair< GlobalVariable *, bool > RandomIRBuilder::findOrCreateGlobalVariable ( Module * M,
ArrayRef< Value * > Srcs,
fuzzerop::SourcePred Pred )

Find or create a global variable.

It will be initialized by random constants that satisfies Pred. It will also report whether this global variable found or created.

Definition at line 78 of file RandomIRBuilder.cpp.

References llvm::PoisonValue::get(), KnownTypes, llvm::make_filter_range(), llvm::make_pointer_range(), llvm::makeSampler(), llvm::GlobalValue::NotThreadLocal, and Rand.

Referenced by connectToSink(), and findOrCreateSource().

◆ findOrCreateSource() [1/2]

Value * RandomIRBuilder::findOrCreateSource ( BasicBlock & BB,
ArrayRef< Instruction * > Insts )

Find a "source" for some operation, which will be used in one of the operation's operands.

This either selects an instruction in Insts or returns some new arbitrary Value.

Definition at line 106 of file RandomIRBuilder.cpp.

References llvm::fuzzerop::anyType(), and findOrCreateSource().

Referenced by findOrCreateSource().

◆ findOrCreateSource() [2/2]

Value * RandomIRBuilder::findOrCreateSource ( BasicBlock & BB,
ArrayRef< Instruction * > Insts,
ArrayRef< Value * > Srcs,
fuzzerop::SourcePred Pred,
bool allowConstant = true )

◆ findPointer()

Value * RandomIRBuilder::findPointer ( BasicBlock & BB,
ArrayRef< Instruction * > Insts )

Definition at line 433 of file RandomIRBuilder.cpp.

References llvm::make_filter_range(), llvm::makeSampler(), and Rand.

Referenced by newSink(), and newSource().

◆ newSink()

◆ newSource()

◆ randomType()

Type * RandomIRBuilder::randomType ( )

Return a uniformly choosen type from AllowedTypes.

Definition at line 448 of file RandomIRBuilder.cpp.

References KnownTypes, Rand, and llvm::uniform().

Referenced by createFunctionDeclaration().

Member Data Documentation

◆ KnownTypes

SmallVector<Type *, 16> llvm::RandomIRBuilder::KnownTypes

◆ MaxArgNum

uint64_t llvm::RandomIRBuilder::MaxArgNum = 5

Definition at line 43 of file RandomIRBuilder.h.

Referenced by createFunctionDeclaration(), and createFunctionDefinition().

◆ MinArgNum

uint64_t llvm::RandomIRBuilder::MinArgNum = 0

Definition at line 42 of file RandomIRBuilder.h.

Referenced by createFunctionDeclaration(), and createFunctionDefinition().

◆ MinFunctionNum

uint64_t llvm::RandomIRBuilder::MinFunctionNum = 1

Definition at line 44 of file RandomIRBuilder.h.

◆ Rand


The documentation for this struct was generated from the following files: