LLVM 17.0.0git
CloneFunction.cpp
Go to the documentation of this file.
1//===- CloneFunction.cpp - Clone a function into another function ---------===//
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 implements the CloneFunctionInto interface, which is used as the
10// low-level function cloner. This is used by the CloneFunction and function
11// inliner to do the dirty work of copying the body of a function around.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/ADT/SetVector.h"
20#include "llvm/IR/CFG.h"
21#include "llvm/IR/Constants.h"
22#include "llvm/IR/DebugInfo.h"
24#include "llvm/IR/Function.h"
27#include "llvm/IR/LLVMContext.h"
28#include "llvm/IR/MDBuilder.h"
29#include "llvm/IR/Metadata.h"
30#include "llvm/IR/Module.h"
35#include <map>
36#include <optional>
37using namespace llvm;
38
39#define DEBUG_TYPE "clone-function"
40
41/// See comments in Cloning.h.
43 const Twine &NameSuffix, Function *F,
44 ClonedCodeInfo *CodeInfo,
45 DebugInfoFinder *DIFinder) {
46 BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), "", F);
47 if (BB->hasName())
48 NewBB->setName(BB->getName() + NameSuffix);
49
50 bool hasCalls = false, hasDynamicAllocas = false, hasMemProfMetadata = false;
51 Module *TheModule = F ? F->getParent() : nullptr;
52
53 // Loop over all instructions, and copy them over.
54 for (const Instruction &I : *BB) {
55 if (DIFinder && TheModule)
56 DIFinder->processInstruction(*TheModule, I);
57
58 Instruction *NewInst = I.clone();
59 if (I.hasName())
60 NewInst->setName(I.getName() + NameSuffix);
61 NewInst->insertInto(NewBB, NewBB->end());
62 VMap[&I] = NewInst; // Add instruction map to value.
63
64 if (isa<CallInst>(I) && !I.isDebugOrPseudoInst()) {
65 hasCalls = true;
66 hasMemProfMetadata |= I.hasMetadata(LLVMContext::MD_memprof);
67 }
68 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
69 if (!AI->isStaticAlloca()) {
70 hasDynamicAllocas = true;
71 }
72 }
73 }
74
75 if (CodeInfo) {
76 CodeInfo->ContainsCalls |= hasCalls;
77 CodeInfo->ContainsMemProfMetadata |= hasMemProfMetadata;
78 CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas;
79 }
80 return NewBB;
81}
82
83// Clone OldFunc into NewFunc, transforming the old arguments into references to
84// VMap values.
85//
86void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
90 const char *NameSuffix, ClonedCodeInfo *CodeInfo,
91 ValueMapTypeRemapper *TypeMapper,
92 ValueMaterializer *Materializer) {
93 assert(NameSuffix && "NameSuffix cannot be null!");
94
95#ifndef NDEBUG
96 for (const Argument &I : OldFunc->args())
97 assert(VMap.count(&I) && "No mapping from source argument specified!");
98#endif
99
100 bool ModuleLevelChanges = Changes > CloneFunctionChangeType::LocalChangesOnly;
101
102 // Copy all attributes other than those stored in the AttributeList. We need
103 // to remap the parameter indices of the AttributeList.
104 AttributeList NewAttrs = NewFunc->getAttributes();
105 NewFunc->copyAttributesFrom(OldFunc);
106 NewFunc->setAttributes(NewAttrs);
107
108 const RemapFlags FuncGlobalRefFlags =
109 ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges;
110
111 // Fix up the personality function that got copied over.
112 if (OldFunc->hasPersonalityFn())
113 NewFunc->setPersonalityFn(MapValue(OldFunc->getPersonalityFn(), VMap,
114 FuncGlobalRefFlags, TypeMapper,
115 Materializer));
116
117 if (OldFunc->hasPrefixData()) {
118 NewFunc->setPrefixData(MapValue(OldFunc->getPrefixData(), VMap,
119 FuncGlobalRefFlags, TypeMapper,
120 Materializer));
121 }
122
123 if (OldFunc->hasPrologueData()) {
124 NewFunc->setPrologueData(MapValue(OldFunc->getPrologueData(), VMap,
125 FuncGlobalRefFlags, TypeMapper,
126 Materializer));
127 }
128
129 SmallVector<AttributeSet, 4> NewArgAttrs(NewFunc->arg_size());
130 AttributeList OldAttrs = OldFunc->getAttributes();
131
132 // Clone any argument attributes that are present in the VMap.
133 for (const Argument &OldArg : OldFunc->args()) {
134 if (Argument *NewArg = dyn_cast<Argument>(VMap[&OldArg])) {
135 NewArgAttrs[NewArg->getArgNo()] =
136 OldAttrs.getParamAttrs(OldArg.getArgNo());
137 }
138 }
139
140 NewFunc->setAttributes(
141 AttributeList::get(NewFunc->getContext(), OldAttrs.getFnAttrs(),
142 OldAttrs.getRetAttrs(), NewArgAttrs));
143
144 // Everything else beyond this point deals with function instructions,
145 // so if we are dealing with a function declaration, we're done.
146 if (OldFunc->isDeclaration())
147 return;
148
149 // When we remap instructions within the same module, we want to avoid
150 // duplicating inlined DISubprograms, so record all subprograms we find as we
151 // duplicate instructions and then freeze them in the MD map. We also record
152 // information about dbg.value and dbg.declare to avoid duplicating the
153 // types.
154 std::optional<DebugInfoFinder> DIFinder;
155
156 // Track the subprogram attachment that needs to be cloned to fine-tune the
157 // mapping within the same module.
158 DISubprogram *SPClonedWithinModule = nullptr;
159 if (Changes < CloneFunctionChangeType::DifferentModule) {
160 assert((NewFunc->getParent() == nullptr ||
161 NewFunc->getParent() == OldFunc->getParent()) &&
162 "Expected NewFunc to have the same parent, or no parent");
163
164 // Need to find subprograms, types, and compile units.
165 DIFinder.emplace();
166
167 SPClonedWithinModule = OldFunc->getSubprogram();
168 if (SPClonedWithinModule)
169 DIFinder->processSubprogram(SPClonedWithinModule);
170 } else {
171 assert((NewFunc->getParent() == nullptr ||
172 NewFunc->getParent() != OldFunc->getParent()) &&
173 "Expected NewFunc to have different parents, or no parent");
174
175 if (Changes == CloneFunctionChangeType::DifferentModule) {
176 assert(NewFunc->getParent() &&
177 "Need parent of new function to maintain debug info invariants");
178
179 // Need to find all the compile units.
180 DIFinder.emplace();
181 }
182 }
183
184 // Loop over all of the basic blocks in the function, cloning them as
185 // appropriate. Note that we save BE this way in order to handle cloning of
186 // recursive functions into themselves.
187 for (const BasicBlock &BB : *OldFunc) {
188
189 // Create a new basic block and copy instructions into it!
190 BasicBlock *CBB = CloneBasicBlock(&BB, VMap, NameSuffix, NewFunc, CodeInfo,
191 DIFinder ? &*DIFinder : nullptr);
192
193 // Add basic block mapping.
194 VMap[&BB] = CBB;
195
196 // It is only legal to clone a function if a block address within that
197 // function is never referenced outside of the function. Given that, we
198 // want to map block addresses from the old function to block addresses in
199 // the clone. (This is different from the generic ValueMapper
200 // implementation, which generates an invalid blockaddress when
201 // cloning a function.)
202 if (BB.hasAddressTaken()) {
203 Constant *OldBBAddr = BlockAddress::get(const_cast<Function *>(OldFunc),
204 const_cast<BasicBlock *>(&BB));
205 VMap[OldBBAddr] = BlockAddress::get(NewFunc, CBB);
206 }
207
208 // Note return instructions for the caller.
209 if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator()))
210 Returns.push_back(RI);
211 }
212
213 if (Changes < CloneFunctionChangeType::DifferentModule &&
214 DIFinder->subprogram_count() > 0) {
215 // Turn on module-level changes, since we need to clone (some of) the
216 // debug info metadata.
217 //
218 // FIXME: Metadata effectively owned by a function should be made
219 // local, and only that local metadata should be cloned.
220 ModuleLevelChanges = true;
221
222 auto mapToSelfIfNew = [&VMap](MDNode *N) {
223 // Avoid clobbering an existing mapping.
224 (void)VMap.MD().try_emplace(N, N);
225 };
226
227 // Avoid cloning types, compile units, and (other) subprograms.
229 for (DISubprogram *ISP : DIFinder->subprograms()) {
230 if (ISP != SPClonedWithinModule) {
231 mapToSelfIfNew(ISP);
232 MappedToSelfSPs.insert(ISP);
233 }
234 }
235
236 // If a subprogram isn't going to be cloned skip its lexical blocks as well.
237 for (DIScope *S : DIFinder->scopes()) {
238 auto *LScope = dyn_cast<DILocalScope>(S);
239 if (LScope && MappedToSelfSPs.count(LScope->getSubprogram()))
240 mapToSelfIfNew(S);
241 }
242
243 for (DICompileUnit *CU : DIFinder->compile_units())
244 mapToSelfIfNew(CU);
245
246 for (DIType *Type : DIFinder->types())
247 mapToSelfIfNew(Type);
248 } else {
249 assert(!SPClonedWithinModule &&
250 "Subprogram should be in DIFinder->subprogram_count()...");
251 }
252
253 const auto RemapFlag = ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges;
254 // Duplicate the metadata that is attached to the cloned function.
255 // Subprograms/CUs/types that were already mapped to themselves won't be
256 // duplicated.
258 OldFunc->getAllMetadata(MDs);
259 for (auto MD : MDs) {
260 NewFunc->addMetadata(MD.first, *MapMetadata(MD.second, VMap, RemapFlag,
261 TypeMapper, Materializer));
262 }
263
264 // Loop over all of the instructions in the new function, fixing up operand
265 // references as we go. This uses VMap to do all the hard work.
267 BB = cast<BasicBlock>(VMap[&OldFunc->front()])->getIterator(),
268 BE = NewFunc->end();
269 BB != BE; ++BB)
270 // Loop over all instructions, fixing each one as we find it...
271 for (Instruction &II : *BB)
272 RemapInstruction(&II, VMap, RemapFlag, TypeMapper, Materializer);
273
274 // Only update !llvm.dbg.cu for DifferentModule (not CloneModule). In the
275 // same module, the compile unit will already be listed (or not). When
276 // cloning a module, CloneModule() will handle creating the named metadata.
277 if (Changes != CloneFunctionChangeType::DifferentModule)
278 return;
279
280 // Update !llvm.dbg.cu with compile units added to the new module if this
281 // function is being cloned in isolation.
282 //
283 // FIXME: This is making global / module-level changes, which doesn't seem
284 // like the right encapsulation Consider dropping the requirement to update
285 // !llvm.dbg.cu (either obsoleting the node, or restricting it to
286 // non-discardable compile units) instead of discovering compile units by
287 // visiting the metadata attached to global values, which would allow this
288 // code to be deleted. Alternatively, perhaps give responsibility for this
289 // update to CloneFunctionInto's callers.
290 auto *NewModule = NewFunc->getParent();
291 auto *NMD = NewModule->getOrInsertNamedMetadata("llvm.dbg.cu");
292 // Avoid multiple insertions of the same DICompileUnit to NMD.
294 for (auto *Operand : NMD->operands())
295 Visited.insert(Operand);
296 for (auto *Unit : DIFinder->compile_units()) {
297 MDNode *MappedUnit =
298 MapMetadata(Unit, VMap, RF_None, TypeMapper, Materializer);
299 if (Visited.insert(MappedUnit).second)
300 NMD->addOperand(MappedUnit);
301 }
302}
303
304/// Return a copy of the specified function and add it to that function's
305/// module. Also, any references specified in the VMap are changed to refer to
306/// their mapped value instead of the original one. If any of the arguments to
307/// the function are in the VMap, the arguments are deleted from the resultant
308/// function. The VMap is updated to include mappings from all of the
309/// instructions and basicblocks in the function from their old to new values.
310///
312 ClonedCodeInfo *CodeInfo) {
313 std::vector<Type *> ArgTypes;
314
315 // The user might be deleting arguments to the function by specifying them in
316 // the VMap. If so, we need to not add the arguments to the arg ty vector
317 //
318 for (const Argument &I : F->args())
319 if (VMap.count(&I) == 0) // Haven't mapped the argument to anything yet?
320 ArgTypes.push_back(I.getType());
321
322 // Create a new function type...
323 FunctionType *FTy =
324 FunctionType::get(F->getFunctionType()->getReturnType(), ArgTypes,
325 F->getFunctionType()->isVarArg());
326
327 // Create the new function...
328 Function *NewF = Function::Create(FTy, F->getLinkage(), F->getAddressSpace(),
329 F->getName(), F->getParent());
330
331 // Loop over the arguments, copying the names of the mapped arguments over...
332 Function::arg_iterator DestI = NewF->arg_begin();
333 for (const Argument &I : F->args())
334 if (VMap.count(&I) == 0) { // Is this argument preserved?
335 DestI->setName(I.getName()); // Copy the name over...
336 VMap[&I] = &*DestI++; // Add mapping to VMap
337 }
338
339 SmallVector<ReturnInst *, 8> Returns; // Ignore returns cloned.
340 CloneFunctionInto(NewF, F, VMap, CloneFunctionChangeType::LocalChangesOnly,
341 Returns, "", CodeInfo);
342
343 return NewF;
344}
345
346namespace {
347/// This is a private class used to implement CloneAndPruneFunctionInto.
348struct PruningFunctionCloner {
349 Function *NewFunc;
350 const Function *OldFunc;
351 ValueToValueMapTy &VMap;
352 bool ModuleLevelChanges;
353 const char *NameSuffix;
354 ClonedCodeInfo *CodeInfo;
355 bool HostFuncIsStrictFP;
356
357 Instruction *cloneInstruction(BasicBlock::const_iterator II);
358
359public:
360 PruningFunctionCloner(Function *newFunc, const Function *oldFunc,
361 ValueToValueMapTy &valueMap, bool moduleLevelChanges,
362 const char *nameSuffix, ClonedCodeInfo *codeInfo)
363 : NewFunc(newFunc), OldFunc(oldFunc), VMap(valueMap),
364 ModuleLevelChanges(moduleLevelChanges), NameSuffix(nameSuffix),
365 CodeInfo(codeInfo) {
366 HostFuncIsStrictFP =
367 newFunc->getAttributes().hasFnAttr(Attribute::StrictFP);
368 }
369
370 /// The specified block is found to be reachable, clone it and
371 /// anything that it can reach.
372 void CloneBlock(const BasicBlock *BB, BasicBlock::const_iterator StartingInst,
373 std::vector<const BasicBlock *> &ToClone);
374};
375} // namespace
376
378 switch (CIID) {
379#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
380 case Intrinsic::INTRINSIC: \
381 return ROUND_MODE == 1;
382#define FUNCTION INSTRUCTION
383#include "llvm/IR/ConstrainedOps.def"
384 default:
385 llvm_unreachable("Unexpected constrained intrinsic id");
386 }
387}
388
390PruningFunctionCloner::cloneInstruction(BasicBlock::const_iterator II) {
391 const Instruction &OldInst = *II;
392 Instruction *NewInst = nullptr;
393 if (HostFuncIsStrictFP) {
395 if (CIID != Intrinsic::not_intrinsic) {
396 // Instead of cloning the instruction, a call to constrained intrinsic
397 // should be created.
398 // Assume the first arguments of constrained intrinsics are the same as
399 // the operands of original instruction.
400
401 // Determine overloaded types of the intrinsic.
404 getIntrinsicInfoTableEntries(CIID, Descriptor);
405 for (unsigned I = 0, E = Descriptor.size(); I != E; ++I) {
406 Intrinsic::IITDescriptor Operand = Descriptor[I];
407 switch (Operand.Kind) {
409 if (Operand.getArgumentKind() !=
410 Intrinsic::IITDescriptor::AK_MatchType) {
411 if (I == 0)
412 TParams.push_back(OldInst.getType());
413 else
414 TParams.push_back(OldInst.getOperand(I - 1)->getType());
415 }
416 break;
418 ++I;
419 break;
420 default:
421 break;
422 }
423 }
424
425 // Create intrinsic call.
426 LLVMContext &Ctx = NewFunc->getContext();
427 Function *IFn =
428 Intrinsic::getDeclaration(NewFunc->getParent(), CIID, TParams);
430 unsigned NumOperands = OldInst.getNumOperands();
431 if (isa<CallInst>(OldInst))
432 --NumOperands;
433 for (unsigned I = 0; I < NumOperands; ++I) {
434 Value *Op = OldInst.getOperand(I);
435 Args.push_back(Op);
436 }
437 if (const auto *CmpI = dyn_cast<FCmpInst>(&OldInst)) {
438 FCmpInst::Predicate Pred = CmpI->getPredicate();
439 StringRef PredName = FCmpInst::getPredicateName(Pred);
440 Args.push_back(MetadataAsValue::get(Ctx, MDString::get(Ctx, PredName)));
441 }
442
443 // The last arguments of a constrained intrinsic are metadata that
444 // represent rounding mode (absents in some intrinsics) and exception
445 // behavior. The inlined function uses default settings.
446 if (hasRoundingModeOperand(CIID))
447 Args.push_back(
448 MetadataAsValue::get(Ctx, MDString::get(Ctx, "round.tonearest")));
449 Args.push_back(
450 MetadataAsValue::get(Ctx, MDString::get(Ctx, "fpexcept.ignore")));
451
452 NewInst = CallInst::Create(IFn, Args, OldInst.getName() + ".strict");
453 }
454 }
455 if (!NewInst)
456 NewInst = II->clone();
457 return NewInst;
458}
459
460/// The specified block is found to be reachable, clone it and
461/// anything that it can reach.
462void PruningFunctionCloner::CloneBlock(
463 const BasicBlock *BB, BasicBlock::const_iterator StartingInst,
464 std::vector<const BasicBlock *> &ToClone) {
465 WeakTrackingVH &BBEntry = VMap[BB];
466
467 // Have we already cloned this block?
468 if (BBEntry)
469 return;
470
471 // Nope, clone it now.
472 BasicBlock *NewBB;
473 BBEntry = NewBB = BasicBlock::Create(BB->getContext());
474 if (BB->hasName())
475 NewBB->setName(BB->getName() + NameSuffix);
476
477 // It is only legal to clone a function if a block address within that
478 // function is never referenced outside of the function. Given that, we
479 // want to map block addresses from the old function to block addresses in
480 // the clone. (This is different from the generic ValueMapper
481 // implementation, which generates an invalid blockaddress when
482 // cloning a function.)
483 //
484 // Note that we don't need to fix the mapping for unreachable blocks;
485 // the default mapping there is safe.
486 if (BB->hasAddressTaken()) {
487 Constant *OldBBAddr = BlockAddress::get(const_cast<Function *>(OldFunc),
488 const_cast<BasicBlock *>(BB));
489 VMap[OldBBAddr] = BlockAddress::get(NewFunc, NewBB);
490 }
491
492 bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
493 bool hasMemProfMetadata = false;
494
495 // Loop over all instructions, and copy them over, DCE'ing as we go. This
496 // loop doesn't include the terminator.
497 for (BasicBlock::const_iterator II = StartingInst, IE = --BB->end(); II != IE;
498 ++II) {
499
500 Instruction *NewInst = cloneInstruction(II);
501
502 if (HostFuncIsStrictFP) {
503 // All function calls in the inlined function must get 'strictfp'
504 // attribute to prevent undesirable optimizations.
505 if (auto *Call = dyn_cast<CallInst>(NewInst))
506 Call->addFnAttr(Attribute::StrictFP);
507 }
508
509 // Eagerly remap operands to the newly cloned instruction, except for PHI
510 // nodes for which we defer processing until we update the CFG. Also defer
511 // debug intrinsic processing because they may contain use-before-defs.
512 if (!isa<PHINode>(NewInst) && !isa<DbgVariableIntrinsic>(NewInst)) {
513 RemapInstruction(NewInst, VMap,
514 ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges);
515
516 // If we can simplify this instruction to some other value, simply add
517 // a mapping to that value rather than inserting a new instruction into
518 // the basic block.
519 //
520 // FIXME: simplifyInstruction should know the context of the new function.
521 if (Value *V =
522 simplifyInstruction(NewInst, BB->getModule()->getDataLayout())) {
523 // On the off-chance that this simplifies to an instruction in the old
524 // function, map it back into the new function.
525 if (NewFunc != OldFunc)
526 if (Value *MappedV = VMap.lookup(V))
527 V = MappedV;
528
529 if (!NewInst->mayHaveSideEffects()) {
530 VMap[&*II] = V;
531 NewInst->deleteValue();
532 continue;
533 }
534 }
535 }
536
537 if (II->hasName())
538 NewInst->setName(II->getName() + NameSuffix);
539 VMap[&*II] = NewInst; // Add instruction map to value.
540 NewInst->insertInto(NewBB, NewBB->end());
541 if (isa<CallInst>(II) && !II->isDebugOrPseudoInst()) {
542 hasCalls = true;
543 hasMemProfMetadata |= II->hasMetadata(LLVMContext::MD_memprof);
544 }
545
546 if (CodeInfo) {
547 CodeInfo->OrigVMap[&*II] = NewInst;
548 if (auto *CB = dyn_cast<CallBase>(&*II))
549 if (CB->hasOperandBundles())
550 CodeInfo->OperandBundleCallSites.push_back(NewInst);
551 }
552
553 if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
554 if (isa<ConstantInt>(AI->getArraySize()))
555 hasStaticAllocas = true;
556 else
557 hasDynamicAllocas = true;
558 }
559 }
560
561 // Finally, clone over the terminator.
562 const Instruction *OldTI = BB->getTerminator();
563 bool TerminatorDone = false;
564 if (const BranchInst *BI = dyn_cast<BranchInst>(OldTI)) {
565 if (BI->isConditional()) {
566 // If the condition was a known constant in the callee...
567 ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition());
568 // Or is a known constant in the caller...
569 if (!Cond) {
570 Value *V = VMap.lookup(BI->getCondition());
571 Cond = dyn_cast_or_null<ConstantInt>(V);
572 }
573
574 // Constant fold to uncond branch!
575 if (Cond) {
576 BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue());
577 VMap[OldTI] = BranchInst::Create(Dest, NewBB);
578 ToClone.push_back(Dest);
579 TerminatorDone = true;
580 }
581 }
582 } else if (const SwitchInst *SI = dyn_cast<SwitchInst>(OldTI)) {
583 // If switching on a value known constant in the caller.
584 ConstantInt *Cond = dyn_cast<ConstantInt>(SI->getCondition());
585 if (!Cond) { // Or known constant after constant prop in the callee...
586 Value *V = VMap.lookup(SI->getCondition());
587 Cond = dyn_cast_or_null<ConstantInt>(V);
588 }
589 if (Cond) { // Constant fold to uncond branch!
590 SwitchInst::ConstCaseHandle Case = *SI->findCaseValue(Cond);
591 BasicBlock *Dest = const_cast<BasicBlock *>(Case.getCaseSuccessor());
592 VMap[OldTI] = BranchInst::Create(Dest, NewBB);
593 ToClone.push_back(Dest);
594 TerminatorDone = true;
595 }
596 }
597
598 if (!TerminatorDone) {
599 Instruction *NewInst = OldTI->clone();
600 if (OldTI->hasName())
601 NewInst->setName(OldTI->getName() + NameSuffix);
602 NewInst->insertInto(NewBB, NewBB->end());
603 VMap[OldTI] = NewInst; // Add instruction map to value.
604
605 if (CodeInfo) {
606 CodeInfo->OrigVMap[OldTI] = NewInst;
607 if (auto *CB = dyn_cast<CallBase>(OldTI))
608 if (CB->hasOperandBundles())
609 CodeInfo->OperandBundleCallSites.push_back(NewInst);
610 }
611
612 // Recursively clone any reachable successor blocks.
613 append_range(ToClone, successors(BB->getTerminator()));
614 }
615
616 if (CodeInfo) {
617 CodeInfo->ContainsCalls |= hasCalls;
618 CodeInfo->ContainsMemProfMetadata |= hasMemProfMetadata;
619 CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas;
620 CodeInfo->ContainsDynamicAllocas |=
621 hasStaticAllocas && BB != &BB->getParent()->front();
622 }
623}
624
625/// This works like CloneAndPruneFunctionInto, except that it does not clone the
626/// entire function. Instead it starts at an instruction provided by the caller
627/// and copies (and prunes) only the code reachable from that instruction.
629 const Instruction *StartingInst,
630 ValueToValueMapTy &VMap,
631 bool ModuleLevelChanges,
633 const char *NameSuffix,
634 ClonedCodeInfo *CodeInfo) {
635 assert(NameSuffix && "NameSuffix cannot be null!");
636
637 ValueMapTypeRemapper *TypeMapper = nullptr;
638 ValueMaterializer *Materializer = nullptr;
639
640#ifndef NDEBUG
641 // If the cloning starts at the beginning of the function, verify that
642 // the function arguments are mapped.
643 if (!StartingInst)
644 for (const Argument &II : OldFunc->args())
645 assert(VMap.count(&II) && "No mapping from source argument specified!");
646#endif
647
648 PruningFunctionCloner PFC(NewFunc, OldFunc, VMap, ModuleLevelChanges,
649 NameSuffix, CodeInfo);
650 const BasicBlock *StartingBB;
651 if (StartingInst)
652 StartingBB = StartingInst->getParent();
653 else {
654 StartingBB = &OldFunc->getEntryBlock();
655 StartingInst = &StartingBB->front();
656 }
657
658 // Collect debug intrinsics for remapping later.
660 for (const auto &BB : *OldFunc) {
661 for (const auto &I : BB) {
662 if (const auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
663 DbgIntrinsics.push_back(DVI);
664 }
665 }
666
667 // Clone the entry block, and anything recursively reachable from it.
668 std::vector<const BasicBlock *> CloneWorklist;
669 PFC.CloneBlock(StartingBB, StartingInst->getIterator(), CloneWorklist);
670 while (!CloneWorklist.empty()) {
671 const BasicBlock *BB = CloneWorklist.back();
672 CloneWorklist.pop_back();
673 PFC.CloneBlock(BB, BB->begin(), CloneWorklist);
674 }
675
676 // Loop over all of the basic blocks in the old function. If the block was
677 // reachable, we have cloned it and the old block is now in the value map:
678 // insert it into the new function in the right order. If not, ignore it.
679 //
680 // Defer PHI resolution until rest of function is resolved.
682 for (const BasicBlock &BI : *OldFunc) {
683 Value *V = VMap.lookup(&BI);
684 BasicBlock *NewBB = cast_or_null<BasicBlock>(V);
685 if (!NewBB)
686 continue; // Dead block.
687
688 // Add the new block to the new function.
689 NewFunc->insert(NewFunc->end(), NewBB);
690
691 // Handle PHI nodes specially, as we have to remove references to dead
692 // blocks.
693 for (const PHINode &PN : BI.phis()) {
694 // PHI nodes may have been remapped to non-PHI nodes by the caller or
695 // during the cloning process.
696 if (isa<PHINode>(VMap[&PN]))
697 PHIToResolve.push_back(&PN);
698 else
699 break;
700 }
701
702 // Finally, remap the terminator instructions, as those can't be remapped
703 // until all BBs are mapped.
704 RemapInstruction(NewBB->getTerminator(), VMap,
705 ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
706 TypeMapper, Materializer);
707 }
708
709 // Defer PHI resolution until rest of function is resolved, PHI resolution
710 // requires the CFG to be up-to-date.
711 for (unsigned phino = 0, e = PHIToResolve.size(); phino != e;) {
712 const PHINode *OPN = PHIToResolve[phino];
713 unsigned NumPreds = OPN->getNumIncomingValues();
714 const BasicBlock *OldBB = OPN->getParent();
715 BasicBlock *NewBB = cast<BasicBlock>(VMap[OldBB]);
716
717 // Map operands for blocks that are live and remove operands for blocks
718 // that are dead.
719 for (; phino != PHIToResolve.size() &&
720 PHIToResolve[phino]->getParent() == OldBB;
721 ++phino) {
722 OPN = PHIToResolve[phino];
723 PHINode *PN = cast<PHINode>(VMap[OPN]);
724 for (unsigned pred = 0, e = NumPreds; pred != e; ++pred) {
725 Value *V = VMap.lookup(PN->getIncomingBlock(pred));
726 if (BasicBlock *MappedBlock = cast_or_null<BasicBlock>(V)) {
727 Value *InVal =
728 MapValue(PN->getIncomingValue(pred), VMap,
729 ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges);
730 assert(InVal && "Unknown input value?");
731 PN->setIncomingValue(pred, InVal);
732 PN->setIncomingBlock(pred, MappedBlock);
733 } else {
734 PN->removeIncomingValue(pred, false);
735 --pred; // Revisit the next entry.
736 --e;
737 }
738 }
739 }
740
741 // The loop above has removed PHI entries for those blocks that are dead
742 // and has updated others. However, if a block is live (i.e. copied over)
743 // but its terminator has been changed to not go to this block, then our
744 // phi nodes will have invalid entries. Update the PHI nodes in this
745 // case.
746 PHINode *PN = cast<PHINode>(NewBB->begin());
747 NumPreds = pred_size(NewBB);
748 if (NumPreds != PN->getNumIncomingValues()) {
749 assert(NumPreds < PN->getNumIncomingValues());
750 // Count how many times each predecessor comes to this block.
751 std::map<BasicBlock *, unsigned> PredCount;
752 for (BasicBlock *Pred : predecessors(NewBB))
753 --PredCount[Pred];
754
755 // Figure out how many entries to remove from each PHI.
756 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
757 ++PredCount[PN->getIncomingBlock(i)];
758
759 // At this point, the excess predecessor entries are positive in the
760 // map. Loop over all of the PHIs and remove excess predecessor
761 // entries.
762 BasicBlock::iterator I = NewBB->begin();
763 for (; (PN = dyn_cast<PHINode>(I)); ++I) {
764 for (const auto &PCI : PredCount) {
765 BasicBlock *Pred = PCI.first;
766 for (unsigned NumToRemove = PCI.second; NumToRemove; --NumToRemove)
767 PN->removeIncomingValue(Pred, false);
768 }
769 }
770 }
771
772 // If the loops above have made these phi nodes have 0 or 1 operand,
773 // replace them with poison or the input value. We must do this for
774 // correctness, because 0-operand phis are not valid.
775 PN = cast<PHINode>(NewBB->begin());
776 if (PN->getNumIncomingValues() == 0) {
777 BasicBlock::iterator I = NewBB->begin();
778 BasicBlock::const_iterator OldI = OldBB->begin();
779 while ((PN = dyn_cast<PHINode>(I++))) {
780 Value *NV = PoisonValue::get(PN->getType());
781 PN->replaceAllUsesWith(NV);
782 assert(VMap[&*OldI] == PN && "VMap mismatch");
783 VMap[&*OldI] = NV;
784 PN->eraseFromParent();
785 ++OldI;
786 }
787 }
788 }
789
790 // Make a second pass over the PHINodes now that all of them have been
791 // remapped into the new function, simplifying the PHINode and performing any
792 // recursive simplifications exposed. This will transparently update the
793 // WeakTrackingVH in the VMap. Notably, we rely on that so that if we coalesce
794 // two PHINodes, the iteration over the old PHIs remains valid, and the
795 // mapping will just map us to the new node (which may not even be a PHI
796 // node).
797 const DataLayout &DL = NewFunc->getParent()->getDataLayout();
799 for (unsigned Idx = 0, Size = PHIToResolve.size(); Idx != Size; ++Idx)
800 if (isa<PHINode>(VMap[PHIToResolve[Idx]]))
801 Worklist.insert(PHIToResolve[Idx]);
802
803 // Note that we must test the size on each iteration, the worklist can grow.
804 for (unsigned Idx = 0; Idx != Worklist.size(); ++Idx) {
805 const Value *OrigV = Worklist[Idx];
806 auto *I = dyn_cast_or_null<Instruction>(VMap.lookup(OrigV));
807 if (!I)
808 continue;
809
810 // Skip over non-intrinsic callsites, we don't want to remove any nodes from
811 // the CGSCC.
812 CallBase *CB = dyn_cast<CallBase>(I);
813 if (CB && CB->getCalledFunction() &&
815 continue;
816
817 // See if this instruction simplifies.
818 Value *SimpleV = simplifyInstruction(I, DL);
819 if (!SimpleV)
820 continue;
821
822 // Stash away all the uses of the old instruction so we can check them for
823 // recursive simplifications after a RAUW. This is cheaper than checking all
824 // uses of To on the recursive step in most cases.
825 for (const User *U : OrigV->users())
826 Worklist.insert(cast<Instruction>(U));
827
828 // Replace the instruction with its simplified value.
829 I->replaceAllUsesWith(SimpleV);
830
831 // If the original instruction had no side effects, remove it.
833 I->eraseFromParent();
834 else
835 VMap[OrigV] = I;
836 }
837
838 // Remap debug intrinsic operands now that all values have been mapped.
839 // Doing this now (late) preserves use-before-defs in debug intrinsics. If
840 // we didn't do this, ValueAsMetadata(use-before-def) operands would be
841 // replaced by empty metadata. This would signal later cleanup passes to
842 // remove the debug intrinsics, potentially causing incorrect locations.
843 for (const auto *DVI : DbgIntrinsics) {
844 if (DbgVariableIntrinsic *NewDVI =
845 cast_or_null<DbgVariableIntrinsic>(VMap.lookup(DVI)))
846 RemapInstruction(NewDVI, VMap,
847 ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
848 TypeMapper, Materializer);
849 }
850
851 // Simplify conditional branches and switches with a constant operand. We try
852 // to prune these out when cloning, but if the simplification required
853 // looking through PHI nodes, those are only available after forming the full
854 // basic block. That may leave some here, and we still want to prune the dead
855 // code as early as possible.
856 Function::iterator Begin = cast<BasicBlock>(VMap[StartingBB])->getIterator();
857 for (BasicBlock &BB : make_range(Begin, NewFunc->end()))
859
860 // Some blocks may have become unreachable as a result. Find and delete them.
861 {
862 SmallPtrSet<BasicBlock *, 16> ReachableBlocks;
864 Worklist.push_back(&*Begin);
865 while (!Worklist.empty()) {
866 BasicBlock *BB = Worklist.pop_back_val();
867 if (ReachableBlocks.insert(BB).second)
868 append_range(Worklist, successors(BB));
869 }
870
871 SmallVector<BasicBlock *, 16> UnreachableBlocks;
872 for (BasicBlock &BB : make_range(Begin, NewFunc->end()))
873 if (!ReachableBlocks.contains(&BB))
874 UnreachableBlocks.push_back(&BB);
875 DeleteDeadBlocks(UnreachableBlocks);
876 }
877
878 // Now that the inlined function body has been fully constructed, go through
879 // and zap unconditional fall-through branches. This happens all the time when
880 // specializing code: code specialization turns conditional branches into
881 // uncond branches, and this code folds them.
882 Function::iterator I = Begin;
883 while (I != NewFunc->end()) {
884 BranchInst *BI = dyn_cast<BranchInst>(I->getTerminator());
885 if (!BI || BI->isConditional()) {
886 ++I;
887 continue;
888 }
889
890 BasicBlock *Dest = BI->getSuccessor(0);
891 if (!Dest->getSinglePredecessor()) {
892 ++I;
893 continue;
894 }
895
896 // We shouldn't be able to get single-entry PHI nodes here, as instsimplify
897 // above should have zapped all of them..
898 assert(!isa<PHINode>(Dest->begin()));
899
900 // We know all single-entry PHI nodes in the inlined function have been
901 // removed, so we just need to splice the blocks.
902 BI->eraseFromParent();
903
904 // Make all PHI nodes that referred to Dest now refer to I as their source.
905 Dest->replaceAllUsesWith(&*I);
906
907 // Move all the instructions in the succ to the pred.
908 I->splice(I->end(), Dest);
909
910 // Remove the dest block.
911 Dest->eraseFromParent();
912
913 // Do not increment I, iteratively merge all things this block branches to.
914 }
915
916 // Make a final pass over the basic blocks from the old function to gather
917 // any return instructions which survived folding. We have to do this here
918 // because we can iteratively remove and merge returns above.
919 for (Function::iterator I = cast<BasicBlock>(VMap[StartingBB])->getIterator(),
920 E = NewFunc->end();
921 I != E; ++I)
922 if (ReturnInst *RI = dyn_cast<ReturnInst>(I->getTerminator()))
923 Returns.push_back(RI);
924}
925
926/// This works exactly like CloneFunctionInto,
927/// except that it does some simple constant prop and DCE on the fly. The
928/// effect of this is to copy significantly less code in cases where (for
929/// example) a function call with constant arguments is inlined, and those
930/// constant arguments cause a significant amount of code in the callee to be
931/// dead. Since this doesn't produce an exact copy of the input, it can't be
932/// used for things like CloneFunction or CloneModule.
934 Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap,
935 bool ModuleLevelChanges, SmallVectorImpl<ReturnInst *> &Returns,
936 const char *NameSuffix, ClonedCodeInfo *CodeInfo) {
937 CloneAndPruneIntoFromInst(NewFunc, OldFunc, &OldFunc->front().front(), VMap,
938 ModuleLevelChanges, Returns, NameSuffix, CodeInfo);
939}
940
941/// Remaps instructions in \p Blocks using the mapping in \p VMap.
943 ValueToValueMapTy &VMap) {
944 // Rewrite the code to refer to itself.
945 for (auto *BB : Blocks)
946 for (auto &Inst : *BB)
947 RemapInstruction(&Inst, VMap,
949}
950
951/// Clones a loop \p OrigLoop. Returns the loop and the blocks in \p
952/// Blocks.
953///
954/// Updates LoopInfo and DominatorTree assuming the loop is dominated by block
955/// \p LoopDomBB. Insert the new blocks before block specified in \p Before.
957 Loop *OrigLoop, ValueToValueMapTy &VMap,
958 const Twine &NameSuffix, LoopInfo *LI,
959 DominatorTree *DT,
961 Function *F = OrigLoop->getHeader()->getParent();
962 Loop *ParentLoop = OrigLoop->getParentLoop();
964
965 Loop *NewLoop = LI->AllocateLoop();
966 LMap[OrigLoop] = NewLoop;
967 if (ParentLoop)
968 ParentLoop->addChildLoop(NewLoop);
969 else
970 LI->addTopLevelLoop(NewLoop);
971
972 BasicBlock *OrigPH = OrigLoop->getLoopPreheader();
973 assert(OrigPH && "No preheader");
974 BasicBlock *NewPH = CloneBasicBlock(OrigPH, VMap, NameSuffix, F);
975 // To rename the loop PHIs.
976 VMap[OrigPH] = NewPH;
977 Blocks.push_back(NewPH);
978
979 // Update LoopInfo.
980 if (ParentLoop)
981 ParentLoop->addBasicBlockToLoop(NewPH, *LI);
982
983 // Update DominatorTree.
984 DT->addNewBlock(NewPH, LoopDomBB);
985
986 for (Loop *CurLoop : OrigLoop->getLoopsInPreorder()) {
987 Loop *&NewLoop = LMap[CurLoop];
988 if (!NewLoop) {
989 NewLoop = LI->AllocateLoop();
990
991 // Establish the parent/child relationship.
992 Loop *OrigParent = CurLoop->getParentLoop();
993 assert(OrigParent && "Could not find the original parent loop");
994 Loop *NewParentLoop = LMap[OrigParent];
995 assert(NewParentLoop && "Could not find the new parent loop");
996
997 NewParentLoop->addChildLoop(NewLoop);
998 }
999 }
1000
1001 for (BasicBlock *BB : OrigLoop->getBlocks()) {
1002 Loop *CurLoop = LI->getLoopFor(BB);
1003 Loop *&NewLoop = LMap[CurLoop];
1004 assert(NewLoop && "Expecting new loop to be allocated");
1005
1006 BasicBlock *NewBB = CloneBasicBlock(BB, VMap, NameSuffix, F);
1007 VMap[BB] = NewBB;
1008
1009 // Update LoopInfo.
1010 NewLoop->addBasicBlockToLoop(NewBB, *LI);
1011
1012 // Add DominatorTree node. After seeing all blocks, update to correct
1013 // IDom.
1014 DT->addNewBlock(NewBB, NewPH);
1015
1016 Blocks.push_back(NewBB);
1017 }
1018
1019 for (BasicBlock *BB : OrigLoop->getBlocks()) {
1020 // Update loop headers.
1021 Loop *CurLoop = LI->getLoopFor(BB);
1022 if (BB == CurLoop->getHeader())
1023 LMap[CurLoop]->moveToHeader(cast<BasicBlock>(VMap[BB]));
1024
1025 // Update DominatorTree.
1026 BasicBlock *IDomBB = DT->getNode(BB)->getIDom()->getBlock();
1027 DT->changeImmediateDominator(cast<BasicBlock>(VMap[BB]),
1028 cast<BasicBlock>(VMap[IDomBB]));
1029 }
1030
1031 // Move them physically from the end of the block list.
1032 F->splice(Before->getIterator(), F, NewPH->getIterator());
1033 F->splice(Before->getIterator(), F, NewLoop->getHeader()->getIterator(),
1034 F->end());
1035
1036 return NewLoop;
1037}
1038
1039/// Duplicate non-Phi instructions from the beginning of block up to
1040/// StopAt instruction into a split block between BB and its predecessor.
1042 BasicBlock *BB, BasicBlock *PredBB, Instruction *StopAt,
1043 ValueToValueMapTy &ValueMapping, DomTreeUpdater &DTU) {
1044
1045 assert(count(successors(PredBB), BB) == 1 &&
1046 "There must be a single edge between PredBB and BB!");
1047 // We are going to have to map operands from the original BB block to the new
1048 // copy of the block 'NewBB'. If there are PHI nodes in BB, evaluate them to
1049 // account for entry from PredBB.
1050 BasicBlock::iterator BI = BB->begin();
1051 for (; PHINode *PN = dyn_cast<PHINode>(BI); ++BI)
1052 ValueMapping[PN] = PN->getIncomingValueForBlock(PredBB);
1053
1054 BasicBlock *NewBB = SplitEdge(PredBB, BB);
1055 NewBB->setName(PredBB->getName() + ".split");
1056 Instruction *NewTerm = NewBB->getTerminator();
1057
1058 // FIXME: SplitEdge does not yet take a DTU, so we include the split edge
1059 // in the update set here.
1060 DTU.applyUpdates({{DominatorTree::Delete, PredBB, BB},
1061 {DominatorTree::Insert, PredBB, NewBB},
1062 {DominatorTree::Insert, NewBB, BB}});
1063
1064 // Clone the non-phi instructions of BB into NewBB, keeping track of the
1065 // mapping and using it to remap operands in the cloned instructions.
1066 // Stop once we see the terminator too. This covers the case where BB's
1067 // terminator gets replaced and StopAt == BB's terminator.
1068 for (; StopAt != &*BI && BB->getTerminator() != &*BI; ++BI) {
1069 Instruction *New = BI->clone();
1070 New->setName(BI->getName());
1071 New->insertBefore(NewTerm);
1072 ValueMapping[&*BI] = New;
1073
1074 // Remap operands to patch up intra-block references.
1075 for (unsigned i = 0, e = New->getNumOperands(); i != e; ++i)
1076 if (Instruction *Inst = dyn_cast<Instruction>(New->getOperand(i))) {
1077 auto I = ValueMapping.find(Inst);
1078 if (I != ValueMapping.end())
1079 New->setOperand(i, I->second);
1080 }
1081 }
1082
1083 return NewBB;
1084}
1085
1087 DenseMap<MDNode *, MDNode *> &ClonedScopes,
1088 StringRef Ext, LLVMContext &Context) {
1089 MDBuilder MDB(Context);
1090
1091 for (auto *ScopeList : NoAliasDeclScopes) {
1092 for (const auto &MDOperand : ScopeList->operands()) {
1093 if (MDNode *MD = dyn_cast<MDNode>(MDOperand)) {
1094 AliasScopeNode SNANode(MD);
1095
1096 std::string Name;
1097 auto ScopeName = SNANode.getName();
1098 if (!ScopeName.empty())
1099 Name = (Twine(ScopeName) + ":" + Ext).str();
1100 else
1101 Name = std::string(Ext);
1102
1103 MDNode *NewScope = MDB.createAnonymousAliasScope(
1104 const_cast<MDNode *>(SNANode.getDomain()), Name);
1105 ClonedScopes.insert(std::make_pair(MD, NewScope));
1106 }
1107 }
1108 }
1109}
1110
1112 const DenseMap<MDNode *, MDNode *> &ClonedScopes,
1113 LLVMContext &Context) {
1114 auto CloneScopeList = [&](const MDNode *ScopeList) -> MDNode * {
1115 bool NeedsReplacement = false;
1116 SmallVector<Metadata *, 8> NewScopeList;
1117 for (const auto &MDOp : ScopeList->operands()) {
1118 if (MDNode *MD = dyn_cast<MDNode>(MDOp)) {
1119 if (auto *NewMD = ClonedScopes.lookup(MD)) {
1120 NewScopeList.push_back(NewMD);
1121 NeedsReplacement = true;
1122 continue;
1123 }
1124 NewScopeList.push_back(MD);
1125 }
1126 }
1127 if (NeedsReplacement)
1128 return MDNode::get(Context, NewScopeList);
1129 return nullptr;
1130 };
1131
1132 if (auto *Decl = dyn_cast<NoAliasScopeDeclInst>(I))
1133 if (auto *NewScopeList = CloneScopeList(Decl->getScopeList()))
1134 Decl->setScopeList(NewScopeList);
1135
1136 auto replaceWhenNeeded = [&](unsigned MD_ID) {
1137 if (const MDNode *CSNoAlias = I->getMetadata(MD_ID))
1138 if (auto *NewScopeList = CloneScopeList(CSNoAlias))
1139 I->setMetadata(MD_ID, NewScopeList);
1140 };
1141 replaceWhenNeeded(LLVMContext::MD_noalias);
1142 replaceWhenNeeded(LLVMContext::MD_alias_scope);
1143}
1144
1146 ArrayRef<BasicBlock *> NewBlocks,
1147 LLVMContext &Context, StringRef Ext) {
1148 if (NoAliasDeclScopes.empty())
1149 return;
1150
1151 DenseMap<MDNode *, MDNode *> ClonedScopes;
1152 LLVM_DEBUG(dbgs() << "cloneAndAdaptNoAliasScopes: cloning "
1153 << NoAliasDeclScopes.size() << " node(s)\n");
1154
1155 cloneNoAliasScopes(NoAliasDeclScopes, ClonedScopes, Ext, Context);
1156 // Identify instructions using metadata that needs adaptation
1157 for (BasicBlock *NewBlock : NewBlocks)
1158 for (Instruction &I : *NewBlock)
1159 adaptNoAliasScopes(&I, ClonedScopes, Context);
1160}
1161
1163 Instruction *IStart, Instruction *IEnd,
1164 LLVMContext &Context, StringRef Ext) {
1165 if (NoAliasDeclScopes.empty())
1166 return;
1167
1168 DenseMap<MDNode *, MDNode *> ClonedScopes;
1169 LLVM_DEBUG(dbgs() << "cloneAndAdaptNoAliasScopes: cloning "
1170 << NoAliasDeclScopes.size() << " node(s)\n");
1171
1172 cloneNoAliasScopes(NoAliasDeclScopes, ClonedScopes, Ext, Context);
1173 // Identify instructions using metadata that needs adaptation
1174 assert(IStart->getParent() == IEnd->getParent() && "different basic block ?");
1175 auto ItStart = IStart->getIterator();
1176 auto ItEnd = IEnd->getIterator();
1177 ++ItEnd; // IEnd is included, increment ItEnd to get the end of the range
1178 for (auto &I : llvm::make_range(ItStart, ItEnd))
1179 adaptNoAliasScopes(&I, ClonedScopes, Context);
1180}
1181
1183 ArrayRef<BasicBlock *> BBs, SmallVectorImpl<MDNode *> &NoAliasDeclScopes) {
1184 for (BasicBlock *BB : BBs)
1185 for (Instruction &I : *BB)
1186 if (auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&I))
1187 NoAliasDeclScopes.push_back(Decl->getScopeList());
1188}
1189
1192 SmallVectorImpl<MDNode *> &NoAliasDeclScopes) {
1193 for (Instruction &I : make_range(Start, End))
1194 if (auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&I))
1195 NoAliasDeclScopes.push_back(Decl->getScopeList());
1196}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
SmallVector< MachineOperand, 4 > Cond
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool hasRoundingModeOperand(Intrinsic::ID CIID)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define LLVM_DEBUG(X)
Definition: Debug.h:101
std::string Name
uint64_t Size
bool End
Definition: ELF_riscv.cpp:464
DenseMap< Block *, BlockRelaxAux > Blocks
Definition: ELF_riscv.cpp:491
hexagon gen pred
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file contains the declarations for metadata subclasses.
Module.h This file contains the declarations for the Module class.
LLVMContext & Context
@ SI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
This is a simple wrapper around an MDNode which provides a higher-level interface by hiding the detai...
Definition: Metadata.h:1440
const MDNode * getDomain() const
Get the MDNode for this AliasScopeNode's domain.
Definition: Metadata.h:1451
StringRef getName() const
Definition: Metadata.h:1456
an instruction to allocate memory on the stack
Definition: Instructions.h:58
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
AttributeSet getFnAttrs() const
The function attributes are returned.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the function.
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
iterator end()
Definition: BasicBlock.h:325
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:323
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
Definition: BasicBlock.h:504
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:88
const Instruction & front() const
Definition: BasicBlock.h:335
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:105
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:293
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:112
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
Definition: BasicBlock.cpp:132
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:87
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:35
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.h:127
const Instruction & back() const
Definition: BasicBlock.h:337
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Definition: BasicBlock.cpp:146
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1762
Conditional or Unconditional Branch instruction.
bool isConditional() const
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
BasicBlock * getSuccessor(unsigned i) const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1190
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1412
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:711
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
This is an important base class in LLVM.
Definition: Constant.h:41
Base class for scope-like contexts.
Subprogram description.
Base class for types.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
This is the common base class for debug info intrinsics for variables.
Utility to find all debug info in a module.
Definition: DebugInfo.h:93
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
Definition: DebugInfo.cpp:183
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:202
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
Definition: DenseMap.h:235
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
DomTreeNodeBase * getIDom() const
NodeT * getBlock() const
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
Class to represent function types.
Definition: DerivedTypes.h:103
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:136
const BasicBlock & getEntryBlock() const
Definition: Function.h:749
BasicBlockListType::iterator iterator
Definition: Function.h:65
void setPrefixData(Constant *PrefixData)
Definition: Function.cpp:1976
const BasicBlock & front() const
Definition: Function.h:772
iterator_range< arg_iterator > args()
Definition: Function.h:804
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1725
bool hasPrefixData() const
Check whether this function has prefix data.
Definition: Function.h:826
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:817
Constant * getPrologueData() const
Get the prologue data associated with this function.
Definition: Function.cpp:1981
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1961
void setPersonalityFn(Constant *Fn)
Definition: Function.cpp:1966
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:313
arg_iterator arg_begin()
Definition: Function.h:780
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition: Function.h:209
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:316
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:319
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
Definition: Function.h:696
size_t arg_size() const
Definition: Function.h:813
void setPrologueData(Constant *PrologueData)
Definition: Function.cpp:1986
Constant * getPrefixData() const
Get the prefix data associated with this function.
Definition: Function.cpp:1971
iterator end()
Definition: Function.h:767
bool hasPrologueData() const
Check whether this function has prologue data.
Definition: Function.h:835
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition: Function.cpp:756
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
Definition: Metadata.cpp:1380
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
Definition: Metadata.cpp:1425
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:273
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
const BasicBlock * getParent() const
Definition: Instruction.h:90
bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
SymbolTableList< Instruction >::iterator insertInto(BasicBlock *ParentBB, SymbolTableList< Instruction >::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
Definition: Instruction.cpp:98
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:82
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
SmallVector< const LoopT *, 4 > getLoopsInPreorder() const
Return all loops in the loop nest rooted by the loop in preorder, with siblings in forward program or...
BlockT * getHeader() const
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
void addChildLoop(LoopT *NewChild)
Add the specified loop to be a child of this loop.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
LoopT * getParentLoop() const
Return the parent loop if it exists or nullptr for top level loops.
void addTopLevelLoop(LoopT *New)
This adds the specified loop to the collection of top-level loops.
LoopT * AllocateLoop(ArgsTy &&...Args)
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:47
MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())
Return metadata appropriate for an alias scope root node.
Definition: MDBuilder.h:159
Metadata node.
Definition: Metadata.h:950
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1416
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:772
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:499
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:102
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:398
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition: Module.cpp:260
void setIncomingBlock(unsigned i, BasicBlock *BB)
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
void setIncomingValue(unsigned i, Value *V)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1743
Return a value (possibly void), from a function.
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:88
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:152
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:383
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:365
bool contains(ConstPtrType Ptr) const
Definition: SmallPtrSet.h:389
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:312
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A handle to a particular switch case.
BasicBlockT * getCaseSuccessor() const
Resolves successor for current case.
Multiway switch.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Value * getOperand(unsigned i) const
Definition: User.h:169
unsigned getNumOperands() const
Definition: User.h:191
This is a class that can be implemented by clients to remap types when cloning constants and instruct...
Definition: ValueMapper.h:36
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: ValueMap.h:164
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: ValueMap.h:151
iterator find(const KeyT &Val)
Definition: ValueMap.h:155
MDMapT & MD()
Definition: ValueMap.h:114
iterator end()
Definition: ValueMap.h:135
This is a class that can be implemented by clients to materialize Values on demand.
Definition: ValueMapper.h:49
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:378
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:535
iterator_range< user_iterator > users()
Definition: Value.h:421
void deleteValue()
Delete a pointer to a generic Value.
Definition: Value.cpp:110
bool hasName() const
Definition: Value.h:261
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
Value handle that is nullable, but tries to track the Value.
Definition: ValueHandle.h:204
self_iterator getIterator()
Definition: ilist_node.h:82
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Function.cpp:1293
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1465
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DomTreeUpdater *DTU=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
Definition: Local.cpp:126
auto successors(const MachineBasicBlock *BB)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:2129
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...
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
Metadata * MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Lookup or compute a mapping for a piece of metadata.
Definition: ValueMapper.h:233
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
Definition: Local.cpp:398
BasicBlock * CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap, const Twine &NameSuffix="", Function *F=nullptr, ClonedCodeInfo *CodeInfo=nullptr, DebugInfoFinder *DIFinder=nullptr)
Return a copy of the specified basic block, but without embedding the block into a particular functio...
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:65
@ RF_IgnoreMissingLocals
If this flag is set, the remapper ignores missing function-local entries (Argument,...
Definition: ValueMapper.h:89
@ RF_None
Definition: ValueMapper.h:66
@ RF_NoModuleLevelChanges
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
Definition: ValueMapper.h:71
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...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
void cloneNoAliasScopes(ArrayRef< MDNode * > NoAliasDeclScopes, DenseMap< MDNode *, MDNode * > &ClonedScopes, StringRef Ext, LLVMContext &Context)
Duplicate the specified list of noalias decl scopes.
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Convert the instruction operands from referencing the current values into those specified by VM.
Definition: ValueMapper.h:256
Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr)
Returns constrained intrinsic id to represent the given instruction in strictfp function.
Definition: FPEnv.cpp:90
Value * MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Look up or compute a value in the value map.
Definition: ValueMapper.h:211
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:2011
void adaptNoAliasScopes(llvm::Instruction *I, const DenseMap< MDNode *, MDNode * > &ClonedScopes, LLVMContext &Context)
Adapt the metadata for the specified instruction according to the provided mapping.
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
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.
auto predecessors(const MachineBasicBlock *BB)
void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified blocks from BB.
void identifyNoAliasScopesToClone(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< MDNode * > &NoAliasDeclScopes)
Find the 'llvm.experimental.noalias.scope.decl' intrinsics in the specified basic blocks and extract ...
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the edge connecting the specified blocks, and return the newly created basic block between From...
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.
unsigned pred_size(const MachineBasicBlock *BB)
Function * CloneFunction(Function *F, ValueToValueMapTy &VMap, ClonedCodeInfo *CodeInfo=nullptr)
Return a copy of the specified function and add it to that function's module.
#define N
This struct can be used to capture information about code being cloned, while it is being cloned.
Definition: Cloning.h:62
bool ContainsDynamicAllocas
This is set to true if the cloned code contains a 'dynamic' alloca.
Definition: Cloning.h:73
bool ContainsCalls
This is set to true if the cloned code contains a normal call instruction.
Definition: Cloning.h:64
bool ContainsMemProfMetadata
This is set to true if there is memprof related metadata (memprof or callsite metadata) in the cloned...
Definition: Cloning.h:68
DenseMap< const Value *, const Value * > OrigVMap
Like VMap, but maps only unsimplified instructions.
Definition: Cloning.h:83
std::vector< WeakTrackingVH > OperandBundleCallSites
All cloned call sites that have operand bundles attached are appended to this vector.
Definition: Cloning.h:78
This is a type descriptor which explains the type requirements of an intrinsic.
Definition: Intrinsics.h:110
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
ArgKind getArgumentKind() const
Definition: Intrinsics.h:169