51 : DstStructTypesSet(DstStructTypesSet) {}
56 void addTypeMapping(
Type *DstTy,
Type *SrcTy);
60 void linkDefinedTypeBodies();
70 return cast<FunctionType>(
get((
Type *)
T));
74 Type *remapType(
Type *SrcTy)
override {
return get(SrcTy); }
76 bool areTypesIsomorphic(
Type *DstTy,
Type *SrcTy);
80 void TypeMapTy::addTypeMapping(
Type *DstTy,
Type *SrcTy) {
81 assert(SpeculativeTypes.empty());
82 assert(SpeculativeDstOpaqueTypes.empty());
86 if (!areTypesIsomorphic(DstTy, SrcTy)) {
89 for (
Type *Ty : SpeculativeTypes)
90 MappedTypes.erase(Ty);
92 SrcDefinitionsToResolve.resize(SrcDefinitionsToResolve.size() -
93 SpeculativeDstOpaqueTypes.size());
94 for (
StructType *Ty : SpeculativeDstOpaqueTypes)
95 DstResolvedOpaqueTypes.erase(Ty);
103 for (
Type *Ty : SpeculativeTypes)
104 if (
auto *STy = dyn_cast<StructType>(Ty))
108 SpeculativeTypes.clear();
109 SpeculativeDstOpaqueTypes.clear();
114 bool TypeMapTy::areTypesIsomorphic(
Type *DstTy,
Type *SrcTy) {
122 return Entry == DstTy;
126 if (DstTy == SrcTy) {
134 if (
StructType *SSTy = dyn_cast<StructType>(SrcTy)) {
136 if (SSTy->isOpaque()) {
138 SpeculativeTypes.push_back(SrcTy);
146 if (cast<StructType>(DstTy)->isOpaque()) {
148 if (!DstResolvedOpaqueTypes.insert(cast<StructType>(DstTy)).second)
150 SrcDefinitionsToResolve.push_back(SSTy);
151 SpeculativeTypes.push_back(SrcTy);
152 SpeculativeDstOpaqueTypes.push_back(cast<StructType>(DstTy));
163 if (isa<IntegerType>(DstTy))
165 if (
PointerType *PT = dyn_cast<PointerType>(DstTy)) {
166 if (PT->getAddressSpace() != cast<PointerType>(SrcTy)->getAddressSpace())
168 }
else if (
FunctionType *FT = dyn_cast<FunctionType>(DstTy)) {
169 if (FT->isVarArg() != cast<FunctionType>(SrcTy)->isVarArg())
171 }
else if (
StructType *DSTy = dyn_cast<StructType>(DstTy)) {
173 if (DSTy->isLiteral() != SSTy->
isLiteral() ||
174 DSTy->isPacked() != SSTy->
isPacked())
176 }
else if (
auto *DSeqTy = dyn_cast<SequentialType>(DstTy)) {
177 if (DSeqTy->getNumElements() !=
178 cast<SequentialType>(SrcTy)->getNumElements())
185 SpeculativeTypes.push_back(SrcTy);
196 void TypeMapTy::linkDefinedTypeBodies() {
198 for (
StructType *SrcSTy : SrcDefinitionsToResolve) {
199 StructType *DstSTy = cast<StructType>(MappedTypes[SrcSTy]);
203 Elements.
resize(SrcSTy->getNumElements());
204 for (
unsigned I = 0,
E = Elements.
size();
I !=
E; ++
I)
205 Elements[
I] =
get(SrcSTy->getElementType(
I));
207 DstSTy->
setBody(Elements, SrcSTy->isPacked());
208 DstStructTypesSet.switchToNonOpaque(DstSTy);
210 SrcDefinitionsToResolve.clear();
211 DstResolvedOpaqueTypes.clear();
225 DstStructTypesSet.addNonOpaque(DTy);
230 return get(Ty, Visited);
235 Type **Entry = &MappedTypes[Ty];
240 bool IsUniqued = !isa<StructType>(Ty) || cast<StructType>(Ty)->isLiteral();
249 DstStructTypesSet.hasType(STy))
253 for (
auto &Pair : MappedTypes) {
254 assert(!(Pair.first != Ty && Pair.second == Ty) &&
255 "mapping to a source type");
259 if (!Visited.
insert(STy).second) {
275 bool AnyChange =
false;
283 Entry = &MappedTypes[Ty];
285 if (
auto *DTy = dyn_cast<StructType>(*Entry)) {
287 auto *STy = cast<StructType>(Ty);
288 finishType(DTy, STy, ElementTypes);
296 if (!AnyChange && IsUniqued)
305 cast<ArrayType>(Ty)->getNumElements());
308 cast<VectorType>(Ty)->getNumElements());
311 cast<PointerType>(Ty)->getAddressSpace());
315 cast<FunctionType>(Ty)->isVarArg());
317 auto *STy = cast<StructType>(Ty);
324 DstStructTypesSet.addOpaque(STy);
329 DstStructTypesSet.findNonOpaque(ElementTypes, IsPacked)) {
331 return *Entry = OldT;
335 DstStructTypesSet.addNonOpaque(STy);
340 finishType(DTy, STy, ElementTypes);
362 IRLinker &TheIRLinker;
365 GlobalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
370 IRLinker &TheIRLinker;
373 LocalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
384 std::unique_ptr<Module> SrcM;
387 std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor;
390 GlobalValueMaterializer GValMaterializer;
391 LocalValueMaterializer LValMaterializer;
404 std::vector<GlobalValue *> Worklist;
405 std::vector<std::pair<GlobalValue *, Value*>> RAUWWorklist;
408 if (ValuesToLink.
insert(GV).second)
409 Worklist.push_back(GV);
417 bool IsPerformingImport;
422 bool DoneLinkingBodies =
false;
429 FoundError = std::move(E);
440 unsigned IndirectSymbolMCID;
446 void emitWarning(
const Twine &Message) {
472 void computeTypeMapping();
484 bool ForIndirectSymbol);
486 Error linkModuleFlagsMetadata();
510 void flushRAUWWorklist();
515 void prepareCompileUnitsForImport();
516 void linkNamedMDNodes();
519 IRLinker(
Module &DstM, MDMapT &SharedMDs,
523 bool IsPerformingImport)
524 : DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(std::move(AddLazyFor)),
525 TypeMap(Set), GValMaterializer(*
this), LValMaterializer(*
this),
526 SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
529 IndirectSymbolMCID(Mapper.registerAlternateMappingContext(
530 IndirectSymbolValueMap, &LValMaterializer)) {
531 ValueMap.
getMDMap() = std::move(SharedMDs);
534 if (IsPerformingImport)
535 prepareCompileUnitsForImport();
537 ~IRLinker() { SharedMDs = std::move(*ValueMap.
getMDMap()); }
540 Value *materialize(
Value *V,
bool ForIndirectSymbol);
558 ConflictGV->setName(Name);
559 assert(ConflictGV->getName() != Name &&
"forceRenaming didn't work");
565 Value *GlobalValueMaterializer::materialize(
Value *SGV) {
566 return TheIRLinker.materialize(SGV,
false);
569 Value *LocalValueMaterializer::materialize(
Value *SGV) {
570 return TheIRLinker.materialize(SGV,
true);
573 Value *IRLinker::materialize(
Value *V,
bool ForIndirectSymbol) {
591 if (
auto *
F = dyn_cast<Function>(New)) {
592 if (!
F->isDeclaration())
594 }
else if (
auto *V = dyn_cast<GlobalVariable>(New)) {
595 if (V->hasInitializer() || V->hasAppendingLinkage())
598 auto *IS = cast<GlobalIndirectSymbol>(New);
599 if (IS->getIndirectSymbol())
614 if (ForIndirectSymbol || shouldLink(New, *SGV))
615 setError(linkGlobalValueBody(*New, *SGV));
660 F->copyAttributesFrom(SF);
661 F->setAttributes(mapAttributeTypes(
F->getContext(),
F->getAttributes()));
673 if (isa<GlobalAlias>(SGIS))
686 bool ForDefinition) {
688 if (
auto *SGVar = dyn_cast<GlobalVariable>(SGV)) {
689 NewGV = copyGlobalVariableProto(SGVar);
690 }
else if (
auto *SF = dyn_cast<Function>(SGV)) {
691 NewGV = copyFunctionProto(SF);
694 NewGV = copyGlobalIndirectSymbolProto(cast<GlobalIndirectSymbol>(SGV));
714 if (
auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
717 NewGO->copyMetadata(cast<GlobalObject>(SGV), 0);
723 if (
auto *NewF = dyn_cast<Function>(NewGV)) {
724 NewF->setPersonalityFn(
nullptr);
725 NewF->setPrefixData(
nullptr);
726 NewF->setPrologueData(
nullptr);
733 size_t DotPos = Name.
rfind(
'.');
735 !isdigit(static_cast<unsigned char>(Name[DotPos + 1])))
744 void IRLinker::computeTypeMapping() {
758 TypeMap.addTypeMapping(DAT->
getElementType(), SAT->getElementType());
763 if (DGV->getType() == SGV.
getType()) {
772 TypeMap.addTypeMapping(DGV->getType(), SGV.
getType());
777 TypeMap.addTypeMapping(DGV->getType(), SGV.
getType());
783 std::vector<StructType *> Types = SrcM->getIdentifiedStructTypes();
788 if (TypeMap.DstStructTypesSet.hasType(
ST)) {
797 if (STTypePrefix.size()==
ST->getName().size())
801 StructType *DST = DstM.getTypeByName(STTypePrefix);
822 if (TypeMap.DstStructTypesSet.hasType(DST))
823 TypeMap.addTypeMapping(DST,
ST);
828 TypeMap.linkDefinedTypeBodies();
833 unsigned NumElements = cast<ArrayType>(C->
getType())->getNumElements();
835 for (
unsigned i = 0; i != NumElements; ++i)
851 bool IsNewStructor =
false;
852 bool IsOldStructor =
false;
853 if (Name ==
"llvm.global_ctors" || Name ==
"llvm.global_dtors") {
854 if (cast<StructType>(EltTy)->getNumElements() == 3)
855 IsNewStructor =
true;
857 IsOldStructor =
true;
862 auto &
ST = *cast<StructType>(EltTy);
863 Type *Tys[3] = {
ST.getElementType(0),
ST.getElementType(1), VoidPtrTy};
867 uint64_t DstNumElements = 0;
874 "Linking globals named '" + SrcGV->
getName() +
875 "': can only link appending global with another appending " 880 return stringErr(
"Appending variables with different element types!");
882 return stringErr(
"Appending variables linked with different const'ness!");
886 "Appending variables with different alignment need to be linked!");
890 "Appending variables with different visibility need to be linked!");
894 "Appending variables with different unnamed_addr need to be linked!");
898 "Appending variables with different section name need to be linked!");
911 return !shouldLink(DGV, *
Key);
913 SrcElements.
erase(It, SrcElements.
end());
915 uint64_t NewSize = DstNumElements + SrcElements.
size();
929 Mapper.scheduleMapAppendingVariable(*NG,
931 IsOldStructor, SrcElements);
936 RAUWWorklist.push_back(
955 bool LazilyAdded =
false;
956 AddLazyFor(SGV, [
this, &LazilyAdded](
GlobalValue &GV) {
964 bool ForIndirectSymbol) {
967 bool ShouldLink = shouldLink(DGV, *SGV);
973 return cast<Constant>(
I->second);
975 I = IndirectSymbolValueMap.find(SGV);
976 if (
I != IndirectSymbolValueMap.end())
977 return cast<Constant>(
I->second);
980 if (!ShouldLink && ForIndirectSymbol)
986 return linkAppendingVarProto(cast_or_null<GlobalVariable>(DGV),
987 cast<GlobalVariable>(SGV));
990 if (DGV && !ShouldLink) {
996 if (DoneLinkingBodies)
999 NewGV = copyGlobalValueProto(SGV, ShouldLink || ForIndirectSymbol);
1000 if (ShouldLink || !ForIndirectSymbol)
1007 if (
Function *
F = dyn_cast<Function>(NewGV))
1009 NewGV = Remangled.getValue();
1011 if (ShouldLink || ForIndirectSymbol) {
1013 if (
auto *GO = dyn_cast<GlobalObject>(NewGV)) {
1014 Comdat *
DC = DstM.getOrInsertComdat(
SC->getName());
1021 if (!ShouldLink && ForIndirectSymbol)
1030 if (DGV && NewGV != SGV) {
1032 NewGV, TypeMap.get(SGV->
getType()));
1035 if (DGV && NewGV != DGV) {
1039 RAUWWorklist.push_back(std::make_pair(
1080 Mapper.scheduleRemapFunction(Dst);
1087 IndirectSymbolMCID);
1091 if (
auto *
F = dyn_cast<Function>(&Src))
1092 return linkFunctionBody(cast<Function>(Dst), *
F);
1093 if (
auto *GVar = dyn_cast<GlobalVariable>(&Src)) {
1094 linkGlobalVariable(cast<GlobalVariable>(Dst), *GVar);
1097 linkIndirectSymbolBody(cast<GlobalIndirectSymbol>(Dst), cast<GlobalIndirectSymbol>(Src));
1101 void IRLinker::flushRAUWWorklist() {
1102 for (
const auto &Elem : RAUWWorklist) {
1105 std::tie(Old, New) = Elem;
1110 RAUWWorklist.clear();
1113 void IRLinker::prepareCompileUnitsForImport() {
1114 NamedMDNode *SrcCompileUnits = SrcM->getNamedMetadata(
"llvm.dbg.cu");
1115 if (!SrcCompileUnits)
1121 auto *
CU = cast<DICompileUnit>(SrcCompileUnits->
getOperand(
I));
1122 assert(
CU &&
"Expected valid compile unit");
1130 ValueMap.
MD()[
CU->getRawRetainedTypes()].reset(
nullptr);
1140 ValueMap.
MD()[
CU->getRawGlobalVariables()].reset(
nullptr);
1155 bool ReplaceImportedEntities =
false;
1156 for (
auto *
IE :
CU->getImportedEntities()) {
1158 assert(Scope &&
"Invalid Scope encoding!");
1159 if (isa<DILocalScope>(Scope))
1162 ReplaceImportedEntities =
true;
1164 if (ReplaceImportedEntities) {
1165 if (!AllImportedModules.
empty())
1169 AllImportedModules.
end())));
1173 ValueMap.
MD()[
CU->getRawImportedEntities()].reset(
nullptr);
1179 void IRLinker::linkNamedMDNodes() {
1180 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1181 for (
const NamedMDNode &NMD : SrcM->named_metadata()) {
1183 if (&NMD == SrcModFlags)
1185 NamedMDNode *DestNMD = DstM.getOrInsertNamedMetadata(NMD.getName());
1187 for (
const MDNode *
Op : NMD.operands())
1193 Error IRLinker::linkModuleFlagsMetadata() {
1195 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1201 NamedMDNode *DstModFlags = DstM.getOrInsertModuleFlagsMetadata();
1220 Flags[
ID] = std::make_pair(Op,
I);
1229 mdconst::extract<ConstantInt>(SrcOp->
getOperand(0));
1233 std::tie(DstOp, DstIndex) = Flags.
lookup(ID);
1234 unsigned SrcBehaviorValue = SrcBehavior->
getZExtValue();
1255 mdconst::extract<ConstantInt>(DstOp->getOperand(0));
1256 unsigned DstBehaviorValue = DstBehavior->
getZExtValue();
1258 auto overrideDstValue = [&]() {
1260 Flags[
ID].first = SrcOp;
1267 SrcOp->
getOperand(2) != DstOp->getOperand(2))
1268 return stringErr(
"linking module flags '" + ID->getString() +
1269 "': IDs have conflicting override values in '" +
1270 SrcM->getModuleIdentifier() +
"' and '" +
1271 DstM.getModuleIdentifier() +
"'");
1280 if (SrcBehaviorValue != DstBehaviorValue) {
1281 bool MaxAndWarn = (SrcBehaviorValue ==
Module::Max &&
1286 return stringErr(
"linking module flags '" + ID->getString() +
1287 "': IDs have conflicting behaviors in '" +
1288 SrcM->getModuleIdentifier() +
"' and '" +
1289 DstM.getModuleIdentifier() +
"'");
1292 auto replaceDstValue = [&](
MDNode *New) {
1293 Metadata *FlagOps[] = {DstOp->getOperand(0),
ID, New};
1303 SrcOp->
getOperand(2) != DstOp->getOperand(2)) {
1306 <<
"linking module flags '" << ID->getString()
1307 <<
"': IDs have conflicting values ('" << *SrcOp->
getOperand(2)
1308 <<
"' from " << SrcM->getModuleIdentifier() <<
" with '" 1309 << *DstOp->getOperand(2) <<
"' from " << DstM.getModuleIdentifier()
1317 mdconst::extract<ConstantInt>(DstOp->getOperand(2));
1319 mdconst::extract<ConstantInt>(SrcOp->
getOperand(2));
1324 (DstBehaviorValue !=
Module::Max ? SrcOp : DstOp)->getOperand(0),
ID,
1325 (SrcValue->getZExtValue() > DstValue->
getZExtValue() ? SrcOp : DstOp)
1334 switch (SrcBehaviorValue) {
1340 if (SrcOp->
getOperand(2) != DstOp->getOperand(2))
1341 return stringErr(
"linking module flags '" + ID->getString() +
1342 "': IDs have conflicting values in '" +
1343 SrcM->getModuleIdentifier() +
"' and '" +
1344 DstM.getModuleIdentifier() +
"'");
1354 MDNode *DstValue = cast<MDNode>(DstOp->getOperand(2));
1359 MDs.append(SrcValue->op_begin(), SrcValue->op_end());
1361 replaceDstValue(
MDNode::get(DstM.getContext(), MDs));
1366 MDNode *DstValue = cast<MDNode>(DstOp->getOperand(2));
1369 Elts.
insert(SrcValue->op_begin(), SrcValue->op_end());
1380 for (
unsigned I = 0,
E = Requirements.
size();
I !=
E; ++
I) {
1381 MDNode *Requirement = Requirements[
I];
1387 return stringErr(
"linking module flags '" + Flag->
getString() +
1388 "': does not have the required value");
1399 return ".text\n.balign 2\n.thumb\n" + InlineAsm;
1401 return ".text\n.balign 4\n.arm\n" + InlineAsm;
1405 Error IRLinker::run() {
1407 if (SrcM->getMaterializer())
1408 if (
Error Err = SrcM->getMaterializer()->materializeMetadata())
1413 if (DstM.getDataLayout().isDefault())
1414 DstM.setDataLayout(SrcM->getDataLayout());
1416 if (SrcM->getDataLayout() != DstM.getDataLayout()) {
1417 emitWarning(
"Linking two modules of different data layouts: '" +
1418 SrcM->getModuleIdentifier() +
"' is '" +
1419 SrcM->getDataLayoutStr() +
"' whereas '" +
1420 DstM.getModuleIdentifier() +
"' is '" +
1421 DstM.getDataLayoutStr() +
"'\n");
1425 if (DstM.getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
1426 DstM.setTargetTriple(SrcM->getTargetTriple());
1428 Triple SrcTriple(SrcM->getTargetTriple()), DstTriple(DstM.getTargetTriple());
1430 if (!SrcM->getTargetTriple().empty()&&
1431 !SrcTriple.isCompatibleWith(DstTriple))
1432 emitWarning(
"Linking two modules of different target triples: " +
1433 SrcM->getModuleIdentifier() +
"' is '" +
1434 SrcM->getTargetTriple() +
"' whereas '" +
1435 DstM.getModuleIdentifier() +
"' is '" + DstM.getTargetTriple() +
1438 DstM.setTargetTriple(SrcTriple.merge(DstTriple));
1441 if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) {
1442 std::string SrcModuleInlineAsm =
adjustInlineAsm(SrcM->getModuleInlineAsm(),
1444 if (DstM.getModuleInlineAsm().empty())
1445 DstM.setModuleInlineAsm(SrcModuleInlineAsm);
1447 DstM.setModuleInlineAsm(DstM.getModuleInlineAsm() +
"\n" +
1448 SrcModuleInlineAsm);
1452 computeTypeMapping();
1455 while (!Worklist.empty()) {
1457 Worklist.pop_back();
1461 IndirectSymbolValueMap.find(GV) != IndirectSymbolValueMap.end())
1465 Mapper.mapValue(*GV);
1467 return std::move(*FoundError);
1468 flushRAUWWorklist();
1473 DoneLinkingBodies =
true;
1482 return linkModuleFlagsMetadata();
1486 : ETypes(E), IsPacked(P) {}
1489 : ETypes(ST->elements()), IsPacked(ST->isPacked()) {}
1499 StructType *IRMover::StructTypeKeyInfo::getEmptyKey() {
1503 StructType *IRMover::StructTypeKeyInfo::getTombstoneKey() {
1507 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const KeyTy &
Key) {
1512 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const StructType *
ST) {
1513 return getHashValue(
KeyTy(ST));
1518 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1520 return LHS ==
KeyTy(RHS);
1525 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1532 NonOpaqueStructTypes.insert(Ty);
1537 NonOpaqueStructTypes.insert(Ty);
1538 bool Removed = OpaqueStructTypes.erase(Ty);
1545 OpaqueStructTypes.insert(Ty);
1552 auto I = NonOpaqueStructTypes.find_as(Key);
1553 return I == NonOpaqueStructTypes.end() ? nullptr : *
I;
1558 return OpaqueStructTypes.count(Ty);
1559 auto I = NonOpaqueStructTypes.find(Ty);
1560 return I == NonOpaqueStructTypes.end() ?
false : *
I == Ty;
1565 StructTypes.
run(M,
false);
1575 for (
auto *MD : StructTypes.getVisitedMetadata()) {
1576 SharedMDs[MD].reset(const_cast<MDNode *>(MD));
1583 bool IsPerformingImport) {
1584 IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
1585 std::move(Src), ValuesToLink, std::move(AddLazyFor),
1586 IsPerformingImport);
1587 Error E = TheIRLinker.run();
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface ...
bool isDeclarationForLinker() const
StringRef getSection() const
Get the custom section of this global if it has one.
unsigned getAlignment() const
reference emplace_back(ArgTypes &&... Args)
ThreadLocalMode getThreadLocalMode() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
bool hasLocalLinkage() const
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
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.
KeyTy(ArrayRef< Type *> E, bool P)
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
ArrayRef< Type * > ETypes
void addOpaque(StructType *Ty)
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
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. ...
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...
Externally visible function.
LLVMContext & getContext() const
All values hold a context through their type.
bool hasPrologueData() const
Check whether this function has prologue data.
Context for (re-)mapping values (and metadata).
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
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
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.
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.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
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.
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
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.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Constant * getPrefixData() const
Get the prefix data associated with this function.
op_iterator op_begin() const
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
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)
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.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Class to represent array types.
Type * getValueAsType() const
Return the attribute's value as a Type.
iterator find(const KeyT &Val)
iterator begin()
Get an iterator to the beginning of the SetVector.
bool operator!=(const KeyTy &that) const
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)...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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 setBody(ArrayRef< Type *> Elements, bool isPacked=false)
Specify a body for an opaque identified type.
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.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
bool hasAppendingLinkage() const
StringRef getString() const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
ExternalWeak linkage description.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
This is a class that can be implemented by clients to materialize Values on demand.
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.
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
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 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.
bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
Optional< MDMapT > & getMDMap()
void splice(iterator where, iplist_impl &L2)
unsigned getAddressSpace() const
StringRef getName() const
Return the name for this struct type if it has an identity.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
Error materialize()
Make sure this GlobalValue is fully read.
void addNonOpaque(StructType *Ty)
const Constant * stripPointerCasts() const
iterator erase(const_iterator CI)
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
LLVM_NODISCARD char back() const
back - Get the last character in the string.
#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.
static void getArrayElements(const Constant *C, SmallVectorImpl< Constant *> &Dest)
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.
void setSelectionKind(SelectionKind Val)
16: SIMD 'packed' format, or other vector type
void dropTriviallyDeadConstantArrays()
Destroy ConstantArrays in LLVMContext if they are not used.
void run(const Module &M, bool onlyNamed)
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.
bool hasGlobalUnnamedAddr() const
void print(DiagnosticPrinter &DP) const override
Print using the given DP a user-friendly message.
bool operator==(const KeyTy &that) const
void setLinkage(LinkageTypes LT)
Uses the specified value, regardless of the behavior or value of the other module.
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
unsigned getNumAttrSets() 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, Instruction, BasicBlock) that are not in the value map.
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.
LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
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.
LLVM_NODISCARD bool empty() const
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
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...
LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
void setPrologueData(Constant *PrologueData)
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Rename collisions when linking (static functions).
const Constant * getIndirectSymbol() const
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< void(GlobalValue &)> ValueAdder
A raw_ostream that writes to an std::string.
StructType * findNonOpaque(ArrayRef< Type *> ETypes, bool IsPacked)
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. ...
Type * getElementType() const
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
void setPersonalityFn(Constant *Fn)
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...
Function Alias Analysis false
static IntegerType * getInt8Ty(LLVMContext &C)
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...
void setPrefixData(Constant *PrefixData)