LLVM 22.0.0git
|
#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 AllocaInst * | 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. | |
LLVM_ABI std::pair< GlobalVariable *, bool > | findOrCreateGlobalVariable (Module *M, ArrayRef< Value * > Srcs, fuzzerop::SourcePred Pred) |
Find or create a global variable. | |
LLVM_ABI Value * | findOrCreateSource (BasicBlock &BB, ArrayRef< Instruction * > Insts) |
Find a "source" for some operation, which will be used in one of the operation's operands. | |
LLVM_ABI Value * | findOrCreateSource (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 Value * | newSource (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 Instruction * | connectToSink (BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V) |
Find a viable user for V in Insts , which should all be contained in BB . | |
LLVM_ABI Instruction * | newSink (BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V) |
Create a user for V in BB . | |
LLVM_ABI Value * | findPointer (BasicBlock &BB, ArrayRef< Instruction * > Insts) |
LLVM_ABI Type * | randomType () |
Return a uniformly choosen type from AllowedTypes . | |
LLVM_ABI Function * | createFunctionDeclaration (Module &M, uint64_t ArgNum) |
LLVM_ABI Function * | createFunctionDeclaration (Module &M) |
LLVM_ABI Function * | createFunctionDefinition (Module &M, uint64_t ArgNum) |
LLVM_ABI Function * | createFunctionDefinition (Module &M) |
Public Attributes | |
RandomEngine | Rand |
SmallVector< Type *, 16 > | KnownTypes |
uint64_t | MinArgNum = 0 |
uint64_t | MaxArgNum = 5 |
uint64_t | MinFunctionNum = 1 |
Definition at line 38 of file RandomIRBuilder.h.
Enumerator | |
---|---|
SinkToInstInCurBlock | TODO: Also consider pointers in function argument. |
PointersInDominator | |
InstInDominatee | |
NewStore | |
SinkToGlobalVariable | |
EndOfValueSink |
Definition at line 89 of file RandomIRBuilder.h.
Enumerator | |
---|---|
SrcFromInstInCurBlock | |
FunctionArgument | |
InstInDominator | |
SrcFromGlobalVariable | |
NewConstOrStack | |
EndOfValueSource |
Definition at line 61 of file RandomIRBuilder.h.
Definition at line 46 of file RandomIRBuilder.h.
References KnownTypes, Rand, and Seed.
Instruction * RandomIRBuilder::connectToSink | ( | BasicBlock & | BB, |
ArrayRef< Instruction * > | Insts, | ||
Value * | V ) |
Find a viable user for V
in Insts
, which should all be contained in BB
.
This may also create some new instruction in BB
and use that.
TODO: allocate a new stack memory.
Definition at line 341 of file RandomIRBuilder.cpp.
References llvm::ArrayRef< T >::back(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), buildTargetLegalStore(), llvm::cast(), llvm::SmallVectorTemplateCommon< T, typename >::end(), EndOfValueSink, findOrCreateGlobalVariable(), getDominatees(), getDominators(), llvm::BasicBlock::getModule(), I, InstInDominatee, llvm::isa(), isCompatibleReplacement(), llvm_unreachable, llvm::makeSampler(), newSink(), NewStore, llvm::fuzzerop::onlyType(), PointersInDominator, llvm::SmallVectorTemplateBase< T, bool >::push_back(), Rand, SinkToGlobalVariable, and SinkToInstInCurBlock.
Definition at line 467 of file RandomIRBuilder.cpp.
References createFunctionDeclaration(), MaxArgNum, MinArgNum, Rand, and llvm::uniform().
Definition at line 453 of file RandomIRBuilder.cpp.
References llvm::Function::Create(), llvm::GlobalValue::ExternalLinkage, F, llvm::FunctionType::get(), and randomType().
Referenced by createFunctionDeclaration(), and createFunctionDefinition().
Definition at line 493 of file RandomIRBuilder.cpp.
References createFunctionDefinition(), MaxArgNum, MinArgNum, Rand, and llvm::uniform().
Definition at line 472 of file RandomIRBuilder.cpp.
References llvm::BasicBlock::Create(), llvm::ReturnInst::Create(), createFunctionDeclaration(), DL, F, and llvm::Type::getVoidTy().
Referenced by createFunctionDefinition().
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().
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().
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().
Value * RandomIRBuilder::findOrCreateSource | ( | 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.
This either selects an instruction in Insts
that matches Pred
, or returns some new Value that matches Pred
. The values in Srcs
should be source operands that have already been selected.
Definition at line 160 of file RandomIRBuilder.cpp.
References llvm::SmallVectorTemplateCommon< T, typename >::begin(), buildTargetLegalLoad(), llvm::SmallVectorTemplateCommon< T, typename >::end(), EndOfValueSource, eraseNewInstructions(), F, findOrCreateGlobalVariable(), FunctionArgument, getDominators(), llvm::BasicBlock::getFirstInsertionPt(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::BasicBlock::getTerminator(), InstInDominator, llvm_unreachable, llvm::make_filter_range(), llvm::make_pointer_range(), llvm::makeSampler(), NewConstOrStack, newSource(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), Rand, SrcFromGlobalVariable, and SrcFromInstInCurBlock.
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().
Instruction * RandomIRBuilder::newSink | ( | BasicBlock & | BB, |
ArrayRef< Instruction * > | Insts, | ||
Value * | V ) |
Create a user for V
in BB
.
Definition at line 417 of file RandomIRBuilder.cpp.
References llvm::ArrayRef< T >::back(), buildTargetLegalStore(), createStackMemory(), findPointer(), llvm::PointerType::get(), llvm::PoisonValue::get(), llvm::BasicBlock::getModule(), llvm::BasicBlock::getParent(), Ptr, Rand, and llvm::uniform().
Referenced by connectToSink().
Value * RandomIRBuilder::newSource | ( | BasicBlock & | BB, |
ArrayRef< Instruction * > | Insts, | ||
ArrayRef< Value * > | Srcs, | ||
fuzzerop::SourcePred | Pred, | ||
bool | allowConstant = true ) |
Create some Value suitable as a source for some operation.
Definition at line 243 of file RandomIRBuilder.cpp.
References assert(), buildTargetLegalLoad(), createStackMemory(), llvm::dyn_cast(), llvm::BasicBlock::end(), eraseNewInstructions(), F, findPointer(), llvm::BasicBlock::getFirstInsertionPt(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::BasicBlock::getModule(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), I, llvm::isa(), KnownTypes, llvm::makeSampler(), Ptr, and Rand.
Referenced by findOrCreateSource().
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().
SmallVector<Type *, 16> llvm::RandomIRBuilder::KnownTypes |
Definition at line 40 of file RandomIRBuilder.h.
Referenced by findOrCreateGlobalVariable(), newSource(), RandomIRBuilder(), and randomType().
uint64_t llvm::RandomIRBuilder::MaxArgNum = 5 |
Definition at line 43 of file RandomIRBuilder.h.
Referenced by createFunctionDeclaration(), and createFunctionDefinition().
uint64_t llvm::RandomIRBuilder::MinArgNum = 0 |
Definition at line 42 of file RandomIRBuilder.h.
Referenced by createFunctionDeclaration(), and createFunctionDefinition().
uint64_t llvm::RandomIRBuilder::MinFunctionNum = 1 |
Definition at line 44 of file RandomIRBuilder.h.
RandomEngine llvm::RandomIRBuilder::Rand |
Definition at line 39 of file RandomIRBuilder.h.
Referenced by connectToSink(), createFunctionDeclaration(), createFunctionDefinition(), findOrCreateGlobalVariable(), findOrCreateSource(), findPointer(), newSink(), newSource(), RandomIRBuilder(), and randomType().