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