Go to the documentation of this file.
59 : DstStructTypesSet(DstStructTypesSet) {}
64 void addTypeMapping(
Type *DstTy,
Type *SrcTy);
68 void linkDefinedTypeBodies();
78 return cast<FunctionType>(
get((
Type *)
T));
82 Type *remapType(
Type *SrcTy)
override {
return get(SrcTy); }
84 bool areTypesIsomorphic(
Type *DstTy,
Type *SrcTy);
88 void TypeMapTy::addTypeMapping(
Type *DstTy,
Type *SrcTy) {
89 assert(SpeculativeTypes.empty());
90 assert(SpeculativeDstOpaqueTypes.empty());
94 if (!areTypesIsomorphic(DstTy, SrcTy)) {
97 for (
Type *Ty : SpeculativeTypes)
98 MappedTypes.
erase(Ty);
100 SrcDefinitionsToResolve.
resize(SrcDefinitionsToResolve.size() -
101 SpeculativeDstOpaqueTypes.size());
102 for (
StructType *Ty : SpeculativeDstOpaqueTypes)
103 DstResolvedOpaqueTypes.
erase(Ty);
111 for (
Type *Ty : SpeculativeTypes)
112 if (
auto *STy = dyn_cast<StructType>(Ty))
116 SpeculativeTypes.clear();
117 SpeculativeDstOpaqueTypes.clear();
122 bool TypeMapTy::areTypesIsomorphic(
Type *DstTy,
Type *SrcTy) {
128 Type *&Entry = MappedTypes[SrcTy];
130 return Entry == DstTy;
134 if (DstTy == SrcTy) {
142 if (
StructType *SSTy = dyn_cast<StructType>(SrcTy)) {
144 if (SSTy->isOpaque()) {
146 SpeculativeTypes.push_back(SrcTy);
154 if (cast<StructType>(DstTy)->isOpaque()) {
156 if (!DstResolvedOpaqueTypes.
insert(cast<StructType>(DstTy)).second)
158 SrcDefinitionsToResolve.push_back(SSTy);
159 SpeculativeTypes.push_back(SrcTy);
160 SpeculativeDstOpaqueTypes.push_back(cast<StructType>(DstTy));
171 if (isa<IntegerType>(DstTy))
173 if (
PointerType *PT = dyn_cast<PointerType>(DstTy)) {
174 if (PT->getAddressSpace() != cast<PointerType>(SrcTy)->getAddressSpace())
176 }
else if (
FunctionType *FT = dyn_cast<FunctionType>(DstTy)) {
177 if (FT->isVarArg() != cast<FunctionType>(SrcTy)->isVarArg())
179 }
else if (
StructType *DSTy = dyn_cast<StructType>(DstTy)) {
181 if (DSTy->isLiteral() != SSTy->
isLiteral() ||
182 DSTy->isPacked() != SSTy->
isPacked())
184 }
else if (
auto *DArrTy = dyn_cast<ArrayType>(DstTy)) {
185 if (DArrTy->getNumElements() != cast<ArrayType>(SrcTy)->getNumElements())
187 }
else if (
auto *DVecTy = dyn_cast<VectorType>(DstTy)) {
188 if (DVecTy->getElementCount() != cast<VectorType>(SrcTy)->getElementCount())
195 SpeculativeTypes.push_back(SrcTy);
206 void TypeMapTy::linkDefinedTypeBodies() {
208 for (
StructType *SrcSTy : SrcDefinitionsToResolve) {
209 StructType *DstSTy = cast<StructType>(MappedTypes[SrcSTy]);
213 Elements.
resize(SrcSTy->getNumElements());
214 for (
unsigned I = 0,
E = Elements.size();
I !=
E; ++
I)
215 Elements[
I] =
get(SrcSTy->getElementType(
I));
217 DstSTy->
setBody(Elements, SrcSTy->isPacked());
220 SrcDefinitionsToResolve.clear();
221 DstResolvedOpaqueTypes.
clear();
240 return get(Ty, Visited);
245 Type **Entry = &MappedTypes[Ty];
250 bool IsUniqued = !isa<StructType>(Ty) || cast<StructType>(Ty)->isLiteral();
254 for (
auto &Pair : MappedTypes) {
255 assert(!(Pair.first != Ty && Pair.second == Ty) &&
256 "mapping to a source type");
260 if (!Visited.
insert(cast<StructType>(Ty)).second) {
276 bool AnyChange =
false;
284 Entry = &MappedTypes[Ty];
286 if (
auto *DTy = dyn_cast<StructType>(*Entry)) {
288 auto *STy = cast<StructType>(Ty);
289 finishType(DTy, STy, ElementTypes);
297 if (!AnyChange && IsUniqued)
306 cast<ArrayType>(Ty)->getNumElements());
310 cast<VectorType>(Ty)->getElementCount());
317 cast<FunctionType>(Ty)->isVarArg());
319 auto *STy = cast<StructType>(Ty);
333 return *Entry = OldT;
342 finishType(DTy, STy, ElementTypes);
364 IRLinker &TheIRLinker;
367 GlobalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
372 IRLinker &TheIRLinker;
375 LocalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
386 std::unique_ptr<Module> SrcM;
392 GlobalValueMaterializer GValMaterializer;
393 LocalValueMaterializer LValMaterializer;
406 std::vector<GlobalValue *> Worklist;
407 std::vector<std::pair<GlobalValue *, Value*>> RAUWWorklist;
410 if (ValuesToLink.
insert(GV).second)
411 Worklist.push_back(GV);
419 bool IsPerformingImport;
424 bool DoneLinkingBodies =
false;
442 unsigned IndirectSymbolMCID;
448 void emitWarning(
const Twine &Message) {
472 if (
auto *FDGV = dyn_cast<Function>(DGV))
473 if (FDGV->isIntrinsic())
474 if (
const auto *FSrcGV = dyn_cast<Function>(SrcGV))
475 if (FDGV->getFunctionType() != TypeMap.get(FSrcGV->getFunctionType()))
482 void computeTypeMapping();
494 bool ForIndirectSymbol);
496 Error linkModuleFlagsMetadata();
520 void flushRAUWWorklist();
525 void prepareCompileUnitsForImport();
526 void linkNamedMDNodes();
529 IRLinker(
Module &DstM, MDMapT &SharedMDs,
533 : DstM(DstM), SrcM(
std::
move(SrcM)), AddLazyFor(
std::
move(AddLazyFor)),
534 TypeMap(Set), GValMaterializer(*
this), LValMaterializer(*
this),
535 SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
537 &TypeMap, &GValMaterializer),
538 IndirectSymbolMCID(Mapper.registerAlternateMappingContext(
539 IndirectSymbolValueMap, &LValMaterializer)) {
543 if (IsPerformingImport)
544 prepareCompileUnitsForImport();
549 Value *materialize(
Value *V,
bool ForIndirectSymbol);
567 ConflictGV->setName(
Name);
568 assert(ConflictGV->getName() !=
Name &&
"forceRenaming didn't work");
574 Value *GlobalValueMaterializer::materialize(
Value *SGV) {
575 return TheIRLinker.materialize(SGV,
false);
578 Value *LocalValueMaterializer::materialize(
Value *SGV) {
579 return TheIRLinker.materialize(SGV,
true);
582 Value *IRLinker::materialize(
Value *V,
bool ForIndirectSymbol) {
583 auto *SGV = dyn_cast<GlobalValue>(V);
591 if (SGV->getParent() != &DstM && SGV->getParent() != SrcM.get())
607 if (
auto *
F = dyn_cast<Function>(New)) {
608 if (!
F->isDeclaration())
610 }
else if (
auto *V = dyn_cast<GlobalVariable>(New)) {
611 if (V->hasInitializer() || V->hasAppendingLinkage())
613 }
else if (
auto *GA = dyn_cast<GlobalAlias>(New)) {
614 if (GA->getAliasee())
616 }
else if (
auto *GI = dyn_cast<GlobalIFunc>(New)) {
617 if (GI->getResolver())
632 (!ForIndirectSymbol && IndirectSymbolValueMap.
lookup(SGV) == New))
635 if (ForIndirectSymbol || shouldLink(New, *SGV))
636 setError(linkGlobalValueBody(*New, *SGV));
659 for (
unsigned i = 0;
i <
Attrs.getNumAttrSets(); ++
i) {
660 for (
int AttrIdx = Attribute::FirstTypeAttr;
661 AttrIdx <= Attribute::LastTypeAttr; AttrIdx++) {
663 if (
Attrs.hasAttributeAtIndex(
i, TypedAttr)) {
666 Attrs =
Attrs.replaceAttributeTypeAtIndex(
C,
i, TypedAttr,
684 F->copyAttributesFrom(SF);
685 F->setAttributes(mapAttributeTypes(
F->getContext(),
F->getAttributes()));
696 if (
auto *GA = dyn_cast<GlobalAlias>(SGV)) {
700 DGA->copyAttributesFrom(GA);
704 if (
auto *GI = dyn_cast<GlobalIFunc>(SGV)) {
707 SGV->
getName(),
nullptr, &DstM);
708 DGI->copyAttributesFrom(GI);
716 bool ForDefinition) {
718 if (
auto *SGVar = dyn_cast<GlobalVariable>(SGV)) {
719 NewGV = copyGlobalVariableProto(SGVar);
720 }
else if (
auto *SF = dyn_cast<Function>(SGV)) {
721 NewGV = copyFunctionProto(SF);
724 NewGV = copyIndirectSymbolProto(SGV);
744 if (
auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
747 NewGO->copyMetadata(cast<GlobalObject>(SGV), 0);
753 if (
auto *NewF = dyn_cast<Function>(NewGV)) {
754 NewF->setPersonalityFn(
nullptr);
755 NewF->setPrefixData(
nullptr);
756 NewF->setPrologueData(
nullptr);
763 size_t DotPos =
Name.rfind(
'.');
765 !isdigit(
static_cast<unsigned char>(
Name[DotPos + 1])))
767 :
Name.substr(0, DotPos);
774 void IRLinker::computeTypeMapping() {
813 std::vector<StructType *> Types = SrcM->getIdentifiedStructTypes();
818 if (TypeMap.DstStructTypesSet.hasType(
ST)) {
827 if (STTypePrefix.size() ==
ST->getName().size())
852 if (TypeMap.DstStructTypesSet.hasType(DST))
853 TypeMap.addTypeMapping(DST,
ST);
858 TypeMap.linkDefinedTypeBodies();
863 unsigned NumElements = cast<ArrayType>(
C->getType())->getNumElements();
865 for (
unsigned i = 0;
i != NumElements; ++
i)
866 Dest.push_back(
C->getAggregateElement(
i));
877 "Linking globals named '" + SrcGV->
getName() +
878 "': can only link appending global with another appending "
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!");
913 bool IsNewStructor =
false;
914 bool IsOldStructor =
false;
915 if (
Name ==
"llvm.global_ctors" ||
Name ==
"llvm.global_dtors") {
916 if (cast<StructType>(EltTy)->getNumElements() == 3)
917 IsNewStructor =
true;
919 IsOldStructor =
true;
924 auto &
ST = *cast<StructType>(EltTy);
925 Type *Tys[3] = {
ST.getElementType(0),
ST.getElementType(1), VoidPtrTy};
936 return stringErr(
"Appending variables with different element types!");
945 dyn_cast<GlobalValue>(
E->getAggregateElement(2)->stripPointerCasts());
949 return !shouldLink(DGV, *
Key);
952 uint64_t NewSize = DstNumElements + SrcElements.size();
969 IsOldStructor, SrcElements);
974 RAUWWorklist.push_back(
993 bool LazilyAdded =
false;
995 AddLazyFor(SGV, [
this, &LazilyAdded](
GlobalValue &GV) {
1003 bool ForIndirectSymbol) {
1006 bool ShouldLink = shouldLink(DGV, *SGV);
1012 return cast<Constant>(
I->second);
1014 I = IndirectSymbolValueMap.
find(SGV);
1015 if (
I != IndirectSymbolValueMap.
end())
1016 return cast<Constant>(
I->second);
1019 if (!ShouldLink && ForIndirectSymbol)
1024 return linkAppendingVarProto(cast_or_null<GlobalVariable>(DGV),
1025 cast<GlobalVariable>(SGV));
1027 bool NeedsRenaming =
false;
1029 if (DGV && !ShouldLink) {
1035 if (DoneLinkingBodies)
1038 NewGV = copyGlobalValueProto(SGV, ShouldLink || ForIndirectSymbol);
1039 if (ShouldLink || !ForIndirectSymbol)
1040 NeedsRenaming =
true;
1046 if (
Function *
F = dyn_cast<Function>(NewGV))
1050 NeedsRenaming =
false;
1056 if (ShouldLink || ForIndirectSymbol) {
1058 if (
auto *GO = dyn_cast<GlobalObject>(NewGV)) {
1060 DC->setSelectionKind(
SC->getSelectionKind());
1066 if (!ShouldLink && ForIndirectSymbol)
1075 if (DGV && NewGV != SGV) {
1077 NewGV, TypeMap.get(SGV->
getType()));
1080 if (DGV && NewGV != DGV) {
1084 RAUWWorklist.push_back(std::make_pair(
1103 assert(Dst.isDeclaration() && !Src.isDeclaration());
1106 if (
Error Err = Src.materialize())
1110 if (Src.hasPrefixData())
1111 Dst.setPrefixData(Src.getPrefixData());
1112 if (Src.hasPrologueData())
1113 Dst.setPrologueData(Src.getPrologueData());
1114 if (Src.hasPersonalityFn())
1115 Dst.setPersonalityFn(Src.getPersonalityFn());
1118 Dst.copyMetadata(&Src, 0);
1121 Dst.stealArgumentListFrom(Src);
1122 Dst.getBasicBlockList().splice(Dst.end(), Src.getBasicBlockList());
1138 if (
auto *
F = dyn_cast<Function>(&Src))
1139 return linkFunctionBody(cast<Function>(Dst), *
F);
1140 if (
auto *GVar = dyn_cast<GlobalVariable>(&Src)) {
1141 linkGlobalVariable(cast<GlobalVariable>(Dst), *GVar);
1144 if (
auto *GA = dyn_cast<GlobalAlias>(&Src)) {
1145 linkAliasAliasee(cast<GlobalAlias>(Dst), *GA);
1148 linkIFuncResolver(cast<GlobalIFunc>(Dst), cast<GlobalIFunc>(Src));
1152 void IRLinker::flushRAUWWorklist() {
1153 for (
const auto &Elem : RAUWWorklist) {
1156 std::tie(Old, New) = Elem;
1161 RAUWWorklist.clear();
1164 void IRLinker::prepareCompileUnitsForImport() {
1165 NamedMDNode *SrcCompileUnits = SrcM->getNamedMetadata(
"llvm.dbg.cu");
1166 if (!SrcCompileUnits)
1172 auto *
CU = cast<DICompileUnit>(SrcCompileUnits->
getOperand(
I));
1173 assert(
CU &&
"Expected valid compile unit");
1177 CU->replaceEnumTypes(
nullptr);
1178 CU->replaceMacros(
nullptr);
1179 CU->replaceRetainedTypes(
nullptr);
1190 CU->replaceGlobalVariables(
nullptr);
1205 bool ReplaceImportedEntities =
false;
1206 for (
auto *
IE :
CU->getImportedEntities()) {
1209 if (isa<DILocalScope>(
Scope))
1212 ReplaceImportedEntities =
true;
1214 if (ReplaceImportedEntities) {
1215 if (!AllImportedModules.empty())
1219 AllImportedModules.end())));
1223 CU->replaceImportedEntities(
nullptr);
1229 void IRLinker::linkNamedMDNodes() {
1230 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1231 for (
const NamedMDNode &NMD : SrcM->named_metadata()) {
1233 if (&NMD == SrcModFlags)
1239 emitWarning(
"Pseudo-probe ignored: source module '" +
1240 SrcM->getModuleIdentifier() +
1241 "' is compiled with -fpseudo-probe-for-profiling while "
1242 "destination module '" +
1248 for (
const MDNode *
Op : NMD.operands())
1254 Error IRLinker::linkModuleFlagsMetadata() {
1256 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1281 mdconst::extract<ConstantInt>(
Op->getOperand(0))->getZExtValue();
1285 Requirements.
insert(cast<MDNode>(
Op->getOperand(2)));
1289 Flags[
ID] = std::make_pair(
Op,
I);
1298 mdconst::extract<ConstantInt>(
SrcOp->getOperand(0));
1303 unsigned SrcBehaviorValue = SrcBehavior->
getZExtValue();
1310 if (Requirements.
insert(cast<MDNode>(
SrcOp->getOperand(2)))) {
1329 mdconst::extract<ConstantInt>(
DstOp->getOperand(0));
1330 unsigned DstBehaviorValue = DstBehavior->
getZExtValue();
1332 auto overrideDstValue = [&]() {
1341 SrcOp->getOperand(2) !=
DstOp->getOperand(2))
1342 return stringErr(
"linking module flags '" +
ID->getString() +
1343 "': IDs have conflicting override values in '" +
1344 SrcM->getModuleIdentifier() +
"' and '" +
1354 if (SrcBehaviorValue != DstBehaviorValue) {
1355 bool MinAndWarn = (SrcBehaviorValue ==
Module::Min &&
1359 bool MaxAndWarn = (SrcBehaviorValue ==
Module::Max &&
1363 if (!(MaxAndWarn || MinAndWarn))
1364 return stringErr(
"linking module flags '" +
ID->getString() +
1365 "': IDs have conflicting behaviors in '" +
1366 SrcM->getModuleIdentifier() +
"' and '" +
1370 auto ensureDistinctOp = [&](
MDNode *DstValue) {
1371 assert(isa<MDTuple>(DstValue) &&
1372 "Expected MDTuple when appending module flags");
1373 if (DstValue->isDistinct())
1374 return dyn_cast<MDTuple>(DstValue);
1390 SrcOp->getOperand(2) !=
DstOp->getOperand(2)) {
1393 <<
"linking module flags '" <<
ID->getString()
1394 <<
"': IDs have conflicting values ('" << *
SrcOp->getOperand(2)
1395 <<
"' from " << SrcM->getModuleIdentifier() <<
" with '"
1404 mdconst::extract<ConstantInt>(
DstOp->getOperand(2));
1406 mdconst::extract<ConstantInt>(
SrcOp->getOperand(2));
1423 mdconst::extract<ConstantInt>(
DstOp->getOperand(2));
1425 mdconst::extract<ConstantInt>(
SrcOp->getOperand(2));
1440 switch (SrcBehaviorValue) {
1446 if (
SrcOp->getOperand(2) !=
DstOp->getOperand(2))
1447 return stringErr(
"linking module flags '" +
ID->getString() +
1448 "': IDs have conflicting values in '" +
1449 SrcM->getModuleIdentifier() +
"' and '" +
1460 MDTuple *DstValue = ensureDistinctOp(cast<MDNode>(
DstOp->getOperand(2)));
1461 MDNode *SrcValue = cast<MDNode>(
SrcOp->getOperand(2));
1462 for (
const auto &
O : SrcValue->
operands())
1468 MDTuple *DstValue = ensureDistinctOp(cast<MDNode>(
DstOp->getOperand(2)));
1469 MDNode *SrcValue = cast<MDNode>(
SrcOp->getOperand(2));
1482 for (
auto Idx : Mins) {
1486 ConstantInt *V = mdconst::extract<ConstantInt>(
Op->getOperand(2));
1488 Op->getOperand(0),
ID,
1495 for (
unsigned I = 0,
E = Requirements.
size();
I !=
E; ++
I) {
1501 if (!
Op ||
Op->getOperand(2) != ReqValue)
1502 return stringErr(
"linking module flags '" +
Flag->getString() +
1503 "': does not have the required value");
1514 return ".text\n.balign 2\n.thumb\n" +
InlineAsm;
1516 return ".text\n.balign 4\n.arm\n" +
InlineAsm;
1522 if (SrcM->getMaterializer())
1523 if (
Error Err = SrcM->getMaterializer()->materializeMetadata())
1532 if (DstM.
getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
1542 bool EnableDLWarning =
true;
1543 bool EnableTripleWarning =
true;
1544 if (SrcTriple.isNVPTX() && DstTriple.isNVPTX()) {
1545 std::string ModuleId = SrcM->getModuleIdentifier();
1547 bool SrcIsLibDevice =
1549 bool SrcHasLibDeviceDL =
1550 (SrcM->getDataLayoutStr().empty() ||
1551 SrcM->getDataLayoutStr() ==
"e-i64:64-v16:16-v32:32-n16:32:64");
1555 bool SrcHasLibDeviceTriple = (SrcTriple.getVendor() ==
Triple::NVIDIA &&
1556 SrcTriple.getOSName() ==
"gpulibs") ||
1557 (SrcTriple.getVendorName() ==
"unknown" &&
1558 SrcTriple.getOSName() ==
"unknown");
1559 EnableTripleWarning = !(SrcIsLibDevice && SrcHasLibDeviceTriple);
1560 EnableDLWarning = !(SrcIsLibDevice && SrcHasLibDeviceDL);
1563 if (EnableDLWarning && (SrcM->getDataLayout() != DstM.
getDataLayout())) {
1564 emitWarning(
"Linking two modules of different data layouts: '" +
1565 SrcM->getModuleIdentifier() +
"' is '" +
1566 SrcM->getDataLayoutStr() +
"' whereas '" +
1571 if (EnableTripleWarning && !SrcM->getTargetTriple().empty() &&
1572 !SrcTriple.isCompatibleWith(DstTriple))
1573 emitWarning(
"Linking two modules of different target triples: '" +
1574 SrcM->getModuleIdentifier() +
"' is '" +
1575 SrcM->getTargetTriple() +
"' whereas '" +
1582 computeTypeMapping();
1585 while (!Worklist.empty()) {
1587 Worklist.pop_back();
1591 IndirectSymbolValueMap.
find(GV) != IndirectSymbolValueMap.
end())
1598 flushRAUWWorklist();
1603 DoneLinkingBodies =
true;
1611 if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) {
1615 }
else if (IsPerformingImport) {
1620 SmallString<256> S(
".symver ");
1624 DstM.appendModuleInlineAsm(S);
1639 Globals.splice(Globals.end(), Globals, NewGV->getIterator());
1644 return linkModuleFlagsMetadata();
1661 StructType *IRMover::StructTypeKeyInfo::getEmptyKey() {
1665 StructType *IRMover::StructTypeKeyInfo::getTombstoneKey() {
1669 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const KeyTy &
Key) {
1674 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const StructType *
ST) {
1675 return getHashValue(KeyTy(
ST));
1680 if (
RHS == getEmptyKey() ||
RHS == getTombstoneKey())
1682 return LHS == KeyTy(
RHS);
1687 if (
RHS == getEmptyKey() ||
RHS == getTombstoneKey())
1689 return KeyTy(
LHS) == KeyTy(
RHS);
1694 NonOpaqueStructTypes.insert(Ty);
1699 NonOpaqueStructTypes.insert(Ty);
1700 bool Removed = OpaqueStructTypes.erase(Ty);
1707 OpaqueStructTypes.insert(Ty);
1714 auto I = NonOpaqueStructTypes.find_as(
Key);
1715 return I == NonOpaqueStructTypes.end() ? nullptr : *
I;
1720 return OpaqueStructTypes.count(Ty);
1721 auto I = NonOpaqueStructTypes.find(Ty);
1722 return I == NonOpaqueStructTypes.end() ?
false : *
I == Ty;
1727 StructTypes.
run(
M,
false);
1737 for (
auto *MD : StructTypes.getVisitedMetadata()) {
1738 SharedMDs[MD].reset(
const_cast<MDNode *
>(MD));
1745 IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
1747 IsPerformingImport);
1748 Error E = TheIRLinker.run();
Optional< MDMapT > & getMDMap()
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
This is an optimization pass for GlobalISel generic memory operations.
void scheduleMapAppendingVariable(GlobalVariable &GV, Constant *InitPrefix, bool IsOldCtorDtor, ArrayRef< Constant * > NewMembers, unsigned MappingContextID=0)
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
@ Min
Takes the min of the two values, which are required to be integers.
ArrayRef< Type * > ETypes
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false.
StringRef getName() const
Return the name for this struct type if it has an identity.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
unsigned getNumOperands() const
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
unique_function is a type-erasing functor similar to std::function.
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
LinkageTypes getLinkage() const
@ RF_NullMapMissingGlobalValues
Any global values not in value map are mapped to null instead of mapping to self.
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...
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
StructType * findNonOpaque(ArrayRef< Type * > ETypes, bool IsPacked)
A raw_ostream that writes to an std::string.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
size_type size() const
Determine the number of elements in the SetVector.
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
StringRef getSection() const
Get the custom section of this global if it has one.
static constexpr size_t npos
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
static ErrorSuccess success()
Create a success value.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
TypeID getTypeID() const
Return the type id for the type.
Triple - Helper class for working with autoconf configuration names.
bool erase(const KeyT &Val)
void setOperand(unsigned I, MDNode *New)
The instances of the Type class are immutable: once they are created, they are never changed.
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
MDNode * mapMDNode(const MDNode &N)
static StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void addNonOpaque(StructType *Ty)
static StringRef getTypeNamePrefix(StringRef Name)
void scheduleMapGlobalInitializer(GlobalVariable &GV, Constant &Init, unsigned MappingContextID=0)
This is a class that can be implemented by clients to remap types when cloning constants and instruct...
Tagged union holding either a T or a Error.
Class to represent array types.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
std::pair< iterator, bool > insert(const ValueT &V)
@ Override
Uses the specified value, regardless of the behavior or value of the other module.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
static IntegerType * getInt8Ty(LLVMContext &C)
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...
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
bool hasExternalWeakLinkage() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a distinct node.
AddressSpace getAddressSpace(T *V)
@ RF_ReuseAndMutateDistinctMDs
Instruct the remapper to reuse and mutate distinct metadata (remapping them in place) instead of clon...
void addOperand(MDNode *M)
void scheduleRemapFunction(Function &F, unsigned MappingContextID=0)
This is the shared class of boolean and integer constants.
An information struct used to provide DenseMap with the various necessary components for a given valu...
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
uint64_t getNumElements() const
bool hasAppendingLinkage() const
@ Append
Appends the two values, which are required to be metadata nodes.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
KeyTy(ArrayRef< Type * > E, bool P)
(vector float) vec_cmpeq(*A, *B) C
bool operator==(const KeyTy &that) const
bool operator!=(const KeyTy &that) const
ThreadLocalMode getThreadLocalMode() const
ArrayRef< MDOperand > operands() const
constexpr const char * PseudoProbeDescMetadataName
void addOpaque(StructType *Ty)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Error move(std::unique_ptr< Module > Src, ArrayRef< GlobalValue * > ValuesToLink, LazyCallback AddLazyFor, bool IsPerformingImport)
Move in the provide values in ValuesToLink from Src.
Value * mapValue(const Value &V)
void setName(const Twine &Name)
Change the name of the value.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
This is the base abstract class for diagnostic reporting in the backend.
bool hasType(StructType *Ty)
bool hasGlobalUnnamedAddr() const
Interface for custom diagnostic printing.
@ InternalLinkage
Rename collisions when linking (static functions).
ArchType getArch() const
Get the parsed architecture type of this triple.
bool isFunctionTy() const
True if this is an instance of FunctionType.
void setTargetTriple(StringRef T)
Set the target triple.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
Context for (re-)mapping values (and metadata).
Implements a dense probed hash-table based set.
Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const
gets the attribute from the list of attributes.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This is an important base class in LLVM.
VisibilityTypes getVisibility() const
Module * getParent()
Get the module that this global value is contained inside of...
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
This is an important class for using LLVM in a threaded context.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Class to represent pointers.
void setLinkage(LinkageTypes LT)
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
void print(DiagnosticPrinter &DP) const override
Print using the given DP a user-friendly message.
void setDataLayout(StringRef Desc)
Set the data layout.
MDNode * getOperand(unsigned i) const
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
bool hasLocalLinkage() const
bool operator==(uint64_t V1, const APInt &V2)
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
A Module instance is used to store all the information related to an LLVM module.
bool insert(const value_type &X)
Insert a new element into the SetVector.
void addFlags(RemapFlags Flags)
Add to the current RemapFlags.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
This compiles xmm1 mulss xmm1 xorps xmm0 movss xmm0 ret Because mulss doesn t modify the top elements
Class to represent struct types.
@ Warning
Emits a warning if two values disagree.
StringRef - Represent a constant reference to a string, i.e.
Analysis the ScalarEvolution expression for r is this
void run(const Module &M, bool onlyNamed)
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
So we should use XX3Form_Rcr to implement intrinsic Convert DP outs ins xscvdpsp No builtin are required Round &Convert QP DP(dword[1] is set to zero) No builtin are required Round to Quad Precision because you need to assign rounding mode in instruction Provide builtin(set f128:$vT,(int_ppc_vsx_xsrqpi f128:$vB))(set f128 yields< n x< ty > >< result > yields< ty >< result > No builtin are required Load Store load store see def memrix16 in PPCInstrInfo td Load Store Vector load store outs ins lxsdx set load store with conversion from to DP
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumContainedTypes() const
Return the number of types in the derived type.
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.
static ManagedStatic< DebugCounter > DC
static void getArrayElements(const Constant *C, SmallVectorImpl< Constant * > &Dest)
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
StringRef getName() const
Return a constant reference to the value's name.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
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...
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
const CustomOperand< const MCSubtargetInfo & > Msg[]
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
@ RF_IgnoreMissingLocals
If this flag is set, the remapper ignores missing function-local entries (Argument,...
bool hasName() const
Return true if this is a named struct that has a non-empty name.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Base class for scope-like contexts.
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
static 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.
Should compile to something r4 addze r3 instead we get
@ FixedVectorTyID
Fixed width SIMD vector type.
Lightweight error class with error context and mandatory checking.
const Comdat * getComdat() const
LLVMContext & getContext() const
Get the global data context.
Type * getValueAsType() const
Return the attribute's value as a Type.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
iterator find(const KeyT &Val)
static bool isEqual(const Function &Caller, const Function &Callee)
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
unsigned getAddressSpace() const
@ ExternalLinkage
Externally visible function.
void scheduleMapGlobalIFunc(GlobalIFunc &GI, Constant &Resolver, unsigned MappingContextID=0)
Error takeError()
Take ownership of the stored error.
Function Alias Analysis false
static void forceRenaming(GlobalValue *GV, StringRef Name)
The LLVM SymbolTable class autorenames globals that conflict in the symbol table.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
void dropTriviallyDeadConstantArrays()
Destroy ConstantArrays in LLVMContext if they are not used.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
op_iterator op_end() const
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
void push_back(Metadata *MD)
Append an element to the tuple. This will resize the node.
bool isDeclarationForLinker() const
@ Max
Takes the max of the two values, which are required to be integers.
bool erase(const ValueT &V)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
@ ScalableVectorTyID
Scalable SIMD vector type.
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
A SetVector that performs no allocations if smaller than a certain size.
Type * getValueType() const
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
void takeName(Value *V)
Transfer the name from V to this value.
void setAlignment(MaybeAlign Align)
@ ExternalWeakLinkage
ExternalWeak linkage description.
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
This is a class that can be implemented by clients to materialize Values on demand.
void switchToNonOpaque(StructType *Ty)
op_iterator op_begin() const
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
LLVM Value Representation.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static std::string adjustInlineAsm(const std::string &InlineAsm, const Triple &Triple)
Return InlineAsm adjusted with target-specific directives if required.
Type * getElementType() const
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Class to represent function types.
reference emplace_back(ArgTypes &&... Args)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void scheduleMapGlobalAlias(GlobalAlias &GA, Constant &Aliasee, unsigned MappingContextID=0)