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) {
82 assert(SpeculativeTypes.empty());
83 assert(SpeculativeDstOpaqueTypes.empty());
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)
151 SrcDefinitionsToResolve.push_back(SSTy);
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 *DSeqTy = dyn_cast<SequentialType>(DstTy)) {
178 if (DSeqTy->getNumElements() !=
179 cast<SequentialType>(SrcTy)->getNumElements())
186 SpeculativeTypes.push_back(SrcTy);
197 void TypeMapTy::linkDefinedTypeBodies() {
199 for (
StructType *SrcSTy : SrcDefinitionsToResolve) {
200 StructType *DstSTy = cast<StructType>(MappedTypes[SrcSTy]);
204 Elements.
resize(SrcSTy->getNumElements());
205 for (
unsigned I = 0,
E = Elements.
size();
I !=
E; ++
I)
206 Elements[
I] =
get(SrcSTy->getElementType(
I));
208 DstSTy->
setBody(Elements, SrcSTy->isPacked());
209 DstStructTypesSet.switchToNonOpaque(DstSTy);
211 SrcDefinitionsToResolve.clear();
212 DstResolvedOpaqueTypes.clear();
226 DstStructTypesSet.addNonOpaque(DTy);
231 return get(Ty, Visited);
236 Type **Entry = &MappedTypes[Ty];
241 bool IsUniqued = !isa<StructType>(Ty) || cast<StructType>(Ty)->isLiteral();
250 DstStructTypesSet.hasType(STy))
254 for (
auto &Pair : MappedTypes) {
255 assert(!(Pair.first != Ty && Pair.second == Ty) &&
256 "mapping to a source type");
260 if (!Visited.
insert(STy).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());
309 cast<VectorType>(Ty)->getNumElements());
312 cast<PointerType>(Ty)->getAddressSpace());
316 cast<FunctionType>(Ty)->isVarArg());
318 auto *STy = cast<StructType>(Ty);
325 DstStructTypesSet.addOpaque(STy);
330 DstStructTypesSet.findNonOpaque(ElementTypes, IsPacked)) {
332 return *Entry = OldT;
336 DstStructTypesSet.addNonOpaque(STy);
341 finishType(DTy, STy, ElementTypes);
363 IRLinker &TheIRLinker;
366 GlobalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
371 IRLinker &TheIRLinker;
374 LocalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
385 std::unique_ptr<Module> SrcM;
388 std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor;
391 GlobalValueMaterializer GValMaterializer;
392 LocalValueMaterializer LValMaterializer;
405 std::vector<GlobalValue *> Worklist;
408 if (ValuesToLink.
insert(GV).second)
409 Worklist.push_back(GV);
417 bool IsPerformingImport;
422 bool DoneLinkingBodies =
false;
429 FoundError = std::move(E);
446 void emitWarning(
const Twine &Message) {
472 void computeTypeMapping();
485 Error linkModuleFlagsMetadata();
501 void prepareCompileUnitsForImport();
502 void linkNamedMDNodes();
505 IRLinker(
Module &DstM, MDMapT &SharedMDs,
509 bool IsPerformingImport)
510 : DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(std::move(AddLazyFor)),
511 TypeMap(Set), GValMaterializer(*
this), LValMaterializer(*
this),
512 SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
515 AliasMCID(Mapper.registerAlternateMappingContext(AliasValueMap,
516 &LValMaterializer)) {
517 ValueMap.
getMDMap() = std::move(SharedMDs);
520 if (IsPerformingImport)
521 prepareCompileUnitsForImport();
523 ~IRLinker() { SharedMDs = std::move(*ValueMap.
getMDMap()); }
544 ConflictGV->setName(Name);
545 assert(ConflictGV->getName() != Name &&
"forceRenaming didn't work");
551 Value *GlobalValueMaterializer::materialize(
Value *SGV) {
552 return TheIRLinker.materialize(SGV,
false);
555 Value *LocalValueMaterializer::materialize(
Value *SGV) {
556 return TheIRLinker.materialize(SGV,
true);
559 Value *IRLinker::materialize(
Value *V,
bool ForAlias) {
577 if (
auto *
F = dyn_cast<Function>(New)) {
578 if (!
F->isDeclaration())
580 }
else if (
auto *V = dyn_cast<GlobalVariable>(New)) {
581 if (V->hasInitializer() || V->hasAppendingLinkage())
584 auto *A = cast<GlobalAlias>(New);
600 if (ForAlias || shouldLink(New, *SGV))
601 setError(linkGlobalValueBody(*New, *SGV));
631 F->copyAttributesFrom(SF);
648 bool ForDefinition) {
650 if (
auto *SGVar = dyn_cast<GlobalVariable>(SGV)) {
651 NewGV = copyGlobalVariableProto(SGVar);
652 }
else if (
auto *SF = dyn_cast<Function>(SGV)) {
653 NewGV = copyFunctionProto(SF);
656 NewGV = copyGlobalAliasProto(cast<GlobalAlias>(SGV));
675 if (
auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
678 NewGO->copyMetadata(cast<GlobalObject>(SGV), 0);
684 if (
auto *NewF = dyn_cast<Function>(NewGV)) {
685 NewF->setPersonalityFn(
nullptr);
686 NewF->setPrefixData(
nullptr);
687 NewF->setPrologueData(
nullptr);
694 size_t DotPos = Name.
rfind(
'.');
696 !isdigit(static_cast<unsigned char>(Name[DotPos + 1])))
705 void IRLinker::computeTypeMapping() {
719 TypeMap.addTypeMapping(DAT->
getElementType(), SAT->getElementType());
724 TypeMap.addTypeMapping(DGV->getType(), SGV.
getType());
728 TypeMap.addTypeMapping(DGV->getType(), SGV.
getType());
734 std::vector<StructType *> Types = SrcM->getIdentifiedStructTypes();
739 if (TypeMap.DstStructTypesSet.hasType(
ST)) {
748 if (STTypePrefix.size()==
ST->getName().size())
752 StructType *DST = DstM.getTypeByName(STTypePrefix);
773 if (TypeMap.DstStructTypesSet.hasType(DST))
774 TypeMap.addTypeMapping(DST,
ST);
779 TypeMap.linkDefinedTypeBodies();
784 unsigned NumElements = cast<ArrayType>(C->
getType())->getNumElements();
786 for (
unsigned i = 0; i != NumElements; ++i)
802 bool IsNewStructor =
false;
803 bool IsOldStructor =
false;
804 if (Name ==
"llvm.global_ctors" || Name ==
"llvm.global_dtors") {
805 if (cast<StructType>(EltTy)->getNumElements() == 3)
806 IsNewStructor =
true;
808 IsOldStructor =
true;
813 auto &
ST = *cast<StructType>(EltTy);
814 Type *Tys[3] = {
ST.getElementType(0),
ST.getElementType(1), VoidPtrTy};
818 uint64_t DstNumElements = 0;
825 "Linking globals named '" + SrcGV->
getName() +
826 "': can only link appending global with another appending " 831 return stringErr(
"Appending variables with different element types!");
833 return stringErr(
"Appending variables linked with different const'ness!");
837 "Appending variables with different alignment need to be linked!");
841 "Appending variables with different visibility need to be linked!");
845 "Appending variables with different unnamed_addr need to be linked!");
849 "Appending variables with different section name need to be linked!");
862 return !shouldLink(DGV, *
Key);
864 SrcElements.
erase(It, SrcElements.
end());
866 uint64_t NewSize = DstNumElements + SrcElements.
size();
880 Mapper.scheduleMapAppendingVariable(*NG,
882 IsOldStructor, SrcElements);
906 bool LazilyAdded =
false;
907 AddLazyFor(SGV, [
this, &LazilyAdded](
GlobalValue &GV) {
918 bool ShouldLink = shouldLink(DGV, *SGV);
924 return cast<Constant>(
I->second);
926 I = AliasValueMap.find(SGV);
927 if (
I != AliasValueMap.end())
928 return cast<Constant>(
I->second);
931 if (!ShouldLink && ForAlias)
937 return linkAppendingVarProto(cast_or_null<GlobalVariable>(DGV),
938 cast<GlobalVariable>(SGV));
941 if (DGV && !ShouldLink) {
947 if (DoneLinkingBodies)
950 NewGV = copyGlobalValueProto(SGV, ShouldLink || ForAlias);
951 if (ShouldLink || !ForAlias)
958 if (
Function *
F = dyn_cast<Function>(NewGV))
960 NewGV = Remangled.getValue();
962 if (ShouldLink || ForAlias) {
964 if (
auto *GO = dyn_cast<GlobalObject>(NewGV)) {
965 Comdat *
DC = DstM.getOrInsertComdat(
SC->getName());
972 if (!ShouldLink && ForAlias)
981 if (DGV && NewGV != SGV) {
983 NewGV, TypeMap.get(SGV->
getType()));
986 if (DGV && NewGV != DGV) {
1028 Mapper.scheduleRemapFunction(Dst);
1033 Mapper.scheduleMapGlobalAliasee(Dst, *Src.
getAliasee(), AliasMCID);
1037 if (
auto *
F = dyn_cast<Function>(&Src))
1038 return linkFunctionBody(cast<Function>(Dst), *
F);
1039 if (
auto *GVar = dyn_cast<GlobalVariable>(&Src)) {
1040 linkGlobalVariable(cast<GlobalVariable>(Dst), *GVar);
1043 linkAliasBody(cast<GlobalAlias>(Dst), cast<GlobalAlias>(Src));
1047 void IRLinker::prepareCompileUnitsForImport() {
1048 NamedMDNode *SrcCompileUnits = SrcM->getNamedMetadata(
"llvm.dbg.cu");
1049 if (!SrcCompileUnits)
1055 auto *
CU = cast<DICompileUnit>(SrcCompileUnits->
getOperand(
I));
1056 assert(
CU &&
"Expected valid compile unit");
1064 ValueMap.
MD()[
CU->getRawRetainedTypes()].reset(
nullptr);
1074 ValueMap.
MD()[
CU->getRawGlobalVariables()].reset(
nullptr);
1089 bool ReplaceImportedEntities =
false;
1090 for (
auto *
IE :
CU->getImportedEntities()) {
1092 assert(Scope &&
"Invalid Scope encoding!");
1093 if (isa<DILocalScope>(Scope))
1096 ReplaceImportedEntities =
true;
1098 if (ReplaceImportedEntities) {
1099 if (!AllImportedModules.
empty())
1103 AllImportedModules.
end())));
1107 ValueMap.
MD()[
CU->getRawImportedEntities()].reset(
nullptr);
1113 void IRLinker::linkNamedMDNodes() {
1114 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1115 for (
const NamedMDNode &NMD : SrcM->named_metadata()) {
1117 if (&NMD == SrcModFlags)
1119 NamedMDNode *DestNMD = DstM.getOrInsertNamedMetadata(NMD.getName());
1121 for (
const MDNode *
Op : NMD.operands())
1127 Error IRLinker::linkModuleFlagsMetadata() {
1129 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1135 NamedMDNode *DstModFlags = DstM.getOrInsertModuleFlagsMetadata();
1154 Flags[
ID] = std::make_pair(Op,
I);
1163 mdconst::extract<ConstantInt>(SrcOp->
getOperand(0));
1167 std::tie(DstOp, DstIndex) = Flags.
lookup(ID);
1168 unsigned SrcBehaviorValue = SrcBehavior->
getZExtValue();
1189 mdconst::extract<ConstantInt>(DstOp->getOperand(0));
1190 unsigned DstBehaviorValue = DstBehavior->
getZExtValue();
1192 auto overrideDstValue = [&]() {
1194 Flags[
ID].first = SrcOp;
1201 SrcOp->
getOperand(2) != DstOp->getOperand(2))
1202 return stringErr(
"linking module flags '" + ID->getString() +
1203 "': IDs have conflicting override values");
1212 if (SrcBehaviorValue != DstBehaviorValue)
1213 return stringErr(
"linking module flags '" + ID->getString() +
1214 "': IDs have conflicting behaviors");
1216 auto replaceDstValue = [&](
MDNode *New) {
1217 Metadata *FlagOps[] = {DstOp->getOperand(0),
ID, New};
1224 switch (SrcBehaviorValue) {
1230 if (SrcOp->
getOperand(2) != DstOp->getOperand(2))
1231 return stringErr(
"linking module flags '" + ID->getString() +
1232 "': IDs have conflicting values");
1237 if (SrcOp->
getOperand(2) != DstOp->getOperand(2)) {
1240 <<
"linking module flags '" << ID->getString()
1241 <<
"': IDs have conflicting values ('" << *SrcOp->
getOperand(2)
1242 <<
"' from " << SrcM->getModuleIdentifier() <<
" with '" 1243 << *DstOp->getOperand(2) <<
"' from " << DstM.getModuleIdentifier()
1251 mdconst::extract<ConstantInt>(DstOp->getOperand(2));
1253 mdconst::extract<ConstantInt>(SrcOp->
getOperand(2));
1254 if (SrcValue->getZExtValue() > DstValue->
getZExtValue())
1259 MDNode *DstValue = cast<MDNode>(DstOp->getOperand(2));
1264 MDs.append(SrcValue->op_begin(), SrcValue->op_end());
1266 replaceDstValue(
MDNode::get(DstM.getContext(), MDs));
1271 MDNode *DstValue = cast<MDNode>(DstOp->getOperand(2));
1274 Elts.
insert(SrcValue->op_begin(), SrcValue->op_end());
1284 for (
unsigned I = 0,
E = Requirements.
size();
I !=
E; ++
I) {
1285 MDNode *Requirement = Requirements[
I];
1291 return stringErr(
"linking module flags '" + Flag->
getString() +
1292 "': does not have the required value");
1303 return ".text\n.balign 2\n.thumb\n" + InlineAsm;
1305 return ".text\n.balign 4\n.arm\n" + InlineAsm;
1309 Error IRLinker::run() {
1311 if (SrcM->getMaterializer())
1312 if (
Error Err = SrcM->getMaterializer()->materializeMetadata())
1317 if (DstM.getDataLayout().isDefault())
1318 DstM.setDataLayout(SrcM->getDataLayout());
1320 if (SrcM->getDataLayout() != DstM.getDataLayout()) {
1321 emitWarning(
"Linking two modules of different data layouts: '" +
1322 SrcM->getModuleIdentifier() +
"' is '" +
1323 SrcM->getDataLayoutStr() +
"' whereas '" +
1324 DstM.getModuleIdentifier() +
"' is '" +
1325 DstM.getDataLayoutStr() +
"'\n");
1329 if (DstM.getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
1330 DstM.setTargetTriple(SrcM->getTargetTriple());
1332 Triple SrcTriple(SrcM->getTargetTriple()), DstTriple(DstM.getTargetTriple());
1334 if (!SrcM->getTargetTriple().empty()&&
1335 !SrcTriple.isCompatibleWith(DstTriple))
1336 emitWarning(
"Linking two modules of different target triples: " +
1337 SrcM->getModuleIdentifier() +
"' is '" +
1338 SrcM->getTargetTriple() +
"' whereas '" +
1339 DstM.getModuleIdentifier() +
"' is '" + DstM.getTargetTriple() +
1342 DstM.setTargetTriple(SrcTriple.merge(DstTriple));
1345 if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) {
1346 std::string SrcModuleInlineAsm =
adjustInlineAsm(SrcM->getModuleInlineAsm(),
1348 if (DstM.getModuleInlineAsm().empty())
1349 DstM.setModuleInlineAsm(SrcModuleInlineAsm);
1351 DstM.setModuleInlineAsm(DstM.getModuleInlineAsm() +
"\n" +
1352 SrcModuleInlineAsm);
1356 computeTypeMapping();
1359 while (!Worklist.empty()) {
1361 Worklist.pop_back();
1365 AliasValueMap.find(GV) != AliasValueMap.end())
1369 Mapper.mapValue(*GV);
1371 return std::move(*FoundError);
1376 DoneLinkingBodies =
true;
1385 return linkModuleFlagsMetadata();
1389 : ETypes(E), IsPacked(P) {}
1392 : ETypes(ST->elements()), IsPacked(ST->isPacked()) {}
1402 StructType *IRMover::StructTypeKeyInfo::getEmptyKey() {
1406 StructType *IRMover::StructTypeKeyInfo::getTombstoneKey() {
1410 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const KeyTy &
Key) {
1415 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const StructType *
ST) {
1416 return getHashValue(
KeyTy(ST));
1421 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1423 return LHS ==
KeyTy(RHS);
1428 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1435 NonOpaqueStructTypes.insert(Ty);
1440 NonOpaqueStructTypes.insert(Ty);
1441 bool Removed = OpaqueStructTypes.erase(Ty);
1448 OpaqueStructTypes.insert(Ty);
1455 auto I = NonOpaqueStructTypes.find_as(Key);
1456 return I == NonOpaqueStructTypes.end() ? nullptr : *
I;
1461 return OpaqueStructTypes.count(Ty);
1462 auto I = NonOpaqueStructTypes.find(Ty);
1463 return I == NonOpaqueStructTypes.end() ?
false : *
I == Ty;
1468 StructTypes.
run(M,
false);
1478 for (
auto *MD : StructTypes.getVisitedMetadata()) {
1479 SharedMDs[MD].reset(const_cast<MDNode *>(MD));
1486 bool IsPerformingImport) {
1487 IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
1488 std::move(Src), ValuesToLink, std::move(AddLazyFor),
1489 IsPerformingImport);
1490 Error E = TheIRLinker.run();
bool isDeclarationForLinker() const
StringRef getSection() const
Get the custom section of this global if it has one.
unsigned getAlignment() const
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. ...
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
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
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 setAlignment(unsigned Align)
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.
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.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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.
void copyAttributesFrom(const GlobalValue *Src)
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...
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.
uint64_t getNumElements() const
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.
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...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool hasType(StructType *Ty)
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...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
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)
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.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
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)
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)
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
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_ATTRIBUTE_ALWAYS_INLINE iterator end()
bool isFunctionTy() const
True if this is an instance of FunctionType.
Appends the two values, which are required to be metadata nodes.
void emplace_back(ArgTypes &&... Args)
LLVM_NODISCARD bool empty() const
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)
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).
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 VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
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)
const Constant * getAliasee() const