clang  5.0.0
CodeGenModule.h
Go to the documentation of this file.
1 //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This is the internal per-translation-unit state used for llvm translation.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
15 #define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
16 
17 #include "CGVTables.h"
18 #include "CodeGenTypeCache.h"
19 #include "CodeGenTypes.h"
20 #include "SanitizerMetadata.h"
21 #include "clang/AST/Attr.h"
22 #include "clang/AST/DeclCXX.h"
23 #include "clang/AST/DeclObjC.h"
24 #include "clang/AST/DeclOpenMP.h"
25 #include "clang/AST/GlobalDecl.h"
26 #include "clang/AST/Mangle.h"
27 #include "clang/Basic/ABI.h"
29 #include "clang/Basic/Module.h"
31 #include "clang/Basic/XRayLists.h"
32 #include "llvm/ADT/DenseMap.h"
33 #include "llvm/ADT/SetVector.h"
34 #include "llvm/ADT/SmallPtrSet.h"
35 #include "llvm/ADT/StringMap.h"
36 #include "llvm/IR/Module.h"
37 #include "llvm/IR/ValueHandle.h"
38 #include "llvm/Transforms/Utils/SanitizerStats.h"
39 
40 namespace llvm {
41 class Module;
42 class Constant;
43 class ConstantInt;
44 class Function;
45 class GlobalValue;
46 class DataLayout;
47 class FunctionType;
48 class LLVMContext;
49 class IndexedInstrProfReader;
50 }
51 
52 namespace clang {
53 class ASTContext;
54 class AtomicType;
55 class FunctionDecl;
56 class IdentifierInfo;
57 class ObjCMethodDecl;
58 class ObjCImplementationDecl;
59 class ObjCCategoryImplDecl;
60 class ObjCProtocolDecl;
61 class ObjCEncodeExpr;
62 class BlockExpr;
63 class CharUnits;
64 class Decl;
65 class Expr;
66 class Stmt;
67 class InitListExpr;
68 class StringLiteral;
69 class NamedDecl;
70 class ValueDecl;
71 class VarDecl;
72 class LangOptions;
73 class CodeGenOptions;
74 class HeaderSearchOptions;
75 class PreprocessorOptions;
76 class DiagnosticsEngine;
77 class AnnotateAttr;
78 class CXXDestructorDecl;
79 class Module;
80 class CoverageSourceInfo;
81 
82 namespace CodeGen {
83 
84 class CallArgList;
85 class CodeGenFunction;
86 class CodeGenTBAA;
87 class CGCXXABI;
88 class CGDebugInfo;
89 class CGObjCRuntime;
90 class CGOpenCLRuntime;
91 class CGOpenMPRuntime;
92 class CGCUDARuntime;
93 class BlockFieldFlags;
94 class FunctionArgList;
95 class CoverageMappingModuleGen;
96 class TargetCodeGenInfo;
97 
98 enum ForDefinition_t : bool {
101 };
102 
104  unsigned int priority;
105  unsigned int lex_order;
106  OrderGlobalInits(unsigned int p, unsigned int l)
107  : priority(p), lex_order(l) {}
108 
109  bool operator==(const OrderGlobalInits &RHS) const {
110  return priority == RHS.priority && lex_order == RHS.lex_order;
111  }
112 
113  bool operator<(const OrderGlobalInits &RHS) const {
114  return std::tie(priority, lex_order) <
115  std::tie(RHS.priority, RHS.lex_order);
116  }
117 };
118 
120  ObjCEntrypoints() { memset(this, 0, sizeof(*this)); }
121 
122  /// void objc_autoreleasePoolPop(void*);
123  llvm::Constant *objc_autoreleasePoolPop;
124 
125  /// void *objc_autoreleasePoolPush(void);
126  llvm::Constant *objc_autoreleasePoolPush;
127 
128  /// id objc_autorelease(id);
129  llvm::Constant *objc_autorelease;
130 
131  /// id objc_autoreleaseReturnValue(id);
133 
134  /// void objc_copyWeak(id *dest, id *src);
135  llvm::Constant *objc_copyWeak;
136 
137  /// void objc_destroyWeak(id*);
138  llvm::Constant *objc_destroyWeak;
139 
140  /// id objc_initWeak(id*, id);
141  llvm::Constant *objc_initWeak;
142 
143  /// id objc_loadWeak(id*);
144  llvm::Constant *objc_loadWeak;
145 
146  /// id objc_loadWeakRetained(id*);
147  llvm::Constant *objc_loadWeakRetained;
148 
149  /// void objc_moveWeak(id *dest, id *src);
150  llvm::Constant *objc_moveWeak;
151 
152  /// id objc_retain(id);
153  llvm::Constant *objc_retain;
154 
155  /// id objc_retainAutorelease(id);
156  llvm::Constant *objc_retainAutorelease;
157 
158  /// id objc_retainAutoreleaseReturnValue(id);
160 
161  /// id objc_retainAutoreleasedReturnValue(id);
163 
164  /// id objc_retainBlock(id);
165  llvm::Constant *objc_retainBlock;
166 
167  /// void objc_release(id);
168  llvm::Constant *objc_release;
169 
170  /// void objc_storeStrong(id*, id);
171  llvm::Constant *objc_storeStrong;
172 
173  /// id objc_storeWeak(id*, id);
174  llvm::Constant *objc_storeWeak;
175 
176  /// id objc_unsafeClaimAutoreleasedReturnValue(id);
178 
179  /// A void(void) inline asm to use to mark that the return value of
180  /// a call will be immediately retain.
182 
183  /// void clang.arc.use(...);
184  llvm::Constant *clang_arc_use;
185 };
186 
187 /// This class records statistics on instrumentation based profiling.
189  uint32_t VisitedInMainFile;
190  uint32_t MissingInMainFile;
191  uint32_t Visited;
192  uint32_t Missing;
193  uint32_t Mismatched;
194 
195 public:
197  : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
198  Mismatched(0) {}
199  /// Record that we've visited a function and whether or not that function was
200  /// in the main source file.
201  void addVisited(bool MainFile) {
202  if (MainFile)
203  ++VisitedInMainFile;
204  ++Visited;
205  }
206  /// Record that a function we've visited has no profile data.
207  void addMissing(bool MainFile) {
208  if (MainFile)
209  ++MissingInMainFile;
210  ++Missing;
211  }
212  /// Record that a function we've visited has mismatched profile data.
213  void addMismatched(bool MainFile) { ++Mismatched; }
214  /// Whether or not the stats we've gathered indicate any potential problems.
215  bool hasDiagnostics() { return Missing || Mismatched; }
216  /// Report potential problems we've found to \c Diags.
217  void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
218 };
219 
220 /// A pair of helper functions for a __block variable.
221 class BlockByrefHelpers : public llvm::FoldingSetNode {
222  // MSVC requires this type to be complete in order to process this
223  // header.
224 public:
225  llvm::Constant *CopyHelper;
226  llvm::Constant *DisposeHelper;
227 
228  /// The alignment of the field. This is important because
229  /// different offsets to the field within the byref struct need to
230  /// have different helper functions.
232 
233  BlockByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
234  BlockByrefHelpers(const BlockByrefHelpers &) = default;
235  virtual ~BlockByrefHelpers();
236 
237  void Profile(llvm::FoldingSetNodeID &id) const {
238  id.AddInteger(Alignment.getQuantity());
239  profileImpl(id);
240  }
241  virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
242 
243  virtual bool needsCopy() const { return true; }
244  virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src) = 0;
245 
246  virtual bool needsDispose() const { return true; }
247  virtual void emitDispose(CodeGenFunction &CGF, Address field) = 0;
248 };
249 
250 /// This class organizes the cross-function state that is used while generating
251 /// LLVM code.
253  CodeGenModule(const CodeGenModule &) = delete;
254  void operator=(const CodeGenModule &) = delete;
255 
256 public:
257  struct Structor {
258  Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
259  Structor(int Priority, llvm::Constant *Initializer,
260  llvm::Constant *AssociatedData)
261  : Priority(Priority), Initializer(Initializer),
262  AssociatedData(AssociatedData) {}
263  int Priority;
264  llvm::Constant *Initializer;
265  llvm::Constant *AssociatedData;
266  };
267 
268  typedef std::vector<Structor> CtorList;
269 
270 private:
271  ASTContext &Context;
272  const LangOptions &LangOpts;
273  const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info.
274  const PreprocessorOptions &PreprocessorOpts; // Only used for debug info.
275  const CodeGenOptions &CodeGenOpts;
276  llvm::Module &TheModule;
277  DiagnosticsEngine &Diags;
278  const TargetInfo &Target;
279  std::unique_ptr<CGCXXABI> ABI;
280  llvm::LLVMContext &VMContext;
281 
282  std::unique_ptr<CodeGenTBAA> TBAA;
283 
284  mutable std::unique_ptr<TargetCodeGenInfo> TheTargetCodeGenInfo;
285 
286  // This should not be moved earlier, since its initialization depends on some
287  // of the previous reference members being already initialized and also checks
288  // if TheTargetCodeGenInfo is NULL
289  CodeGenTypes Types;
290 
291  /// Holds information about C++ vtables.
292  CodeGenVTables VTables;
293 
294  std::unique_ptr<CGObjCRuntime> ObjCRuntime;
295  std::unique_ptr<CGOpenCLRuntime> OpenCLRuntime;
296  std::unique_ptr<CGOpenMPRuntime> OpenMPRuntime;
297  std::unique_ptr<CGCUDARuntime> CUDARuntime;
298  std::unique_ptr<CGDebugInfo> DebugInfo;
299  std::unique_ptr<ObjCEntrypoints> ObjCData;
300  llvm::MDNode *NoObjCARCExceptionsMetadata = nullptr;
301  std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
302  InstrProfStats PGOStats;
303  std::unique_ptr<llvm::SanitizerStatReport> SanStats;
304 
305  // A set of references that have only been seen via a weakref so far. This is
306  // used to remove the weak of the reference if we ever see a direct reference
307  // or a definition.
308  llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
309 
310  /// This contains all the decls which have definitions but/ which are deferred
311  /// for emission and therefore should only be output if they are actually
312  /// used. If a decl is in this, then it is known to have not been referenced
313  /// yet.
314  std::map<StringRef, GlobalDecl> DeferredDecls;
315 
316  /// This is a list of deferred decls which we have seen that *are* actually
317  /// referenced. These get code generated when the module is done.
318  std::vector<GlobalDecl> DeferredDeclsToEmit;
319  void addDeferredDeclToEmit(GlobalDecl GD) {
320  DeferredDeclsToEmit.emplace_back(GD);
321  }
322 
323  /// List of alias we have emitted. Used to make sure that what they point to
324  /// is defined once we get to the end of the of the translation unit.
325  std::vector<GlobalDecl> Aliases;
326 
327  typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
328  ReplacementsTy Replacements;
329 
330  /// List of global values to be replaced with something else. Used when we
331  /// want to replace a GlobalValue but can't identify it by its mangled name
332  /// anymore (because the name is already taken).
334  GlobalValReplacements;
335 
336  /// Set of global decls for which we already diagnosed mangled name conflict.
337  /// Required to not issue a warning (on a mangling conflict) multiple times
338  /// for the same decl.
339  llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions;
340 
341  /// A queue of (optional) vtables to consider emitting.
342  std::vector<const CXXRecordDecl*> DeferredVTables;
343 
344  /// A queue of (optional) vtables that may be emitted opportunistically.
345  std::vector<const CXXRecordDecl *> OpportunisticVTables;
346 
347  /// List of global values which are required to be present in the object file;
348  /// bitcast to i8*. This is used for forcing visibility of symbols which may
349  /// otherwise be optimized out.
350  std::vector<llvm::WeakTrackingVH> LLVMUsed;
351  std::vector<llvm::WeakTrackingVH> LLVMCompilerUsed;
352 
353  /// Store the list of global constructors and their respective priorities to
354  /// be emitted when the translation unit is complete.
355  CtorList GlobalCtors;
356 
357  /// Store the list of global destructors and their respective priorities to be
358  /// emitted when the translation unit is complete.
359  CtorList GlobalDtors;
360 
361  /// An ordered map of canonical GlobalDecls to their mangled names.
362  llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
363  llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
364 
365  /// Global annotations.
366  std::vector<llvm::Constant*> Annotations;
367 
368  /// Map used to get unique annotation strings.
369  llvm::StringMap<llvm::Constant*> AnnotationStrings;
370 
371  llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
372 
373  llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
374  llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
375  llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
376  llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
377 
378  llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
379  llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
380 
381  /// Map used to get unique type descriptor constants for sanitizers.
382  llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
383 
384  /// Map used to track internal linkage functions declared within
385  /// extern "C" regions.
386  typedef llvm::MapVector<IdentifierInfo *,
387  llvm::GlobalValue *> StaticExternCMap;
388  StaticExternCMap StaticExternCValues;
389 
390  /// \brief thread_local variables defined or used in this TU.
391  std::vector<const VarDecl *> CXXThreadLocals;
392 
393  /// \brief thread_local variables with initializers that need to run
394  /// before any thread_local variable in this TU is odr-used.
395  std::vector<llvm::Function *> CXXThreadLocalInits;
396  std::vector<const VarDecl *> CXXThreadLocalInitVars;
397 
398  /// Global variables with initializers that need to run before main.
399  std::vector<llvm::Function *> CXXGlobalInits;
400 
401  /// When a C++ decl with an initializer is deferred, null is
402  /// appended to CXXGlobalInits, and the index of that null is placed
403  /// here so that the initializer will be performed in the correct
404  /// order. Once the decl is emitted, the index is replaced with ~0U to ensure
405  /// that we don't re-emit the initializer.
406  llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
407 
408  typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
409 
410  struct GlobalInitPriorityCmp {
411  bool operator()(const GlobalInitData &LHS,
412  const GlobalInitData &RHS) const {
413  return LHS.first.priority < RHS.first.priority;
414  }
415  };
416 
417  /// Global variables with initializers whose order of initialization is set by
418  /// init_priority attribute.
419  SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
420 
421  /// Global destructor functions and arguments that need to run on termination.
422  std::vector<std::pair<llvm::WeakTrackingVH, llvm::Constant *>> CXXGlobalDtors;
423 
424  /// \brief The complete set of modules that has been imported.
425  llvm::SetVector<clang::Module *> ImportedModules;
426 
427  /// \brief The set of modules for which the module initializers
428  /// have been emitted.
429  llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
430 
431  /// \brief A vector of metadata strings.
432  SmallVector<llvm::MDNode *, 16> LinkerOptionsMetadata;
433 
434  /// @name Cache for Objective-C runtime types
435  /// @{
436 
437  /// Cached reference to the class for constant strings. This value has type
438  /// int * but is actually an Obj-C class pointer.
439  llvm::WeakTrackingVH CFConstantStringClassRef;
440 
441  /// \brief The type used to describe the state of a fast enumeration in
442  /// Objective-C's for..in loop.
443  QualType ObjCFastEnumerationStateType;
444 
445  /// @}
446 
447  /// Lazily create the Objective-C runtime
448  void createObjCRuntime();
449 
450  void createOpenCLRuntime();
451  void createOpenMPRuntime();
452  void createCUDARuntime();
453 
454  bool isTriviallyRecursive(const FunctionDecl *F);
455  bool shouldEmitFunction(GlobalDecl GD);
456  bool shouldOpportunisticallyEmitVTables();
457  /// Map used to be sure we don't emit the same CompoundLiteral twice.
458  llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *>
459  EmittedCompoundLiterals;
460 
461  /// Map of the global blocks we've emitted, so that we don't have to re-emit
462  /// them if the constexpr evaluator gets aggressive.
463  llvm::DenseMap<const BlockExpr *, llvm::Constant *> EmittedGlobalBlocks;
464 
465  /// @name Cache for Blocks Runtime Globals
466  /// @{
467 
468  llvm::Constant *NSConcreteGlobalBlock = nullptr;
469  llvm::Constant *NSConcreteStackBlock = nullptr;
470 
471  llvm::Constant *BlockObjectAssign = nullptr;
472  llvm::Constant *BlockObjectDispose = nullptr;
473 
474  llvm::Type *BlockDescriptorType = nullptr;
475  llvm::Type *GenericBlockLiteralType = nullptr;
476 
477  struct {
479  } Block;
480 
481  /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
482  llvm::Constant *LifetimeStartFn = nullptr;
483 
484  /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
485  llvm::Constant *LifetimeEndFn = nullptr;
486 
487  GlobalDecl initializedGlobalDecl;
488 
489  std::unique_ptr<SanitizerMetadata> SanitizerMD;
490 
491  /// @}
492 
493  llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
494 
495  std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
496 
497  /// Mapping from canonical types to their metadata identifiers. We need to
498  /// maintain this mapping because identifiers may be formed from distinct
499  /// MDNodes.
500  llvm::DenseMap<QualType, llvm::Metadata *> MetadataIdMap;
501 
502 public:
503  CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts,
504  const PreprocessorOptions &ppopts,
505  const CodeGenOptions &CodeGenOpts, llvm::Module &M,
506  DiagnosticsEngine &Diags,
507  CoverageSourceInfo *CoverageInfo = nullptr);
508 
509  ~CodeGenModule();
510 
511  void clear();
512 
513  /// Finalize LLVM code generation.
514  void Release();
515 
516  /// Return a reference to the configured Objective-C runtime.
518  if (!ObjCRuntime) createObjCRuntime();
519  return *ObjCRuntime;
520  }
521 
522  /// Return true iff an Objective-C runtime has been configured.
523  bool hasObjCRuntime() { return !!ObjCRuntime; }
524 
525  /// Return a reference to the configured OpenCL runtime.
527  assert(OpenCLRuntime != nullptr);
528  return *OpenCLRuntime;
529  }
530 
531  /// Return a reference to the configured OpenMP runtime.
533  assert(OpenMPRuntime != nullptr);
534  return *OpenMPRuntime;
535  }
536 
537  /// Return a reference to the configured CUDA runtime.
539  assert(CUDARuntime != nullptr);
540  return *CUDARuntime;
541  }
542 
544  assert(ObjCData != nullptr);
545  return *ObjCData;
546  }
547 
548  // Version checking function, used to implement ObjC's @available:
549  // i32 @__isOSVersionAtLeast(i32, i32, i32)
550  llvm::Constant *IsOSVersionAtLeastFn = nullptr;
551 
552  InstrProfStats &getPGOStats() { return PGOStats; }
553  llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
554 
556  return CoverageMapping.get();
557  }
558 
559  llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
560  return StaticLocalDeclMap[D];
561  }
563  llvm::Constant *C) {
564  StaticLocalDeclMap[D] = C;
565  }
566 
567  llvm::Constant *
569  llvm::GlobalValue::LinkageTypes Linkage);
570 
571  llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
572  return StaticLocalDeclGuardMap[D];
573  }
575  llvm::GlobalVariable *C) {
576  StaticLocalDeclGuardMap[D] = C;
577  }
578 
579  bool lookupRepresentativeDecl(StringRef MangledName,
580  GlobalDecl &Result) const;
581 
582  llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
583  return AtomicSetterHelperFnMap[Ty];
584  }
586  llvm::Constant *Fn) {
587  AtomicSetterHelperFnMap[Ty] = Fn;
588  }
589 
590  llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
591  return AtomicGetterHelperFnMap[Ty];
592  }
594  llvm::Constant *Fn) {
595  AtomicGetterHelperFnMap[Ty] = Fn;
596  }
597 
598  llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
599  return TypeDescriptorMap[Ty];
600  }
601  void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
602  TypeDescriptorMap[Ty] = C;
603  }
604 
605  CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); }
606 
608  if (!NoObjCARCExceptionsMetadata)
609  NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None);
610  return NoObjCARCExceptionsMetadata;
611  }
612 
613  ASTContext &getContext() const { return Context; }
614  const LangOptions &getLangOpts() const { return LangOpts; }
616  const { return HeaderSearchOpts; }
618  const { return PreprocessorOpts; }
619  const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
620  llvm::Module &getModule() const { return TheModule; }
621  DiagnosticsEngine &getDiags() const { return Diags; }
622  const llvm::DataLayout &getDataLayout() const {
623  return TheModule.getDataLayout();
624  }
625  const TargetInfo &getTarget() const { return Target; }
626  const llvm::Triple &getTriple() const { return Target.getTriple(); }
627  bool supportsCOMDAT() const;
628  void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
629 
630  CGCXXABI &getCXXABI() const { return *ABI; }
631  llvm::LLVMContext &getLLVMContext() { return VMContext; }
632 
633  bool shouldUseTBAA() const { return TBAA != nullptr; }
634 
636 
637  CodeGenTypes &getTypes() { return Types; }
638 
639  CodeGenVTables &getVTables() { return VTables; }
640 
642  return VTables.getItaniumVTableContext();
643  }
644 
646  return VTables.getMicrosoftVTableContext();
647  }
648 
649  CtorList &getGlobalCtors() { return GlobalCtors; }
650  CtorList &getGlobalDtors() { return GlobalDtors; }
651 
652  llvm::MDNode *getTBAAInfo(QualType QTy);
653  llvm::MDNode *getTBAAInfoForVTablePtr();
654  llvm::MDNode *getTBAAStructInfo(QualType QTy);
655  /// Return the path-aware tag for given base type, access node and offset.
656  llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
657  uint64_t O);
658 
659  bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
660 
662  bool isPaddedAtomicType(const AtomicType *type);
663 
664  /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
665  /// is the same as the type. For struct-path aware TBAA, the tag
666  /// is different from the type: base type, access type and offset.
667  /// When ConvertTypeToTag is true, we create a tag based on the scalar type.
668  void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
669  llvm::MDNode *TBAAInfo,
670  bool ConvertTypeToTag = true);
671 
672  /// Adds !invariant.barrier !tag to instruction
673  void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
674  const CXXRecordDecl *RD);
675 
676  /// Emit the given number of characters as a value of type size_t.
677  llvm::ConstantInt *getSize(CharUnits numChars);
678 
679  /// Set the visibility for the given LLVM GlobalValue.
680  void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
681 
682  /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
683  /// variable declaration D.
684  void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
685 
686  static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
687  switch (V) {
691  }
692  llvm_unreachable("unknown visibility!");
693  }
694 
695  llvm::Constant *GetAddrOfGlobal(GlobalDecl GD,
696  ForDefinition_t IsForDefinition
697  = NotForDefinition);
698 
699  /// Will return a global variable of the given type. If a variable with a
700  /// different type already exists then a new variable with the right type
701  /// will be created and all uses of the old variable will be replaced with a
702  /// bitcast to the new variable.
703  llvm::GlobalVariable *
705  llvm::GlobalValue::LinkageTypes Linkage);
706 
707  llvm::Function *
708  CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name,
709  const CGFunctionInfo &FI,
711  bool TLS = false);
712 
713  /// Return the AST address space of the underlying global variable for D, as
714  /// determined by its declaration. Normally this is the same as the address
715  /// space of D's type, but in CUDA, address spaces are associated with
716  /// declarations, not types. If D is nullptr, return the default address
717  /// space for global variable.
718  ///
719  /// For languages without explicit address spaces, if D has default address
720  /// space, target-specific global or constant address space may be returned.
721  unsigned GetGlobalVarAddressSpace(const VarDecl *D);
722 
723  /// Return the llvm::Constant for the address of the given global variable.
724  /// If Ty is non-null and if the global doesn't exist, then it will be created
725  /// with the specified type instead of whatever the normal requested type
726  /// would be. If IsForDefinition is true, it is guranteed that an actual
727  /// global with type Ty will be returned, not conversion of a variable with
728  /// the same mangled name but some other type.
729  llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
730  llvm::Type *Ty = nullptr,
731  ForDefinition_t IsForDefinition
732  = NotForDefinition);
733 
734  /// Return the address of the given function. If Ty is non-null, then this
735  /// function will use the specified type if it has to create it.
736  llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
737  bool ForVTable = false,
738  bool DontDefer = false,
739  ForDefinition_t IsForDefinition
740  = NotForDefinition);
741 
742  /// Get the address of the RTTI descriptor for the given type.
743  llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
744 
745  /// Get the address of a uuid descriptor .
747 
748  /// Get the address of the thunk for the given global decl.
749  llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
750 
751  /// Get a reference to the target of VD.
753 
754  /// Returns the assumed alignment of an opaque pointer to the given class.
756 
757  /// Returns the assumed alignment of a virtual base of a class.
759  const CXXRecordDecl *Derived,
760  const CXXRecordDecl *VBase);
761 
762  /// Given a class pointer with an actual known alignment, and the
763  /// expected alignment of an object at a dynamic offset w.r.t that
764  /// pointer, return the alignment to assume at the offset.
766  const CXXRecordDecl *Class,
767  CharUnits ExpectedTargetAlign);
768 
769  CharUnits
773 
774  /// Returns the offset from a derived class to a class. Returns null if the
775  /// offset is 0.
776  llvm::Constant *
780 
781  llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
782 
783  /// Fetches the global unique block count.
784  int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
785 
786  /// Fetches the type of a generic block descriptor.
788 
789  /// The type of a generic block literal.
791 
792  /// Gets the address of a block which requires no captures.
793  llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name);
794 
795  /// Returns the address of a block which requires no caputres, or null if
796  /// we've yet to emit the block for BE.
797  llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) {
798  return EmittedGlobalBlocks.lookup(BE);
799  }
800 
801  /// Notes that BE's global block is available via Addr. Asserts that BE
802  /// isn't already emitted.
803  void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
804 
805  /// Return a pointer to a constant CFString object for the given string.
807 
808  /// Return a pointer to a constant NSString object for the given string. Or a
809  /// user defined String object as defined via
810  /// -fconstant-string-class=class_name option.
812 
813  /// Return a constant array for the given string.
814  llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
815 
816  /// Return a pointer to a constant array for the given string literal.
819  StringRef Name = ".str");
820 
821  /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
824 
825  /// Returns a pointer to a character array containing the literal and a
826  /// terminating '\0' character. The result has pointer to array type.
827  ///
828  /// \param GlobalName If provided, the name to use for the global (if one is
829  /// created).
831  GetAddrOfConstantCString(const std::string &Str,
832  const char *GlobalName = nullptr);
833 
834  /// Returns a pointer to a constant global variable for the given file-scope
835  /// compound literal expression.
837 
838  /// If it's been emitted already, returns the GlobalVariable corresponding to
839  /// a compound literal. Otherwise, returns null.
840  llvm::GlobalVariable *
842 
843  /// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already
844  /// emitted.
846  llvm::GlobalVariable *GV);
847 
848  /// \brief Returns a pointer to a global variable representing a temporary
849  /// with static or thread storage duration.
851  const Expr *Inner);
852 
853  /// \brief Retrieve the record type that describes the state of an
854  /// Objective-C fast enumeration loop (for..in).
856 
857  // Produce code for this constructor/destructor. This method doesn't try
858  // to apply any ABI rules about which other constructors/destructors
859  // are needed or if they are alias to each other.
860  llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
862 
863  /// Return the address of the constructor/destructor of the given type.
864  llvm::Constant *
866  const CGFunctionInfo *FnInfo = nullptr,
867  llvm::FunctionType *FnType = nullptr,
868  bool DontDefer = false,
869  ForDefinition_t IsForDefinition = NotForDefinition);
870 
871  /// Given a builtin id for a function like "__builtin_fabsf", return a
872  /// Function* for "fabsf".
873  llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
874  unsigned BuiltinID);
875 
876  llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
877 
878  /// Emit code for a single top level declaration.
879  void EmitTopLevelDecl(Decl *D);
880 
881  /// \brief Stored a deferred empty coverage mapping for an unused
882  /// and thus uninstrumented top level declaration.
884 
885  /// \brief Remove the deferred empty coverage mapping as this
886  /// declaration is actually instrumented.
887  void ClearUnusedCoverageMapping(const Decl *D);
888 
889  /// \brief Emit all the deferred coverage mappings
890  /// for the uninstrumented functions.
892 
893  /// Tell the consumer that this variable has been instantiated.
895 
896  /// \brief If the declaration has internal linkage but is inside an
897  /// extern "C" linkage specification, prepare to emit an alias for it
898  /// to the expected name.
899  template<typename SomeDecl>
900  void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
901 
902  /// Add a global to a list to be added to the llvm.used metadata.
903  void addUsedGlobal(llvm::GlobalValue *GV);
904 
905  /// Add a global to a list to be added to the llvm.compiler.used metadata.
906  void addCompilerUsedGlobal(llvm::GlobalValue *GV);
907 
908  /// Add a destructor and object to add to the C++ global destructor function.
909  void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
910  CXXGlobalDtors.emplace_back(DtorFn, Object);
911  }
912 
913  /// Create a new runtime function with the specified type and name.
914  llvm::Constant *
915  CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name,
916  llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
917  bool Local = false);
918 
919  /// Create a new compiler builtin function with the specified type and name.
920  llvm::Constant *
921  CreateBuiltinFunction(llvm::FunctionType *Ty, StringRef Name,
922  llvm::AttributeList ExtraAttrs = llvm::AttributeList());
923  /// Create a new runtime global variable with the specified type and name.
924  llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
925  StringRef Name);
926 
927  ///@name Custom Blocks Runtime Interfaces
928  ///@{
929 
930  llvm::Constant *getNSConcreteGlobalBlock();
931  llvm::Constant *getNSConcreteStackBlock();
932  llvm::Constant *getBlockObjectAssign();
933  llvm::Constant *getBlockObjectDispose();
934 
935  ///@}
936 
937  llvm::Constant *getLLVMLifetimeStartFn();
938  llvm::Constant *getLLVMLifetimeEndFn();
939 
940  // Make sure that this type is translated.
941  void UpdateCompletedType(const TagDecl *TD);
942 
943  llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
944 
945  /// Try to emit the initializer for the given declaration as a constant;
946  /// returns 0 if the expression cannot be emitted as a constant.
947  llvm::Constant *EmitConstantInit(const VarDecl &D,
948  CodeGenFunction *CGF = nullptr);
949 
950  /// Try to emit the given expression as a constant; returns 0 if the
951  /// expression cannot be emitted as a constant.
952  llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
953  CodeGenFunction *CGF = nullptr);
954 
955  /// Emit the given constant value as a constant, in the type's scalar
956  /// representation.
957  llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
958  CodeGenFunction *CGF = nullptr);
959 
960  /// Emit the given constant value as a constant, in the type's memory
961  /// representation.
962  llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
963  QualType DestType,
964  CodeGenFunction *CGF = nullptr);
965 
966  /// \brief Emit type info if type of an expression is a variably modified
967  /// type. Also emit proper debug info for cast types.
969  CodeGenFunction *CGF = nullptr);
970 
971  /// Return the result of value-initializing the given type, i.e. a null
972  /// expression of the given type. This is usually, but not always, an LLVM
973  /// null constant.
974  llvm::Constant *EmitNullConstant(QualType T);
975 
976  /// Return a null constant appropriate for zero-initializing a base class with
977  /// the given type. This is usually, but not always, an LLVM null constant.
978  llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
979 
980  /// Emit a general error that something can't be done.
981  void Error(SourceLocation loc, StringRef error);
982 
983  /// Print out an error that codegen doesn't support the specified stmt yet.
984  void ErrorUnsupported(const Stmt *S, const char *Type);
985 
986  /// Print out an error that codegen doesn't support the specified decl yet.
987  void ErrorUnsupported(const Decl *D, const char *Type);
988 
989  /// Set the attributes on the LLVM function for the given decl and function
990  /// info. This applies attributes necessary for handling the ABI as well as
991  /// user specified attributes like section.
992  void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
993  const CGFunctionInfo &FI);
994 
995  /// Set the LLVM function attributes (sext, zext, etc).
996  void SetLLVMFunctionAttributes(const Decl *D,
997  const CGFunctionInfo &Info,
998  llvm::Function *F);
999 
1000  /// Set the LLVM function attributes which only apply to a function
1001  /// definition.
1002  void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
1003 
1004  /// Return true iff the given type uses 'sret' when used as a return type.
1005  bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
1006 
1007  /// Return true iff the given type uses an argument slot when 'sret' is used
1008  /// as a return type.
1010 
1011  /// Return true iff the given type uses 'fpret' when used as a return type.
1012  bool ReturnTypeUsesFPRet(QualType ResultType);
1013 
1014  /// Return true iff the given type uses 'fp2ret' when used as a return type.
1015  bool ReturnTypeUsesFP2Ret(QualType ResultType);
1016 
1017  /// Get the LLVM attributes and calling convention to use for a particular
1018  /// function type.
1019  ///
1020  /// \param Name - The function name.
1021  /// \param Info - The function type information.
1022  /// \param CalleeInfo - The callee information these attributes are being
1023  /// constructed for. If valid, the attributes applied to this decl may
1024  /// contribute to the function attributes and calling convention.
1025  /// \param Attrs [out] - On return, the attribute list to use.
1026  /// \param CallingConv [out] - On return, the LLVM calling convention to use.
1027  void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
1028  CGCalleeInfo CalleeInfo,
1029  llvm::AttributeList &Attrs, unsigned &CallingConv,
1030  bool AttrOnCallSite);
1031 
1032  /// Adds attributes to F according to our CodeGenOptions and LangOptions, as
1033  /// though we had emitted it ourselves. We remove any attributes on F that
1034  /// conflict with the attributes we add here.
1035  ///
1036  /// This is useful for adding attrs to bitcode modules that you want to link
1037  /// with but don't control, such as CUDA's libdevice. When linking with such
1038  /// a bitcode library, you might want to set e.g. its functions'
1039  /// "unsafe-fp-math" attribute to match the attr of the functions you're
1040  /// codegen'ing. Otherwise, LLVM will interpret the bitcode module's lack of
1041  /// unsafe-fp-math attrs as tantamount to unsafe-fp-math=false, and then LLVM
1042  /// will propagate unsafe-fp-math=false up to every transitive caller of a
1043  /// function in the bitcode library!
1044  ///
1045  /// With the exception of fast-math attrs, this will only make the attributes
1046  /// on the function more conservative. But it's unsafe to call this on a
1047  /// function which relies on particular fast-math attributes for correctness.
1048  /// It's up to you to ensure that this is safe.
1049  void AddDefaultFnAttrs(llvm::Function &F);
1050 
1051  // Fills in the supplied string map with the set of target features for the
1052  // passed in function.
1053  void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
1054  const FunctionDecl *FD);
1055 
1056  StringRef getMangledName(GlobalDecl GD);
1057  StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
1058 
1059  void EmitTentativeDefinition(const VarDecl *D);
1060 
1061  void EmitVTable(CXXRecordDecl *Class);
1062 
1063  void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
1064 
1065  /// \brief Appends Opts to the "llvm.linker.options" metadata value.
1066  void AppendLinkerOptions(StringRef Opts);
1067 
1068  /// \brief Appends a detect mismatch command to the linker options.
1069  void AddDetectMismatch(StringRef Name, StringRef Value);
1070 
1071  /// \brief Appends a dependent lib to the "llvm.linker.options" metadata
1072  /// value.
1073  void AddDependentLib(StringRef Lib);
1074 
1075  llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
1076 
1077  void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
1078  F->setLinkage(getFunctionLinkage(GD));
1079  }
1080 
1081  /// Set the DLL storage class on F.
1082  void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F);
1083 
1084  /// Return the appropriate linkage for the vtable, VTT, and type information
1085  /// of the given class.
1086  llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
1087 
1088  /// Return the store size, in character units, of the given LLVM type.
1090 
1091  /// Returns LLVM linkage for a declarator.
1092  llvm::GlobalValue::LinkageTypes
1094  bool IsConstantVariable);
1095 
1096  /// Returns LLVM linkage for a declarator.
1097  llvm::GlobalValue::LinkageTypes
1098  getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
1099 
1100  /// Emit all the global annotations.
1101  void EmitGlobalAnnotations();
1102 
1103  /// Emit an annotation string.
1104  llvm::Constant *EmitAnnotationString(StringRef Str);
1105 
1106  /// Emit the annotation's translation unit.
1107  llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
1108 
1109  /// Emit the annotation line number.
1110  llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
1111 
1112  /// Generate the llvm::ConstantStruct which contains the annotation
1113  /// information for a given GlobalValue. The annotation struct is
1114  /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
1115  /// GlobalValue being annotated. The second field is the constant string
1116  /// created from the AnnotateAttr's annotation. The third field is a constant
1117  /// string containing the name of the translation unit. The fourth field is
1118  /// the line number in the file of the annotated value declaration.
1119  llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
1120  const AnnotateAttr *AA,
1121  SourceLocation L);
1122 
1123  /// Add global annotations that are set on D, for the global GV. Those
1124  /// annotations are emitted during finalization of the LLVM code.
1125  void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
1126 
1127  bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const;
1128 
1129  bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
1130  QualType Ty,
1131  StringRef Category = StringRef()) const;
1132 
1133  /// Imbue XRay attributes to a function, applying the always/never attribute
1134  /// lists in the process. Returns true if we did imbue attributes this way,
1135  /// false otherwise.
1136  bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
1137  StringRef Category = StringRef()) const;
1138 
1140  return SanitizerMD.get();
1141  }
1142 
1144  DeferredVTables.push_back(RD);
1145  }
1146 
1147  /// Emit code for a singal global function or var decl. Forward declarations
1148  /// are emitted lazily.
1149  void EmitGlobal(GlobalDecl D);
1150 
1151  bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
1152  bool InEveryTU);
1154 
1155  /// Set attributes for a global definition.
1157  llvm::Function *F);
1158 
1159  llvm::GlobalValue *GetGlobalValue(StringRef Ref);
1160 
1161  /// Set attributes which are common to any form of a global definition (alias,
1162  /// Objective-C method, function, global variable).
1163  ///
1164  /// NOTE: This should only be called for definitions.
1165  void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
1166 
1167  /// Set attributes which must be preserved by an alias. This includes common
1168  /// attributes (i.e. it includes a call to SetCommonAttributes).
1169  ///
1170  /// NOTE: This should only be called for definitions.
1171  void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
1172 
1173  void addReplacement(StringRef Name, llvm::Constant *C);
1174 
1175  void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
1176 
1177  /// \brief Emit a code for threadprivate directive.
1178  /// \param D Threadprivate declaration.
1180 
1181  /// \brief Emit a code for declare reduction construct.
1183  CodeGenFunction *CGF = nullptr);
1184 
1185  /// Returns whether the given record has hidden LTO visibility and therefore
1186  /// may participate in (single-module) CFI and whole-program vtable
1187  /// optimization.
1188  bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
1189 
1190  /// Emit type metadata for the given vtable using the given layout.
1191  void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
1192  const VTableLayout &VTLayout);
1193 
1194  /// Generate a cross-DSO type identifier for MD.
1195  llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD);
1196 
1197  /// Create a metadata identifier for the given type. This may either be an
1198  /// MDString (for external identifiers) or a distinct unnamed MDNode (for
1199  /// internal identifiers).
1200  llvm::Metadata *CreateMetadataIdentifierForType(QualType T);
1201 
1202  /// Create and attach type metadata to the given function.
1203  void CreateFunctionTypeMetadata(const FunctionDecl *FD, llvm::Function *F);
1204 
1205  /// Returns whether this module needs the "all-vtables" type identifier.
1206  bool NeedAllVtablesTypeId() const;
1207 
1208  /// Create and attach type metadata for the given vtable.
1209  void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset,
1210  const CXXRecordDecl *RD);
1211 
1212  /// \brief Get the declaration of std::terminate for the platform.
1213  llvm::Constant *getTerminateFn();
1214 
1215  llvm::SanitizerStatReport &getSanStats();
1216 
1217  llvm::Value *
1219 
1220  /// Get target specific null pointer.
1221  /// \param T is the LLVM type of the null pointer.
1222  /// \param QT is the clang QualType of the null pointer.
1223  llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT);
1224 
1225 private:
1226  llvm::Constant *GetOrCreateLLVMFunction(
1227  StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
1228  bool DontDefer = false, bool IsThunk = false,
1229  llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1230  ForDefinition_t IsForDefinition = NotForDefinition);
1231 
1232  llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
1233  llvm::PointerType *PTy,
1234  const VarDecl *D,
1235  ForDefinition_t IsForDefinition
1236  = NotForDefinition);
1237 
1238  void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
1239 
1240  /// Set function attributes for a function declaration.
1241  void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1242  bool IsIncompleteFunction, bool IsThunk);
1243 
1244  void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
1245 
1246  void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
1247  void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
1248  void EmitAliasDefinition(GlobalDecl GD);
1249  void emitIFuncDefinition(GlobalDecl GD);
1250  void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
1251  void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
1252 
1253  // C++ related functions.
1254 
1255  void EmitDeclContext(const DeclContext *DC);
1256  void EmitLinkageSpec(const LinkageSpecDecl *D);
1257 
1258  /// \brief Emit the function that initializes C++ thread_local variables.
1259  void EmitCXXThreadLocalInitFunc();
1260 
1261  /// Emit the function that initializes C++ globals.
1262  void EmitCXXGlobalInitFunc();
1263 
1264  /// Emit the function that destroys C++ globals.
1265  void EmitCXXGlobalDtorFunc();
1266 
1267  /// Emit the function that initializes the specified global (if PerformInit is
1268  /// true) and registers its destructor.
1269  void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
1270  llvm::GlobalVariable *Addr,
1271  bool PerformInit);
1272 
1273  void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
1274  llvm::Function *InitFunc, InitSegAttr *ISA);
1275 
1276  // FIXME: Hardcoding priority here is gross.
1277  void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
1278  llvm::Constant *AssociatedData = nullptr);
1279  void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
1280 
1281  /// EmitCtorList - Generates a global array of functions and priorities using
1282  /// the given list and name. This array will have appending linkage and is
1283  /// suitable for use as a LLVM constructor or destructor array. Clears Fns.
1284  void EmitCtorList(CtorList &Fns, const char *GlobalName);
1285 
1286  /// Emit any needed decls for which code generation was deferred.
1287  void EmitDeferred();
1288 
1289  /// Try to emit external vtables as available_externally if they have emitted
1290  /// all inlined virtual functions. It runs after EmitDeferred() and therefore
1291  /// is not allowed to create new references to things that need to be emitted
1292  /// lazily.
1293  void EmitVTablesOpportunistically();
1294 
1295  /// Call replaceAllUsesWith on all pairs in Replacements.
1296  void applyReplacements();
1297 
1298  /// Call replaceAllUsesWith on all pairs in GlobalValReplacements.
1299  void applyGlobalValReplacements();
1300 
1301  void checkAliases();
1302 
1303  /// Emit any vtables which we deferred and still have a use for.
1304  void EmitDeferredVTables();
1305 
1306  /// Emit a dummy function that reference a CoreFoundation symbol when
1307  /// @available is used on Darwin.
1308  void emitAtAvailableLinkGuard();
1309 
1310  /// Emit the llvm.used and llvm.compiler.used metadata.
1311  void emitLLVMUsed();
1312 
1313  /// \brief Emit the link options introduced by imported modules.
1314  void EmitModuleLinkOptions();
1315 
1316  /// \brief Emit aliases for internal-linkage declarations inside "C" language
1317  /// linkage specifications, giving them the "expected" name where possible.
1318  void EmitStaticExternCAliases();
1319 
1320  void EmitDeclMetadata();
1321 
1322  /// \brief Emit the Clang version as llvm.ident metadata.
1323  void EmitVersionIdentMetadata();
1324 
1325  /// Emits target specific Metadata for global declarations.
1326  void EmitTargetMetadata();
1327 
1328  /// Emits OpenCL specific Metadata e.g. OpenCL version.
1329  void EmitOpenCLMetadata();
1330 
1331  /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
1332  /// .gcda files in a way that persists in .bc files.
1333  void EmitCoverageFile();
1334 
1335  /// Emits the initializer for a uuidof string.
1336  llvm::Constant *EmitUuidofInitializer(StringRef uuidstr);
1337 
1338  /// Determine whether the definition must be emitted; if this returns \c
1339  /// false, the definition can be emitted lazily if it's used.
1340  bool MustBeEmitted(const ValueDecl *D);
1341 
1342  /// Determine whether the definition can be emitted eagerly, or should be
1343  /// delayed until the end of the translation unit. This is relevant for
1344  /// definitions whose linkage can change, e.g. implicit function instantions
1345  /// which may later be explicitly instantiated.
1346  bool MayBeEmittedEagerly(const ValueDecl *D);
1347 
1348  /// Check whether we can use a "simpler", more core exceptions personality
1349  /// function.
1350  void SimplifyPersonality();
1351 
1352  /// Helper function for ConstructAttributeList and AddDefaultFnAttrs.
1353  /// Constructs an AttrList for a function with the given properties.
1354  void ConstructDefaultFnAttrList(StringRef Name, bool HasOptnone,
1355  bool AttrOnCallSite,
1356  llvm::AttrBuilder &FuncAttrs);
1357 };
1358 } // end namespace CodeGen
1359 } // end namespace clang
1360 
1361 #endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1618
llvm::Type * getGenericBlockLiteralType()
The type of a generic block literal.
Definition: CGBlocks.cpp:975
void EmitDeferredUnusedCoverageMappings()
Emit all the deferred coverage mappings for the uninstrumented functions.
void DecorateInstructionWithInvariantGroup(llvm::Instruction *I, const CXXRecordDecl *RD)
Adds !invariant.barrier !tag to instruction.
ObjCEntrypoints & getObjCEntrypoints() const
void Profile(llvm::FoldingSetNodeID &id) const
void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C)
A (possibly-)qualified type.
Definition: Type.h:616
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI)
Return true iff the given type uses 'sret' when used as a return type.
Definition: CGCall.cpp:1476
bool hasObjCRuntime()
Return true iff an Objective-C runtime has been configured.
llvm::Module & getModule() const
llvm::Constant * getMemberPointerConstant(const UnaryOperator *e)
llvm::LLVMContext & getLLVMContext()
ConstantAddress GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *)
Return a pointer to a constant array for the given ObjCEncodeExpr node.
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
Definition: CGClass.cpp:36
Stmt - This represents one statement.
Definition: Stmt.h:60
unsigned GetGlobalVarAddressSpace(const VarDecl *D)
Return the AST address space of the underlying global variable for D, as determined by its declaratio...
Implements runtime-specific code generation functions.
Definition: CGObjCRuntime.h:63
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
Defines the clang::Module class, which describes a module in the source code.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
llvm::Constant * objc_autoreleaseReturnValue
id objc_autoreleaseReturnValue(id);
llvm::MDNode * getTBAAStructInfo(QualType QTy)
BlockByrefHelpers(CharUnits alignment)
void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV)
Set attributes which must be preserved by an alias.
const llvm::DataLayout & getDataLayout() const
The base class of the type hierarchy.
Definition: Type.h:1303
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
Stores additional source code information like skipped ranges which is required by the coverage mappi...
llvm::Constant * objc_loadWeakRetained
id objc_loadWeakRetained(id*);
const PreprocessorOptions & getPreprocessorOpts() const
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool HasHiddenLTOVisibility(const CXXRecordDecl *RD)
Returns whether the given record has hidden LTO visibility and therefore may participate in (single-m...
Definition: CGVTables.cpp:912
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
bool operator==(const OrderGlobalInits &RHS) const
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D)
Try to emit a base destructor as an alias to its primary base-class destructor.
Definition: CGCXX.cpp:34
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Definition: ExprCXX.h:3946
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V)
llvm::Constant * EmitConstantValue(const APValue &Value, QualType DestType, CodeGenFunction *CGF=nullptr)
Emit the given constant value as a constant, in the type's scalar representation. ...
const CXXBaseSpecifier *const * path_const_iterator
Definition: Expr.h:2766
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD)
Tell the consumer that this variable has been instantiated.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:758
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition: Visibility.h:35
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:2628
void setFunctionDefinitionAttributes(const FunctionDecl *D, llvm::Function *F)
Set attributes for a global definition.
CGDebugInfo * getModuleDebugInfo()
void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F)
Set the DLL storage class on F.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:53
CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const
Return the store size, in character units, of the given LLVM type.
llvm::Constant * getAtomicSetterHelperFnMap(QualType Ty)
bool NeedAllVtablesTypeId() const
Returns whether this module needs the "all-vtables" type identifier.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:25
llvm::Constant * EmitConstantValueForMemory(const APValue &Value, QualType DestType, CodeGenFunction *CGF=nullptr)
Emit the given constant value as a constant, in the type's memory representation. ...
llvm::Constant * objc_autorelease
id objc_autorelease(id);
llvm::GlobalVariable * getStaticLocalDeclGuardAddress(const VarDecl *D)
llvm::Constant * objc_copyWeak
void objc_copyWeak(id *dest, id *src);
llvm::Constant * getAtomicGetterHelperFnMap(QualType Ty)
One of these records is kept for each identifier that is lexed.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Constant * objc_loadWeak
id objc_loadWeak(id*);
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
llvm::Constant * objc_retainAutoreleasedReturnValue
id objc_retainAutoreleasedReturnValue(id);
llvm::Constant * getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the constructor/destructor of the given type.
Definition: CGCXX.cpp:240
int Category
Definition: Format.cpp:1304
bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc, StringRef Category=StringRef()) const
Imbue XRay attributes to a function, applying the always/never attribute lists in the process...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
llvm::Function * codegenCXXStructor(const CXXMethodDecl *MD, StructorType Type)
Definition: CGCXX.cpp:215
The this pointer adjustment as well as an optional return adjustment for a thunk. ...
Definition: ABI.h:179
bool isPaddedAtomicType(QualType type)
Objects with "default" visibility are seen by the dynamic linker and act like normal objects...
Definition: Visibility.h:44
llvm::Constant * GetConstantArrayFromStringLiteral(const StringLiteral *E)
Return a constant array for the given string.
CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign, const CXXRecordDecl *Class, CharUnits ExpectedTargetAlign)
Given a class pointer with an actual known alignment, and the expected alignment of an object at a dy...
Definition: CGClass.cpp:70
llvm::Constant * getLLVMLifetimeStartFn()
Lazily declare the .lifetime.start intrinsic.
Definition: CGDecl.cpp:1733
virtual void profileImpl(llvm::FoldingSetNodeID &id) const =0
bool operator<(const OrderGlobalInits &RHS) const
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
llvm::Constant * objc_initWeak
id objc_initWeak(id*, id);
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
uint32_t Offset
Definition: CacheTokens.cpp:43
void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare reduction construct.
Definition: CGDecl.cpp:1933
Structor(int Priority, llvm::Constant *Initializer, llvm::Constant *AssociatedData)
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:32
void setStaticLocalDeclAddress(const VarDecl *D, llvm::Constant *C)
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
llvm::Constant * objc_release
void objc_release(id);
ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal)
Return a pointer to a constant NSString object for the given string.
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs, unsigned &CallingConv, bool AttrOnCallSite)
Get the LLVM attributes and calling convention to use for a particular function type.
Definition: CGCall.cpp:1772
llvm::Constant * getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE)
Returns the address of a block which requires no caputres, or null if we've yet to emit the block for...
void addDeferredVTable(const CXXRecordDecl *RD)
void setAtomicGetterHelperFnMap(QualType Ty, llvm::Constant *Fn)
llvm::Constant * getTerminateFn()
Get the declaration of std::terminate for the platform.
Definition: CGException.cpp:50
void addMissing(bool MainFile)
Record that a function we've visited has no profile data.
void addCompilerUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.compiler.used metadata.
Enums/classes describing ABI related information about constructors, destructors and thunks...
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
ItaniumVTableContext & getItaniumVTableContext()
Definition: CGVTables.h:81
void EmitTentativeDefinition(const VarDecl *D)
llvm::SanitizerStatReport & getSanStats()
Represents a linkage specification.
Definition: DeclCXX.h:2666
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const
Set the visibility for the given LLVM GlobalValue.
detail::InMemoryDirectory::const_iterator I
llvm::Constant * getNSConcreteStackBlock()
Definition: CGBlocks.cpp:2491
llvm::Constant * CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false)
Create a new runtime function with the specified type and name.
InstrProfStats & getPGOStats()
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
const HeaderSearchOptions & getHeaderSearchOpts() const
llvm::Constant * getStaticLocalDeclAddress(const VarDecl *D)
const TargetCodeGenInfo & getTargetCodeGenInfo()
llvm::Constant * objc_storeStrong
void objc_storeStrong(id*, id);
virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src)=0
void AddDetectMismatch(StringRef Name, StringRef Value)
Appends a detect mismatch command to the linker options.
const TargetInfo & getTarget() const
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:636
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
llvm::Constant * getNullPointer(llvm::PointerType *T, QualType QT)
Get target specific null pointer.
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *FD)
Exposes information about the current target.
Definition: TargetInfo.h:54
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, llvm::MDNode *TBAAInfo, bool ConvertTypeToTag=true)
Decorate the instruction with a TBAA tag.
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
void SetLLVMFunctionAttributes(const Decl *D, const CGFunctionInfo &Info, llvm::Function *F)
Set the LLVM function attributes (sext, zext, etc).
llvm::Constant * EmitAnnotationUnit(SourceLocation Loc)
Emit the annotation's translation unit.
CharUnits Alignment
The alignment of the field.
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Definition: Decl.h:3557
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:580
Expr - This represents one expression.
Definition: Expr.h:105
Defines the clang::LangOptions interface.
llvm::Constant * objc_autoreleasePoolPop
void objc_autoreleasePoolPop(void*);
virtual bool needsCopy() const
CGCXXABI & getCXXABI() const
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV)
Add global annotations that are set on D, for the global GV.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, ForDefinition_t IsForDefinition=NotForDefinition)
Return the llvm::Constant for the address of the given global variable.
void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, const CGFunctionInfo &FI)
Set the attributes on the LLVM function for the given decl and function info.
Organizes the cross-function state that is used while generating code coverage mapping data...
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:4820
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2551
void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile)
Report potential problems we've found to Diags.
void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object)
Add a destructor and object to add to the C++ global destructor function.
llvm::Constant * objc_retain
id objc_retain(id);
ASTContext & getContext() const
void setStaticLocalDeclGuardAddress(const VarDecl *D, llvm::GlobalVariable *C)
MicrosoftVTableContext & getMicrosoftVTableContext()
bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI)
Return true iff the given type uses an argument slot when 'sret' is used as a return type...
Definition: CGCall.cpp:1480
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
Objects with "protected" visibility are seen by the dynamic linker but always dynamically resolve to ...
Definition: Visibility.h:40
void addMismatched(bool MainFile)
Record that a function we've visited has mismatched profile data.
llvm::Constant * EmitAnnotationString(StringRef Str)
Emit an annotation string.
ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr *E)
Get the address of a uuid descriptor .
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1714
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
CGOpenMPRuntime(CodeGenModule &CGM)
void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset, const CXXRecordDecl *RD)
Create and attach type metadata for the given vtable.
bool lookupRepresentativeDecl(StringRef MangledName, GlobalDecl &Result) const
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:232
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:29
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage)
Will return a global variable of the given type.
llvm::Constant * EmitAnnotateAttr(llvm::GlobalValue *GV, const AnnotateAttr *AA, SourceLocation L)
Generate the llvm::ConstantStruct which contains the annotation information for a given GlobalValue...
llvm::Constant * GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk)
Get the address of the thunk for the given global decl.
Definition: CGVTables.cpp:33
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
void addVisited(bool MainFile)
Record that we've visited a function and whether or not that function was in the main source file...
The l-value was considered opaque, so the alignment was determined from a type.
llvm::Constant * objc_retainBlock
id objc_retainBlock(id);
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
Definition: CGDecl.cpp:204
void RefreshTypeCacheForClass(const CXXRecordDecl *Class)
bool ReturnTypeUsesFPRet(QualType ResultType)
Return true iff the given type uses 'fpret' when used as a return type.
Definition: CGCall.cpp:1485
llvm::Constant * objc_storeWeak
id objc_storeWeak(id*, id);
void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV)
If the declaration has internal linkage but is inside an extern "C" linkage specification, prepare to emit an alias for it to the expected name.
llvm::Constant * EmitConstantExpr(const Expr *E, QualType DestType, CodeGenFunction *CGF=nullptr)
Try to emit the given expression as a constant; returns 0 if the expression cannot be emitted as a co...
Encodes a location in the source.
llvm::Constant * getTypeDescriptorFromMap(QualType Ty)
This represents '#pragma omp declare reduction ...' directive.
Definition: DeclOpenMP.h:102
ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal)
Return a pointer to a constant CFString object for the given string.
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2816
llvm::Metadata * CreateMetadataIdentifierForType(QualType T)
Create a metadata identifier for the given type.
llvm::Constant * objc_autoreleasePoolPush
void *objc_autoreleasePoolPush(void);
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1903
ConstantAddress GetAddrOfConstantStringFromLiteral(const StringLiteral *S, StringRef Name=".str")
Return a pointer to a constant array for the given string literal.
llvm::Constant * EmitNullConstantForBase(const CXXRecordDecl *Record)
Return a null constant appropriate for zero-initializing a base class with the given type...
This file defines OpenMP nodes for declarative directives.
llvm::Constant * CreateBuiltinFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList())
Create a new compiler builtin function with the specified type and name.
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
llvm::MDNode * getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN, uint64_t O)
Return the path-aware tag for given base type, access node and offset.
llvm::InlineAsm * retainAutoreleasedReturnValueMarker
A void(void) inline asm to use to mark that the return value of a call will be immediately retain...
const CodeGenOptions & getCodeGenOpts() const
void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C)
ConstantAddress GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
llvm::Constant * getBlockObjectDispose()
Definition: CGBlocks.cpp:2456
An aligned address.
Definition: Address.h:25
const LangOptions & getLangOpts() const
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
void EmitTopLevelDecl(Decl *D)
Emit code for a single top level declaration.
llvm::GlobalVariable * getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E)
If it's been emitted already, returns the GlobalVariable corresponding to a compound literal...
void CreateFunctionTypeMetadata(const FunctionDecl *FD, llvm::Function *F)
Create and attach type metadata to the given function.
llvm::Constant * EmitAnnotationLineNo(SourceLocation L)
Emit the annotation line number.
virtual bool needsDispose() const
ItaniumVTableContext & getItaniumVTableContext()
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues, like target-specific attributes, builtins and so on.
Definition: TargetInfo.h:44
bool ReturnTypeUsesFP2Ret(QualType ResultType)
Return true iff the given type uses 'fp2ret' when used as a return type.
Definition: CGCall.cpp:1502
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can't be done.
llvm::Constant * getLLVMLifetimeEndFn()
Lazily declare the .lifetime.end intrinsic.
Definition: CGDecl.cpp:1742
std::vector< Structor > CtorList
void addReplacement(StringRef Name, llvm::Constant *C)
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character...
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
llvm::Constant * objc_unsafeClaimAutoreleasedReturnValue
id objc_unsafeClaimAutoreleasedReturnValue(id);
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
llvm::FoldingSet< BlockByrefHelpers > ByrefHelpersCache
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1215
int getUniqueBlockCount()
Fetches the global unique block count.
StringRef Name
Definition: USRFinder.cpp:123
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:2126
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:25
void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable, const VTableLayout &VTLayout)
Emit type metadata for the given vtable using the given layout.
Definition: CGVTables.cpp:946
bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target, bool InEveryTU)
Try to emit a definition as a global alias for another definition.
Definition: CGCXX.cpp:120
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const
Set the TLS mode for the given LLVM GlobalValue for the thread-local variable declaration D...
void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D)
Emit a code for threadprivate directive.
llvm::Constant * objc_destroyWeak
void objc_destroyWeak(id*);
llvm::Constant * clang_arc_use
void clang.arc.use(...);
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:792
void UpdateCompletedType(const TagDecl *TD)
detail::InMemoryDirectory::const_iterator E
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:2870
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO)
CharUnits getVBaseAlignment(CharUnits DerivedAlign, const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the assumed alignment of a virtual base of a class.
Definition: CGClass.cpp:55
bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const
void AddDeferredUnusedCoverageMapping(Decl *D)
Stored a deferred empty coverage mapping for an unused and thus uninstrumented top level declaration...
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class...
Definition: CGVTables.cpp:730
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2448
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
Definition: CGExpr.cpp:880
void AppendLinkerOptions(StringRef Opts)
Appends Opts to the "llvm.linker.options" metadata value.
Implements C++ ABI-specific code generation functions.
Definition: CGCXXABI.h:44
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:355
This class organizes the cross-module state that is used while lowering AST types to LLVM types...
Definition: CodeGenTypes.h:120
bool hasDiagnostics()
Whether or not the stats we've gathered indicate any potential problems.
This class records statistics on instrumentation based profiling.
llvm::Constant * objc_retainAutorelease
id objc_retainAutorelease(id);
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
llvm::Constant * GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd)
Returns the offset from a derived class to a class.
Definition: CGClass.cpp:175
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
StringRef getMangledName(GlobalDecl GD)
virtual void emitDispose(CodeGenFunction &CGF, Address field)=0
llvm::Value * createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF)
llvm::Constant * getBlockObjectAssign()
Definition: CGBlocks.cpp:2468
void setAtomicSetterHelperFnMap(QualType Ty, llvm::Constant *Fn)
ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *E)
Returns a pointer to a constant global variable for the given file-scope compound literal expression...
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Definition: APValue.h:38
llvm::Constant * EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF=nullptr)
Try to emit the initializer for the given declaration as a constant; returns 0 if the expression cann...
llvm::MDNode * getNoObjCARCExceptionsMetadata()
llvm::Constant * objc_moveWeak
void objc_moveWeak(id *dest, id *src);
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
A pair of helper functions for a __block variable.
void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE, llvm::GlobalVariable *GV)
Notes that CLE's GlobalVariable is GV.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
MicrosoftVTableContext & getMicrosoftVTableContext()
Definition: CGVTables.h:85
DiagnosticsEngine & getDiags() const
Represents a C++ struct/union/class.
Definition: DeclCXX.h:267
llvm::Function * CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI, SourceLocation Loc=SourceLocation(), bool TLS=false)
Definition: CGDeclCXX.cpp:262
A specialization of Address that requires the address to be an LLVM Constant.
Definition: Address.h:75
void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr)
Notes that BE's global block is available via Addr.
Definition: CGBlocks.cpp:1096
void Release()
Finalize LLVM code generation.
void ClearUnusedCoverageMapping(const Decl *D)
Remove the deferred empty coverage mapping as this declaration is actually instrumented.
void EmitGlobalAnnotations()
Emit all the global annotations.
llvm::ConstantInt * CreateCrossDsoCfiTypeId(llvm::Metadata *MD)
Generate a cross-DSO type identifier for MD.
OrderGlobalInits(unsigned int p, unsigned int l)
void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV)
Set attributes which are common to any form of a global definition (alias, Objective-C method...
llvm::Constant * getBuiltinLibFunction(const FunctionDecl *FD, unsigned BuiltinID)
Given a builtin id for a function like "__builtin_fabsf", return a Function* for "fabsf".
Definition: CGBuiltin.cpp:45
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1506
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass, CastExpr::path_const_iterator Start, CastExpr::path_const_iterator End)
Definition: CGClass.cpp:147
llvm::MDNode * getTBAAInfo(QualType QTy)
llvm::Constant * IsOSVersionAtLeastFn
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
QualType getObjCFastEnumerationStateType()
Retrieve the record type that describes the state of an Objective-C fast enumeration loop (for...
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition: Linkage.h:75
const llvm::Triple & getTriple() const
This structure provides a set of types that are commonly used during IR emission. ...
CoverageMappingModuleGen * getCoverageMapping() const
llvm::Constant * getNSConcreteGlobalBlock()
Definition: CGBlocks.cpp:2480
llvm::Type * getBlockDescriptorType()
Fetches the type of a generic block descriptor.
Definition: CGBlocks.cpp:943
llvm::Constant * GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name)
Gets the address of a block which requires no captures.
Definition: CGBlocks.cpp:1104
CodeGenVTables & getVTables()
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition: ExprCXX.h:799
SanitizerMetadata * getSanitizerMetadata()
llvm::IndexedInstrProfReader * getPGOReader() const
void AddDefaultFnAttrs(llvm::Function &F)
Adds attributes to F according to our CodeGenOptions and LangOptions, as though we had emitted it our...
Definition: CGCall.cpp:1764
llvm::Constant * objc_retainAutoreleaseReturnValue
id objc_retainAutoreleaseReturnValue(id);
This represents '#pragma omp threadprivate ...' directive.
Definition: DeclOpenMP.h:39
void EmitGlobal(GlobalDecl D)
Emit code for a singal global function or var decl.
Abstract information about a function or function prototype.
Definition: CGCall.h:44
void AddDependentLib(StringRef Lib)
Appends a dependent lib to the "llvm.linker.options" metadata value.
llvm::GlobalValue::LinkageTypes getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage, bool IsConstantVariable)
Returns LLVM linkage for a declarator.
void EmitVTable(CXXRecordDecl *Class)
This is a callback from Sema to tell us that that a particular vtable is required to be emitted in th...
Definition: CGVTables.cpp:822
llvm::MDNode * getTBAAInfoForVTablePtr()