17#ifndef LLVM_TRANSFORMS_UTILS_CLONING_H
18#define LLVM_TRANSFORMS_UTILS_CLONING_H
36class BlockFrequencyInfo;
44class PGOContextualProfile;
45class ProfileSummaryInfo;
57std::unique_ptr<Module>
59 function_ref<
bool(
const GlobalValue *)> ShouldCloneDefinition);
121 const Twine &NameSuffix =
"", Function *
F =
nullptr,
122 ClonedCodeInfo *CodeInfo =
nullptr);
136 ClonedCodeInfo *CodeInfo =
nullptr);
171 SmallVectorImpl<ReturnInst *> &Returns,
172 const char *NameSuffix =
"",
173 ClonedCodeInfo *CodeInfo =
nullptr,
174 ValueMapTypeRemapper *TypeMapper =
nullptr,
175 ValueMaterializer *Materializer =
nullptr);
181 bool ModuleLevelChanges,
182 ValueMapTypeRemapper *TypeMapper =
nullptr,
183 ValueMaterializer *Materializer =
nullptr);
195 ValueMapTypeRemapper *TypeMapper =
nullptr,
196 ValueMaterializer *Materializer =
nullptr,
202 SmallVectorImpl<ReturnInst *> &Returns,
203 const char *NameSuffix =
"",
204 ClonedCodeInfo *CodeInfo =
nullptr,
205 ValueMapTypeRemapper *TypeMapper =
nullptr,
206 ValueMaterializer *Materializer =
nullptr,
210 const Instruction *StartingInst,
212 SmallVectorImpl<ReturnInst *> &Returns,
213 const char *NameSuffix =
"",
214 ClonedCodeInfo *CodeInfo =
nullptr);
229 SmallVectorImpl<ReturnInst*> &Returns,
230 const char *NameSuffix =
"",
231 ClonedCodeInfo *CodeInfo =
nullptr);
245 DebugInfoFinder &DIFinder);
263 DebugInfoFinder &DIFinder,
264 DISubprogram *SPClonedWithinModule);
333 bool MergeAttributes =
false,
334 AAResults *CalleeAAR =
nullptr,
335 bool InsertLifetime =
true,
336 Function *ForwardVarArgsTo =
nullptr);
343 PGOContextualProfile &CtxProf,
344 bool MergeAttributes =
false,
345 AAResults *CalleeAAR =
nullptr,
346 bool InsertLifetime =
true,
347 Function *ForwardVarArgsTo =
nullptr);
357 const Twine &NameSuffix, LoopInfo *LI,
359 SmallVectorImpl<BasicBlock *> &
Blocks);
375 DomTreeUpdater &DTU);
381 Function *Callee, int64_t EntryDelta,
382 const ValueMap<const Value *, WeakTrackingVH> *VMap =
nullptr);
388 ArrayRef<BasicBlock *> BBs, SmallVectorImpl<MDNode *> &NoAliasDeclScopes);
395 SmallVectorImpl<MDNode *> &NoAliasDeclScopes);
403 ArrayRef<MDNode *> NoAliasDeclScopes,
404 DenseMap<MDNode *, MDNode *> &ClonedScopes,
405 StringRef Ext, LLVMContext &Context);
412 LLVMContext &Context);
418 ArrayRef<BasicBlock *> NewBlocks,
419 LLVMContext &Context, StringRef Ext);
425 Instruction *IStart, Instruction *IEnd,
426 LLVMContext &Context, StringRef Ext);
BlockVerifier::State From
DenseMap< Block *, BlockRelaxAux > Blocks
Machine Check Debug Module
This file defines the SmallVector class.
A cache of @llvm.assume calls within a function.
InstListType::iterator iterator
Instruction iterators...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
This class captures the data input to the InlineFunction call, and records the auxiliary results prod...
bool UpdateProfile
Update profile for callee as well as cloned version.
function_ref< AssumptionCache &(Function &)> GetAssumptionCache
If non-null, InlineFunction will update the callgraph to reflect the changes it makes.
BlockFrequencyInfo * CalleeBFI
SmallVector< AllocaInst *, 4 > StaticAllocas
InlineFunction fills this in with all static allocas that get copied into the caller.
InlineFunctionInfo(function_ref< AssumptionCache &(Function &)> GetAssumptionCache=nullptr, ProfileSummaryInfo *PSI=nullptr, BlockFrequencyInfo *CallerBFI=nullptr, BlockFrequencyInfo *CalleeBFI=nullptr, bool UpdateProfile=true)
BlockFrequencyInfo * CallerBFI
SmallVector< WeakTrackingVH, 8 > InlinedCalls
InlineFunction fills this in with callsites that were inlined from the callee.
SmallVector< CallBase *, 8 > InlinedCallSites
All of the new call sites inlined into the caller.
Analysis providing profile information.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
void CloneFunctionAttributesInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Clone OldFunc's attributes into NewFunc, transforming values based on the mappings in VMap.
BasicBlock * DuplicateInstructionsInSplitBetween(BasicBlock *BB, BasicBlock *PredBB, Instruction *StopAt, ValueToValueMapTy &ValueMapping, DomTreeUpdater &DTU)
Split edge between BB and PredBB and duplicate all non-Phi instructions from BB between its beginning...
Loop * cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB, Loop *OrigLoop, ValueToValueMapTy &VMap, const Twine &NameSuffix, LoopInfo *LI, DominatorTree *DT, SmallVectorImpl< BasicBlock * > &Blocks)
Clones a loop OrigLoop.
RemapFlags
These are flags that the value mapping APIs allow.
void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr)
This works exactly like CloneFunctionInto, except that it does some simple constant prop and DCE on t...
void cloneNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, DenseMap< MDNode *, MDNode * > &ClonedScopes, StringRef Ext, LLVMContext &Context)
Duplicate the specified list of noalias decl scopes.
MetadataSetTy FindDebugInfoToIdentityMap(CloneFunctionChangeType Changes, DebugInfoFinder &DIFinder, DISubprogram *SPClonedWithinModule)
Based on Changes and DIFinder return debug info that needs to be identity mapped during Metadata clon...
void CloneFunctionMetadataInto(Function &NewFunc, const Function &OldFunc, ValueToValueMapTy &VMap, RemapFlags RemapFlag, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataSetTy *IdentityMD=nullptr)
Clone OldFunc's metadata into NewFunc.
BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
void updateProfileCallee(Function *Callee, int64_t EntryDelta, const ValueMap< const Value *, WeakTrackingVH > *VMap=nullptr)
Updates profile information by adjusting the entry count by adding EntryDelta then scaling callsite i...
void adaptNoAliasScopes(llvm::Instruction *I, const DenseMap< MDNode *, MDNode * > &ClonedScopes, LLVMContext &Context)
Adapt the metadata for the specified instruction according to the provided mapping.
InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, Function *ForwardVarArgsTo=nullptr)
This function inlines the called function into the basic block of the caller.
void cloneAndAdaptNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, ArrayRef< BasicBlock * > NewBlocks, LLVMContext &Context, StringRef Ext)
Clone the specified noalias decl scopes.
void remapInstructionsInBlocks(ArrayRef< BasicBlock * > Blocks, ValueToValueMapTy &VMap)
Remaps instructions in Blocks using the mapping in VMap.
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, CloneFunctionChangeType Changes, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Clone OldFunc into NewFunc, transforming the old arguments into references to VMap values.
DISubprogram * CollectDebugInfoForCloning(const Function &F, CloneFunctionChangeType Changes, DebugInfoFinder &DIFinder)
Collect debug information such as types, compile units, and other subprograms that are reachable from...
void identifyNoAliasScopesToClone(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< MDNode * > &NoAliasDeclScopes)
Find the 'llvm.experimental.noalias.scope.decl' intrinsics in the specified basic blocks and extract ...
std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
void CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc, const Instruction *StartingInst, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr)
This works like CloneAndPruneFunctionInto, except that it does not clone the entire function.
Function * CloneFunction(Function *F, ValueToValueMapTy &VMap, ClonedCodeInfo *CodeInfo=nullptr)
Return a copy of the specified function and add it to that function's module.
SmallPtrSet< const Metadata *, 16 > MetadataSetTy
void CloneFunctionBodyInto(Function &NewFunc, const Function &OldFunc, ValueToValueMapTy &VMap, RemapFlags RemapFlag, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataSetTy *IdentityMD=nullptr)
Clone OldFunc's body into NewFunc.
This struct can be used to capture information about code being cloned, while it is being cloned.
bool ContainsDynamicAllocas
This is set to true if the cloned code contains a 'dynamic' alloca.
bool isSimplified(const Value *From, const Value *To) const
bool ContainsCalls
This is set to true if the cloned code contains a normal call instruction.
bool ContainsMemProfMetadata
This is set to true if there is memprof related metadata (memprof or callsite metadata) in the cloned...
DenseMap< const Value *, const Value * > OrigVMap
Like VMap, but maps only unsimplified instructions.
std::vector< WeakTrackingVH > OperandBundleCallSites
All cloned call sites that have operand bundles attached are appended to this vector.