LLVM 23.0.0git
Cloning.h
Go to the documentation of this file.
1//===- Cloning.h - Clone various parts of LLVM programs ---------*- C++ -*-===//
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//
9// This file defines various functions that are used to clone chunks of LLVM
10// code for various purposes. This varies from copying whole modules into new
11// modules, to cloning functions with different arguments, to inlining
12// functions, to copying basic blocks to support loop unrolling or superblock
13// formation, etc.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_TRANSFORMS_UTILS_CLONING_H
18#define LLVM_TRANSFORMS_UTILS_CLONING_H
19
20#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/Twine.h"
26#include "llvm/IR/BasicBlock.h"
27#include "llvm/IR/DebugLoc.h"
28#include "llvm/IR/ValueHandle.h"
31#include <functional>
32#include <memory>
33#include <vector>
34
35namespace llvm {
36
37class AAResults;
38class AllocaInst;
39class BasicBlock;
41class DebugInfoFinder;
42class DominatorTree;
43class Function;
44class Instruction;
45class Loop;
46class LoopInfo;
47class Module;
51class ReturnInst;
52class DomTreeUpdater;
53
54/// Return an exact copy of the specified module
55LLVM_ABI std::unique_ptr<Module> CloneModule(const Module &M);
56LLVM_ABI std::unique_ptr<Module> CloneModule(const Module &M,
57 ValueToValueMapTy &VMap);
58
59/// Return a copy of the specified module. The ShouldCloneDefinition function
60/// controls whether a specific GlobalValue's definition is cloned. If the
61/// function returns false, the module copy will contain an external reference
62/// in place of the global definition.
63LLVM_ABI std::unique_ptr<Module>
65 function_ref<bool(const GlobalValue *)> ShouldCloneDefinition);
66
67/// This struct can be used to capture information about code
68/// being cloned, while it is being cloned.
70 /// This is set to true if the cloned code contains a normal call instruction.
71 bool ContainsCalls = false;
72
73 /// This is set to true if there is memprof related metadata (memprof or
74 /// callsite metadata) in the cloned code.
76
77 /// This is set to true if the cloned code contains a 'dynamic' alloca.
78 /// Dynamic allocas are allocas that are either not in the entry block or they
79 /// are in the entry block but are not a constant size.
81
82 /// All cloned call sites that have operand bundles attached are appended to
83 /// this vector. This vector may contain nulls or undefs if some of the
84 /// originally inserted callsites were DCE'ed after they were cloned.
85 std::vector<WeakTrackingVH> OperandBundleCallSites;
86
87 /// Like VMap, but maps only unsimplified instructions. Values in the map
88 /// may be dangling, it is only intended to be used via isSimplified(), to
89 /// check whether the main VMap mapping involves simplification or not.
91
92 // Cloned calls that were originally an indirect call. They may be direct or
93 // indirect after cloning.
95
96 ClonedCodeInfo() = default;
97
98 bool isSimplified(const Value *From, const Value *To) const {
99 return OrigVMap.lookup(From) != To;
100 }
101};
102
103/// Return a copy of the specified basic block, but without
104/// embedding the block into a particular function. The block returned is an
105/// exact copy of the specified basic block, without any remapping having been
106/// performed. Because of this, this is only suitable for applications where
107/// the basic block will be inserted into the same function that it was cloned
108/// from (loop unrolling would use this, for example).
109///
110/// Also, note that this function makes a direct copy of the basic block, and
111/// can thus produce illegal LLVM code. In particular, it will copy any PHI
112/// nodes from the original block, even though there are no predecessors for the
113/// newly cloned block (thus, phi nodes will have to be updated). Also, this
114/// block will branch to the old successors of the original block: these
115/// successors will have to have any PHI nodes updated to account for the new
116/// incoming edges.
117///
118/// The correlation between instructions in the source and result basic blocks
119/// is recorded in the VMap map.
120///
121/// If you have a particular suffix you'd like to use to add to any cloned
122/// names, specify it as the optional third parameter.
123///
124/// If you would like the basic block to be auto-inserted into the end of a
125/// function, you can specify it as the optional fourth parameter.
126///
127/// If you would like to collect additional information about the cloned
128/// function, you can specify a ClonedCodeInfo object with the optional fifth
129/// parameter.
130///
131/// \p MapAtoms indicates whether source location atoms should be mapped for
132/// later remapping. Must be true when you duplicate a code path and a source
133/// location is intended to appear twice in the generated instructions. Can be
134/// set to false if you are transplanting code from one place to another.
135/// Setting true (default) is always safe (won't produce incorrect debug info)
136/// but is sometimes unnecessary, causing extra work that could be avoided by
137/// setting the parameter to false.
138LLVM_ABI BasicBlock *
139CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,
140 const Twine &NameSuffix = "", Function *F = nullptr,
141 ClonedCodeInfo *CodeInfo = nullptr, bool MapAtoms = true);
142
143/// Mark a cloned instruction as a new instance so that its source loc can
144/// be updated when remapped.
146
147/// Return a copy of the specified function and add it to that
148/// function's module. Also, any references specified in the VMap are changed
149/// to refer to their mapped value instead of the original one. If any of the
150/// arguments to the function are in the VMap, the arguments are deleted from
151/// the resultant function. The VMap is updated to include mappings from all of
152/// the instructions and basicblocks in the function from their old to new
153/// values. The final argument captures information about the cloned code if
154/// non-null.
155///
156/// \pre VMap contains no non-identity GlobalValue mappings.
157///
158LLVM_ABI Function *CloneFunction(Function *F, ValueToValueMapTy &VMap,
159 ClonedCodeInfo *CodeInfo = nullptr);
160
167
168/// Clone OldFunc into NewFunc, transforming the old arguments into references
169/// to VMap values. Note that if NewFunc already has basic blocks, the ones
170/// cloned into it will be added to the end of the function. This function
171/// fills in a list of return instructions, and can optionally remap types
172/// and/or append the specified suffix to all values cloned.
173///
174/// If \p Changes is \a CloneFunctionChangeType::LocalChangesOnly, VMap is
175/// required to contain no non-identity GlobalValue mappings. Otherwise,
176/// referenced metadata will be cloned.
177///
178/// If \p Changes is less than \a CloneFunctionChangeType::DifferentModule
179/// indicating cloning into the same module (even if it's LocalChangesOnly), if
180/// debug info metadata transitively references a \a DISubprogram, it will be
181/// cloned, effectively upgrading \p Changes to GlobalChanges while suppressing
182/// cloning of types and compile units.
183///
184/// If \p Changes is \a CloneFunctionChangeType::DifferentModule, the new
185/// module's \c !llvm.dbg.cu will get updated with any newly created compile
186/// units. (\a CloneFunctionChangeType::ClonedModule leaves that work for the
187/// caller.)
188///
189/// FIXME: Consider simplifying this function by splitting out \a
190/// CloneFunctionMetadataInto() and expecting / updating callers to call it
191/// first when / how it's needed.
192LLVM_ABI void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
193 ValueToValueMapTy &VMap,
195 SmallVectorImpl<ReturnInst *> &Returns,
196 const char *NameSuffix = "",
197 ClonedCodeInfo *CodeInfo = nullptr,
198 ValueMapTypeRemapper *TypeMapper = nullptr,
199 ValueMaterializer *Materializer = nullptr);
200
201/// Clone OldFunc's attributes into NewFunc, transforming values based on the
202/// mappings in VMap.
203LLVM_ABI void
204CloneFunctionAttributesInto(Function *NewFunc, const Function *OldFunc,
205 ValueToValueMapTy &VMap, bool ModuleLevelChanges,
206 ValueMapTypeRemapper *TypeMapper = nullptr,
207 ValueMaterializer *Materializer = nullptr);
208
209/// Clone OldFunc's metadata into NewFunc.
210///
211/// The caller is expected to populate \p VMap beforehand and set an appropriate
212/// \p RemapFlag. Subprograms/CUs/types that were already mapped to themselves
213/// won't be duplicated.
214///
215/// NOTE: This function doesn't clone !llvm.dbg.cu when cloning into a different
216/// module. Use CloneFunctionInto for that behavior.
217LLVM_ABI void
218CloneFunctionMetadataInto(Function &NewFunc, const Function &OldFunc,
219 ValueToValueMapTy &VMap, RemapFlags RemapFlag,
220 ValueMapTypeRemapper *TypeMapper = nullptr,
221 ValueMaterializer *Materializer = nullptr,
222 const MetadataPredicate *IdentityMD = nullptr);
223
224/// Clone OldFunc's body into NewFunc.
226 Function &NewFunc, const Function &OldFunc, ValueToValueMapTy &VMap,
227 RemapFlags RemapFlag, SmallVectorImpl<ReturnInst *> &Returns,
228 const char *NameSuffix = "", ClonedCodeInfo *CodeInfo = nullptr,
229 ValueMapTypeRemapper *TypeMapper = nullptr,
230 ValueMaterializer *Materializer = nullptr,
231 const MetadataPredicate *IdentityMD = nullptr);
232
233LLVM_ABI void
234CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
235 const Instruction *StartingInst,
236 ValueToValueMapTy &VMap, bool ModuleLevelChanges,
237 SmallVectorImpl<ReturnInst *> &Returns,
238 const char *NameSuffix, ClonedCodeInfo &CodeInfo);
239
240/// This works exactly like CloneFunctionInto,
241/// except that it does some simple constant prop and DCE on the fly. The
242/// effect of this is to copy significantly less code in cases where (for
243/// example) a function call with constant arguments is inlined, and those
244/// constant arguments cause a significant amount of code in the callee to be
245/// dead. Since this doesn't produce an exactly copy of the input, it can't be
246/// used for things like CloneFunction or CloneModule.
247///
248/// If ModuleLevelChanges is false, VMap contains no non-identity GlobalValue
249/// mappings.
250///
251LLVM_ABI void
252CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
253 ValueToValueMapTy &VMap, bool ModuleLevelChanges,
254 SmallVectorImpl<ReturnInst *> &Returns,
255 const char *NameSuffix, ClonedCodeInfo &CodeInfo);
256
257/// This class captures the data input to the InlineFunction call, and records
258/// the auxiliary results produced by it.
260public:
268
269 /// If non-null, InlineFunction will update the callgraph to reflect the
270 /// changes it makes.
274
275 /// InlineFunction fills this in with all static allocas that get copied into
276 /// the caller.
278
279 /// All of the new call sites inlined into the caller.
280 ///
281 /// 'InlineFunction' fills this in by scanning the inlined instructions.
283
286
287 /// Update profile for callee as well as cloned version. We need to do this
288 /// for regular inlining, but not for inlining from sample profile loader.
290
291 void reset() {
292 StaticAllocas.clear();
293 InlinedCallSites.clear();
294 ConvergenceControlToken = nullptr;
295 CallSiteEHPad = nullptr;
296 }
297};
298
299/// Check if it is legal to perform inlining of the function called by \p CB
300/// into the caller at this particular use, and sets fields in \p IFI.
301///
302/// This does not consider whether it is possible for the function callee itself
303/// to be inlined; for that see isInlineViable.
304LLVM_ABI InlineResult CanInlineCallSite(const CallBase &CB,
305 InlineFunctionInfo &IFI);
306
307/// This should generally not be used, use InlineFunction instead.
308///
309/// Perform mechanical inlining of \p CB into the caller.
310///
311/// This does not perform any legality or profitability checks for the
312/// inlining. This assumes that CanInlineCallSite was already called, populated
313/// \p IFI, and returned InlineResult::success.
314///
315/// Also assumes that isInlineViable returned InlineResult::success for the
316/// called function.
317LLVM_ABI void InlineFunctionImpl(CallBase &CB, InlineFunctionInfo &IFI,
318 bool MergeAttributes = false,
319 AAResults *CalleeAAR = nullptr,
320 bool InsertLifetime = true,
321 bool TrackInlineHistory = false,
322 Function *ForwardVarArgsTo = nullptr,
323 OptimizationRemarkEmitter *ORE = nullptr);
324
325/// This function inlines the called function into the basic
326/// block of the caller. This returns false if it is not possible to inline
327/// this call. The program is still in a well defined state if this occurs
328/// though.
329///
330/// Note that this only does one level of inlining. For example, if the
331/// instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now
332/// exists in the instruction stream. Similarly this will inline a recursive
333/// function by one level.
334///
335/// Note that while this routine is allowed to cleanup and optimize the
336/// *inlined* code to minimize the actual inserted code, it must not delete
337/// code in the caller as users of this routine may have pointers to
338/// instructions in the caller that need to remain stable.
339///
340/// If ForwardVarArgsTo is passed, inlining a function with varargs is allowed
341/// and all varargs at the callsite will be passed to any calls to
342/// ForwardVarArgsTo. The caller of InlineFunction has to make sure any varargs
343/// are only used by ForwardVarArgsTo.
344///
345/// The callee's function attributes are merged into the callers' if
346/// MergeAttributes is set to true.
347LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
348 bool MergeAttributes = false,
349 AAResults *CalleeAAR = nullptr,
350 bool InsertLifetime = true,
351 bool TrackInlineHistory = false,
352 Function *ForwardVarArgsTo = nullptr,
353 OptimizationRemarkEmitter *ORE = nullptr);
354
355/// Same as above, but it will update the contextual profile. If the contextual
356/// profile is invalid (i.e. not loaded because it is not present), it defaults
357/// to the behavior of the non-contextual profile updating variant above. This
358/// makes it easy to drop-in replace uses of the non-contextual overload.
359LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
360 PGOContextualProfile &CtxProf,
361 bool MergeAttributes = false,
362 AAResults *CalleeAAR = nullptr,
363 bool InsertLifetime = true,
364 bool TrackInlineHistory = false,
365 Function *ForwardVarArgsTo = nullptr,
366 OptimizationRemarkEmitter *ORE = nullptr);
367
368/// Clones a loop \p OrigLoop. Returns the loop and the blocks in \p
369/// Blocks.
370///
371/// Updates LoopInfo and DominatorTree assuming the loop is dominated by block
372/// \p LoopDomBB. Insert the new blocks before block specified in \p Before.
373/// Note: Only innermost loops are supported.
374LLVM_ABI Loop *cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB,
375 Loop *OrigLoop, ValueToValueMapTy &VMap,
376 const Twine &NameSuffix, LoopInfo *LI,
377 DominatorTree *DT,
378 SmallVectorImpl<BasicBlock *> &Blocks);
379
380/// Remaps instructions in \p Blocks using the mapping in \p VMap.
382 ValueToValueMapTy &VMap);
383
384/// Split edge between BB and PredBB and duplicate all non-Phi instructions
385/// from BB between its beginning and the StopAt instruction into the split
386/// block. Phi nodes are not duplicated, but their uses are handled correctly:
387/// we replace them with the uses of corresponding Phi inputs. ValueMapping
388/// is used to map the original instructions from BB to their newly-created
389/// copies. Returns the split block.
391 BasicBlock *BB, BasicBlock *PredBB, Instruction *StopAt,
392 ValueToValueMapTy &ValueMapping, DomTreeUpdater &DTU);
393
394/// Updates profile information by adjusting the entry count by adding
395/// EntryDelta then scaling callsite information by the new count divided by the
396/// old count. VMap is used during inlinng to also update the new clone
398 Function *Callee, int64_t EntryDelta,
399 const ValueMap<const Value *, WeakTrackingVH> *VMap = nullptr);
400
401/// Find the 'llvm.experimental.noalias.scope.decl' intrinsics in the specified
402/// basic blocks and extract their scope. These are candidates for duplication
403/// when cloning.
404LLVM_ABI void
406 SmallVectorImpl<MDNode *> &NoAliasDeclScopes);
407
408/// Find the 'llvm.experimental.noalias.scope.decl' intrinsics in the specified
409/// instruction range and extract their scope. These are candidates for
410/// duplication when cloning.
411LLVM_ABI void
414 SmallVectorImpl<MDNode *> &NoAliasDeclScopes);
415
416/// Duplicate the specified list of noalias decl scopes.
417/// The 'Ext' string is added as an extension to the name.
418/// Afterwards, the ClonedScopes contains the mapping of the original scope
419/// MDNode onto the cloned scope.
420/// Be aware that the cloned scopes are still part of the original scope domain.
421LLVM_ABI void cloneNoAliasScopes(ArrayRef<MDNode *> NoAliasDeclScopes,
422 DenseMap<MDNode *, MDNode *> &ClonedScopes,
423 StringRef Ext, LLVMContext &Context);
424
425/// Adapt the metadata for the specified instruction according to the
426/// provided mapping. This is normally used after cloning an instruction, when
427/// some noalias scopes needed to be cloned.
428LLVM_ABI void
430 const DenseMap<MDNode *, MDNode *> &ClonedScopes,
431 LLVMContext &Context);
432
433/// Clone the specified noalias decl scopes. Then adapt all instructions in the
434/// NewBlocks basicblocks to the cloned versions.
435/// 'Ext' will be added to the duplicate scope names.
437 ArrayRef<BasicBlock *> NewBlocks,
438 LLVMContext &Context, StringRef Ext);
439
440/// Clone the specified noalias decl scopes. Then adapt all instructions in the
441/// [IStart, IEnd] (IEnd included !) range to the cloned versions. 'Ext' will be
442/// added to the duplicate scope names.
444 Instruction *IStart, Instruction *IEnd,
445 LLVMContext &Context, StringRef Ext);
446} // end namespace llvm
447
448#endif // LLVM_TRANSFORMS_UTILS_CLONING_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:213
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
an instruction to allocate memory on the stack
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Utility to find all debug info in a module.
Definition DebugInfo.h:105
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:159
Value * ConvergenceControlToken
Definition Cloning.h:284
ProfileSummaryInfo * PSI
Definition Cloning.h:272
bool UpdateProfile
Update profile for callee as well as cloned version.
Definition Cloning.h:289
Instruction * CallSiteEHPad
Definition Cloning.h:285
function_ref< AssumptionCache &(Function &)> GetAssumptionCache
If non-null, InlineFunction will update the callgraph to reflect the changes it makes.
Definition Cloning.h:271
BlockFrequencyInfo * CalleeBFI
Definition Cloning.h:273
SmallVector< AllocaInst *, 4 > StaticAllocas
InlineFunction fills this in with all static allocas that get copied into the caller.
Definition Cloning.h:277
InlineFunctionInfo(function_ref< AssumptionCache &(Function &)> GetAssumptionCache=nullptr, ProfileSummaryInfo *PSI=nullptr, BlockFrequencyInfo *CallerBFI=nullptr, BlockFrequencyInfo *CalleeBFI=nullptr, bool UpdateProfile=true)
Definition Cloning.h:261
BlockFrequencyInfo * CallerBFI
Definition Cloning.h:273
SmallVector< CallBase *, 8 > InlinedCallSites
All of the new call sites inlined into the caller.
Definition Cloning.h:282
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
The optimization diagnostic interface.
The instrumented contextual profile, produced by the CtxProfAnalysis.
Analysis providing profile information.
Return a value (possibly void), from a function.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
Definition Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI 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.
std::function< bool(const Metadata *)> MetadataPredicate
Definition ValueMapper.h:41
static cl::opt< unsigned long > StopAt("sbvec-stop-at", cl::init(StopAtDisabled), cl::Hidden, cl::desc("Vectorize if the invocation count is < than this. 0 " "disables vectorization."))
LLVM_ABI BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, bool MapAtoms=true)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
LLVM_ABI void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix, ClonedCodeInfo &CodeInfo)
This works exactly like CloneFunctionInto, except that it does some simple constant prop and DCE on t...
LLVM_ABI 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...
LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, bool TrackInlineHistory=false, Function *ForwardVarArgsTo=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
This function inlines the called function into the basic block of the caller.
LLVM_ABI InlineResult CanInlineCallSite(const CallBase &CB, InlineFunctionInfo &IFI)
Check if it is legal to perform inlining of the function called by CB into the caller at this particu...
LLVM_ABI void CloneFunctionMetadataInto(Function &NewFunc, const Function &OldFunc, ValueToValueMapTy &VMap, RemapFlags RemapFlag, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataPredicate *IdentityMD=nullptr)
Clone OldFunc's metadata into NewFunc.
LLVM_ABI 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.
Definition ValueMapper.h:74
LLVM_ABI void cloneNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, DenseMap< MDNode *, MDNode * > &ClonedScopes, StringRef Ext, LLVMContext &Context)
Duplicate the specified list of noalias decl scopes.
LLVM_ABI 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 MetadataPredicate *IdentityMD=nullptr)
Clone OldFunc's body into NewFunc.
LLVM_ABI 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...
LLVM_ABI void InlineFunctionImpl(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, bool TrackInlineHistory=false, Function *ForwardVarArgsTo=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
This should generally not be used, use InlineFunction instead.
LLVM_ABI void CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc, const Instruction *StartingInst, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix, ClonedCodeInfo &CodeInfo)
This works like CloneAndPruneFunctionInto, except that it does not clone the entire function.
LLVM_ABI void adaptNoAliasScopes(llvm::Instruction *I, const DenseMap< MDNode *, MDNode * > &ClonedScopes, LLVMContext &Context)
Adapt the metadata for the specified instruction according to the provided mapping.
LLVM_ABI void cloneAndAdaptNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, ArrayRef< BasicBlock * > NewBlocks, LLVMContext &Context, StringRef Ext)
Clone the specified noalias decl scopes.
LLVM_ABI void remapInstructionsInBlocks(ArrayRef< BasicBlock * > Blocks, ValueToValueMapTy &VMap)
Remaps instructions in Blocks using the mapping in VMap.
ArrayRef(const T &OneElt) -> ArrayRef< T >
CloneFunctionChangeType
Definition Cloning.h:161
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
LLVM_ABI 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.
LLVM_ABI void identifyNoAliasScopesToClone(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< MDNode * > &NoAliasDeclScopes)
Find the 'llvm.experimental.noalias.scope.decl' intrinsics in the specified basic blocks and extract ...
LLVM_ABI std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
LLVM_ABI Function * CloneFunction(Function *F, ValueToValueMapTy &VMap, ClonedCodeInfo *CodeInfo=nullptr)
Return a copy of the specified function and add it to that function's module.
LLVM_ABI void mapAtomInstance(const DebugLoc &DL, ValueToValueMapTy &VMap)
Mark a cloned instruction as a new instance so that its source loc can be updated when remapped.
ClonedCodeInfo()=default
bool ContainsDynamicAllocas
This is set to true if the cloned code contains a 'dynamic' alloca.
Definition Cloning.h:80
bool isSimplified(const Value *From, const Value *To) const
Definition Cloning.h:98
bool ContainsCalls
This is set to true if the cloned code contains a normal call instruction.
Definition Cloning.h:71
bool ContainsMemProfMetadata
This is set to true if there is memprof related metadata (memprof or callsite metadata) in the cloned...
Definition Cloning.h:75
SmallPtrSet< const Value *, 4 > OriginallyIndirectCalls
Definition Cloning.h:94
DenseMap< const Value *, const Value * > OrigVMap
Like VMap, but maps only unsimplified instructions.
Definition Cloning.h:90
std::vector< WeakTrackingVH > OperandBundleCallSites
All cloned call sites that have operand bundles attached are appended to this vector.
Definition Cloning.h:85