47#define DEBUG_TYPE "value-mapper"
50void ValueMapTypeRemapper::anchor() {}
51void ValueMaterializer::anchor() {}
57struct DelayedBasicBlock {
59 std::unique_ptr<BasicBlock> TempBB;
62 : OldBB(Old.getBasicBlock()),
63 TempBB(
BasicBlock::Create(Old.getContext())) {}
77 struct AppendingGVTy {
81 struct AliasOrIFuncTy {
88 unsigned AppendingGVIsOldCtorDtor : 1;
89 unsigned AppendingGVNumNewMembers;
92 AppendingGVTy AppendingGV;
93 AliasOrIFuncTy AliasOrIFunc;
98struct MappingContext {
105 : VM(&VM), Materializer(Materializer) {}
109 friend class MDNodeMapper;
117 unsigned CurrentMCID = 0;
127 MCs(1, MappingContext(VM, Materializer)) {}
130 ~Mapper() {
assert(!hasWorkToDo() &&
"Expected to be flushed"); }
132 bool hasWorkToDo()
const {
return !Worklist.
empty(); }
137 MCs.
push_back(MappingContext(VM, Materializer));
138 return MCs.
size() - 1;
150 return cast_or_null<Constant>(mapValue(
C));
167 void scheduleRemapFunction(
Function &
F,
unsigned MCID);
182 std::optional<Metadata *> mapSimpleMetadata(
const Metadata *MD);
193 bool HasChanged =
false;
194 unsigned ID = std::numeric_limits<unsigned>::max();
195 TempMDNode Placeholder;
199 struct UniquedGraph {
207 void propagateChanges();
221 MDNodeMapper(Mapper &M) :
M(
M) {}
274 std::optional<Metadata *> tryToMapOperand(
const Metadata *Op);
302 bool createPOT(UniquedGraph &
G,
const MDNode &FirstN);
323 void mapNodesInPOT(UniquedGraph &
G);
331 template <
class OperandMapper>
332 void remapOperands(
MDNode &
N, OperandMapper mapOperand);
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))) {
356 if (isa<GlobalValue>(V)) {
359 return getVM()[
V] =
const_cast<Value *
>(
V);
362 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
366 NewTy = cast<FunctionType>(TypeMapper->
remapType(NewTy));
368 if (NewTy !=
IA->getFunctionType())
370 IA->hasSideEffects(),
IA->isAlignStack(),
371 IA->getDialect(),
IA->canThrow());
374 return getVM()[
V] =
const_cast<Value *
>(
V);
377 if (
const auto *MDV = dyn_cast<MetadataAsValue>(V)) {
378 const Metadata *MD = MDV->getMetadata();
380 if (
auto *
LAM = dyn_cast<LocalAsMetadata>(MD)) {
382 if (
Value *LV = mapValue(
LAM->getValue())) {
383 if (V ==
LAM->getValue())
384 return const_cast<Value *
>(V);
396 if (
auto *AL = dyn_cast<DIArgList>(MD)) {
398 for (
auto *VAM :
AL->getArgs()) {
406 }
else if (
Value *LV = mapValue(VAM->getValue())) {
424 return getVM()[
V] =
const_cast<Value *
>(
V);
427 auto *MappedMD = mapMetadata(MD);
429 return getVM()[
V] =
const_cast<Value *
>(
V);
440 return mapBlockAddress(*BA);
442 if (
const auto *
E = dyn_cast<DSOLocalEquivalent>(
C)) {
443 auto *Val = mapValue(
E->getGlobalValue());
448 auto *
Func = cast<Function>(Val->stripPointerCastsAndAliases());
449 Type *NewTy =
E->getType();
456 if (
const auto *
NC = dyn_cast<NoCFIValue>(
C)) {
457 auto *Val = mapValue(
NC->getGlobalValue());
462 auto mapValueOrNull = [
this](
Value *
V) {
463 auto Mapped = mapValue(V);
465 "Unexpected null mapping for constant operand without "
466 "NullMapMissingGlobalValues flag");
472 unsigned OpNo = 0, NumOperands =
C->getNumOperands();
473 Value *Mapped =
nullptr;
474 for (; OpNo != NumOperands; ++OpNo) {
476 Mapped = mapValueOrNull(Op);
484 Type *NewTy =
C->getType();
490 if (OpNo == NumOperands && NewTy ==
C->getType())
491 return getVM()[
V] =
C;
497 for (
unsigned j = 0;
j != OpNo; ++
j)
498 Ops.
push_back(cast<Constant>(
C->getOperand(j)));
501 if (OpNo != NumOperands) {
505 for (++OpNo; OpNo != NumOperands; ++OpNo) {
506 Mapped = mapValueOrNull(
C->getOperand(OpNo));
512 Type *NewSrcTy =
nullptr;
514 if (
auto *GEPO = dyn_cast<GEPOperator>(
C))
515 NewSrcTy = TypeMapper->
remapType(GEPO->getSourceElementType());
518 return getVM()[
V] =
CE->getWithOperands(Ops, NewTy,
false, NewSrcTy);
519 if (isa<ConstantArray>(
C))
521 if (isa<ConstantStruct>(
C))
523 if (isa<ConstantVector>(
C))
526 if (isa<PoisonValue>(
C))
528 if (isa<UndefValue>(
C))
530 if (isa<ConstantAggregateZero>(
C))
532 assert(isa<ConstantPointerNull>(
C));
544 DelayedBBs.
push_back(DelayedBasicBlock(BA));
545 BB = DelayedBBs.
back().TempBB.get();
554 getVM().MD()[
Key].reset(Val);
559 return mapToMetadata(MD,
const_cast<Metadata *
>(MD));
562std::optional<Metadata *> MDNodeMapper::tryToMapOperand(
const Metadata *Op) {
566 if (std::optional<Metadata *> MappedOp =
M.mapSimpleMetadata(Op)) {
568 if (
auto *CMD = dyn_cast<ConstantAsMetadata>(Op))
569 assert((!*MappedOp ||
M.getVM().count(CMD->getValue()) ||
570 M.getVM().getMappedMD(Op)) &&
571 "Expected Value to be memoized");
573 assert((isa<MDString>(Op) ||
M.getVM().getMappedMD(Op)) &&
574 "Expected result to be memoized");
579 const MDNode &
N = *cast<MDNode>(Op);
581 return mapDistinctNode(
N);
586 assert(
N.isDistinct() &&
"Expected a distinct node");
587 assert(!
M.getVM().getMappedMD(&
N) &&
"Expected an unmapped node");
591 NewM =
M.mapToSelf(&
N);
595 <<
"To " << *NewM <<
"\n\n");
596 M.mapToMetadata(&
N, NewM);
598 DistinctWorklist.push_back(cast<MDNode>(NewM));
600 return DistinctWorklist.back();
610std::optional<Metadata *> MDNodeMapper::getMappedOp(
const Metadata *Op)
const {
614 if (std::optional<Metadata *> MappedOp =
M.getVM().getMappedMD(Op))
617 if (isa<MDString>(Op))
620 if (
auto *CMD = dyn_cast<ConstantAsMetadata>(Op))
626Metadata &MDNodeMapper::UniquedGraph::getFwdReference(
MDNode &Op) {
627 auto Where =
Info.find(&Op);
628 assert(Where !=
Info.end() &&
"Expected a valid reference");
630 auto &OpD = Where->second;
635 if (!OpD.Placeholder)
636 OpD.Placeholder =
Op.clone();
638 return *OpD.Placeholder;
641template <
class OperandMapper>
642void MDNodeMapper::remapOperands(
MDNode &
N, OperandMapper mapOperand) {
643 assert(!
N.isUniqued() &&
"Expected distinct or temporary nodes");
644 for (
unsigned I = 0,
E =
N.getNumOperands();
I !=
E; ++
I) {
648 LLVM_DEBUG(
dbgs() <<
"Replacing Op " << Old <<
" with " << New <<
" in "
652 N.replaceOperandWith(
I, New);
659struct POTWorklistEntry {
665 bool HasChanged =
false;
667 POTWorklistEntry(
MDNode &
N) :
N(&
N),
Op(
N.op_begin()) {}
672bool MDNodeMapper::createPOT(UniquedGraph &
G,
const MDNode &FirstN) {
673 assert(
G.Info.empty() &&
"Expected a fresh traversal");
677 bool AnyChanges =
false;
680 (void)
G.Info[&FirstN];
681 while (!Worklist.
empty()) {
683 auto &WE = Worklist.
back();
684 if (
MDNode *
N = visitOperands(
G, WE.Op, WE.N->op_end(), WE.HasChanged)) {
691 assert(WE.N->isUniqued() &&
"Expected only uniqued nodes");
692 assert(WE.Op == WE.N->op_end() &&
"Expected to visit all operands");
693 auto &
D =
G.Info[WE.N];
694 AnyChanges |=
D.HasChanged = WE.HasChanged;
696 G.POT.push_back(WE.N);
708 if (std::optional<Metadata *> MappedOp = tryToMapOperand(Op)) {
710 HasChanged |=
Op != *MappedOp;
715 MDNode &OpN = *cast<MDNode>(Op);
717 "Only uniqued operands cannot be mapped immediately");
718 if (
G.Info.insert(std::make_pair(&OpN,
Data())).second)
724void MDNodeMapper::UniquedGraph::propagateChanges() {
734 auto Where = Info.find(Op);
735 return Where != Info.end() && Where->second.HasChanged;
739 AnyChanges =
D.HasChanged =
true;
741 }
while (AnyChanges);
744void MDNodeMapper::mapNodesInPOT(UniquedGraph &
G) {
747 for (
auto *
N :
G.POT) {
756 bool HadPlaceholder(
D.Placeholder);
759 TempMDNode ClonedN =
D.Placeholder ? std::move(
D.Placeholder) :
N->clone();
760 remapOperands(*ClonedN, [
this, &
D, &
G](
Metadata *Old) {
761 if (std::optional<Metadata *> MappedOp =
getMappedOp(Old))
764 assert(
G.Info[Old].ID >
D.ID &&
"Expected a forward reference");
765 return &
G.getFwdReference(*cast<MDNode>(Old));
769 if (
N && NewN &&
N != NewN) {
771 <<
"To " << *NewN <<
"\n\n");
774 M.mapToMetadata(
N, NewN);
783 for (
auto *
N : CyclicNodes)
784 if (!
N->isResolved())
789 assert(DistinctWorklist.empty() &&
"MDNodeMapper::map is not recursive");
791 "MDNodeMapper::map assumes module-level changes");
794 assert(
N.isResolved() &&
"Unexpected unresolved node");
797 N.isUniqued() ? mapTopLevelUniquedNode(
N) : mapDistinctNode(
N);
798 while (!DistinctWorklist.empty())
799 remapOperands(*DistinctWorklist.pop_back_val(), [
this](
Metadata *Old) {
800 if (std::optional<Metadata *> MappedOp = tryToMapOperand(Old))
802 return mapTopLevelUniquedNode(*cast<MDNode>(Old));
807Metadata *MDNodeMapper::mapTopLevelUniquedNode(
const MDNode &FirstN) {
812 if (!createPOT(
G, FirstN)) {
816 return &
const_cast<MDNode &
>(FirstN);
820 G.propagateChanges();
829std::optional<Metadata *> Mapper::mapSimpleMetadata(
const Metadata *MD) {
831 if (std::optional<Metadata *> NewMD = getVM().getMappedMD(MD))
834 if (isa<MDString>(MD))
842 if (
auto *CMD = dyn_cast<ConstantAsMetadata>(MD)) {
850 assert(isa<MDNode>(MD) &&
"Expected a metadata node");
856 assert(MD &&
"Expected valid metadata");
857 assert(!isa<LocalAsMetadata>(MD) &&
"Unexpected local metadata");
859 if (std::optional<Metadata *> NewMD = mapSimpleMetadata(MD))
862 return MDNodeMapper(*this).map(*cast<MDNode>(MD));
865void Mapper::flush() {
867 while (!Worklist.
empty()) {
869 CurrentMCID =
E.MCID;
871 case WorklistEntry::MapGlobalInit:
872 E.Data.GVInit.GV->setInitializer(mapConstant(
E.Data.GVInit.Init));
873 remapGlobalObjectMetadata(*
E.Data.GVInit.GV);
875 case WorklistEntry::MapAppendingVar: {
876 unsigned PrefixSize = AppendingInits.
size() -
E.AppendingGVNumNewMembers;
882 AppendingInits.
resize(PrefixSize);
883 mapAppendingVariable(*
E.Data.AppendingGV.GV,
884 E.Data.AppendingGV.InitPrefix,
885 E.AppendingGVIsOldCtorDtor,
ArrayRef(NewInits));
888 case WorklistEntry::MapAliasOrIFunc: {
891 if (
auto *GA = dyn_cast<GlobalAlias>(GV))
893 else if (
auto *GI = dyn_cast<GlobalIFunc>(GV))
899 case WorklistEntry::RemapFunction:
900 remapFunction(*
E.Data.RemapF);
908 while (!DelayedBBs.
empty()) {
910 BasicBlock *BB = cast_or_null<BasicBlock>(mapValue(DBB.OldBB));
911 DBB.TempBB->replaceAllUsesWith(BB ? BB : DBB.OldBB);
917 for (
Use &Op :
I->operands()) {
924 "Referenced value not in value map!");
928 if (
PHINode *PN = dyn_cast<PHINode>(
I)) {
929 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
930 Value *
V = mapValue(PN->getIncomingBlock(i));
933 PN->setIncomingBlock(i, cast<BasicBlock>(V));
936 "Referenced block not in value map!");
942 I->getAllMetadata(MDs);
943 for (
const auto &
MI : MDs) {
945 MDNode *
New = cast_or_null<MDNode>(mapMetadata(Old));
947 I->setMetadata(
MI.first, New);
954 if (
auto *CB = dyn_cast<CallBase>(
I)) {
957 Tys.
reserve(FTy->getNumParams());
958 for (
Type *Ty : FTy->params())
961 TypeMapper->
remapType(
I->getType()), Tys, FTy->isVarArg()));
965 for (
unsigned i = 0; i <
Attrs.getNumAttrSets(); ++i) {
966 for (
int AttrIdx = Attribute::FirstTypeAttr;
967 AttrIdx <= Attribute::LastTypeAttr; AttrIdx++) {
970 Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) {
971 Attrs =
Attrs.replaceAttributeTypeAtIndex(
C, i, TypedAttr,
977 CB->setAttributes(Attrs);
980 if (
auto *AI = dyn_cast<AllocaInst>(
I))
981 AI->setAllocatedType(TypeMapper->
remapType(AI->getAllocatedType()));
982 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(
I)) {
983 GEP->setSourceElementType(
985 GEP->setResultElementType(
988 I->mutateType(TypeMapper->
remapType(
I->getType()));
991void Mapper::remapGlobalObjectMetadata(
GlobalObject &GO) {
995 for (
const auto &
I : MDs)
996 GO.
addMetadata(
I.first, *cast<MDNode>(mapMetadata(
I.second)));
1001 for (
Use &Op :
F.operands())
1006 remapGlobalObjectMetadata(
F);
1016 remapInstruction(&
I);
1024 unsigned NumElements =
1025 cast<ArrayType>(InitPrefix->
getType())->getNumElements();
1026 for (
unsigned I = 0;
I != NumElements; ++
I)
1032 if (IsOldCtorDtor) {
1036 auto &
ST = *cast<StructType>(NewMembers.
front()->getType());
1037 Type *Tys[3] = {
ST.getElementType(0),
ST.getElementType(1), VoidPtrTy};
1041 for (
auto *V : NewMembers) {
1043 if (IsOldCtorDtor) {
1044 auto *S = cast<ConstantStruct>(V);
1045 auto *E1 = cast<Constant>(mapValue(S->getOperand(0)));
1046 auto *E2 = cast<Constant>(mapValue(S->getOperand(1)));
1050 NewV = cast_or_null<Constant>(mapValue(V));
1061 assert(AlreadyScheduled.
insert(&GV).second &&
"Should not reschedule");
1062 assert(MCID < MCs.
size() &&
"Invalid mapping context");
1065 WE.Kind = WorklistEntry::MapGlobalInit;
1067 WE.Data.GVInit.GV = &GV;
1068 WE.Data.GVInit.Init = &
Init;
1077 assert(AlreadyScheduled.
insert(&GV).second &&
"Should not reschedule");
1078 assert(MCID < MCs.
size() &&
"Invalid mapping context");
1081 WE.Kind = WorklistEntry::MapAppendingVar;
1083 WE.Data.AppendingGV.GV = &GV;
1084 WE.Data.AppendingGV.InitPrefix = InitPrefix;
1085 WE.AppendingGVIsOldCtorDtor = IsOldCtorDtor;
1086 WE.AppendingGVNumNewMembers = NewMembers.
size();
1093 assert(AlreadyScheduled.
insert(&GV).second &&
"Should not reschedule");
1094 assert((isa<GlobalAlias>(GV) || isa<GlobalIFunc>(GV)) &&
1095 "Should be alias or ifunc");
1096 assert(MCID < MCs.
size() &&
"Invalid mapping context");
1099 WE.Kind = WorklistEntry::MapAliasOrIFunc;
1101 WE.Data.AliasOrIFunc.GV = &GV;
1102 WE.Data.AliasOrIFunc.Target = &
Target;
1106void Mapper::scheduleRemapFunction(
Function &
F,
unsigned MCID) {
1107 assert(AlreadyScheduled.
insert(&
F).second &&
"Should not reschedule");
1108 assert(MCID < MCs.
size() &&
"Invalid mapping context");
1111 WE.Kind = WorklistEntry::RemapFunction;
1113 WE.Data.RemapF = &
F;
1118 assert(!hasWorkToDo() &&
"Expected to have flushed the worklist");
1119 this->Flags = this->Flags |
Flags;
1123 return reinterpret_cast<Mapper *
>(pImpl);
1128class FlushingMapper {
1132 explicit FlushingMapper(
void *pImpl) :
M(*
getAsMapper(pImpl)) {
1133 assert(!
M.hasWorkToDo() &&
"Expected to be flushed");
1136 ~FlushingMapper() {
M.flush(); }
1138 Mapper *operator->()
const {
return &
M; }
1146 : pImpl(new Mapper(VM,
Flags, TypeMapper, Materializer)) {}
1153 return getAsMapper(pImpl)->registerAlternateMappingContext(VM, Materializer);
1157 FlushingMapper(pImpl)->addFlags(
Flags);
1161 return FlushingMapper(pImpl)->mapValue(&V);
1165 return cast_or_null<Constant>(
mapValue(
C));
1169 return FlushingMapper(pImpl)->mapMetadata(&MD);
1177 FlushingMapper(pImpl)->remapInstruction(&
I);
1181 FlushingMapper(pImpl)->remapFunction(
F);
1185 FlushingMapper(pImpl)->remapGlobalObjectMetadata(GO);
1200 GV, InitPrefix, IsOldCtorDtor, NewMembers, MCID);
1205 getAsMapper(pImpl)->scheduleMapAliasOrIFunc(GA, Aliasee, MCID);
static unsigned getMappedOp(unsigned PseudoOp)
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")
Analysis containing CSE Info
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.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static Mapper * getAsMapper(void *pImpl)
static ConstantAsMetadata * wrapConstantAsMetadata(const ConstantAsMetadata &CMD, Value *MappedV)
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),...
const T & front() const
front - Get the first element.
size_t size() const
size - 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 BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
static ConstantAggregateZero * get(Type *Ty)
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
A constant value that is initialized with an expression using other constant values.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
Implements a dense probed hash-table based set.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
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.
void clearMetadata()
Erase all metadata attached to this Value.
Type * getValueType() const
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
static 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.
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.
Tracking metadata reference owned by Metadata.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
static 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 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.
The instances of the Type class are immutable: once they are created, they are never changed.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
static IntegerType * getInt8Ty(LLVMContext &C)
static 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.
MDNode * mapMDNode(const MDNode &N)
Metadata * mapMetadata(const Metadata &MD)
void remapInstruction(Instruction &I)
void scheduleMapGlobalInitializer(GlobalVariable &GV, Constant &Init, unsigned MappingContextID=0)
void scheduleRemapFunction(Function &F, unsigned MappingContextID=0)
void scheduleMapGlobalIFunc(GlobalIFunc &GI, Constant &Resolver, unsigned MappingContextID=0)
unsigned registerAlternateMappingContext(ValueToValueMapTy &VM, ValueMaterializer *Materializer=nullptr)
Register an alternate mapping context.
void remapFunction(Function &F)
Constant * mapConstant(const Constant &C)
ValueMapper(ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
void scheduleMapAppendingVariable(GlobalVariable &GV, Constant *InitPrefix, bool IsOldCtorDtor, ArrayRef< Constant * > NewMembers, unsigned MappingContextID=0)
void scheduleMapGlobalAlias(GlobalAlias &GA, Constant &Aliasee, unsigned MappingContextID=0)
void remapGlobalObjectMetadata(GlobalObject &GO)
Value * mapValue(const Value &V)
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.
std::pair< iterator, bool > insert(const ValueT &V)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
@ C
The default llvm calling convention, compatible with C.
@ CE
Windows NT (Windows on ARM)
const_iterator end(StringRef path)
Get end iterator over path.
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.
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_ReuseAndMutateDistinctMDs
Instruct the remapper to reuse and mutate distinct metadata (remapping them in place) instead of clon...
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.
void RemapFunction(Function &F, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Remap the operands, metadata, arguments, and instructions of a function.