LLVM 23.0.0git
RandomIRBuilder.cpp
Go to the documentation of this file.
1//===-- RandomIRBuilder.cpp -----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/ADT/STLExtras.h"
13#include "llvm/IR/BasicBlock.h"
14#include "llvm/IR/Constants.h"
15#include "llvm/IR/DataLayout.h"
16#include "llvm/IR/Dominators.h"
17#include "llvm/IR/Function.h"
19#include "llvm/IR/Module.h"
20
21using namespace llvm;
22using namespace fuzzerop;
23
25 // Dominator tree construction requires that all blocks have terminators.
27 for (BasicBlock &BB : F)
28 if (!BB.hasTerminator())
29 AddedInsts.push_back(new UnreachableInst(F.getContext(), &BB));
30 DominatorTree DT(F);
31 for (Instruction *I : AddedInsts)
32 I->eraseFromParent();
33 return DT;
34}
35
36/// Return a vector of Blocks that dominates this block, excluding current
37/// block.
38static std::vector<BasicBlock *> getDominators(BasicBlock *BB) {
39 std::vector<BasicBlock *> ret;
41 DomTreeNode *Node = DT.getNode(BB);
42 // It's possible that an orphan block is not in the dom tree. In that case we
43 // just return nothing.
44 if (!Node)
45 return ret;
46 Node = Node->getIDom();
47 while (Node && Node->getBlock()) {
48 ret.push_back(Node->getBlock());
49 // Get parent block.
50 Node = Node->getIDom();
51 }
52 return ret;
53}
54
55/// Return a vector of Blocks that is dominated by this block, excluding current
56/// block
57static std::vector<BasicBlock *> getDominatees(BasicBlock *BB) {
59 std::vector<BasicBlock *> ret;
60 DomTreeNode *Parent = DT.getNode(BB);
61 // It's possible that an orphan block is not in the dom tree. In that case we
62 // just return nothing.
63 if (!Parent)
64 return ret;
65 for (DomTreeNode *Child : Parent->children())
66 ret.push_back(Child->getBlock());
67 uint64_t Idx = 0;
68 while (Idx < ret.size()) {
69 DomTreeNode *Node = DT[ret[Idx]];
70 Idx++;
71 for (DomTreeNode *Child : Node->children())
72 ret.push_back(Child->getBlock());
73 }
74 return ret;
75}
76
78 Value *Init) {
79 /// TODO: For all Allocas, maybe allocate an array.
80 BasicBlock *EntryBB = &F->getEntryBlock();
81 const DataLayout &DL = F->getDataLayout();
82 AllocaInst *Alloca = new AllocaInst(Ty, DL.getAllocaAddrSpace(), "A",
83 EntryBB->getFirstInsertionPt());
84 if (Init)
85 new StoreInst(Init, Alloca, std::next(Alloca->getIterator()));
86 return Alloca;
87}
88
89std::pair<GlobalVariable *, bool>
92 auto MatchesPred = [&Srcs, &Pred](GlobalVariable *GV) {
93 // Can't directly compare GV's type, as it would be a pointer to the actual
94 // type.
95 return Pred.matches(Srcs, PoisonValue::get(GV->getValueType()));
96 };
97 bool DidCreate = false;
99 llvm::make_pointer_range(M->globals()));
100 auto RS = makeSampler(Rand, make_filter_range(GlobalVars, MatchesPred));
101 RS.sample(nullptr, 1);
102 GlobalVariable *GV = RS.getSelection();
103 if (!GV) {
104 DidCreate = true;
105 using LinkageTypes = GlobalVariable::LinkageTypes;
106 auto TRS = makeSampler<Constant *>(Rand);
107 TRS.sample(Pred.generate(Srcs, KnownTypes));
108 Constant *Init = TRS.getSelection();
109 Type *Ty = Init->getType();
110 GV = new GlobalVariable(*M, Ty, false, LinkageTypes::ExternalLinkage, Init,
111 "G", nullptr,
113 M->getDataLayout().getDefaultGlobalsAddressSpace());
114 }
115 return {GV, DidCreate};
116}
117
122
123// Adapts the current pointer for a legal mem operation on the target arch.
125 const Twine &Name,
126 SmallVector<Instruction *> *NewInsts) {
127 if (M && M->getTargetTriple().isAMDGCN()) {
128 // Check if we should perform an address space cast
129 PointerType *pointerType = dyn_cast<PointerType>(Ptr->getType());
130 if (pointerType && pointerType->getAddressSpace() == 8) {
131 // Perform address space cast from address space 8 to address space 7
132 auto NewPtr = new AddrSpaceCastInst(
133 Ptr, PointerType::get(M->getContext(), 7), Name + ".ASC", IP);
134 if (NewInsts)
135 NewInsts->push_back(NewPtr);
136 return NewPtr;
137 }
138 }
139
140 return Ptr;
141}
142
143// Stores a value to memory, considering the target triple's restrictions.
145 InsertPosition IP, Module *M) {
146 Value *StorePtr = buildTargetLegalPtr(M, Ptr, IP, "", nullptr);
147 Instruction *Store = new StoreInst(Val, StorePtr, IP);
148 return Store;
149}
150
151// Loads a value from memory, considering the target triple's restrictions.
152static std::pair<Instruction *, SmallVector<Instruction *>>
154 const Twine &LoadName) {
156
157 Value *LoadPtr = buildTargetLegalPtr(M, Ptr, IP, LoadName, &NewInsts);
158
159 Instruction *Load = new LoadInst(AccessTy, LoadPtr, LoadName, IP);
160 NewInsts.push_back(Load);
161
162 return std::make_pair(Load, NewInsts);
163}
164
166 // Remove in reverse order (uses before defs)
167 for (auto it = NewInsts.rbegin(); it != NewInsts.rend(); ++it) {
168 (*it)->eraseFromParent();
169 }
170}
171
175 SourcePred Pred,
176 bool allowConstant) {
177 auto MatchesPred = [&Srcs, &Pred](Value *V) { return Pred.matches(Srcs, V); };
179 for (uint64_t i = 0; i < EndOfValueSource; i++)
180 SrcTys.push_back(i);
181 std::shuffle(SrcTys.begin(), SrcTys.end(), Rand);
182 for (uint64_t SrcTy : SrcTys) {
183 switch (SrcTy) {
185 auto RS = makeSampler(Rand, make_filter_range(Insts, MatchesPred));
186 if (!RS.isEmpty()) {
187 return RS.getSelection();
188 }
189 break;
190 }
191 case FunctionArgument: {
192 Function *F = BB.getParent();
194 for (uint64_t i = 0; i < F->arg_size(); i++) {
195 Args.push_back(F->getArg(i));
196 }
197 auto RS = makeSampler(Rand, make_filter_range(Args, MatchesPred));
198 if (!RS.isEmpty()) {
199 return RS.getSelection();
200 }
201 break;
202 }
203 case InstInDominator: {
204 auto Dominators = getDominators(&BB);
205 std::shuffle(Dominators.begin(), Dominators.end(), Rand);
206 for (BasicBlock *Dom : Dominators) {
209 auto RS =
210 makeSampler(Rand, make_filter_range(Instructions, MatchesPred));
211 // Also consider choosing no source, meaning we want a new one.
212 if (!RS.isEmpty()) {
213 return RS.getSelection();
214 }
215 }
216 break;
217 }
219 Module *M = BB.getParent()->getParent();
220 auto [GV, DidCreate] = findOrCreateGlobalVariable(M, Srcs, Pred);
221 Type *Ty = GV->getValueType();
224 : InsertPosition(&BB);
225 // Build a legal load and track new instructions in case a rollback is
226 // needed.
227 auto [LoadGV, NewInsts] = buildTargetLegalLoad(Ty, GV, IP, M, "LGV");
228 // Because we might be generating new values, we have to check if it
229 // matches again.
230 if (DidCreate) {
231 if (Pred.matches(Srcs, LoadGV)) {
232 return LoadGV;
233 }
234 // Remove newly inserted instructions
235 eraseNewInstructions(NewInsts);
236 // If no one is using this GlobalVariable, delete it too.
237 if (GV->use_empty()) {
238 GV->eraseFromParent();
239 }
240 }
241 break;
242 }
243 case NewConstOrStack: {
244 return newSource(BB, Insts, Srcs, Pred, allowConstant);
245 }
246 default:
247 case EndOfValueSource: {
248 llvm_unreachable("EndOfValueSource executed");
249 }
250 }
251 }
252 llvm_unreachable("Can't find a source");
253}
254
256 ArrayRef<Value *> Srcs, SourcePred Pred,
257 bool allowConstant) {
258 // Generate some constants to choose from.
259 auto RS = makeSampler<Value *>(Rand);
260 RS.sample(Pred.generate(Srcs, KnownTypes));
261
262 // If we can find a pointer to load from, use it half the time.
263 Value *Ptr = findPointer(BB, Insts);
264 if (Ptr) {
265 // Create load from the chosen pointer
266 auto IP = BB.getFirstInsertionPt();
267 if (auto *I = dyn_cast<Instruction>(Ptr)) {
268 IP = ++I->getIterator();
269 assert(IP != BB.end() && "guaranteed by the findPointer");
270 }
271 // Pick the type independently.
272 Type *AccessTy = RS.getSelection()->getType();
273 // Build a legal load and track new instructions in case a rollback is
274 // needed.
275 auto [NewLoad, NewInsts] =
276 buildTargetLegalLoad(AccessTy, Ptr, IP, BB.getModule(), "L");
277
278 // Only sample this load if it really matches the descriptor
279 if (Pred.matches(Srcs, NewLoad))
280 RS.sample(NewLoad, RS.totalWeight());
281 else {
282 // Remove newly inserted instructions
283 eraseNewInstructions(NewInsts);
284 }
285 }
286
287 Value *newSrc = RS.getSelection();
288 // Generate a stack alloca and store the constant to it if constant is not
289 // allowed, our hope is that later mutations can generate some values and
290 // store to this placeholder.
291 if (!allowConstant && isa<Constant>(newSrc)) {
292 Type *Ty = newSrc->getType();
293 Function *F = BB.getParent();
294 AllocaInst *Alloca = createStackMemory(F, Ty, newSrc);
295 if (BB.hasTerminator()) {
296 newSrc = new LoadInst(Ty, Alloca, /*ArrLen,*/ "L",
297 BB.getTerminator()->getIterator());
298 } else {
299 newSrc = new LoadInst(Ty, Alloca, /*ArrLen,*/ "L", &BB);
300 }
301 }
302 return newSrc;
303}
304
305static bool isCompatibleReplacement(const Instruction *I, const Use &Operand,
306 const Value *Replacement) {
307 unsigned int OperandNo = Operand.getOperandNo();
308 if (Operand->getType() != Replacement->getType())
309 return false;
310 switch (I->getOpcode()) {
311 case Instruction::GetElementPtr:
312 case Instruction::ExtractElement:
313 case Instruction::ExtractValue:
314 // TODO: We could potentially validate these, but for now just leave indices
315 // alone.
316 if (OperandNo >= 1)
317 return false;
318 break;
319 case Instruction::InsertValue:
320 case Instruction::InsertElement:
321 case Instruction::ShuffleVector:
322 if (OperandNo >= 2)
323 return false;
324 break;
325 // For Br/Switch, we only try to modify the 1st Operand (condition).
326 // Modify other operands, like switch case may accidently change case from
327 // ConstantInt to a register, which is illegal.
328 case Instruction::Switch:
329 case Instruction::CondBr:
330 if (OperandNo >= 1)
331 return false;
332 break;
333 case Instruction::Call:
334 case Instruction::Invoke:
335 case Instruction::CallBr: {
336 const Function *Callee = cast<CallBase>(I)->getCalledFunction();
337 // If it's an indirect call, give up.
338 if (!Callee)
339 return false;
340 // If callee is not an intrinsic, operand 0 is the function to be called.
341 // Since we cannot assume that the replacement is a function pointer,
342 // we give up.
343 if (!Callee->getIntrinsicID() && OperandNo == 0)
344 return false;
345 return !Callee->hasParamAttribute(OperandNo, Attribute::ImmArg);
346 }
347 case Instruction::CatchPad:
348 // Argument operand must be alloca or constant
349 if (!isa<Constant>(Replacement) && !isa<AllocaInst>(Replacement))
350 return false;
351 break;
352 default:
353 break;
354 }
355 return true;
356}
357
360 Value *V) {
362 for (uint64_t i = 0; i < EndOfValueSink; i++)
363 SinkTys.push_back(i);
364 std::shuffle(SinkTys.begin(), SinkTys.end(), Rand);
365 auto findSinkAndConnect =
366 [this, V](ArrayRef<Instruction *> Instructions) -> Instruction * {
367 auto RS = makeSampler<Use *>(Rand);
368 for (auto &I : Instructions) {
369 for (Use &U : I->operands())
370 if (isCompatibleReplacement(I, U, V))
371 RS.sample(&U, 1);
372 }
373 if (!RS.isEmpty()) {
374 Use *Sink = RS.getSelection();
375 User *U = Sink->getUser();
376 unsigned OpNo = Sink->getOperandNo();
377 U->setOperand(OpNo, V);
378 return cast<Instruction>(U);
379 }
380 return nullptr;
381 };
382 Instruction *Sink = nullptr;
383 for (uint64_t SinkTy : SinkTys) {
384 switch (SinkTy) {
386 Sink = findSinkAndConnect(Insts);
387 if (Sink)
388 return Sink;
389 break;
390 case PointersInDominator: {
391 auto Dominators = getDominators(&BB);
392 std::shuffle(Dominators.begin(), Dominators.end(), Rand);
393 for (BasicBlock *Dom : Dominators) {
394 for (Instruction &I : *Dom) {
395 if (isa<PointerType>(I.getType())) {
396 return buildTargetLegalStore(V, &I, Insts.back()->getIterator(),
397 I.getModule());
398 }
399 }
400 }
401 break;
402 }
403 case InstInDominatee: {
404 auto Dominatees = getDominatees(&BB);
405 std::shuffle(Dominatees.begin(), Dominatees.end(), Rand);
406 for (BasicBlock *Dominee : Dominatees) {
407 std::vector<Instruction *> Instructions;
408 for (Instruction &I : *Dominee)
409 Instructions.push_back(&I);
410 Sink = findSinkAndConnect(Instructions);
411 if (Sink) {
412 return Sink;
413 }
414 }
415 break;
416 }
417 case NewStore:
418 /// TODO: allocate a new stack memory.
419 return newSink(BB, Insts, V);
421 Module *M = BB.getModule();
422 auto [GV, DidCreate] =
424 return buildTargetLegalStore(V, GV, Insts.back()->getIterator(), M);
425 }
426 case EndOfValueSink:
427 default:
428 llvm_unreachable("EndOfValueSink executed");
429 }
430 }
431 llvm_unreachable("Can't find a sink");
432}
433
435 ArrayRef<Instruction *> Insts, Value *V) {
436 Value *Ptr = findPointer(BB, Insts);
437 if (!Ptr) {
438 if (uniform(Rand, 0, 1)) {
439 Type *Ty = V->getType();
440 Ptr = createStackMemory(BB.getParent(), Ty, PoisonValue::get(Ty));
441 } else {
442 Ptr = PoisonValue::get(PointerType::get(V->getContext(), 0));
443 }
444 }
445
446 return buildTargetLegalStore(V, Ptr, Insts.back()->getIterator(),
447 BB.getModule());
448}
449
452 auto IsMatchingPtr = [](Instruction *Inst) {
453 // Invoke instructions sometimes produce valid pointers but currently
454 // we can't insert loads or stores from them
455 if (Inst->isTerminator())
456 return false;
457
458 return Inst->getType()->isPointerTy();
459 };
460 if (auto RS = makeSampler(Rand, make_filter_range(Insts, IsMatchingPtr)))
461 return RS.getSelection();
462 return nullptr;
463}
464
466 uint64_t TyIdx = uniform<uint64_t>(Rand, 0, KnownTypes.size() - 1);
467 return KnownTypes[TyIdx];
468}
469
471 uint64_t ArgNum) {
472 Type *RetType = randomType();
473
475 for (uint64_t i = 0; i < ArgNum; i++) {
476 Args.push_back(randomType());
477 }
478
480 /*isVarArg=*/false),
482 return F;
483}
488
490 uint64_t ArgNum) {
491 Function *F = this->createFunctionDeclaration(M, ArgNum);
492
493 // TODO: Some arguments and a return value would probably be more
494 // interesting.
495 LLVMContext &Context = M.getContext();
496 const DataLayout &DL = M.getDataLayout();
497 BasicBlock *BB = BasicBlock::Create(Context, "BB", F);
498 Type *RetTy = F->getReturnType();
499 if (RetTy != Type::getVoidTy(Context)) {
500 Instruction *RetAlloca =
501 new AllocaInst(RetTy, DL.getAllocaAddrSpace(), "RP", BB);
502 Instruction *RetLoad = new LoadInst(RetTy, RetAlloca, "", BB);
503 ReturnInst::Create(Context, RetLoad, BB);
504 } else {
505 ReturnInst::Create(Context, BB);
506 }
507
508 return F;
509}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static bool isCompatibleReplacement(const Instruction *I, const Use &Operand, const Value *Replacement)
static Value * buildTargetLegalPtr(Module *M, Value *Ptr, InsertPosition IP, const Twine &Name, SmallVector< Instruction * > *NewInsts)
static void eraseNewInstructions(SmallVector< Instruction * > &NewInsts)
static std::pair< Instruction *, SmallVector< Instruction * > > buildTargetLegalLoad(Type *AccessTy, Value *Ptr, InsertPosition IP, Module *M, const Twine &LoadName)
static Instruction * buildTargetLegalStore(Value *Val, Value *Ptr, InsertPosition IP, Module *M)
static std::vector< BasicBlock * > getDominators(BasicBlock *BB)
Return a vector of Blocks that dominates this block, excluding current block.
static DominatorTree getDomTree(Function &F)
static std::vector< BasicBlock * > getDominatees(BasicBlock *BB)
Return a vector of Blocks that is dominated by this block, excluding current block.
This file contains some templates that are useful if you are working with the STL at all.
This class represents a conversion between pointers from one address space to another.
an instruction to allocate memory on the stack
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
const T & back() const
back - Get the last element.
Definition ArrayRef.h:151
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator end()
Definition BasicBlock.h:474
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
bool hasTerminator() const LLVM_READONLY
Returns whether the block has a terminator.
Definition BasicBlock.h:232
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition BasicBlock.h:206
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
LLVM_ABI const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
iterator_range< iterator > children()
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:159
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition Function.h:168
Module * getParent()
Get the module that this global value is contained inside of...
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition GlobalValue.h:52
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:286
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM_ABI unsigned getOperandNo() const
Return the operand # of this use in its User.
Definition Use.cpp:35
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
A matcher/generator for finding suitable values for the next source in an operation's partially compl...
self_iterator getIterator()
Definition ilist_node.h:123
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static SourcePred onlyType(Type *Only)
static SourcePred anyType()
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
DomTreeNodeBase< BasicBlock > DomTreeNode
Definition Dominators.h:94
ReservoirSampler< ElT, GenT > makeSampler(GenT &RandGen, RangeT &&Items)
Definition Random.h:75
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:552
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
Definition iterator.h:368
T uniform(GenT &Gen, T Min, T Max)
Return a uniformly distributed random value between Min and Max.
Definition Random.h:21
LLVM_ABI Function * createFunctionDeclaration(Module &M, uint64_t ArgNum)
SmallVector< Type *, 16 > KnownTypes
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 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 Instruction * newSink(BasicBlock &BB, ArrayRef< Instruction * > Insts, Value *V)
Create a user for V in BB.
LLVM_ABI Function * createFunctionDefinition(Module &M, uint64_t ArgNum)
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.
@ SinkToInstInCurBlock
TODO: Also consider pointers in function argument.
LLVM_ABI Value * findPointer(BasicBlock &BB, ArrayRef< Instruction * > Insts)
LLVM_ABI Type * randomType()
Return a uniformly choosen type from AllowedTypes.