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