LLVM 19.0.0git
Public Types | Public Member Functions | Public Attributes | List of all members
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)
 
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.
 
std::pair< GlobalVariable *, boolfindOrCreateGlobalVariable (Module *M, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred)
 Find or create a global variable.
 
ValuefindOrCreateSource (BasicBlock &BB, ArrayRef< Instruction * > Insts)
 Find a "source" for some operation, which will be used in one of the operation's operands.
 
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.
 
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.
 
InstructionconnectToSink (BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
 Find a viable user for V in Insts, which should all be contained in BB.
 
InstructionnewSink (BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
 Create a user for V in BB.
 
ValuefindPointer (BasicBlock &BB, ArrayRef< Instruction * > Insts)
 
TyperandomType ()
 Return a uniformly choosen type from AllowedTypes.
 
FunctioncreateFunctionDeclaration (Module &M, uint64_t ArgNum)
 
FunctioncreateFunctionDeclaration (Module &M)
 
FunctioncreateFunctionDefinition (Module &M, uint64_t ArgNum)
 
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 37 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 84 of file RandomIRBuilder.h.

◆ SourceType

Enumerator
SrcFromInstInCurBlock 
FunctionArgument 
InstInDominator 
SrcFromGlobalVariable 
NewConstOrStack 
EndOfValueSource 

Definition at line 59 of file RandomIRBuilder.h.

Constructor & Destructor Documentation

◆ RandomIRBuilder()

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

Definition at line 45 of file RandomIRBuilder.h.

Member Function Documentation

◆ connectToSink()

Instruction * RandomIRBuilder::connectToSink ( BasicBlock BB,
ArrayRef< Instruction * >  Insts,
Value V 
)

◆ createFunctionDeclaration() [1/2]

Function * RandomIRBuilder::createFunctionDeclaration ( Module M)

Definition at line 413 of file RandomIRBuilder.cpp.

References createFunctionDeclaration(), MaxArgNum, MinArgNum, and Rand.

◆ createFunctionDeclaration() [2/2]

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

◆ createFunctionDefinition() [1/2]

Function * RandomIRBuilder::createFunctionDefinition ( Module M)

Definition at line 439 of file RandomIRBuilder.cpp.

References createFunctionDefinition(), MaxArgNum, MinArgNum, and Rand.

◆ 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 66 of file RandomIRBuilder.cpp.

References DL, F, llvm::BasicBlock::getFirstInsertionPt(), and llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode().

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 79 of file RandomIRBuilder.cpp.

References llvm::fuzzerop::SourcePred::generate(), llvm::UndefValue::get(), KnownTypes, llvm::make_filter_range(), llvm::makeSampler(), llvm::fuzzerop::SourcePred::matches(), llvm::GlobalValue::NotThreadLocal, llvm::SmallVectorTemplateBase< T, bool >::push_back(), 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 109 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 
)

◆ newSink()

Instruction * RandomIRBuilder::newSink ( BasicBlock BB,
ArrayRef< Instruction * >  Insts,
Value V 
)

◆ newSource()

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

◆ randomType()

Type * RandomIRBuilder::randomType ( )

Return a uniformly choosen type from AllowedTypes.

Definition at line 394 of file RandomIRBuilder.cpp.

References KnownTypes, and Rand.

Referenced by createFunctionDeclaration().

Member Data Documentation

◆ KnownTypes

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

Definition at line 39 of file RandomIRBuilder.h.

Referenced by findOrCreateGlobalVariable(), newSource(), and randomType().

◆ MaxArgNum

uint64_t llvm::RandomIRBuilder::MaxArgNum = 5

Definition at line 42 of file RandomIRBuilder.h.

Referenced by createFunctionDeclaration(), and createFunctionDefinition().

◆ MinArgNum

uint64_t llvm::RandomIRBuilder::MinArgNum = 0

Definition at line 41 of file RandomIRBuilder.h.

Referenced by createFunctionDeclaration(), and createFunctionDefinition().

◆ MinFunctionNum

uint64_t llvm::RandomIRBuilder::MinFunctionNum = 1

Definition at line 43 of file RandomIRBuilder.h.

◆ Rand

RandomEngine llvm::RandomIRBuilder::Rand

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