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