LLVM 24.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"
21#include "llvm/ADT/DenseSet.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 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 // Cloned calls that were originally an indirect call. They may be direct or
92 // indirect after cloning.
94
95 ClonedCodeInfo() = default;
96
97 bool isSimplified(const Value *From, const Value *To) const {
98 return OrigVMap.lookup(From) != To;
99 }
100
101 bool isOriginallyIndirectCall(const Value *V) const {
102 return OriginallyIndirectCalls.find_as(V) != OriginallyIndirectCalls.end();
103 }
104
106 if (auto It = OriginallyIndirectCalls.find_as(V);
107 It != OriginallyIndirectCalls.end()) {
108 OriginallyIndirectCalls.erase(It);
109 return true;
110 }
111 return false;
112 }
113
114 void replaceOriginallyIndirectCall(const Value *Old, const Value *New) {
116 OriginallyIndirectCalls.insert(New);
117 }
118};
119
120/// Return a copy of the specified basic block, but without
121/// embedding the block into a particular function. The block returned is an
122/// exact copy of the specified basic block, without any remapping having been
123/// performed. Because of this, this is only suitable for applications where
124/// the basic block will be inserted into the same function that it was cloned
125/// from (loop unrolling would use this, for example).
126///
127/// Also, note that this function makes a direct copy of the basic block, and
128/// can thus produce illegal LLVM code. In particular, it will copy any PHI
129/// nodes from the original block, even though there are no predecessors for the
130/// newly cloned block (thus, phi nodes will have to be updated). Also, this
131/// block will branch to the old successors of the original block: these
132/// successors will have to have any PHI nodes updated to account for the new
133/// incoming edges.
134///
135/// The correlation between instructions in the source and result basic blocks
136/// is recorded in the VMap map.
137///
138/// If you have a particular suffix you'd like to use to add to any cloned
139/// names, specify it as the optional third parameter.
140///
141/// If you would like the basic block to be auto-inserted into the end of a
142/// function, you can specify it as the optional fourth parameter.
143///
144/// If you would like to collect additional information about the cloned
145/// function, you can specify a ClonedCodeInfo object with the optional fifth
146/// parameter.
147///
148/// \p MapAtoms indicates whether source location atoms should be mapped for
149/// later remapping. Must be true when you duplicate a code path and a source
150/// location is intended to appear twice in the generated instructions. Can be
151/// set to false if you are transplanting code from one place to another.
152/// Setting true (default) is always safe (won't produce incorrect debug info)
153/// but is sometimes unnecessary, causing extra work that could be avoided by
154/// setting the parameter to false.
155LLVM_ABI BasicBlock *
156CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,
157 const Twine &NameSuffix = "", Function *F = nullptr,
158 ClonedCodeInfo *CodeInfo = nullptr, bool MapAtoms = true);
159
160/// Mark a cloned instruction as a new instance so that its source loc can
161/// be updated when remapped.
163
164/// Return a copy of the specified function and add it to that
165/// function's module. Also, any references specified in the VMap are changed
166/// to refer to their mapped value instead of the original one. If any of the
167/// arguments to the function are in the VMap, the arguments are deleted from
168/// the resultant function. The VMap is updated to include mappings from all of
169/// the instructions and basicblocks in the function from their old to new
170/// values. The final argument captures information about the cloned code if
171/// non-null.
172///
173/// \pre VMap contains no non-identity GlobalValue mappings.
174///
176 ClonedCodeInfo *CodeInfo = nullptr);
177
184
185/// Clone OldFunc into NewFunc, transforming the old arguments into references
186/// to VMap values. Note that if NewFunc already has basic blocks, the ones
187/// cloned into it will be added to the end of the function. This function
188/// fills in a list of return instructions, and can optionally remap types
189/// and/or append the specified suffix to all values cloned.
190///
191/// If \p Changes is \a CloneFunctionChangeType::LocalChangesOnly, VMap is
192/// required to contain no non-identity GlobalValue mappings. Otherwise,
193/// referenced metadata will be cloned.
194///
195/// If \p Changes is less than \a CloneFunctionChangeType::DifferentModule
196/// indicating cloning into the same module (even if it's LocalChangesOnly), if
197/// debug info metadata transitively references a \a DISubprogram, it will be
198/// cloned, effectively upgrading \p Changes to GlobalChanges while suppressing
199/// cloning of types and compile units.
200///
201/// If \p Changes is \a CloneFunctionChangeType::DifferentModule, the new
202/// module's \c !llvm.dbg.cu will get updated with any newly created compile
203/// units. (\a CloneFunctionChangeType::ClonedModule leaves that work for the
204/// caller.)
205///
206/// FIXME: Consider simplifying this function by splitting out \a
207/// CloneFunctionMetadataInto() and expecting / updating callers to call it
208/// first when / how it's needed.
209LLVM_ABI void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
210 ValueToValueMapTy &VMap,
212 SmallVectorImpl<ReturnInst *> &Returns,
213 const char *NameSuffix = "",
214 ClonedCodeInfo *CodeInfo = nullptr,
215 ValueMapTypeRemapper *TypeMapper = nullptr,
216 ValueMaterializer *Materializer = nullptr);
217
218/// Clone OldFunc's attributes into NewFunc, transforming values based on the
219/// mappings in VMap.
220LLVM_ABI void
221CloneFunctionAttributesInto(Function *NewFunc, const Function *OldFunc,
222 ValueToValueMapTy &VMap, bool ModuleLevelChanges,
223 ValueMapTypeRemapper *TypeMapper = nullptr,
224 ValueMaterializer *Materializer = nullptr);
225
226/// Clone OldFunc's metadata into NewFunc.
227///
228/// The caller is expected to populate \p VMap beforehand and set an appropriate
229/// \p RemapFlag. Subprograms/CUs/types that were already mapped to themselves
230/// won't be duplicated.
231///
232/// NOTE: This function doesn't clone !llvm.dbg.cu when cloning into a different
233/// module. Use CloneFunctionInto for that behavior.
234LLVM_ABI void
235CloneFunctionMetadataInto(Function &NewFunc, const Function &OldFunc,
236 ValueToValueMapTy &VMap, RemapFlags RemapFlag,
237 ValueMapTypeRemapper *TypeMapper = nullptr,
238 ValueMaterializer *Materializer = nullptr,
239 const MetadataPredicate *IdentityMD = nullptr);
240
241/// Clone OldFunc's body into NewFunc.
243 Function &NewFunc, const Function &OldFunc, ValueToValueMapTy &VMap,
244 RemapFlags RemapFlag, SmallVectorImpl<ReturnInst *> &Returns,
245 const char *NameSuffix = "", ClonedCodeInfo *CodeInfo = nullptr,
246 ValueMapTypeRemapper *TypeMapper = nullptr,
247 ValueMaterializer *Materializer = nullptr,
248 const MetadataPredicate *IdentityMD = nullptr);
249
250LLVM_ABI void
251CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
252 const Instruction *StartingInst,
253 ValueToValueMapTy &VMap, bool ModuleLevelChanges,
254 SmallVectorImpl<ReturnInst *> &Returns,
255 const char *NameSuffix, ClonedCodeInfo &CodeInfo);
256
257/// This works exactly like CloneFunctionInto,
258/// except that it does some simple constant prop and DCE on the fly. The
259/// effect of this is to copy significantly less code in cases where (for
260/// example) a function call with constant arguments is inlined, and those
261/// constant arguments cause a significant amount of code in the callee to be
262/// dead. Since this doesn't produce an exactly copy of the input, it can't be
263/// used for things like CloneFunction or CloneModule.
264///
265/// If ModuleLevelChanges is false, VMap contains no non-identity GlobalValue
266/// mappings.
267///
268LLVM_ABI void
269CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
270 ValueToValueMapTy &VMap, bool ModuleLevelChanges,
271 SmallVectorImpl<ReturnInst *> &Returns,
272 const char *NameSuffix, ClonedCodeInfo &CodeInfo);
273
274/// This class captures the data input to the InlineFunction call, and records
275/// the auxiliary results produced by it.
277public:
285
286 /// If non-null, InlineFunction will update the callgraph to reflect the
287 /// changes it makes.
291
292 /// InlineFunction fills this in with all static allocas that get copied into
293 /// the caller.
295
296 /// All of the new call sites inlined into the caller.
297 ///
298 /// 'InlineFunction' fills this in by scanning the inlined instructions.
300
303
304 /// Update profile for callee as well as cloned version. We need to do this
305 /// for regular inlining, but not for inlining from sample profile loader.
307
308 void reset() {
309 StaticAllocas.clear();
310 InlinedCallSites.clear();
311 ConvergenceControlToken = nullptr;
312 CallSiteEHPad = nullptr;
313 }
314};
315
316/// Check if it is legal to perform inlining of the function called by \p CB
317/// into the caller at this particular use, and sets fields in \p IFI.
318///
319/// This does not consider whether it is possible for the function callee itself
320/// to be inlined; for that see isInlineViable.
321LLVM_ABI InlineResult CanInlineCallSite(const CallBase &CB,
322 InlineFunctionInfo &IFI);
323
324/// This should generally not be used, use InlineFunction instead.
325///
326/// Perform mechanical inlining of \p CB into the caller.
327///
328/// This does not perform any legality or profitability checks for the
329/// inlining. This assumes that CanInlineCallSite was already called, populated
330/// \p IFI, and returned InlineResult::success.
331///
332/// Also assumes that isInlineViable returned InlineResult::success for the
333/// called function.
334LLVM_ABI void InlineFunctionImpl(CallBase &CB, InlineFunctionInfo &IFI,
335 bool MergeAttributes = false,
336 AAResults *CalleeAAR = nullptr,
337 bool InsertLifetime = true,
338 bool TrackInlineHistory = false,
339 Function *ForwardVarArgsTo = nullptr,
340 OptimizationRemarkEmitter *ORE = nullptr);
341
342/// This function inlines the called function into the basic
343/// block of the caller. This returns false if it is not possible to inline
344/// this call. The program is still in a well defined state if this occurs
345/// though.
346///
347/// Note that this only does one level of inlining. For example, if the
348/// instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now
349/// exists in the instruction stream. Similarly this will inline a recursive
350/// function by one level.
351///
352/// Note that while this routine is allowed to cleanup and optimize the
353/// *inlined* code to minimize the actual inserted code, it must not delete
354/// code in the caller as users of this routine may have pointers to
355/// instructions in the caller that need to remain stable.
356///
357/// If ForwardVarArgsTo is passed, inlining a function with varargs is allowed
358/// and all varargs at the callsite will be passed to any calls to
359/// ForwardVarArgsTo. The caller of InlineFunction has to make sure any varargs
360/// are only used by ForwardVarArgsTo.
361///
362/// The callee's function attributes are merged into the callers' if
363/// MergeAttributes is set to true.
364LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
365 bool MergeAttributes = false,
366 AAResults *CalleeAAR = nullptr,
367 bool InsertLifetime = true,
368 bool TrackInlineHistory = false,
369 Function *ForwardVarArgsTo = nullptr,
370 OptimizationRemarkEmitter *ORE = nullptr);
371
372/// Same as above, but it will update the contextual profile. If the contextual
373/// profile is invalid (i.e. not loaded because it is not present), it defaults
374/// to the behavior of the non-contextual profile updating variant above. This
375/// makes it easy to drop-in replace uses of the non-contextual overload.
376LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
377 PGOContextualProfile &CtxProf,
378 bool MergeAttributes = false,
379 AAResults *CalleeAAR = nullptr,
380 bool InsertLifetime = true,
381 bool TrackInlineHistory = false,
382 Function *ForwardVarArgsTo = nullptr,
383 OptimizationRemarkEmitter *ORE = nullptr);
384
385/// Clones a loop \p OrigLoop. Returns the loop and the blocks in \p
386/// Blocks.
387///
388/// Updates LoopInfo and DominatorTree assuming the loop is dominated by block
389/// \p LoopDomBB. Insert the new blocks before block specified in \p Before.
390/// The client needs to further update the CFG and DominatorTree after calling
391/// this function, to ensure the IR remains valid.
392/// Note: Only innermost loops are supported.
393LLVM_ABI Loop *cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB,
394 Loop *OrigLoop, ValueToValueMapTy &VMap,
395 const Twine &NameSuffix, LoopInfo *LI,
396 DominatorTree *DT,
397 SmallVectorImpl<BasicBlock *> &Blocks);
398
399/// Remaps instructions in \p Blocks using the mapping in \p VMap. If \p AC is
400/// given, the remapped llvm.assume calls are registered with it.
402 ValueToValueMapTy &VMap,
403 AssumptionCache *AC = nullptr);
404
405/// Split edge between BB and PredBB and duplicate all non-Phi instructions
406/// from BB between its beginning and the StopAt instruction into the split
407/// block. Phi nodes are not duplicated, but their uses are handled correctly:
408/// we replace them with the uses of corresponding Phi inputs. ValueMapping
409/// is used to map the original instructions from BB to their newly-created
410/// copies. Returns the split block.
412 BasicBlock *BB, BasicBlock *PredBB, Instruction *StopAt,
413 ValueToValueMapTy &ValueMapping, DomTreeUpdater &DTU);
414
415/// Updates profile information by adjusting the entry count by adding
416/// EntryDelta then scaling callsite information by the new count divided by the
417/// old count. VMap is used during inlinng to also update the new clone
419 Function *Callee, int64_t EntryDelta,
420 const ValueMap<const Value *, WeakTrackingVH> *VMap = nullptr);
421
422/// Find the 'llvm.experimental.noalias.scope.decl' intrinsics in the specified
423/// basic blocks and extract their scope. These are candidates for duplication
424/// when cloning.
425LLVM_ABI void
427 SmallVectorImpl<MDNode *> &NoAliasDeclScopes);
428
429/// Find the 'llvm.experimental.noalias.scope.decl' intrinsics in the specified
430/// instruction range and extract their scope. These are candidates for
431/// duplication when cloning.
432LLVM_ABI void
435 SmallVectorImpl<MDNode *> &NoAliasDeclScopes);
436
437/// Duplicate the specified list of noalias decl scopes.
438/// The 'Ext' string is added as an extension to the name.
439/// Afterwards, the ClonedScopes contains the mapping of the original scope
440/// MDNode onto the cloned scope.
441/// Be aware that the cloned scopes are still part of the original scope domain,
442/// unless that domain has disjoint scopes, in which case they are placed in a
443/// clone of the domain. ClonedDomains contains the mapping of such domains onto
444/// their clones.
445LLVM_ABI void
446cloneNoAliasScopes(ArrayRef<MDNode *> NoAliasDeclScopes,
447 DenseMap<MDNode *, MDNode *> &ClonedScopes,
448 DenseMap<const MDNode *, MDNode *> &ClonedDomains,
449 StringRef Ext, LLVMContext &Context);
450
451/// Adapt the metadata for the specified instruction according to the
452/// provided mapping. This is normally used after cloning an instruction, when
453/// some noalias scopes needed to be cloned.
454/// Scopes that belong to a domain in ClonedDomains but are not in ClonedScopes
455/// (because they have no declaration in the cloned code) are also cloned into
456/// the cloned domain, using 'Ext' as an extension to their name, and added to
457/// ClonedScopes.
458LLVM_ABI void
460 DenseMap<MDNode *, MDNode *> &ClonedScopes,
461 const DenseMap<const MDNode *, MDNode *> &ClonedDomains,
462 StringRef Ext, LLVMContext &Context);
463
464/// Clone the specified noalias decl scopes. Then adapt all instructions in the
465/// NewBlocks basicblocks to the cloned versions.
466/// 'Ext' will be added to the duplicate scope names.
468 ArrayRef<BasicBlock *> NewBlocks,
469 LLVMContext &Context, StringRef Ext);
470
471/// Clone the specified noalias decl scopes. Then adapt all instructions in the
472/// [IStart, IEnd] (IEnd included !) range to the cloned versions. 'Ext' will be
473/// added to the duplicate scope names.
475 Instruction *IStart, Instruction *IEnd,
476 LLVMContext &Context, StringRef Ext);
477} // end namespace llvm
478
479#endif // LLVM_TRANSFORMS_UTILS_CLONING_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseSet and SmallDenseSet classes.
#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:61
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:169
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
Value * ConvergenceControlToken
Definition Cloning.h:301
ProfileSummaryInfo * PSI
Definition Cloning.h:289
bool UpdateProfile
Update profile for callee as well as cloned version.
Definition Cloning.h:306
Instruction * CallSiteEHPad
Definition Cloning.h:302
function_ref< AssumptionCache &(Function &)> GetAssumptionCache
If non-null, InlineFunction will update the callgraph to reflect the changes it makes.
Definition Cloning.h:288
BlockFrequencyInfo * CalleeBFI
Definition Cloning.h:290
SmallVector< AllocaInst *, 4 > StaticAllocas
InlineFunction fills this in with all static allocas that get copied into the caller.
Definition Cloning.h:294
InlineFunctionInfo(function_ref< AssumptionCache &(Function &)> GetAssumptionCache=nullptr, ProfileSummaryInfo *PSI=nullptr, BlockFrequencyInfo *CallerBFI=nullptr, BlockFrequencyInfo *CalleeBFI=nullptr, bool UpdateProfile=true)
Definition Cloning.h:278
BlockFrequencyInfo * CallerBFI
Definition Cloning.h:290
SmallVector< CallBase *, 8 > InlinedCallSites
All of the new call sites inlined into the caller.
Definition Cloning.h:299
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:68
The optimization diagnostic interface.
The instrumented contextual profile, produced by the CtxProfAnalysis.
Analysis providing profile information.
Return a value (possibly void), from a function.
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition DenseSet.h:295
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:40
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 void remapInstructionsInBlocks(ArrayRef< BasicBlock * > Blocks, ValueToValueMapTy &VMap, AssumptionCache *AC=nullptr)
Remaps instructions in Blocks using the mapping in VMap.
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:73
LLVM_ABI void cloneNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, DenseMap< MDNode *, MDNode * > &ClonedScopes, DenseMap< const MDNode *, MDNode * > &ClonedDomains, 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 cloneAndAdaptNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, ArrayRef< BasicBlock * > NewBlocks, LLVMContext &Context, StringRef Ext)
Clone the specified noalias decl scopes.
ArrayRef(const T &OneElt) -> ArrayRef< T >
CloneFunctionChangeType
Definition Cloning.h:178
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 adaptNoAliasScopes(llvm::Instruction *I, DenseMap< MDNode *, MDNode * > &ClonedScopes, const DenseMap< const MDNode *, MDNode * > &ClonedDomains, StringRef Ext, LLVMContext &Context)
Adapt the metadata for the specified instruction according to the provided mapping.
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.
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
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 removeOriginallyIndirectCall(const Value *V)
Definition Cloning.h:105
bool isOriginallyIndirectCall(const Value *V) const
Definition Cloning.h:101
bool isSimplified(const Value *From, const Value *To) const
Definition Cloning.h:97
bool ContainsCalls
This is set to true if the cloned code contains a normal call instruction.
Definition Cloning.h:70
SmallDenseSet< AssertingVH< const Value >, 4 > OriginallyIndirectCalls
Definition Cloning.h:93
bool ContainsMemProfMetadata
This is set to true if there is memprof related metadata (memprof or callsite metadata) in the cloned...
Definition Cloning.h:74
void replaceOriginallyIndirectCall(const Value *Old, const Value *New)
Definition Cloning.h:114
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