52 : DstStructTypesSet(DstStructTypesSet) {}
57 void addTypeMapping(
Type *DstTy,
Type *SrcTy);
61 void linkDefinedTypeBodies();
71 return cast<FunctionType>(get((
Type *)
T));
75 Type *remapType(
Type *SrcTy)
override {
return get(SrcTy); }
77 bool areTypesIsomorphic(
Type *DstTy,
Type *SrcTy);
81 void TypeMapTy::addTypeMapping(
Type *DstTy,
Type *SrcTy) {
87 if (!areTypesIsomorphic(DstTy, SrcTy)) {
90 for (
Type *Ty : SpeculativeTypes)
91 MappedTypes.
erase(Ty);
93 SrcDefinitionsToResolve.
resize(SrcDefinitionsToResolve.
size() -
94 SpeculativeDstOpaqueTypes.
size());
95 for (
StructType *Ty : SpeculativeDstOpaqueTypes)
96 DstResolvedOpaqueTypes.
erase(Ty);
104 for (
Type *Ty : SpeculativeTypes)
105 if (
auto *STy = dyn_cast<StructType>(Ty))
109 SpeculativeTypes.clear();
110 SpeculativeDstOpaqueTypes.clear();
115 bool TypeMapTy::areTypesIsomorphic(
Type *DstTy,
Type *SrcTy) {
121 Type *&Entry = MappedTypes[SrcTy];
123 return Entry == DstTy;
127 if (DstTy == SrcTy) {
135 if (
StructType *SSTy = dyn_cast<StructType>(SrcTy)) {
137 if (SSTy->isOpaque()) {
139 SpeculativeTypes.push_back(SrcTy);
147 if (cast<StructType>(DstTy)->isOpaque()) {
149 if (!DstResolvedOpaqueTypes.
insert(cast<StructType>(DstTy)).second)
152 SpeculativeTypes.push_back(SrcTy);
153 SpeculativeDstOpaqueTypes.push_back(cast<StructType>(DstTy));
164 if (isa<IntegerType>(DstTy))
166 if (
PointerType *PT = dyn_cast<PointerType>(DstTy)) {
167 if (PT->getAddressSpace() != cast<PointerType>(SrcTy)->getAddressSpace())
169 }
else if (
FunctionType *FT = dyn_cast<FunctionType>(DstTy)) {
170 if (FT->isVarArg() != cast<FunctionType>(SrcTy)->isVarArg())
172 }
else if (
StructType *DSTy = dyn_cast<StructType>(DstTy)) {
174 if (DSTy->isLiteral() != SSTy->
isLiteral() ||
175 DSTy->isPacked() != SSTy->
isPacked())
177 }
else if (
auto *DArrTy = dyn_cast<ArrayType>(DstTy)) {
178 if (DArrTy->getNumElements() != cast<ArrayType>(SrcTy)->getNumElements())
180 }
else if (
auto *DVecTy = dyn_cast<VectorType>(DstTy)) {
181 if (DVecTy->getElementCount() != cast<VectorType>(SrcTy)->getElementCount())
188 SpeculativeTypes.push_back(SrcTy);
199 void TypeMapTy::linkDefinedTypeBodies() {
201 for (
StructType *SrcSTy : SrcDefinitionsToResolve) {
202 StructType *DstSTy = cast<StructType>(MappedTypes[SrcSTy]);
206 Elements.
resize(SrcSTy->getNumElements());
207 for (
unsigned I = 0,
E = Elements.
size();
I !=
E; ++
I)
208 Elements[
I] = get(SrcSTy->getElementType(
I));
210 DstSTy->
setBody(Elements, SrcSTy->isPacked());
213 SrcDefinitionsToResolve.clear();
214 DstResolvedOpaqueTypes.
clear();
233 return get(Ty, Visited);
238 Type **Entry = &MappedTypes[Ty];
243 bool IsUniqued = !isa<StructType>(Ty) || cast<StructType>(Ty)->isLiteral();
247 for (
auto &Pair : MappedTypes) {
248 assert(!(Pair.first != Ty && Pair.second == Ty) &&
249 "mapping to a source type");
253 if (!Visited.
insert(cast<StructType>(Ty)).second) {
269 bool AnyChange =
false;
277 Entry = &MappedTypes[Ty];
279 if (
auto *DTy = dyn_cast<StructType>(*Entry)) {
281 auto *STy = cast<StructType>(Ty);
282 finishType(DTy, STy, ElementTypes);
290 if (!AnyChange && IsUniqued)
299 cast<ArrayType>(Ty)->getNumElements());
304 ElementTypes[0], cast<FixedVectorType>(Ty)->getNumElements());
307 cast<PointerType>(Ty)->getAddressSpace());
311 cast<FunctionType>(Ty)->isVarArg());
313 auto *STy = cast<StructType>(Ty);
327 return *Entry = OldT;
336 finishType(DTy, STy, ElementTypes);
358 IRLinker &TheIRLinker;
361 GlobalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
366 IRLinker &TheIRLinker;
369 LocalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
380 std::unique_ptr<Module> SrcM;
386 GlobalValueMaterializer GValMaterializer;
387 LocalValueMaterializer LValMaterializer;
400 std::vector<GlobalValue *> Worklist;
401 std::vector<std::pair<GlobalValue *, Value*>> RAUWWorklist;
404 if (ValuesToLink.
insert(GV).second)
405 Worklist.push_back(GV);
413 bool IsPerformingImport;
418 bool DoneLinkingBodies =
false;
436 unsigned IndirectSymbolMCID;
442 void emitWarning(
const Twine &Message) {
468 void computeTypeMapping();
480 bool ForIndirectSymbol);
482 Error linkModuleFlagsMetadata();
506 void flushRAUWWorklist();
511 void prepareCompileUnitsForImport();
512 void linkNamedMDNodes();
515 IRLinker(
Module &DstM, MDMapT &SharedMDs,
519 bool IsPerformingImport)
520 : DstM(DstM), SrcM(
std::
move(SrcM)), AddLazyFor(
std::
move(AddLazyFor)),
521 TypeMap(Set), GValMaterializer(*this), LValMaterializer(*this),
522 SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
525 IndirectSymbolMCID(Mapper.registerAlternateMappingContext(
526 IndirectSymbolValueMap, &LValMaterializer)) {
530 if (IsPerformingImport)
531 prepareCompileUnitsForImport();
536 Value *materialize(
Value *V,
bool ForIndirectSymbol);
554 ConflictGV->setName(
Name);
555 assert(ConflictGV->getName() !=
Name &&
"forceRenaming didn't work");
561 Value *GlobalValueMaterializer::materialize(
Value *SGV) {
562 return TheIRLinker.materialize(SGV,
false);
565 Value *LocalValueMaterializer::materialize(
Value *SGV) {
566 return TheIRLinker.materialize(SGV,
true);
569 Value *IRLinker::materialize(
Value *V,
bool ForIndirectSymbol) {
570 auto *SGV = dyn_cast<GlobalValue>(V);
578 if (SGV->getParent() != &DstM && SGV->getParent() != SrcM.get())
594 if (
auto *
F = dyn_cast<Function>(New)) {
595 if (!
F->isDeclaration())
597 }
else if (
auto *V = dyn_cast<GlobalVariable>(New)) {
598 if (V->hasInitializer() || V->hasAppendingLinkage())
601 auto *IS = cast<GlobalIndirectSymbol>(New);
602 if (IS->getIndirectSymbol())
617 if (ForIndirectSymbol || shouldLink(New, *SGV))
618 setError(linkGlobalValueBody(*New, *SGV));
641 for (
unsigned i = 0; i <
Attrs.getNumAttrSets(); ++i) {
643 {Attribute::ByVal, Attribute::StructRet, Attribute::ByRef}) {
644 if (
Attrs.hasAttribute(i, TypedAttr)) {
645 if (
Type *Ty =
Attrs.getAttribute(i, TypedAttr).getValueAsType()) {
646 Attrs =
Attrs.replaceAttributeType(
C, i, TypedAttr, TypeMap.get(Ty));
663 F->copyAttributesFrom(SF);
664 F->setAttributes(mapAttributeTypes(
F->getContext(),
F->getAttributes()));
676 if (isa<GlobalAlias>(SGIS))
689 bool ForDefinition) {
691 if (
auto *SGVar = dyn_cast<GlobalVariable>(SGV)) {
692 NewGV = copyGlobalVariableProto(SGVar);
693 }
else if (
auto *SF = dyn_cast<Function>(SGV)) {
694 NewGV = copyFunctionProto(SF);
697 NewGV = copyGlobalIndirectSymbolProto(cast<GlobalIndirectSymbol>(SGV));
717 if (
auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
720 NewGO->copyMetadata(cast<GlobalObject>(SGV), 0);
726 if (
auto *NewF = dyn_cast<Function>(NewGV)) {
727 NewF->setPersonalityFn(
nullptr);
728 NewF->setPrefixData(
nullptr);
729 NewF->setPrologueData(
nullptr);
736 size_t DotPos =
Name.rfind(
'.');
738 !isdigit(static_cast<unsigned char>(
Name[DotPos + 1])))
740 :
Name.substr(0, DotPos);
747 void IRLinker::computeTypeMapping() {
761 TypeMap.addTypeMapping(DAT->
getElementType(), SAT->getElementType());
786 std::vector<StructType *> Types = SrcM->getIdentifiedStructTypes();
791 if (TypeMap.DstStructTypesSet.hasType(
ST)) {
800 if (STTypePrefix.size() ==
ST->getName().size())
825 if (TypeMap.DstStructTypesSet.hasType(DST))
826 TypeMap.addTypeMapping(DST,
ST);
831 TypeMap.linkDefinedTypeBodies();
836 unsigned NumElements = cast<ArrayType>(
C->
getType())->getNumElements();
838 for (
unsigned i = 0; i != NumElements; ++i)
854 bool IsNewStructor =
false;
855 bool IsOldStructor =
false;
856 if (
Name ==
"llvm.global_ctors" ||
Name ==
"llvm.global_dtors") {
857 if (cast<StructType>(EltTy)->getNumElements() == 3)
858 IsNewStructor =
true;
860 IsOldStructor =
true;
865 auto &
ST = *cast<StructType>(EltTy);
866 Type *Tys[3] = {
ST.getElementType(0),
ST.getElementType(1), VoidPtrTy};
870 uint64_t DstNumElements = 0;
877 "Linking globals named '" + SrcGV->
getName() +
878 "': can only link appending global with another appending " 883 return stringErr(
"Appending variables with different element types!");
885 return stringErr(
"Appending variables linked with different const'ness!");
889 "Appending variables with different alignment need to be linked!");
893 "Appending variables with different visibility need to be linked!");
897 "Appending variables with different unnamed_addr need to be linked!");
901 "Appending variables with different section name need to be linked!");
910 dyn_cast<GlobalValue>(
E->getAggregateElement(2)->stripPointerCasts());
914 return !shouldLink(DGV, *
Key);
917 uint64_t NewSize = DstNumElements + SrcElements.
size();
933 IsOldStructor, SrcElements);
938 RAUWWorklist.push_back(
957 bool LazilyAdded =
false;
958 AddLazyFor(SGV, [
this, &LazilyAdded](
GlobalValue &GV) {
966 bool ForIndirectSymbol) {
969 bool ShouldLink = shouldLink(DGV, *SGV);
975 return cast<Constant>(
I->second);
977 I = IndirectSymbolValueMap.
find(SGV);
978 if (
I != IndirectSymbolValueMap.
end())
979 return cast<Constant>(
I->second);
982 if (!ShouldLink && ForIndirectSymbol)
988 return linkAppendingVarProto(cast_or_null<GlobalVariable>(DGV),
989 cast<GlobalVariable>(SGV));
992 if (DGV && !ShouldLink) {
998 if (DoneLinkingBodies)
1001 NewGV = copyGlobalValueProto(SGV, ShouldLink || ForIndirectSymbol);
1002 if (ShouldLink || !ForIndirectSymbol)
1009 if (
Function *
F = dyn_cast<Function>(NewGV))
1011 NewGV = Remangled.getValue();
1013 if (ShouldLink || ForIndirectSymbol) {
1015 if (
auto *GO = dyn_cast<GlobalObject>(NewGV)) {
1017 DC->setSelectionKind(
SC->getSelectionKind());
1023 if (!ShouldLink && ForIndirectSymbol)
1032 if (DGV && NewGV != SGV) {
1034 NewGV, TypeMap.get(SGV->
getType()));
1037 if (DGV && NewGV != DGV) {
1041 RAUWWorklist.push_back(std::make_pair(
1089 IndirectSymbolMCID);
1093 if (
auto *
F = dyn_cast<Function>(&Src))
1094 return linkFunctionBody(cast<Function>(Dst), *
F);
1095 if (
auto *GVar = dyn_cast<GlobalVariable>(&Src)) {
1096 linkGlobalVariable(cast<GlobalVariable>(Dst), *GVar);
1099 linkIndirectSymbolBody(cast<GlobalIndirectSymbol>(Dst), cast<GlobalIndirectSymbol>(Src));
1103 void IRLinker::flushRAUWWorklist() {
1104 for (
const auto &Elem : RAUWWorklist) {
1107 std::tie(Old, New) = Elem;
1112 RAUWWorklist.clear();
1115 void IRLinker::prepareCompileUnitsForImport() {
1116 NamedMDNode *SrcCompileUnits = SrcM->getNamedMetadata(
"llvm.dbg.cu");
1117 if (!SrcCompileUnits)
1123 auto *
CU = cast<DICompileUnit>(SrcCompileUnits->
getOperand(
I));
1124 assert(
CU &&
"Expected valid compile unit");
1128 CU->replaceEnumTypes(
nullptr);
1129 CU->replaceMacros(
nullptr);
1130 CU->replaceRetainedTypes(
nullptr);
1141 CU->replaceGlobalVariables(
nullptr);
1156 bool ReplaceImportedEntities =
false;
1157 for (
auto *
IE :
CU->getImportedEntities()) {
1160 if (isa<DILocalScope>(
Scope))
1163 ReplaceImportedEntities =
true;
1165 if (ReplaceImportedEntities) {
1166 if (!AllImportedModules.
empty())
1170 AllImportedModules.
end())));
1174 CU->replaceImportedEntities(
nullptr);
1180 void IRLinker::linkNamedMDNodes() {
1181 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1182 for (
const NamedMDNode &NMD : SrcM->named_metadata()) {
1184 if (&NMD == SrcModFlags)
1188 for (
const MDNode *
Op : NMD.operands())
1194 Error IRLinker::linkModuleFlagsMetadata() {
1196 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1215 ConstantInt *Behavior = mdconst::extract<ConstantInt>(
Op->getOperand(0));
1219 Requirements.
insert(cast<MDNode>(
Op->getOperand(2)));
1221 Flags[
ID] = std::make_pair(
Op,
I);
1230 mdconst::extract<ConstantInt>(
SrcOp->getOperand(0));
1235 unsigned SrcBehaviorValue = SrcBehavior->
getZExtValue();
1241 if (Requirements.
insert(cast<MDNode>(
SrcOp->getOperand(2)))) {
1256 mdconst::extract<ConstantInt>(
DstOp->getOperand(0));
1257 unsigned DstBehaviorValue = DstBehavior->
getZExtValue();
1259 auto overrideDstValue = [&]() {
1268 SrcOp->getOperand(2) !=
DstOp->getOperand(2))
1269 return stringErr(
"linking module flags '" +
ID->getString() +
1270 "': IDs have conflicting override values in '" +
1271 SrcM->getModuleIdentifier() +
"' and '" +
1281 if (SrcBehaviorValue != DstBehaviorValue) {
1282 bool MaxAndWarn = (SrcBehaviorValue ==
Module::Max &&
1287 return stringErr(
"linking module flags '" +
ID->getString() +
1288 "': IDs have conflicting behaviors in '" +
1289 SrcM->getModuleIdentifier() +
"' and '" +
1293 auto replaceDstValue = [&](
MDNode *
New) {
1304 SrcOp->getOperand(2) !=
DstOp->getOperand(2)) {
1307 <<
"linking module flags '" <<
ID->getString()
1308 <<
"': IDs have conflicting values ('" << *
SrcOp->getOperand(2)
1309 <<
"' from " << SrcM->getModuleIdentifier() <<
" with '" 1318 mdconst::extract<ConstantInt>(
DstOp->getOperand(2));
1320 mdconst::extract<ConstantInt>(
SrcOp->getOperand(2));
1335 switch (SrcBehaviorValue) {
1341 if (
SrcOp->getOperand(2) !=
DstOp->getOperand(2))
1342 return stringErr(
"linking module flags '" +
ID->getString() +
1343 "': IDs have conflicting values in '" +
1344 SrcM->getModuleIdentifier() +
"' and '" +
1355 MDNode *DstValue = cast<MDNode>(
DstOp->getOperand(2));
1356 MDNode *SrcValue = cast<MDNode>(
SrcOp->getOperand(2));
1360 MDs.append(SrcValue->op_begin(), SrcValue->op_end());
1367 MDNode *DstValue = cast<MDNode>(
DstOp->getOperand(2));
1368 MDNode *SrcValue = cast<MDNode>(
SrcOp->getOperand(2));
1370 Elts.
insert(SrcValue->op_begin(), SrcValue->op_end());
1381 for (
unsigned I = 0,
E = Requirements.
size();
I !=
E; ++
I) {
1382 MDNode *Requirement = Requirements[
I];
1387 if (!
Op ||
Op->getOperand(2) != ReqValue)
1388 return stringErr(
"linking module flags '" +
Flag->getString() +
1389 "': does not have the required value");
1400 return ".text\n.balign 2\n.thumb\n" +
InlineAsm;
1402 return ".text\n.balign 4\n.arm\n" +
InlineAsm;
1406 Error IRLinker::run() {
1408 if (SrcM->getMaterializer())
1409 if (
Error Err = SrcM->getMaterializer()->materializeMetadata())
1418 emitWarning(
"Linking two modules of different data layouts: '" +
1419 SrcM->getModuleIdentifier() +
"' is '" +
1420 SrcM->getDataLayoutStr() +
"' whereas '" +
1426 if (DstM.
getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
1431 if (!SrcM->getTargetTriple().empty()&&
1432 !SrcTriple.isCompatibleWith(DstTriple))
1433 emitWarning(
"Linking two modules of different target triples: '" +
1434 SrcM->getModuleIdentifier() +
"' is '" +
1435 SrcM->getTargetTriple() +
"' whereas '" +
1442 computeTypeMapping();
1445 while (!Worklist.empty()) {
1447 Worklist.pop_back();
1451 IndirectSymbolValueMap.
find(GV) != IndirectSymbolValueMap.
end())
1458 flushRAUWWorklist();
1463 DoneLinkingBodies =
true;
1471 if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) {
1475 }
else if (IsPerformingImport) {
1490 return linkModuleFlagsMetadata();
1507 StructType *IRMover::StructTypeKeyInfo::getEmptyKey() {
1511 StructType *IRMover::StructTypeKeyInfo::getTombstoneKey() {
1515 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const KeyTy &
Key) {
1520 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const StructType *
ST) {
1521 return getHashValue(KeyTy(
ST));
1526 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1528 return LHS == KeyTy(RHS);
1533 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1535 return KeyTy(LHS) == KeyTy(RHS);
1540 NonOpaqueStructTypes.insert(Ty);
1545 NonOpaqueStructTypes.insert(Ty);
1546 bool Removed = OpaqueStructTypes.erase(Ty);
1553 OpaqueStructTypes.insert(Ty);
1560 auto I = NonOpaqueStructTypes.find_as(
Key);
1561 return I == NonOpaqueStructTypes.end() ? nullptr : *
I;
1566 return OpaqueStructTypes.count(Ty);
1567 auto I = NonOpaqueStructTypes.find(Ty);
1568 return I == NonOpaqueStructTypes.end() ?
false : *
I == Ty;
1573 StructTypes.
run(M,
false);
1583 for (
auto *MD : StructTypes.getVisitedMetadata()) {
1584 SharedMDs[MD].reset(const_cast<MDNode *>(MD));
1591 bool IsPerformingImport) {
1592 IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
1594 IsPerformingImport);
1595 Error E = TheIRLinker.run();
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
bool isDeclarationForLinker() const
StringRef getSection() const
Get the custom section of this global if it has one.
unsigned getAlignment() const
FIXME: Remove this function once transition to Align is over.
reference emplace_back(ArgTypes &&... Args)
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
ThreadLocalMode getThreadLocalMode() const
bool hasLocalLinkage() const
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
uint64_t getNumElements() const
Takes the max of the two values, which are required to be integers.
MDNode * getOperand(unsigned i) const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
size_type size() const
Determine the number of elements in the SetVector.
A Module instance is used to store all the information related to an LLVM module.
LLVM_NODISCARD bool empty() const
ArrayRef< Type * > ETypes
void addOpaque(StructType *Ty)
Implements a dense probed hash-table based set.
void push_back(const T &Elt)
Any global values not in value map are mapped to null instead of mapping to self.
StructType * findNonOpaque(ArrayRef< Type * > ETypes, bool IsPacked)
void addOperand(MDNode *M)
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Externally visible function.
LLVMContext & getContext() const
All values hold a context through their type.
bool hasPrologueData() const
Check whether this function has prologue data.
void setDataLayout(StringRef Desc)
Set the data layout.
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
Context for (re-)mapping values (and metadata).
static void getArrayElements(const Constant *C, SmallVectorImpl< Constant * > &Dest)
void scheduleRemapFunction(Function &F, unsigned MappingContextID=0)
const MDOperand & getOperand(unsigned I) const
void switchToNonOpaque(StructType *Ty)
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
bool hasExternalWeakLinkage() const
Error takeError()
Take ownership of the stored error.
void reserve(size_type N)
void setOperand(unsigned I, MDNode *New)
iterator end()
Get an iterator to the end of the SetVector.
op_iterator op_end() const
Constant * getPrologueData() const
Get the prologue data associated with this function.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Appends the two values, which are required to be metadata nodes.
Error move(std::unique_ptr< Module > Src, ArrayRef< GlobalValue * > ValuesToLink, std::function< void(GlobalValue &GV, ValueAdder Add)> AddLazyFor, bool IsPerformingImport)
Move in the provide values in ValuesToLink from Src.
void copyMetadata(const GlobalObject *Src, unsigned Offset)
Copy metadata from Src, adjusting offsets by Offset.
bool hasPrefixData() const
Check whether this function has prefix data.
Scalable SIMD vector type.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
static ManagedStatic< DebugCounter > DC
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
TypeID getTypeID() const
Return the type id for the type.
Class to represent struct types.
LLVMContext & getContext() const
Get the global data context.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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...
unsigned getNumOperands() const
Fixed width SIMD vector type.
void setName(const Twine &Name)
Change the name of the value.
Tagged union holding either a T or a Error.
Interface for custom diagnostic printing.
static constexpr size_t npos
Constant * getPrefixData() const
Get the prefix data associated with this function.
op_iterator op_begin() const
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Class to represent function types.
Instruct the remapper to move distinct metadata instead of duplicating it when there are module-level...
Type * getType() const
All values are typed, get the type of this value.
bool insert(const value_type &X)
Insert a new element into the SetVector.
static bool isEqual(const Function &Caller, const Function &Callee)
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Class to represent array types.
iterator find(const KeyT &Val)
iterator begin()
Get an iterator to the beginning of the SetVector.
bool operator!=(const KeyTy &that) const
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool hasPersonalityFn() const
Check whether this function has a personality function.
LinkageTypes getLinkage() const
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
bool hasType(StructType *Ty)
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
void takeName(Value *V)
Transfer the name from V to this value.
Class to represent pointers.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
bool hasAppendingLinkage() const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
ExternalWeak linkage description.
This is a class that can be implemented by clients to materialize Values on demand.
bool erase(const KeyT &Val)
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
This is the base abstract class for diagnostic reporting in the backend.
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.
void stealArgumentListFrom(Function &Src)
Steal arguments from another function.
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
VisibilityTypes getVisibility() const
KeyTy(ArrayRef< Type * > E, bool P)
The instances of the Type class are immutable: once they are created, they are never changed.
This is an important class for using LLVM in a threaded context.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
unsigned getNumContainedTypes() const
Return the number of types in the derived type.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(const ValueT &V)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Optional< MDMapT > & getMDMap()
void splice(iterator where, iplist_impl &L2)
void scheduleMapGlobalInitializer(GlobalVariable &GV, Constant &Init, unsigned MappingContextID=0)
unsigned getAddressSpace() const
StringRef getName() const
Return the name for this struct type if it has an identity.
Error materialize()
Make sure this GlobalValue is fully read.
Function Alias Analysis false
void addNonOpaque(StructType *Ty)
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Base class for scope-like contexts.
A SetVector that performs no allocations if smaller than a certain size.
static ErrorSuccess success()
Create a success value.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is the shared class of boolean and integer constants.
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false.
void dropTriviallyDeadConstantArrays()
Destroy ConstantArrays in LLVMContext if they are not used.
void run(const Module &M, bool onlyNamed)
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
void scheduleMapAppendingVariable(GlobalVariable &GV, Constant *InitPrefix, bool IsOldCtorDtor, ArrayRef< Constant * > NewMembers, unsigned MappingContextID=0)
void copyAttributesFrom(const GlobalValue *Src)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
CHAIN = SC CHAIN, Imm128 - System call.
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
bool hasGlobalUnnamedAddr() const
void print(DiagnosticPrinter &DP) const override
Print using the given DP a user-friendly message.
bool operator==(const KeyTy &that) const
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
static StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
void setLinkage(LinkageTypes LT)
Uses the specified value, regardless of the behavior or value of the other module.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
FunctionType * getFunctionType() const
Returns the FunctionType for me.
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
static StringRef getTypeNamePrefix(StringRef Name)
const Comdat * getComdat() const
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg)
Emits a warning if two values disagree.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
This is a class that can be implemented by clients to remap types when cloning constants and instruct...
If this flag is set, the remapper ignores missing function-local entries (Argument,...
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
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...
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
bool isFunctionTy() const
True if this is an instance of FunctionType.
void setAlignment(MaybeAlign Align)
Appends the two values, which are required to be metadata nodes.
StringRef getName() const
Return a constant reference to the value's name.
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
void setPrologueData(Constant *PrologueData)
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
void setTargetTriple(StringRef T)
Set the target triple.
Type * getValueType() const
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Rename collisions when linking (static functions).
const Constant * getIndirectSymbol() const
void addFlags(RemapFlags Flags)
Add to the current RemapFlags.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Value * mapValue(const Value &V)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< void(GlobalValue &)> ValueAdder
A raw_ostream that writes to an std::string.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Lightweight error class with error context and mandatory checking.
static std::string adjustInlineAsm(const std::string &InlineAsm, const Triple &Triple)
Return InlineAsm adjusted with target-specific directives if required.
static void forceRenaming(GlobalValue *GV, StringRef Name)
The LLVM SymbolTable class autorenames globals that conflict in the symbol table.
print Print MemDeps of function
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
StringRef - Represent a constant reference to a string, i.e.
void setPersonalityFn(Constant *Fn)
bool operator==(uint64_t V1, const APInt &V2)
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
unsigned getNumOperands() const
Return number of MDNode operands.
bool hasName() const
Return true if this is a named struct that has a non-empty name.
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
Type * getElementType() const
static IntegerType * getInt8Ty(LLVMContext &C)
void scheduleMapGlobalIndirectSymbol(GlobalIndirectSymbol &GIS, Constant &Target, unsigned MappingContextID=0)
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...
PointerType * getType() const
Global values are always pointers.
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
MDNode * mapMDNode(const MDNode &N)
void setPrefixData(Constant *PrefixData)