49 DenseMap<Type *, Type *> MappedTypes;
52 TypeMapTy(IRMover::IdentifiedStructTypeSet &DstStructTypesSet)
53 : DstStructTypesSet(DstStructTypesSet) {}
55 IRMover::IdentifiedStructTypeSet &DstStructTypesSet;
58 void addTypeMapping(
Type *DstTy,
Type *SrcTy);
64 FunctionType *
get(FunctionType *
T) {
69 Type *remapType(
Type *SrcTy)
override {
return get(SrcTy); }
71 bool recursivelyAddMappingIfTypesAreIsomorphic(
Type *DstTy,
Type *SrcTy);
75void TypeMapTy::addTypeMapping(
Type *DstTy,
Type *SrcTy) {
76 recursivelyAddMappingIfTypesAreIsomorphic(DstTy, SrcTy);
82bool TypeMapTy::recursivelyAddMappingIfTypesAreIsomorphic(
Type *DstTy,
91 return Entry == DstTy;
123 if (DSTy->isLiteral() != SSTy->
isLiteral() ||
124 DSTy->isPacked() != SSTy->
isPacked())
127 if (DArrTy->getNumElements() !=
cast<ArrayType>(SrcTy)->getNumElements())
130 if (DVecTy->getElementCount() !=
cast<VectorType>(SrcTy)->getElementCount())
141 [[maybe_unused]]
auto Res = MappedTypes.
insert({SrcTy, DstTy});
142 assert(!Res.second &&
"Recursive type?");
176 bool AnyChange =
false;
184 Entry = &MappedTypes[Ty];
185 assert(!*Entry &&
"Recursive type!");
189 if (!AnyChange && IsUniqued)
196 case Type::ArrayTyID:
197 return *
Entry = ArrayType::get(ElementTypes[0],
199 case Type::ScalableVectorTyID:
200 case Type::FixedVectorTyID:
201 return *
Entry = VectorType::get(ElementTypes[0],
203 case Type::FunctionTyID:
204 return *
Entry = FunctionType::get(ElementTypes[0],
207 case Type::StructTyID: {
214 if (STy->isOpaque()) {
219 if (StructType *OldT =
221 return *
Entry = OldT;
233 if (STy->hasName()) {
234 SmallString<16> TmpName = STy->getName();
261 IRLinker &TheIRLinker;
264 GlobalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
269 IRLinker &TheIRLinker;
272 LocalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
283 std::unique_ptr<Module> SrcM;
292 GlobalValueMaterializer GValMaterializer;
293 LocalValueMaterializer LValMaterializer;
305 DenseSet<GlobalValue *> ValuesToLink;
306 std::vector<GlobalValue *> Worklist;
307 std::vector<std::pair<GlobalValue *, Value*>> RAUWWorklist;
311 DenseSet<GlobalObject *> UnmappedMetadata;
313 void maybeAdd(GlobalValue *GV) {
314 if (ValuesToLink.
insert(GV).second)
315 Worklist.push_back(GV);
323 bool IsPerformingImport;
328 bool DoneLinkingBodies =
false;
332 std::optional<Error> FoundError;
335 FoundError = std::move(
E);
340 unsigned IndirectSymbolMCID;
344 GlobalValue *copyGlobalValueProto(
const GlobalValue *SGV,
bool ForDefinition);
346 void emitWarning(
const Twine &Message) {
347 SrcM->getContext().diagnose(LinkDiagnosticInfo(
DS_Warning, Message));
352 GlobalValue *getLinkedToGlobal(
const GlobalValue *SrcGV) {
371 if (FDGV->isIntrinsic())
373 if (FDGV->getFunctionType() != TypeMap.get(FSrcGV->getFunctionType()))
380 void computeTypeMapping();
382 Expected<Constant *> linkAppendingVarProto(GlobalVariable *DstGV,
383 const GlobalVariable *SrcGV);
390 bool shouldLink(GlobalValue *DGV, GlobalValue &SGV);
391 Expected<Constant *> linkGlobalValueProto(GlobalValue *GV,
392 bool ForIndirectSymbol);
394 Error linkModuleFlagsMetadata();
396 void linkGlobalVariable(GlobalVariable &Dst, GlobalVariable &Src);
398 void linkAliasAliasee(GlobalAlias &Dst, GlobalAlias &Src);
399 void linkIFuncResolver(GlobalIFunc &Dst, GlobalIFunc &Src);
400 Error linkGlobalValueBody(GlobalValue &Dst, GlobalValue &Src);
404 AttributeList mapAttributeTypes(LLVMContext &
C, AttributeList Attrs);
408 GlobalVariable *copyGlobalVariableProto(
const GlobalVariable *SGVar);
410 GlobalValue *copyIndirectSymbolProto(
const GlobalValue *SGV);
418 void flushRAUWWorklist();
423 void prepareCompileUnitsForImport();
424 void linkNamedMDNodes();
427 void updateAttributes(GlobalValue &GV);
430 IRLinker(
Module &DstM, MDMapT &SharedMDs,
431 IRMover::IdentifiedStructTypeSet &Set, std::unique_ptr<Module> SrcM,
435 : DstM(DstM), SrcM(std::
move(SrcM)), NamedMDNodes(NamedMDNodes),
436 AddLazyFor(std::
move(AddLazyFor)), TypeMap(
Set),
437 GValMaterializer(*this), LValMaterializer(*this), SharedMDs(SharedMDs),
438 IsPerformingImport(IsPerformingImport),
442 &TypeMap, &GValMaterializer),
443 IndirectSymbolMCID(
Mapper.registerAlternateMappingContext(
444 IndirectSymbolValueMap, &LValMaterializer)) {
445 ValueMap.
getMDMap() = std::move(SharedMDs);
446 for (GlobalValue *GV : ValuesToLink)
448 if (IsPerformingImport)
449 prepareCompileUnitsForImport();
451 ~IRLinker() { SharedMDs = std::move(*ValueMap.
getMDMap()); }
454 Value *materialize(
Value *V,
bool ForIndirectSymbol);
470 if (
GlobalValue *ConflictGV = M->getNamedValue(Name)) {
472 ConflictGV->setName(Name);
473 assert(ConflictGV->getName() != Name &&
"forceRenaming didn't work");
479Value *GlobalValueMaterializer::materialize(
Value *SGV) {
480 return TheIRLinker.materialize(SGV,
false);
483Value *LocalValueMaterializer::materialize(
Value *SGV) {
484 return TheIRLinker.materialize(SGV,
true);
487Value *IRLinker::materialize(
Value *V,
bool ForIndirectSymbol) {
493 if (
SGV->getParent() == &DstM)
500 if (
SGV->getParent() != SrcM.get())
517 if (!
F->isDeclaration())
520 if (
V->hasInitializer() ||
V->hasAppendingLinkage())
523 if (GA->getAliasee())
526 if (GI->getResolver())
541 (!ForIndirectSymbol && IndirectSymbolValueMap.
lookup(SGV) == New))
544 if (ForIndirectSymbol || shouldLink(New, *SGV))
545 setError(linkGlobalValueBody(*New, *SGV));
547 updateAttributes(*New);
568AttributeList IRLinker::mapAttributeTypes(
LLVMContext &
C, AttributeList Attrs) {
569 for (
unsigned i = 0; i <
Attrs.getNumAttrSets(); ++i) {
570 for (
int AttrIdx = Attribute::FirstTypeAttr;
571 AttrIdx <= Attribute::LastTypeAttr; AttrIdx++) {
573 if (
Attrs.hasAttributeAtIndex(i, TypedAttr)) {
575 Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) {
576 Attrs =
Attrs.replaceAttributeTypeAtIndex(
C, i, TypedAttr,
594 F->copyAttributesFrom(SF);
595 F->setAttributes(mapAttributeTypes(
F->getContext(),
F->getAttributes()));
604 auto *Ty = TypeMap.get(
SGV->getValueType());
609 SGV->getName(), &DstM);
610 DGA->copyAttributesFrom(GA);
617 SGV->getName(),
nullptr, &DstM);
618 DGI->copyAttributesFrom(GI);
626 bool ForDefinition) {
629 NewGV = copyGlobalVariableProto(SGVar);
631 NewGV = copyFunctionProto(SF);
634 NewGV = copyIndirectSymbolProto(SGV);
635 else if (
SGV->getValueType()->isFunctionTy())
639 SGV->getName(), &DstM);
644 nullptr,
SGV->getName(),
646 SGV->getThreadLocalMode(),
SGV->getAddressSpace());
651 else if (
SGV->hasExternalWeakLinkage())
658 if (
SGV->isDeclaration() && NewGO->hasMetadata())
659 UnmappedMetadata.
insert(NewGO);
667 NewF->setPersonalityFn(
nullptr);
668 NewF->setPrefixData(
nullptr);
669 NewF->setPrologueData(
nullptr);
676 size_t DotPos = Name.rfind(
'.');
677 return (DotPos == 0 || DotPos ==
StringRef::npos || Name.back() ==
'.' ||
678 !isdigit(
static_cast<unsigned char>(Name[DotPos + 1])))
680 : Name.substr(0, DotPos);
687void IRLinker::computeTypeMapping() {
694 TypeMap.addTypeMapping(DGV->
getType(),
SGV.getType());
701 TypeMap.addTypeMapping(DAT->getElementType(),
SAT->getElementType());
715 TypeMap.addTypeMapping(DGV->
getType(),
SGV.getType());
720 TypeMap.addTypeMapping(DGV->
getType(),
SGV.getType());
726 std::vector<StructType *>
Types = SrcM->getIdentifiedStructTypes();
731 if (TypeMap.DstStructTypesSet.
hasType(ST)) {
740 if (STTypePrefix.size() ==
ST->getName().size())
765 if (TypeMap.DstStructTypesSet.
hasType(DST))
766 TypeMap.addTypeMapping(DST, ST);
774 for (
unsigned i = 0; i != NumElements; ++i)
786 "Linking globals named '" + SrcGV->
getName() +
787 "': can only link appending global with another appending "
791 return stringErr(
"Appending variables linked with different const'ness!");
795 "Appending variables with different alignment need to be linked!");
799 "Appending variables with different visibility need to be linked!");
803 "Appending variables with different unnamed_addr need to be linked!");
807 "Appending variables with different section name need to be linked!");
810 return stringErr(
"Appending variables with different address spaces need "
826 bool IsNewStructor =
false;
827 bool IsOldStructor =
false;
828 if (Name ==
"llvm.global_ctors" || Name ==
"llvm.global_dtors") {
830 IsNewStructor =
true;
832 IsOldStructor =
true;
838 Type *Tys[3] = {
ST.getElementType(0),
ST.getElementType(1), VoidPtrTy};
845 DstNumElements = DstTy->getNumElements();
848 if (EltTy != DstTy->getElementType())
849 return stringErr(
"Appending variables with different element types!");
862 return !shouldLink(DGV, *
Key);
877 Mapper.scheduleMapAppendingVariable(*NG, DstGV, IsOldStructor, SrcElements);
882 RAUWWorklist.push_back(std::make_pair(DstGV, NG));
889 if (ValuesToLink.count(&SGV) ||
SGV.hasLocalLinkage())
895 if (
SGV.isDeclaration() || DoneLinkingBodies)
900 bool LazilyAdded =
false;
902 AddLazyFor(SGV, [
this, &LazilyAdded](
GlobalValue &GV) {
910 bool ForIndirectSymbol) {
913 bool ShouldLink = shouldLink(DGV, *SGV);
921 I = IndirectSymbolValueMap.
find(SGV);
922 if (
I != IndirectSymbolValueMap.
end())
926 if (!ShouldLink && ForIndirectSymbol)
934 bool NeedsRenaming =
false;
936 if (DGV && !ShouldLink) {
944 SGV->hasExactDefinition() && !DoneLinkingBodies) {
945 NewGV = copyGlobalValueProto(SGV,
false);
946 NeedsRenaming =
true;
952 if (DoneLinkingBodies)
955 NewGV = copyGlobalValueProto(SGV, ShouldLink || ForIndirectSymbol);
956 if (ShouldLink || !ForIndirectSymbol)
957 NeedsRenaming =
true;
968 assert(!UnmappedMetadata.
count(
F) &&
"intrinsic has unmapped metadata");
971 NeedsRenaming =
false;
977 if (ShouldLink || ForIndirectSymbol) {
978 if (
const Comdat *SC =
SGV->getComdat()) {
987 if (!ShouldLink && ForIndirectSymbol)
996 if (DGV && NewGV != SGV) {
998 NewGV, TypeMap.get(
SGV->getType()));
1001 if (DGV && NewGV != DGV) {
1005 RAUWWorklist.push_back(std::make_pair(
1017 Mapper.scheduleMapGlobalInitializer(Dst, *Src.getInitializer());
1024 assert(Dst.isDeclaration() && !Src.isDeclaration());
1027 if (
Error Err = Src.materialize())
1031 if (Src.hasPrefixData())
1032 Dst.setPrefixData(Src.getPrefixData());
1033 if (Src.hasPrologueData())
1034 Dst.setPrologueData(Src.getPrologueData());
1035 if (Src.hasPersonalityFn())
1036 Dst.setPersonalityFn(Src.getPersonalityFn());
1039 Dst.copyMetadata(&Src, 0);
1042 Dst.stealArgumentListFrom(Src);
1043 Dst.splice(Dst.end(), &Src);
1046 Mapper.scheduleRemapFunction(Dst);
1051 Mapper.scheduleMapGlobalAlias(Dst, *Src.getAliasee(), IndirectSymbolMCID);
1055 Mapper.scheduleMapGlobalIFunc(Dst, *Src.getResolver(), IndirectSymbolMCID);
1073void IRLinker::flushRAUWWorklist() {
1074 for (
const auto &Elem : RAUWWorklist) {
1077 std::tie(Old, New) = Elem;
1082 RAUWWorklist.clear();
1085void IRLinker::prepareCompileUnitsForImport() {
1086 NamedMDNode *SrcCompileUnits = SrcM->getNamedMetadata(
"llvm.dbg.cu");
1087 if (!SrcCompileUnits)
1094 assert(CU &&
"Expected valid compile unit");
1098 CU->replaceEnumTypes(
nullptr);
1099 CU->replaceMacros(
nullptr);
1100 CU->replaceRetainedTypes(
nullptr);
1111 CU->replaceGlobalVariables(
nullptr);
1113 CU->replaceImportedEntities(
nullptr);
1118void IRLinker::linkNamedMDNodes() {
1119 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1120 for (
const NamedMDNode &NMD : SrcM->named_metadata()) {
1122 if (&NMD == SrcModFlags)
1128 emitWarning(
"Pseudo-probe ignored: source module '" +
1129 SrcM->getModuleIdentifier() +
1130 "' is compiled with -fpseudo-probe-for-profiling while "
1131 "destination module '" +
1137 if (IsPerformingImport && NMD.getName() ==
"llvm.stats")
1142 auto &
Inserted = NamedMDNodes[DestNMD];
1149 for (
const MDNode *
Op : NMD.operands()) {
1158Error IRLinker::linkModuleFlagsMetadata() {
1160 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1207 std::tie(
DstOp, DstIndex) =
Flags.lookup(ID);
1208 unsigned SrcBehaviorValue = SrcBehavior->
getZExtValue();
1235 unsigned DstBehaviorValue = DstBehavior->
getZExtValue();
1237 auto overrideDstValue = [&]() {
1246 SrcOp->getOperand(2) !=
DstOp->getOperand(2))
1247 return stringErr(
"linking module flags '" +
ID->getString() +
1248 "': IDs have conflicting override values in '" +
1249 SrcM->getModuleIdentifier() +
"' and '" +
1259 if (SrcBehaviorValue != DstBehaviorValue) {
1260 bool MinAndWarn = (SrcBehaviorValue ==
Module::Min &&
1264 bool MaxAndWarn = (SrcBehaviorValue ==
Module::Max &&
1268 if (!(MaxAndWarn || MinAndWarn))
1269 return stringErr(
"linking module flags '" +
ID->getString() +
1270 "': IDs have conflicting behaviors in '" +
1271 SrcM->getModuleIdentifier() +
"' and '" +
1275 auto ensureDistinctOp = [&](
MDNode *DstValue) {
1277 "Expected MDTuple when appending module flags");
1278 if (DstValue->isDistinct())
1294 SrcOp->getOperand(2) !=
DstOp->getOperand(2)) {
1297 <<
"linking module flags '" <<
ID->getString()
1298 <<
"': IDs have conflicting values ('" << *
SrcOp->getOperand(2)
1299 <<
"' from " << SrcM->getModuleIdentifier() <<
" with '"
1344 switch (SrcBehaviorValue) {
1350 if (
SrcOp->getOperand(2) !=
DstOp->getOperand(2)) {
1353 <<
"linking module flags '" <<
ID->getString()
1354 <<
"': IDs have conflicting values: '" << *
SrcOp->getOperand(2)
1355 <<
"' from " << SrcM->getModuleIdentifier() <<
", and '"
1370 for (
const auto &O : SrcValue->
operands())
1390 for (
auto Idx : Mins) {
1393 if (!SeenMin.
count(ID)) {
1396 Op->getOperand(0),
ID,
1403 for (
MDNode *Requirement : Requirements) {
1408 if (!
Op ||
Op->getOperand(2) != ReqValue)
1409 return stringErr(
"linking module flags '" +
Flag->getString() +
1410 "': does not have the required value");
1421 return ".text\n.balign 2\n.thumb\n" +
InlineAsm;
1423 return ".text\n.balign 4\n.arm\n" +
InlineAsm;
1443 if (!
F->isIntrinsic())
1444 F->removeFnAttr(llvm::Attribute::NoCallback);
1450 CI->removeFnAttr(Attribute::NoCallback);
1454Error IRLinker::run() {
1456 if (SrcM->getMaterializer())
1457 if (
Error Err = SrcM->getMaterializer()->materializeMetadata())
1476 bool EnableDLWarning =
true;
1477 bool EnableTripleWarning =
true;
1478 if (SrcTriple.isNVPTX() && DstTriple.isNVPTX()) {
1479 bool SrcHasLibDeviceDL =
1480 (SrcM->getDataLayoutStr().
empty() ||
1481 SrcM->getDataLayoutStr() ==
"e-i64:64-v16:16-v32:32-n16:32:64");
1485 bool SrcHasLibDeviceTriple = (SrcTriple.getVendor() ==
Triple::NVIDIA &&
1486 SrcTriple.getOSName() ==
"gpulibs") ||
1487 (SrcTriple.getVendorName() ==
"unknown" &&
1488 SrcTriple.getOSName() ==
"unknown");
1489 EnableTripleWarning = !SrcHasLibDeviceTriple;
1490 EnableDLWarning = !(SrcHasLibDeviceTriple && SrcHasLibDeviceDL);
1493 if (EnableDLWarning && (SrcM->getDataLayout() != DstM.
getDataLayout())) {
1494 emitWarning(
"Linking two modules of different data layouts: '" +
1495 SrcM->getModuleIdentifier() +
"' is '" +
1496 SrcM->getDataLayoutStr() +
"' whereas '" +
1501 if (EnableTripleWarning && !SrcM->getTargetTriple().empty() &&
1502 !SrcTriple.isCompatibleWith(DstTriple))
1503 emitWarning(
"Linking two modules of different target triples: '" +
1504 SrcM->getModuleIdentifier() +
"' is '" +
1505 SrcM->getTargetTriple().str() +
"' whereas '" +
1512 computeTypeMapping();
1519 std::reverse(Worklist.begin(), Worklist.end());
1520 while (!Worklist.empty()) {
1522 Worklist.pop_back();
1526 IndirectSymbolValueMap.
find(GV) != IndirectSymbolValueMap.
end())
1532 return std::move(*FoundError);
1533 flushRAUWWorklist();
1538 DoneLinkingBodies =
true;
1549 if (NGO->isDeclaration())
1550 Mapper.remapGlobalObjectMetadata(*NGO);
1553 if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) {
1560 }
else if (IsPerformingImport) {
1570 {std::string(S), SrcM->getModuleInlineAsm().back().Props});
1582 return std::move(*FoundError);
1593 return linkModuleFlagsMetadata();
1610unsigned IRMover::StructTypeKeyInfo::getHashValue(
const KeyTy &
Key) {
1614unsigned IRMover::StructTypeKeyInfo::getHashValue(
const StructType *ST) {
1615 return getHashValue(KeyTy(ST));
1618bool IRMover::StructTypeKeyInfo::isEqual(
const KeyTy &LHS,
1620 return LHS == KeyTy(RHS);
1623bool IRMover::StructTypeKeyInfo::isEqual(
const StructType *
LHS,
1625 return KeyTy(
LHS) == KeyTy(
RHS);
1630 NonOpaqueStructTypes.insert(Ty);
1635 NonOpaqueStructTypes.insert(Ty);
1636 bool Removed = OpaqueStructTypes.erase(Ty);
1643 OpaqueStructTypes.insert(Ty);
1650 auto I = NonOpaqueStructTypes.find_as(
Key);
1651 return I == NonOpaqueStructTypes.end() ? nullptr : *
I;
1656 return OpaqueStructTypes.count(Ty);
1657 auto I = NonOpaqueStructTypes.find(Ty);
1658 return I == NonOpaqueStructTypes.end() ?
false : *
I == Ty;
1663 StructTypes.
run(M,
false);
1666 IdentifiedStructTypes.addOpaque(Ty);
1668 IdentifiedStructTypes.addNonOpaque(Ty);
1674 SharedMDs[MD].reset(const_cast<MDNode *>(MD));
1686 IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
1687 std::move(Src), ValuesToLink, std::move(AddLazyFor),
1688 IsPerformingImport, NamedMDNodes);
1689 return TheIRLinker.run();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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 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)
static Error stringErr(const Twine &T)
Most of the errors produced by this module are inconvertible StringErrors.
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallString class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Class to represent array types.
static LLVM_ABI 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 LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
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.
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
DiagnosticInfo(int Kind, DiagnosticSeverity Severity)
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.
static LLVM_ABI 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 LLVM_ABI 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.
VisibilityTypes getVisibility() const
LLVM_ABI 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
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...
LLVM_ABI 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
LLVM_ABI 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.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
LLVM_ABI 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 setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
LLVM_ABI void addNonOpaque(StructType *Ty)
LLVM_ABI bool hasType(StructType *Ty)
LLVM_ABI void switchToNonOpaque(StructType *Ty)
LLVM_ABI void addOpaque(StructType *Ty)
LLVM_ABI StructType * findNonOpaque(ArrayRef< Type * > ETypes, bool IsPacked)
LLVM_ABI IRMover(Module &M)
LLVM_ABI Error move(std::unique_ptr< Module > Src, ArrayRef< GlobalValue * > ValuesToLink, LazyCallback AddLazyFor, bool IsPerformingImport)
Move in the provide values in ValuesToLink from Src.
DenseMap< const NamedMDNode *, SmallPtrSet< const MDNode *, 8 > > NamedMDNodesT
llvm::unique_function< void(GlobalValue &GV, ValueAdder Add)> LazyCallback
This is an important class for using LLVM in a threaded context.
LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg LLVM_LIFETIME_BOUND)
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 LLVM_ABI 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.
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
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.
void setTargetTriple(Triple T)
Set the target triple.
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
void appendModuleInlineAsm(GlobalAsmFragment Fragment)
Append to the module-scope inline assembly blocks.
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.
LLVM_ABI void setOperand(unsigned I, MDNode *New)
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
iterator_range< op_iterator > operands()
LLVM_ABI void addOperand(MDNode *M)
Class to represent pointers.
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object 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.
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.
Represent a constant reference to a string, i.e.
static constexpr size_t npos
Class to represent struct types.
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.
static LLVM_ABI StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
LLVM_ABI 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 isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
const std::string & str() const
bool empty() const
Whether the triple is empty / default constructed.
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()
LLVM_ABI void run(const Module &M, bool onlyNamed)
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getNumContainedTypes() const
Return the number of types in the derived type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
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...
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)
This is a class that can be implemented by clients to materialize Values on demand.
LLVM Value Representation.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI 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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
LLVM_ABI std::optional< Function * > remangleIntrinsicFunction(Function *F)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
unsigned getNumElements(Type *Ty)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
LLVM_ABI void UpgradeNVVMAnnotations(Module &M)
Convert legacy nvvm.annotations metadata to appropriate function attributes.
auto cast_or_null(const Y &Val)
LLVM_ABI bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
LLVM_ABI void copyModuleAttrToFunctions(Module &M)
Copies module attributes to the functions in the module.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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_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...
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
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
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.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
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
LLVM_ABI KeyTy(ArrayRef< Type * > E, bool P)
LLVM_ABI bool operator==(const KeyTy &that) const
ArrayRef< Type * > ETypes
LLVM_ABI bool operator!=(const KeyTy &that) const