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);
98 for (
Type *Ty : SpeculativeTypes)
99 if (
auto *STy = dyn_cast<StructType>(Ty))
103 SpeculativeTypes.clear();
104 SpeculativeDstOpaqueTypes.clear();
109 bool TypeMapTy::areTypesIsomorphic(
Type *DstTy,
Type *SrcTy) {
115 Type *&Entry = MappedTypes[SrcTy];
117 return Entry == DstTy;
121 if (DstTy == SrcTy) {
129 if (
StructType *SSTy = dyn_cast<StructType>(SrcTy)) {
131 if (SSTy->isOpaque()) {
133 SpeculativeTypes.push_back(SrcTy);
141 if (cast<StructType>(DstTy)->isOpaque()) {
143 if (!DstResolvedOpaqueTypes.insert(cast<StructType>(DstTy)).second)
145 SrcDefinitionsToResolve.push_back(SSTy);
146 SpeculativeTypes.push_back(SrcTy);
147 SpeculativeDstOpaqueTypes.push_back(cast<StructType>(DstTy));
158 if (isa<IntegerType>(DstTy))
160 if (
PointerType *PT = dyn_cast<PointerType>(DstTy)) {
161 if (PT->getAddressSpace() != cast<PointerType>(SrcTy)->getAddressSpace())
164 }
else if (
FunctionType *FT = dyn_cast<FunctionType>(DstTy)) {
165 if (FT->isVarArg() != cast<FunctionType>(SrcTy)->isVarArg())
167 }
else if (
StructType *DSTy = dyn_cast<StructType>(DstTy)) {
169 if (DSTy->isLiteral() != SSTy->
isLiteral() ||
170 DSTy->isPacked() != SSTy->
isPacked())
172 }
else if (
auto *DSeqTy = dyn_cast<SequentialType>(DstTy)) {
173 if (DSeqTy->getNumElements() !=
174 cast<SequentialType>(SrcTy)->getNumElements())
181 SpeculativeTypes.push_back(SrcTy);
192 void TypeMapTy::linkDefinedTypeBodies() {
194 for (
StructType *SrcSTy : SrcDefinitionsToResolve) {
195 StructType *DstSTy = cast<StructType>(MappedTypes[SrcSTy]);
199 Elements.
resize(SrcSTy->getNumElements());
200 for (
unsigned I = 0,
E = Elements.
size();
I !=
E; ++
I)
201 Elements[
I] =
get(SrcSTy->getElementType(
I));
203 DstSTy->
setBody(Elements, SrcSTy->isPacked());
204 DstStructTypesSet.switchToNonOpaque(DstSTy);
206 SrcDefinitionsToResolve.clear();
207 DstResolvedOpaqueTypes.clear();
221 DstStructTypesSet.addNonOpaque(DTy);
226 return get(Ty, Visited);
231 Type **Entry = &MappedTypes[Ty];
236 bool IsUniqued = !isa<StructType>(Ty) || cast<StructType>(Ty)->isLiteral();
240 for (
auto &Pair : MappedTypes) {
241 assert(!(Pair.first != Ty && Pair.second == Ty) &&
242 "mapping to a source type");
247 if (!IsUniqued && !Visited.
insert(cast<StructType>(Ty)).second) {
262 bool AnyChange =
false;
270 Entry = &MappedTypes[Ty];
272 if (
auto *DTy = dyn_cast<StructType>(*Entry)) {
274 auto *STy = cast<StructType>(Ty);
275 finishType(DTy, STy, ElementTypes);
283 if (!AnyChange && IsUniqued)
292 cast<ArrayType>(Ty)->getNumElements());
295 cast<VectorType>(Ty)->getNumElements());
298 cast<PointerType>(Ty)->getAddressSpace());
302 cast<FunctionType>(Ty)->isVarArg());
304 auto *STy = cast<StructType>(Ty);
311 DstStructTypesSet.addOpaque(STy);
316 DstStructTypesSet.findNonOpaque(ElementTypes, IsPacked)) {
318 return *Entry = OldT;
322 DstStructTypesSet.addNonOpaque(STy);
327 finishType(DTy, STy, ElementTypes);
349 IRLinker &TheIRLinker;
352 GlobalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
357 IRLinker &TheIRLinker;
360 LocalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
371 std::unique_ptr<Module> SrcM;
374 std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor;
377 GlobalValueMaterializer GValMaterializer;
378 LocalValueMaterializer LValMaterializer;
391 std::vector<GlobalValue *> Worklist;
394 if (ValuesToLink.insert(GV).second)
395 Worklist.push_back(GV);
403 bool IsPerformingImport;
408 bool DoneLinkingBodies =
false;
415 FoundError = std::move(E);
432 void emitWarning(
const Twine &Message) {
458 void computeTypeMapping();
471 Error linkModuleFlagsMetadata();
487 void prepareCompileUnitsForImport();
488 void linkNamedMDNodes();
491 IRLinker(
Module &DstM, MDMapT &SharedMDs,
495 bool IsPerformingImport)
496 : DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(std::move(AddLazyFor)),
497 TypeMap(Set), GValMaterializer(*this), LValMaterializer(*this),
498 SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
501 AliasMCID(Mapper.registerAlternateMappingContext(AliasValueMap,
502 &LValMaterializer)) {
506 if (IsPerformingImport)
507 prepareCompileUnitsForImport();
530 ConflictGV->setName(Name);
531 assert(ConflictGV->getName() != Name &&
"forceRenaming didn't work");
537 Value *GlobalValueMaterializer::materialize(
Value *SGV) {
538 return TheIRLinker.materialize(SGV,
false);
541 Value *LocalValueMaterializer::materialize(
Value *SGV) {
542 return TheIRLinker.materialize(SGV,
true);
545 Value *IRLinker::materialize(
Value *V,
bool ForAlias) {
563 if (
auto *
F = dyn_cast<Function>(New)) {
564 if (!
F->isDeclaration())
566 }
else if (
auto *V = dyn_cast<GlobalVariable>(New)) {
567 if (V->hasInitializer() || V->hasAppendingLinkage())
570 auto *
A = cast<GlobalAlias>(New);
586 if (ForAlias || shouldLink(New, *SGV))
587 setError(linkGlobalValueBody(*New, *SGV));
617 F->copyAttributesFrom(SF);
634 bool ForDefinition) {
636 if (
auto *SGVar = dyn_cast<GlobalVariable>(SGV)) {
637 NewGV = copyGlobalVariableProto(SGVar);
638 }
else if (
auto *SF = dyn_cast<Function>(SGV)) {
639 NewGV = copyFunctionProto(SF);
642 NewGV = copyGlobalAliasProto(cast<GlobalAlias>(SGV));
657 if (
auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
660 NewGO->copyMetadata(cast<GlobalObject>(SGV), 0);
666 if (
auto *NewF = dyn_cast<Function>(NewGV)) {
667 NewF->setPersonalityFn(
nullptr);
668 NewF->setPrefixData(
nullptr);
669 NewF->setPrologueData(
nullptr);
679 void IRLinker::computeTypeMapping() {
693 TypeMap.addTypeMapping(DAT->
getElementType(), SAT->getElementType());
708 std::vector<StructType *> Types = SrcM->getIdentifiedStructTypes();
713 if (TypeMap.DstStructTypesSet.hasType(
ST)) {
722 size_t DotPos =
ST->getName().rfind(
'.');
724 ST->getName().back() ==
'.' ||
725 !isdigit(static_cast<unsigned char>(
ST->getName()[DotPos + 1])))
750 if (TypeMap.DstStructTypesSet.hasType(DST))
751 TypeMap.addTypeMapping(DST,
ST);
756 TypeMap.linkDefinedTypeBodies();
761 unsigned NumElements = cast<ArrayType>(C->
getType())->getNumElements();
763 for (
unsigned i = 0; i != NumElements; ++i)
779 bool IsNewStructor =
false;
780 bool IsOldStructor =
false;
781 if (Name ==
"llvm.global_ctors" || Name ==
"llvm.global_dtors") {
782 if (cast<StructType>(EltTy)->getNumElements() == 3)
783 IsNewStructor =
true;
785 IsOldStructor =
true;
790 auto &
ST = *cast<StructType>(EltTy);
791 Type *Tys[3] = {
ST.getElementType(0),
ST.getElementType(1), VoidPtrTy};
795 uint64_t DstNumElements = 0;
802 "Linking globals named '" + SrcGV->
getName() +
803 "': can only link appending global with another appending "
808 return stringErr(
"Appending variables with different element types!");
810 return stringErr(
"Appending variables linked with different const'ness!");
814 "Appending variables with different alignment need to be linked!");
818 "Appending variables with different visibility need to be linked!");
822 "Appending variables with different unnamed_addr need to be linked!");
826 "Appending variables with different section name need to be linked!");
839 return !shouldLink(DGV, *Key);
841 SrcElements.
erase(It, SrcElements.
end());
843 uint64_t NewSize = DstNumElements + SrcElements.
size();
857 Mapper.scheduleMapAppendingVariable(*NG,
859 IsOldStructor, SrcElements);
883 bool LazilyAdded =
false;
884 AddLazyFor(SGV, [
this, &LazilyAdded](
GlobalValue &GV) {
895 bool ShouldLink = shouldLink(DGV, *SGV);
901 return cast<Constant>(
I->second);
903 I = AliasValueMap.find(SGV);
904 if (
I != AliasValueMap.end())
905 return cast<Constant>(
I->second);
908 if (!ShouldLink && ForAlias)
914 return linkAppendingVarProto(cast_or_null<GlobalVariable>(DGV),
915 cast<GlobalVariable>(SGV));
918 if (DGV && !ShouldLink) {
924 if (DoneLinkingBodies)
927 NewGV = copyGlobalValueProto(SGV, ShouldLink);
928 if (ShouldLink || !ForAlias)
935 if (
Function *
F = dyn_cast<Function>(NewGV))
937 NewGV = Remangled.getValue();
939 if (ShouldLink || ForAlias) {
941 if (
auto *GO = dyn_cast<GlobalObject>(NewGV)) {
949 if (!ShouldLink && ForAlias)
956 if (DGV && NewGV != DGV) {
997 Mapper.scheduleRemapFunction(Dst);
1002 Mapper.scheduleMapGlobalAliasee(Dst, *Src.
getAliasee(), AliasMCID);
1006 if (
auto *
F = dyn_cast<Function>(&Src))
1007 return linkFunctionBody(cast<Function>(Dst), *
F);
1008 if (
auto *GVar = dyn_cast<GlobalVariable>(&Src)) {
1009 linkGlobalVariable(cast<GlobalVariable>(Dst), *GVar);
1012 linkAliasBody(cast<GlobalAlias>(Dst), cast<GlobalAlias>(Src));
1016 void IRLinker::prepareCompileUnitsForImport() {
1017 NamedMDNode *SrcCompileUnits = SrcM->getNamedMetadata(
"llvm.dbg.cu");
1018 if (!SrcCompileUnits)
1024 auto *CU = cast<DICompileUnit>(SrcCompileUnits->
getOperand(
I));
1025 assert(CU &&
"Expected valid compile unit");
1031 ValueMap.
MD()[CU->getRawEnumTypes()].reset(
nullptr);
1032 ValueMap.
MD()[CU->getRawMacros()].reset(
nullptr);
1033 ValueMap.
MD()[CU->getRawRetainedTypes()].reset(
nullptr);
1040 [](
const GlobalValue *GV) {
return isa<GlobalVariable>(GV); }) &&
1041 "Unexpected importing of a GlobalVariable definition");
1042 ValueMap.
MD()[CU->getRawGlobalVariables()].reset(
nullptr);
1057 bool ReplaceImportedEntities =
false;
1058 for (
auto *
IE : CU->getImportedEntities()) {
1060 assert(Scope &&
"Invalid Scope encoding!");
1061 if (isa<DILocalScope>(Scope))
1064 ReplaceImportedEntities =
true;
1066 if (ReplaceImportedEntities) {
1067 if (!AllImportedModules.
empty())
1071 AllImportedModules.
end())));
1075 ValueMap.
MD()[CU->getRawImportedEntities()].reset(
nullptr);
1081 void IRLinker::linkNamedMDNodes() {
1082 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1083 for (
const NamedMDNode &NMD : SrcM->named_metadata()) {
1085 if (&NMD == SrcModFlags)
1089 for (
const MDNode *
Op : NMD.operands())
1095 Error IRLinker::linkModuleFlagsMetadata() {
1097 const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1122 Flags[
ID] = std::make_pair(Op,
I);
1131 mdconst::extract<ConstantInt>(SrcOp->
getOperand(0));
1135 std::tie(DstOp, DstIndex) = Flags.
lookup(ID);
1136 unsigned SrcBehaviorValue = SrcBehavior->
getZExtValue();
1157 mdconst::extract<ConstantInt>(DstOp->getOperand(0));
1158 unsigned DstBehaviorValue = DstBehavior->
getZExtValue();
1160 auto overrideDstValue = [&]() {
1162 Flags[
ID].first = SrcOp;
1169 SrcOp->
getOperand(2) != DstOp->getOperand(2))
1170 return stringErr(
"linking module flags '" + ID->getString() +
1171 "': IDs have conflicting override values");
1180 if (SrcBehaviorValue != DstBehaviorValue)
1181 return stringErr(
"linking module flags '" + ID->getString() +
1182 "': IDs have conflicting behaviors");
1184 auto replaceDstValue = [&](
MDNode *New) {
1185 Metadata *FlagOps[] = {DstOp->getOperand(0),
ID, New};
1192 switch (SrcBehaviorValue) {
1198 if (SrcOp->
getOperand(2) != DstOp->getOperand(2))
1199 return stringErr(
"linking module flags '" + ID->getString() +
1200 "': IDs have conflicting values");
1205 if (SrcOp->
getOperand(2) != DstOp->getOperand(2)) {
1206 emitWarning(
"linking module flags '" + ID->getString() +
1207 "': IDs have conflicting values");
1213 mdconst::extract<ConstantInt>(DstOp->getOperand(2));
1215 mdconst::extract<ConstantInt>(SrcOp->
getOperand(2));
1216 if (SrcValue->getZExtValue() > DstValue->
getZExtValue())
1221 MDNode *DstValue = cast<MDNode>(DstOp->getOperand(2));
1226 MDs.append(SrcValue->op_begin(), SrcValue->op_end());
1233 MDNode *DstValue = cast<MDNode>(DstOp->getOperand(2));
1236 Elts.
insert(SrcValue->op_begin(), SrcValue->op_end());
1246 for (
unsigned I = 0, E = Requirements.
size();
I !=
E; ++
I) {
1247 MDNode *Requirement = Requirements[
I];
1253 return stringErr(
"linking module flags '" + Flag->
getString() +
1254 "': does not have the required value");
1265 return ".text\n.balign 2\n.thumb\n" + InlineAsm;
1267 return ".text\n.balign 4\n.arm\n" + InlineAsm;
1271 Error IRLinker::run() {
1273 if (SrcM->getMaterializer())
1274 if (
Error Err = SrcM->getMaterializer()->materializeMetadata())
1283 emitWarning(
"Linking two modules of different data layouts: '" +
1284 SrcM->getModuleIdentifier() +
"' is '" +
1285 SrcM->getDataLayoutStr() +
"' whereas '" +
1291 if (DstM.
getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
1296 if (!SrcM->getTargetTriple().empty()&&
1297 !SrcTriple.isCompatibleWith(DstTriple))
1298 emitWarning(
"Linking two modules of different target triples: " +
1299 SrcM->getModuleIdentifier() +
"' is '" +
1300 SrcM->getTargetTriple() +
"' whereas '" +
1307 if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) {
1308 std::string SrcModuleInlineAsm =
adjustInlineAsm(SrcM->getModuleInlineAsm(),
1314 SrcModuleInlineAsm);
1318 computeTypeMapping();
1321 while (!Worklist.empty()) {
1323 Worklist.pop_back();
1327 AliasValueMap.find(GV) != AliasValueMap.end())
1331 Mapper.mapValue(*GV);
1333 return std::move(*FoundError);
1338 DoneLinkingBodies =
true;
1347 return linkModuleFlagsMetadata();
1351 : ETypes(E), IsPacked(P) {}
1354 : ETypes(ST->elements()), IsPacked(ST->isPacked()) {}
1364 StructType *IRMover::StructTypeKeyInfo::getEmptyKey() {
1368 StructType *IRMover::StructTypeKeyInfo::getTombstoneKey() {
1372 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const KeyTy &Key) {
1377 unsigned IRMover::StructTypeKeyInfo::getHashValue(
const StructType *
ST) {
1378 return getHashValue(KeyTy(ST));
1383 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1385 return LHS == KeyTy(RHS);
1390 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1392 return KeyTy(LHS) == KeyTy(RHS);
1397 NonOpaqueStructTypes.insert(Ty);
1402 NonOpaqueStructTypes.insert(Ty);
1403 bool Removed = OpaqueStructTypes.erase(Ty);
1410 OpaqueStructTypes.insert(Ty);
1417 auto I = NonOpaqueStructTypes.find_as(Key);
1418 return I == NonOpaqueStructTypes.end() ?
nullptr : *
I;
1423 return OpaqueStructTypes.count(Ty);
1424 auto I = NonOpaqueStructTypes.find(Ty);
1425 return I == NonOpaqueStructTypes.end() ?
false : *
I == Ty;
1430 StructTypes.
run(M,
false);
1440 for (
auto *MD : StructTypes.getVisitedMetadata()) {
1441 SharedMDs[MD].reset(const_cast<MDNode *>(MD));
1448 bool IsPerformingImport) {
1449 IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
1450 std::move(Src), ValuesToLink, std::move(AddLazyFor),
1451 IsPerformingImport);
1452 Error E = TheIRLinker.run();
void push_back(const T &Elt)
LinkageTypes getLinkage() 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...
VisibilityTypes getVisibility() const
Constant * getPrologueData() const
Get the prologue data associated with this function.
Takes the max of the two values, which are required to be integers.
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
A Module instance is used to store all the information related to an LLVM module. ...
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
ArrayRef< Type * > ETypes
bool operator!=(const KeyTy &that) const
void addOpaque(StructType *Ty)
Implements a dense probed hash-table based set.
unsigned getNumOperands() const
Return number of MDNode operands.
Any global values not in value map are mapped to null instead of mapping to self. ...
StructType * findNonOpaque(ArrayRef< Type * > ETypes, bool IsPacked)
Type * getValueType() const
void addOperand(MDNode *M)
bool hasAppendingLinkage() const
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Externally visible function.
void setDataLayout(StringRef Desc)
Set the data layout.
op_iterator op_begin() const
bool hasPrologueData() const
Check whether this function has prologue data.
Context for (re-)mapping values (and metadata).
static void getArrayElements(const Constant *C, SmallVectorImpl< Constant * > &Dest)
void switchToNonOpaque(StructType *Ty)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Error takeError()
Take ownership of the stored error.
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
void reserve(size_type N)
void setAlignment(unsigned Align)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
void setOperand(unsigned I, MDNode *New)
iterator end()
Get an iterator to the end of the SetVector.
const Constant * getAliasee() const
const Comdat * getComdat() const
op_iterator op_end() const
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
size_type size() const
Determine the number of elements in the SetVector.
StructType * getTypeByName(StringRef Name) const
Return the type with the specified name, or null if there is none by that name.
StringRef getName() const
Return a constant reference to the value's name.
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Appends the two values, which are required to be metadata nodes.
Error move(std::unique_ptr< Module > Src, ArrayRef< GlobalValue * > ValuesToLink, std::function< void(GlobalValue &GV, ValueAdder Add)> AddLazyFor, bool IsPerformingImport)
Move in the provide values in ValuesToLink from Src.
void copyMetadata(const GlobalObject *Src, unsigned Offset)
Copy metadata from Src, adjusting offsets by Offset.
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.
void copyAttributesFrom(const GlobalValue *Src)
Class to represent struct types.
const Constant * stripPointerCasts() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition...
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
Constant * getPersonalityFn() const
Get the personality function associated with this function.
void setModuleInlineAsm(StringRef Asm)
Set the module-scope inline assembly blocks.
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.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
LLVM_NODISCARD bool empty() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
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...
bool insert(const value_type &X)
Insert a new element into the SetVector.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static bool isEqual(const Function &Caller, const Function &Callee)
bool operator==(const KeyTy &that) const
unsigned getAlignment() const
Class to represent array types.
iterator find(const KeyT &Val)
iterator begin()
Get an iterator to the beginning of the SetVector.
StringRef getSection() const
Get the custom section of this global if it has one.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
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...
TypeID getTypeID() const
Return the type id for the type.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool hasType(StructType *Ty)
void takeName(Value *V)
Transfer the name from V to this value.
Type * getElementType() const
Class to represent pointers.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
ExternalWeak linkage description.
This is a class that can be implemented by clients to materialize Values on demand.
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...
KeyTy(ArrayRef< Type * > E, bool P)
The instances of the Type class are immutable: once they are created, they are never changed...
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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 hasPersonalityFn() const
Check whether this function has a personality function.
Optional< MDMapT > & getMDMap()
void splice(iterator where, iplist_impl &L2)
MDNode * getOperand(unsigned i) const
uint64_t getNumElements() const
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
unsigned getNumContainedTypes() const
Return the number of types in the derived type.
Error materialize()
Make sure this GlobalValue is fully read.
void addNonOpaque(StructType *Ty)
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
iterator erase(const_iterator CI)
LLVMContext & getContext() const
All values hold a context through their type.
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
Triple - Helper class for working with autoconf configuration names.
Base class for scope-like contexts.
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
bool hasExternalWeakLinkage() const
StringRef getString() const
const MDOperand & getOperand(unsigned I) const
A SetVector that performs no allocations if smaller than a certain size.
static ErrorSuccess success()
Create a success value.
bool hasGlobalUnnamedAddr() const
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
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)
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
bool hasName() const
Return true if this is a named struct that has a non-empty name.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
CHAIN = SC CHAIN, Imm128 - System call.
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
void print(DiagnosticPrinter &DP) const override
Print using the given DP a user-friendly message.
void setLinkage(LinkageTypes LT)
Uses the specified value, regardless of the behavior or value of the other module.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg)
Emits a warning if two values disagree.
StringRef getName() const
Return the name for this struct type if it has an identity.
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.
llvm_unreachable("Unknown RegBank!")
ThreadLocalMode getThreadLocalMode() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static std::vector< std::string > Flags
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...
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void emplace_back(ArgTypes &&...Args)
Appends the two values, which are required to be metadata nodes.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void setPrologueData(Constant *PrologueData)
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
void setTargetTriple(StringRef T)
Set the target triple.
bool hasPrefixData() const
Check whether this function has prefix data.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Rename collisions when linking (static functions).
Constant * getPrefixData() const
Get the prefix data associated with this function.
bool hasLocalLinkage() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< void(GlobalValue &)> ValueAdder
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
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. ...
unsigned getNumOperands() const
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
void setPersonalityFn(Constant *Fn)
bool operator==(uint64_t V1, const APInt &V2)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
bool isDeclarationForLinker() const
static IntegerType * getInt8Ty(LLVMContext &C)
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
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...
LLVMContext & getContext() const
Get the global data context.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
void setPrefixData(Constant *PrefixData)