blob: 33b622972d9d81b1a28403116fda28996ae90640 [file] [log] [blame]
Daniel Dunbar9c426522008-07-29 23:18:29 +00001//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
Chris Lattnerf97fe382007-05-24 06:29:05 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerf97fe382007-05-24 06:29:05 +00007//
8//===----------------------------------------------------------------------===//
9//
Mike Stump1676c5b2009-02-13 19:12:34 +000010// This is the internal per-translation-unit state used for llvm translation.
Chris Lattnerf97fe382007-05-24 06:29:05 +000011//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
15#define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
Chris Lattnerf97fe382007-05-24 06:29:05 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "CGVTables.h"
John McCall7f416cc2015-09-08 08:05:57 +000018#include "CodeGenTypeCache.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000019#include "CodeGenTypes.h"
Alexey Samsonov4b8de112014-08-01 21:35:28 +000020#include "SanitizerMetadata.h"
Dan Gohman75d69da2008-05-22 00:50:06 +000021#include "clang/AST/Attr.h"
Anders Carlssondae1abc2009-05-05 04:44:02 +000022#include "clang/AST/DeclCXX.h"
Anders Carlsson73fcc952009-09-11 00:07:24 +000023#include "clang/AST/DeclObjC.h"
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000024#include "clang/AST/DeclOpenMP.h"
Peter Collingbourneee781d52011-06-14 04:02:39 +000025#include "clang/AST/GlobalDecl.h"
Peter Collingbourne0ff0b372011-01-13 18:57:25 +000026#include "clang/AST/Mangle.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000027#include "clang/Basic/ABI.h"
28#include "clang/Basic/LangOptions.h"
Douglas Gregor6ddfca92013-01-14 17:21:00 +000029#include "clang/Basic/Module.h"
Alexey Samsonov8d043e82014-10-15 19:57:45 +000030#include "clang/Basic/SanitizerBlacklist.h"
Dean Michael Berris835832d2017-03-30 00:29:36 +000031#include "clang/Basic/XRayLists.h"
Chris Lattnerb6984c42007-06-20 04:44:43 +000032#include "llvm/ADT/DenseMap.h"
Douglas Gregor6ddfca92013-01-14 17:21:00 +000033#include "llvm/ADT/SetVector.h"
Rafael Espindola2e42fec2010-03-04 18:17:24 +000034#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000035#include "llvm/ADT/StringMap.h"
Chandler Carruthffd55512013-01-02 11:45:17 +000036#include "llvm/IR/Module.h"
Chandler Carruth61743af2014-03-04 11:18:19 +000037#include "llvm/IR/ValueHandle.h"
Peter Collingbournedc134532016-01-16 00:31:22 +000038#include "llvm/Transforms/Utils/SanitizerStats.h"
Anders Carlsson762e1622009-01-04 02:08:04 +000039
Chris Lattnerf97fe382007-05-24 06:29:05 +000040namespace llvm {
Rafael Espindola42ae7452014-05-09 00:57:59 +000041class Module;
42class Constant;
43class ConstantInt;
44class Function;
45class GlobalValue;
46class DataLayout;
47class FunctionType;
48class LLVMContext;
49class IndexedInstrProfReader;
Alexander Kornienkoab9db512015-06-22 23:07:51 +000050}
Chris Lattner23b7eb62007-06-15 23:05:46 +000051
Chris Lattnerf97fe382007-05-24 06:29:05 +000052namespace clang {
Rafael Espindola42ae7452014-05-09 00:57:59 +000053class ASTContext;
54class AtomicType;
55class FunctionDecl;
56class IdentifierInfo;
57class ObjCMethodDecl;
58class ObjCImplementationDecl;
59class ObjCCategoryImplDecl;
60class ObjCProtocolDecl;
61class ObjCEncodeExpr;
62class BlockExpr;
63class CharUnits;
64class Decl;
65class Expr;
66class Stmt;
67class InitListExpr;
68class StringLiteral;
69class NamedDecl;
70class ValueDecl;
71class VarDecl;
72class LangOptions;
73class CodeGenOptions;
Adrian Prantle74f5252015-06-30 02:26:03 +000074class HeaderSearchOptions;
75class PreprocessorOptions;
Rafael Espindola42ae7452014-05-09 00:57:59 +000076class DiagnosticsEngine;
77class AnnotateAttr;
78class CXXDestructorDecl;
Rafael Espindola42ae7452014-05-09 00:57:59 +000079class Module;
Alex Lorenzee024992014-08-04 18:41:51 +000080class CoverageSourceInfo;
Mike Stump1676c5b2009-02-13 19:12:34 +000081
Chris Lattnerf97fe382007-05-24 06:29:05 +000082namespace CodeGen {
83
Rafael Espindola42ae7452014-05-09 00:57:59 +000084class CallArgList;
85class CodeGenFunction;
86class CodeGenTBAA;
87class CGCXXABI;
88class CGDebugInfo;
89class CGObjCRuntime;
90class CGOpenCLRuntime;
91class CGOpenMPRuntime;
92class CGCUDARuntime;
93class BlockFieldFlags;
94class FunctionArgList;
Alex Lorenzee024992014-08-04 18:41:51 +000095class CoverageMappingModuleGen;
John McCall12f23522016-04-04 18:33:08 +000096class TargetCodeGenInfo;
Justin Bogneref512b92014-01-06 22:27:43 +000097
John McCalld195d4c2016-11-30 23:25:13 +000098enum ForDefinition_t : bool {
99 NotForDefinition = false,
100 ForDefinition = true
101};
102
Rafael Espindola42ae7452014-05-09 00:57:59 +0000103struct OrderGlobalInits {
104 unsigned int priority;
105 unsigned int lex_order;
106 OrderGlobalInits(unsigned int p, unsigned int l)
Chris Lattnere0009072010-06-27 06:32:58 +0000107 : priority(p), lex_order(l) {}
Rafael Espindola42ae7452014-05-09 00:57:59 +0000108
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
John McCallb04ecb72015-10-21 18:06:43 +0000119struct ObjCEntrypoints {
120 ObjCEntrypoints() { memset(this, 0, sizeof(*this)); }
121
Pete Cooper94867712016-03-21 20:50:03 +0000122 /// void objc_autoreleasePoolPop(void*);
John McCall31168b02011-06-15 23:02:42 +0000123 llvm::Constant *objc_autoreleasePoolPop;
124
125 /// void *objc_autoreleasePoolPush(void);
126 llvm::Constant *objc_autoreleasePoolPush;
John McCall31168b02011-06-15 23:02:42 +0000127
128 /// id objc_autorelease(id);
129 llvm::Constant *objc_autorelease;
130
131 /// id objc_autoreleaseReturnValue(id);
132 llvm::Constant *objc_autoreleaseReturnValue;
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);
159 llvm::Constant *objc_retainAutoreleaseReturnValue;
160
161 /// id objc_retainAutoreleasedReturnValue(id);
162 llvm::Constant *objc_retainAutoreleasedReturnValue;
163
164 /// id objc_retainBlock(id);
165 llvm::Constant *objc_retainBlock;
166
167 /// void objc_release(id);
168 llvm::Constant *objc_release;
169
Saleem Abdulrasool5b1f0ed2017-02-11 17:24:09 +0000170 /// void objc_storeStrong(id*, id);
John McCall31168b02011-06-15 23:02:42 +0000171 llvm::Constant *objc_storeStrong;
172
173 /// id objc_storeWeak(id*, id);
174 llvm::Constant *objc_storeWeak;
175
John McCalle399e5b2016-01-27 18:32:30 +0000176 /// id objc_unsafeClaimAutoreleasedReturnValue(id);
177 llvm::Constant *objc_unsafeClaimAutoreleasedReturnValue;
178
John McCall31168b02011-06-15 23:02:42 +0000179 /// A void(void) inline asm to use to mark that the return value of
180 /// a call will be immediately retain.
181 llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
John McCalleff18842013-03-23 02:35:54 +0000182
183 /// void clang.arc.use(...);
184 llvm::Constant *clang_arc_use;
John McCall31168b02011-06-15 23:02:42 +0000185};
Will Dietzf54319c2013-01-18 11:30:38 +0000186
Justin Bognere2ef2a02014-04-15 21:22:35 +0000187/// This class records statistics on instrumentation based profiling.
Justin Bogner40b8ba12014-06-26 01:45:07 +0000188class InstrProfStats {
189 uint32_t VisitedInMainFile;
190 uint32_t MissingInMainFile;
Justin Bognere2ef2a02014-04-15 21:22:35 +0000191 uint32_t Visited;
192 uint32_t Missing;
193 uint32_t Mismatched;
Justin Bogner40b8ba12014-06-26 01:45:07 +0000194
195public:
196 InstrProfStats()
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);
Justin Bognere2ef2a02014-04-15 21:22:35 +0000218};
219
John McCallbd96e982015-09-08 08:21:11 +0000220/// A pair of helper functions for a __block variable.
221class BlockByrefHelpers : public llvm::FoldingSetNode {
222 // MSVC requires this type to be complete in order to process this
223 // header.
224public:
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.
231 CharUnits Alignment;
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
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000250/// This class organizes the cross-function state that is used while generating
251/// LLVM code.
John McCalle3dc1702011-02-15 09:22:45 +0000252class CodeGenModule : public CodeGenTypeCache {
Aaron Ballmanabc18922015-02-15 22:54:08 +0000253 CodeGenModule(const CodeGenModule &) = delete;
254 void operator=(const CodeGenModule &) = delete;
Anders Carlsson729a8202009-02-24 04:21:31 +0000255
Keno Fischer76f4ab02014-12-30 08:12:39 +0000256public:
Reid Kleckner563f0e82014-05-23 21:13:45 +0000257 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;
Daniel Dunbar74aa7e12008-08-01 00:01:51 +0000269
Keno Fischer76f4ab02014-12-30 08:12:39 +0000270private:
Chris Lattnerf97fe382007-05-24 06:29:05 +0000271 ASTContext &Context;
David Blaikiebbafb8a2012-03-11 07:00:24 +0000272 const LangOptions &LangOpts;
Adrian Prantle74f5252015-06-30 02:26:03 +0000273 const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info.
274 const PreprocessorOptions &PreprocessorOpts; // Only used for debug info.
Chandler Carruthbc55fe22009-11-12 17:24:48 +0000275 const CodeGenOptions &CodeGenOpts;
Chris Lattner23b7eb62007-06-15 23:05:46 +0000276 llvm::Module &TheModule;
David Blaikie9c902b52011-09-25 23:23:43 +0000277 DiagnosticsEngine &Diags;
John McCallc8e01702013-04-16 22:48:15 +0000278 const TargetInfo &Target;
Ahmed Charlesb8984322014-03-07 20:03:18 +0000279 std::unique_ptr<CGCXXABI> ABI;
John McCallc8e01702013-04-16 22:48:15 +0000280 llvm::LLVMContext &VMContext;
Anders Carlssonff971e82009-10-07 01:06:45 +0000281
Reid Kleckner9305fd12016-04-13 23:37:17 +0000282 std::unique_ptr<CodeGenTBAA> TBAA;
John McCallc8e01702013-04-16 22:48:15 +0000283
Reid Kleckner9305fd12016-04-13 23:37:17 +0000284 mutable std::unique_ptr<TargetCodeGenInfo> TheTargetCodeGenInfo;
John McCallc8e01702013-04-16 22:48:15 +0000285
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
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000291 /// Holds information about C++ vtables.
Anders Carlssona864caf2010-03-23 04:11:45 +0000292 CodeGenVTables VTables;
Douglas Gregorbc6a4342010-04-08 16:07:47 +0000293
Reid Kleckner9305fd12016-04-13 23:37:17 +0000294 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;
Justin Bogner837a6f62014-04-18 21:52:00 +0000301 std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
Justin Bognere2ef2a02014-04-15 21:22:35 +0000302 InstrProfStats PGOStats;
Peter Collingbournedc134532016-01-16 00:31:22 +0000303 std::unique_ptr<llvm::SanitizerStatReport> SanStats;
Daniel Dunbare49df9b52008-07-30 16:32:24 +0000304
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000305 // 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.
Rafael Espindola2e42fec2010-03-04 18:17:24 +0000308 llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
309
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000310 /// 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.
Alp Tokerfb8d02b2014-06-05 22:10:59 +0000314 std::map<StringRef, GlobalDecl> DeferredDecls;
Daniel Dunbar08b26a02009-02-13 20:29:50 +0000315
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000316 /// 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.
Sanjoy Das70a60512017-05-01 06:12:13 +0000318 std::vector<GlobalDecl> DeferredDeclsToEmit;
319 void addDeferredDeclToEmit(GlobalDecl GD) {
320 DeferredDeclsToEmit.emplace_back(GD);
Rafael Espindolac0ff7442013-12-09 14:59:08 +0000321 }
Daniel Dunbar7dd749e2009-04-15 22:08:45 +0000322
Rafael Espindola208b5c02013-10-22 19:26:13 +0000323 /// 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
Rafael Espindola2e2995b2013-11-05 21:37:29 +0000327 typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
328 ReplacementsTy Replacements;
329
Andrey Bokhankocab58582015-08-31 13:20:44 +0000330 /// 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).
333 llvm::SmallVector<std::pair<llvm::GlobalValue *, llvm::Constant *>, 8>
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
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000341 /// A queue of (optional) vtables to consider emitting.
John McCall6bd2a892013-01-25 22:31:03 +0000342 std::vector<const CXXRecordDecl*> DeferredVTables;
343
Piotr Padlewskid3b1cbd2017-06-01 08:04:05 +0000344 /// A queue of (optional) vtables that may be emitted opportunistically.
345 std::vector<const CXXRecordDecl *> OpportunisticVTables;
346
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000347 /// 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.
Sanjoy Dase369bd92017-05-01 17:08:00 +0000350 std::vector<llvm::WeakTrackingVH> LLVMUsed;
351 std::vector<llvm::WeakTrackingVH> LLVMCompilerUsed;
Mike Stump1676c5b2009-02-13 19:12:34 +0000352
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000353 /// Store the list of global constructors and their respective priorities to
354 /// be emitted when the translation unit is complete.
Daniel Dunbar74aa7e12008-08-01 00:01:51 +0000355 CtorList GlobalCtors;
356
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000357 /// Store the list of global destructors and their respective priorities to be
358 /// emitted when the translation unit is complete.
Daniel Dunbar74aa7e12008-08-01 00:01:51 +0000359 CtorList GlobalDtors;
360
Robert Lytton57765d52014-07-03 09:30:33 +0000361 /// An ordered map of canonical GlobalDecls to their mangled names.
362 llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
Alp Tokerfb8d02b2014-06-05 22:10:59 +0000363 llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
364
Julien Lerouge5a6b6982011-09-09 22:41:49 +0000365 /// Global annotations.
Nate Begeman7fab5782008-04-18 23:43:57 +0000366 std::vector<llvm::Constant*> Annotations;
Mike Stump1676c5b2009-02-13 19:12:34 +0000367
Julien Lerouge5a6b6982011-09-09 22:41:49 +0000368 /// Map used to get unique annotation strings.
369 llvm::StringMap<llvm::Constant*> AnnotationStrings;
370
David Blaikie2e804282015-04-05 22:47:07 +0000371 llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
David Majnemer58e5bee2014-03-24 21:43:36 +0000372
Richard Smith00db2f12014-07-29 21:20:12 +0000373 llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
Eli Friedman1c8d2ca2012-03-09 03:27:46 +0000374 llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
John McCallb88a5662012-03-30 21:00:39 +0000375 llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
Richard Smithe6c01442013-06-05 00:46:14 +0000376 llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
377
Fariborz Jahanian1bed4132012-01-08 19:13:23 +0000378 llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
379 llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
Daniel Dunbard644ad62008-08-23 18:37:06 +0000380
Will Dietz949ec542013-11-08 01:09:22 +0000381 /// Map used to get unique type descriptor constants for sanitizers.
382 llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
383
Richard Smithdf931ce2013-04-06 05:00:46 +0000384 /// Map used to track internal linkage functions declared within
385 /// extern "C" regions.
Richard Smithf21c9612013-04-13 01:28:18 +0000386 typedef llvm::MapVector<IdentifierInfo *,
387 llvm::GlobalValue *> StaticExternCMap;
Richard Smithdf931ce2013-04-06 05:00:46 +0000388 StaticExternCMap StaticExternCValues;
389
Richard Smith2fd1d7a2013-04-19 16:42:07 +0000390 /// \brief thread_local variables defined or used in this TU.
Richard Smith5a99c492015-12-01 01:10:48 +0000391 std::vector<const VarDecl *> CXXThreadLocals;
Richard Smith2fd1d7a2013-04-19 16:42:07 +0000392
393 /// \brief thread_local variables with initializers that need to run
394 /// before any thread_local variable in this TU is odr-used.
David Majnemerb3341ea2014-10-05 05:05:40 +0000395 std::vector<llvm::Function *> CXXThreadLocalInits;
Richard Smith5a99c492015-12-01 01:10:48 +0000396 std::vector<const VarDecl *> CXXThreadLocalInitVars;
Richard Smith2fd1d7a2013-04-19 16:42:07 +0000397
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000398 /// Global variables with initializers that need to run before main.
David Majnemerb3341ea2014-10-05 05:05:40 +0000399 std::vector<llvm::Function *> CXXGlobalInits;
John McCall70013b62010-07-15 23:40:35 +0000400
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
Reid Klecknere07140e2015-04-15 01:08:06 +0000404 /// order. Once the decl is emitted, the index is replaced with ~0U to ensure
405 /// that we don't re-emit the initializer.
John McCall70013b62010-07-15 23:40:35 +0000406 llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
Fariborz Jahanian9f2a4ee2010-06-21 18:45:05 +0000407
Anton Korobeynikovabed7492012-11-06 22:44:45 +0000408 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
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000417 /// Global variables with initializers whose order of initialization is set by
418 /// init_priority attribute.
Anton Korobeynikovabed7492012-11-06 22:44:45 +0000419 SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
Mike Stump11289f42009-09-09 15:08:12 +0000420
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000421 /// Global destructor functions and arguments that need to run on termination.
Sanjoy Dase369bd92017-05-01 17:08:00 +0000422 std::vector<std::pair<llvm::WeakTrackingVH, llvm::Constant *>> CXXGlobalDtors;
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000423
Douglas Gregor6ddfca92013-01-14 17:21:00 +0000424 /// \brief The complete set of modules that has been imported.
425 llvm::SetVector<clang::Module *> ImportedModules;
426
Manman Ren3b5dbf22016-10-14 18:55:44 +0000427 /// \brief The set of modules for which the module initializers
428 /// have been emitted.
429 llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
430
Reid Klecknere43f0fe2013-05-08 13:44:39 +0000431 /// \brief A vector of metadata strings.
Peter Collingbourne89061b22017-06-12 20:10:48 +0000432 SmallVector<llvm::MDNode *, 16> LinkerOptionsMetadata;
Reid Klecknere43f0fe2013-05-08 13:44:39 +0000433
Douglas Gregorabf4e0d2011-08-09 15:54:21 +0000434 /// @name Cache for Objective-C runtime types
435 /// @{
436
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000437 /// Cached reference to the class for constant strings. This value has type
438 /// int * but is actually an Obj-C class pointer.
Sanjoy Dase369bd92017-05-01 17:08:00 +0000439 llvm::WeakTrackingVH CFConstantStringClassRef;
Mike Stump11289f42009-09-09 15:08:12 +0000440
Douglas Gregor636e2002011-08-09 17:23:49 +0000441 /// \brief The type used to describe the state of a fast enumeration in
442 /// Objective-C's for..in loop.
443 QualType ObjCFastEnumerationStateType;
444
Douglas Gregorabf4e0d2011-08-09 15:54:21 +0000445 /// @}
446
David Chisnall481e3a82010-01-23 02:40:42 +0000447 /// Lazily create the Objective-C runtime
448 void createObjCRuntime();
449
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000450 void createOpenCLRuntime();
Alexey Bataev9959db52014-05-06 10:08:46 +0000451 void createOpenMPRuntime();
Peter Collingbournefe883422011-10-06 18:29:37 +0000452 void createCUDARuntime();
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000453
Rafael Espindola4fdc1752011-12-19 14:41:01 +0000454 bool isTriviallyRecursive(const FunctionDecl *F);
Peter Collingbourne4d90dba2013-06-05 17:49:37 +0000455 bool shouldEmitFunction(GlobalDecl GD);
Piotr Padlewskid3b1cbd2017-06-01 08:04:05 +0000456 bool shouldOpportunisticallyEmitVTables();
George Burgess IV1a39b862016-12-28 07:27:40 +0000457 /// Map used to be sure we don't emit the same CompoundLiteral twice.
458 llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *>
459 EmittedCompoundLiterals;
460
George Burgess IVe3763372016-12-22 02:50:20 +0000461 /// 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
Daniel Dunbar900546d2010-07-16 00:00:15 +0000465 /// @name Cache for Blocks Runtime Globals
466 /// @{
467
Reid Kleckner9305fd12016-04-13 23:37:17 +0000468 llvm::Constant *NSConcreteGlobalBlock = nullptr;
469 llvm::Constant *NSConcreteStackBlock = nullptr;
Daniel Dunbar3348e2d2010-07-16 00:00:19 +0000470
Reid Kleckner9305fd12016-04-13 23:37:17 +0000471 llvm::Constant *BlockObjectAssign = nullptr;
472 llvm::Constant *BlockObjectDispose = nullptr;
Daniel Dunbar900546d2010-07-16 00:00:15 +0000473
Reid Kleckner9305fd12016-04-13 23:37:17 +0000474 llvm::Type *BlockDescriptorType = nullptr;
475 llvm::Type *GenericBlockLiteralType = nullptr;
John McCallad7c5c12011-02-08 08:22:06 +0000476
477 struct {
478 int GlobalUniqueCount;
479 } Block;
Will Dietzf54319c2013-01-18 11:30:38 +0000480
Nadav Rotem1da30942013-03-23 06:43:35 +0000481 /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
Reid Kleckner9305fd12016-04-13 23:37:17 +0000482 llvm::Constant *LifetimeStartFn = nullptr;
Nadav Rotem1da30942013-03-23 06:43:35 +0000483
484 /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
Reid Kleckner9305fd12016-04-13 23:37:17 +0000485 llvm::Constant *LifetimeEndFn = nullptr;
Nadav Rotem1da30942013-03-23 06:43:35 +0000486
Fariborz Jahanian63628032012-06-26 16:06:38 +0000487 GlobalDecl initializedGlobalDecl;
John McCallad7c5c12011-02-08 08:22:06 +0000488
Alexey Samsonov4b8de112014-08-01 21:35:28 +0000489 std::unique_ptr<SanitizerMetadata> SanitizerMD;
490
Daniel Dunbar900546d2010-07-16 00:00:15 +0000491 /// @}
Alex Lorenzee024992014-08-04 18:41:51 +0000492
493 llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
494
495 std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
Peter Collingbourne25a80bf2015-09-08 23:01:30 +0000496
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
Chris Lattnerf97fe382007-05-24 06:29:05 +0000502public:
Mehdi Aminica3cf9e2015-07-24 16:04:29 +0000503 CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts,
Adrian Prantle74f5252015-06-30 02:26:03 +0000504 const PreprocessorOptions &ppopts,
Mehdi Aminica3cf9e2015-07-24 16:04:29 +0000505 const CodeGenOptions &CodeGenOpts, llvm::Module &M,
Alex Lorenzee024992014-08-04 18:41:51 +0000506 DiagnosticsEngine &Diags,
507 CoverageSourceInfo *CoverageInfo = nullptr);
Ted Kremenek2c674f62008-08-05 18:50:11 +0000508
Chris Lattnera087ff92008-03-01 08:45:05 +0000509 ~CodeGenModule();
Mike Stump1676c5b2009-02-13 19:12:34 +0000510
Rafael Espindolac0ff7442013-12-09 14:59:08 +0000511 void clear();
512
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000513 /// Finalize LLVM code generation.
Ted Kremenek2c674f62008-08-05 18:50:11 +0000514 void Release();
Daniel Dunbar8d480592008-08-11 18:12:00 +0000515
Bob Haarmanc6c9b8f2017-09-11 22:11:57 +0000516 /// Return true if we should emit location information for expressions.
517 bool getExpressionLocationsEnabled() const;
518
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000519 /// Return a reference to the configured Objective-C runtime.
Mike Stump1676c5b2009-02-13 19:12:34 +0000520 CGObjCRuntime &getObjCRuntime() {
Peter Collingbournee1d20992011-07-27 20:29:46 +0000521 if (!ObjCRuntime) createObjCRuntime();
522 return *ObjCRuntime;
Daniel Dunbar8d480592008-08-11 18:12:00 +0000523 }
Mike Stump1676c5b2009-02-13 19:12:34 +0000524
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000525 /// Return true iff an Objective-C runtime has been configured.
Peter Collingbournee1d20992011-07-27 20:29:46 +0000526 bool hasObjCRuntime() { return !!ObjCRuntime; }
Daniel Dunbar8d480592008-08-11 18:12:00 +0000527
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000528 /// Return a reference to the configured OpenCL runtime.
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000529 CGOpenCLRuntime &getOpenCLRuntime() {
Craig Topper8a13c412014-05-21 05:09:00 +0000530 assert(OpenCLRuntime != nullptr);
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000531 return *OpenCLRuntime;
532 }
533
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000534 /// Return a reference to the configured OpenMP runtime.
Alexey Bataev9959db52014-05-06 10:08:46 +0000535 CGOpenMPRuntime &getOpenMPRuntime() {
536 assert(OpenMPRuntime != nullptr);
537 return *OpenMPRuntime;
538 }
539
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000540 /// Return a reference to the configured CUDA runtime.
Peter Collingbournefe883422011-10-06 18:29:37 +0000541 CGCUDARuntime &getCUDARuntime() {
Craig Topper8a13c412014-05-21 05:09:00 +0000542 assert(CUDARuntime != nullptr);
Peter Collingbournefe883422011-10-06 18:29:37 +0000543 return *CUDARuntime;
544 }
545
John McCallb04ecb72015-10-21 18:06:43 +0000546 ObjCEntrypoints &getObjCEntrypoints() const {
547 assert(ObjCData != nullptr);
548 return *ObjCData;
John McCall31168b02011-06-15 23:02:42 +0000549 }
550
Erik Pilkington9c42a8d2017-02-23 21:08:08 +0000551 // Version checking function, used to implement ObjC's @available:
552 // i32 @__isOSVersionAtLeast(i32, i32, i32)
553 llvm::Constant *IsOSVersionAtLeastFn = nullptr;
554
Justin Bogner837a6f62014-04-18 21:52:00 +0000555 InstrProfStats &getPGOStats() { return PGOStats; }
556 llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
Justin Bogneref512b92014-01-06 22:27:43 +0000557
Alex Lorenzee024992014-08-04 18:41:51 +0000558 CoverageMappingModuleGen *getCoverageMapping() const {
559 return CoverageMapping.get();
560 }
561
Eli Friedman1c8d2ca2012-03-09 03:27:46 +0000562 llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
563 return StaticLocalDeclMap[D];
Fariborz Jahanian3fef72f2010-04-18 21:01:23 +0000564 }
Fariborz Jahanian4d55b2d2010-04-19 18:15:02 +0000565 void setStaticLocalDeclAddress(const VarDecl *D,
Eli Friedman1c8d2ca2012-03-09 03:27:46 +0000566 llvm::Constant *C) {
567 StaticLocalDeclMap[D] = C;
Fariborz Jahanian3fef72f2010-04-18 21:01:23 +0000568 }
569
Reid Kleckner453e0562014-10-08 01:07:54 +0000570 llvm::Constant *
571 getOrCreateStaticVarDecl(const VarDecl &D,
572 llvm::GlobalValue::LinkageTypes Linkage);
573
John McCallb88a5662012-03-30 21:00:39 +0000574 llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
575 return StaticLocalDeclGuardMap[D];
576 }
577 void setStaticLocalDeclGuardAddress(const VarDecl *D,
578 llvm::GlobalVariable *C) {
579 StaticLocalDeclGuardMap[D] = C;
580 }
581
Alp Tokerfb8d02b2014-06-05 22:10:59 +0000582 bool lookupRepresentativeDecl(StringRef MangledName,
583 GlobalDecl &Result) const;
584
Fariborz Jahanian1bed4132012-01-08 19:13:23 +0000585 llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
586 return AtomicSetterHelperFnMap[Ty];
Fariborz Jahanian7ff610b2012-01-06 22:33:54 +0000587 }
Fariborz Jahanian1bed4132012-01-08 19:13:23 +0000588 void setAtomicSetterHelperFnMap(QualType Ty,
Fariborz Jahanian7ff610b2012-01-06 22:33:54 +0000589 llvm::Constant *Fn) {
Fariborz Jahanian1bed4132012-01-08 19:13:23 +0000590 AtomicSetterHelperFnMap[Ty] = Fn;
591 }
592
593 llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
594 return AtomicGetterHelperFnMap[Ty];
595 }
596 void setAtomicGetterHelperFnMap(QualType Ty,
597 llvm::Constant *Fn) {
598 AtomicGetterHelperFnMap[Ty] = Fn;
Fariborz Jahanian7ff610b2012-01-06 22:33:54 +0000599 }
600
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000601 llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
Will Dietz949ec542013-11-08 01:09:22 +0000602 return TypeDescriptorMap[Ty];
603 }
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000604 void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
Will Dietz949ec542013-11-08 01:09:22 +0000605 TypeDescriptorMap[Ty] = C;
606 }
607
Reid Kleckner9305fd12016-04-13 23:37:17 +0000608 CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); }
Devang Patele65982c2011-03-07 18:29:53 +0000609
Dan Gohman515a60d2012-02-16 00:57:37 +0000610 llvm::MDNode *getNoObjCARCExceptionsMetadata() {
611 if (!NoObjCARCExceptionsMetadata)
Duncan P. N. Exon Smithfb494912014-12-09 18:39:32 +0000612 NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None);
Dan Gohman515a60d2012-02-16 00:57:37 +0000613 return NoObjCARCExceptionsMetadata;
614 }
615
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000616 ASTContext &getContext() const { return Context; }
David Blaikiebbafb8a2012-03-11 07:00:24 +0000617 const LangOptions &getLangOpts() const { return LangOpts; }
Adrian Prantle74f5252015-06-30 02:26:03 +0000618 const HeaderSearchOptions &getHeaderSearchOpts()
619 const { return HeaderSearchOpts; }
620 const PreprocessorOptions &getPreprocessorOpts()
621 const { return PreprocessorOpts; }
John McCallc8e01702013-04-16 22:48:15 +0000622 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
Chris Lattner23b7eb62007-06-15 23:05:46 +0000623 llvm::Module &getModule() const { return TheModule; }
David Blaikie9c902b52011-09-25 23:23:43 +0000624 DiagnosticsEngine &getDiags() const { return Diags; }
Mehdi Aminica3cf9e2015-07-24 16:04:29 +0000625 const llvm::DataLayout &getDataLayout() const {
626 return TheModule.getDataLayout();
627 }
John McCallc8e01702013-04-16 22:48:15 +0000628 const TargetInfo &getTarget() const { return Target; }
Saleem Abdulrasool7246dcc2016-09-14 15:17:46 +0000629 const llvm::Triple &getTriple() const { return Target.getTriple(); }
Rafael Espindola9f834732014-09-19 01:54:22 +0000630 bool supportsCOMDAT() const;
Rafael Espindoladbee8a72015-01-15 21:36:08 +0000631 void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
Rafael Espindola9f834732014-09-19 01:54:22 +0000632
Alp Toker82862252013-12-28 21:58:40 +0000633 CGCXXABI &getCXXABI() const { return *ABI; }
Owen Anderson170229f2009-07-14 23:10:40 +0000634 llvm::LLVMContext &getLLVMContext() { return VMContext; }
Craig Topper8a13c412014-05-21 05:09:00 +0000635
636 bool shouldUseTBAA() const { return TBAA != nullptr; }
John McCall53fcbd22011-02-26 08:07:02 +0000637
John McCallc8e01702013-04-16 22:48:15 +0000638 const TargetCodeGenInfo &getTargetCodeGenInfo();
639
640 CodeGenTypes &getTypes() { return Types; }
641
642 CodeGenVTables &getVTables() { return VTables; }
Timur Iskhodzhanov88fd4392013-08-21 06:25:03 +0000643
Timur Iskhodzhanov58776632013-11-05 15:54:58 +0000644 ItaniumVTableContext &getItaniumVTableContext() {
645 return VTables.getItaniumVTableContext();
Timur Iskhodzhanove1ebc5f2013-10-09 11:33:51 +0000646 }
John McCallc8e01702013-04-16 22:48:15 +0000647
Timur Iskhodzhanov58776632013-11-05 15:54:58 +0000648 MicrosoftVTableContext &getMicrosoftVTableContext() {
649 return VTables.getMicrosoftVTableContext();
Timur Iskhodzhanov88fd4392013-08-21 06:25:03 +0000650 }
651
Keno Fischer76f4ab02014-12-30 08:12:39 +0000652 CtorList &getGlobalCtors() { return GlobalCtors; }
653 CtorList &getGlobalDtors() { return GlobalDtors; }
654
Ivan A. Kosarev289574e2017-10-02 09:54:47 +0000655 /// getTBAATypeInfo - Get metadata used to describe accesses to objects of
656 /// the given type.
657 llvm::MDNode *getTBAATypeInfo(QualType QTy);
658
Ivan A. Kosarevafc074c2017-10-05 11:05:43 +0000659 llvm::MDNode *getTBAAInfoForVTablePtr();
Dan Gohman22695fc2012-09-28 21:58:29 +0000660 llvm::MDNode *getTBAAStructInfo(QualType QTy);
Ivan A. Kosareva511ed72017-10-03 10:52:39 +0000661
Ivan A. Kosarevafc074c2017-10-05 11:05:43 +0000662 /// Get path-aware TBAA tag for a given memory access.
663 llvm::MDNode *getTBAAStructTagInfo(TBAAAccessInfo Info);
Dan Gohman947c9af2010-10-14 23:06:10 +0000664
Ivan A. Kosarevafc074c2017-10-05 11:05:43 +0000665 /// getTBAAMayAliasTypeInfo - Get TBAA information that represents
Ivan A. Kosarev5c8e7592017-10-02 11:10:04 +0000666 /// may-alias accesses.
Ivan A. Kosarevafc074c2017-10-05 11:05:43 +0000667 llvm::MDNode *getTBAAMayAliasTypeInfo();
Ivan A. Kosarev5c8e7592017-10-02 11:10:04 +0000668
Richard Smithe070fd22012-02-17 06:48:11 +0000669 bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
670
John McCalla8ec7eb2013-03-07 21:37:17 +0000671 bool isPaddedAtomicType(QualType type);
672 bool isPaddedAtomicType(const AtomicType *type);
673
Ivan A. Kosarevafc074c2017-10-05 11:05:43 +0000674 /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
675 /// is the same as the type. For struct-path aware TBAA, the tag
676 /// is different from the type: base type, access type and offset.
677 /// When ConvertTypeToTag is true, we create a tag based on the scalar type.
Piotr Padlewski4b1ac722015-09-15 21:46:55 +0000678 void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
Ivan A. Kosarevafc074c2017-10-05 11:05:43 +0000679 llvm::MDNode *TBAAInfo,
680 bool ConvertTypeToTag = true);
Piotr Padlewski4b1ac722015-09-15 21:46:55 +0000681
682 /// Adds !invariant.barrier !tag to instruction
683 void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
684 const CXXRecordDecl *RD);
Dan Gohman947c9af2010-10-14 23:06:10 +0000685
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000686 /// Emit the given number of characters as a value of type size_t.
John McCall23c29fe2011-06-24 21:55:10 +0000687 llvm::ConstantInt *getSize(CharUnits numChars);
688
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000689 /// Set the visibility for the given LLVM GlobalValue.
Anders Carlssonc6a47892011-01-29 19:39:23 +0000690 void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
Daniel Dunbarf5f359f2009-04-14 06:00:08 +0000691
David Majnemerbb525f7c2014-10-15 22:38:23 +0000692 /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000693 /// variable declaration D.
David Majnemerbb525f7c2014-10-15 22:38:23 +0000694 void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
Hans Wennborgf60f6af2012-06-28 08:01:44 +0000695
Anders Carlsson537fdce2011-01-29 20:59:35 +0000696 static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
697 switch (V) {
698 case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
699 case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
700 case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
701 }
702 llvm_unreachable("unknown visibility!");
Anders Carlsson537fdce2011-01-29 20:59:35 +0000703 }
704
John McCalld195d4c2016-11-30 23:25:13 +0000705 llvm::Constant *GetAddrOfGlobal(GlobalDecl GD,
706 ForDefinition_t IsForDefinition
707 = NotForDefinition);
John McCalld4324142010-02-19 01:32:20 +0000708
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000709 /// Will return a global variable of the given type. If a variable with a
710 /// different type already exists then a new variable with the right type
711 /// will be created and all uses of the old variable will be replaced with a
712 /// bitcast to the new variable.
Anders Carlssonda80af32011-01-29 18:20:20 +0000713 llvm::GlobalVariable *
Chris Lattner01cf8db2011-07-20 06:58:45 +0000714 CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
Anders Carlssonda80af32011-01-29 18:20:20 +0000715 llvm::GlobalValue::LinkageTypes Linkage);
716
Alexey Samsonov1444bb92014-10-17 00:20:19 +0000717 llvm::Function *
718 CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name,
Akira Hatanaka7791f1a42015-10-31 01:28:07 +0000719 const CGFunctionInfo &FI,
Alexey Samsonov1444bb92014-10-17 00:20:19 +0000720 SourceLocation Loc = SourceLocation(),
721 bool TLS = false);
David Majnemerb3341ea2014-10-05 05:05:40 +0000722
Yaxun Liucbf647c2017-07-08 13:24:52 +0000723 /// Return the AST address space of the underlying global variable for D, as
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000724 /// determined by its declaration. Normally this is the same as the address
725 /// space of D's type, but in CUDA, address spaces are associated with
Yaxun Liucbf647c2017-07-08 13:24:52 +0000726 /// declarations, not types. If D is nullptr, return the default address
727 /// space for global variable.
728 ///
729 /// For languages without explicit address spaces, if D has default address
730 /// space, target-specific global or constant address space may be returned.
731 unsigned GetGlobalVarAddressSpace(const VarDecl *D);
Peter Collingbournef44bdf92012-05-20 21:08:35 +0000732
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000733 /// Return the llvm::Constant for the address of the given global variable.
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +0000734 /// If Ty is non-null and if the global doesn't exist, then it will be created
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000735 /// with the specified type instead of whatever the normal requested type
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +0000736 /// would be. If IsForDefinition is true, it is guranteed that an actual
737 /// global with type Ty will be returned, not conversion of a variable with
738 /// the same mangled name but some other type.
Chris Lattner149927c2009-03-21 09:16:30 +0000739 llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +0000740 llvm::Type *Ty = nullptr,
John McCalld195d4c2016-11-30 23:25:13 +0000741 ForDefinition_t IsForDefinition
742 = NotForDefinition);
Daniel Dunbar9c426522008-07-29 23:18:29 +0000743
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000744 /// Return the address of the given function. If Ty is non-null, then this
745 /// function will use the specified type if it has to create it.
Hans Wennborg59dbe862015-09-29 20:56:43 +0000746 llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
Rafael Espindola94abb8f2013-12-09 04:29:47 +0000747 bool ForVTable = false,
Andrey Bokhankocab58582015-08-31 13:20:44 +0000748 bool DontDefer = false,
John McCalld195d4c2016-11-30 23:25:13 +0000749 ForDefinition_t IsForDefinition
750 = NotForDefinition);
Daniel Dunbarc4baa062008-08-13 23:20:05 +0000751
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000752 /// Get the address of the RTTI descriptor for the given type.
John McCall48bf3492010-04-30 01:15:21 +0000753 llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
Anders Carlssonfd7dfeb2009-12-11 02:46:30 +0000754
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000755 /// Get the address of a uuid descriptor .
John McCall7f416cc2015-09-08 08:05:57 +0000756 ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
Nico Webercf4ff5862012-10-11 10:13:44 +0000757
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000758 /// Get the address of the thunk for the given global decl.
Anders Carlssonfe8a9932011-02-06 17:15:43 +0000759 llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
Anders Carlssoncd836f02010-03-23 17:17:29 +0000760
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000761 /// Get a reference to the target of VD.
John McCall7f416cc2015-09-08 08:05:57 +0000762 ConstantAddress GetWeakRefReference(const ValueDecl *VD);
763
764 /// Returns the assumed alignment of an opaque pointer to the given class.
765 CharUnits getClassPointerAlignment(const CXXRecordDecl *CD);
766
767 /// Returns the assumed alignment of a virtual base of a class.
768 CharUnits getVBaseAlignment(CharUnits DerivedAlign,
769 const CXXRecordDecl *Derived,
770 const CXXRecordDecl *VBase);
771
772 /// Given a class pointer with an actual known alignment, and the
773 /// expected alignment of an object at a dynamic offset w.r.t that
774 /// pointer, return the alignment to assume at the offset.
775 CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign,
776 const CXXRecordDecl *Class,
777 CharUnits ExpectedTargetAlign);
Rafael Espindola2e42fec2010-03-04 18:17:24 +0000778
David Majnemerc1709d32015-06-23 07:31:11 +0000779 CharUnits
780 computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass,
781 CastExpr::path_const_iterator Start,
782 CastExpr::path_const_iterator End);
783
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000784 /// Returns the offset from a derived class to a class. Returns null if the
785 /// offset is 0.
Anders Carlsson8a64c1c2010-04-24 21:23:59 +0000786 llvm::Constant *
787 GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
John McCallcf142162010-08-07 06:22:56 +0000788 CastExpr::path_const_iterator PathBegin,
789 CastExpr::path_const_iterator PathEnd);
John McCallad7c5c12011-02-08 08:22:06 +0000790
John McCall7f416cc2015-09-08 08:05:57 +0000791 llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
John McCallad7c5c12011-02-08 08:22:06 +0000792
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000793 /// Fetches the global unique block count.
John McCall147d0212011-02-22 22:38:33 +0000794 int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
Fariborz Jahanian63628032012-06-26 16:06:38 +0000795
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000796 /// Fetches the type of a generic block descriptor.
Chris Lattnera5f58b02011-07-09 17:41:47 +0000797 llvm::Type *getBlockDescriptorType();
John McCallad7c5c12011-02-08 08:22:06 +0000798
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000799 /// The type of a generic block literal.
Chris Lattnera5f58b02011-07-09 17:41:47 +0000800 llvm::Type *getGenericBlockLiteralType();
John McCallad7c5c12011-02-08 08:22:06 +0000801
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000802 /// Gets the address of a block which requires no captures.
George Burgess IV70d15b32016-11-03 02:21:43 +0000803 llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name);
George Burgess IVe3763372016-12-22 02:50:20 +0000804
805 /// Returns the address of a block which requires no caputres, or null if
806 /// we've yet to emit the block for BE.
807 llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) {
808 return EmittedGlobalBlocks.lookup(BE);
809 }
810
811 /// Notes that BE's global block is available via Addr. Asserts that BE
812 /// isn't already emitted.
813 void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
Anders Carlsson8a64c1c2010-04-24 21:23:59 +0000814
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000815 /// Return a pointer to a constant CFString object for the given string.
John McCall7f416cc2015-09-08 08:05:57 +0000816 ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal);
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000817
818 /// Return a pointer to a constant NSString object for the given string. Or a
819 /// user defined String object as defined via
Fariborz Jahanian50c925f2010-10-19 17:19:29 +0000820 /// -fconstant-string-class=class_name option.
John McCall7f416cc2015-09-08 08:05:57 +0000821 ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal);
Chris Lattner36fc8792008-02-11 00:02:17 +0000822
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000823 /// Return a constant array for the given string.
Eli Friedmanfcec6302011-11-01 02:23:42 +0000824 llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
825
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000826 /// Return a pointer to a constant array for the given string literal.
John McCall7f416cc2015-09-08 08:05:57 +0000827 ConstantAddress
Alexey Bataevec474782014-10-09 08:45:04 +0000828 GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
829 StringRef Name = ".str");
Daniel Dunbar6dfdf8c2008-08-10 20:25:57 +0000830
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000831 /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
John McCall7f416cc2015-09-08 08:05:57 +0000832 ConstantAddress
Alexey Samsonovb2cc23d2014-07-10 22:18:36 +0000833 GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
Mike Stump11289f42009-09-09 15:08:12 +0000834
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000835 /// Returns a pointer to a character array containing the literal and a
836 /// terminating '\0' character. The result has pointer to array type.
Daniel Dunbardfcf5992008-10-17 21:56:50 +0000837 ///
Mike Stump1676c5b2009-02-13 19:12:34 +0000838 /// \param GlobalName If provided, the name to use for the global (if one is
839 /// created).
John McCall7f416cc2015-09-08 08:05:57 +0000840 ConstantAddress
Alexey Samsonovb2cc23d2014-07-10 22:18:36 +0000841 GetAddrOfConstantCString(const std::string &Str,
John McCall7f416cc2015-09-08 08:05:57 +0000842 const char *GlobalName = nullptr);
Richard Smith2d988f02011-11-22 22:48:32 +0000843
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000844 /// Returns a pointer to a constant global variable for the given file-scope
845 /// compound literal expression.
John McCall7f416cc2015-09-08 08:05:57 +0000846 ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
Richard Smithe6c01442013-06-05 00:46:14 +0000847
George Burgess IV1a39b862016-12-28 07:27:40 +0000848 /// If it's been emitted already, returns the GlobalVariable corresponding to
849 /// a compound literal. Otherwise, returns null.
850 llvm::GlobalVariable *
851 getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E);
852
853 /// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already
854 /// emitted.
855 void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE,
856 llvm::GlobalVariable *GV);
857
Richard Smithe6c01442013-06-05 00:46:14 +0000858 /// \brief Returns a pointer to a global variable representing a temporary
859 /// with static or thread storage duration.
John McCall7f416cc2015-09-08 08:05:57 +0000860 ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
Richard Smithe6c01442013-06-05 00:46:14 +0000861 const Expr *Inner);
862
Douglas Gregor636e2002011-08-09 17:23:49 +0000863 /// \brief Retrieve the record type that describes the state of an
864 /// Objective-C fast enumeration loop (for..in).
865 QualType getObjCFastEnumerationStateType();
Rafael Espindola8d2a19b2014-09-08 16:01:27 +0000866
Rafael Espindola53686182014-09-15 19:34:18 +0000867 // Produce code for this constructor/destructor. This method doesn't try
868 // to apply any ABI rules about which other constructors/destructors
869 // are needed or if they are alias to each other.
870 llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
871 StructorType Type);
872
Rafael Espindola1ac0ec82014-09-11 15:42:06 +0000873 /// Return the address of the constructor/destructor of the given type.
Andrey Bokhankocab58582015-08-31 13:20:44 +0000874 llvm::Constant *
Rafael Espindola8d2a19b2014-09-08 16:01:27 +0000875 getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type,
876 const CGFunctionInfo *FnInfo = nullptr,
877 llvm::FunctionType *FnType = nullptr,
John McCalld195d4c2016-11-30 23:25:13 +0000878 bool DontDefer = false,
879 ForDefinition_t IsForDefinition = NotForDefinition);
Rafael Espindola8d2a19b2014-09-08 16:01:27 +0000880
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000881 /// Given a builtin id for a function like "__builtin_fabsf", return a
882 /// Function* for "fabsf".
John McCallb92ab1a2016-10-26 23:46:34 +0000883 llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
884 unsigned BuiltinID);
Daniel Dunbarc4baa062008-08-13 23:20:05 +0000885
Dmitri Gribenko44ebbd52013-05-05 00:41:58 +0000886 llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
Daniel Dunbar9c426522008-07-29 23:18:29 +0000887
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000888 /// Emit code for a single top level declaration.
Daniel Dunbarfce4be82008-08-15 23:26:23 +0000889 void EmitTopLevelDecl(Decl *D);
Daniel Dunbar9c426522008-07-29 23:18:29 +0000890
Alex Lorenzee024992014-08-04 18:41:51 +0000891 /// \brief Stored a deferred empty coverage mapping for an unused
892 /// and thus uninstrumented top level declaration.
893 void AddDeferredUnusedCoverageMapping(Decl *D);
894
895 /// \brief Remove the deferred empty coverage mapping as this
896 /// declaration is actually instrumented.
897 void ClearUnusedCoverageMapping(const Decl *D);
898
899 /// \brief Emit all the deferred coverage mappings
900 /// for the uninstrumented functions.
901 void EmitDeferredUnusedCoverageMappings();
902
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000903 /// Tell the consumer that this variable has been instantiated.
Rafael Espindoladf88f6f2012-03-08 15:51:03 +0000904 void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
Rafael Espindola189fa742012-03-05 10:54:55 +0000905
Richard Smithdf931ce2013-04-06 05:00:46 +0000906 /// \brief If the declaration has internal linkage but is inside an
907 /// extern "C" linkage specification, prepare to emit an alias for it
908 /// to the expected name.
909 template<typename SomeDecl>
910 void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
911
Rafael Espindola060062a2014-03-06 22:15:10 +0000912 /// Add a global to a list to be added to the llvm.used metadata.
913 void addUsedGlobal(llvm::GlobalValue *GV);
914
915 /// Add a global to a list to be added to the llvm.compiler.used metadata.
916 void addCompilerUsedGlobal(llvm::GlobalValue *GV);
Daniel Dunbar08b26a02009-02-13 20:29:50 +0000917
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000918 /// Add a destructor and object to add to the C++ global destructor function.
Chris Lattner87233f72010-06-19 05:52:45 +0000919 void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
Benjamin Kramer3204b152015-05-29 19:42:19 +0000920 CXXGlobalDtors.emplace_back(DtorFn, Object);
Chris Lattner87233f72010-06-19 05:52:45 +0000921 }
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000922
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000923 /// Create a new runtime function with the specified type and name.
Saleem Abdulrasool6cb07442016-12-15 06:59:05 +0000924 llvm::Constant *
925 CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name,
Reid Klecknerde864822017-03-21 16:57:30 +0000926 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
Saleem Abdulrasool6cb07442016-12-15 06:59:05 +0000927 bool Local = false);
928
Anton Korobeynikovd90dd792014-12-02 16:04:58 +0000929 /// Create a new compiler builtin function with the specified type and name.
Reid Klecknerde864822017-03-21 16:57:30 +0000930 llvm::Constant *
931 CreateBuiltinFunction(llvm::FunctionType *Ty, StringRef Name,
932 llvm::AttributeList ExtraAttrs = llvm::AttributeList());
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000933 /// Create a new runtime global variable with the specified type and name.
Chris Lattner2192fe52011-07-18 04:24:23 +0000934 llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000935 StringRef Name);
Daniel Dunbar23fd4622008-10-01 00:49:24 +0000936
Daniel Dunbar900546d2010-07-16 00:00:15 +0000937 ///@name Custom Blocks Runtime Interfaces
938 ///@{
939
940 llvm::Constant *getNSConcreteGlobalBlock();
941 llvm::Constant *getNSConcreteStackBlock();
942 llvm::Constant *getBlockObjectAssign();
943 llvm::Constant *getBlockObjectDispose();
944
945 ///@}
946
Nadav Rotem1da30942013-03-23 06:43:35 +0000947 llvm::Constant *getLLVMLifetimeStartFn();
948 llvm::Constant *getLLVMLifetimeEndFn();
949
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000950 // Make sure that this type is translated.
Devang Patel945b8ae2011-03-23 16:29:39 +0000951 void UpdateCompletedType(const TagDecl *TD);
Daniel Dunbar38ad1e62009-02-17 18:43:32 +0000952
John McCallf3a88602011-02-03 08:15:49 +0000953 llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
954
Alexey Bataev2bf9b4c2015-10-20 04:24:12 +0000955 /// \brief Emit type info if type of an expression is a variably modified
956 /// type. Also emit proper debug info for cast types.
957 void EmitExplicitCastExprType(const ExplicitCastExpr *E,
958 CodeGenFunction *CGF = nullptr);
959
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000960 /// Return the result of value-initializing the given type, i.e. a null
961 /// expression of the given type. This is usually, but not always, an LLVM
962 /// null constant.
Eli Friedman20bb5e02009-04-13 21:47:26 +0000963 llvm::Constant *EmitNullConstant(QualType T);
964
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000965 /// Return a null constant appropriate for zero-initializing a base class with
966 /// the given type. This is usually, but not always, an LLVM null constant.
Eli Friedmanfde961d2011-10-14 02:27:24 +0000967 llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
968
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000969 /// Emit a general error that something can't be done.
Chandler Carruth84537952012-03-30 19:44:53 +0000970 void Error(SourceLocation loc, StringRef error);
John McCall7ef5cb32011-03-18 02:56:14 +0000971
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000972 /// Print out an error that codegen doesn't support the specified stmt yet.
David Blaikie4a9ec7b2013-08-19 21:02:26 +0000973 void ErrorUnsupported(const Stmt *S, const char *Type);
Mike Stump1676c5b2009-02-13 19:12:34 +0000974
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000975 /// Print out an error that codegen doesn't support the specified decl yet.
David Blaikie4a9ec7b2013-08-19 21:02:26 +0000976 void ErrorUnsupported(const Decl *D, const char *Type);
Dan Gohman75d69da2008-05-22 00:50:06 +0000977
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000978 /// Set the attributes on the LLVM function for the given decl and function
979 /// info. This applies attributes necessary for handling the ABI as well as
980 /// user specified attributes like section.
Daniel Dunbarc3e7cff2009-04-17 00:48:04 +0000981 void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
982 const CGFunctionInfo &FI);
Daniel Dunbar449a3392008-09-04 23:41:35 +0000983
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000984 /// Set the LLVM function attributes (sext, zext, etc).
Daniel Dunbaraeddffc2009-04-14 07:08:30 +0000985 void SetLLVMFunctionAttributes(const Decl *D,
986 const CGFunctionInfo &Info,
987 llvm::Function *F);
Daniel Dunbarc68897d2008-09-10 00:41:16 +0000988
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000989 /// Set the LLVM function attributes which only apply to a function
James Dennett64fa1232014-08-15 20:04:40 +0000990 /// definition.
Daniel Dunbar38932572009-04-14 08:05:55 +0000991 void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
992
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000993 /// Return true iff the given type uses 'sret' when used as a return type.
Daniel Dunbar6f2e8392010-07-14 23:39:36 +0000994 bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
995
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000996 /// Return true iff the given type uses an argument slot when 'sret' is used
997 /// as a return type.
Tim Northovere77cc392014-03-29 13:28:05 +0000998 bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
999
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001000 /// Return true iff the given type uses 'fpret' when used as a return type.
Daniel Dunbar6f2e8392010-07-14 23:39:36 +00001001 bool ReturnTypeUsesFPRet(QualType ResultType);
Daniel Dunbarc68897d2008-09-10 00:41:16 +00001002
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001003 /// Return true iff the given type uses 'fp2ret' when used as a return type.
Anders Carlsson2f1a6c32011-10-31 16:27:11 +00001004 bool ReturnTypeUsesFP2Ret(QualType ResultType);
1005
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001006 /// Get the LLVM attributes and calling convention to use for a particular
1007 /// function type.
Daniel Dunbar0ef34792009-09-12 00:59:20 +00001008 ///
Chad Rosier7dbc9cf2016-01-06 14:35:46 +00001009 /// \param Name - The function name.
Daniel Dunbar0ef34792009-09-12 00:59:20 +00001010 /// \param Info - The function type information.
Samuel Antao798f11c2015-11-23 22:04:44 +00001011 /// \param CalleeInfo - The callee information these attributes are being
1012 /// constructed for. If valid, the attributes applied to this decl may
1013 /// contribute to the function attributes and calling convention.
Reid Klecknercdd26792017-04-18 23:50:03 +00001014 /// \param Attrs [out] - On return, the attribute list to use.
Daniel Dunbar0ef34792009-09-12 00:59:20 +00001015 /// \param CallingConv [out] - On return, the LLVM calling convention to use.
Chad Rosier7dbc9cf2016-01-06 14:35:46 +00001016 void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
Reid Klecknercdd26792017-04-18 23:50:03 +00001017 CGCalleeInfo CalleeInfo,
1018 llvm::AttributeList &Attrs, unsigned &CallingConv,
1019 bool AttrOnCallSite);
Daniel Dunbarc68897d2008-09-10 00:41:16 +00001020
Justin Lebarb080b632017-01-25 21:29:48 +00001021 /// Adds attributes to F according to our CodeGenOptions and LangOptions, as
1022 /// though we had emitted it ourselves. We remove any attributes on F that
1023 /// conflict with the attributes we add here.
1024 ///
1025 /// This is useful for adding attrs to bitcode modules that you want to link
1026 /// with but don't control, such as CUDA's libdevice. When linking with such
1027 /// a bitcode library, you might want to set e.g. its functions'
1028 /// "unsafe-fp-math" attribute to match the attr of the functions you're
1029 /// codegen'ing. Otherwise, LLVM will interpret the bitcode module's lack of
1030 /// unsafe-fp-math attrs as tantamount to unsafe-fp-math=false, and then LLVM
1031 /// will propagate unsafe-fp-math=false up to every transitive caller of a
1032 /// function in the bitcode library!
1033 ///
1034 /// With the exception of fast-math attrs, this will only make the attributes
1035 /// on the function more conservative. But it's unsafe to call this on a
1036 /// function which relies on particular fast-math attributes for correctness.
1037 /// It's up to you to ensure that this is safe.
1038 void AddDefaultFnAttrs(llvm::Function &F);
1039
Eric Christopher2b90a642015-11-11 23:05:08 +00001040 // Fills in the supplied string map with the set of target features for the
1041 // passed in function.
1042 void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
1043 const FunctionDecl *FD);
1044
Chris Lattner01cf8db2011-07-20 06:58:45 +00001045 StringRef getMangledName(GlobalDecl GD);
Alp Tokerfb8d02b2014-06-05 22:10:59 +00001046 StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
Douglas Gregorbeecd582009-04-21 17:11:58 +00001047
1048 void EmitTentativeDefinition(const VarDecl *D);
Mike Stumpbc78a722009-07-31 18:25:34 +00001049
Nico Weberb6a5d052015-01-15 04:07:35 +00001050 void EmitVTable(CXXRecordDecl *Class);
Douglas Gregor88d292c2010-05-13 16:44:06 +00001051
David Majnemer929025d2016-01-26 19:30:26 +00001052 void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
1053
Peter Collingbourne89061b22017-06-12 20:10:48 +00001054 /// \brief Appends Opts to the "llvm.linker.options" metadata value.
Reid Klecknere43f0fe2013-05-08 13:44:39 +00001055 void AppendLinkerOptions(StringRef Opts);
1056
Benjamin Kramer82dfc972013-06-04 09:13:21 +00001057 /// \brief Appends a detect mismatch command to the linker options.
Aaron Ballman5d041be2013-06-04 02:07:14 +00001058 void AddDetectMismatch(StringRef Name, StringRef Value);
1059
Peter Collingbourne89061b22017-06-12 20:10:48 +00001060 /// \brief Appends a dependent lib to the "llvm.linker.options" metadata
1061 /// value.
Reid Klecknere43f0fe2013-05-08 13:44:39 +00001062 void AddDependentLib(StringRef Lib);
1063
Peter Collingbourne4d90dba2013-06-05 17:49:37 +00001064 llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
John McCalld4324142010-02-19 01:32:20 +00001065
Rafael Espindola64926362014-05-08 14:46:46 +00001066 void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
1067 F->setLinkage(getFunctionLinkage(GD));
John McCall7cb02202010-05-25 04:30:21 +00001068 }
1069
Hans Wennborgbb4f9622015-05-28 17:44:56 +00001070 /// Set the DLL storage class on F.
1071 void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F);
1072
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001073 /// Return the appropriate linkage for the vtable, VTT, and type information
1074 /// of the given class.
Anders Carlsson68d34242011-01-24 02:04:33 +00001075 llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
Ken Dyck98ca7942010-01-26 13:48:07 +00001076
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001077 /// Return the store size, in character units, of the given LLVM type.
Chris Lattner2192fe52011-07-18 04:24:23 +00001078 CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
Fariborz Jahanian1518a5ec2010-10-27 16:21:54 +00001079
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001080 /// Returns LLVM linkage for a declarator.
David Majnemer27d69db2014-04-28 22:17:59 +00001081 llvm::GlobalValue::LinkageTypes
Hans Wennborg1a3a0742014-05-14 19:54:53 +00001082 getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
Hans Wennborg275efb92014-05-28 01:52:23 +00001083 bool IsConstantVariable);
David Majnemer27d69db2014-04-28 22:17:59 +00001084
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001085 /// Returns LLVM linkage for a declarator.
David Majnemer27d69db2014-04-28 22:17:59 +00001086 llvm::GlobalValue::LinkageTypes
1087 getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
1088
Julien Lerouge5a6b6982011-09-09 22:41:49 +00001089 /// Emit all the global annotations.
1090 void EmitGlobalAnnotations();
1091
1092 /// Emit an annotation string.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00001093 llvm::Constant *EmitAnnotationString(StringRef Str);
Julien Lerouge5a6b6982011-09-09 22:41:49 +00001094
1095 /// Emit the annotation's translation unit.
1096 llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
1097
1098 /// Emit the annotation line number.
1099 llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
1100
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001101 /// Generate the llvm::ConstantStruct which contains the annotation
1102 /// information for a given GlobalValue. The annotation struct is
Julien Lerouge5a6b6982011-09-09 22:41:49 +00001103 /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
1104 /// GlobalValue being annotated. The second field is the constant string
1105 /// created from the AnnotateAttr's annotation. The third field is a constant
1106 /// string containing the name of the translation unit. The fourth field is
1107 /// the line number in the file of the annotated value declaration.
1108 llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
1109 const AnnotateAttr *AA,
1110 SourceLocation L);
1111
1112 /// Add global annotations that are set on D, for the global GV. Those
1113 /// annotations are emitted during finalization of the LLVM code.
1114 void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
1115
Vlad Tsyrklevich2eccdab2017-09-25 22:11:12 +00001116 bool isInSanitizerBlacklist(SanitizerMask Kind, llvm::Function *Fn,
1117 SourceLocation Loc) const;
Will Dietzf54319c2013-01-18 11:30:38 +00001118
Alexey Samsonova0ac3c22014-10-17 22:37:33 +00001119 bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
1120 QualType Ty,
1121 StringRef Category = StringRef()) const;
1122
Dean Michael Berris835832d2017-03-30 00:29:36 +00001123 /// Imbue XRay attributes to a function, applying the always/never attribute
1124 /// lists in the process. Returns true if we did imbue attributes this way,
1125 /// false otherwise.
1126 bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
1127 StringRef Category = StringRef()) const;
1128
Alexey Samsonov4b8de112014-08-01 21:35:28 +00001129 SanitizerMetadata *getSanitizerMetadata() {
1130 return SanitizerMD.get();
1131 }
Alexey Samsonov4f319cc2014-07-02 16:54:41 +00001132
John McCall6bd2a892013-01-25 22:31:03 +00001133 void addDeferredVTable(const CXXRecordDecl *RD) {
1134 DeferredVTables.push_back(RD);
1135 }
1136
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001137 /// Emit code for a singal global function or var decl. Forward declarations
1138 /// are emitted lazily.
Reid Klecknere7de47e2013-07-22 13:51:44 +00001139 void EmitGlobal(GlobalDecl D);
1140
Rafael Espindola02b77f42014-09-15 18:46:13 +00001141 bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
1142 bool InEveryTU);
1143 bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
1144
1145 /// Set attributes for a global definition.
1146 void setFunctionDefinitionAttributes(const FunctionDecl *D,
1147 llvm::Function *F);
1148
Chris Lattner01cf8db2011-07-20 06:58:45 +00001149 llvm::GlobalValue *GetGlobalValue(StringRef Ref);
Mike Stump11289f42009-09-09 15:08:12 +00001150
Rafael Espindola1e4df922014-09-16 15:18:21 +00001151 /// Set attributes which are common to any form of a global definition (alias,
1152 /// Objective-C method, function, global variable).
1153 ///
1154 /// NOTE: This should only be called for definitions.
1155 void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
1156
Dario Domiziolic4fb8ca72014-09-19 22:06:24 +00001157 /// Set attributes which must be preserved by an alias. This includes common
1158 /// attributes (i.e. it includes a call to SetCommonAttributes).
1159 ///
1160 /// NOTE: This should only be called for definitions.
1161 void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
1162
Rafael Espindola1e4df922014-09-16 15:18:21 +00001163 void addReplacement(StringRef Name, llvm::Constant *C);
Alexey Bataev97720002014-11-11 04:05:39 +00001164
Andrey Bokhankocab58582015-08-31 13:20:44 +00001165 void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
1166
Alexey Bataev97720002014-11-11 04:05:39 +00001167 /// \brief Emit a code for threadprivate directive.
1168 /// \param D Threadprivate declaration.
1169 void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
1170
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001171 /// \brief Emit a code for declare reduction construct.
Alexey Bataevc5b1d322016-03-04 09:22:22 +00001172 void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D,
1173 CodeGenFunction *CGF = nullptr);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001174
Peter Collingbourne3afb2662016-04-28 17:09:37 +00001175 /// Returns whether the given record has hidden LTO visibility and therefore
1176 /// may participate in (single-module) CFI and whole-program vtable
1177 /// optimization.
1178 bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
Peter Collingbournee5706442015-07-09 19:56:14 +00001179
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001180 /// Emit type metadata for the given vtable using the given layout.
1181 void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
1182 const VTableLayout &VTLayout);
Peter Collingbournea4ccff32015-02-20 20:30:56 +00001183
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001184 /// Generate a cross-DSO type identifier for MD.
1185 llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD);
Evgeniy Stepanovfd6f92d2015-12-15 23:00:20 +00001186
Peter Collingbourne25a80bf2015-09-08 23:01:30 +00001187 /// Create a metadata identifier for the given type. This may either be an
1188 /// MDString (for external identifiers) or a distinct unnamed MDNode (for
1189 /// internal identifiers).
1190 llvm::Metadata *CreateMetadataIdentifierForType(QualType T);
1191
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001192 /// Create and attach type metadata to the given function.
1193 void CreateFunctionTypeMetadata(const FunctionDecl *FD, llvm::Function *F);
Evgeniy Stepanovfd6f92d2015-12-15 23:00:20 +00001194
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001195 /// Returns whether this module needs the "all-vtables" type identifier.
1196 bool NeedAllVtablesTypeId() const;
Evgeniy Stepanovf31ea302016-02-03 22:18:55 +00001197
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001198 /// Create and attach type metadata for the given vtable.
1199 void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset,
1200 const CXXRecordDecl *RD);
Peter Collingbourne86d34a72015-06-17 19:08:05 +00001201
Simon Pilgrim2c518802017-03-30 14:13:19 +00001202 /// \brief Get the declaration of std::terminate for the platform.
Reid Klecknerfff8e7f2015-03-03 19:21:04 +00001203 llvm::Constant *getTerminateFn();
1204
Peter Collingbournedc134532016-01-16 00:31:22 +00001205 llvm::SanitizerStatReport &getSanStats();
1206
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +00001207 llvm::Value *
1208 createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF);
1209
Yaxun Liu402804b2016-12-15 08:09:08 +00001210 /// Get target specific null pointer.
1211 /// \param T is the LLVM type of the null pointer.
1212 /// \param QT is the clang QualType of the null pointer.
1213 llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT);
1214
Rafael Espindola1e4df922014-09-16 15:18:21 +00001215private:
Reid Klecknerde864822017-03-21 16:57:30 +00001216 llvm::Constant *GetOrCreateLLVMFunction(
1217 StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
1218 bool DontDefer = false, bool IsThunk = false,
1219 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1220 ForDefinition_t IsForDefinition = NotForDefinition);
Rafael Espindola94abb8f2013-12-09 04:29:47 +00001221
Chris Lattner01cf8db2011-07-20 06:58:45 +00001222 llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
Chris Lattner2192fe52011-07-18 04:24:23 +00001223 llvm::PointerType *PTy,
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +00001224 const VarDecl *D,
John McCalld195d4c2016-11-30 23:25:13 +00001225 ForDefinition_t IsForDefinition
1226 = NotForDefinition);
Mike Stump11289f42009-09-09 15:08:12 +00001227
Rafael Espindolaee076a22014-05-13 18:45:53 +00001228 void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
Rafael Espindola502f65a2014-05-05 20:21:03 +00001229
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001230 /// Set function attributes for a function declaration.
David Majnemerb9bd6fb2014-11-01 05:42:23 +00001231 void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
Simon Atanasyan1a116db2017-07-20 20:34:18 +00001232 bool IsIncompleteFunction, bool IsThunk,
1233 ForDefinition_t IsForDefinition);
Nuno Lopesb6f79532008-06-08 15:45:52 +00001234
Craig Topper8a13c412014-05-21 05:09:00 +00001235 void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
Daniel Dunbarf0acf7b2009-02-19 07:15:39 +00001236
Rafael Espindolacd7743b2013-12-09 16:01:03 +00001237 void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +00001238 void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
John McCall7ec50432010-03-19 23:29:14 +00001239 void EmitAliasDefinition(GlobalDecl GD);
Dmitry Polukhin85eda122016-04-11 07:48:59 +00001240 void emitIFuncDefinition(GlobalDecl GD);
Daniel Dunbar89654ee2008-08-26 08:29:31 +00001241 void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
Fariborz Jahanian0dec1e02010-04-28 21:28:56 +00001242 void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
Fariborz Jahanian1518a5ec2010-10-27 16:21:54 +00001243
Anders Carlssonf7475242009-04-15 15:55:24 +00001244 // C++ related functions.
Mike Stump11289f42009-09-09 15:08:12 +00001245
Richard Smith8df390f2016-09-08 23:14:54 +00001246 void EmitDeclContext(const DeclContext *DC);
Anders Carlssoncbaeb9e2009-04-02 05:55:18 +00001247 void EmitLinkageSpec(const LinkageSpecDecl *D);
Anders Carlssonf7475242009-04-15 15:55:24 +00001248
Richard Smith2fd1d7a2013-04-19 16:42:07 +00001249 /// \brief Emit the function that initializes C++ thread_local variables.
1250 void EmitCXXThreadLocalInitFunc();
1251
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001252 /// Emit the function that initializes C++ globals.
Anders Carlssonb8be93f2009-08-08 23:24:23 +00001253 void EmitCXXGlobalInitFunc();
Eli Friedman5866fe32010-01-08 00:50:11 +00001254
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001255 /// Emit the function that destroys C++ globals.
Daniel Dunbarfe06df42010-03-20 04:15:41 +00001256 void EmitCXXGlobalDtorFunc();
1257
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001258 /// Emit the function that initializes the specified global (if PerformInit is
1259 /// true) and registers its destructor.
John McCallcdf7ef52010-11-06 09:44:32 +00001260 void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
Richard Smith6331c402012-02-13 22:16:19 +00001261 llvm::GlobalVariable *Addr,
1262 bool PerformInit);
Eli Friedman5866fe32010-01-08 00:50:11 +00001263
Reid Kleckner1a711b12014-07-22 00:53:05 +00001264 void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
1265 llvm::Function *InitFunc, InitSegAttr *ISA);
1266
Daniel Dunbar74aa7e12008-08-01 00:01:51 +00001267 // FIXME: Hardcoding priority here is gross.
Reid Kleckner563f0e82014-05-23 21:13:45 +00001268 void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
Hans Wennborg59dbe862015-09-29 20:56:43 +00001269 llvm::Constant *AssociatedData = nullptr);
Reid Kleckner563f0e82014-05-23 21:13:45 +00001270 void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
Daniel Dunbar9c426522008-07-29 23:18:29 +00001271
Vassil Vassilev188ad3a2016-10-27 09:12:20 +00001272 /// EmitCtorList - Generates a global array of functions and priorities using
1273 /// the given list and name. This array will have appending linkage and is
1274 /// suitable for use as a LLVM constructor or destructor array. Clears Fns.
1275 void EmitCtorList(CtorList &Fns, const char *GlobalName);
Daniel Dunbar74aa7e12008-08-01 00:01:51 +00001276
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001277 /// Emit any needed decls for which code generation was deferred.
Dmitri Gribenkob2aa9232012-11-15 14:28:07 +00001278 void EmitDeferred();
Daniel Dunbar08b26a02009-02-13 20:29:50 +00001279
Piotr Padlewskid3b1cbd2017-06-01 08:04:05 +00001280 /// Try to emit external vtables as available_externally if they have emitted
1281 /// all inlined virtual functions. It runs after EmitDeferred() and therefore
1282 /// is not allowed to create new references to things that need to be emitted
1283 /// lazily.
1284 void EmitVTablesOpportunistically();
1285
Rafael Espindola2e2995b2013-11-05 21:37:29 +00001286 /// Call replaceAllUsesWith on all pairs in Replacements.
1287 void applyReplacements();
1288
Andrey Bokhankocab58582015-08-31 13:20:44 +00001289 /// Call replaceAllUsesWith on all pairs in GlobalValReplacements.
1290 void applyGlobalValReplacements();
1291
Rafael Espindola208b5c02013-10-22 19:26:13 +00001292 void checkAliases();
1293
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001294 /// Emit any vtables which we deferred and still have a use for.
John McCall6bd2a892013-01-25 22:31:03 +00001295 void EmitDeferredVTables();
1296
Alex Lorenza8fbef42017-03-23 11:14:27 +00001297 /// Emit a dummy function that reference a CoreFoundation symbol when
1298 /// @available is used on Darwin.
1299 void emitAtAvailableLinkGuard();
1300
Rafael Espindola060062a2014-03-06 22:15:10 +00001301 /// Emit the llvm.used and llvm.compiler.used metadata.
1302 void emitLLVMUsed();
Daniel Dunbar23fd4622008-10-01 00:49:24 +00001303
Douglas Gregorbc25ff42013-01-14 20:53:57 +00001304 /// \brief Emit the link options introduced by imported modules.
1305 void EmitModuleLinkOptions();
1306
Richard Smithdf931ce2013-04-06 05:00:46 +00001307 /// \brief Emit aliases for internal-linkage declarations inside "C" language
1308 /// linkage specifications, giving them the "expected" name where possible.
1309 void EmitStaticExternCAliases();
1310
John McCall09ae0322010-07-06 23:57:41 +00001311 void EmitDeclMetadata();
1312
Rafael Espindola3bfa4682013-10-16 19:28:50 +00001313 /// \brief Emit the Clang version as llvm.ident metadata.
1314 void EmitVersionIdentMetadata();
1315
Robert Lytton57765d52014-07-03 09:30:33 +00001316 /// Emits target specific Metadata for global declarations.
1317 void EmitTargetMetadata();
1318
Alexey Bader364a1162017-06-20 14:30:18 +00001319 /// Emits OpenCL specific Metadata e.g. OpenCL version.
1320 void EmitOpenCLMetadata();
1321
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001322 /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
1323 /// .gcda files in a way that persists in .bc files.
Nick Lewycky85c011d2011-05-05 00:08:20 +00001324 void EmitCoverageFile();
Nick Lewycky480cb992011-05-04 20:46:58 +00001325
Nico Webercf4ff5862012-10-11 10:13:44 +00001326 /// Emits the initializer for a uuidof string.
Nico Weber17d3a2c2014-09-08 16:26:36 +00001327 llvm::Constant *EmitUuidofInitializer(StringRef uuidstr);
Nico Webercf4ff5862012-10-11 10:13:44 +00001328
Hans Wennborg43a0f992015-01-10 01:19:48 +00001329 /// Determine whether the definition must be emitted; if this returns \c
1330 /// false, the definition can be emitted lazily if it's used.
1331 bool MustBeEmitted(const ValueDecl *D);
1332
1333 /// Determine whether the definition can be emitted eagerly, or should be
1334 /// delayed until the end of the translation unit. This is relevant for
1335 /// definitions whose linkage can change, e.g. implicit function instantions
1336 /// which may later be explicitly instantiated.
1337 bool MayBeEmittedEagerly(const ValueDecl *D);
John McCall0bdb1fd2010-09-16 06:16:50 +00001338
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001339 /// Check whether we can use a "simpler", more core exceptions personality
1340 /// function.
John McCall0bdb1fd2010-09-16 06:16:50 +00001341 void SimplifyPersonality();
Justin Lebarb080b632017-01-25 21:29:48 +00001342
1343 /// Helper function for ConstructAttributeList and AddDefaultFnAttrs.
1344 /// Constructs an AttrList for a function with the given properties.
1345 void ConstructDefaultFnAttrList(StringRef Name, bool HasOptnone,
1346 bool AttrOnCallSite,
1347 llvm::AttrBuilder &FuncAttrs);
Chris Lattnerf97fe382007-05-24 06:29:05 +00001348};
John McCallde0fe072017-08-15 21:42:52 +00001349
Chris Lattnerf97fe382007-05-24 06:29:05 +00001350} // end namespace CodeGen
1351} // end namespace clang
Chris Lattnerf97fe382007-05-24 06:29:05 +00001352
Hans Wennborg59dbe862015-09-29 20:56:43 +00001353#endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H