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