LLVM  13.0.0git
IRMover.cpp
Go to the documentation of this file.
1 //===- lib/Linker/IRMover.cpp ---------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/Linker/IRMover.h"
10 #include "LinkDiagnosticInfo.h"
11 #include "llvm/ADT/SetVector.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/Triple.h"
14 #include "llvm/IR/Constants.h"
15 #include "llvm/IR/DebugInfo.h"
17 #include "llvm/IR/GVMaterializer.h"
18 #include "llvm/IR/Intrinsics.h"
19 #include "llvm/IR/TypeFinder.h"
21 #include "llvm/Support/Error.h"
23 #include <utility>
24 using namespace llvm;
25 
26 //===----------------------------------------------------------------------===//
27 // TypeMap implementation.
28 //===----------------------------------------------------------------------===//
29 
30 namespace {
31 class TypeMapTy : public ValueMapTypeRemapper {
32  /// This is a mapping from a source type to a destination type to use.
33  DenseMap<Type *, Type *> MappedTypes;
34 
35  /// When checking to see if two subgraphs are isomorphic, we speculatively
36  /// add types to MappedTypes, but keep track of them here in case we need to
37  /// roll back.
38  SmallVector<Type *, 16> SpeculativeTypes;
39 
40  SmallVector<StructType *, 16> SpeculativeDstOpaqueTypes;
41 
42  /// This is a list of non-opaque structs in the source module that are mapped
43  /// to an opaque struct in the destination module.
44  SmallVector<StructType *, 16> SrcDefinitionsToResolve;
45 
46  /// This is the set of opaque types in the destination modules who are
47  /// getting a body from the source module.
48  SmallPtrSet<StructType *, 16> DstResolvedOpaqueTypes;
49 
50 public:
51  TypeMapTy(IRMover::IdentifiedStructTypeSet &DstStructTypesSet)
52  : DstStructTypesSet(DstStructTypesSet) {}
53 
54  IRMover::IdentifiedStructTypeSet &DstStructTypesSet;
55  /// Indicate that the specified type in the destination module is conceptually
56  /// equivalent to the specified type in the source module.
57  void addTypeMapping(Type *DstTy, Type *SrcTy);
58 
59  /// Produce a body for an opaque type in the dest module from a type
60  /// definition in the source module.
61  void linkDefinedTypeBodies();
62 
63  /// Return the mapped type to use for the specified input type from the
64  /// source module.
65  Type *get(Type *SrcTy);
66  Type *get(Type *SrcTy, SmallPtrSet<StructType *, 8> &Visited);
67 
68  void finishType(StructType *DTy, StructType *STy, ArrayRef<Type *> ETypes);
69 
71  return cast<FunctionType>(get((Type *)T));
72  }
73 
74 private:
75  Type *remapType(Type *SrcTy) override { return get(SrcTy); }
76 
77  bool areTypesIsomorphic(Type *DstTy, Type *SrcTy);
78 };
79 }
80 
81 void TypeMapTy::addTypeMapping(Type *DstTy, Type *SrcTy) {
82  assert(SpeculativeTypes.empty());
83  assert(SpeculativeDstOpaqueTypes.empty());
84 
85  // Check to see if these types are recursively isomorphic and establish a
86  // mapping between them if so.
87  if (!areTypesIsomorphic(DstTy, SrcTy)) {
88  // Oops, they aren't isomorphic. Just discard this request by rolling out
89  // any speculative mappings we've established.
90  for (Type *Ty : SpeculativeTypes)
91  MappedTypes.erase(Ty);
92 
93  SrcDefinitionsToResolve.resize(SrcDefinitionsToResolve.size() -
94  SpeculativeDstOpaqueTypes.size());
95  for (StructType *Ty : SpeculativeDstOpaqueTypes)
96  DstResolvedOpaqueTypes.erase(Ty);
97  } else {
98  // SrcTy and DstTy are recursively ismorphic. We clear names of SrcTy
99  // and all its descendants to lower amount of renaming in LLVM context
100  // Renaming occurs because we load all source modules to the same context
101  // and declaration with existing name gets renamed (i.e Foo -> Foo.42).
102  // As a result we may get several different types in the destination
103  // module, which are in fact the same.
104  for (Type *Ty : SpeculativeTypes)
105  if (auto *STy = dyn_cast<StructType>(Ty))
106  if (STy->hasName())
107  STy->setName("");
108  }
109  SpeculativeTypes.clear();
110  SpeculativeDstOpaqueTypes.clear();
111 }
112 
113 /// Recursively walk this pair of types, returning true if they are isomorphic,
114 /// false if they are not.
115 bool TypeMapTy::areTypesIsomorphic(Type *DstTy, Type *SrcTy) {
116  // Two types with differing kinds are clearly not isomorphic.
117  if (DstTy->getTypeID() != SrcTy->getTypeID())
118  return false;
119 
120  // If we have an entry in the MappedTypes table, then we have our answer.
121  Type *&Entry = MappedTypes[SrcTy];
122  if (Entry)
123  return Entry == DstTy;
124 
125  // Two identical types are clearly isomorphic. Remember this
126  // non-speculatively.
127  if (DstTy == SrcTy) {
128  Entry = DstTy;
129  return true;
130  }
131 
132  // Okay, we have two types with identical kinds that we haven't seen before.
133 
134  // If this is an opaque struct type, special case it.
135  if (StructType *SSTy = dyn_cast<StructType>(SrcTy)) {
136  // Mapping an opaque type to any struct, just keep the dest struct.
137  if (SSTy->isOpaque()) {
138  Entry = DstTy;
139  SpeculativeTypes.push_back(SrcTy);
140  return true;
141  }
142 
143  // Mapping a non-opaque source type to an opaque dest. If this is the first
144  // type that we're mapping onto this destination type then we succeed. Keep
145  // the dest, but fill it in later. If this is the second (different) type
146  // that we're trying to map onto the same opaque type then we fail.
147  if (cast<StructType>(DstTy)->isOpaque()) {
148  // We can only map one source type onto the opaque destination type.
149  if (!DstResolvedOpaqueTypes.insert(cast<StructType>(DstTy)).second)
150  return false;
151  SrcDefinitionsToResolve.push_back(SSTy);
152  SpeculativeTypes.push_back(SrcTy);
153  SpeculativeDstOpaqueTypes.push_back(cast<StructType>(DstTy));
154  Entry = DstTy;
155  return true;
156  }
157  }
158 
159  // If the number of subtypes disagree between the two types, then we fail.
160  if (SrcTy->getNumContainedTypes() != DstTy->getNumContainedTypes())
161  return false;
162 
163  // Fail if any of the extra properties (e.g. array size) of the type disagree.
164  if (isa<IntegerType>(DstTy))
165  return false; // bitwidth disagrees.
166  if (PointerType *PT = dyn_cast<PointerType>(DstTy)) {
167  if (PT->getAddressSpace() != cast<PointerType>(SrcTy)->getAddressSpace())
168  return false;
169  } else if (FunctionType *FT = dyn_cast<FunctionType>(DstTy)) {
170  if (FT->isVarArg() != cast<FunctionType>(SrcTy)->isVarArg())
171  return false;
172  } else if (StructType *DSTy = dyn_cast<StructType>(DstTy)) {
173  StructType *SSTy = cast<StructType>(SrcTy);
174  if (DSTy->isLiteral() != SSTy->isLiteral() ||
175  DSTy->isPacked() != SSTy->isPacked())
176  return false;
177  } else if (auto *DArrTy = dyn_cast<ArrayType>(DstTy)) {
178  if (DArrTy->getNumElements() != cast<ArrayType>(SrcTy)->getNumElements())
179  return false;
180  } else if (auto *DVecTy = dyn_cast<VectorType>(DstTy)) {
181  if (DVecTy->getElementCount() != cast<VectorType>(SrcTy)->getElementCount())
182  return false;
183  }
184 
185  // Otherwise, we speculate that these two types will line up and recursively
186  // check the subelements.
187  Entry = DstTy;
188  SpeculativeTypes.push_back(SrcTy);
189 
190  for (unsigned I = 0, E = SrcTy->getNumContainedTypes(); I != E; ++I)
191  if (!areTypesIsomorphic(DstTy->getContainedType(I),
192  SrcTy->getContainedType(I)))
193  return false;
194 
195  // If everything seems to have lined up, then everything is great.
196  return true;
197 }
198 
199 void TypeMapTy::linkDefinedTypeBodies() {
200  SmallVector<Type *, 16> Elements;
201  for (StructType *SrcSTy : SrcDefinitionsToResolve) {
202  StructType *DstSTy = cast<StructType>(MappedTypes[SrcSTy]);
203  assert(DstSTy->isOpaque());
204 
205  // Map the body of the source type over to a new body for the dest type.
206  Elements.resize(SrcSTy->getNumElements());
207  for (unsigned I = 0, E = Elements.size(); I != E; ++I)
208  Elements[I] = get(SrcSTy->getElementType(I));
209 
210  DstSTy->setBody(Elements, SrcSTy->isPacked());
211  DstStructTypesSet.switchToNonOpaque(DstSTy);
212  }
213  SrcDefinitionsToResolve.clear();
214  DstResolvedOpaqueTypes.clear();
215 }
216 
217 void TypeMapTy::finishType(StructType *DTy, StructType *STy,
218  ArrayRef<Type *> ETypes) {
219  DTy->setBody(ETypes, STy->isPacked());
220 
221  // Steal STy's name.
222  if (STy->hasName()) {
223  SmallString<16> TmpName = STy->getName();
224  STy->setName("");
225  DTy->setName(TmpName);
226  }
227 
228  DstStructTypesSet.addNonOpaque(DTy);
229 }
230 
231 Type *TypeMapTy::get(Type *Ty) {
233  return get(Ty, Visited);
234 }
235 
237  // If we already have an entry for this type, return it.
238  Type **Entry = &MappedTypes[Ty];
239  if (*Entry)
240  return *Entry;
241 
242  // These are types that LLVM itself will unique.
243  bool IsUniqued = !isa<StructType>(Ty) || cast<StructType>(Ty)->isLiteral();
244 
245  if (!IsUniqued) {
246 #ifndef NDEBUG
247  for (auto &Pair : MappedTypes) {
248  assert(!(Pair.first != Ty && Pair.second == Ty) &&
249  "mapping to a source type");
250  }
251 #endif
252 
253  if (!Visited.insert(cast<StructType>(Ty)).second) {
255  return *Entry = DTy;
256  }
257  }
258 
259  // If this is not a recursive type, then just map all of the elements and
260  // then rebuild the type from inside out.
261  SmallVector<Type *, 4> ElementTypes;
262 
263  // If there are no element types to map, then the type is itself. This is
264  // true for the anonymous {} struct, things like 'float', integers, etc.
265  if (Ty->getNumContainedTypes() == 0 && IsUniqued)
266  return *Entry = Ty;
267 
268  // Remap all of the elements, keeping track of whether any of them change.
269  bool AnyChange = false;
270  ElementTypes.resize(Ty->getNumContainedTypes());
271  for (unsigned I = 0, E = Ty->getNumContainedTypes(); I != E; ++I) {
272  ElementTypes[I] = get(Ty->getContainedType(I), Visited);
273  AnyChange |= ElementTypes[I] != Ty->getContainedType(I);
274  }
275 
276  // If we found our type while recursively processing stuff, just use it.
277  Entry = &MappedTypes[Ty];
278  if (*Entry) {
279  if (auto *DTy = dyn_cast<StructType>(*Entry)) {
280  if (DTy->isOpaque()) {
281  auto *STy = cast<StructType>(Ty);
282  finishType(DTy, STy, ElementTypes);
283  }
284  }
285  return *Entry;
286  }
287 
288  // If all of the element types mapped directly over and the type is not
289  // a named struct, then the type is usable as-is.
290  if (!AnyChange && IsUniqued)
291  return *Entry = Ty;
292 
293  // Otherwise, rebuild a modified type.
294  switch (Ty->getTypeID()) {
295  default:
296  llvm_unreachable("unknown derived type to remap");
297  case Type::ArrayTyID:
298  return *Entry = ArrayType::get(ElementTypes[0],
299  cast<ArrayType>(Ty)->getNumElements());
302  return *Entry = VectorType::get(ElementTypes[0],
303  cast<VectorType>(Ty)->getElementCount());
304  case Type::PointerTyID:
305  return *Entry = PointerType::get(ElementTypes[0],
306  cast<PointerType>(Ty)->getAddressSpace());
307  case Type::FunctionTyID:
308  return *Entry = FunctionType::get(ElementTypes[0],
309  makeArrayRef(ElementTypes).slice(1),
310  cast<FunctionType>(Ty)->isVarArg());
311  case Type::StructTyID: {
312  auto *STy = cast<StructType>(Ty);
313  bool IsPacked = STy->isPacked();
314  if (IsUniqued)
315  return *Entry = StructType::get(Ty->getContext(), ElementTypes, IsPacked);
316 
317  // If the type is opaque, we can just use it directly.
318  if (STy->isOpaque()) {
319  DstStructTypesSet.addOpaque(STy);
320  return *Entry = Ty;
321  }
322 
323  if (StructType *OldT =
324  DstStructTypesSet.findNonOpaque(ElementTypes, IsPacked)) {
325  STy->setName("");
326  return *Entry = OldT;
327  }
328 
329  if (!AnyChange) {
330  DstStructTypesSet.addNonOpaque(STy);
331  return *Entry = Ty;
332  }
333 
335  finishType(DTy, STy, ElementTypes);
336  return *Entry = DTy;
337  }
338  }
339 }
340 
342  const Twine &Msg)
343  : DiagnosticInfo(DK_Linker, Severity), Msg(Msg) {}
345 
346 //===----------------------------------------------------------------------===//
347 // IRLinker implementation.
348 //===----------------------------------------------------------------------===//
349 
350 namespace {
351 class IRLinker;
352 
353 /// Creates prototypes for functions that are lazily linked on the fly. This
354 /// speeds up linking for modules with many/ lazily linked functions of which
355 /// few get used.
356 class GlobalValueMaterializer final : public ValueMaterializer {
357  IRLinker &TheIRLinker;
358 
359 public:
360  GlobalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
361  Value *materialize(Value *V) override;
362 };
363 
364 class LocalValueMaterializer final : public ValueMaterializer {
365  IRLinker &TheIRLinker;
366 
367 public:
368  LocalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
369  Value *materialize(Value *V) override;
370 };
371 
372 /// Type of the Metadata map in \a ValueToValueMapTy.
374 
375 /// This is responsible for keeping track of the state used for moving data
376 /// from SrcM to DstM.
377 class IRLinker {
378  Module &DstM;
379  std::unique_ptr<Module> SrcM;
380 
381  /// See IRMover::move().
382  std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor;
383 
384  TypeMapTy TypeMap;
385  GlobalValueMaterializer GValMaterializer;
386  LocalValueMaterializer LValMaterializer;
387 
388  /// A metadata map that's shared between IRLinker instances.
389  MDMapT &SharedMDs;
390 
391  /// Mapping of values from what they used to be in Src, to what they are now
392  /// in DstM. ValueToValueMapTy is a ValueMap, which involves some overhead
393  /// due to the use of Value handles which the Linker doesn't actually need,
394  /// but this allows us to reuse the ValueMapper code.
396  ValueToValueMapTy IndirectSymbolValueMap;
397 
398  DenseSet<GlobalValue *> ValuesToLink;
399  std::vector<GlobalValue *> Worklist;
400  std::vector<std::pair<GlobalValue *, Value*>> RAUWWorklist;
401 
402  void maybeAdd(GlobalValue *GV) {
403  if (ValuesToLink.insert(GV).second)
404  Worklist.push_back(GV);
405  }
406 
407  /// Whether we are importing globals for ThinLTO, as opposed to linking the
408  /// source module. If this flag is set, it means that we can rely on some
409  /// other object file to define any non-GlobalValue entities defined by the
410  /// source module. This currently causes us to not link retained types in
411  /// debug info metadata and module inline asm.
412  bool IsPerformingImport;
413 
414  /// Set to true when all global value body linking is complete (including
415  /// lazy linking). Used to prevent metadata linking from creating new
416  /// references.
417  bool DoneLinkingBodies = false;
418 
419  /// The Error encountered during materialization. We use an Optional here to
420  /// avoid needing to manage an unconsumed success value.
421  Optional<Error> FoundError;
422  void setError(Error E) {
423  if (E)
424  FoundError = std::move(E);
425  }
426 
427  /// Most of the errors produced by this module are inconvertible StringErrors.
428  /// This convenience function lets us return one of those more easily.
429  Error stringErr(const Twine &T) {
430  return make_error<StringError>(T, inconvertibleErrorCode());
431  }
432 
433  /// Entry point for mapping values and alternate context for mapping aliases.
434  ValueMapper Mapper;
435  unsigned IndirectSymbolMCID;
436 
437  /// Handles cloning of a global values from the source module into
438  /// the destination module, including setting the attributes and visibility.
439  GlobalValue *copyGlobalValueProto(const GlobalValue *SGV, bool ForDefinition);
440 
441  void emitWarning(const Twine &Message) {
442  SrcM->getContext().diagnose(LinkDiagnosticInfo(DS_Warning, Message));
443  }
444 
445  /// Given a global in the source module, return the global in the
446  /// destination module that is being linked to, if any.
447  GlobalValue *getLinkedToGlobal(const GlobalValue *SrcGV) {
448  // If the source has no name it can't link. If it has local linkage,
449  // there is no name match-up going on.
450  if (!SrcGV->hasName() || SrcGV->hasLocalLinkage())
451  return nullptr;
452 
453  // Otherwise see if we have a match in the destination module's symtab.
454  GlobalValue *DGV = DstM.getNamedValue(SrcGV->getName());
455  if (!DGV)
456  return nullptr;
457 
458  // If we found a global with the same name in the dest module, but it has
459  // internal linkage, we are really not doing any linkage here.
460  if (DGV->hasLocalLinkage())
461  return nullptr;
462 
463  // If we found an intrinsic declaration with mismatching prototypes, we
464  // probably had a nameclash. Don't use that version.
465  if (auto *FDGV = dyn_cast<Function>(DGV))
466  if (FDGV->isIntrinsic())
467  if (const auto *FSrcGV = dyn_cast<Function>(SrcGV))
468  if (FDGV->getFunctionType() != TypeMap.get(FSrcGV->getFunctionType()))
469  return nullptr;
470 
471  // Otherwise, we do in fact link to the destination global.
472  return DGV;
473  }
474 
475  void computeTypeMapping();
476 
477  Expected<Constant *> linkAppendingVarProto(GlobalVariable *DstGV,
478  const GlobalVariable *SrcGV);
479 
480  /// Given the GlobaValue \p SGV in the source module, and the matching
481  /// GlobalValue \p DGV (if any), return true if the linker will pull \p SGV
482  /// into the destination module.
483  ///
484  /// Note this code may call the client-provided \p AddLazyFor.
485  bool shouldLink(GlobalValue *DGV, GlobalValue &SGV);
486  Expected<Constant *> linkGlobalValueProto(GlobalValue *GV,
487  bool ForIndirectSymbol);
488 
489  Error linkModuleFlagsMetadata();
490 
491  void linkGlobalVariable(GlobalVariable &Dst, GlobalVariable &Src);
492  Error linkFunctionBody(Function &Dst, Function &Src);
493  void linkIndirectSymbolBody(GlobalIndirectSymbol &Dst,
494  GlobalIndirectSymbol &Src);
495  Error linkGlobalValueBody(GlobalValue &Dst, GlobalValue &Src);
496 
497  /// Replace all types in the source AttributeList with the
498  /// corresponding destination type.
499  AttributeList mapAttributeTypes(LLVMContext &C, AttributeList Attrs);
500 
501  /// Functions that take care of cloning a specific global value type
502  /// into the destination module.
503  GlobalVariable *copyGlobalVariableProto(const GlobalVariable *SGVar);
504  Function *copyFunctionProto(const Function *SF);
505  GlobalValue *copyGlobalIndirectSymbolProto(const GlobalIndirectSymbol *SGIS);
506 
507  /// Perform "replace all uses with" operations. These work items need to be
508  /// performed as part of materialization, but we postpone them to happen after
509  /// materialization is done. The materializer called by ValueMapper is not
510  /// expected to delete constants, as ValueMapper is holding pointers to some
511  /// of them, but constant destruction may be indirectly triggered by RAUW.
512  /// Hence, the need to move this out of the materialization call chain.
513  void flushRAUWWorklist();
514 
515  /// When importing for ThinLTO, prevent importing of types listed on
516  /// the DICompileUnit that we don't need a copy of in the importing
517  /// module.
518  void prepareCompileUnitsForImport();
519  void linkNamedMDNodes();
520 
521 public:
522  IRLinker(Module &DstM, MDMapT &SharedMDs,
523  IRMover::IdentifiedStructTypeSet &Set, std::unique_ptr<Module> SrcM,
524  ArrayRef<GlobalValue *> ValuesToLink,
525  std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor,
526  bool IsPerformingImport)
527  : DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(std::move(AddLazyFor)),
528  TypeMap(Set), GValMaterializer(*this), LValMaterializer(*this),
529  SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
531  &TypeMap, &GValMaterializer),
532  IndirectSymbolMCID(Mapper.registerAlternateMappingContext(
533  IndirectSymbolValueMap, &LValMaterializer)) {
534  ValueMap.getMDMap() = std::move(SharedMDs);
535  for (GlobalValue *GV : ValuesToLink)
536  maybeAdd(GV);
537  if (IsPerformingImport)
538  prepareCompileUnitsForImport();
539  }
540  ~IRLinker() { SharedMDs = std::move(*ValueMap.getMDMap()); }
541 
542  Error run();
543  Value *materialize(Value *V, bool ForIndirectSymbol);
544 };
545 }
546 
547 /// The LLVM SymbolTable class autorenames globals that conflict in the symbol
548 /// table. This is good for all clients except for us. Go through the trouble
549 /// to force this back.
551  // If the global doesn't force its name or if it already has the right name,
552  // there is nothing for us to do.
553  if (GV->hasLocalLinkage() || GV->getName() == Name)
554  return;
555 
556  Module *M = GV->getParent();
557 
558  // If there is a conflict, rename the conflict.
559  if (GlobalValue *ConflictGV = M->getNamedValue(Name)) {
560  GV->takeName(ConflictGV);
561  ConflictGV->setName(Name); // This will cause ConflictGV to get renamed
562  assert(ConflictGV->getName() != Name && "forceRenaming didn't work");
563  } else {
564  GV->setName(Name); // Force the name back
565  }
566 }
567 
568 Value *GlobalValueMaterializer::materialize(Value *SGV) {
569  return TheIRLinker.materialize(SGV, false);
570 }
571 
572 Value *LocalValueMaterializer::materialize(Value *SGV) {
573  return TheIRLinker.materialize(SGV, true);
574 }
575 
576 Value *IRLinker::materialize(Value *V, bool ForIndirectSymbol) {
577  auto *SGV = dyn_cast<GlobalValue>(V);
578  if (!SGV)
579  return nullptr;
580 
581  // When linking a global from other modules than source & dest, skip
582  // materializing it because it would be mapped later when its containing
583  // module is linked. Linking it now would potentially pull in many types that
584  // may not be mapped properly.
585  if (SGV->getParent() != &DstM && SGV->getParent() != SrcM.get())
586  return nullptr;
587 
588  Expected<Constant *> NewProto = linkGlobalValueProto(SGV, ForIndirectSymbol);
589  if (!NewProto) {
590  setError(NewProto.takeError());
591  return nullptr;
592  }
593  if (!*NewProto)
594  return nullptr;
595 
596  GlobalValue *New = dyn_cast<GlobalValue>(*NewProto);
597  if (!New)
598  return *NewProto;
599 
600  // If we already created the body, just return.
601  if (auto *F = dyn_cast<Function>(New)) {
602  if (!F->isDeclaration())
603  return New;
604  } else if (auto *V = dyn_cast<GlobalVariable>(New)) {
605  if (V->hasInitializer() || V->hasAppendingLinkage())
606  return New;
607  } else {
608  auto *IS = cast<GlobalIndirectSymbol>(New);
609  if (IS->getIndirectSymbol())
610  return New;
611  }
612 
613  // If the global is being linked for an indirect symbol, it may have already
614  // been scheduled to satisfy a regular symbol. Similarly, a global being linked
615  // for a regular symbol may have already been scheduled for an indirect
616  // symbol. Check for these cases by looking in the other value map and
617  // confirming the same value has been scheduled. If there is an entry in the
618  // ValueMap but the value is different, it means that the value already had a
619  // definition in the destination module (linkonce for instance), but we need a
620  // new definition for the indirect symbol ("New" will be different).
621  if ((ForIndirectSymbol && ValueMap.lookup(SGV) == New) ||
622  (!ForIndirectSymbol && IndirectSymbolValueMap.lookup(SGV) == New))
623  return New;
624 
625  if (ForIndirectSymbol || shouldLink(New, *SGV))
626  setError(linkGlobalValueBody(*New, *SGV));
627 
628  return New;
629 }
630 
631 /// Loop through the global variables in the src module and merge them into the
632 /// dest module.
633 GlobalVariable *IRLinker::copyGlobalVariableProto(const GlobalVariable *SGVar) {
634  // No linking to be performed or linking from the source: simply create an
635  // identical version of the symbol over in the dest module... the
636  // initializer will be filled in later by LinkGlobalInits.
637  GlobalVariable *NewDGV =
638  new GlobalVariable(DstM, TypeMap.get(SGVar->getValueType()),
640  /*init*/ nullptr, SGVar->getName(),
641  /*insertbefore*/ nullptr, SGVar->getThreadLocalMode(),
642  SGVar->getAddressSpace());
643  NewDGV->setAlignment(MaybeAlign(SGVar->getAlignment()));
644  NewDGV->copyAttributesFrom(SGVar);
645  return NewDGV;
646 }
647 
648 AttributeList IRLinker::mapAttributeTypes(LLVMContext &C, AttributeList Attrs) {
649  for (unsigned i = 0; i < Attrs.getNumAttrSets(); ++i) {
650  for (Attribute::AttrKind TypedAttr :
651  {Attribute::ByVal, Attribute::StructRet, Attribute::ByRef,
652  Attribute::InAlloca}) {
653  if (Attrs.hasAttribute(i, TypedAttr)) {
654  if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) {
655  Attrs = Attrs.replaceAttributeType(C, i, TypedAttr, TypeMap.get(Ty));
656  break;
657  }
658  }
659  }
660  }
661  return Attrs;
662 }
663 
664 /// Link the function in the source module into the destination module if
665 /// needed, setting up mapping information.
666 Function *IRLinker::copyFunctionProto(const Function *SF) {
667  // If there is no linkage to be performed or we are linking from the source,
668  // bring SF over.
669  auto *F = Function::Create(TypeMap.get(SF->getFunctionType()),
671  SF->getAddressSpace(), SF->getName(), &DstM);
672  F->copyAttributesFrom(SF);
673  F->setAttributes(mapAttributeTypes(F->getContext(), F->getAttributes()));
674  return F;
675 }
676 
677 /// Set up prototypes for any indirect symbols that come over from the source
678 /// module.
679 GlobalValue *
680 IRLinker::copyGlobalIndirectSymbolProto(const GlobalIndirectSymbol *SGIS) {
681  // If there is no linkage to be performed or we're linking from the source,
682  // bring over SGA.
683  auto *Ty = TypeMap.get(SGIS->getValueType());
685  if (isa<GlobalAlias>(SGIS))
686  GIS = GlobalAlias::create(Ty, SGIS->getAddressSpace(),
688  &DstM);
689  else
690  GIS = GlobalIFunc::create(Ty, SGIS->getAddressSpace(),
692  nullptr, &DstM);
693  GIS->copyAttributesFrom(SGIS);
694  return GIS;
695 }
696 
697 GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV,
698  bool ForDefinition) {
699  GlobalValue *NewGV;
700  if (auto *SGVar = dyn_cast<GlobalVariable>(SGV)) {
701  NewGV = copyGlobalVariableProto(SGVar);
702  } else if (auto *SF = dyn_cast<Function>(SGV)) {
703  NewGV = copyFunctionProto(SF);
704  } else {
705  if (ForDefinition)
706  NewGV = copyGlobalIndirectSymbolProto(cast<GlobalIndirectSymbol>(SGV));
707  else if (SGV->getValueType()->isFunctionTy())
708  NewGV =
709  Function::Create(cast<FunctionType>(TypeMap.get(SGV->getValueType())),
711  SGV->getName(), &DstM);
712  else
713  NewGV =
714  new GlobalVariable(DstM, TypeMap.get(SGV->getValueType()),
715  /*isConstant*/ false, GlobalValue::ExternalLinkage,
716  /*init*/ nullptr, SGV->getName(),
717  /*insertbefore*/ nullptr,
718  SGV->getThreadLocalMode(), SGV->getAddressSpace());
719  }
720 
721  if (ForDefinition)
722  NewGV->setLinkage(SGV->getLinkage());
723  else if (SGV->hasExternalWeakLinkage())
725 
726  if (auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
727  // Metadata for global variables and function declarations is copied eagerly.
728  if (isa<GlobalVariable>(SGV) || SGV->isDeclaration())
729  NewGO->copyMetadata(cast<GlobalObject>(SGV), 0);
730  }
731 
732  // Remove these copied constants in case this stays a declaration, since
733  // they point to the source module. If the def is linked the values will
734  // be mapped in during linkFunctionBody.
735  if (auto *NewF = dyn_cast<Function>(NewGV)) {
736  NewF->setPersonalityFn(nullptr);
737  NewF->setPrefixData(nullptr);
738  NewF->setPrologueData(nullptr);
739  }
740 
741  return NewGV;
742 }
743 
745  size_t DotPos = Name.rfind('.');
746  return (DotPos == 0 || DotPos == StringRef::npos || Name.back() == '.' ||
747  !isdigit(static_cast<unsigned char>(Name[DotPos + 1])))
748  ? Name
749  : Name.substr(0, DotPos);
750 }
751 
752 /// Loop over all of the linked values to compute type mappings. For example,
753 /// if we link "extern Foo *x" and "Foo *x = NULL", then we have two struct
754 /// types 'Foo' but one got renamed when the module was loaded into the same
755 /// LLVMContext.
756 void IRLinker::computeTypeMapping() {
757  for (GlobalValue &SGV : SrcM->globals()) {
758  GlobalValue *DGV = getLinkedToGlobal(&SGV);
759  if (!DGV)
760  continue;
761 
762  if (!DGV->hasAppendingLinkage() || !SGV.hasAppendingLinkage()) {
763  TypeMap.addTypeMapping(DGV->getType(), SGV.getType());
764  continue;
765  }
766 
767  // Unify the element type of appending arrays.
768  ArrayType *DAT = cast<ArrayType>(DGV->getValueType());
769  ArrayType *SAT = cast<ArrayType>(SGV.getValueType());
770  TypeMap.addTypeMapping(DAT->getElementType(), SAT->getElementType());
771  }
772 
773  for (GlobalValue &SGV : *SrcM)
774  if (GlobalValue *DGV = getLinkedToGlobal(&SGV)) {
775  if (DGV->getType() == SGV.getType()) {
776  // If the types of DGV and SGV are the same, it means that DGV is from
777  // the source module and got added to DstM from a shared metadata. We
778  // shouldn't map this type to itself in case the type's components get
779  // remapped to a new type from DstM (for instance, during the loop over
780  // SrcM->getIdentifiedStructTypes() below).
781  continue;
782  }
783 
784  TypeMap.addTypeMapping(DGV->getType(), SGV.getType());
785  }
786 
787  for (GlobalValue &SGV : SrcM->aliases())
788  if (GlobalValue *DGV = getLinkedToGlobal(&SGV))
789  TypeMap.addTypeMapping(DGV->getType(), SGV.getType());
790 
791  // Incorporate types by name, scanning all the types in the source module.
792  // At this point, the destination module may have a type "%foo = { i32 }" for
793  // example. When the source module got loaded into the same LLVMContext, if
794  // it had the same type, it would have been renamed to "%foo.42 = { i32 }".
795  std::vector<StructType *> Types = SrcM->getIdentifiedStructTypes();
796  for (StructType *ST : Types) {
797  if (!ST->hasName())
798  continue;
799 
800  if (TypeMap.DstStructTypesSet.hasType(ST)) {
801  // This is actually a type from the destination module.
802  // getIdentifiedStructTypes() can have found it by walking debug info
803  // metadata nodes, some of which get linked by name when ODR Type Uniquing
804  // is enabled on the Context, from the source to the destination module.
805  continue;
806  }
807 
808  auto STTypePrefix = getTypeNamePrefix(ST->getName());
809  if (STTypePrefix.size() == ST->getName().size())
810  continue;
811 
812  // Check to see if the destination module has a struct with the prefix name.
813  StructType *DST = StructType::getTypeByName(ST->getContext(), STTypePrefix);
814  if (!DST)
815  continue;
816 
817  // Don't use it if this actually came from the source module. They're in
818  // the same LLVMContext after all. Also don't use it unless the type is
819  // actually used in the destination module. This can happen in situations
820  // like this:
821  //
822  // Module A Module B
823  // -------- --------
824  // %Z = type { %A } %B = type { %C.1 }
825  // %A = type { %B.1, [7 x i8] } %C.1 = type { i8* }
826  // %B.1 = type { %C } %A.2 = type { %B.3, [5 x i8] }
827  // %C = type { i8* } %B.3 = type { %C.1 }
828  //
829  // When we link Module B with Module A, the '%B' in Module B is
830  // used. However, that would then use '%C.1'. But when we process '%C.1',
831  // we prefer to take the '%C' version. So we are then left with both
832  // '%C.1' and '%C' being used for the same types. This leads to some
833  // variables using one type and some using the other.
834  if (TypeMap.DstStructTypesSet.hasType(DST))
835  TypeMap.addTypeMapping(DST, ST);
836  }
837 
838  // Now that we have discovered all of the type equivalences, get a body for
839  // any 'opaque' types in the dest module that are now resolved.
840  TypeMap.linkDefinedTypeBodies();
841 }
842 
843 static void getArrayElements(const Constant *C,
845  unsigned NumElements = cast<ArrayType>(C->getType())->getNumElements();
846 
847  for (unsigned i = 0; i != NumElements; ++i)
848  Dest.push_back(C->getAggregateElement(i));
849 }
850 
851 /// If there were any appending global variables, link them together now.
853 IRLinker::linkAppendingVarProto(GlobalVariable *DstGV,
854  const GlobalVariable *SrcGV) {
855  // Check that both variables have compatible properties.
856  if (DstGV && !DstGV->isDeclaration() && !SrcGV->isDeclaration()) {
857  if (!SrcGV->hasAppendingLinkage() || !DstGV->hasAppendingLinkage())
858  return stringErr(
859  "Linking globals named '" + SrcGV->getName() +
860  "': can only link appending global with another appending "
861  "global!");
862 
863  if (DstGV->isConstant() != SrcGV->isConstant())
864  return stringErr("Appending variables linked with different const'ness!");
865 
866  if (DstGV->getAlignment() != SrcGV->getAlignment())
867  return stringErr(
868  "Appending variables with different alignment need to be linked!");
869 
870  if (DstGV->getVisibility() != SrcGV->getVisibility())
871  return stringErr(
872  "Appending variables with different visibility need to be linked!");
873 
874  if (DstGV->hasGlobalUnnamedAddr() != SrcGV->hasGlobalUnnamedAddr())
875  return stringErr(
876  "Appending variables with different unnamed_addr need to be linked!");
877 
878  if (DstGV->getSection() != SrcGV->getSection())
879  return stringErr(
880  "Appending variables with different section name need to be linked!");
881  }
882 
883  // Do not need to do anything if source is a declaration.
884  if (SrcGV->isDeclaration())
885  return DstGV;
886 
887  Type *EltTy = cast<ArrayType>(TypeMap.get(SrcGV->getValueType()))
888  ->getElementType();
889 
890  // FIXME: This upgrade is done during linking to support the C API. Once the
891  // old form is deprecated, we should move this upgrade to
892  // llvm::UpgradeGlobalVariable() and simplify the logic here and in
893  // Mapper::mapAppendingVariable() in ValueMapper.cpp.
894  StringRef Name = SrcGV->getName();
895  bool IsNewStructor = false;
896  bool IsOldStructor = false;
897  if (Name == "llvm.global_ctors" || Name == "llvm.global_dtors") {
898  if (cast<StructType>(EltTy)->getNumElements() == 3)
899  IsNewStructor = true;
900  else
901  IsOldStructor = true;
902  }
903 
904  PointerType *VoidPtrTy = Type::getInt8Ty(SrcGV->getContext())->getPointerTo();
905  if (IsOldStructor) {
906  auto &ST = *cast<StructType>(EltTy);
907  Type *Tys[3] = {ST.getElementType(0), ST.getElementType(1), VoidPtrTy};
908  EltTy = StructType::get(SrcGV->getContext(), Tys, false);
909  }
910 
911  uint64_t DstNumElements = 0;
912  if (DstGV && !DstGV->isDeclaration()) {
913  ArrayType *DstTy = cast<ArrayType>(DstGV->getValueType());
914  DstNumElements = DstTy->getNumElements();
915 
916  // Check to see that they two arrays agree on type.
917  if (EltTy != DstTy->getElementType())
918  return stringErr("Appending variables with different element types!");
919  }
920 
921  SmallVector<Constant *, 16> SrcElements;
922  getArrayElements(SrcGV->getInitializer(), SrcElements);
923 
924  if (IsNewStructor) {
925  erase_if(SrcElements, [this](Constant *E) {
926  auto *Key =
927  dyn_cast<GlobalValue>(E->getAggregateElement(2)->stripPointerCasts());
928  if (!Key)
929  return false;
930  GlobalValue *DGV = getLinkedToGlobal(Key);
931  return !shouldLink(DGV, *Key);
932  });
933  }
934  uint64_t NewSize = DstNumElements + SrcElements.size();
935  ArrayType *NewType = ArrayType::get(EltTy, NewSize);
936 
937  // Create the new global variable.
938  GlobalVariable *NG = new GlobalVariable(
939  DstM, NewType, SrcGV->isConstant(), SrcGV->getLinkage(),
940  /*init*/ nullptr, /*name*/ "", DstGV, SrcGV->getThreadLocalMode(),
941  SrcGV->getAddressSpace());
942 
943  NG->copyAttributesFrom(SrcGV);
944  forceRenaming(NG, SrcGV->getName());
945 
946  Constant *Ret = ConstantExpr::getBitCast(NG, TypeMap.get(SrcGV->getType()));
947 
949  *NG,
950  (DstGV && !DstGV->isDeclaration()) ? DstGV->getInitializer() : nullptr,
951  IsOldStructor, SrcElements);
952 
953  // Replace any uses of the two global variables with uses of the new
954  // global.
955  if (DstGV) {
956  RAUWWorklist.push_back(
957  std::make_pair(DstGV, ConstantExpr::getBitCast(NG, DstGV->getType())));
958  }
959 
960  return Ret;
961 }
962 
963 bool IRLinker::shouldLink(GlobalValue *DGV, GlobalValue &SGV) {
964  if (ValuesToLink.count(&SGV) || SGV.hasLocalLinkage())
965  return true;
966 
967  if (DGV && !DGV->isDeclarationForLinker())
968  return false;
969 
970  if (SGV.isDeclaration() || DoneLinkingBodies)
971  return false;
972 
973  // Callback to the client to give a chance to lazily add the Global to the
974  // list of value to link.
975  bool LazilyAdded = false;
976  AddLazyFor(SGV, [this, &LazilyAdded](GlobalValue &GV) {
977  maybeAdd(&GV);
978  LazilyAdded = true;
979  });
980  return LazilyAdded;
981 }
982 
983 Expected<Constant *> IRLinker::linkGlobalValueProto(GlobalValue *SGV,
984  bool ForIndirectSymbol) {
985  GlobalValue *DGV = getLinkedToGlobal(SGV);
986 
987  bool ShouldLink = shouldLink(DGV, *SGV);
988 
989  // just missing from map
990  if (ShouldLink) {
991  auto I = ValueMap.find(SGV);
992  if (I != ValueMap.end())
993  return cast<Constant>(I->second);
994 
995  I = IndirectSymbolValueMap.find(SGV);
996  if (I != IndirectSymbolValueMap.end())
997  return cast<Constant>(I->second);
998  }
999 
1000  if (!ShouldLink && ForIndirectSymbol)
1001  DGV = nullptr;
1002 
1003  // Handle the ultra special appending linkage case first.
1004  if (SGV->hasAppendingLinkage() || (DGV && DGV->hasAppendingLinkage()))
1005  return linkAppendingVarProto(cast_or_null<GlobalVariable>(DGV),
1006  cast<GlobalVariable>(SGV));
1007 
1008  bool NeedsRenaming = false;
1009  GlobalValue *NewGV;
1010  if (DGV && !ShouldLink) {
1011  NewGV = DGV;
1012  } else {
1013  // If we are done linking global value bodies (i.e. we are performing
1014  // metadata linking), don't link in the global value due to this
1015  // reference, simply map it to null.
1016  if (DoneLinkingBodies)
1017  return nullptr;
1018 
1019  NewGV = copyGlobalValueProto(SGV, ShouldLink || ForIndirectSymbol);
1020  if (ShouldLink || !ForIndirectSymbol)
1021  NeedsRenaming = true;
1022  }
1023 
1024  // Overloaded intrinsics have overloaded types names as part of their
1025  // names. If we renamed overloaded types we should rename the intrinsic
1026  // as well.
1027  if (Function *F = dyn_cast<Function>(NewGV))
1028  if (auto Remangled = Intrinsic::remangleIntrinsicFunction(F)) {
1029  NewGV->eraseFromParent();
1030  NewGV = Remangled.getValue();
1031  NeedsRenaming = false;
1032  }
1033 
1034  if (NeedsRenaming)
1035  forceRenaming(NewGV, SGV->getName());
1036 
1037  if (ShouldLink || ForIndirectSymbol) {
1038  if (const Comdat *SC = SGV->getComdat()) {
1039  if (auto *GO = dyn_cast<GlobalObject>(NewGV)) {
1040  Comdat *DC = DstM.getOrInsertComdat(SC->getName());
1041  DC->setSelectionKind(SC->getSelectionKind());
1042  GO->setComdat(DC);
1043  }
1044  }
1045  }
1046 
1047  if (!ShouldLink && ForIndirectSymbol)
1049 
1050  Constant *C = NewGV;
1051  // Only create a bitcast if necessary. In particular, with
1052  // DebugTypeODRUniquing we may reach metadata in the destination module
1053  // containing a GV from the source module, in which case SGV will be
1054  // the same as DGV and NewGV, and TypeMap.get() will assert since it
1055  // assumes it is being invoked on a type in the source module.
1056  if (DGV && NewGV != SGV) {
1058  NewGV, TypeMap.get(SGV->getType()));
1059  }
1060 
1061  if (DGV && NewGV != DGV) {
1062  // Schedule "replace all uses with" to happen after materializing is
1063  // done. It is not safe to do it now, since ValueMapper may be holding
1064  // pointers to constants that will get deleted if RAUW runs.
1065  RAUWWorklist.push_back(std::make_pair(
1066  DGV,
1068  }
1069 
1070  return C;
1071 }
1072 
1073 /// Update the initializers in the Dest module now that all globals that may be
1074 /// referenced are in Dest.
1075 void IRLinker::linkGlobalVariable(GlobalVariable &Dst, GlobalVariable &Src) {
1076  // Figure out what the initializer looks like in the dest module.
1077  Mapper.scheduleMapGlobalInitializer(Dst, *Src.getInitializer());
1078 }
1079 
1080 /// Copy the source function over into the dest function and fix up references
1081 /// to values. At this point we know that Dest is an external function, and
1082 /// that Src is not.
1083 Error IRLinker::linkFunctionBody(Function &Dst, Function &Src) {
1084  assert(Dst.isDeclaration() && !Src.isDeclaration());
1085 
1086  // Materialize if needed.
1087  if (Error Err = Src.materialize())
1088  return Err;
1089 
1090  // Link in the operands without remapping.
1091  if (Src.hasPrefixData())
1092  Dst.setPrefixData(Src.getPrefixData());
1093  if (Src.hasPrologueData())
1094  Dst.setPrologueData(Src.getPrologueData());
1095  if (Src.hasPersonalityFn())
1097 
1098  // Copy over the metadata attachments without remapping.
1099  Dst.copyMetadata(&Src, 0);
1100 
1101  // Steal arguments and splice the body of Src into Dst.
1102  Dst.stealArgumentListFrom(Src);
1103  Dst.getBasicBlockList().splice(Dst.end(), Src.getBasicBlockList());
1104 
1105  // Everything has been moved over. Remap it.
1106  Mapper.scheduleRemapFunction(Dst);
1107  return Error::success();
1108 }
1109 
1110 void IRLinker::linkIndirectSymbolBody(GlobalIndirectSymbol &Dst,
1111  GlobalIndirectSymbol &Src) {
1113  IndirectSymbolMCID);
1114 }
1115 
1116 Error IRLinker::linkGlobalValueBody(GlobalValue &Dst, GlobalValue &Src) {
1117  if (auto *F = dyn_cast<Function>(&Src))
1118  return linkFunctionBody(cast<Function>(Dst), *F);
1119  if (auto *GVar = dyn_cast<GlobalVariable>(&Src)) {
1120  linkGlobalVariable(cast<GlobalVariable>(Dst), *GVar);
1121  return Error::success();
1122  }
1123  linkIndirectSymbolBody(cast<GlobalIndirectSymbol>(Dst), cast<GlobalIndirectSymbol>(Src));
1124  return Error::success();
1125 }
1126 
1127 void IRLinker::flushRAUWWorklist() {
1128  for (const auto &Elem : RAUWWorklist) {
1129  GlobalValue *Old;
1130  Value *New;
1131  std::tie(Old, New) = Elem;
1132 
1133  Old->replaceAllUsesWith(New);
1134  Old->eraseFromParent();
1135  }
1136  RAUWWorklist.clear();
1137 }
1138 
1139 void IRLinker::prepareCompileUnitsForImport() {
1140  NamedMDNode *SrcCompileUnits = SrcM->getNamedMetadata("llvm.dbg.cu");
1141  if (!SrcCompileUnits)
1142  return;
1143  // When importing for ThinLTO, prevent importing of types listed on
1144  // the DICompileUnit that we don't need a copy of in the importing
1145  // module. They will be emitted by the originating module.
1146  for (unsigned I = 0, E = SrcCompileUnits->getNumOperands(); I != E; ++I) {
1147  auto *CU = cast<DICompileUnit>(SrcCompileUnits->getOperand(I));
1148  assert(CU && "Expected valid compile unit");
1149  // Enums, macros, and retained types don't need to be listed on the
1150  // imported DICompileUnit. This means they will only be imported
1151  // if reached from the mapped IR.
1152  CU->replaceEnumTypes(nullptr);
1153  CU->replaceMacros(nullptr);
1154  CU->replaceRetainedTypes(nullptr);
1155 
1156  // The original definition (or at least its debug info - if the variable is
1157  // internalized and optimized away) will remain in the source module, so
1158  // there's no need to import them.
1159  // If LLVM ever does more advanced optimizations on global variables
1160  // (removing/localizing write operations, for instance) that can track
1161  // through debug info, this decision may need to be revisited - but do so
1162  // with care when it comes to debug info size. Emitting small CUs containing
1163  // only a few imported entities into every destination module may be very
1164  // size inefficient.
1165  CU->replaceGlobalVariables(nullptr);
1166 
1167  // Imported entities only need to be mapped in if they have local
1168  // scope, as those might correspond to an imported entity inside a
1169  // function being imported (any locally scoped imported entities that
1170  // don't end up referenced by an imported function will not be emitted
1171  // into the object). Imported entities not in a local scope
1172  // (e.g. on the namespace) only need to be emitted by the originating
1173  // module. Create a list of the locally scoped imported entities, and
1174  // replace the source CUs imported entity list with the new list, so
1175  // only those are mapped in.
1176  // FIXME: Locally-scoped imported entities could be moved to the
1177  // functions they are local to instead of listing them on the CU, and
1178  // we would naturally only link in those needed by function importing.
1179  SmallVector<TrackingMDNodeRef, 4> AllImportedModules;
1180  bool ReplaceImportedEntities = false;
1181  for (auto *IE : CU->getImportedEntities()) {
1182  DIScope *Scope = IE->getScope();
1183  assert(Scope && "Invalid Scope encoding!");
1184  if (isa<DILocalScope>(Scope))
1185  AllImportedModules.emplace_back(IE);
1186  else
1187  ReplaceImportedEntities = true;
1188  }
1189  if (ReplaceImportedEntities) {
1190  if (!AllImportedModules.empty())
1191  CU->replaceImportedEntities(MDTuple::get(
1192  CU->getContext(),
1193  SmallVector<Metadata *, 16>(AllImportedModules.begin(),
1194  AllImportedModules.end())));
1195  else
1196  // If there were no local scope imported entities, we can map
1197  // the whole list to nullptr.
1198  CU->replaceImportedEntities(nullptr);
1199  }
1200  }
1201 }
1202 
1203 /// Insert all of the named MDNodes in Src into the Dest module.
1204 void IRLinker::linkNamedMDNodes() {
1205  const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1206  for (const NamedMDNode &NMD : SrcM->named_metadata()) {
1207  // Don't link module flags here. Do them separately.
1208  if (&NMD == SrcModFlags)
1209  continue;
1210  NamedMDNode *DestNMD = DstM.getOrInsertNamedMetadata(NMD.getName());
1211  // Add Src elements into Dest node.
1212  for (const MDNode *Op : NMD.operands())
1213  DestNMD->addOperand(Mapper.mapMDNode(*Op));
1214  }
1215 }
1216 
1217 /// Merge the linker flags in Src into the Dest module.
1218 Error IRLinker::linkModuleFlagsMetadata() {
1219  // If the source module has no module flags, we are done.
1220  const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
1221  if (!SrcModFlags)
1222  return Error::success();
1223 
1224  // If the destination module doesn't have module flags yet, then just copy
1225  // over the source module's flags.
1226  NamedMDNode *DstModFlags = DstM.getOrInsertModuleFlagsMetadata();
1227  if (DstModFlags->getNumOperands() == 0) {
1228  for (unsigned I = 0, E = SrcModFlags->getNumOperands(); I != E; ++I)
1229  DstModFlags->addOperand(SrcModFlags->getOperand(I));
1230 
1231  return Error::success();
1232  }
1233 
1234  // First build a map of the existing module flags and requirements.
1236  SmallSetVector<MDNode *, 16> Requirements;
1237  for (unsigned I = 0, E = DstModFlags->getNumOperands(); I != E; ++I) {
1238  MDNode *Op = DstModFlags->getOperand(I);
1239  ConstantInt *Behavior = mdconst::extract<ConstantInt>(Op->getOperand(0));
1240  MDString *ID = cast<MDString>(Op->getOperand(1));
1241 
1242  if (Behavior->getZExtValue() == Module::Require) {
1243  Requirements.insert(cast<MDNode>(Op->getOperand(2)));
1244  } else {
1245  Flags[ID] = std::make_pair(Op, I);
1246  }
1247  }
1248 
1249  // Merge in the flags from the source module, and also collect its set of
1250  // requirements.
1251  for (unsigned I = 0, E = SrcModFlags->getNumOperands(); I != E; ++I) {
1252  MDNode *SrcOp = SrcModFlags->getOperand(I);
1253  ConstantInt *SrcBehavior =
1254  mdconst::extract<ConstantInt>(SrcOp->getOperand(0));
1255  MDString *ID = cast<MDString>(SrcOp->getOperand(1));
1256  MDNode *DstOp;
1257  unsigned DstIndex;
1258  std::tie(DstOp, DstIndex) = Flags.lookup(ID);
1259  unsigned SrcBehaviorValue = SrcBehavior->getZExtValue();
1260 
1261  // If this is a requirement, add it and continue.
1262  if (SrcBehaviorValue == Module::Require) {
1263  // If the destination module does not already have this requirement, add
1264  // it.
1265  if (Requirements.insert(cast<MDNode>(SrcOp->getOperand(2)))) {
1266  DstModFlags->addOperand(SrcOp);
1267  }
1268  continue;
1269  }
1270 
1271  // If there is no existing flag with this ID, just add it.
1272  if (!DstOp) {
1273  Flags[ID] = std::make_pair(SrcOp, DstModFlags->getNumOperands());
1274  DstModFlags->addOperand(SrcOp);
1275  continue;
1276  }
1277 
1278  // Otherwise, perform a merge.
1279  ConstantInt *DstBehavior =
1280  mdconst::extract<ConstantInt>(DstOp->getOperand(0));
1281  unsigned DstBehaviorValue = DstBehavior->getZExtValue();
1282 
1283  auto overrideDstValue = [&]() {
1284  DstModFlags->setOperand(DstIndex, SrcOp);
1285  Flags[ID].first = SrcOp;
1286  };
1287 
1288  // If either flag has override behavior, handle it first.
1289  if (DstBehaviorValue == Module::Override) {
1290  // Diagnose inconsistent flags which both have override behavior.
1291  if (SrcBehaviorValue == Module::Override &&
1292  SrcOp->getOperand(2) != DstOp->getOperand(2))
1293  return stringErr("linking module flags '" + ID->getString() +
1294  "': IDs have conflicting override values in '" +
1295  SrcM->getModuleIdentifier() + "' and '" +
1296  DstM.getModuleIdentifier() + "'");
1297  continue;
1298  } else if (SrcBehaviorValue == Module::Override) {
1299  // Update the destination flag to that of the source.
1300  overrideDstValue();
1301  continue;
1302  }
1303 
1304  // Diagnose inconsistent merge behavior types.
1305  if (SrcBehaviorValue != DstBehaviorValue) {
1306  bool MaxAndWarn = (SrcBehaviorValue == Module::Max &&
1307  DstBehaviorValue == Module::Warning) ||
1308  (DstBehaviorValue == Module::Max &&
1309  SrcBehaviorValue == Module::Warning);
1310  if (!MaxAndWarn)
1311  return stringErr("linking module flags '" + ID->getString() +
1312  "': IDs have conflicting behaviors in '" +
1313  SrcM->getModuleIdentifier() + "' and '" +
1314  DstM.getModuleIdentifier() + "'");
1315  }
1316 
1317  auto replaceDstValue = [&](MDNode *New) {
1318  Metadata *FlagOps[] = {DstOp->getOperand(0), ID, New};
1319  MDNode *Flag = MDNode::get(DstM.getContext(), FlagOps);
1320  DstModFlags->setOperand(DstIndex, Flag);
1321  Flags[ID].first = Flag;
1322  };
1323 
1324  // Emit a warning if the values differ and either source or destination
1325  // request Warning behavior.
1326  if ((DstBehaviorValue == Module::Warning ||
1327  SrcBehaviorValue == Module::Warning) &&
1328  SrcOp->getOperand(2) != DstOp->getOperand(2)) {
1329  std::string Str;
1330  raw_string_ostream(Str)
1331  << "linking module flags '" << ID->getString()
1332  << "': IDs have conflicting values ('" << *SrcOp->getOperand(2)
1333  << "' from " << SrcM->getModuleIdentifier() << " with '"
1334  << *DstOp->getOperand(2) << "' from " << DstM.getModuleIdentifier()
1335  << ')';
1336  emitWarning(Str);
1337  }
1338 
1339  // Choose the maximum if either source or destination request Max behavior.
1340  if (DstBehaviorValue == Module::Max || SrcBehaviorValue == Module::Max) {
1341  ConstantInt *DstValue =
1342  mdconst::extract<ConstantInt>(DstOp->getOperand(2));
1343  ConstantInt *SrcValue =
1344  mdconst::extract<ConstantInt>(SrcOp->getOperand(2));
1345 
1346  // The resulting flag should have a Max behavior, and contain the maximum
1347  // value from between the source and destination values.
1348  Metadata *FlagOps[] = {
1349  (DstBehaviorValue != Module::Max ? SrcOp : DstOp)->getOperand(0), ID,
1350  (SrcValue->getZExtValue() > DstValue->getZExtValue() ? SrcOp : DstOp)
1351  ->getOperand(2)};
1352  MDNode *Flag = MDNode::get(DstM.getContext(), FlagOps);
1353  DstModFlags->setOperand(DstIndex, Flag);
1354  Flags[ID].first = Flag;
1355  continue;
1356  }
1357 
1358  // Perform the merge for standard behavior types.
1359  switch (SrcBehaviorValue) {
1360  case Module::Require:
1361  case Module::Override:
1362  llvm_unreachable("not possible");
1363  case Module::Error: {
1364  // Emit an error if the values differ.
1365  if (SrcOp->getOperand(2) != DstOp->getOperand(2))
1366  return stringErr("linking module flags '" + ID->getString() +
1367  "': IDs have conflicting values in '" +
1368  SrcM->getModuleIdentifier() + "' and '" +
1369  DstM.getModuleIdentifier() + "'");
1370  continue;
1371  }
1372  case Module::Warning: {
1373  break;
1374  }
1375  case Module::Max: {
1376  break;
1377  }
1378  case Module::Append: {
1379  MDNode *DstValue = cast<MDNode>(DstOp->getOperand(2));
1380  MDNode *SrcValue = cast<MDNode>(SrcOp->getOperand(2));
1382  MDs.reserve(DstValue->getNumOperands() + SrcValue->getNumOperands());
1383  MDs.append(DstValue->op_begin(), DstValue->op_end());
1384  MDs.append(SrcValue->op_begin(), SrcValue->op_end());
1385 
1386  replaceDstValue(MDNode::get(DstM.getContext(), MDs));
1387  break;
1388  }
1389  case Module::AppendUnique: {
1391  MDNode *DstValue = cast<MDNode>(DstOp->getOperand(2));
1392  MDNode *SrcValue = cast<MDNode>(SrcOp->getOperand(2));
1393  Elts.insert(DstValue->op_begin(), DstValue->op_end());
1394  Elts.insert(SrcValue->op_begin(), SrcValue->op_end());
1395 
1396  replaceDstValue(MDNode::get(DstM.getContext(),
1397  makeArrayRef(Elts.begin(), Elts.end())));
1398  break;
1399  }
1400  }
1401 
1402  }
1403 
1404  // Check all of the requirements.
1405  for (unsigned I = 0, E = Requirements.size(); I != E; ++I) {
1406  MDNode *Requirement = Requirements[I];
1407  MDString *Flag = cast<MDString>(Requirement->getOperand(0));
1408  Metadata *ReqValue = Requirement->getOperand(1);
1409 
1410  MDNode *Op = Flags[Flag].first;
1411  if (!Op || Op->getOperand(2) != ReqValue)
1412  return stringErr("linking module flags '" + Flag->getString() +
1413  "': does not have the required value");
1414  }
1415  return Error::success();
1416 }
1417 
1418 /// Return InlineAsm adjusted with target-specific directives if required.
1419 /// For ARM and Thumb, we have to add directives to select the appropriate ISA
1420 /// to support mixing module-level inline assembly from ARM and Thumb modules.
1421 static std::string adjustInlineAsm(const std::string &InlineAsm,
1422  const Triple &Triple) {
1424  return ".text\n.balign 2\n.thumb\n" + InlineAsm;
1426  return ".text\n.balign 4\n.arm\n" + InlineAsm;
1427  return InlineAsm;
1428 }
1429 
1430 Error IRLinker::run() {
1431  // Ensure metadata materialized before value mapping.
1432  if (SrcM->getMaterializer())
1433  if (Error Err = SrcM->getMaterializer()->materializeMetadata())
1434  return Err;
1435 
1436  // Inherit the target data from the source module if the destination module
1437  // doesn't have one already.
1438  if (DstM.getDataLayout().isDefault())
1439  DstM.setDataLayout(SrcM->getDataLayout());
1440 
1441  if (SrcM->getDataLayout() != DstM.getDataLayout()) {
1442  emitWarning("Linking two modules of different data layouts: '" +
1443  SrcM->getModuleIdentifier() + "' is '" +
1444  SrcM->getDataLayoutStr() + "' whereas '" +
1445  DstM.getModuleIdentifier() + "' is '" +
1446  DstM.getDataLayoutStr() + "'\n");
1447  }
1448 
1449  // Copy the target triple from the source to dest if the dest's is empty.
1450  if (DstM.getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
1451  DstM.setTargetTriple(SrcM->getTargetTriple());
1452 
1453  Triple SrcTriple(SrcM->getTargetTriple()), DstTriple(DstM.getTargetTriple());
1454 
1455  if (!SrcM->getTargetTriple().empty()&&
1456  !SrcTriple.isCompatibleWith(DstTriple))
1457  emitWarning("Linking two modules of different target triples: '" +
1458  SrcM->getModuleIdentifier() + "' is '" +
1459  SrcM->getTargetTriple() + "' whereas '" +
1460  DstM.getModuleIdentifier() + "' is '" + DstM.getTargetTriple() +
1461  "'\n");
1462 
1463  DstM.setTargetTriple(SrcTriple.merge(DstTriple));
1464 
1465  // Loop over all of the linked values to compute type mappings.
1466  computeTypeMapping();
1467 
1468  std::reverse(Worklist.begin(), Worklist.end());
1469  while (!Worklist.empty()) {
1470  GlobalValue *GV = Worklist.back();
1471  Worklist.pop_back();
1472 
1473  // Already mapped.
1474  if (ValueMap.find(GV) != ValueMap.end() ||
1475  IndirectSymbolValueMap.find(GV) != IndirectSymbolValueMap.end())
1476  continue;
1477 
1478  assert(!GV->isDeclaration());
1479  Mapper.mapValue(*GV);
1480  if (FoundError)
1481  return std::move(*FoundError);
1482  flushRAUWWorklist();
1483  }
1484 
1485  // Note that we are done linking global value bodies. This prevents
1486  // metadata linking from creating new references.
1487  DoneLinkingBodies = true;
1489 
1490  // Remap all of the named MDNodes in Src into the DstM module. We do this
1491  // after linking GlobalValues so that MDNodes that reference GlobalValues
1492  // are properly remapped.
1493  linkNamedMDNodes();
1494 
1495  if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) {
1496  // Append the module inline asm string.
1497  DstM.appendModuleInlineAsm(adjustInlineAsm(SrcM->getModuleInlineAsm(),
1498  SrcTriple));
1499  } else if (IsPerformingImport) {
1500  // Import any symver directives for symbols in DstM.
1502  [&](StringRef Name, StringRef Alias) {
1503  if (DstM.getNamedValue(Name)) {
1504  SmallString<256> S(".symver ");
1505  S += Name;
1506  S += ", ";
1507  S += Alias;
1508  DstM.appendModuleInlineAsm(S);
1509  }
1510  });
1511  }
1512 
1513  // Reorder the globals just added to the destination module to match their
1514  // original order in the source module.
1515  Module::GlobalListType &Globals = DstM.getGlobalList();
1516  for (GlobalVariable &GV : SrcM->globals()) {
1517  if (GV.hasAppendingLinkage())
1518  continue;
1519  Value *NewValue = Mapper.mapValue(GV);
1520  if (NewValue) {
1521  auto *NewGV = dyn_cast<GlobalVariable>(NewValue->stripPointerCasts());
1522  if (NewGV)
1523  Globals.splice(Globals.end(), Globals, NewGV->getIterator());
1524  }
1525  }
1526 
1527  // Merge the module flags into the DstM module.
1528  return linkModuleFlagsMetadata();
1529 }
1530 
1532  : ETypes(E), IsPacked(P) {}
1533 
1535  : ETypes(ST->elements()), IsPacked(ST->isPacked()) {}
1536 
1538  return IsPacked == That.IsPacked && ETypes == That.ETypes;
1539 }
1540 
1542  return !this->operator==(That);
1543 }
1544 
1545 StructType *IRMover::StructTypeKeyInfo::getEmptyKey() {
1547 }
1548 
1549 StructType *IRMover::StructTypeKeyInfo::getTombstoneKey() {
1551 }
1552 
1553 unsigned IRMover::StructTypeKeyInfo::getHashValue(const KeyTy &Key) {
1554  return hash_combine(hash_combine_range(Key.ETypes.begin(), Key.ETypes.end()),
1555  Key.IsPacked);
1556 }
1557 
1558 unsigned IRMover::StructTypeKeyInfo::getHashValue(const StructType *ST) {
1559  return getHashValue(KeyTy(ST));
1560 }
1561 
1562 bool IRMover::StructTypeKeyInfo::isEqual(const KeyTy &LHS,
1563  const StructType *RHS) {
1564  if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1565  return false;
1566  return LHS == KeyTy(RHS);
1567 }
1568 
1570  const StructType *RHS) {
1571  if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1572  return LHS == RHS;
1573  return KeyTy(LHS) == KeyTy(RHS);
1574 }
1575 
1577  assert(!Ty->isOpaque());
1578  NonOpaqueStructTypes.insert(Ty);
1579 }
1580 
1582  assert(!Ty->isOpaque());
1583  NonOpaqueStructTypes.insert(Ty);
1584  bool Removed = OpaqueStructTypes.erase(Ty);
1585  (void)Removed;
1586  assert(Removed);
1587 }
1588 
1590  assert(Ty->isOpaque());
1591  OpaqueStructTypes.insert(Ty);
1592 }
1593 
1594 StructType *
1596  bool IsPacked) {
1598  auto I = NonOpaqueStructTypes.find_as(Key);
1599  return I == NonOpaqueStructTypes.end() ? nullptr : *I;
1600 }
1601 
1603  if (Ty->isOpaque())
1604  return OpaqueStructTypes.count(Ty);
1605  auto I = NonOpaqueStructTypes.find(Ty);
1606  return I == NonOpaqueStructTypes.end() ? false : *I == Ty;
1607 }
1608 
1609 IRMover::IRMover(Module &M) : Composite(M) {
1610  TypeFinder StructTypes;
1611  StructTypes.run(M, /* OnlyNamed */ false);
1612  for (StructType *Ty : StructTypes) {
1613  if (Ty->isOpaque())
1614  IdentifiedStructTypes.addOpaque(Ty);
1615  else
1616  IdentifiedStructTypes.addNonOpaque(Ty);
1617  }
1618  // Self-map metadatas in the destination module. This is needed when
1619  // DebugTypeODRUniquing is enabled on the LLVMContext, since metadata in the
1620  // destination module may be reached from the source module.
1621  for (auto *MD : StructTypes.getVisitedMetadata()) {
1622  SharedMDs[MD].reset(const_cast<MDNode *>(MD));
1623  }
1624 }
1625 
1627  std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
1628  std::function<void(GlobalValue &, ValueAdder Add)> AddLazyFor,
1629  bool IsPerformingImport) {
1630  IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
1631  std::move(Src), ValuesToLink, std::move(AddLazyFor),
1632  IsPerformingImport);
1633  Error E = TheIRLinker.run();
1634  Composite.dropTriviallyDeadConstantArrays();
1635  return E;
1636 }
llvm::ValueMap::getMDMap
Optional< MDMapT > & getMDMap()
Definition: ValueMap.h:120
i
i
Definition: README.txt:29
llvm::Type::ArrayTyID
@ ArrayTyID
Arrays.
Definition: Type.h:76
llvm::Module::appendModuleInlineAsm
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
Definition: Module.h:312
llvm::Intrinsic::remangleIntrinsicFunction
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Definition: Function.cpp:1641
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::Module::getOrInsertModuleFlagsMetadata
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
Definition: Module.cpp:341
llvm
Definition: AllocatorList.h:23
llvm::ValueMapper::scheduleMapAppendingVariable
void scheduleMapAppendingVariable(GlobalVariable &GV, Constant *InitPrefix, bool IsOldCtorDtor, ArrayRef< Constant * > NewMembers, unsigned MappingContextID=0)
Definition: ValueMapper.cpp:1168
M
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
Definition: README.txt:252
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1386
llvm::IRMover::StructTypeKeyInfo::KeyTy::ETypes
ArrayRef< Type * > ETypes
Definition: IRMover.h:28
llvm::SmallPtrSetImpl::erase
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false.
Definition: SmallPtrSet.h:378
llvm::StructType::getName
StringRef getName() const
Return the name for this struct type if it has an identity.
Definition: Type.cpp:541
llvm::StructType::get
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:366
llvm::Function::end
iterator end()
Definition: Function.h:780
llvm::NamedMDNode::getNumOperands
unsigned getNumOperands() const
Definition: Metadata.cpp:1114
llvm::Function::getPrefixData
Constant * getPrefixData() const
Get the prefix data associated with this function.
Definition: Function.cpp:1753
llvm::ValueMap::end
iterator end()
Definition: ValueMap.h:136
llvm::Function::getBasicBlockList
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:755
llvm::GlobalVariable::copyAttributesFrom
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
Definition: Globals.cpp:412
llvm::SIInstrFlags::IsPacked
@ IsPacked
Definition: SIDefines.h:88
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:461
llvm::RF_NullMapMissingGlobalValues
@ RF_NullMapMissingGlobalValues
Any global values not in value map are mapped to null instead of mapping to self.
Definition: ValueMapper.h:100
llvm::Function
Definition: Function.h:61
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::lookup
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...
Definition: DenseMap.h:197
P
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
Definition: README-SSE.txt:411
llvm::IRMover::IdentifiedStructTypeSet::findNonOpaque
StructType * findNonOpaque(ArrayRef< Type * > ETypes, bool IsPacked)
Definition: IRMover.cpp:1595
llvm::IRMover::StructTypeKeyInfo::KeyTy
Definition: IRMover.h:27
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:614
llvm::PointerType::get
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Definition: Type.cpp:687
llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::size
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:77
llvm::StructType::setBody
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
Definition: Type.cpp:405
llvm::GlobalObject::getSection
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:112
llvm::StringRef::npos
static constexpr size_t npos
Definition: StringRef.h:60
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1167
llvm::GlobalValue::materialize
Error materialize()
Make sure this GlobalValue is fully read.
Definition: Globals.cpp:49
llvm::Value::hasName
bool hasName() const
Definition: Value.h:262
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
llvm::GlobalIndirectSymbol
Definition: GlobalIndirectSymbol.h:28
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::erase_if
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition: STLExtras.h:1656
llvm::ConstantExpr::getBitCast
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2220
llvm::FunctionType::get
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:321
Error.h
llvm::Type::getTypeID
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::erase
bool erase(const KeyT &Val)
Definition: DenseMap.h:302
llvm::NamedMDNode::setOperand
void setOperand(unsigned I, MDNode *New)
Definition: Metadata.cpp:1126
llvm::DK_Linker
@ DK_Linker
Definition: DiagnosticInfo.h:59
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::reverse
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
Definition: STLExtras.h:329
llvm::AttributeList
Definition: Attributes.h:385
llvm::ValueMapper::mapMDNode
MDNode * mapMDNode(const MDNode &N)
Definition: ValueMapper.cpp:1150
llvm::StructType::getTypeByName
static StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
Definition: Type.cpp:583
llvm::Optional
Definition: APInt.h:33
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
llvm::IRMover::IdentifiedStructTypeSet::addNonOpaque
void addNonOpaque(StructType *Ty)
Definition: IRMover.cpp:1576
getTypeNamePrefix
static StringRef getTypeNamePrefix(StringRef Name)
Definition: IRMover.cpp:744
llvm::ValueMapper::scheduleMapGlobalInitializer
void scheduleMapGlobalInitializer(GlobalVariable &GV, Constant &Init, unsigned MappingContextID=0)
Definition: ValueMapper.cpp:1162
llvm::ValueMapTypeRemapper
This is a class that can be implemented by clients to remap types when cloning constants and instruct...
Definition: ValueMapper.h:37
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::GlobalIndirectSymbol::copyAttributesFrom
void copyAttributesFrom(const GlobalValue *Src)
Definition: GlobalIndirectSymbol.h:45
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:359
llvm::StructType::create
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:473
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::Module::Override
@ Override
Uses the specified value, regardless of the behavior or value of the other module.
Definition: Module.h:138
llvm::Type::getInt8Ty
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:195
llvm::StructType::setName
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...
Definition: Type.cpp:422
llvm::Module::getGlobalList
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
Definition: Module.h:544
llvm::GlobalValue::hasExternalWeakLinkage
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:446
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1198
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MDNode::getNumOperands
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1108
llvm::ValueMapper::scheduleMapGlobalIndirectSymbol
void scheduleMapGlobalIndirectSymbol(GlobalIndirectSymbol &GIS, Constant &Target, unsigned MappingContextID=0)
Definition: ValueMapper.cpp:1177
llvm::RF_ReuseAndMutateDistinctMDs
@ RF_ReuseAndMutateDistinctMDs
Instruct the remapper to reuse and mutate distinct metadata (remapping them in place) instead of clon...
Definition: ValueMapper.h:96
llvm::NamedMDNode::addOperand
void addOperand(MDNode *M)
Definition: Metadata.cpp:1124
llvm::ValueMapper::scheduleRemapFunction
void scheduleRemapFunction(Function &F, unsigned MappingContextID=0)
Definition: ValueMapper.cpp:1183
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:77
llvm::DenseMapInfo
Definition: APInt.h:34
llvm::Type::FunctionTyID
@ FunctionTyID
Functions.
Definition: Type.h:73
llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::begin
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition: SetVector.h:82
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:228
LinkDiagnosticInfo.h
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition: PPCISelLowering.h:410
llvm::ArrayType::getNumElements
uint64_t getNumElements() const
Definition: DerivedTypes.h:371
llvm::GlobalValue::hasAppendingLinkage
bool hasAppendingLinkage() const
Definition: GlobalValue.h:442
Constants.h
llvm::Module::Append
@ Append
Appends the two values, which are required to be metadata nodes.
Definition: Module.h:141
llvm::Function::stealArgumentListFrom
void stealArgumentListFrom(Function &Src)
Steal arguments from another function.
Definition: Function.cpp:471
SmallString.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::SmallVectorImpl::append
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:647
llvm::DS_Warning
@ DS_Warning
Definition: DiagnosticInfo.h:46
llvm::StructType::isPacked
bool isPacked() const
Definition: DerivedTypes.h:274
llvm::IRMover::StructTypeKeyInfo::KeyTy::KeyTy
KeyTy(ArrayRef< Type * > E, bool P)
Definition: IRMover.cpp:1531
Intrinsics.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::IRMover::StructTypeKeyInfo::KeyTy::operator==
bool operator==(const KeyTy &that) const
Definition: IRMover.cpp:1537
llvm::IRMover::StructTypeKeyInfo::KeyTy::operator!=
bool operator!=(const KeyTy &that) const
Definition: IRMover.cpp:1541
llvm::GlobalValue::getThreadLocalMode
ThreadLocalMode getThreadLocalMode() const
Definition: GlobalValue.h:252
TypeFinder.h
llvm::rust_demangle::BasicType::Str
@ Str
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::IRMover::IdentifiedStructTypeSet::addOpaque
void addOpaque(StructType *Ty)
Definition: IRMover.cpp:1589
GVMaterializer.h
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:146
llvm::DiagnosticSeverity
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Definition: DiagnosticInfo.h:44
llvm::ValueMapper::mapValue
Value * mapValue(const Value &V)
Definition: ValueMapper.cpp:1138
llvm::Value::setName
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:361
llvm::Function::hasPersonalityFn
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:830
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition: SmallVector.h:605
llvm::Module::getDataLayoutStr
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
Definition: Module.h:248
llvm::DiagnosticInfo
This is the base abstract class for diagnostic reporting in the backend.
Definition: DiagnosticInfo.h:101
llvm::Type::PointerTyID
@ PointerTyID
Pointers.
Definition: Type.h:74
llvm::IRMover::IdentifiedStructTypeSet::hasType
bool hasType(StructType *Ty)
Definition: IRMover.cpp:1602
llvm::GlobalValue::hasGlobalUnnamedAddr
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:196
llvm::DiagnosticPrinter
Interface for custom diagnostic printing.
Definition: DiagnosticPrinter.h:31
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::Comdat
Definition: Comdat.h:31
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::Triple::getArch
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:307
llvm::Type::isFunctionTy
bool isFunctionTy() const
True if this is an instance of FunctionType.
Definition: Type.h:220
llvm::Module::setTargetTriple
void setTargetTriple(StringRef T)
Set the target triple.
Definition: Module.h:300
llvm::Function::hasPrologueData
bool hasPrologueData() const
Check whether this function has prologue data.
Definition: Function.h:848
llvm::SmallString< 16 >
llvm::Module::AppendUnique
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
Definition: Module.h:146
llvm::ARM_PROC::IE
@ IE
Definition: ARMBaseInfo.h:27
llvm::ValueMapper
Context for (re-)mapping values (and metadata).
Definition: ValueMapper.h:143
llvm::InlineAsm
Definition: InlineAsm.h:31
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::GlobalVariable::getInitializer
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition: GlobalVariable.h:136
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::IRMover::StructTypeKeyInfo::KeyTy::IsPacked
bool IsPacked
Definition: IRMover.h:29
llvm::Function::hasPrefixData
bool hasPrefixData() const
Check whether this function has prefix data.
Definition: Function.h:839
llvm::GlobalValue::getVisibility
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:229
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:572
llvm::IRMover::IRMover
IRMover(Module &M)
Definition: IRMover.cpp:1609
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::StructType::isOpaque
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
Definition: DerivedTypes.h:282
llvm::GlobalObject::copyMetadata
void copyMetadata(const GlobalObject *Src, unsigned Offset)
Copy metadata from Src, adjusting offsets by Offset.
Definition: Metadata.cpp:1451
move
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
Definition: README.txt:546
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::DenseMap
Definition: DenseMap.h:714
DebugInfo.h
llvm::orc::Requirement
Requirement
Definition: DebugObjectManagerPlugin.cpp:114
llvm::IRMover::ValueAdder
std::function< void(GlobalValue &)> ValueAdder
Definition: IRMover.h:64
I
#define I(x, y, z)
Definition: MD5.cpp:59
Cloning.h
llvm::Attribute::AttrKind
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:71
llvm::DataLayout::isDefault
bool isDefault() const
Test if the DataLayout was constructed from an empty string.
Definition: DataLayout.h:254
llvm::PointerType
Class to represent pointers.
Definition: DerivedTypes.h:634
llvm::GlobalValue::setLinkage
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:454
llvm::Module::getOrInsertComdat
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Definition: Module.cpp:581
llvm::LinkDiagnosticInfo::print
void print(DiagnosticPrinter &DP) const override
Print using the given DP a user-friendly message.
Definition: IRMover.cpp:344
llvm::Module::setDataLayout
void setDataLayout(StringRef Desc)
Set the data layout.
Definition: Module.cpp:391
llvm::NamedMDNode::getOperand
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1118
llvm::Function::Create
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:137
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1540
llvm::IRMover::move
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.
Definition: IRMover.cpp:1626
llvm::GlobalValue::hasLocalLinkage
bool hasLocalLinkage() const
Definition: GlobalValue.h:445
llvm::operator==
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:2037
llvm::Module::getModuleIdentifier
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition: Module.h:227
llvm::MDTuple::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1165
llvm::Function::hasAttribute
bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:444
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::Function::setPersonalityFn
void setPersonalityFn(Constant *Fn)
Definition: Function.cpp:1748
llvm::GlobalObject::getAlignment
unsigned getAlignment() const
FIXME: Remove this function once transition to Align is over.
Definition: GlobalObject.h:71
llvm::ArrayType::get
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:598
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
IRMover.h
llvm::Triple::armeb
@ armeb
Definition: Triple.h:51
llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::insert
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
Triple.h
ModuleSymbolTable.h
llvm::ValueMapper::addFlags
void addFlags(RemapFlags Flags)
Add to the current RemapFlags.
Definition: ValueMapper.cpp:1134
llvm::SmallPtrSetImplBase::clear
void clear()
Definition: SmallPtrSet.h:94
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::Triple::arm
@ arm
Definition: Triple.h:50
elements
This compiles xmm1 mulss xmm1 xorps xmm0 movss xmm0 ret Because mulss doesn t modify the top elements
Definition: README-SSE.txt:221
llvm::SymbolTableList< GlobalVariable >
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:212
llvm::Module::Warning
@ Warning
Emits a warning if two values disagree.
Definition: Module.h:124
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
llvm::TypeFinder::run
void run(const Module &M, bool onlyNamed)
Definition: TypeFinder.cpp:32
llvm::TypeFinder
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
Definition: TypeFinder.h:30
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::Type::getNumContainedTypes
unsigned getNumContainedTypes() const
Return the number of types in the derived type.
Definition: Type.h:352
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:517
llvm::ms_demangle::IntrinsicFunctionKind::New
@ New
llvm::Triple::thumb
@ thumb
Definition: Triple.h:81
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:965
DC
static ManagedStatic< DebugCounter > DC
Definition: DebugCounter.cpp:55
getArrayElements
static void getArrayElements(const Constant *C, SmallVectorImpl< Constant * > &Dest)
Definition: IRMover.cpp:843
llvm::IRMover::IdentifiedStructTypeSet
Definition: IRMover.h:47
llvm::GlobalIndirectSymbol::getIndirectSymbol
const Constant * getIndirectSymbol() const
Definition: GlobalIndirectSymbol.h:53
llvm::Module::Error
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
Definition: Module.h:120
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:294
llvm::ValueMap< const Value *, WeakTrackingVH >
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
llvm::GlobalIFunc::create
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...
Definition: Globals.cpp:540
llvm::GlobalValue::eraseFromParent
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:86
llvm::Value::stripPointerCasts
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:662
llvm::ConstantInt::getZExtValue
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:140
llvm::RF_IgnoreMissingLocals
@ RF_IgnoreMissingLocals
If this flag is set, the remapper ignores missing function-local entries (Argument,...
Definition: ValueMapper.h:90
llvm::StructType::hasName
bool hasName() const
Return true if this is a named struct that has a non-empty name.
Definition: DerivedTypes.h:291
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
llvm::DIScope
Base class for scope-like contexts.
Definition: DebugInfoMetadata.h:476
llvm::GlobalAlias::create
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...
Definition: Globals.cpp:485
llvm::ModuleSymbolTable::CollectAsmSymvers
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.
Definition: ModuleSymbolTable.cpp:169
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::Type::FixedVectorTyID
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition: Type.h:77
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::GlobalValue::getComdat
const Comdat * getComdat() const
Definition: Globals.cpp:172
llvm::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:261
llvm::Attribute::getValueAsType
Type * getValueAsType() const
Return the attribute's value as a Type.
Definition: Attributes.cpp:311
llvm::Type::getPointerTo
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
Definition: Type.cpp:728
llvm::Module::getOrInsertNamedMetadata
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition: Module.cpp:259
llvm::Function::getFunctionType
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:175
llvm::ValueMap::find
iterator find(const KeyT &Val)
Definition: ValueMap.h:156
DP
So we should use XX3Form_Rcr to implement instrinsic 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
Definition: README_P9.txt:520
isEqual
static bool isEqual(const Function &Caller, const Function &Callee)
Definition: Attributes.cpp:2130
llvm::Module::Require
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition: Module.h:133
llvm::Function::getPersonalityFn
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1743
llvm::LinkDiagnosticInfo::LinkDiagnosticInfo
LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg)
Definition: IRMover.cpp:341
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::GlobalValue::getAddressSpace
unsigned getAddressSpace() const
Definition: Globals.cpp:112
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:557
llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::end
iterator end()
Get an iterator to the end of the SetVector.
Definition: SetVector.h:92
false
Function Alias Analysis false
Definition: AliasAnalysis.cpp:853
llvm::Type::StructTyID
@ StructTyID
Structures.
Definition: Type.h:75
forceRenaming
static void forceRenaming(GlobalValue *GV, StringRef Name)
The LLVM SymbolTable class autorenames globals that conflict in the symbol table.
Definition: IRMover.cpp:550
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
Definition: Constants.cpp:2047
llvm::Function::setPrefixData
void setPrefixData(Constant *PrefixData)
Definition: Function.cpp:1758
llvm::hash_combine
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:604
llvm::Module::dropTriviallyDeadConstantArrays
void dropTriviallyDeadConstantArrays()
Destroy ConstantArrays in LLVMContext if they are not used.
Definition: LLVMContextImpl.cpp:152
llvm::Triple::thumbeb
@ thumbeb
Definition: Triple.h:82
llvm::GlobalVariable::isConstant
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Definition: GlobalVariable.h:153
llvm::Module::getTargetTriple
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:257
llvm::DstOp
Definition: MachineIRBuilder.h:58
llvm::hash_combine_range
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:482
llvm::MDNode::op_end
op_iterator op_end() const
Definition: Metadata.h:1096
llvm::GlobalValue::isDeclarationForLinker
bool isDeclarationForLinker() const
Definition: GlobalValue.h:534
llvm::LinkDiagnosticInfo
Definition: LinkDiagnosticInfo.h:15
llvm::Module::Max
@ Max
Takes the max of the two values, which are required to be integers.
Definition: Module.h:149
llvm::Function::getAttribute
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
gets the attribute from the list of attributes.
Definition: Function.h:459
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::Type::ScalableVectorTyID
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:78
llvm::GlobalValue::getType
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:271
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:397
llvm::SmallSetVector
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:307
llvm::Function::setPrologueData
void setPrologueData(Constant *PrologueData)
Definition: Function.cpp:1768
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition: GlobalValue.h:273
llvm::Function::getPrologueData
Constant * getPrologueData() const
Get the prologue data associated with this function.
Definition: Function.cpp:1763
llvm::ValueMap::lookup
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: ValueMap.h:165
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:367
llvm::GlobalObject::setAlignment
void setAlignment(MaybeAlign Align)
Definition: Globals.cpp:117
llvm::GlobalValue::ExternalWeakLinkage
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition: GlobalValue.h:57
llvm::StructType::isLiteral
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
Definition: DerivedTypes.h:278
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:623
llvm::MDString
A single uniqued string.
Definition: Metadata.h:611
DiagnosticPrinter.h
llvm::ValueMaterializer
This is a class that can be implemented by clients to materialize Values on demand.
Definition: ValueMapper.h:50
llvm::IRMover::IdentifiedStructTypeSet::switchToNonOpaque
void switchToNonOpaque(StructType *Ty)
Definition: IRMover.cpp:1581
CU
Definition: AArch64AsmBackend.cpp:499
llvm::MDNode::op_begin
op_iterator op_begin() const
Definition: Metadata.h:1092
llvm::Type::getContainedType
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
Definition: Type.h:346
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::VectorType::get
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:628
adjustInlineAsm
static std::string adjustInlineAsm(const std::string &InlineAsm, const Triple &Triple)
Return InlineAsm adjusted with target-specific directives if required.
Definition: IRMover.cpp:1421
llvm::ArrayType::getElementType
Type * getElementType() const
Definition: DerivedTypes.h:372
llvm::SrcOp
Definition: MachineIRBuilder.h:119
llvm::Module::getNamedValue
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition: Module.cpp:113
SetVector.h
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:102
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:907
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:364
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38