41#define DEBUG_TYPE "clone-function"
53 bool hasCalls =
false, hasDynamicAllocas =
false, hasMemProfMetadata =
false;
54 Module *TheModule =
F ?
F->getParent() :
nullptr;
58 if (DIFinder && TheModule)
63 NewInst->
setName(
I.getName() + NameSuffix);
70 if (isa<CallInst>(
I) && !
I.isDebugOrPseudoInst()) {
72 hasMemProfMetadata |=
I.hasMetadata(LLVMContext::MD_memprof);
74 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&
I)) {
75 if (!AI->isStaticAlloca()) {
76 hasDynamicAllocas =
true;
100 assert(NameSuffix &&
"NameSuffix cannot be null!");
104 assert(VMap.
count(&
I) &&
"No mapping from source argument specified!");
107 bool ModuleLevelChanges = Changes > CloneFunctionChangeType::LocalChangesOnly;
121 FuncGlobalRefFlags, TypeMapper,
126 FuncGlobalRefFlags, TypeMapper,
132 FuncGlobalRefFlags, TypeMapper,
141 if (
Argument *NewArg = dyn_cast<Argument>(VMap[&OldArg])) {
142 NewArgAttrs[NewArg->getArgNo()] =
161 std::optional<DebugInfoFinder> DIFinder;
166 if (Changes < CloneFunctionChangeType::DifferentModule) {
169 "Expected NewFunc to have the same parent, or no parent");
175 if (SPClonedWithinModule)
176 DIFinder->processSubprogram(SPClonedWithinModule);
180 "Expected NewFunc to have different parents, or no parent");
182 if (Changes == CloneFunctionChangeType::DifferentModule) {
184 "Need parent of new function to maintain debug info invariants");
198 DIFinder ? &*DIFinder :
nullptr);
209 if (BB.hasAddressTaken()) {
220 if (Changes < CloneFunctionChangeType::DifferentModule &&
221 DIFinder->subprogram_count() > 0) {
227 ModuleLevelChanges =
true;
229 auto mapToSelfIfNew = [&VMap](
MDNode *
N) {
237 if (ISP != SPClonedWithinModule) {
239 MappedToSelfSPs.
insert(ISP);
244 for (
DIScope *S : DIFinder->scopes()) {
245 auto *LScope = dyn_cast<DILocalScope>(S);
246 if (LScope && MappedToSelfSPs.
count(LScope->getSubprogram()))
254 mapToSelfIfNew(
Type);
256 assert(!SPClonedWithinModule &&
257 "Subprogram should be in DIFinder->subprogram_count()...");
266 for (
auto MD : MDs) {
268 TypeMapper, Materializer));
274 BB = cast<BasicBlock>(VMap[&OldFunc->
front()])->getIterator(),
282 RemapFlag, TypeMapper, Materializer);
288 if (Changes != CloneFunctionChangeType::DifferentModule)
305 for (
auto *Operand : NMD->operands())
307 for (
auto *Unit : DIFinder->compile_units()) {
310 if (Visited.
insert(MappedUnit).second)
311 NMD->addOperand(MappedUnit);
324 std::vector<Type *> ArgTypes;
331 ArgTypes.push_back(
I.getType());
335 FunctionType::get(
F->getFunctionType()->getReturnType(), ArgTypes,
336 F->getFunctionType()->isVarArg());
340 F->getName(),
F->getParent());
346 if (VMap.
count(&
I) == 0) {
348 VMap[&
I] = &*DestI++;
353 Returns,
"", CodeInfo);
360struct PruningFunctionCloner {
364 bool ModuleLevelChanges;
365 const char *NameSuffix;
367 bool HostFuncIsStrictFP;
375 : NewFunc(newFunc), OldFunc(oldFunc), VMap(valueMap),
376 ModuleLevelChanges(moduleLevelChanges), NameSuffix(nameSuffix),
385 std::vector<const BasicBlock *> &ToClone);
391#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
392 case Intrinsic::INTRINSIC: \
393 return ROUND_MODE == 1;
394#define FUNCTION INSTRUCTION
395#include "llvm/IR/ConstrainedOps.def"
405 if (HostFuncIsStrictFP) {
417 for (
unsigned I = 0, E = Descriptor.
size();
I != E; ++
I) {
419 switch (Operand.
Kind) {
422 Intrinsic::IITDescriptor::AK_MatchType) {
443 if (isa<CallInst>(OldInst))
445 for (
unsigned I = 0;
I < NumOperands; ++
I) {
449 if (
const auto *CmpI = dyn_cast<FCmpInst>(&OldInst)) {
451 StringRef PredName = FCmpInst::getPredicateName(Pred);
468 NewInst = II->
clone();
474void PruningFunctionCloner::CloneBlock(
476 std::vector<const BasicBlock *> &ToClone) {
504 bool hasCalls =
false, hasDynamicAllocas =
false, hasStaticAllocas =
false;
505 bool hasMemProfMetadata =
false;
509 auto CloneDbgRecordsToHere =
517 for (; DbgCursor != II; ++DbgCursor)
518 NewInst->cloneDebugInfoFrom(&*DbgCursor, std::nullopt,
false);
519 NewInst->cloneDebugInfoFrom(&*II);
520 DbgCursor = std::next(II);
531 if (HostFuncIsStrictFP) {
534 if (
auto *Call = dyn_cast<CallInst>(NewInst))
535 Call->addFnAttr(Attribute::StrictFP);
541 if (!isa<PHINode>(NewInst) && !isa<DbgVariableIntrinsic>(NewInst)) {
560 NewInst->
setName(II->getName() + NameSuffix);
561 VMap[&*II] = NewInst;
562 if (isa<CallInst>(II) && !II->isDebugOrPseudoInst()) {
564 hasMemProfMetadata |= II->hasMetadata(LLVMContext::MD_memprof);
567 CloneDbgRecordsToHere(NewInst, II);
571 if (
auto *CB = dyn_cast<CallBase>(&*II))
572 if (CB->hasOperandBundles())
576 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
577 if (isa<ConstantInt>(AI->getArraySize()))
578 hasStaticAllocas =
true;
580 hasDynamicAllocas =
true;
586 bool TerminatorDone =
false;
587 if (
const BranchInst *BI = dyn_cast<BranchInst>(OldTI)) {
588 if (BI->isConditional()) {
594 Cond = dyn_cast_or_null<ConstantInt>(V);
601 ToClone.push_back(Dest);
602 TerminatorDone =
true;
605 }
else if (
const SwitchInst *SI = dyn_cast<SwitchInst>(OldTI)) {
610 Cond = dyn_cast_or_null<ConstantInt>(V);
616 ToClone.push_back(Dest);
617 TerminatorDone =
true;
621 if (!TerminatorDone) {
627 CloneDbgRecordsToHere(NewInst, OldTI->
getIterator());
629 VMap[OldTI] = NewInst;
632 CodeInfo->
OrigVMap[OldTI] = NewInst;
633 if (
auto *CB = dyn_cast<CallBase>(OldTI))
634 if (CB->hasOperandBundles())
646 CloneDbgRecordsToHere(NewInst, OldTI->
getIterator());
664 bool ModuleLevelChanges,
666 const char *NameSuffix,
668 assert(NameSuffix &&
"NameSuffix cannot be null!");
678 assert(VMap.
count(&II) &&
"No mapping from source argument specified!");
681 PruningFunctionCloner PFC(NewFunc, OldFunc, VMap, ModuleLevelChanges,
682 NameSuffix, CodeInfo);
688 StartingInst = &StartingBB->
front();
693 for (
const auto &BB : *OldFunc) {
694 for (
const auto &
I : BB) {
695 if (
const auto *DVI = dyn_cast<DbgVariableIntrinsic>(&
I))
701 std::vector<const BasicBlock *> CloneWorklist;
702 PFC.CloneBlock(StartingBB, StartingInst->
getIterator(), CloneWorklist);
703 while (!CloneWorklist.empty()) {
705 CloneWorklist.pop_back();
706 PFC.CloneBlock(BB, BB->
begin(), CloneWorklist);
717 BasicBlock *NewBB = cast_or_null<BasicBlock>(V);
726 for (
const PHINode &PN : BI.phis()) {
729 if (isa<PHINode>(VMap[&PN]))
739 TypeMapper, Materializer);
744 for (
unsigned phino = 0, e = PHIToResolve.
size(); phino != e;) {
745 const PHINode *OPN = PHIToResolve[phino];
748 BasicBlock *NewBB = cast<BasicBlock>(VMap[OldBB]);
752 for (; phino != PHIToResolve.
size() &&
753 PHIToResolve[phino]->
getParent() == OldBB;
755 OPN = PHIToResolve[phino];
756 PHINode *PN = cast<PHINode>(VMap[OPN]);
757 for (
unsigned pred = 0, e = NumPreds;
pred != e; ++
pred) {
759 if (
BasicBlock *MappedBlock = cast_or_null<BasicBlock>(V)) {
763 assert(InVal &&
"Unknown input value?");
782 assert(NumPreds < PN->getNumIncomingValues());
784 std::map<BasicBlock *, unsigned> PredCount;
796 for (; (PN = dyn_cast<PHINode>(
I)); ++
I) {
797 for (
const auto &PCI : PredCount) {
799 for (
unsigned NumToRemove = PCI.second; NumToRemove; --NumToRemove)
808 PN = cast<PHINode>(NewBB->
begin());
812 while ((PN = dyn_cast<PHINode>(
I++))) {
815 assert(VMap[&*OldI] == PN &&
"VMap mismatch");
834 for (
const auto &BB : *OldFunc) {
835 for (
const auto &
I : BB) {
836 auto *NewI = dyn_cast_or_null<Instruction>(VMap.
lookup(&
I));
842 CallBase *CB = dyn_cast<CallBase>(NewI);
848 NewI->replaceAllUsesWith(V);
851 NewI->eraseFromParent();
869 for (
const auto *DVI : DbgIntrinsics) {
871 cast_or_null<DbgVariableIntrinsic>(VMap.
lookup(DVI)))
874 TypeMapper, Materializer);
885 TypeMapper, Materializer);
902 while (!Worklist.
empty()) {
904 if (ReachableBlocks.
insert(BB).second)
920 while (
I != NewFunc->
end()) {
921 BranchInst *BI = dyn_cast<BranchInst>(
I->getTerminator());
945 I->splice(
I->end(), Dest);
959 if (
ReturnInst *RI = dyn_cast<ReturnInst>(
I->getTerminator()))
975 ModuleLevelChanges, Returns, NameSuffix, CodeInfo);
983 for (
auto &Inst : *BB) {
985 Inst.getModule(), Inst.getDbgRecordRange(), VMap,
1008 LMap[OrigLoop] = NewLoop;
1015 assert(OrigPH &&
"No preheader");
1018 VMap[OrigPH] = NewPH;
1029 Loop *&NewLoop = LMap[CurLoop];
1035 assert(OrigParent &&
"Could not find the original parent loop");
1036 Loop *NewParentLoop = LMap[OrigParent];
1037 assert(NewParentLoop &&
"Could not find the new parent loop");
1045 Loop *&NewLoop = LMap[CurLoop];
1046 assert(NewLoop &&
"Expecting new loop to be allocated");
1065 LMap[CurLoop]->moveToHeader(cast<BasicBlock>(VMap[BB]));
1070 cast<BasicBlock>(VMap[IDomBB]));
1088 "There must be a single edge between PredBB and BB!");
1093 for (;
PHINode *PN = dyn_cast<PHINode>(BI); ++BI)
1103 {DominatorTree::Insert, PredBB, NewBB},
1104 {DominatorTree::Insert, NewBB, BB}});
1110 for (; StopAt != &*BI && BB->
getTerminator() != &*BI; ++BI) {
1112 New->setName(BI->getName());
1113 New->insertBefore(NewTerm);
1114 New->cloneDebugInfoFrom(&*BI);
1115 ValueMapping[&*BI] = New;
1118 for (
unsigned i = 0, e = New->getNumOperands(); i != e; ++i)
1119 if (
Instruction *Inst = dyn_cast<Instruction>(New->getOperand(i))) {
1120 auto I = ValueMapping.
find(Inst);
1121 if (
I != ValueMapping.
end())
1122 New->setOperand(i,
I->second);
1137 for (
auto *ScopeList : NoAliasDeclScopes) {
1138 for (
const auto &
MDOperand : ScopeList->operands()) {
1143 auto ScopeName = SNANode.
getName();
1144 if (!ScopeName.empty())
1145 Name = (
Twine(ScopeName) +
":" + Ext).str();
1147 Name = std::string(Ext);
1151 ClonedScopes.
insert(std::make_pair(MD, NewScope));
1160 auto CloneScopeList = [&](
const MDNode *ScopeList) ->
MDNode * {
1161 bool NeedsReplacement =
false;
1163 for (
const auto &MDOp : ScopeList->operands()) {
1164 if (
MDNode *MD = dyn_cast<MDNode>(MDOp)) {
1165 if (
auto *NewMD = ClonedScopes.
lookup(MD)) {
1167 NeedsReplacement =
true;
1173 if (NeedsReplacement)
1178 if (
auto *Decl = dyn_cast<NoAliasScopeDeclInst>(
I))
1179 if (
auto *NewScopeList = CloneScopeList(Decl->getScopeList()))
1180 Decl->setScopeList(NewScopeList);
1182 auto replaceWhenNeeded = [&](
unsigned MD_ID) {
1183 if (
const MDNode *CSNoAlias =
I->getMetadata(MD_ID))
1184 if (
auto *NewScopeList = CloneScopeList(CSNoAlias))
1185 I->setMetadata(MD_ID, NewScopeList);
1187 replaceWhenNeeded(LLVMContext::MD_noalias);
1188 replaceWhenNeeded(LLVMContext::MD_alias_scope);
1194 if (NoAliasDeclScopes.
empty())
1199 << NoAliasDeclScopes.
size() <<
" node(s)\n");
1211 if (NoAliasDeclScopes.
empty())
1216 << NoAliasDeclScopes.
size() <<
" node(s)\n");
1232 if (
auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&
I))
1233 NoAliasDeclScopes.
push_back(Decl->getScopeList());
1240 if (
auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&
I))
1241 NoAliasDeclScopes.
push_back(Decl->getScopeList());
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
static bool hasRoundingModeOperand(Intrinsic::ID CIID)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DenseMap< Block *, BlockRelaxAux > Blocks
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Module.h This file contains the declarations for the Module class.
const SmallVectorImpl< MachineOperand > & Cond
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...
const MDNode * getDomain() const
Get the MDNode for this AliasScopeNode's domain.
StringRef getName() const
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
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.
iterator begin()
Instruction iterator methods.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
InstListType::const_iterator const_iterator
const Instruction & front() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
const Function * getParent() const
Return the enclosing method, or null if none.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
InstListType::iterator iterator
Instruction iterators...
LLVMContext & getContext() const
Get the context in which this basic block lives.
bool IsNewDbgInfoFormat
Flag recording whether or not this block stores debug-info in the form of intrinsic instructions (fal...
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
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...
const Instruction & back() const
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, BasicBlock::iterator InsertBefore)
bool isConditional() const
BasicBlock * getSuccessor(unsigned i) const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr, BasicBlock::iterator InsertBefore)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
This is the shared class of boolean and integer constants.
This is an important base class in LLVM.
Base class for scope-like contexts.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
This is the common base class for debug info intrinsics for variables.
Utility to find all debug info in a module.
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
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...
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
DomTreeNodeBase * getIDom() 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.
Class to represent function types.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
const BasicBlock & getEntryBlock() const
BasicBlockListType::iterator iterator
void setPrefixData(Constant *PrefixData)
const BasicBlock & front() const
iterator_range< arg_iterator > args()
DISubprogram * getSubprogram() const
Get the attached subprogram.
bool IsNewDbgInfoFormat
Is this function using intrinsics to record the position of debugging information,...
bool hasPrefixData() const
Check whether this function has prefix data.
bool hasPersonalityFn() const
Check whether this function has a personality function.
Constant * getPrologueData() const
Get the prologue data associated with this function.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
void setPersonalityFn(Constant *Fn)
AttributeList getAttributes() const
Return the attribute list for this Function.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
void setPrologueData(Constant *PrologueData)
void removeRetAttrs(const AttributeMask &Attrs)
removes the attributes from the return value list of attributes.
void setIsNewDbgInfoFormat(bool NewVal)
Type * getReturnType() const
Returns the type of the ret val.
Constant * getPrefixData() const
Get the prefix data associated with this function.
bool hasPrologueData() const
Check whether this function has prologue data.
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Module * getParent()
Get the module that this global value is contained inside of...
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(const Instruction *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere=std::nullopt, bool InsertAtHead=false)
Clone any debug-info attached to From onto this instruction.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
const BasicBlock * getParent() const
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
This is an important class for using LLVM in a threaded context.
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.
MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())
Return metadata appropriate for an alias scope root node.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Tracking metadata reference owned by Metadata.
static MDString * get(LLVMContext &Context, StringRef Str)
A Module instance is used to store all the information related to an LLVM module.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
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.
Return a value (possibly void), from a function.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
A handle to a particular switch case.
BasicBlockT * getCaseSuccessor() const
Resolves successor for current case.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
This is a class that can be implemented by clients to remap types when cloning constants and instruct...
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
iterator find(const KeyT &Val)
This is a class that can be implemented by clients to materialize Values on demand.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
StringRef getName() const
Return a constant reference to the value's name.
Value handle that is nullable, but tries to track the Value.
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
AttributeMask typeIncompatible(Type *Ty, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
This is an optimization pass for GlobalISel generic memory operations.
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...
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 range R to container C.
void remapDebugVariable(ValueToValueMapTy &Mapping, Instruction *Inst)
Remap the operands of the debug records attached to Inst, and the operands of Inst itself if it's a d...
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 RemapDbgVariableRecordRange(Module *M, iterator_range< DbgRecordIterator > Range, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Remap the Values used in the DbgVariableRecord V using the value map VM.
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.
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.
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.
@ RF_IgnoreMissingLocals
If this flag is set, the remapper ignores missing function-local entries (Argument,...
@ RF_NoModuleLevelChanges
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
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.
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.
Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr)
Returns constrained intrinsic id to represent the given instruction in strictfp function.
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.
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...
void adaptNoAliasScopes(llvm::Instruction *I, const DenseMap< MDNode *, MDNode * > &ClonedScopes, LLVMContext &Context)
Adapt the metadata for the specified instruction according to the provided mapping.
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
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.
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.
This struct can be used to capture information about code being cloned, while it is being cloned.
bool ContainsDynamicAllocas
This is set to true if the cloned code contains a 'dynamic' alloca.
bool ContainsCalls
This is set to true if the cloned code contains a normal call instruction.
bool ContainsMemProfMetadata
This is set to true if there is memprof related metadata (memprof or callsite metadata) in the cloned...
DenseMap< const Value *, const Value * > OrigVMap
Like VMap, but maps only unsimplified instructions.
std::vector< WeakTrackingVH > OperandBundleCallSites
All cloned call sites that have operand bundles attached are appended to this vector.
This is a type descriptor which explains the type requirements of an intrinsic.
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
ArgKind getArgumentKind() const