blob: 1d59230c2c2087dc0628b3d8174823cf6219a54f [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"
Chris Lattnerb6984c42007-06-20 04:44:43 +000031#include "llvm/ADT/DenseMap.h"
Douglas Gregor6ddfca92013-01-14 17:21:00 +000032#include "llvm/ADT/SetVector.h"
Rafael Espindola2e42fec2010-03-04 18:17:24 +000033#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000034#include "llvm/ADT/StringMap.h"
Chandler Carruthffd55512013-01-02 11:45:17 +000035#include "llvm/IR/Module.h"
Chandler Carruth61743af2014-03-04 11:18:19 +000036#include "llvm/IR/ValueHandle.h"
Peter Collingbournedc134532016-01-16 00:31:22 +000037#include "llvm/Transforms/Utils/SanitizerStats.h"
Anders Carlsson762e1622009-01-04 02:08:04 +000038
Chris Lattnerf97fe382007-05-24 06:29:05 +000039namespace llvm {
Rafael Espindola42ae7452014-05-09 00:57:59 +000040class Module;
41class Constant;
42class ConstantInt;
43class Function;
44class GlobalValue;
45class DataLayout;
46class FunctionType;
47class LLVMContext;
48class IndexedInstrProfReader;
Alexander Kornienkoab9db512015-06-22 23:07:51 +000049}
Chris Lattner23b7eb62007-06-15 23:05:46 +000050
Chris Lattnerf97fe382007-05-24 06:29:05 +000051namespace clang {
Rafael Espindola42ae7452014-05-09 00:57:59 +000052class ASTContext;
53class AtomicType;
54class FunctionDecl;
55class IdentifierInfo;
56class ObjCMethodDecl;
57class ObjCImplementationDecl;
58class ObjCCategoryImplDecl;
59class ObjCProtocolDecl;
60class ObjCEncodeExpr;
61class BlockExpr;
62class CharUnits;
63class Decl;
64class Expr;
65class Stmt;
66class InitListExpr;
67class StringLiteral;
68class NamedDecl;
69class ValueDecl;
70class VarDecl;
71class LangOptions;
72class CodeGenOptions;
Adrian Prantle74f5252015-06-30 02:26:03 +000073class HeaderSearchOptions;
74class PreprocessorOptions;
Rafael Espindola42ae7452014-05-09 00:57:59 +000075class DiagnosticsEngine;
76class AnnotateAttr;
77class CXXDestructorDecl;
Rafael Espindola42ae7452014-05-09 00:57:59 +000078class Module;
Alex Lorenzee024992014-08-04 18:41:51 +000079class CoverageSourceInfo;
Mike Stump1676c5b2009-02-13 19:12:34 +000080
Chris Lattnerf97fe382007-05-24 06:29:05 +000081namespace CodeGen {
82
Rafael Espindola42ae7452014-05-09 00:57:59 +000083class CallArgList;
84class CodeGenFunction;
85class CodeGenTBAA;
86class CGCXXABI;
87class CGDebugInfo;
88class CGObjCRuntime;
89class CGOpenCLRuntime;
90class CGOpenMPRuntime;
91class CGCUDARuntime;
92class BlockFieldFlags;
93class FunctionArgList;
Alex Lorenzee024992014-08-04 18:41:51 +000094class CoverageMappingModuleGen;
John McCall12f23522016-04-04 18:33:08 +000095class TargetCodeGenInfo;
Justin Bogneref512b92014-01-06 22:27:43 +000096
John McCalld195d4c2016-11-30 23:25:13 +000097enum ForDefinition_t : bool {
98 NotForDefinition = false,
99 ForDefinition = true
100};
101
Rafael Espindola42ae7452014-05-09 00:57:59 +0000102struct OrderGlobalInits {
103 unsigned int priority;
104 unsigned int lex_order;
105 OrderGlobalInits(unsigned int p, unsigned int l)
Chris Lattnere0009072010-06-27 06:32:58 +0000106 : priority(p), lex_order(l) {}
Rafael Espindola42ae7452014-05-09 00:57:59 +0000107
108 bool operator==(const OrderGlobalInits &RHS) const {
109 return priority == RHS.priority && lex_order == RHS.lex_order;
110 }
111
112 bool operator<(const OrderGlobalInits &RHS) const {
113 return std::tie(priority, lex_order) <
114 std::tie(RHS.priority, RHS.lex_order);
115 }
116};
117
John McCallb04ecb72015-10-21 18:06:43 +0000118struct ObjCEntrypoints {
119 ObjCEntrypoints() { memset(this, 0, sizeof(*this)); }
120
Pete Cooper94867712016-03-21 20:50:03 +0000121 /// void objc_autoreleasePoolPop(void*);
John McCall31168b02011-06-15 23:02:42 +0000122 llvm::Constant *objc_autoreleasePoolPop;
123
124 /// void *objc_autoreleasePoolPush(void);
125 llvm::Constant *objc_autoreleasePoolPush;
John McCall31168b02011-06-15 23:02:42 +0000126
127 /// id objc_autorelease(id);
128 llvm::Constant *objc_autorelease;
129
130 /// id objc_autoreleaseReturnValue(id);
131 llvm::Constant *objc_autoreleaseReturnValue;
132
133 /// void objc_copyWeak(id *dest, id *src);
134 llvm::Constant *objc_copyWeak;
135
136 /// void objc_destroyWeak(id*);
137 llvm::Constant *objc_destroyWeak;
138
139 /// id objc_initWeak(id*, id);
140 llvm::Constant *objc_initWeak;
141
142 /// id objc_loadWeak(id*);
143 llvm::Constant *objc_loadWeak;
144
145 /// id objc_loadWeakRetained(id*);
146 llvm::Constant *objc_loadWeakRetained;
147
148 /// void objc_moveWeak(id *dest, id *src);
149 llvm::Constant *objc_moveWeak;
150
151 /// id objc_retain(id);
152 llvm::Constant *objc_retain;
153
154 /// id objc_retainAutorelease(id);
155 llvm::Constant *objc_retainAutorelease;
156
157 /// id objc_retainAutoreleaseReturnValue(id);
158 llvm::Constant *objc_retainAutoreleaseReturnValue;
159
160 /// id objc_retainAutoreleasedReturnValue(id);
161 llvm::Constant *objc_retainAutoreleasedReturnValue;
162
163 /// id objc_retainBlock(id);
164 llvm::Constant *objc_retainBlock;
165
166 /// void objc_release(id);
167 llvm::Constant *objc_release;
168
Saleem Abdulrasool5b1f0ed2017-02-11 17:24:09 +0000169 /// void objc_storeStrong(id*, id);
John McCall31168b02011-06-15 23:02:42 +0000170 llvm::Constant *objc_storeStrong;
171
172 /// id objc_storeWeak(id*, id);
173 llvm::Constant *objc_storeWeak;
174
John McCalle399e5b2016-01-27 18:32:30 +0000175 /// id objc_unsafeClaimAutoreleasedReturnValue(id);
176 llvm::Constant *objc_unsafeClaimAutoreleasedReturnValue;
177
John McCall31168b02011-06-15 23:02:42 +0000178 /// A void(void) inline asm to use to mark that the return value of
179 /// a call will be immediately retain.
180 llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
John McCalleff18842013-03-23 02:35:54 +0000181
182 /// void clang.arc.use(...);
183 llvm::Constant *clang_arc_use;
John McCall31168b02011-06-15 23:02:42 +0000184};
Will Dietzf54319c2013-01-18 11:30:38 +0000185
Justin Bognere2ef2a02014-04-15 21:22:35 +0000186/// This class records statistics on instrumentation based profiling.
Justin Bogner40b8ba12014-06-26 01:45:07 +0000187class InstrProfStats {
188 uint32_t VisitedInMainFile;
189 uint32_t MissingInMainFile;
Justin Bognere2ef2a02014-04-15 21:22:35 +0000190 uint32_t Visited;
191 uint32_t Missing;
192 uint32_t Mismatched;
Justin Bogner40b8ba12014-06-26 01:45:07 +0000193
194public:
195 InstrProfStats()
196 : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
197 Mismatched(0) {}
198 /// Record that we've visited a function and whether or not that function was
199 /// in the main source file.
200 void addVisited(bool MainFile) {
201 if (MainFile)
202 ++VisitedInMainFile;
203 ++Visited;
204 }
205 /// Record that a function we've visited has no profile data.
206 void addMissing(bool MainFile) {
207 if (MainFile)
208 ++MissingInMainFile;
209 ++Missing;
210 }
211 /// Record that a function we've visited has mismatched profile data.
212 void addMismatched(bool MainFile) { ++Mismatched; }
213 /// Whether or not the stats we've gathered indicate any potential problems.
214 bool hasDiagnostics() { return Missing || Mismatched; }
215 /// Report potential problems we've found to \c Diags.
216 void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
Justin Bognere2ef2a02014-04-15 21:22:35 +0000217};
218
John McCallbd96e982015-09-08 08:21:11 +0000219/// A pair of helper functions for a __block variable.
220class BlockByrefHelpers : public llvm::FoldingSetNode {
221 // MSVC requires this type to be complete in order to process this
222 // header.
223public:
224 llvm::Constant *CopyHelper;
225 llvm::Constant *DisposeHelper;
226
227 /// The alignment of the field. This is important because
228 /// different offsets to the field within the byref struct need to
229 /// have different helper functions.
230 CharUnits Alignment;
231
232 BlockByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
233 BlockByrefHelpers(const BlockByrefHelpers &) = default;
234 virtual ~BlockByrefHelpers();
235
236 void Profile(llvm::FoldingSetNodeID &id) const {
237 id.AddInteger(Alignment.getQuantity());
238 profileImpl(id);
239 }
240 virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
241
242 virtual bool needsCopy() const { return true; }
243 virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src) = 0;
244
245 virtual bool needsDispose() const { return true; }
246 virtual void emitDispose(CodeGenFunction &CGF, Address field) = 0;
247};
248
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000249/// This class organizes the cross-function state that is used while generating
250/// LLVM code.
John McCalle3dc1702011-02-15 09:22:45 +0000251class CodeGenModule : public CodeGenTypeCache {
Aaron Ballmanabc18922015-02-15 22:54:08 +0000252 CodeGenModule(const CodeGenModule &) = delete;
253 void operator=(const CodeGenModule &) = delete;
Anders Carlsson729a8202009-02-24 04:21:31 +0000254
Keno Fischer76f4ab02014-12-30 08:12:39 +0000255public:
Reid Kleckner563f0e82014-05-23 21:13:45 +0000256 struct Structor {
257 Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
258 Structor(int Priority, llvm::Constant *Initializer,
259 llvm::Constant *AssociatedData)
260 : Priority(Priority), Initializer(Initializer),
261 AssociatedData(AssociatedData) {}
262 int Priority;
263 llvm::Constant *Initializer;
264 llvm::Constant *AssociatedData;
265 };
266
267 typedef std::vector<Structor> CtorList;
Daniel Dunbar74aa7e12008-08-01 00:01:51 +0000268
Keno Fischer76f4ab02014-12-30 08:12:39 +0000269private:
Chris Lattnerf97fe382007-05-24 06:29:05 +0000270 ASTContext &Context;
David Blaikiebbafb8a2012-03-11 07:00:24 +0000271 const LangOptions &LangOpts;
Adrian Prantle74f5252015-06-30 02:26:03 +0000272 const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info.
273 const PreprocessorOptions &PreprocessorOpts; // Only used for debug info.
Chandler Carruthbc55fe22009-11-12 17:24:48 +0000274 const CodeGenOptions &CodeGenOpts;
Chris Lattner23b7eb62007-06-15 23:05:46 +0000275 llvm::Module &TheModule;
David Blaikie9c902b52011-09-25 23:23:43 +0000276 DiagnosticsEngine &Diags;
John McCallc8e01702013-04-16 22:48:15 +0000277 const TargetInfo &Target;
Ahmed Charlesb8984322014-03-07 20:03:18 +0000278 std::unique_ptr<CGCXXABI> ABI;
John McCallc8e01702013-04-16 22:48:15 +0000279 llvm::LLVMContext &VMContext;
Anders Carlssonff971e82009-10-07 01:06:45 +0000280
Reid Kleckner9305fd12016-04-13 23:37:17 +0000281 std::unique_ptr<CodeGenTBAA> TBAA;
John McCallc8e01702013-04-16 22:48:15 +0000282
Reid Kleckner9305fd12016-04-13 23:37:17 +0000283 mutable std::unique_ptr<TargetCodeGenInfo> TheTargetCodeGenInfo;
John McCallc8e01702013-04-16 22:48:15 +0000284
285 // This should not be moved earlier, since its initialization depends on some
286 // of the previous reference members being already initialized and also checks
287 // if TheTargetCodeGenInfo is NULL
288 CodeGenTypes Types;
289
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000290 /// Holds information about C++ vtables.
Anders Carlssona864caf2010-03-23 04:11:45 +0000291 CodeGenVTables VTables;
Douglas Gregorbc6a4342010-04-08 16:07:47 +0000292
Reid Kleckner9305fd12016-04-13 23:37:17 +0000293 std::unique_ptr<CGObjCRuntime> ObjCRuntime;
294 std::unique_ptr<CGOpenCLRuntime> OpenCLRuntime;
295 std::unique_ptr<CGOpenMPRuntime> OpenMPRuntime;
296 std::unique_ptr<CGCUDARuntime> CUDARuntime;
297 std::unique_ptr<CGDebugInfo> DebugInfo;
298 std::unique_ptr<ObjCEntrypoints> ObjCData;
299 llvm::MDNode *NoObjCARCExceptionsMetadata = nullptr;
Justin Bogner837a6f62014-04-18 21:52:00 +0000300 std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
Justin Bognere2ef2a02014-04-15 21:22:35 +0000301 InstrProfStats PGOStats;
Peter Collingbournedc134532016-01-16 00:31:22 +0000302 std::unique_ptr<llvm::SanitizerStatReport> SanStats;
Daniel Dunbare49df9b52008-07-30 16:32:24 +0000303
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000304 // A set of references that have only been seen via a weakref so far. This is
305 // used to remove the weak of the reference if we ever see a direct reference
306 // or a definition.
Rafael Espindola2e42fec2010-03-04 18:17:24 +0000307 llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
308
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000309 /// This contains all the decls which have definitions but/ which are deferred
310 /// for emission and therefore should only be output if they are actually
311 /// used. If a decl is in this, then it is known to have not been referenced
312 /// yet.
Alp Tokerfb8d02b2014-06-05 22:10:59 +0000313 std::map<StringRef, GlobalDecl> DeferredDecls;
Daniel Dunbar08b26a02009-02-13 20:29:50 +0000314
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000315 /// This is a list of deferred decls which we have seen that *are* actually
316 /// referenced. These get code generated when the module is done.
Rafael Espindolac0ff7442013-12-09 14:59:08 +0000317 struct DeferredGlobal {
318 DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {}
Rafael Espindola6565e922015-01-23 05:26:38 +0000319 llvm::TrackingVH<llvm::GlobalValue> GV;
Rafael Espindolac0ff7442013-12-09 14:59:08 +0000320 GlobalDecl GD;
321 };
322 std::vector<DeferredGlobal> DeferredDeclsToEmit;
323 void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) {
Benjamin Kramer3204b152015-05-29 19:42:19 +0000324 DeferredDeclsToEmit.emplace_back(GV, GD);
Rafael Espindolac0ff7442013-12-09 14:59:08 +0000325 }
Daniel Dunbar7dd749e2009-04-15 22:08:45 +0000326
Rafael Espindola208b5c02013-10-22 19:26:13 +0000327 /// List of alias we have emitted. Used to make sure that what they point to
328 /// is defined once we get to the end of the of the translation unit.
329 std::vector<GlobalDecl> Aliases;
330
Rafael Espindola2e2995b2013-11-05 21:37:29 +0000331 typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
332 ReplacementsTy Replacements;
333
Andrey Bokhankocab58582015-08-31 13:20:44 +0000334 /// List of global values to be replaced with something else. Used when we
335 /// want to replace a GlobalValue but can't identify it by its mangled name
336 /// anymore (because the name is already taken).
337 llvm::SmallVector<std::pair<llvm::GlobalValue *, llvm::Constant *>, 8>
338 GlobalValReplacements;
339
340 /// Set of global decls for which we already diagnosed mangled name conflict.
341 /// Required to not issue a warning (on a mangling conflict) multiple times
342 /// for the same decl.
343 llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions;
344
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000345 /// A queue of (optional) vtables to consider emitting.
John McCall6bd2a892013-01-25 22:31:03 +0000346 std::vector<const CXXRecordDecl*> DeferredVTables;
347
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000348 /// List of global values which are required to be present in the object file;
349 /// bitcast to i8*. This is used for forcing visibility of symbols which may
350 /// otherwise be optimized out.
Chris Lattnerf41e87f2009-03-31 22:37:52 +0000351 std::vector<llvm::WeakVH> LLVMUsed;
Rafael Espindola060062a2014-03-06 22:15:10 +0000352 std::vector<llvm::WeakVH> LLVMCompilerUsed;
Mike Stump1676c5b2009-02-13 19:12:34 +0000353
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000354 /// Store the list of global constructors and their respective priorities to
355 /// be emitted when the translation unit is complete.
Daniel Dunbar74aa7e12008-08-01 00:01:51 +0000356 CtorList GlobalCtors;
357
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000358 /// Store the list of global destructors and their respective priorities to be
359 /// emitted when the translation unit is complete.
Daniel Dunbar74aa7e12008-08-01 00:01:51 +0000360 CtorList GlobalDtors;
361
Robert Lytton57765d52014-07-03 09:30:33 +0000362 /// An ordered map of canonical GlobalDecls to their mangled names.
363 llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
Alp Tokerfb8d02b2014-06-05 22:10:59 +0000364 llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
365
Julien Lerouge5a6b6982011-09-09 22:41:49 +0000366 /// Global annotations.
Nate Begeman7fab5782008-04-18 23:43:57 +0000367 std::vector<llvm::Constant*> Annotations;
Mike Stump1676c5b2009-02-13 19:12:34 +0000368
Julien Lerouge5a6b6982011-09-09 22:41:49 +0000369 /// Map used to get unique annotation strings.
370 llvm::StringMap<llvm::Constant*> AnnotationStrings;
371
David Blaikie2e804282015-04-05 22:47:07 +0000372 llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
David Majnemer58e5bee2014-03-24 21:43:36 +0000373
Richard Smith00db2f12014-07-29 21:20:12 +0000374 llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
Eli Friedman1c8d2ca2012-03-09 03:27:46 +0000375 llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
John McCallb88a5662012-03-30 21:00:39 +0000376 llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
Richard Smithe6c01442013-06-05 00:46:14 +0000377 llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
378
Fariborz Jahanian1bed4132012-01-08 19:13:23 +0000379 llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
380 llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
Daniel Dunbard644ad62008-08-23 18:37:06 +0000381
Will Dietz949ec542013-11-08 01:09:22 +0000382 /// Map used to get unique type descriptor constants for sanitizers.
383 llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
384
Richard Smithdf931ce2013-04-06 05:00:46 +0000385 /// Map used to track internal linkage functions declared within
386 /// extern "C" regions.
Richard Smithf21c9612013-04-13 01:28:18 +0000387 typedef llvm::MapVector<IdentifierInfo *,
388 llvm::GlobalValue *> StaticExternCMap;
Richard Smithdf931ce2013-04-06 05:00:46 +0000389 StaticExternCMap StaticExternCValues;
390
Richard Smith2fd1d7a2013-04-19 16:42:07 +0000391 /// \brief thread_local variables defined or used in this TU.
Richard Smith5a99c492015-12-01 01:10:48 +0000392 std::vector<const VarDecl *> CXXThreadLocals;
Richard Smith2fd1d7a2013-04-19 16:42:07 +0000393
394 /// \brief thread_local variables with initializers that need to run
395 /// before any thread_local variable in this TU is odr-used.
David Majnemerb3341ea2014-10-05 05:05:40 +0000396 std::vector<llvm::Function *> CXXThreadLocalInits;
Richard Smith5a99c492015-12-01 01:10:48 +0000397 std::vector<const VarDecl *> CXXThreadLocalInitVars;
Richard Smith2fd1d7a2013-04-19 16:42:07 +0000398
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000399 /// Global variables with initializers that need to run before main.
David Majnemerb3341ea2014-10-05 05:05:40 +0000400 std::vector<llvm::Function *> CXXGlobalInits;
John McCall70013b62010-07-15 23:40:35 +0000401
402 /// When a C++ decl with an initializer is deferred, null is
403 /// appended to CXXGlobalInits, and the index of that null is placed
404 /// here so that the initializer will be performed in the correct
Reid Klecknere07140e2015-04-15 01:08:06 +0000405 /// order. Once the decl is emitted, the index is replaced with ~0U to ensure
406 /// that we don't re-emit the initializer.
John McCall70013b62010-07-15 23:40:35 +0000407 llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
Fariborz Jahanian9f2a4ee2010-06-21 18:45:05 +0000408
Anton Korobeynikovabed7492012-11-06 22:44:45 +0000409 typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
410
411 struct GlobalInitPriorityCmp {
412 bool operator()(const GlobalInitData &LHS,
413 const GlobalInitData &RHS) const {
414 return LHS.first.priority < RHS.first.priority;
415 }
416 };
417
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000418 /// Global variables with initializers whose order of initialization is set by
419 /// init_priority attribute.
Anton Korobeynikovabed7492012-11-06 22:44:45 +0000420 SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
Mike Stump11289f42009-09-09 15:08:12 +0000421
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000422 /// Global destructor functions and arguments that need to run on termination.
Chris Lattner87233f72010-06-19 05:52:45 +0000423 std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000424
Douglas Gregor6ddfca92013-01-14 17:21:00 +0000425 /// \brief The complete set of modules that has been imported.
426 llvm::SetVector<clang::Module *> ImportedModules;
427
Manman Ren3b5dbf22016-10-14 18:55:44 +0000428 /// \brief The set of modules for which the module initializers
429 /// have been emitted.
430 llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
431
Reid Klecknere43f0fe2013-05-08 13:44:39 +0000432 /// \brief A vector of metadata strings.
Duncan P. N. Exon Smithfb494912014-12-09 18:39:32 +0000433 SmallVector<llvm::Metadata *, 16> LinkerOptionsMetadata;
Reid Klecknere43f0fe2013-05-08 13:44:39 +0000434
Douglas Gregorabf4e0d2011-08-09 15:54:21 +0000435 /// @name Cache for Objective-C runtime types
436 /// @{
437
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000438 /// Cached reference to the class for constant strings. This value has type
439 /// int * but is actually an Obj-C class pointer.
Fariborz Jahaniand1b67782013-04-16 15:25:39 +0000440 llvm::WeakVH CFConstantStringClassRef;
Mike Stump11289f42009-09-09 15:08:12 +0000441
Douglas Gregor636e2002011-08-09 17:23:49 +0000442 /// \brief The type used to describe the state of a fast enumeration in
443 /// Objective-C's for..in loop.
444 QualType ObjCFastEnumerationStateType;
445
Douglas Gregorabf4e0d2011-08-09 15:54:21 +0000446 /// @}
447
David Chisnall481e3a82010-01-23 02:40:42 +0000448 /// Lazily create the Objective-C runtime
449 void createObjCRuntime();
450
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000451 void createOpenCLRuntime();
Alexey Bataev9959db52014-05-06 10:08:46 +0000452 void createOpenMPRuntime();
Peter Collingbournefe883422011-10-06 18:29:37 +0000453 void createCUDARuntime();
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000454
Rafael Espindola4fdc1752011-12-19 14:41:01 +0000455 bool isTriviallyRecursive(const FunctionDecl *F);
Peter Collingbourne4d90dba2013-06-05 17:49:37 +0000456 bool shouldEmitFunction(GlobalDecl GD);
Daniel Dunbar900546d2010-07-16 00:00:15 +0000457
George Burgess IV1a39b862016-12-28 07:27:40 +0000458 /// Map used to be sure we don't emit the same CompoundLiteral twice.
459 llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *>
460 EmittedCompoundLiterals;
461
George Burgess IVe3763372016-12-22 02:50:20 +0000462 /// Map of the global blocks we've emitted, so that we don't have to re-emit
463 /// them if the constexpr evaluator gets aggressive.
464 llvm::DenseMap<const BlockExpr *, llvm::Constant *> EmittedGlobalBlocks;
465
Daniel Dunbar900546d2010-07-16 00:00:15 +0000466 /// @name Cache for Blocks Runtime Globals
467 /// @{
468
Reid Kleckner9305fd12016-04-13 23:37:17 +0000469 llvm::Constant *NSConcreteGlobalBlock = nullptr;
470 llvm::Constant *NSConcreteStackBlock = nullptr;
Daniel Dunbar3348e2d2010-07-16 00:00:19 +0000471
Reid Kleckner9305fd12016-04-13 23:37:17 +0000472 llvm::Constant *BlockObjectAssign = nullptr;
473 llvm::Constant *BlockObjectDispose = nullptr;
Daniel Dunbar900546d2010-07-16 00:00:15 +0000474
Reid Kleckner9305fd12016-04-13 23:37:17 +0000475 llvm::Type *BlockDescriptorType = nullptr;
476 llvm::Type *GenericBlockLiteralType = nullptr;
John McCallad7c5c12011-02-08 08:22:06 +0000477
478 struct {
479 int GlobalUniqueCount;
480 } Block;
Will Dietzf54319c2013-01-18 11:30:38 +0000481
Nadav Rotem1da30942013-03-23 06:43:35 +0000482 /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
Reid Kleckner9305fd12016-04-13 23:37:17 +0000483 llvm::Constant *LifetimeStartFn = nullptr;
Nadav Rotem1da30942013-03-23 06:43:35 +0000484
485 /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
Reid Kleckner9305fd12016-04-13 23:37:17 +0000486 llvm::Constant *LifetimeEndFn = nullptr;
Nadav Rotem1da30942013-03-23 06:43:35 +0000487
Fariborz Jahanian63628032012-06-26 16:06:38 +0000488 GlobalDecl initializedGlobalDecl;
John McCallad7c5c12011-02-08 08:22:06 +0000489
Alexey Samsonov4b8de112014-08-01 21:35:28 +0000490 std::unique_ptr<SanitizerMetadata> SanitizerMD;
491
Daniel Dunbar900546d2010-07-16 00:00:15 +0000492 /// @}
Alex Lorenzee024992014-08-04 18:41:51 +0000493
494 llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
495
496 std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
Peter Collingbourne25a80bf2015-09-08 23:01:30 +0000497
498 /// Mapping from canonical types to their metadata identifiers. We need to
499 /// maintain this mapping because identifiers may be formed from distinct
500 /// MDNodes.
501 llvm::DenseMap<QualType, llvm::Metadata *> MetadataIdMap;
502
Chris Lattnerf97fe382007-05-24 06:29:05 +0000503public:
Mehdi Aminica3cf9e2015-07-24 16:04:29 +0000504 CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts,
Adrian Prantle74f5252015-06-30 02:26:03 +0000505 const PreprocessorOptions &ppopts,
Mehdi Aminica3cf9e2015-07-24 16:04:29 +0000506 const CodeGenOptions &CodeGenOpts, llvm::Module &M,
Alex Lorenzee024992014-08-04 18:41:51 +0000507 DiagnosticsEngine &Diags,
508 CoverageSourceInfo *CoverageInfo = nullptr);
Ted Kremenek2c674f62008-08-05 18:50:11 +0000509
Chris Lattnera087ff92008-03-01 08:45:05 +0000510 ~CodeGenModule();
Mike Stump1676c5b2009-02-13 19:12:34 +0000511
Rafael Espindolac0ff7442013-12-09 14:59:08 +0000512 void clear();
513
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000514 /// Finalize LLVM code generation.
Ted Kremenek2c674f62008-08-05 18:50:11 +0000515 void Release();
Daniel Dunbar8d480592008-08-11 18:12:00 +0000516
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000517 /// Return a reference to the configured Objective-C runtime.
Mike Stump1676c5b2009-02-13 19:12:34 +0000518 CGObjCRuntime &getObjCRuntime() {
Peter Collingbournee1d20992011-07-27 20:29:46 +0000519 if (!ObjCRuntime) createObjCRuntime();
520 return *ObjCRuntime;
Daniel Dunbar8d480592008-08-11 18:12:00 +0000521 }
Mike Stump1676c5b2009-02-13 19:12:34 +0000522
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000523 /// Return true iff an Objective-C runtime has been configured.
Peter Collingbournee1d20992011-07-27 20:29:46 +0000524 bool hasObjCRuntime() { return !!ObjCRuntime; }
Daniel Dunbar8d480592008-08-11 18:12:00 +0000525
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000526 /// Return a reference to the configured OpenCL runtime.
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000527 CGOpenCLRuntime &getOpenCLRuntime() {
Craig Topper8a13c412014-05-21 05:09:00 +0000528 assert(OpenCLRuntime != nullptr);
Peter Collingbourne2dbb7082011-09-19 21:14:35 +0000529 return *OpenCLRuntime;
530 }
531
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000532 /// Return a reference to the configured OpenMP runtime.
Alexey Bataev9959db52014-05-06 10:08:46 +0000533 CGOpenMPRuntime &getOpenMPRuntime() {
534 assert(OpenMPRuntime != nullptr);
535 return *OpenMPRuntime;
536 }
537
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000538 /// Return a reference to the configured CUDA runtime.
Peter Collingbournefe883422011-10-06 18:29:37 +0000539 CGCUDARuntime &getCUDARuntime() {
Craig Topper8a13c412014-05-21 05:09:00 +0000540 assert(CUDARuntime != nullptr);
Peter Collingbournefe883422011-10-06 18:29:37 +0000541 return *CUDARuntime;
542 }
543
John McCallb04ecb72015-10-21 18:06:43 +0000544 ObjCEntrypoints &getObjCEntrypoints() const {
545 assert(ObjCData != nullptr);
546 return *ObjCData;
John McCall31168b02011-06-15 23:02:42 +0000547 }
548
Erik Pilkington9c42a8d2017-02-23 21:08:08 +0000549 // Version checking function, used to implement ObjC's @available:
550 // i32 @__isOSVersionAtLeast(i32, i32, i32)
551 llvm::Constant *IsOSVersionAtLeastFn = nullptr;
552
Justin Bogner837a6f62014-04-18 21:52:00 +0000553 InstrProfStats &getPGOStats() { return PGOStats; }
554 llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
Justin Bogneref512b92014-01-06 22:27:43 +0000555
Alex Lorenzee024992014-08-04 18:41:51 +0000556 CoverageMappingModuleGen *getCoverageMapping() const {
557 return CoverageMapping.get();
558 }
559
Eli Friedman1c8d2ca2012-03-09 03:27:46 +0000560 llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
561 return StaticLocalDeclMap[D];
Fariborz Jahanian3fef72f2010-04-18 21:01:23 +0000562 }
Fariborz Jahanian4d55b2d2010-04-19 18:15:02 +0000563 void setStaticLocalDeclAddress(const VarDecl *D,
Eli Friedman1c8d2ca2012-03-09 03:27:46 +0000564 llvm::Constant *C) {
565 StaticLocalDeclMap[D] = C;
Fariborz Jahanian3fef72f2010-04-18 21:01:23 +0000566 }
567
Reid Kleckner453e0562014-10-08 01:07:54 +0000568 llvm::Constant *
569 getOrCreateStaticVarDecl(const VarDecl &D,
570 llvm::GlobalValue::LinkageTypes Linkage);
571
John McCallb88a5662012-03-30 21:00:39 +0000572 llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
573 return StaticLocalDeclGuardMap[D];
574 }
575 void setStaticLocalDeclGuardAddress(const VarDecl *D,
576 llvm::GlobalVariable *C) {
577 StaticLocalDeclGuardMap[D] = C;
578 }
579
Alp Tokerfb8d02b2014-06-05 22:10:59 +0000580 bool lookupRepresentativeDecl(StringRef MangledName,
581 GlobalDecl &Result) const;
582
Fariborz Jahanian1bed4132012-01-08 19:13:23 +0000583 llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
584 return AtomicSetterHelperFnMap[Ty];
Fariborz Jahanian7ff610b2012-01-06 22:33:54 +0000585 }
Fariborz Jahanian1bed4132012-01-08 19:13:23 +0000586 void setAtomicSetterHelperFnMap(QualType Ty,
Fariborz Jahanian7ff610b2012-01-06 22:33:54 +0000587 llvm::Constant *Fn) {
Fariborz Jahanian1bed4132012-01-08 19:13:23 +0000588 AtomicSetterHelperFnMap[Ty] = Fn;
589 }
590
591 llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
592 return AtomicGetterHelperFnMap[Ty];
593 }
594 void setAtomicGetterHelperFnMap(QualType Ty,
595 llvm::Constant *Fn) {
596 AtomicGetterHelperFnMap[Ty] = Fn;
Fariborz Jahanian7ff610b2012-01-06 22:33:54 +0000597 }
598
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000599 llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
Will Dietz949ec542013-11-08 01:09:22 +0000600 return TypeDescriptorMap[Ty];
601 }
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000602 void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
Will Dietz949ec542013-11-08 01:09:22 +0000603 TypeDescriptorMap[Ty] = C;
604 }
605
Reid Kleckner9305fd12016-04-13 23:37:17 +0000606 CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); }
Devang Patele65982c2011-03-07 18:29:53 +0000607
Dan Gohman515a60d2012-02-16 00:57:37 +0000608 llvm::MDNode *getNoObjCARCExceptionsMetadata() {
609 if (!NoObjCARCExceptionsMetadata)
Duncan P. N. Exon Smithfb494912014-12-09 18:39:32 +0000610 NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None);
Dan Gohman515a60d2012-02-16 00:57:37 +0000611 return NoObjCARCExceptionsMetadata;
612 }
613
Chris Lattnerd1af2d22007-05-29 23:17:50 +0000614 ASTContext &getContext() const { return Context; }
David Blaikiebbafb8a2012-03-11 07:00:24 +0000615 const LangOptions &getLangOpts() const { return LangOpts; }
Adrian Prantle74f5252015-06-30 02:26:03 +0000616 const HeaderSearchOptions &getHeaderSearchOpts()
617 const { return HeaderSearchOpts; }
618 const PreprocessorOptions &getPreprocessorOpts()
619 const { return PreprocessorOpts; }
John McCallc8e01702013-04-16 22:48:15 +0000620 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
Chris Lattner23b7eb62007-06-15 23:05:46 +0000621 llvm::Module &getModule() const { return TheModule; }
David Blaikie9c902b52011-09-25 23:23:43 +0000622 DiagnosticsEngine &getDiags() const { return Diags; }
Mehdi Aminica3cf9e2015-07-24 16:04:29 +0000623 const llvm::DataLayout &getDataLayout() const {
624 return TheModule.getDataLayout();
625 }
John McCallc8e01702013-04-16 22:48:15 +0000626 const TargetInfo &getTarget() const { return Target; }
Saleem Abdulrasool7246dcc2016-09-14 15:17:46 +0000627 const llvm::Triple &getTriple() const { return Target.getTriple(); }
Rafael Espindola9f834732014-09-19 01:54:22 +0000628 bool supportsCOMDAT() const;
Rafael Espindoladbee8a72015-01-15 21:36:08 +0000629 void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
Rafael Espindola9f834732014-09-19 01:54:22 +0000630
Alp Toker82862252013-12-28 21:58:40 +0000631 CGCXXABI &getCXXABI() const { return *ABI; }
Owen Anderson170229f2009-07-14 23:10:40 +0000632 llvm::LLVMContext &getLLVMContext() { return VMContext; }
Craig Topper8a13c412014-05-21 05:09:00 +0000633
634 bool shouldUseTBAA() const { return TBAA != nullptr; }
John McCall53fcbd22011-02-26 08:07:02 +0000635
John McCallc8e01702013-04-16 22:48:15 +0000636 const TargetCodeGenInfo &getTargetCodeGenInfo();
637
638 CodeGenTypes &getTypes() { return Types; }
639
640 CodeGenVTables &getVTables() { return VTables; }
Timur Iskhodzhanov88fd4392013-08-21 06:25:03 +0000641
Timur Iskhodzhanov58776632013-11-05 15:54:58 +0000642 ItaniumVTableContext &getItaniumVTableContext() {
643 return VTables.getItaniumVTableContext();
Timur Iskhodzhanove1ebc5f2013-10-09 11:33:51 +0000644 }
John McCallc8e01702013-04-16 22:48:15 +0000645
Timur Iskhodzhanov58776632013-11-05 15:54:58 +0000646 MicrosoftVTableContext &getMicrosoftVTableContext() {
647 return VTables.getMicrosoftVTableContext();
Timur Iskhodzhanov88fd4392013-08-21 06:25:03 +0000648 }
649
Keno Fischer76f4ab02014-12-30 08:12:39 +0000650 CtorList &getGlobalCtors() { return GlobalCtors; }
651 CtorList &getGlobalDtors() { return GlobalDtors; }
652
Dan Gohman947c9af2010-10-14 23:06:10 +0000653 llvm::MDNode *getTBAAInfo(QualType QTy);
Kostya Serebryany141e46f2012-03-26 17:03:51 +0000654 llvm::MDNode *getTBAAInfoForVTablePtr();
Dan Gohman22695fc2012-09-28 21:58:29 +0000655 llvm::MDNode *getTBAAStructInfo(QualType QTy);
Manman Renc451e572013-04-04 21:53:22 +0000656 /// Return the path-aware tag for given base type, access node and offset.
657 llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
658 uint64_t O);
Dan Gohman947c9af2010-10-14 23:06:10 +0000659
Richard Smithe070fd22012-02-17 06:48:11 +0000660 bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
661
John McCalla8ec7eb2013-03-07 21:37:17 +0000662 bool isPaddedAtomicType(QualType type);
663 bool isPaddedAtomicType(const AtomicType *type);
664
Manman Rene1ad74e2013-04-11 23:02:56 +0000665 /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
666 /// is the same as the type. For struct-path aware TBAA, the tag
667 /// is different from the type: base type, access type and offset.
668 /// When ConvertTypeToTag is true, we create a tag based on the scalar type.
Piotr Padlewski4b1ac722015-09-15 21:46:55 +0000669 void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
670 llvm::MDNode *TBAAInfo,
671 bool ConvertTypeToTag = true);
672
673 /// Adds !invariant.barrier !tag to instruction
674 void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
675 const CXXRecordDecl *RD);
Dan Gohman947c9af2010-10-14 23:06:10 +0000676
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000677 /// Emit the given number of characters as a value of type size_t.
John McCall23c29fe2011-06-24 21:55:10 +0000678 llvm::ConstantInt *getSize(CharUnits numChars);
679
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000680 /// Set the visibility for the given LLVM GlobalValue.
Anders Carlssonc6a47892011-01-29 19:39:23 +0000681 void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
Daniel Dunbarf5f359f2009-04-14 06:00:08 +0000682
David Majnemerbb525f7c2014-10-15 22:38:23 +0000683 /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000684 /// variable declaration D.
David Majnemerbb525f7c2014-10-15 22:38:23 +0000685 void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
Hans Wennborgf60f6af2012-06-28 08:01:44 +0000686
Anders Carlsson537fdce2011-01-29 20:59:35 +0000687 static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
688 switch (V) {
689 case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
690 case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
691 case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
692 }
693 llvm_unreachable("unknown visibility!");
Anders Carlsson537fdce2011-01-29 20:59:35 +0000694 }
695
John McCalld195d4c2016-11-30 23:25:13 +0000696 llvm::Constant *GetAddrOfGlobal(GlobalDecl GD,
697 ForDefinition_t IsForDefinition
698 = NotForDefinition);
John McCalld4324142010-02-19 01:32:20 +0000699
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000700 /// Will return a global variable of the given type. If a variable with a
701 /// different type already exists then a new variable with the right type
702 /// will be created and all uses of the old variable will be replaced with a
703 /// bitcast to the new variable.
Anders Carlssonda80af32011-01-29 18:20:20 +0000704 llvm::GlobalVariable *
Chris Lattner01cf8db2011-07-20 06:58:45 +0000705 CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
Anders Carlssonda80af32011-01-29 18:20:20 +0000706 llvm::GlobalValue::LinkageTypes Linkage);
707
Alexey Samsonov1444bb92014-10-17 00:20:19 +0000708 llvm::Function *
709 CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name,
Akira Hatanaka7791f1a42015-10-31 01:28:07 +0000710 const CGFunctionInfo &FI,
Alexey Samsonov1444bb92014-10-17 00:20:19 +0000711 SourceLocation Loc = SourceLocation(),
712 bool TLS = false);
David Majnemerb3341ea2014-10-05 05:05:40 +0000713
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000714 /// Return the address space of the underlying global variable for D, as
715 /// determined by its declaration. Normally this is the same as the address
716 /// space of D's type, but in CUDA, address spaces are associated with
717 /// declarations, not types.
Peter Collingbournef44bdf92012-05-20 21:08:35 +0000718 unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace);
719
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000720 /// Return the llvm::Constant for the address of the given global variable.
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +0000721 /// If Ty is non-null and if the global doesn't exist, then it will be created
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000722 /// with the specified type instead of whatever the normal requested type
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +0000723 /// would be. If IsForDefinition is true, it is guranteed that an actual
724 /// global with type Ty will be returned, not conversion of a variable with
725 /// the same mangled name but some other type.
Chris Lattner149927c2009-03-21 09:16:30 +0000726 llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +0000727 llvm::Type *Ty = nullptr,
John McCalld195d4c2016-11-30 23:25:13 +0000728 ForDefinition_t IsForDefinition
729 = NotForDefinition);
Daniel Dunbar9c426522008-07-29 23:18:29 +0000730
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000731 /// Return the address of the given function. If Ty is non-null, then this
732 /// function will use the specified type if it has to create it.
Hans Wennborg59dbe862015-09-29 20:56:43 +0000733 llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
Rafael Espindola94abb8f2013-12-09 04:29:47 +0000734 bool ForVTable = false,
Andrey Bokhankocab58582015-08-31 13:20:44 +0000735 bool DontDefer = false,
John McCalld195d4c2016-11-30 23:25:13 +0000736 ForDefinition_t IsForDefinition
737 = NotForDefinition);
Daniel Dunbarc4baa062008-08-13 23:20:05 +0000738
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000739 /// Get the address of the RTTI descriptor for the given type.
John McCall48bf3492010-04-30 01:15:21 +0000740 llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
Anders Carlssonfd7dfeb2009-12-11 02:46:30 +0000741
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000742 /// Get the address of a uuid descriptor .
John McCall7f416cc2015-09-08 08:05:57 +0000743 ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
Nico Webercf4ff5862012-10-11 10:13:44 +0000744
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000745 /// Get the address of the thunk for the given global decl.
Anders Carlssonfe8a9932011-02-06 17:15:43 +0000746 llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
Anders Carlssoncd836f02010-03-23 17:17:29 +0000747
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000748 /// Get a reference to the target of VD.
John McCall7f416cc2015-09-08 08:05:57 +0000749 ConstantAddress GetWeakRefReference(const ValueDecl *VD);
750
751 /// Returns the assumed alignment of an opaque pointer to the given class.
752 CharUnits getClassPointerAlignment(const CXXRecordDecl *CD);
753
754 /// Returns the assumed alignment of a virtual base of a class.
755 CharUnits getVBaseAlignment(CharUnits DerivedAlign,
756 const CXXRecordDecl *Derived,
757 const CXXRecordDecl *VBase);
758
759 /// Given a class pointer with an actual known alignment, and the
760 /// expected alignment of an object at a dynamic offset w.r.t that
761 /// pointer, return the alignment to assume at the offset.
762 CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign,
763 const CXXRecordDecl *Class,
764 CharUnits ExpectedTargetAlign);
Rafael Espindola2e42fec2010-03-04 18:17:24 +0000765
David Majnemerc1709d32015-06-23 07:31:11 +0000766 CharUnits
767 computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass,
768 CastExpr::path_const_iterator Start,
769 CastExpr::path_const_iterator End);
770
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000771 /// Returns the offset from a derived class to a class. Returns null if the
772 /// offset is 0.
Anders Carlsson8a64c1c2010-04-24 21:23:59 +0000773 llvm::Constant *
774 GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
John McCallcf142162010-08-07 06:22:56 +0000775 CastExpr::path_const_iterator PathBegin,
776 CastExpr::path_const_iterator PathEnd);
John McCallad7c5c12011-02-08 08:22:06 +0000777
John McCall7f416cc2015-09-08 08:05:57 +0000778 llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
John McCallad7c5c12011-02-08 08:22:06 +0000779
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000780 /// Fetches the global unique block count.
John McCall147d0212011-02-22 22:38:33 +0000781 int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
Fariborz Jahanian63628032012-06-26 16:06:38 +0000782
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000783 /// Fetches the type of a generic block descriptor.
Chris Lattnera5f58b02011-07-09 17:41:47 +0000784 llvm::Type *getBlockDescriptorType();
John McCallad7c5c12011-02-08 08:22:06 +0000785
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000786 /// The type of a generic block literal.
Chris Lattnera5f58b02011-07-09 17:41:47 +0000787 llvm::Type *getGenericBlockLiteralType();
John McCallad7c5c12011-02-08 08:22:06 +0000788
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000789 /// Gets the address of a block which requires no captures.
George Burgess IV70d15b32016-11-03 02:21:43 +0000790 llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name);
George Burgess IVe3763372016-12-22 02:50:20 +0000791
792 /// Returns the address of a block which requires no caputres, or null if
793 /// we've yet to emit the block for BE.
794 llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) {
795 return EmittedGlobalBlocks.lookup(BE);
796 }
797
798 /// Notes that BE's global block is available via Addr. Asserts that BE
799 /// isn't already emitted.
800 void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
Anders Carlsson8a64c1c2010-04-24 21:23:59 +0000801
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000802 /// Return a pointer to a constant CFString object for the given string.
John McCall7f416cc2015-09-08 08:05:57 +0000803 ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal);
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000804
805 /// Return a pointer to a constant NSString object for the given string. Or a
806 /// user defined String object as defined via
Fariborz Jahanian50c925f2010-10-19 17:19:29 +0000807 /// -fconstant-string-class=class_name option.
John McCall7f416cc2015-09-08 08:05:57 +0000808 ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal);
Chris Lattner36fc8792008-02-11 00:02:17 +0000809
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000810 /// Return a constant array for the given string.
Eli Friedmanfcec6302011-11-01 02:23:42 +0000811 llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
812
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000813 /// Return a pointer to a constant array for the given string literal.
John McCall7f416cc2015-09-08 08:05:57 +0000814 ConstantAddress
Alexey Bataevec474782014-10-09 08:45:04 +0000815 GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
816 StringRef Name = ".str");
Daniel Dunbar6dfdf8c2008-08-10 20:25:57 +0000817
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000818 /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
John McCall7f416cc2015-09-08 08:05:57 +0000819 ConstantAddress
Alexey Samsonovb2cc23d2014-07-10 22:18:36 +0000820 GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
Mike Stump11289f42009-09-09 15:08:12 +0000821
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000822 /// Returns a pointer to a character array containing the literal and a
823 /// terminating '\0' character. The result has pointer to array type.
Daniel Dunbardfcf5992008-10-17 21:56:50 +0000824 ///
Mike Stump1676c5b2009-02-13 19:12:34 +0000825 /// \param GlobalName If provided, the name to use for the global (if one is
826 /// created).
John McCall7f416cc2015-09-08 08:05:57 +0000827 ConstantAddress
Alexey Samsonovb2cc23d2014-07-10 22:18:36 +0000828 GetAddrOfConstantCString(const std::string &Str,
John McCall7f416cc2015-09-08 08:05:57 +0000829 const char *GlobalName = nullptr);
Richard Smith2d988f02011-11-22 22:48:32 +0000830
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000831 /// Returns a pointer to a constant global variable for the given file-scope
832 /// compound literal expression.
John McCall7f416cc2015-09-08 08:05:57 +0000833 ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
Richard Smithe6c01442013-06-05 00:46:14 +0000834
George Burgess IV1a39b862016-12-28 07:27:40 +0000835 /// If it's been emitted already, returns the GlobalVariable corresponding to
836 /// a compound literal. Otherwise, returns null.
837 llvm::GlobalVariable *
838 getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E);
839
840 /// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already
841 /// emitted.
842 void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE,
843 llvm::GlobalVariable *GV);
844
Richard Smithe6c01442013-06-05 00:46:14 +0000845 /// \brief Returns a pointer to a global variable representing a temporary
846 /// with static or thread storage duration.
John McCall7f416cc2015-09-08 08:05:57 +0000847 ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
Richard Smithe6c01442013-06-05 00:46:14 +0000848 const Expr *Inner);
849
Douglas Gregor636e2002011-08-09 17:23:49 +0000850 /// \brief Retrieve the record type that describes the state of an
851 /// Objective-C fast enumeration loop (for..in).
852 QualType getObjCFastEnumerationStateType();
Rafael Espindola8d2a19b2014-09-08 16:01:27 +0000853
Rafael Espindola53686182014-09-15 19:34:18 +0000854 // Produce code for this constructor/destructor. This method doesn't try
855 // to apply any ABI rules about which other constructors/destructors
856 // are needed or if they are alias to each other.
857 llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
858 StructorType Type);
859
Rafael Espindola1ac0ec82014-09-11 15:42:06 +0000860 /// Return the address of the constructor/destructor of the given type.
Andrey Bokhankocab58582015-08-31 13:20:44 +0000861 llvm::Constant *
Rafael Espindola8d2a19b2014-09-08 16:01:27 +0000862 getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type,
863 const CGFunctionInfo *FnInfo = nullptr,
864 llvm::FunctionType *FnType = nullptr,
John McCalld195d4c2016-11-30 23:25:13 +0000865 bool DontDefer = false,
866 ForDefinition_t IsForDefinition = NotForDefinition);
Rafael Espindola8d2a19b2014-09-08 16:01:27 +0000867
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000868 /// Given a builtin id for a function like "__builtin_fabsf", return a
869 /// Function* for "fabsf".
John McCallb92ab1a2016-10-26 23:46:34 +0000870 llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
871 unsigned BuiltinID);
Daniel Dunbarc4baa062008-08-13 23:20:05 +0000872
Dmitri Gribenko44ebbd52013-05-05 00:41:58 +0000873 llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
Daniel Dunbar9c426522008-07-29 23:18:29 +0000874
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000875 /// Emit code for a single top level declaration.
Daniel Dunbarfce4be82008-08-15 23:26:23 +0000876 void EmitTopLevelDecl(Decl *D);
Daniel Dunbar9c426522008-07-29 23:18:29 +0000877
Alex Lorenzee024992014-08-04 18:41:51 +0000878 /// \brief Stored a deferred empty coverage mapping for an unused
879 /// and thus uninstrumented top level declaration.
880 void AddDeferredUnusedCoverageMapping(Decl *D);
881
882 /// \brief Remove the deferred empty coverage mapping as this
883 /// declaration is actually instrumented.
884 void ClearUnusedCoverageMapping(const Decl *D);
885
886 /// \brief Emit all the deferred coverage mappings
887 /// for the uninstrumented functions.
888 void EmitDeferredUnusedCoverageMappings();
889
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000890 /// Tell the consumer that this variable has been instantiated.
Rafael Espindoladf88f6f2012-03-08 15:51:03 +0000891 void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
Rafael Espindola189fa742012-03-05 10:54:55 +0000892
Richard Smithdf931ce2013-04-06 05:00:46 +0000893 /// \brief If the declaration has internal linkage but is inside an
894 /// extern "C" linkage specification, prepare to emit an alias for it
895 /// to the expected name.
896 template<typename SomeDecl>
897 void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
898
Rafael Espindola060062a2014-03-06 22:15:10 +0000899 /// Add a global to a list to be added to the llvm.used metadata.
900 void addUsedGlobal(llvm::GlobalValue *GV);
901
902 /// Add a global to a list to be added to the llvm.compiler.used metadata.
903 void addCompilerUsedGlobal(llvm::GlobalValue *GV);
Daniel Dunbar08b26a02009-02-13 20:29:50 +0000904
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000905 /// Add a destructor and object to add to the C++ global destructor function.
Chris Lattner87233f72010-06-19 05:52:45 +0000906 void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
Benjamin Kramer3204b152015-05-29 19:42:19 +0000907 CXXGlobalDtors.emplace_back(DtorFn, Object);
Chris Lattner87233f72010-06-19 05:52:45 +0000908 }
Daniel Dunbarfe06df42010-03-20 04:15:41 +0000909
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000910 /// Create a new runtime function with the specified type and name.
Saleem Abdulrasool6cb07442016-12-15 06:59:05 +0000911 llvm::Constant *
912 CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name,
Reid Klecknerde864822017-03-21 16:57:30 +0000913 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
Saleem Abdulrasool6cb07442016-12-15 06:59:05 +0000914 bool Local = false);
915
Anton Korobeynikovd90dd792014-12-02 16:04:58 +0000916 /// Create a new compiler builtin function with the specified type and name.
Reid Klecknerde864822017-03-21 16:57:30 +0000917 llvm::Constant *
918 CreateBuiltinFunction(llvm::FunctionType *Ty, StringRef Name,
919 llvm::AttributeList ExtraAttrs = llvm::AttributeList());
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000920 /// Create a new runtime global variable with the specified type and name.
Chris Lattner2192fe52011-07-18 04:24:23 +0000921 llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000922 StringRef Name);
Daniel Dunbar23fd4622008-10-01 00:49:24 +0000923
Daniel Dunbar900546d2010-07-16 00:00:15 +0000924 ///@name Custom Blocks Runtime Interfaces
925 ///@{
926
927 llvm::Constant *getNSConcreteGlobalBlock();
928 llvm::Constant *getNSConcreteStackBlock();
929 llvm::Constant *getBlockObjectAssign();
930 llvm::Constant *getBlockObjectDispose();
931
932 ///@}
933
Nadav Rotem1da30942013-03-23 06:43:35 +0000934 llvm::Constant *getLLVMLifetimeStartFn();
935 llvm::Constant *getLLVMLifetimeEndFn();
936
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000937 // Make sure that this type is translated.
Devang Patel945b8ae2011-03-23 16:29:39 +0000938 void UpdateCompletedType(const TagDecl *TD);
Daniel Dunbar38ad1e62009-02-17 18:43:32 +0000939
John McCallf3a88602011-02-03 08:15:49 +0000940 llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
941
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000942 /// Try to emit the initializer for the given declaration as a constant;
943 /// returns 0 if the expression cannot be emitted as a constant.
Craig Topper8a13c412014-05-21 05:09:00 +0000944 llvm::Constant *EmitConstantInit(const VarDecl &D,
945 CodeGenFunction *CGF = nullptr);
Richard Smithdafff942012-01-14 04:30:29 +0000946
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000947 /// Try to emit the given expression as a constant; returns 0 if the
948 /// expression cannot be emitted as a constant.
Anders Carlsson80f97ab2009-04-08 04:48:15 +0000949 llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
Craig Topper8a13c412014-05-21 05:09:00 +0000950 CodeGenFunction *CGF = nullptr);
Daniel Dunbar38ad1e62009-02-17 18:43:32 +0000951
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000952 /// Emit the given constant value as a constant, in the type's scalar
953 /// representation.
Richard Smithdafff942012-01-14 04:30:29 +0000954 llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
Craig Topper8a13c412014-05-21 05:09:00 +0000955 CodeGenFunction *CGF = nullptr);
Richard Smithdafff942012-01-14 04:30:29 +0000956
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000957 /// Emit the given constant value as a constant, in the type's memory
958 /// representation.
Richard Smithbc6387672012-03-02 23:27:11 +0000959 llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
960 QualType DestType,
Craig Topper8a13c412014-05-21 05:09:00 +0000961 CodeGenFunction *CGF = nullptr);
Richard Smithbc6387672012-03-02 23:27:11 +0000962
Alexey Bataev2bf9b4c2015-10-20 04:24:12 +0000963 /// \brief Emit type info if type of an expression is a variably modified
964 /// type. Also emit proper debug info for cast types.
965 void EmitExplicitCastExprType(const ExplicitCastExpr *E,
966 CodeGenFunction *CGF = nullptr);
967
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000968 /// Return the result of value-initializing the given type, i.e. a null
969 /// expression of the given type. This is usually, but not always, an LLVM
970 /// null constant.
Eli Friedman20bb5e02009-04-13 21:47:26 +0000971 llvm::Constant *EmitNullConstant(QualType T);
972
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000973 /// Return a null constant appropriate for zero-initializing a base class with
974 /// the given type. This is usually, but not always, an LLVM null constant.
Eli Friedmanfde961d2011-10-14 02:27:24 +0000975 llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
976
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000977 /// Emit a general error that something can't be done.
Chandler Carruth84537952012-03-30 19:44:53 +0000978 void Error(SourceLocation loc, StringRef error);
John McCall7ef5cb32011-03-18 02:56:14 +0000979
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000980 /// Print out an error that codegen doesn't support the specified stmt yet.
David Blaikie4a9ec7b2013-08-19 21:02:26 +0000981 void ErrorUnsupported(const Stmt *S, const char *Type);
Mike Stump1676c5b2009-02-13 19:12:34 +0000982
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000983 /// Print out an error that codegen doesn't support the specified decl yet.
David Blaikie4a9ec7b2013-08-19 21:02:26 +0000984 void ErrorUnsupported(const Decl *D, const char *Type);
Dan Gohman75d69da2008-05-22 00:50:06 +0000985
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000986 /// Set the attributes on the LLVM function for the given decl and function
987 /// info. This applies attributes necessary for handling the ABI as well as
988 /// user specified attributes like section.
Daniel Dunbarc3e7cff2009-04-17 00:48:04 +0000989 void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
990 const CGFunctionInfo &FI);
Daniel Dunbar449a3392008-09-04 23:41:35 +0000991
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000992 /// Set the LLVM function attributes (sext, zext, etc).
Daniel Dunbaraeddffc2009-04-14 07:08:30 +0000993 void SetLLVMFunctionAttributes(const Decl *D,
994 const CGFunctionInfo &Info,
995 llvm::Function *F);
Daniel Dunbarc68897d2008-09-10 00:41:16 +0000996
Rafael Espindolae98ed2f2014-05-09 01:34:38 +0000997 /// Set the LLVM function attributes which only apply to a function
James Dennett64fa1232014-08-15 20:04:40 +0000998 /// definition.
Daniel Dunbar38932572009-04-14 08:05:55 +0000999 void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
1000
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001001 /// Return true iff the given type uses 'sret' when used as a return type.
Daniel Dunbar6f2e8392010-07-14 23:39:36 +00001002 bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
1003
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001004 /// Return true iff the given type uses an argument slot when 'sret' is used
1005 /// as a return type.
Tim Northovere77cc392014-03-29 13:28:05 +00001006 bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
1007
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001008 /// Return true iff the given type uses 'fpret' when used as a return type.
Daniel Dunbar6f2e8392010-07-14 23:39:36 +00001009 bool ReturnTypeUsesFPRet(QualType ResultType);
Daniel Dunbarc68897d2008-09-10 00:41:16 +00001010
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001011 /// Return true iff the given type uses 'fp2ret' when used as a return type.
Anders Carlsson2f1a6c32011-10-31 16:27:11 +00001012 bool ReturnTypeUsesFP2Ret(QualType ResultType);
1013
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001014 /// Get the LLVM attributes and calling convention to use for a particular
1015 /// function type.
Daniel Dunbar0ef34792009-09-12 00:59:20 +00001016 ///
Chad Rosier7dbc9cf2016-01-06 14:35:46 +00001017 /// \param Name - The function name.
Daniel Dunbar0ef34792009-09-12 00:59:20 +00001018 /// \param Info - The function type information.
Samuel Antao798f11c2015-11-23 22:04:44 +00001019 /// \param CalleeInfo - The callee information these attributes are being
1020 /// constructed for. If valid, the attributes applied to this decl may
1021 /// contribute to the function attributes and calling convention.
Daniel Dunbar0ef34792009-09-12 00:59:20 +00001022 /// \param PAL [out] - On return, the attribute list to use.
1023 /// \param CallingConv [out] - On return, the LLVM calling convention to use.
Chad Rosier7dbc9cf2016-01-06 14:35:46 +00001024 void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
Samuel Antao798f11c2015-11-23 22:04:44 +00001025 CGCalleeInfo CalleeInfo, AttributeListType &PAL,
1026 unsigned &CallingConv, bool AttrOnCallSite);
Daniel Dunbarc68897d2008-09-10 00:41:16 +00001027
Justin Lebarb080b632017-01-25 21:29:48 +00001028 /// Adds attributes to F according to our CodeGenOptions and LangOptions, as
1029 /// though we had emitted it ourselves. We remove any attributes on F that
1030 /// conflict with the attributes we add here.
1031 ///
1032 /// This is useful for adding attrs to bitcode modules that you want to link
1033 /// with but don't control, such as CUDA's libdevice. When linking with such
1034 /// a bitcode library, you might want to set e.g. its functions'
1035 /// "unsafe-fp-math" attribute to match the attr of the functions you're
1036 /// codegen'ing. Otherwise, LLVM will interpret the bitcode module's lack of
1037 /// unsafe-fp-math attrs as tantamount to unsafe-fp-math=false, and then LLVM
1038 /// will propagate unsafe-fp-math=false up to every transitive caller of a
1039 /// function in the bitcode library!
1040 ///
1041 /// With the exception of fast-math attrs, this will only make the attributes
1042 /// on the function more conservative. But it's unsafe to call this on a
1043 /// function which relies on particular fast-math attributes for correctness.
1044 /// It's up to you to ensure that this is safe.
1045 void AddDefaultFnAttrs(llvm::Function &F);
1046
Eric Christopher2b90a642015-11-11 23:05:08 +00001047 // Fills in the supplied string map with the set of target features for the
1048 // passed in function.
1049 void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
1050 const FunctionDecl *FD);
1051
Chris Lattner01cf8db2011-07-20 06:58:45 +00001052 StringRef getMangledName(GlobalDecl GD);
Alp Tokerfb8d02b2014-06-05 22:10:59 +00001053 StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
Douglas Gregorbeecd582009-04-21 17:11:58 +00001054
1055 void EmitTentativeDefinition(const VarDecl *D);
Mike Stumpbc78a722009-07-31 18:25:34 +00001056
Nico Weberb6a5d052015-01-15 04:07:35 +00001057 void EmitVTable(CXXRecordDecl *Class);
Douglas Gregor88d292c2010-05-13 16:44:06 +00001058
David Majnemer929025d2016-01-26 19:30:26 +00001059 void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
1060
Reid Klecknere43f0fe2013-05-08 13:44:39 +00001061 /// \brief Appends Opts to the "Linker Options" metadata value.
1062 void AppendLinkerOptions(StringRef Opts);
1063
Benjamin Kramer82dfc972013-06-04 09:13:21 +00001064 /// \brief Appends a detect mismatch command to the linker options.
Aaron Ballman5d041be2013-06-04 02:07:14 +00001065 void AddDetectMismatch(StringRef Name, StringRef Value);
1066
Reid Klecknere43f0fe2013-05-08 13:44:39 +00001067 /// \brief Appends a dependent lib to the "Linker Options" metadata value.
1068 void AddDependentLib(StringRef Lib);
1069
Peter Collingbourne4d90dba2013-06-05 17:49:37 +00001070 llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
John McCalld4324142010-02-19 01:32:20 +00001071
Rafael Espindola64926362014-05-08 14:46:46 +00001072 void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
1073 F->setLinkage(getFunctionLinkage(GD));
John McCall7cb02202010-05-25 04:30:21 +00001074 }
1075
Hans Wennborgbb4f9622015-05-28 17:44:56 +00001076 /// Set the DLL storage class on F.
1077 void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F);
1078
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001079 /// Return the appropriate linkage for the vtable, VTT, and type information
1080 /// of the given class.
Anders Carlsson68d34242011-01-24 02:04:33 +00001081 llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
Ken Dyck98ca7942010-01-26 13:48:07 +00001082
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001083 /// Return the store size, in character units, of the given LLVM type.
Chris Lattner2192fe52011-07-18 04:24:23 +00001084 CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
Fariborz Jahanian1518a5ec2010-10-27 16:21:54 +00001085
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001086 /// Returns LLVM linkage for a declarator.
David Majnemer27d69db2014-04-28 22:17:59 +00001087 llvm::GlobalValue::LinkageTypes
Hans Wennborg1a3a0742014-05-14 19:54:53 +00001088 getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
Hans Wennborg275efb92014-05-28 01:52:23 +00001089 bool IsConstantVariable);
David Majnemer27d69db2014-04-28 22:17:59 +00001090
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001091 /// Returns LLVM linkage for a declarator.
David Majnemer27d69db2014-04-28 22:17:59 +00001092 llvm::GlobalValue::LinkageTypes
1093 getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
1094
Julien Lerouge5a6b6982011-09-09 22:41:49 +00001095 /// Emit all the global annotations.
1096 void EmitGlobalAnnotations();
1097
1098 /// Emit an annotation string.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00001099 llvm::Constant *EmitAnnotationString(StringRef Str);
Julien Lerouge5a6b6982011-09-09 22:41:49 +00001100
1101 /// Emit the annotation's translation unit.
1102 llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
1103
1104 /// Emit the annotation line number.
1105 llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
1106
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001107 /// Generate the llvm::ConstantStruct which contains the annotation
1108 /// information for a given GlobalValue. The annotation struct is
Julien Lerouge5a6b6982011-09-09 22:41:49 +00001109 /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
1110 /// GlobalValue being annotated. The second field is the constant string
1111 /// created from the AnnotateAttr's annotation. The third field is a constant
1112 /// string containing the name of the translation unit. The fourth field is
1113 /// the line number in the file of the annotated value declaration.
1114 llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
1115 const AnnotateAttr *AA,
1116 SourceLocation L);
1117
1118 /// Add global annotations that are set on D, for the global GV. Those
1119 /// annotations are emitted during finalization of the LLVM code.
1120 void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
1121
Alexey Samsonov1444bb92014-10-17 00:20:19 +00001122 bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const;
Will Dietzf54319c2013-01-18 11:30:38 +00001123
Alexey Samsonova0ac3c22014-10-17 22:37:33 +00001124 bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
1125 QualType Ty,
1126 StringRef Category = StringRef()) const;
1127
Alexey Samsonov4b8de112014-08-01 21:35:28 +00001128 SanitizerMetadata *getSanitizerMetadata() {
1129 return SanitizerMD.get();
1130 }
Alexey Samsonov4f319cc2014-07-02 16:54:41 +00001131
John McCall6bd2a892013-01-25 22:31:03 +00001132 void addDeferredVTable(const CXXRecordDecl *RD) {
1133 DeferredVTables.push_back(RD);
1134 }
1135
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001136 /// Emit code for a singal global function or var decl. Forward declarations
1137 /// are emitted lazily.
Reid Klecknere7de47e2013-07-22 13:51:44 +00001138 void EmitGlobal(GlobalDecl D);
1139
Rafael Espindola02b77f42014-09-15 18:46:13 +00001140 bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
1141 bool InEveryTU);
1142 bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
1143
1144 /// Set attributes for a global definition.
1145 void setFunctionDefinitionAttributes(const FunctionDecl *D,
1146 llvm::Function *F);
1147
Chris Lattner01cf8db2011-07-20 06:58:45 +00001148 llvm::GlobalValue *GetGlobalValue(StringRef Ref);
Mike Stump11289f42009-09-09 15:08:12 +00001149
Rafael Espindola1e4df922014-09-16 15:18:21 +00001150 /// Set attributes which are common to any form of a global definition (alias,
1151 /// Objective-C method, function, global variable).
1152 ///
1153 /// NOTE: This should only be called for definitions.
1154 void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
1155
Dario Domiziolic4fb8ca72014-09-19 22:06:24 +00001156 /// Set attributes which must be preserved by an alias. This includes common
1157 /// attributes (i.e. it includes a call to SetCommonAttributes).
1158 ///
1159 /// NOTE: This should only be called for definitions.
1160 void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
1161
Rafael Espindola1e4df922014-09-16 15:18:21 +00001162 void addReplacement(StringRef Name, llvm::Constant *C);
Alexey Bataev97720002014-11-11 04:05:39 +00001163
Andrey Bokhankocab58582015-08-31 13:20:44 +00001164 void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
1165
Alexey Bataev97720002014-11-11 04:05:39 +00001166 /// \brief Emit a code for threadprivate directive.
1167 /// \param D Threadprivate declaration.
1168 void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
1169
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001170 /// \brief Emit a code for declare reduction construct.
Alexey Bataevc5b1d322016-03-04 09:22:22 +00001171 void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D,
1172 CodeGenFunction *CGF = nullptr);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001173
Peter Collingbourne3afb2662016-04-28 17:09:37 +00001174 /// Returns whether the given record has hidden LTO visibility and therefore
1175 /// may participate in (single-module) CFI and whole-program vtable
1176 /// optimization.
1177 bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
Peter Collingbournee5706442015-07-09 19:56:14 +00001178
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001179 /// Emit type metadata for the given vtable using the given layout.
1180 void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
1181 const VTableLayout &VTLayout);
Peter Collingbournea4ccff32015-02-20 20:30:56 +00001182
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001183 /// Generate a cross-DSO type identifier for MD.
1184 llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD);
Evgeniy Stepanovfd6f92d2015-12-15 23:00:20 +00001185
Peter Collingbourne25a80bf2015-09-08 23:01:30 +00001186 /// Create a metadata identifier for the given type. This may either be an
1187 /// MDString (for external identifiers) or a distinct unnamed MDNode (for
1188 /// internal identifiers).
1189 llvm::Metadata *CreateMetadataIdentifierForType(QualType T);
1190
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001191 /// Create and attach type metadata to the given function.
1192 void CreateFunctionTypeMetadata(const FunctionDecl *FD, llvm::Function *F);
Evgeniy Stepanovfd6f92d2015-12-15 23:00:20 +00001193
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001194 /// Returns whether this module needs the "all-vtables" type identifier.
1195 bool NeedAllVtablesTypeId() const;
Evgeniy Stepanovf31ea302016-02-03 22:18:55 +00001196
Peter Collingbourne8dd14da2016-06-24 21:21:46 +00001197 /// Create and attach type metadata for the given vtable.
1198 void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset,
1199 const CXXRecordDecl *RD);
Peter Collingbourne86d34a72015-06-17 19:08:05 +00001200
Reid Klecknerfff8e7f2015-03-03 19:21:04 +00001201 /// \breif Get the declaration of std::terminate for the platform.
1202 llvm::Constant *getTerminateFn();
1203
Peter Collingbournedc134532016-01-16 00:31:22 +00001204 llvm::SanitizerStatReport &getSanStats();
1205
Yaxun Liu0bc4b2d2016-07-28 19:26:30 +00001206 llvm::Value *
1207 createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF);
1208
Yaxun Liu402804b2016-12-15 08:09:08 +00001209 /// Get target specific null pointer.
1210 /// \param T is the LLVM type of the null pointer.
1211 /// \param QT is the clang QualType of the null pointer.
1212 llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT);
1213
Rafael Espindola1e4df922014-09-16 15:18:21 +00001214private:
Reid Klecknerde864822017-03-21 16:57:30 +00001215 llvm::Constant *GetOrCreateLLVMFunction(
1216 StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
1217 bool DontDefer = false, bool IsThunk = false,
1218 llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1219 ForDefinition_t IsForDefinition = NotForDefinition);
Rafael Espindola94abb8f2013-12-09 04:29:47 +00001220
Chris Lattner01cf8db2011-07-20 06:58:45 +00001221 llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
Chris Lattner2192fe52011-07-18 04:24:23 +00001222 llvm::PointerType *PTy,
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +00001223 const VarDecl *D,
John McCalld195d4c2016-11-30 23:25:13 +00001224 ForDefinition_t IsForDefinition
1225 = NotForDefinition);
Mike Stump11289f42009-09-09 15:08:12 +00001226
Rafael Espindolaee076a22014-05-13 18:45:53 +00001227 void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
Rafael Espindola502f65a2014-05-05 20:21:03 +00001228
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001229 /// Set function attributes for a function declaration.
David Majnemerb9bd6fb2014-11-01 05:42:23 +00001230 void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
1231 bool IsIncompleteFunction, bool IsThunk);
Nuno Lopesb6f79532008-06-08 15:45:52 +00001232
Craig Topper8a13c412014-05-21 05:09:00 +00001233 void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
Daniel Dunbarf0acf7b2009-02-19 07:15:39 +00001234
Rafael Espindolacd7743b2013-12-09 16:01:03 +00001235 void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
Andrey Bokhanko7aa88ce2016-01-14 10:41:16 +00001236 void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
John McCall7ec50432010-03-19 23:29:14 +00001237 void EmitAliasDefinition(GlobalDecl GD);
Dmitry Polukhin85eda122016-04-11 07:48:59 +00001238 void emitIFuncDefinition(GlobalDecl GD);
Daniel Dunbar89654ee2008-08-26 08:29:31 +00001239 void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
Fariborz Jahanian0dec1e02010-04-28 21:28:56 +00001240 void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
Fariborz Jahanian1518a5ec2010-10-27 16:21:54 +00001241
Anders Carlssonf7475242009-04-15 15:55:24 +00001242 // C++ related functions.
Mike Stump11289f42009-09-09 15:08:12 +00001243
Richard Smith8df390f2016-09-08 23:14:54 +00001244 void EmitDeclContext(const DeclContext *DC);
Anders Carlssoncbaeb9e2009-04-02 05:55:18 +00001245 void EmitLinkageSpec(const LinkageSpecDecl *D);
Anders Carlssonf7475242009-04-15 15:55:24 +00001246
Richard Smith2fd1d7a2013-04-19 16:42:07 +00001247 /// \brief Emit the function that initializes C++ thread_local variables.
1248 void EmitCXXThreadLocalInitFunc();
1249
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001250 /// Emit the function that initializes C++ globals.
Anders Carlssonb8be93f2009-08-08 23:24:23 +00001251 void EmitCXXGlobalInitFunc();
Eli Friedman5866fe32010-01-08 00:50:11 +00001252
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001253 /// Emit the function that destroys C++ globals.
Daniel Dunbarfe06df42010-03-20 04:15:41 +00001254 void EmitCXXGlobalDtorFunc();
1255
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001256 /// Emit the function that initializes the specified global (if PerformInit is
1257 /// true) and registers its destructor.
John McCallcdf7ef52010-11-06 09:44:32 +00001258 void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
Richard Smith6331c402012-02-13 22:16:19 +00001259 llvm::GlobalVariable *Addr,
1260 bool PerformInit);
Eli Friedman5866fe32010-01-08 00:50:11 +00001261
Reid Kleckner1a711b12014-07-22 00:53:05 +00001262 void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
1263 llvm::Function *InitFunc, InitSegAttr *ISA);
1264
Daniel Dunbar74aa7e12008-08-01 00:01:51 +00001265 // FIXME: Hardcoding priority here is gross.
Reid Kleckner563f0e82014-05-23 21:13:45 +00001266 void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
Hans Wennborg59dbe862015-09-29 20:56:43 +00001267 llvm::Constant *AssociatedData = nullptr);
Reid Kleckner563f0e82014-05-23 21:13:45 +00001268 void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
Daniel Dunbar9c426522008-07-29 23:18:29 +00001269
Vassil Vassilev188ad3a2016-10-27 09:12:20 +00001270 /// EmitCtorList - Generates a global array of functions and priorities using
1271 /// the given list and name. This array will have appending linkage and is
1272 /// suitable for use as a LLVM constructor or destructor array. Clears Fns.
1273 void EmitCtorList(CtorList &Fns, const char *GlobalName);
Daniel Dunbar74aa7e12008-08-01 00:01:51 +00001274
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001275 /// Emit any needed decls for which code generation was deferred.
Dmitri Gribenkob2aa9232012-11-15 14:28:07 +00001276 void EmitDeferred();
Daniel Dunbar08b26a02009-02-13 20:29:50 +00001277
Rafael Espindola2e2995b2013-11-05 21:37:29 +00001278 /// Call replaceAllUsesWith on all pairs in Replacements.
1279 void applyReplacements();
1280
Andrey Bokhankocab58582015-08-31 13:20:44 +00001281 /// Call replaceAllUsesWith on all pairs in GlobalValReplacements.
1282 void applyGlobalValReplacements();
1283
Rafael Espindola208b5c02013-10-22 19:26:13 +00001284 void checkAliases();
1285
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001286 /// Emit any vtables which we deferred and still have a use for.
John McCall6bd2a892013-01-25 22:31:03 +00001287 void EmitDeferredVTables();
1288
Rafael Espindola060062a2014-03-06 22:15:10 +00001289 /// Emit the llvm.used and llvm.compiler.used metadata.
1290 void emitLLVMUsed();
Daniel Dunbar23fd4622008-10-01 00:49:24 +00001291
Douglas Gregorbc25ff42013-01-14 20:53:57 +00001292 /// \brief Emit the link options introduced by imported modules.
1293 void EmitModuleLinkOptions();
1294
Richard Smithdf931ce2013-04-06 05:00:46 +00001295 /// \brief Emit aliases for internal-linkage declarations inside "C" language
1296 /// linkage specifications, giving them the "expected" name where possible.
1297 void EmitStaticExternCAliases();
1298
John McCall09ae0322010-07-06 23:57:41 +00001299 void EmitDeclMetadata();
1300
Rafael Espindola3bfa4682013-10-16 19:28:50 +00001301 /// \brief Emit the Clang version as llvm.ident metadata.
1302 void EmitVersionIdentMetadata();
1303
Robert Lytton57765d52014-07-03 09:30:33 +00001304 /// Emits target specific Metadata for global declarations.
1305 void EmitTargetMetadata();
1306
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001307 /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
1308 /// .gcda files in a way that persists in .bc files.
Nick Lewycky85c011d2011-05-05 00:08:20 +00001309 void EmitCoverageFile();
Nick Lewycky480cb992011-05-04 20:46:58 +00001310
Nico Webercf4ff5862012-10-11 10:13:44 +00001311 /// Emits the initializer for a uuidof string.
Nico Weber17d3a2c2014-09-08 16:26:36 +00001312 llvm::Constant *EmitUuidofInitializer(StringRef uuidstr);
Nico Webercf4ff5862012-10-11 10:13:44 +00001313
Hans Wennborg43a0f992015-01-10 01:19:48 +00001314 /// Determine whether the definition must be emitted; if this returns \c
1315 /// false, the definition can be emitted lazily if it's used.
1316 bool MustBeEmitted(const ValueDecl *D);
1317
1318 /// Determine whether the definition can be emitted eagerly, or should be
1319 /// delayed until the end of the translation unit. This is relevant for
1320 /// definitions whose linkage can change, e.g. implicit function instantions
1321 /// which may later be explicitly instantiated.
1322 bool MayBeEmittedEagerly(const ValueDecl *D);
John McCall0bdb1fd2010-09-16 06:16:50 +00001323
Rafael Espindolae98ed2f2014-05-09 01:34:38 +00001324 /// Check whether we can use a "simpler", more core exceptions personality
1325 /// function.
John McCall0bdb1fd2010-09-16 06:16:50 +00001326 void SimplifyPersonality();
Justin Lebarb080b632017-01-25 21:29:48 +00001327
1328 /// Helper function for ConstructAttributeList and AddDefaultFnAttrs.
1329 /// Constructs an AttrList for a function with the given properties.
1330 void ConstructDefaultFnAttrList(StringRef Name, bool HasOptnone,
1331 bool AttrOnCallSite,
1332 llvm::AttrBuilder &FuncAttrs);
Chris Lattnerf97fe382007-05-24 06:29:05 +00001333};
1334} // end namespace CodeGen
1335} // end namespace clang
Chris Lattnerf97fe382007-05-24 06:29:05 +00001336
Hans Wennborg59dbe862015-09-29 20:56:43 +00001337#endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H