48#define DEBUG_TYPE "value-mapper"
51void ValueMapTypeRemapper::anchor() {}
52void ValueMaterializer::anchor() {}
58struct DelayedBasicBlock {
60 std::unique_ptr<BasicBlock> TempBB;
62 DelayedBasicBlock(
const BlockAddress &Old)
63 : OldBB(Old.getBasicBlock()),
78 struct AppendingGVTy {
80 GlobalVariable *OldGV;
82 struct AliasOrIFuncTy {
89 unsigned AppendingGVIsOldCtorDtor : 1;
90 unsigned AppendingGVNumNewMembers;
93 AppendingGVTy AppendingGV;
94 AliasOrIFuncTy AliasOrIFunc;
99struct MappingContext {
101 ValueMaterializer *Materializer =
nullptr;
105 ValueMaterializer *Materializer =
nullptr)
106 : VM(&VM), Materializer(Materializer) {}
110 friend class MDNodeMapper;
113 DenseSet<GlobalValue *> AlreadyScheduled;
117 ValueMapTypeRemapper *TypeMapper;
118 unsigned CurrentMCID = 0;
127 ValueMapTypeRemapper *TypeMapper, ValueMaterializer *Materializer,
130 MCs(1, MappingContext(VM, Materializer)), IdentityMD(IdentityMD) {}
133 ~Mapper() {
assert(!hasWorkToDo() &&
"Expected to be flushed"); }
135 bool hasWorkToDo()
const {
return !Worklist.
empty(); }
139 ValueMaterializer *Materializer =
nullptr) {
140 MCs.
push_back(MappingContext(VM, Materializer));
141 return MCs.
size() - 1;
146 void remapGlobalObjectMetadata(GlobalObject &GO);
149 void remapInstruction(Instruction *
I);
151 void remapDbgRecord(DbgRecord &DVR);
153 Constant *mapConstant(
const Constant *
C) {
163 void scheduleMapGlobalInitializer(GlobalVariable &GV, Constant &Init,
165 void scheduleMapAppendingVariable(GlobalVariable &GV, GlobalVariable *OldGV,
169 void scheduleMapAliasOrIFunc(GlobalValue &GV, Constant &Target,
171 void scheduleRemapFunction(
Function &
F,
unsigned MCID);
176 void mapAppendingVariable(GlobalVariable &GV, GlobalVariable *OldGV,
181 ValueMaterializer *getMaterializer() {
return MCs[CurrentMCID].Materializer; }
183 Value *mapBlockAddress(
const BlockAddress &BA);
186 std::optional<Metadata *> mapSimpleMetadata(
const Metadata *MD);
197 bool HasChanged =
false;
198 unsigned ID = std::numeric_limits<unsigned>::max();
199 TempMDNode Placeholder;
203 struct UniquedGraph {
204 SmallDenseMap<const Metadata *, Data, 32>
Info;
211 void propagateChanges();
221 MDNodeMapper(Mapper &M) :
M(
M) {}
263 Metadata *mapTopLevelUniquedNode(
const MDNode &FirstN);
274 std::optional<Metadata *> tryToMapOperand(
const Metadata *
Op);
283 MDNode *mapDistinctNode(
const MDNode &
N);
302 bool createPOT(UniquedGraph &
G,
const MDNode &FirstN);
323 void mapNodesInPOT(UniquedGraph &
G);
331 template <
class OperandMapper>
341 if (
I != getVM().
end()) {
342 assert(
I->second &&
"Unexpected null mapping");
347 if (
auto *Materializer = getMaterializer()) {
348 if (
Value *NewV = Materializer->materialize(
const_cast<Value *
>(
V))) {
359 return getVM()[
V] =
const_cast<Value *
>(
V);
368 if (NewTy !=
IA->getFunctionType())
370 IA->hasSideEffects(),
IA->isAlignStack(),
371 IA->getDialect(),
IA->canThrow());
374 return getVM()[
V] =
const_cast<Value *
>(
V);
378 const Metadata *MD = MDV->getMetadata();
382 if (
Value *LV = mapValue(
LAM->getValue())) {
383 if (
V ==
LAM->getValue())
384 return const_cast<Value *
>(
V);
397 for (
auto *VAM :
AL->getArgs()) {
405 }
else if (
Value *LV = mapValue(VAM->getValue())) {
423 return getVM()[
V] =
const_cast<Value *
>(
V);
426 auto *MappedMD = mapMetadata(MD);
428 return getVM()[
V] =
const_cast<Value *
>(
V);
439 return mapBlockAddress(*BA);
442 auto *Val = mapValue(
E->getGlobalValue());
448 Type *NewTy =
E->getType();
456 auto *Val = mapValue(
NC->getGlobalValue());
461 auto mapValueOrNull = [
this](
Value *
V) {
462 auto Mapped = mapValue(
V);
464 "Unexpected null mapping for constant operand without "
465 "NullMapMissingGlobalValues flag");
471 unsigned OpNo = 0, NumOperands =
C->getNumOperands();
472 Value *Mapped =
nullptr;
473 for (; OpNo != NumOperands; ++OpNo) {
475 Mapped = mapValueOrNull(
Op);
483 Type *NewTy =
C->getType();
489 if (OpNo == NumOperands && NewTy ==
C->getType())
490 return getVM()[
V] =
C;
496 for (
unsigned j = 0;
j != OpNo; ++
j)
500 if (OpNo != NumOperands) {
504 for (++OpNo; OpNo != NumOperands; ++OpNo) {
505 Mapped = mapValueOrNull(
C->getOperand(OpNo));
511 Type *NewSrcTy =
nullptr;
514 NewSrcTy = TypeMapper->
remapType(GEPO->getSourceElementType());
517 return getVM()[
V] =
CE->getWithOperands(
Ops, NewTy,
false, NewSrcTy);
541void Mapper::remapDbgRecord(
DbgRecord &DR) {
554 auto *MappedVar = mapMetadata(
V.getVariable());
559 if (
V.isDbgAssign()) {
560 auto *NewAddr = mapValue(
V.getAddress());
561 if (!IgnoreMissingLocals && !NewAddr)
564 V.setAddress(NewAddr);
571 for (
Value *Val : Vals)
584 for (
unsigned int I = 0;
I < Vals.size(); ++
I)
586 V.replaceVariableLocationOp(
I, NewVals[
I]);
598 DelayedBBs.
push_back(DelayedBasicBlock(BA));
599 BB = DelayedBBs.
back().TempBB.get();
608 getVM().MD()[
Key].reset(Val);
613 return mapToMetadata(MD,
const_cast<Metadata *
>(MD));
616std::optional<Metadata *> MDNodeMapper::tryToMapOperand(
const Metadata *
Op) {
620 if (std::optional<Metadata *> MappedOp =
M.mapSimpleMetadata(
Op)) {
623 assert((!*MappedOp ||
M.getVM().count(CMD->getValue()) ||
624 M.getVM().getMappedMD(
Op)) &&
625 "Expected Value to be memoized");
628 "Expected result to be memoized");
635 return mapDistinctNode(
N);
640 assert(
N.isDistinct() &&
"Expected a distinct node");
641 assert(!
M.getVM().getMappedMD(&
N) &&
"Expected an unmapped node");
645 NewM =
M.mapToSelf(&
N);
649 <<
"To " << *NewM <<
"\n\n");
650 M.mapToMetadata(&
N, NewM);
654 return DistinctWorklist.back();
664std::optional<Metadata *> MDNodeMapper::getMappedOp(
const Metadata *
Op)
const {
668 if (std::optional<Metadata *> MappedOp =
M.getVM().getMappedMD(
Op))
681 auto Where =
Info.find(&
Op);
682 assert(Where !=
Info.end() &&
"Expected a valid reference");
684 auto &OpD = Where->second;
689 if (!OpD.Placeholder)
690 OpD.Placeholder =
Op.clone();
692 return *OpD.Placeholder;
695template <
class OperandMapper>
696void MDNodeMapper::remapOperands(
MDNode &
N, OperandMapper mapOperand) {
697 assert(!
N.isUniqued() &&
"Expected distinct or temporary nodes");
698 for (
unsigned I = 0,
E =
N.getNumOperands();
I !=
E; ++
I) {
702 LLVM_DEBUG(
dbgs() <<
"Replacing Op " << Old <<
" with " << New <<
" in "
706 N.replaceOperandWith(
I, New);
713struct POTWorklistEntry {
719 bool HasChanged =
false;
721 POTWorklistEntry(MDNode &
N) :
N(&
N),
Op(
N.op_begin()) {}
726bool MDNodeMapper::createPOT(UniquedGraph &
G,
const MDNode &FirstN) {
727 assert(
G.Info.empty() &&
"Expected a fresh traversal");
731 bool AnyChanges =
false;
734 (void)
G.Info[&FirstN];
735 while (!Worklist.
empty()) {
737 auto &WE = Worklist.
back();
738 if (
MDNode *
N = visitOperands(
G, WE.Op, WE.N->op_end(), WE.HasChanged)) {
745 assert(WE.N->isUniqued() &&
"Expected only uniqued nodes");
746 assert(WE.Op == WE.N->op_end() &&
"Expected to visit all operands");
747 auto &
D =
G.Info[WE.N];
748 AnyChanges |=
D.HasChanged = WE.HasChanged;
750 G.POT.push_back(WE.N);
762 if (std::optional<Metadata *> MappedOp = tryToMapOperand(
Op)) {
764 HasChanged |=
Op != *MappedOp;
771 "Only uniqued operands cannot be mapped immediately");
772 if (
G.Info.try_emplace(&OpN).second)
778void MDNodeMapper::UniquedGraph::propagateChanges() {
788 auto Where = Info.find(Op);
789 return Where != Info.end() && Where->second.HasChanged;
793 AnyChanges =
D.HasChanged =
true;
795 }
while (AnyChanges);
798void MDNodeMapper::mapNodesInPOT(UniquedGraph &
G) {
801 for (
auto *
N :
G.POT) {
810 bool HadPlaceholder(
D.Placeholder);
813 TempMDNode ClonedN =
D.Placeholder ? std::move(
D.Placeholder) :
N->clone();
815 if (std::optional<Metadata *> MappedOp =
getMappedOp(Old))
818 assert(
G.Info[Old].ID >
D.ID &&
"Expected a forward reference");
823 if (
N && NewN &&
N != NewN) {
825 <<
"To " << *NewN <<
"\n\n");
828 M.mapToMetadata(
N, NewN);
837 for (
auto *
N : CyclicNodes)
838 if (!
N->isResolved())
843 assert(DistinctWorklist.empty() &&
"MDNodeMapper::map is not recursive");
845 "MDNodeMapper::map assumes module-level changes");
848 assert(
N.isResolved() &&
"Unexpected unresolved node");
851 N.isUniqued() ? mapTopLevelUniquedNode(
N) : mapDistinctNode(
N);
852 while (!DistinctWorklist.empty())
854 if (std::optional<Metadata *> MappedOp = tryToMapOperand(Old))
856 return mapTopLevelUniquedNode(*cast<MDNode>(Old));
861Metadata *MDNodeMapper::mapTopLevelUniquedNode(
const MDNode &FirstN) {
866 if (!createPOT(
G, FirstN)) {
870 return &
const_cast<MDNode &
>(FirstN);
874 G.propagateChanges();
883std::optional<Metadata *> Mapper::mapSimpleMetadata(
const Metadata *MD) {
885 if (std::optional<Metadata *> NewMD = getVM().getMappedMD(MD))
907 if (IdentityMD && (*IdentityMD)(MD))
916 assert(MD &&
"Expected valid metadata");
919 if (std::optional<Metadata *> NewMD = mapSimpleMetadata(MD))
925void Mapper::flush() {
927 while (!Worklist.
empty()) {
929 CurrentMCID =
E.MCID;
931 case WorklistEntry::MapGlobalInit:
932 E.Data.GVInit.GV->setInitializer(mapConstant(
E.Data.GVInit.Init));
933 remapGlobalObjectMetadata(*
E.Data.GVInit.GV);
935 case WorklistEntry::MapAppendingVar: {
936 unsigned PrefixSize = AppendingInits.
size() -
E.AppendingGVNumNewMembers;
942 AppendingInits.
resize(PrefixSize);
943 mapAppendingVariable(*
E.Data.AppendingGV.GV,
944 E.Data.AppendingGV.OldGV,
945 E.AppendingGVIsOldCtorDtor,
ArrayRef(NewInits));
948 case WorklistEntry::MapAliasOrIFunc: {
959 case WorklistEntry::RemapFunction:
960 remapFunction(*
E.Data.RemapF);
968 while (!DelayedBBs.
empty()) {
971 DBB.TempBB->replaceAllUsesWith(BB ? BB : DBB.OldBB);
977 for (
Use &
Op :
I->operands()) {
984 "Referenced value not in value map!");
990 if (CB->getMetadata(LLVMContext::MD_callee_type) && !CB->isIndirectCall())
991 CB->setMetadata(LLVMContext::MD_callee_type,
nullptr);
996 CB->getMetadata(LLVMContext::MD_inline_history))
997 CB->setMetadata(LLVMContext::MD_inline_history,
nullptr);
1002 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
1003 Value *
V = mapValue(PN->getIncomingBlock(i));
1009 "Referenced block not in value map!");
1015 I->getAllMetadata(MDs);
1016 for (
const auto &
MI : MDs) {
1020 I->setMetadata(
MI.first, New);
1034 Tys.
reserve(FTy->getNumParams());
1035 for (
Type *Ty : FTy->params())
1038 TypeMapper->
remapType(
I->getType()), Tys, FTy->isVarArg()));
1041 AttributeList
Attrs = CB->getAttributes();
1042 for (
unsigned i = 0; i <
Attrs.getNumAttrSets(); ++i) {
1043 for (
unsigned AttrIdx = Attribute::FirstTypeAttr;
1044 AttrIdx <= Attribute::LastTypeAttr; AttrIdx++) {
1047 Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) {
1048 Attrs =
Attrs.replaceAttributeTypeAtIndex(
C, i, TypedAttr,
1054 CB->setAttributes(Attrs);
1058 AI->setAllocatedType(TypeMapper->
remapType(AI->getAllocatedType()));
1060 GEP->setSourceElementType(
1062 GEP->setResultElementType(
1065 I->mutateType(TypeMapper->
remapType(
I->getType()));
1068void Mapper::remapGlobalObjectMetadata(
GlobalObject &GO) {
1072 for (
const auto &
I : MDs)
1076void Mapper::remapFunction(
Function &
F) {
1078 for (
Use &
Op :
F.operands())
1083 remapGlobalObjectMetadata(
F);
1093 remapInstruction(&
I);
1108 unsigned NumElements =
1110 for (
unsigned I = 0;
I != NumElements; ++
I)
1119 if (IsOldCtorDtor) {
1124 Type *Tys[3] = {
ST.getElementType(0),
ST.getElementType(1), VoidPtrTy};
1128 for (
auto *
V : NewMembers) {
1130 if (IsOldCtorDtor) {
1148 assert(AlreadyScheduled.
insert(&GV).second &&
"Should not reschedule");
1152 WE.Kind = WorklistEntry::MapGlobalInit;
1154 WE.Data.GVInit.GV = &GV;
1155 WE.Data.GVInit.Init = &
Init;
1164 assert(AlreadyScheduled.
insert(&GV).second &&
"Should not reschedule");
1168 WE.Kind = WorklistEntry::MapAppendingVar;
1170 WE.Data.AppendingGV.GV = &GV;
1171 WE.Data.AppendingGV.OldGV = OldGV;
1172 WE.AppendingGVIsOldCtorDtor = IsOldCtorDtor;
1173 WE.AppendingGVNumNewMembers = NewMembers.
size();
1180 assert(AlreadyScheduled.
insert(&GV).second &&
"Should not reschedule");
1182 "Should be alias or ifunc");
1186 WE.Kind = WorklistEntry::MapAliasOrIFunc;
1188 WE.Data.AliasOrIFunc.GV = &GV;
1189 WE.Data.AliasOrIFunc.Target = &
Target;
1193void Mapper::scheduleRemapFunction(
Function &
F,
unsigned MCID) {
1194 assert(AlreadyScheduled.
insert(&
F).second &&
"Should not reschedule");
1198 WE.Kind = WorklistEntry::RemapFunction;
1200 WE.Data.RemapF = &
F;
1205 assert(!hasWorkToDo() &&
"Expected to have flushed the worklist");
1210 return reinterpret_cast<Mapper *
>(pImpl);
1215class FlushingMapper {
1219 explicit FlushingMapper(
void *pImpl) :
M(*
getAsMapper(pImpl)) {
1220 assert(!
M.hasWorkToDo() &&
"Expected to be flushed");
1223 ~FlushingMapper() {
M.flush(); }
1225 Mapper *operator->()
const {
return &
M; }
1234 : pImpl(new Mapper(VM, Flags, TypeMapper, Materializer, IdentityMD)) {}
1241 return getAsMapper(pImpl)->registerAlternateMappingContext(VM, Materializer);
1245 FlushingMapper(pImpl)->addFlags(Flags);
1249 return FlushingMapper(pImpl)->mapValue(&V);
1257 return FlushingMapper(pImpl)->mapMetadata(&MD);
1265 FlushingMapper(pImpl)->remapInstruction(&
I);
1269 FlushingMapper(pImpl)->remapDbgRecord(DR);
1280 FlushingMapper(pImpl)->remapFunction(
F);
1284 FlushingMapper(pImpl)->remapGlobalObjectMetadata(GO);
1299 GV, OldGV, IsOldCtorDtor, NewMembers,
MCID);
1321 auto AtomGroup =
DL->getAtomGroup();
1325 auto R = VM.
AtomMap.find({
DL->getInlinedAt(), AtomGroup});
1328 AtomGroup = R->second;
1332 I->getContext(),
DL.getLine(),
DL.getCol(),
DL.getScope(),
1333 DL.getInlinedAt(),
DL.isImplicitCode(), AtomGroup,
DL->getAtomRank());
1334 I->setDebugLoc(New);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static unsigned getMappedOp(unsigned PseudoOp)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
static APFloat flush(APFloat Value, DenormalMode::DenormalModeKind Mode)
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file defines the SmallVector class.
static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry, DenseMap< VPValue *, VPValue * > &Old2NewVPValues)
static Mapper * getAsMapper(void *pImpl)
static ConstantAsMetadata * wrapConstantAsMetadata(const ConstantAsMetadata &CMD, Value *MappedV)
This class represents an incoming formal argument to a Function.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & front() const
Get the first element.
size_t size() const
Get the array size.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
LLVM Basic Block Representation.
The address of a basic block.
Function * getFunction() const
BasicBlock * getBasicBlock() const
static LLVM_ABI BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
static LLVM_ABI ConstantAggregateZero * get(Type *Ty)
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
A constant value that is initialized with an expression using other constant values.
static LLVM_ABI Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static LLVM_ABI ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc, Constant *DeactivationSymbol)
Return a pointer signed with the specified parameters.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
LLVM_ABI void destroyConstant()
Called if some element of this constant is no longer valid.
static LLVM_ABI DIArgList * get(LLVMContext &Context, ArrayRef< ValueAsMetadata * > Args)
static LLVM_ABI DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
Records a position in IR for a source label (DILabel).
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
void setDebugLoc(DebugLoc Loc)
Record of a variable value-assignment, aka a non instruction representation of the dbg....
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
LLVM_ABI void clearMetadata()
Erase all metadata attached to this Value.
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ABI void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
static LLVM_ABI InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT, bool canThrow=false)
InlineAsm::get - Return the specified uniqued inline asm string.
This is an important class for using LLVM in a threaded context.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithDistinct(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a distinct one.
const MDOperand * op_iterator
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithUniqued(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a uniqued one.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
Class to represent pointers.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Target - Wrapper for Target specific information.
Tracking metadata reference.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
This is a class that can be implemented by clients to remap types when cloning constants and instruct...
virtual Type * remapType(Type *SrcTy)=0
The client should implement this method if they want to remap types while mapping values.
ValueMapIteratorImpl< MapT, const Value *, false > iterator
DMAtomT AtomMap
Map {(InlinedAt, old atom number) -> new atom number}.
LLVM_ABI void remapDbgRecord(Module *M, DbgRecord &V)
LLVM_ABI void remapDbgRecordRange(Module *M, iterator_range< DbgRecordIterator > Range)
LLVM_ABI MDNode * mapMDNode(const MDNode &N)
LLVM_ABI Metadata * mapMetadata(const Metadata &MD)
LLVM_ABI void remapInstruction(Instruction &I)
LLVM_ABI void scheduleMapGlobalInitializer(GlobalVariable &GV, Constant &Init, unsigned MappingContextID=0)
LLVM_ABI void scheduleRemapFunction(Function &F, unsigned MappingContextID=0)
LLVM_ABI ValueMapper(ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataPredicate *IdentityMD=nullptr)
LLVM_ABI void scheduleMapGlobalIFunc(GlobalIFunc &GI, Constant &Resolver, unsigned MappingContextID=0)
LLVM_ABI unsigned registerAlternateMappingContext(ValueToValueMapTy &VM, ValueMaterializer *Materializer=nullptr)
Register an alternate mapping context.
LLVM_ABI void remapFunction(Function &F)
LLVM_ABI Constant * mapConstant(const Constant &C)
LLVM_ABI void scheduleMapGlobalAlias(GlobalAlias &GA, Constant &Aliasee, unsigned MappingContextID=0)
LLVM_ABI void remapGlobalObjectMetadata(GlobalObject &GO)
LLVM_ABI Value * mapValue(const Value &V)
LLVM_ABI void scheduleMapAppendingVariable(GlobalVariable &GV, GlobalVariable *OldGV, bool IsOldCtorDtor, ArrayRef< Constant * > NewMembers, unsigned MappingContextID=0)
LLVM_ABI void addFlags(RemapFlags Flags)
Add to the current RemapFlags.
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.
LLVMContext & getContext() const
All values hold a context through their type.
bool hasUseList() const
Check if this Value has a use-list.
std::pair< iterator, bool > insert(const ValueT &V)
A range adaptor for a pair of iterators.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
@ BasicBlock
Various leaf nodes.
@ CE
Windows NT (Windows on ARM)
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
std::function< bool(const Metadata *)> MetadataPredicate
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto cast_or_null(const Y &Val)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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_NullMapMissingGlobalValues
Any global values not in value map are mapped to null instead of mapping to self.
@ RF_NoModuleLevelChanges
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
@ RF_DoNotRemapAtoms
Do not remap source location atoms.
@ RF_Importing
Indicate that we are importing functions, specifically in the context of ThinLTO.
@ RF_ReuseAndMutateDistinctMDs
Instruct the remapper to reuse and mutate distinct metadata (remapping them in place) instead of clon...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void RemapFunction(Function &F, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataPredicate *IdentityMD=nullptr)
Remap the operands, metadata, arguments, and instructions of a function.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI void RemapSourceAtom(Instruction *I, ValueToValueMapTy &VM)
Remap source location atom.