63 : DstStructTypesSet(DstStructTypesSet) {}
68 void addTypeMapping(
Type *DstTy,
Type *SrcTy);
72 void linkDefinedTypeBodies();
82 return cast<FunctionType>(
get((
Type *)
T));
88 bool areTypesIsomorphic(
Type *DstTy,
Type *SrcTy);
92void TypeMapTy::addTypeMapping(
Type *DstTy,
Type *SrcTy) {
98 if (!areTypesIsomorphic(DstTy, SrcTy)) {
101 for (
Type *Ty : SpeculativeTypes)
102 MappedTypes.
erase(Ty);
104 SrcDefinitionsToResolve.
resize(SrcDefinitionsToResolve.
size() -
105 SpeculativeDstOpaqueTypes.
size());
106 for (
StructType *Ty : SpeculativeDstOpaqueTypes)
107 DstResolvedOpaqueTypes.
erase(Ty);
115 for (
Type *Ty : SpeculativeTypes)
116 if (
auto *STy = dyn_cast<StructType>(Ty))
120 SpeculativeTypes.clear();
121 SpeculativeDstOpaqueTypes.clear();
126bool TypeMapTy::areTypesIsomorphic(
Type *DstTy,
Type *SrcTy) {
134 return Entry == DstTy;
138 if (DstTy == SrcTy) {
146 if (
StructType *SSTy = dyn_cast<StructType>(SrcTy)) {
148 if (SSTy->isOpaque()) {
150 SpeculativeTypes.push_back(SrcTy);
158 if (cast<StructType>(DstTy)->isOpaque()) {
160 if (!DstResolvedOpaqueTypes.
insert(cast<StructType>(DstTy)).second)
163 SpeculativeTypes.push_back(SrcTy);
164 SpeculativeDstOpaqueTypes.push_back(cast<StructType>(DstTy));
175 if (isa<IntegerType>(DstTy))
177 if (
PointerType *PT = dyn_cast<PointerType>(DstTy)) {
178 if (PT->getAddressSpace() != cast<PointerType>(SrcTy)->getAddressSpace())
180 }
else if (
FunctionType *FT = dyn_cast<FunctionType>(DstTy)) {
181 if (FT->isVarArg() != cast<FunctionType>(SrcTy)->isVarArg())
183 }
else if (
StructType *DSTy = dyn_cast<StructType>(DstTy)) {
185 if (DSTy->isLiteral() != SSTy->
isLiteral() ||
186 DSTy->isPacked() != SSTy->
isPacked())
188 }
else if (
auto *DArrTy = dyn_cast<ArrayType>(DstTy)) {
189 if (DArrTy->getNumElements() != cast<ArrayType>(SrcTy)->getNumElements())
191 }
else if (
auto *DVecTy = dyn_cast<VectorType>(DstTy)) {
192 if (DVecTy->getElementCount() != cast<VectorType>(SrcTy)->getElementCount())
199 SpeculativeTypes.push_back(SrcTy);
210void TypeMapTy::linkDefinedTypeBodies() {
212 for (
StructType *SrcSTy : SrcDefinitionsToResolve) {
213 StructType *DstSTy = cast<StructType>(MappedTypes[SrcSTy]);
217 Elements.resize(SrcSTy->getNumElements());
218 for (
unsigned I = 0, E =
Elements.size();
I != E; ++
I)
221 DstSTy->
setBody(Elements, SrcSTy->isPacked());
224 SrcDefinitionsToResolve.clear();
225 DstResolvedOpaqueTypes.
clear();
244 return get(Ty, Visited);
254 bool IsUniqued = !isa<StructType>(Ty) || cast<StructType>(Ty)->isLiteral();
258 for (
auto &Pair : MappedTypes) {
259 assert(!(Pair.first != Ty && Pair.second == Ty) &&
260 "mapping to a source type");
264 if (!Visited.
insert(cast<StructType>(Ty)).second) {
280 bool AnyChange =
false;
288 Entry = &MappedTypes[Ty];
290 if (
auto *DTy = dyn_cast<StructType>(*Entry)) {
292 auto *STy = cast<StructType>(Ty);
293 finishType(DTy, STy, ElementTypes);
301 if (!AnyChange && IsUniqued)
309 return *
Entry = ArrayType::get(ElementTypes[0],
313 return *
Entry = VectorType::get(ElementTypes[0],
314 cast<VectorType>(Ty)->getElementCount());
316 return *
Entry = PointerType::get(ElementTypes[0],
319 return *
Entry = FunctionType::get(ElementTypes[0],
321 cast<FunctionType>(Ty)->isVarArg());
323 auto *STy = cast<StructType>(Ty);
337 return *
Entry = OldT;
346 finishType(DTy, STy, ElementTypes);
368 IRLinker &TheIRLinker;
371 GlobalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
376 IRLinker &TheIRLinker;
379 LocalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
390 std::unique_ptr<Module> SrcM;
396 GlobalValueMaterializer GValMaterializer;
397 LocalValueMaterializer LValMaterializer;
410 std::vector<GlobalValue *> Worklist;
411 std::vector<std::pair<GlobalValue *, Value*>> RAUWWorklist;
418 if (ValuesToLink.
insert(GV).second)
419 Worklist.push_back(GV);
427 bool IsPerformingImport;
432 bool DoneLinkingBodies =
false;
436 std::optional<Error> FoundError;
439 FoundError = std::move(
E);
450 unsigned IndirectSymbolMCID;
456 void emitWarning(
const Twine &Message) {
480 if (
auto *FDGV = dyn_cast<Function>(DGV))
481 if (FDGV->isIntrinsic())
482 if (
const auto *FSrcGV = dyn_cast<Function>(SrcGV))
483 if (FDGV->getFunctionType() != TypeMap.get(FSrcGV->getFunctionType()))
490 void computeTypeMapping();
502 bool ForIndirectSymbol);
504 Error linkModuleFlagsMetadata();
528 void flushRAUWWorklist();
533 void prepareCompileUnitsForImport();
534 void linkNamedMDNodes();
540 IRLinker(
Module &DstM, MDMapT &SharedMDs,
544 : DstM(DstM), SrcM(
std::
move(SrcM)), AddLazyFor(
std::
move(AddLazyFor)),
545 TypeMap(
Set), GValMaterializer(*this), LValMaterializer(*this),
546 SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
548 &TypeMap, &GValMaterializer),
549 IndirectSymbolMCID(Mapper.registerAlternateMappingContext(
550 IndirectSymbolValueMap, &LValMaterializer)) {
554 if (IsPerformingImport)
555 prepareCompileUnitsForImport();
560 Value *materialize(
Value *V,
bool ForIndirectSymbol);
578 ConflictGV->setName(
Name);
579 assert(ConflictGV->getName() !=
Name &&
"forceRenaming didn't work");
585Value *GlobalValueMaterializer::materialize(
Value *SGV) {
586 return TheIRLinker.materialize(SGV,
false);
589Value *LocalValueMaterializer::materialize(
Value *SGV) {
590 return TheIRLinker.materialize(SGV,
true);
593Value *IRLinker::materialize(
Value *V,
bool ForIndirectSymbol) {
594 auto *SGV = dyn_cast<GlobalValue>(V);
602 if (SGV->getParent() != &DstM && SGV->getParent() != SrcM.get())
618 if (
auto *
F = dyn_cast<Function>(New)) {
619 if (!
F->isDeclaration())
621 }
else if (
auto *V = dyn_cast<GlobalVariable>(New)) {
622 if (
V->hasInitializer() ||
V->hasAppendingLinkage())
624 }
else if (
auto *GA = dyn_cast<GlobalAlias>(New)) {
625 if (GA->getAliasee())
627 }
else if (
auto *GI = dyn_cast<GlobalIFunc>(New)) {
628 if (GI->getResolver())
643 (!ForIndirectSymbol && IndirectSymbolValueMap.
lookup(SGV) == New))
646 if (ForIndirectSymbol || shouldLink(New, *SGV))
647 setError(linkGlobalValueBody(*New, *SGV));
649 updateAttributes(*New);
671 for (
unsigned i = 0; i <
Attrs.getNumAttrSets(); ++i) {
672 for (
int AttrIdx = Attribute::FirstTypeAttr;
673 AttrIdx <= Attribute::LastTypeAttr; AttrIdx++) {
675 if (
Attrs.hasAttributeAtIndex(i, TypedAttr)) {
677 Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) {
678 Attrs =
Attrs.replaceAttributeTypeAtIndex(
C, i, TypedAttr,
696 F->copyAttributesFrom(SF);
697 F->setAttributes(mapAttributeTypes(
F->getContext(),
F->getAttributes()));
709 if (
auto *GA = dyn_cast<GlobalAlias>(SGV)) {
713 DGA->copyAttributesFrom(GA);
717 if (
auto *GI = dyn_cast<GlobalIFunc>(SGV)) {
720 SGV->
getName(),
nullptr, &DstM);
721 DGI->copyAttributesFrom(GI);
729 bool ForDefinition) {
731 if (
auto *SGVar = dyn_cast<GlobalVariable>(SGV)) {
732 NewGV = copyGlobalVariableProto(SGVar);
733 }
else if (
auto *SF = dyn_cast<Function>(SGV)) {
734 NewGV = copyFunctionProto(SF);
737 NewGV = copyIndirectSymbolProto(SGV);
757 if (
auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
760 NewGO->copyMetadata(cast<GlobalObject>(SGV), 0);
762 UnmappedMetadata.
insert(NewGO);
769 if (
auto *NewF = dyn_cast<Function>(NewGV)) {
770 NewF->setPersonalityFn(
nullptr);
771 NewF->setPrefixData(
nullptr);
772 NewF->setPrologueData(
nullptr);
779 size_t DotPos =
Name.rfind(
'.');
781 !isdigit(
static_cast<unsigned char>(
Name[DotPos + 1])))
783 :
Name.substr(0, DotPos);
790void IRLinker::computeTypeMapping() {
804 TypeMap.addTypeMapping(DAT->getElementType(), SAT->getElementType());
829 std::vector<StructType *>
Types = SrcM->getIdentifiedStructTypes();
834 if (TypeMap.DstStructTypesSet.hasType(ST)) {
843 if (STTypePrefix.size() ==
ST->getName().size())
868 if (TypeMap.DstStructTypesSet.hasType(DST))
869 TypeMap.addTypeMapping(DST, ST);
874 TypeMap.linkDefinedTypeBodies();
879 unsigned NumElements = cast<ArrayType>(
C->getType())->getNumElements();
881 for (
unsigned i = 0; i != NumElements; ++i)
893 "Linking globals named '" + SrcGV->
getName() +
894 "': can only link appending global with another appending "
898 return stringErr(
"Appending variables linked with different const'ness!");
902 "Appending variables with different alignment need to be linked!");
906 "Appending variables with different visibility need to be linked!");
910 "Appending variables with different unnamed_addr need to be linked!");
914 "Appending variables with different section name need to be linked!");
917 return stringErr(
"Appending variables with different address spaces need "
933 bool IsNewStructor =
false;
934 bool IsOldStructor =
false;
935 if (
Name ==
"llvm.global_ctors" ||
Name ==
"llvm.global_dtors") {
937 IsNewStructor =
true;
939 IsOldStructor =
true;
944 auto &
ST = *cast<StructType>(EltTy);
945 Type *Tys[3] = {
ST.getElementType(0),
ST.getElementType(1), VoidPtrTy};
952 DstNumElements = DstTy->getNumElements();
955 if (EltTy != DstTy->getElementType())
956 return stringErr(
"Appending variables with different element types!");
969 return !shouldLink(DGV, *Key);
989 IsOldStructor, SrcElements);
994 RAUWWorklist.push_back(std::make_pair(DstGV, NG));
1012 bool LazilyAdded =
false;
1014 AddLazyFor(SGV, [
this, &LazilyAdded](
GlobalValue &GV) {
1022 bool ForIndirectSymbol) {
1025 bool ShouldLink = shouldLink(DGV, *SGV);
1031 return cast<Constant>(
I->second);
1033 I = IndirectSymbolValueMap.
find(SGV);
1034 if (
I != IndirectSymbolValueMap.
end())
1035 return cast<Constant>(
I->second);
1038 if (!ShouldLink && ForIndirectSymbol)
1043 return linkAppendingVarProto(cast_or_null<GlobalVariable>(DGV),
1044 cast<GlobalVariable>(SGV));
1046 bool NeedsRenaming =
false;
1048 if (DGV && !ShouldLink) {
1054 if (DoneLinkingBodies)
1057 NewGV = copyGlobalValueProto(SGV, ShouldLink || ForIndirectSymbol);
1058 if (ShouldLink || !ForIndirectSymbol)
1059 NeedsRenaming =
true;
1065 if (
Function *
F = dyn_cast<Function>(NewGV))
1070 assert(!UnmappedMetadata.
count(
F) &&
"intrinsic has unmapped metadata");
1073 NeedsRenaming =
false;
1079 if (ShouldLink || ForIndirectSymbol) {
1081 if (
auto *GO = dyn_cast<GlobalObject>(NewGV)) {
1089 if (!ShouldLink && ForIndirectSymbol)
1098 if (DGV && NewGV != SGV) {
1100 NewGV, TypeMap.get(SGV->
getType()));
1103 if (DGV && NewGV != DGV) {
1107 RAUWWorklist.push_back(std::make_pair(
1126 assert(Dst.isDeclaration() && !Src.isDeclaration());
1129 if (
Error Err = Src.materialize())
1133 if (Src.hasPrefixData())
1134 Dst.setPrefixData(Src.getPrefixData());
1135 if (Src.hasPrologueData())
1136 Dst.setPrologueData(Src.getPrologueData());
1137 if (Src.hasPersonalityFn())
1138 Dst.setPersonalityFn(Src.getPersonalityFn());
1139 assert(Src.IsNewDbgInfoFormat == Dst.IsNewDbgInfoFormat);
1142 Dst.copyMetadata(&Src, 0);
1145 Dst.stealArgumentListFrom(Src);
1146 Dst.splice(Dst.end(), &Src);
1162 if (
auto *
F = dyn_cast<Function>(&Src))
1163 return linkFunctionBody(cast<Function>(Dst), *
F);
1164 if (
auto *GVar = dyn_cast<GlobalVariable>(&Src)) {
1165 linkGlobalVariable(cast<GlobalVariable>(Dst), *GVar);
1168 if (
auto *GA = dyn_cast<GlobalAlias>(&Src)) {
1169 linkAliasAliasee(cast<GlobalAlias>(Dst), *GA);
1172 linkIFuncResolver(cast<GlobalIFunc>(Dst), cast<GlobalIFunc>(Src));
1176void IRLinker::flushRAUWWorklist() {
1177 for (
const auto &Elem : RAUWWorklist) {
1180 std::tie(Old, New) = Elem;
1185 RAUWWorklist.clear();
1188void IRLinker::prepareCompileUnitsForImport() {
1189 NamedMDNode *SrcCompileUnits = SrcM->getNamedMetadata(
"llvm.dbg.cu");
1190 if (!SrcCompileUnits)
1196 auto *
CU = cast<DICompileUnit>(
N);
1197 assert(
CU &&
"Expected valid compile unit");
1201 CU->replaceEnumTypes(
nullptr);
1202 CU->replaceMacros(
nullptr);
1203 CU->replaceRetainedTypes(
nullptr);
1214 CU->replaceGlobalVariables(
nullptr);
1216 CU->replaceImportedEntities(
nullptr);
1221void IRLinker::linkNamedMDNodes() {
1222 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1223 for (
const NamedMDNode &NMD : SrcM->named_metadata()) {
1225 if (&NMD == SrcModFlags)
1231 emitWarning(
"Pseudo-probe ignored: source module '" +
1232 SrcM->getModuleIdentifier() +
1233 "' is compiled with -fpseudo-probe-for-profiling while "
1234 "destination module '" +
1240 if (IsPerformingImport && NMD.getName() ==
"llvm.stats")
1245 for (
const MDNode *
Op : NMD.operands())
1251Error IRLinker::linkModuleFlagsMetadata() {
1253 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1278 mdconst::extract<ConstantInt>(
Op->getOperand(0))->getZExtValue();
1282 Requirements.
insert(cast<MDNode>(
Op->getOperand(2)));
1295 mdconst::extract<ConstantInt>(
SrcOp->getOperand(0));
1300 unsigned SrcBehaviorValue = SrcBehavior->
getZExtValue();
1307 if (Requirements.
insert(cast<MDNode>(
SrcOp->getOperand(2)))) {
1326 mdconst::extract<ConstantInt>(
DstOp->getOperand(0));
1327 unsigned DstBehaviorValue = DstBehavior->
getZExtValue();
1329 auto overrideDstValue = [&]() {
1338 SrcOp->getOperand(2) !=
DstOp->getOperand(2))
1339 return stringErr(
"linking module flags '" +
ID->getString() +
1340 "': IDs have conflicting override values in '" +
1341 SrcM->getModuleIdentifier() +
"' and '" +
1351 if (SrcBehaviorValue != DstBehaviorValue) {
1352 bool MinAndWarn = (SrcBehaviorValue ==
Module::Min &&
1356 bool MaxAndWarn = (SrcBehaviorValue ==
Module::Max &&
1360 if (!(MaxAndWarn || MinAndWarn))
1361 return stringErr(
"linking module flags '" +
ID->getString() +
1362 "': IDs have conflicting behaviors in '" +
1363 SrcM->getModuleIdentifier() +
"' and '" +
1367 auto ensureDistinctOp = [&](
MDNode *DstValue) {
1368 assert(isa<MDTuple>(DstValue) &&
1369 "Expected MDTuple when appending module flags");
1370 if (DstValue->isDistinct())
1371 return dyn_cast<MDTuple>(DstValue);
1386 SrcOp->getOperand(2) !=
DstOp->getOperand(2)) {
1389 <<
"linking module flags '" <<
ID->getString()
1390 <<
"': IDs have conflicting values ('" << *
SrcOp->getOperand(2)
1391 <<
"' from " << SrcM->getModuleIdentifier() <<
" with '"
1400 mdconst::extract<ConstantInt>(
DstOp->getOperand(2));
1402 mdconst::extract<ConstantInt>(
SrcOp->getOperand(2));
1419 mdconst::extract<ConstantInt>(
DstOp->getOperand(2));
1421 mdconst::extract<ConstantInt>(
SrcOp->getOperand(2));
1436 switch (SrcBehaviorValue) {
1442 if (
SrcOp->getOperand(2) !=
DstOp->getOperand(2))
1443 return stringErr(
"linking module flags '" +
ID->getString() +
1444 "': IDs have conflicting values in '" +
1445 SrcM->getModuleIdentifier() +
"' and '" +
1456 MDTuple *DstValue = ensureDistinctOp(cast<MDNode>(
DstOp->getOperand(2)));
1457 MDNode *SrcValue = cast<MDNode>(
SrcOp->getOperand(2));
1458 for (
const auto &O : SrcValue->
operands())
1464 MDTuple *DstValue = ensureDistinctOp(cast<MDNode>(
DstOp->getOperand(2)));
1465 MDNode *SrcValue = cast<MDNode>(
SrcOp->getOperand(2));
1478 for (
auto Idx : Mins) {
1482 ConstantInt *
V = mdconst::extract<ConstantInt>(
Op->getOperand(2));
1484 Op->getOperand(0),
ID,
1491 for (
MDNode *Requirement : Requirements) {
1492 MDString *
Flag = cast<MDString>(Requirement->getOperand(0));
1493 Metadata *ReqValue = Requirement->getOperand(1);
1496 if (!
Op ||
Op->getOperand(2) != ReqValue)
1497 return stringErr(
"linking module flags '" +
Flag->getString() +
1498 "': does not have the required value");
1509 return ".text\n.balign 2\n.thumb\n" +
InlineAsm;
1511 return ".text\n.balign 4\n.arm\n" +
InlineAsm;
1530 if (
auto *
F = dyn_cast<Function>(&GV)) {
1531 if (!
F->isIntrinsic())
1532 F->removeFnAttr(llvm::Attribute::NoCallback);
1537 if (
CallBase *CI = dyn_cast<CallBase>(&
I))
1538 CI->removeFnAttr(Attribute::NoCallback);
1542Error IRLinker::run() {
1544 if (SrcM->getMaterializer())
1545 if (
Error Err = SrcM->getMaterializer()->materializeMetadata())
1557 if (DstM.
getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
1567 bool EnableDLWarning =
true;
1568 bool EnableTripleWarning =
true;
1569 if (SrcTriple.isNVPTX() && DstTriple.isNVPTX()) {
1570 std::string ModuleId = SrcM->getModuleIdentifier();
1572 bool SrcIsLibDevice =
1574 bool SrcHasLibDeviceDL =
1575 (SrcM->getDataLayoutStr().empty() ||
1576 SrcM->getDataLayoutStr() ==
"e-i64:64-v16:16-v32:32-n16:32:64");
1580 bool SrcHasLibDeviceTriple = (SrcTriple.getVendor() ==
Triple::NVIDIA &&
1581 SrcTriple.getOSName() ==
"gpulibs") ||
1582 (SrcTriple.getVendorName() ==
"unknown" &&
1583 SrcTriple.getOSName() ==
"unknown");
1584 EnableTripleWarning = !(SrcIsLibDevice && SrcHasLibDeviceTriple);
1585 EnableDLWarning = !(SrcIsLibDevice && SrcHasLibDeviceDL);
1588 if (EnableDLWarning && (SrcM->getDataLayout() != DstM.
getDataLayout())) {
1589 emitWarning(
"Linking two modules of different data layouts: '" +
1590 SrcM->getModuleIdentifier() +
"' is '" +
1591 SrcM->getDataLayoutStr() +
"' whereas '" +
1596 if (EnableTripleWarning && !SrcM->getTargetTriple().empty() &&
1597 !SrcTriple.isCompatibleWith(DstTriple))
1598 emitWarning(
"Linking two modules of different target triples: '" +
1599 SrcM->getModuleIdentifier() +
"' is '" +
1600 SrcM->getTargetTriple() +
"' whereas '" +
1607 computeTypeMapping();
1609 std::reverse(Worklist.begin(), Worklist.end());
1610 while (!Worklist.empty()) {
1612 Worklist.pop_back();
1616 IndirectSymbolValueMap.
find(GV) != IndirectSymbolValueMap.
end())
1622 return std::move(*FoundError);
1623 flushRAUWWorklist();
1628 DoneLinkingBodies =
true;
1639 if (NGO->isDeclaration())
1643 if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) {
1647 }
else if (IsPerformingImport) {
1652 SmallString<256> S(
".symver ");
1656 DstM.appendModuleInlineAsm(S);
1677 return linkModuleFlagsMetadata();
1681 : ETypes(E), IsPacked(
P) {}
1684 : ETypes(ST->elements()), IsPacked(ST->isPacked()) {}
1694StructType *IRMover::StructTypeKeyInfo::getEmptyKey() {
1698StructType *IRMover::StructTypeKeyInfo::getTombstoneKey() {
1702unsigned IRMover::StructTypeKeyInfo::getHashValue(
const KeyTy &Key) {
1707unsigned IRMover::StructTypeKeyInfo::getHashValue(
const StructType *ST) {
1708 return getHashValue(KeyTy(ST));
1711bool IRMover::StructTypeKeyInfo::isEqual(
const KeyTy &LHS,
1713 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1715 return LHS == KeyTy(RHS);
1718bool IRMover::StructTypeKeyInfo::isEqual(
const StructType *LHS,
1720 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1722 return KeyTy(LHS) == KeyTy(RHS);
1727 NonOpaqueStructTypes.insert(Ty);
1732 NonOpaqueStructTypes.insert(Ty);
1733 bool Removed = OpaqueStructTypes.erase(Ty);
1740 OpaqueStructTypes.insert(Ty);
1747 auto I = NonOpaqueStructTypes.find_as(Key);
1748 return I == NonOpaqueStructTypes.end() ? nullptr : *
I;
1753 return OpaqueStructTypes.count(Ty);
1754 auto I = NonOpaqueStructTypes.find(Ty);
1755 return I == NonOpaqueStructTypes.end() ?
false : *
I == Ty;
1760 StructTypes.
run(M,
false);
1771 SharedMDs[MD].reset(
const_cast<MDNode *
>(MD));
1778 IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
1779 std::move(Src), ValuesToLink, std::move(AddLazyFor),
1780 IsPerformingImport);
1781 Error E = TheIRLinker.run();
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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
static void forceRenaming(GlobalValue *GV, StringRef Name)
The LLVM SymbolTable class autorenames globals that conflict in the symbol table.
static void getArrayElements(const Constant *C, SmallVectorImpl< Constant * > &Dest)
static std::string adjustInlineAsm(const std::string &InlineAsm, const Triple &Triple)
Return InlineAsm adjusted with target-specific directives if required.
static StringRef getTypeNamePrefix(StringRef Name)
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getNumElements(Type *Ty)
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
LLVM Basic Block Representation.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void setSelectionKind(SelectionKind Val)
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
This is an important base class in LLVM.
const Constant * stripPointerCasts() const
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
This class represents an Operation in the Expression.
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
bool erase(const KeyT &Val)
Implements a dense probed hash-table based set.
This is the base abstract class for diagnostic reporting in the backend.
Interface for custom diagnostic printing.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
bool IsNewDbgInfoFormat
Is this function using intrinsics to record the position of debugging information,...
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
static GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
StringRef getSection() const
Get the custom section of this global if it has one.
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
VisibilityTypes getVisibility() const
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
LinkageTypes getLinkage() const
bool hasLocalLinkage() const
const Comdat * getComdat() const
bool hasExternalWeakLinkage() const
ThreadLocalMode getThreadLocalMode() const
void setLinkage(LinkageTypes LT)
bool isDeclarationForLinker() const
unsigned getAddressSpace() const
Module * getParent()
Get the module that this global value is contained inside of...
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
PointerType * getType() const
Global values are always pointers.
bool hasGlobalUnnamedAddr() const
bool hasAppendingLinkage() const
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
@ InternalLinkage
Rename collisions when linking (static functions).
@ ExternalLinkage
Externally visible function.
@ ExternalWeakLinkage
ExternalWeak linkage description.
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
void addNonOpaque(StructType *Ty)
bool hasType(StructType *Ty)
void switchToNonOpaque(StructType *Ty)
void addOpaque(StructType *Ty)
StructType * findNonOpaque(ArrayRef< Type * > ETypes, bool IsPacked)
Error move(std::unique_ptr< Module > Src, ArrayRef< GlobalValue * > ValuesToLink, LazyCallback AddLazyFor, bool IsPerformingImport)
Move in the provide values in ValuesToLink from Src.
This is an important class for using LLVM in a threaded context.
LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg)
void print(DiagnosticPrinter &DP) const override
Print using the given DP a user-friendly message.
ArrayRef< MDOperand > operands() const
op_iterator op_end() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
op_iterator op_begin() const
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a distinct node.
void push_back(Metadata *MD)
Append an element to the tuple. This will resize the node.
static void CollectAsmSymvers(const Module &M, function_ref< void(StringRef, StringRef)> AsmSymver)
Parse inline ASM and collect the symvers directives that are defined in the current module.
A Module instance is used to store all the information related to an LLVM module.
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
@ Override
Uses the specified value, regardless of the behavior or value of the other module.
@ Warning
Emits a warning if two values disagree.
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
@ Min
Takes the min of the two values, which are required to be integers.
@ Append
Appends the two values, which are required to be metadata nodes.
@ Max
Takes the max of the two values, which are required to be integers.
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
LLVMContext & getContext() const
Get the global data context.
bool IsNewDbgInfoFormat
Is this Module using intrinsics to record the position of debugging information, or non-intrinsic rec...
void dropTriviallyDeadConstantArrays()
Destroy ConstantArrays in LLVMContext if they are not used.
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
void setDataLayout(StringRef Desc)
Set the data layout.
void insertGlobalVariable(GlobalVariable *GV)
Insert global variable GV at the end of the global variable list and take ownership.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
void setTargetTriple(StringRef T)
Set the target triple.
void setOperand(unsigned I, MDNode *New)
MDNode * getOperand(unsigned i) const
unsigned getNumOperands() const
iterator_range< op_iterator > operands()
void addOperand(MDNode *M)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
size_type size() const
Determine the number of elements in the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool erase(PtrType Ptr)
Remove pointer from the set.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
static constexpr size_t npos
Class to represent struct types.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
static StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
void setName(StringRef Name)
Change the name of this type to the specified name, or to a name with a suffix if there is a collisio...
bool hasName() const
Return true if this is a named struct that has a non-empty name.
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
StringRef getName() const
Return the name for this struct type if it has an identity.
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
DenseSet< const MDNode * > & getVisitedMetadata()
void run(const Module &M, bool onlyNamed)
The instances of the Type class are immutable: once they are created, they are never changed.
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FixedVectorTyID
Fixed width SIMD vector type.
unsigned getNumContainedTypes() const
Return the number of types in the derived type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isFunctionTy() const
True if this is an instance of FunctionType.
TypeID getTypeID() const
Return the type id for the type.
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
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.
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
std::optional< MDMapT > & getMDMap()
iterator find(const KeyT &Val)
Context for (re-)mapping values (and metadata).
MDNode * mapMDNode(const MDNode &N)
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)
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.
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.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVMContext & getContext() const
All values hold a context through their type.
StringRef getName() const
Return a constant reference to the value's name.
void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
bool erase(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
A raw_ostream that writes to an std::string.
unique_function is a type-erasing functor similar to std::function.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AddressSpace getAddressSpace(T *V)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
std::optional< Function * > remangleIntrinsicFunction(Function *F)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
@ 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_ReuseAndMutateDistinctMDs
Instruct the remapper to reuse and mutate distinct metadata (remapping them in place) instead of clon...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
constexpr const char * PseudoProbeDescMetadataName
Implement std::hash so that hash_code can be used in STL containers.
An information struct used to provide DenseMap with the various necessary components for a given valu...
KeyTy(ArrayRef< Type * > E, bool P)
bool operator==(const KeyTy &that) const
ArrayRef< Type * > ETypes
bool operator!=(const KeyTy &that) const