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