2008-07-30 07:18:29 +08:00
|
|
|
//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-02-14 03:12:34 +08:00
|
|
|
// This is the internal per-translation-unit state used for llvm translation.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
|
2007-05-24 14:29:05 +08:00
|
|
|
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "CGVTables.h"
|
|
|
|
#include "CodeGenTypes.h"
|
2014-07-10 03:40:08 +08:00
|
|
|
#include "SanitizerBlacklist.h"
|
2014-08-02 05:35:28 +08:00
|
|
|
#include "SanitizerMetadata.h"
|
2008-05-22 08:50:06 +08:00
|
|
|
#include "clang/AST/Attr.h"
|
2009-05-05 12:44:02 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-09-11 08:07:24 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2011-06-14 12:02:39 +08:00
|
|
|
#include "clang/AST/GlobalDecl.h"
|
2011-01-14 02:57:25 +08:00
|
|
|
#include "clang/AST/Mangle.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/ABI.h"
|
|
|
|
#include "clang/Basic/LangOptions.h"
|
2013-01-15 01:21:00 +08:00
|
|
|
#include "clang/Basic/Module.h"
|
2007-06-20 12:44:43 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2013-01-15 01:21:00 +08:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2010-03-05 02:17:24 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2013-03-01 03:01:20 +08:00
|
|
|
#include "llvm/IR/CallingConv.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2014-03-04 19:18:19 +08:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2009-01-04 10:08:04 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace llvm {
|
2014-05-09 08:57:59 +08:00
|
|
|
class Module;
|
|
|
|
class Constant;
|
|
|
|
class ConstantInt;
|
|
|
|
class Function;
|
|
|
|
class GlobalValue;
|
|
|
|
class DataLayout;
|
|
|
|
class FunctionType;
|
|
|
|
class LLVMContext;
|
|
|
|
class IndexedInstrProfReader;
|
2007-06-16 07:05:46 +08:00
|
|
|
}
|
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace clang {
|
2014-05-09 08:57:59 +08:00
|
|
|
class TargetCodeGenInfo;
|
|
|
|
class ASTContext;
|
|
|
|
class AtomicType;
|
|
|
|
class FunctionDecl;
|
|
|
|
class IdentifierInfo;
|
|
|
|
class ObjCMethodDecl;
|
|
|
|
class ObjCImplementationDecl;
|
|
|
|
class ObjCCategoryImplDecl;
|
|
|
|
class ObjCProtocolDecl;
|
|
|
|
class ObjCEncodeExpr;
|
|
|
|
class BlockExpr;
|
|
|
|
class CharUnits;
|
|
|
|
class Decl;
|
|
|
|
class Expr;
|
|
|
|
class Stmt;
|
|
|
|
class InitListExpr;
|
|
|
|
class StringLiteral;
|
|
|
|
class NamedDecl;
|
|
|
|
class ValueDecl;
|
|
|
|
class VarDecl;
|
|
|
|
class LangOptions;
|
|
|
|
class CodeGenOptions;
|
|
|
|
class DiagnosticsEngine;
|
|
|
|
class AnnotateAttr;
|
|
|
|
class CXXDestructorDecl;
|
|
|
|
class Module;
|
2014-08-05 02:41:51 +08:00
|
|
|
class CoverageSourceInfo;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace CodeGen {
|
|
|
|
|
2014-05-09 08:57:59 +08:00
|
|
|
class CallArgList;
|
|
|
|
class CodeGenFunction;
|
|
|
|
class CodeGenTBAA;
|
|
|
|
class CGCXXABI;
|
|
|
|
class CGDebugInfo;
|
|
|
|
class CGObjCRuntime;
|
|
|
|
class CGOpenCLRuntime;
|
|
|
|
class CGOpenMPRuntime;
|
|
|
|
class CGCUDARuntime;
|
|
|
|
class BlockFieldFlags;
|
|
|
|
class FunctionArgList;
|
2014-08-05 02:41:51 +08:00
|
|
|
class CoverageMappingModuleGen;
|
2014-05-09 08:57:59 +08:00
|
|
|
|
|
|
|
struct OrderGlobalInits {
|
|
|
|
unsigned int priority;
|
|
|
|
unsigned int lex_order;
|
|
|
|
OrderGlobalInits(unsigned int p, unsigned int l)
|
2010-06-27 14:32:58 +08:00
|
|
|
: priority(p), lex_order(l) {}
|
2014-05-09 08:57:59 +08:00
|
|
|
|
|
|
|
bool operator==(const OrderGlobalInits &RHS) const {
|
|
|
|
return priority == RHS.priority && lex_order == RHS.lex_order;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const OrderGlobalInits &RHS) const {
|
|
|
|
return std::tie(priority, lex_order) <
|
|
|
|
std::tie(RHS.priority, RHS.lex_order);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CodeGenTypeCache {
|
|
|
|
/// void
|
|
|
|
llvm::Type *VoidTy;
|
|
|
|
|
|
|
|
/// i8, i16, i32, and i64
|
|
|
|
llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty;
|
|
|
|
/// float, double
|
|
|
|
llvm::Type *FloatTy, *DoubleTy;
|
|
|
|
|
|
|
|
/// int
|
|
|
|
llvm::IntegerType *IntTy;
|
|
|
|
|
|
|
|
/// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
|
|
|
|
union {
|
|
|
|
llvm::IntegerType *IntPtrTy;
|
|
|
|
llvm::IntegerType *SizeTy;
|
|
|
|
llvm::IntegerType *PtrDiffTy;
|
2010-06-27 14:32:58 +08:00
|
|
|
};
|
2011-02-15 17:22:45 +08:00
|
|
|
|
2014-05-09 08:57:59 +08:00
|
|
|
/// void* in address space 0
|
|
|
|
union {
|
|
|
|
llvm::PointerType *VoidPtrTy;
|
|
|
|
llvm::PointerType *Int8PtrTy;
|
2011-02-15 17:22:45 +08:00
|
|
|
};
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2014-05-09 08:57:59 +08:00
|
|
|
/// void** in address space 0
|
|
|
|
union {
|
|
|
|
llvm::PointerType *VoidPtrPtrTy;
|
|
|
|
llvm::PointerType *Int8PtrPtrTy;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The width of a pointer into the generic address space.
|
|
|
|
unsigned char PointerWidthInBits;
|
|
|
|
|
|
|
|
/// The size and alignment of a pointer into the generic address
|
|
|
|
/// space.
|
|
|
|
union {
|
|
|
|
unsigned char PointerAlignInBytes;
|
|
|
|
unsigned char PointerSizeInBytes;
|
|
|
|
unsigned char SizeSizeInBytes; // sizeof(size_t)
|
|
|
|
};
|
|
|
|
|
|
|
|
llvm::CallingConv::ID RuntimeCC;
|
|
|
|
llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
|
|
|
|
};
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
struct RREntrypoints {
|
|
|
|
RREntrypoints() { memset(this, 0, sizeof(*this)); }
|
|
|
|
/// void objc_autoreleasePoolPop(void*);
|
|
|
|
llvm::Constant *objc_autoreleasePoolPop;
|
|
|
|
|
|
|
|
/// void *objc_autoreleasePoolPush(void);
|
|
|
|
llvm::Constant *objc_autoreleasePoolPush;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ARCEntrypoints {
|
|
|
|
ARCEntrypoints() { memset(this, 0, sizeof(*this)); }
|
|
|
|
|
|
|
|
/// id objc_autorelease(id);
|
|
|
|
llvm::Constant *objc_autorelease;
|
|
|
|
|
|
|
|
/// id objc_autoreleaseReturnValue(id);
|
|
|
|
llvm::Constant *objc_autoreleaseReturnValue;
|
|
|
|
|
|
|
|
/// void objc_copyWeak(id *dest, id *src);
|
|
|
|
llvm::Constant *objc_copyWeak;
|
|
|
|
|
|
|
|
/// void objc_destroyWeak(id*);
|
|
|
|
llvm::Constant *objc_destroyWeak;
|
|
|
|
|
|
|
|
/// id objc_initWeak(id*, id);
|
|
|
|
llvm::Constant *objc_initWeak;
|
|
|
|
|
|
|
|
/// id objc_loadWeak(id*);
|
|
|
|
llvm::Constant *objc_loadWeak;
|
|
|
|
|
|
|
|
/// id objc_loadWeakRetained(id*);
|
|
|
|
llvm::Constant *objc_loadWeakRetained;
|
|
|
|
|
|
|
|
/// void objc_moveWeak(id *dest, id *src);
|
|
|
|
llvm::Constant *objc_moveWeak;
|
|
|
|
|
|
|
|
/// id objc_retain(id);
|
|
|
|
llvm::Constant *objc_retain;
|
|
|
|
|
|
|
|
/// id objc_retainAutorelease(id);
|
|
|
|
llvm::Constant *objc_retainAutorelease;
|
|
|
|
|
|
|
|
/// id objc_retainAutoreleaseReturnValue(id);
|
|
|
|
llvm::Constant *objc_retainAutoreleaseReturnValue;
|
|
|
|
|
|
|
|
/// id objc_retainAutoreleasedReturnValue(id);
|
|
|
|
llvm::Constant *objc_retainAutoreleasedReturnValue;
|
|
|
|
|
|
|
|
/// id objc_retainBlock(id);
|
|
|
|
llvm::Constant *objc_retainBlock;
|
|
|
|
|
|
|
|
/// void objc_release(id);
|
|
|
|
llvm::Constant *objc_release;
|
|
|
|
|
|
|
|
/// id objc_storeStrong(id*, id);
|
|
|
|
llvm::Constant *objc_storeStrong;
|
|
|
|
|
|
|
|
/// id objc_storeWeak(id*, id);
|
|
|
|
llvm::Constant *objc_storeWeak;
|
|
|
|
|
|
|
|
/// A void(void) inline asm to use to mark that the return value of
|
|
|
|
/// a call will be immediately retain.
|
|
|
|
llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
|
2013-03-23 10:35:54 +08:00
|
|
|
|
|
|
|
/// void clang.arc.use(...);
|
|
|
|
llvm::Constant *clang_arc_use;
|
2011-06-16 07:02:42 +08:00
|
|
|
};
|
2013-01-18 19:30:38 +08:00
|
|
|
|
2014-04-16 05:22:35 +08:00
|
|
|
/// This class records statistics on instrumentation based profiling.
|
2014-06-26 09:45:07 +08:00
|
|
|
class InstrProfStats {
|
|
|
|
uint32_t VisitedInMainFile;
|
|
|
|
uint32_t MissingInMainFile;
|
2014-04-16 05:22:35 +08:00
|
|
|
uint32_t Visited;
|
|
|
|
uint32_t Missing;
|
|
|
|
uint32_t Mismatched;
|
2014-06-26 09:45:07 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
InstrProfStats()
|
|
|
|
: VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
|
|
|
|
Mismatched(0) {}
|
|
|
|
/// Record that we've visited a function and whether or not that function was
|
|
|
|
/// in the main source file.
|
|
|
|
void addVisited(bool MainFile) {
|
|
|
|
if (MainFile)
|
|
|
|
++VisitedInMainFile;
|
|
|
|
++Visited;
|
|
|
|
}
|
|
|
|
/// Record that a function we've visited has no profile data.
|
|
|
|
void addMissing(bool MainFile) {
|
|
|
|
if (MainFile)
|
|
|
|
++MissingInMainFile;
|
|
|
|
++Missing;
|
|
|
|
}
|
|
|
|
/// Record that a function we've visited has mismatched profile data.
|
|
|
|
void addMismatched(bool MainFile) { ++Mismatched; }
|
|
|
|
/// Whether or not the stats we've gathered indicate any potential problems.
|
|
|
|
bool hasDiagnostics() { return Missing || Mismatched; }
|
|
|
|
/// Report potential problems we've found to \c Diags.
|
|
|
|
void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
|
2014-04-16 05:22:35 +08:00
|
|
|
};
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// This class organizes the cross-function state that is used while generating
|
|
|
|
/// LLVM code.
|
2011-02-15 17:22:45 +08:00
|
|
|
class CodeGenModule : public CodeGenTypeCache {
|
2012-09-16 04:20:27 +08:00
|
|
|
CodeGenModule(const CodeGenModule &) LLVM_DELETED_FUNCTION;
|
|
|
|
void operator=(const CodeGenModule &) LLVM_DELETED_FUNCTION;
|
2009-02-24 12:21:31 +08:00
|
|
|
|
2014-05-24 05:13:45 +08:00
|
|
|
struct Structor {
|
|
|
|
Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
|
|
|
|
Structor(int Priority, llvm::Constant *Initializer,
|
|
|
|
llvm::Constant *AssociatedData)
|
|
|
|
: Priority(Priority), Initializer(Initializer),
|
|
|
|
AssociatedData(AssociatedData) {}
|
|
|
|
int Priority;
|
|
|
|
llvm::Constant *Initializer;
|
|
|
|
llvm::Constant *AssociatedData;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Structor> CtorList;
|
2008-08-01 08:01:51 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
ASTContext &Context;
|
2012-03-11 15:00:24 +08:00
|
|
|
const LangOptions &LangOpts;
|
2009-11-13 01:24:48 +08:00
|
|
|
const CodeGenOptions &CodeGenOpts;
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::Module &TheModule;
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags;
|
2013-04-17 06:48:15 +08:00
|
|
|
const llvm::DataLayout &TheDataLayout;
|
|
|
|
const TargetInfo &Target;
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<CGCXXABI> ABI;
|
2013-04-17 06:48:15 +08:00
|
|
|
llvm::LLVMContext &VMContext;
|
2009-10-07 09:06:45 +08:00
|
|
|
|
2013-04-17 06:48:15 +08:00
|
|
|
CodeGenTBAA *TBAA;
|
|
|
|
|
|
|
|
mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
|
|
|
|
|
|
|
|
// This should not be moved earlier, since its initialization depends on some
|
|
|
|
// of the previous reference members being already initialized and also checks
|
|
|
|
// if TheTargetCodeGenInfo is NULL
|
|
|
|
CodeGenTypes Types;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Holds information about C++ vtables.
|
2010-03-23 12:11:45 +08:00
|
|
|
CodeGenVTables VTables;
|
2010-04-09 00:07:47 +08:00
|
|
|
|
2011-07-28 04:29:46 +08:00
|
|
|
CGObjCRuntime* ObjCRuntime;
|
2011-09-20 05:14:35 +08:00
|
|
|
CGOpenCLRuntime* OpenCLRuntime;
|
2014-05-06 18:08:46 +08:00
|
|
|
CGOpenMPRuntime* OpenMPRuntime;
|
2011-10-07 02:29:37 +08:00
|
|
|
CGCUDARuntime* CUDARuntime;
|
2008-08-06 02:50:11 +08:00
|
|
|
CGDebugInfo* DebugInfo;
|
2011-06-16 07:02:42 +08:00
|
|
|
ARCEntrypoints *ARCData;
|
2012-02-16 08:57:37 +08:00
|
|
|
llvm::MDNode *NoObjCARCExceptionsMetadata;
|
2011-06-16 07:02:42 +08:00
|
|
|
RREntrypoints *RRData;
|
2014-04-19 05:52:00 +08:00
|
|
|
std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
|
2014-04-16 05:22:35 +08:00
|
|
|
InstrProfStats PGOStats;
|
2008-07-31 00:32:24 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
// A set of references that have only been seen via a weakref so far. This is
|
|
|
|
// used to remove the weak of the reference if we ever see a direct reference
|
|
|
|
// or a definition.
|
2010-03-05 02:17:24 +08:00
|
|
|
llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// This contains all the decls which have definitions but/ which are deferred
|
|
|
|
/// for emission and therefore should only be output if they are actually
|
|
|
|
/// used. If a decl is in this, then it is known to have not been referenced
|
|
|
|
/// yet.
|
2014-06-06 06:10:59 +08:00
|
|
|
std::map<StringRef, GlobalDecl> DeferredDecls;
|
2009-03-21 17:44:56 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// This is a list of deferred decls which we have seen that *are* actually
|
|
|
|
/// referenced. These get code generated when the module is done.
|
2013-12-09 22:59:08 +08:00
|
|
|
struct DeferredGlobal {
|
|
|
|
DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {}
|
|
|
|
llvm::AssertingVH<llvm::GlobalValue> GV;
|
|
|
|
GlobalDecl GD;
|
|
|
|
};
|
|
|
|
std::vector<DeferredGlobal> DeferredDeclsToEmit;
|
|
|
|
void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) {
|
|
|
|
DeferredDeclsToEmit.push_back(DeferredGlobal(GV, GD));
|
|
|
|
}
|
2009-04-16 06:08:45 +08:00
|
|
|
|
2013-10-23 03:26:13 +08:00
|
|
|
/// List of alias we have emitted. Used to make sure that what they point to
|
|
|
|
/// is defined once we get to the end of the of the translation unit.
|
|
|
|
std::vector<GlobalDecl> Aliases;
|
|
|
|
|
2013-11-06 05:37:29 +08:00
|
|
|
typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
|
|
|
|
ReplacementsTy Replacements;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// A queue of (optional) vtables to consider emitting.
|
2013-01-26 06:31:03 +08:00
|
|
|
std::vector<const CXXRecordDecl*> DeferredVTables;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// List of global values which are required to be present in the object file;
|
|
|
|
/// bitcast to i8*. This is used for forcing visibility of symbols which may
|
|
|
|
/// otherwise be optimized out.
|
2009-04-01 06:37:52 +08:00
|
|
|
std::vector<llvm::WeakVH> LLVMUsed;
|
2014-03-07 06:15:10 +08:00
|
|
|
std::vector<llvm::WeakVH> LLVMCompilerUsed;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Store the list of global constructors and their respective priorities to
|
|
|
|
/// be emitted when the translation unit is complete.
|
2008-08-01 08:01:51 +08:00
|
|
|
CtorList GlobalCtors;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Store the list of global destructors and their respective priorities to be
|
|
|
|
/// emitted when the translation unit is complete.
|
2008-08-01 08:01:51 +08:00
|
|
|
CtorList GlobalDtors;
|
|
|
|
|
2014-07-03 17:30:33 +08:00
|
|
|
/// An ordered map of canonical GlobalDecls to their mangled names.
|
|
|
|
llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
|
2014-06-06 06:10:59 +08:00
|
|
|
llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
|
|
|
|
|
2011-09-10 06:41:49 +08:00
|
|
|
/// Global annotations.
|
2008-04-19 07:43:57 +08:00
|
|
|
std::vector<llvm::Constant*> Annotations;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2011-09-10 06:41:49 +08:00
|
|
|
/// Map used to get unique annotation strings.
|
|
|
|
llvm::StringMap<llvm::Constant*> AnnotationStrings;
|
|
|
|
|
2007-08-21 08:21:21 +08:00
|
|
|
llvm::StringMap<llvm::Constant*> CFConstantStringMap;
|
2014-03-25 05:43:36 +08:00
|
|
|
|
2014-07-30 05:20:12 +08:00
|
|
|
llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
|
2012-03-09 11:27:46 +08:00
|
|
|
llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
|
2012-03-31 05:00:39 +08:00
|
|
|
llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
|
2013-06-05 08:46:14 +08:00
|
|
|
llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
|
|
|
|
|
2012-01-09 03:13:23 +08:00
|
|
|
llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
|
|
|
|
llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
|
2008-08-24 02:37:06 +08:00
|
|
|
|
2013-11-08 09:09:22 +08:00
|
|
|
/// Map used to get unique type descriptor constants for sanitizers.
|
|
|
|
llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
|
|
|
|
|
2013-04-06 13:00:46 +08:00
|
|
|
/// Map used to track internal linkage functions declared within
|
|
|
|
/// extern "C" regions.
|
2013-04-13 09:28:18 +08:00
|
|
|
typedef llvm::MapVector<IdentifierInfo *,
|
|
|
|
llvm::GlobalValue *> StaticExternCMap;
|
2013-04-06 13:00:46 +08:00
|
|
|
StaticExternCMap StaticExternCValues;
|
|
|
|
|
2013-04-20 00:42:07 +08:00
|
|
|
/// \brief thread_local variables defined or used in this TU.
|
|
|
|
std::vector<std::pair<const VarDecl *, llvm::GlobalVariable *> >
|
|
|
|
CXXThreadLocals;
|
|
|
|
|
|
|
|
/// \brief thread_local variables with initializers that need to run
|
|
|
|
/// before any thread_local variable in this TU is odr-used.
|
2014-10-05 13:05:40 +08:00
|
|
|
std::vector<llvm::Function *> CXXThreadLocalInits;
|
|
|
|
std::vector<llvm::GlobalVariable *> CXXThreadLocalInitVars;
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Global variables with initializers that need to run before main.
|
2014-10-05 13:05:40 +08:00
|
|
|
std::vector<llvm::Function *> CXXGlobalInits;
|
2010-07-16 07:40:35 +08:00
|
|
|
|
|
|
|
/// When a C++ decl with an initializer is deferred, null is
|
|
|
|
/// appended to CXXGlobalInits, and the index of that null is placed
|
|
|
|
/// here so that the initializer will be performed in the correct
|
|
|
|
/// order.
|
|
|
|
llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
|
2010-06-22 02:45:05 +08:00
|
|
|
|
2012-11-07 06:44:45 +08:00
|
|
|
typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
|
|
|
|
|
|
|
|
struct GlobalInitPriorityCmp {
|
|
|
|
bool operator()(const GlobalInitData &LHS,
|
|
|
|
const GlobalInitData &RHS) const {
|
|
|
|
return LHS.first.priority < RHS.first.priority;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Global variables with initializers whose order of initialization is set by
|
|
|
|
/// init_priority attribute.
|
2012-11-07 06:44:45 +08:00
|
|
|
SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Global destructor functions and arguments that need to run on termination.
|
2010-06-19 13:52:45 +08:00
|
|
|
std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
|
2010-03-20 12:15:41 +08:00
|
|
|
|
2013-01-15 01:21:00 +08:00
|
|
|
/// \brief The complete set of modules that has been imported.
|
|
|
|
llvm::SetVector<clang::Module *> ImportedModules;
|
|
|
|
|
2013-05-08 21:44:39 +08:00
|
|
|
/// \brief A vector of metadata strings.
|
|
|
|
SmallVector<llvm::Value *, 16> LinkerOptionsMetadata;
|
|
|
|
|
2011-08-09 23:54:21 +08:00
|
|
|
/// @name Cache for Objective-C runtime types
|
|
|
|
/// @{
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Cached reference to the class for constant strings. This value has type
|
|
|
|
/// int * but is actually an Obj-C class pointer.
|
2013-04-16 23:25:39 +08:00
|
|
|
llvm::WeakVH CFConstantStringClassRef;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Cached reference to the class for constant strings. This value has type
|
|
|
|
/// int * but is actually an Obj-C class pointer.
|
2013-04-16 23:25:39 +08:00
|
|
|
llvm::WeakVH ConstantStringClassRef;
|
2010-04-24 01:41:07 +08:00
|
|
|
|
2011-08-09 23:54:21 +08:00
|
|
|
/// \brief The LLVM type corresponding to NSConstantString.
|
|
|
|
llvm::StructType *NSConstantStringType;
|
|
|
|
|
2011-08-10 01:23:49 +08:00
|
|
|
/// \brief The type used to describe the state of a fast enumeration in
|
|
|
|
/// Objective-C's for..in loop.
|
|
|
|
QualType ObjCFastEnumerationStateType;
|
|
|
|
|
2011-08-09 23:54:21 +08:00
|
|
|
/// @}
|
|
|
|
|
2010-01-23 10:40:42 +08:00
|
|
|
/// Lazily create the Objective-C runtime
|
|
|
|
void createObjCRuntime();
|
|
|
|
|
2011-09-20 05:14:35 +08:00
|
|
|
void createOpenCLRuntime();
|
2014-05-06 18:08:46 +08:00
|
|
|
void createOpenMPRuntime();
|
2011-10-07 02:29:37 +08:00
|
|
|
void createCUDARuntime();
|
2011-09-20 05:14:35 +08:00
|
|
|
|
2011-12-19 22:41:01 +08:00
|
|
|
bool isTriviallyRecursive(const FunctionDecl *F);
|
2013-06-06 01:49:37 +08:00
|
|
|
bool shouldEmitFunction(GlobalDecl GD);
|
2010-07-16 08:00:15 +08:00
|
|
|
|
|
|
|
/// @name Cache for Blocks Runtime Globals
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
llvm::Constant *NSConcreteGlobalBlock;
|
|
|
|
llvm::Constant *NSConcreteStackBlock;
|
2010-07-16 08:00:19 +08:00
|
|
|
|
2010-07-16 08:00:15 +08:00
|
|
|
llvm::Constant *BlockObjectAssign;
|
|
|
|
llvm::Constant *BlockObjectDispose;
|
|
|
|
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *BlockDescriptorType;
|
|
|
|
llvm::Type *GenericBlockLiteralType;
|
2011-02-08 16:22:06 +08:00
|
|
|
|
|
|
|
struct {
|
|
|
|
int GlobalUniqueCount;
|
|
|
|
} Block;
|
2013-01-18 19:30:38 +08:00
|
|
|
|
2013-03-23 14:43:35 +08:00
|
|
|
/// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
|
|
|
|
llvm::Constant *LifetimeStartFn;
|
|
|
|
|
|
|
|
/// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
|
|
|
|
llvm::Constant *LifetimeEndFn;
|
|
|
|
|
2012-06-27 00:06:38 +08:00
|
|
|
GlobalDecl initializedGlobalDecl;
|
2011-02-08 16:22:06 +08:00
|
|
|
|
2014-07-10 03:40:08 +08:00
|
|
|
SanitizerBlacklist SanitizerBL;
|
2013-01-18 19:30:38 +08:00
|
|
|
|
2014-08-02 05:35:28 +08:00
|
|
|
std::unique_ptr<SanitizerMetadata> SanitizerMD;
|
|
|
|
|
2010-07-16 08:00:15 +08:00
|
|
|
/// @}
|
2014-08-05 02:41:51 +08:00
|
|
|
|
|
|
|
llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
|
|
|
|
|
|
|
|
std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
|
2007-05-24 14:29:05 +08:00
|
|
|
public:
|
2009-11-13 01:24:48 +08:00
|
|
|
CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
|
2013-04-17 06:48:20 +08:00
|
|
|
llvm::Module &M, const llvm::DataLayout &TD,
|
2014-08-05 02:41:51 +08:00
|
|
|
DiagnosticsEngine &Diags,
|
|
|
|
CoverageSourceInfo *CoverageInfo = nullptr);
|
2008-08-06 02:50:11 +08:00
|
|
|
|
2008-03-01 16:45:05 +08:00
|
|
|
~CodeGenModule();
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2013-12-09 22:59:08 +08:00
|
|
|
void clear();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Finalize LLVM code generation.
|
2008-08-06 02:50:11 +08:00
|
|
|
void Release();
|
2008-08-12 02:12:00 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a reference to the configured Objective-C runtime.
|
2009-02-14 03:12:34 +08:00
|
|
|
CGObjCRuntime &getObjCRuntime() {
|
2011-07-28 04:29:46 +08:00
|
|
|
if (!ObjCRuntime) createObjCRuntime();
|
|
|
|
return *ObjCRuntime;
|
2008-08-12 02:12:00 +08:00
|
|
|
}
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff an Objective-C runtime has been configured.
|
2011-07-28 04:29:46 +08:00
|
|
|
bool hasObjCRuntime() { return !!ObjCRuntime; }
|
2008-08-12 02:12:00 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a reference to the configured OpenCL runtime.
|
2011-09-20 05:14:35 +08:00
|
|
|
CGOpenCLRuntime &getOpenCLRuntime() {
|
2014-05-21 13:09:00 +08:00
|
|
|
assert(OpenCLRuntime != nullptr);
|
2011-09-20 05:14:35 +08:00
|
|
|
return *OpenCLRuntime;
|
|
|
|
}
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a reference to the configured OpenMP runtime.
|
2014-05-06 18:08:46 +08:00
|
|
|
CGOpenMPRuntime &getOpenMPRuntime() {
|
|
|
|
assert(OpenMPRuntime != nullptr);
|
|
|
|
return *OpenMPRuntime;
|
|
|
|
}
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a reference to the configured CUDA runtime.
|
2011-10-07 02:29:37 +08:00
|
|
|
CGCUDARuntime &getCUDARuntime() {
|
2014-05-21 13:09:00 +08:00
|
|
|
assert(CUDARuntime != nullptr);
|
2011-10-07 02:29:37 +08:00
|
|
|
return *CUDARuntime;
|
|
|
|
}
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
ARCEntrypoints &getARCEntrypoints() const {
|
2014-05-21 13:09:00 +08:00
|
|
|
assert(getLangOpts().ObjCAutoRefCount && ARCData != nullptr);
|
2011-06-16 07:02:42 +08:00
|
|
|
return *ARCData;
|
|
|
|
}
|
|
|
|
|
|
|
|
RREntrypoints &getRREntrypoints() const {
|
2014-05-21 13:09:00 +08:00
|
|
|
assert(RRData != nullptr);
|
2011-06-16 07:02:42 +08:00
|
|
|
return *RRData;
|
|
|
|
}
|
|
|
|
|
2014-04-19 05:52:00 +08:00
|
|
|
InstrProfStats &getPGOStats() { return PGOStats; }
|
|
|
|
llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
|
2014-01-07 06:27:43 +08:00
|
|
|
|
2014-08-05 02:41:51 +08:00
|
|
|
CoverageMappingModuleGen *getCoverageMapping() const {
|
|
|
|
return CoverageMapping.get();
|
|
|
|
}
|
|
|
|
|
2012-03-09 11:27:46 +08:00
|
|
|
llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
|
|
|
|
return StaticLocalDeclMap[D];
|
2010-04-19 05:01:23 +08:00
|
|
|
}
|
2010-04-20 02:15:02 +08:00
|
|
|
void setStaticLocalDeclAddress(const VarDecl *D,
|
2012-03-09 11:27:46 +08:00
|
|
|
llvm::Constant *C) {
|
|
|
|
StaticLocalDeclMap[D] = C;
|
2010-04-19 05:01:23 +08:00
|
|
|
}
|
|
|
|
|
2014-10-08 09:07:54 +08:00
|
|
|
llvm::Constant *
|
|
|
|
getOrCreateStaticVarDecl(const VarDecl &D,
|
|
|
|
llvm::GlobalValue::LinkageTypes Linkage);
|
|
|
|
|
2012-03-31 05:00:39 +08:00
|
|
|
llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
|
|
|
|
return StaticLocalDeclGuardMap[D];
|
|
|
|
}
|
|
|
|
void setStaticLocalDeclGuardAddress(const VarDecl *D,
|
|
|
|
llvm::GlobalVariable *C) {
|
|
|
|
StaticLocalDeclGuardMap[D] = C;
|
|
|
|
}
|
|
|
|
|
2014-06-06 06:10:59 +08:00
|
|
|
bool lookupRepresentativeDecl(StringRef MangledName,
|
|
|
|
GlobalDecl &Result) const;
|
|
|
|
|
2012-01-09 03:13:23 +08:00
|
|
|
llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
|
|
|
|
return AtomicSetterHelperFnMap[Ty];
|
2012-01-07 06:33:54 +08:00
|
|
|
}
|
2012-01-09 03:13:23 +08:00
|
|
|
void setAtomicSetterHelperFnMap(QualType Ty,
|
2012-01-07 06:33:54 +08:00
|
|
|
llvm::Constant *Fn) {
|
2012-01-09 03:13:23 +08:00
|
|
|
AtomicSetterHelperFnMap[Ty] = Fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
|
|
|
|
return AtomicGetterHelperFnMap[Ty];
|
|
|
|
}
|
|
|
|
void setAtomicGetterHelperFnMap(QualType Ty,
|
|
|
|
llvm::Constant *Fn) {
|
|
|
|
AtomicGetterHelperFnMap[Ty] = Fn;
|
2012-01-07 06:33:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-24 00:07:43 +08:00
|
|
|
llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
|
2013-11-08 09:09:22 +08:00
|
|
|
return TypeDescriptorMap[Ty];
|
|
|
|
}
|
2014-05-24 00:07:43 +08:00
|
|
|
void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
|
2013-11-08 09:09:22 +08:00
|
|
|
TypeDescriptorMap[Ty] = C;
|
|
|
|
}
|
|
|
|
|
2011-03-08 02:45:56 +08:00
|
|
|
CGDebugInfo *getModuleDebugInfo() { return DebugInfo; }
|
2011-03-08 02:29:53 +08:00
|
|
|
|
2012-02-16 08:57:37 +08:00
|
|
|
llvm::MDNode *getNoObjCARCExceptionsMetadata() {
|
|
|
|
if (!NoObjCARCExceptionsMetadata)
|
|
|
|
NoObjCARCExceptionsMetadata =
|
|
|
|
llvm::MDNode::get(getLLVMContext(),
|
|
|
|
SmallVector<llvm::Value*,1>());
|
|
|
|
return NoObjCARCExceptionsMetadata;
|
|
|
|
}
|
|
|
|
|
2007-05-30 07:17:50 +08:00
|
|
|
ASTContext &getContext() const { return Context; }
|
2012-03-11 15:00:24 +08:00
|
|
|
const LangOptions &getLangOpts() const { return LangOpts; }
|
2013-04-17 06:48:15 +08:00
|
|
|
const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::Module &getModule() const { return TheModule; }
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &getDiags() const { return Diags; }
|
2012-10-09 00:25:52 +08:00
|
|
|
const llvm::DataLayout &getDataLayout() const { return TheDataLayout; }
|
2013-04-17 06:48:15 +08:00
|
|
|
const TargetInfo &getTarget() const { return Target; }
|
2014-09-19 09:54:22 +08:00
|
|
|
const llvm::Triple &getTriple() const;
|
|
|
|
bool supportsCOMDAT() const;
|
|
|
|
|
2013-12-29 05:58:40 +08:00
|
|
|
CGCXXABI &getCXXABI() const { return *ABI; }
|
2009-07-15 07:10:40 +08:00
|
|
|
llvm::LLVMContext &getLLVMContext() { return VMContext; }
|
2014-05-21 13:09:00 +08:00
|
|
|
|
|
|
|
bool shouldUseTBAA() const { return TBAA != nullptr; }
|
2011-02-26 16:07:02 +08:00
|
|
|
|
2013-04-17 06:48:15 +08:00
|
|
|
const TargetCodeGenInfo &getTargetCodeGenInfo();
|
|
|
|
|
|
|
|
CodeGenTypes &getTypes() { return Types; }
|
|
|
|
|
|
|
|
CodeGenVTables &getVTables() { return VTables; }
|
2013-08-21 14:25:03 +08:00
|
|
|
|
2013-11-05 23:54:58 +08:00
|
|
|
ItaniumVTableContext &getItaniumVTableContext() {
|
|
|
|
return VTables.getItaniumVTableContext();
|
2013-10-09 19:33:51 +08:00
|
|
|
}
|
2013-04-17 06:48:15 +08:00
|
|
|
|
2013-11-05 23:54:58 +08:00
|
|
|
MicrosoftVTableContext &getMicrosoftVTableContext() {
|
|
|
|
return VTables.getMicrosoftVTableContext();
|
2013-08-21 14:25:03 +08:00
|
|
|
}
|
|
|
|
|
2010-10-15 07:06:10 +08:00
|
|
|
llvm::MDNode *getTBAAInfo(QualType QTy);
|
2012-03-27 01:03:51 +08:00
|
|
|
llvm::MDNode *getTBAAInfoForVTablePtr();
|
2012-09-29 05:58:29 +08:00
|
|
|
llvm::MDNode *getTBAAStructInfo(QualType QTy);
|
2013-04-05 05:53:22 +08:00
|
|
|
/// Return the MDNode in the type DAG for the given struct type.
|
|
|
|
llvm::MDNode *getTBAAStructTypeInfo(QualType QTy);
|
|
|
|
/// Return the path-aware tag for given base type, access node and offset.
|
|
|
|
llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
|
|
|
|
uint64_t O);
|
2010-10-15 07:06:10 +08:00
|
|
|
|
2012-02-17 14:48:11 +08:00
|
|
|
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
|
|
|
|
|
2013-03-08 05:37:17 +08:00
|
|
|
bool isPaddedAtomicType(QualType type);
|
|
|
|
bool isPaddedAtomicType(const AtomicType *type);
|
|
|
|
|
2013-04-12 07:02:56 +08:00
|
|
|
/// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
|
|
|
|
/// is the same as the type. For struct-path aware TBAA, the tag
|
|
|
|
/// is different from the type: base type, access type and offset.
|
|
|
|
/// When ConvertTypeToTag is true, we create a tag based on the scalar type.
|
|
|
|
void DecorateInstruction(llvm::Instruction *Inst,
|
|
|
|
llvm::MDNode *TBAAInfo,
|
|
|
|
bool ConvertTypeToTag = true);
|
2010-10-15 07:06:10 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the given number of characters as a value of type size_t.
|
2011-06-25 05:55:10 +08:00
|
|
|
llvm::ConstantInt *getSize(CharUnits numChars);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set the visibility for the given LLVM GlobalValue.
|
2011-01-30 03:39:23 +08:00
|
|
|
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
|
2009-04-14 14:00:08 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set the TLS mode for the given LLVM GlobalVariable for the thread-local
|
|
|
|
/// variable declaration D.
|
2012-06-28 16:01:44 +08:00
|
|
|
void setTLSMode(llvm::GlobalVariable *GV, const VarDecl &D) const;
|
|
|
|
|
2011-01-30 04:59:35 +08:00
|
|
|
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
|
|
|
|
switch (V) {
|
|
|
|
case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
|
|
|
|
case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
|
|
|
|
case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown visibility!");
|
|
|
|
}
|
|
|
|
|
2010-02-19 09:32:20 +08:00
|
|
|
llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
|
|
|
|
if (isa<CXXConstructorDecl>(GD.getDecl()))
|
2014-09-11 23:42:06 +08:00
|
|
|
return getAddrOfCXXStructor(cast<CXXConstructorDecl>(GD.getDecl()),
|
|
|
|
getFromCtorType(GD.getCtorType()));
|
2010-02-19 09:32:20 +08:00
|
|
|
else if (isa<CXXDestructorDecl>(GD.getDecl()))
|
2014-09-11 23:42:06 +08:00
|
|
|
return getAddrOfCXXStructor(cast<CXXDestructorDecl>(GD.getDecl()),
|
|
|
|
getFromDtorType(GD.getDtorType()));
|
2010-02-19 09:32:20 +08:00
|
|
|
else if (isa<FunctionDecl>(GD.getDecl()))
|
|
|
|
return GetAddrOfFunction(GD);
|
|
|
|
else
|
|
|
|
return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
|
|
|
|
}
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Will return a global variable of the given type. If a variable with a
|
|
|
|
/// different type already exists then a new variable with the right type
|
|
|
|
/// will be created and all uses of the old variable will be replaced with a
|
|
|
|
/// bitcast to the new variable.
|
2011-01-30 02:20:20 +08:00
|
|
|
llvm::GlobalVariable *
|
2011-07-20 14:58:45 +08:00
|
|
|
CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
|
2011-01-30 02:20:20 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes Linkage);
|
|
|
|
|
2014-10-05 13:05:40 +08:00
|
|
|
llvm::Function *CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty,
|
|
|
|
const Twine &name,
|
|
|
|
bool TLS = false);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the address space of the underlying global variable for D, as
|
|
|
|
/// determined by its declaration. Normally this is the same as the address
|
|
|
|
/// space of D's type, but in CUDA, address spaces are associated with
|
|
|
|
/// declarations, not types.
|
2012-05-21 05:08:35 +08:00
|
|
|
unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the llvm::Constant for the address of the given global variable.
|
|
|
|
/// If Ty is non-null and if the global doesn't exist, then it will be greated
|
|
|
|
/// with the specified type instead of whatever the normal requested type
|
|
|
|
/// would be.
|
2009-03-21 17:16:30 +08:00
|
|
|
llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Type *Ty = nullptr);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the address of the given function. If Ty is non-null, then this
|
|
|
|
/// function will use the specified type if it has to create it.
|
2013-12-09 12:29:47 +08:00
|
|
|
llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = 0,
|
|
|
|
bool ForVTable = false,
|
|
|
|
bool DontDefer = false);
|
2008-08-14 07:20:05 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Get the address of the RTTI descriptor for the given type.
|
2010-04-30 09:15:21 +08:00
|
|
|
llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
|
2009-12-11 10:46:30 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Get the address of a uuid descriptor .
|
2012-10-11 18:13:44 +08:00
|
|
|
llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Get the address of the thunk for the given global decl.
|
2011-02-07 01:15:43 +08:00
|
|
|
llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
|
2010-03-24 01:17:29 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Get a reference to the target of VD.
|
2010-03-05 02:17:24 +08:00
|
|
|
llvm::Constant *GetWeakRefReference(const ValueDecl *VD);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns the offset from a derived class to a class. Returns null if the
|
|
|
|
/// offset is 0.
|
2010-04-25 05:23:59 +08:00
|
|
|
llvm::Constant *
|
|
|
|
GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
|
2010-08-07 14:22:56 +08:00
|
|
|
CastExpr::path_const_iterator PathBegin,
|
|
|
|
CastExpr::path_const_iterator PathEnd);
|
2011-02-08 16:22:06 +08:00
|
|
|
|
2011-03-31 16:03:29 +08:00
|
|
|
/// A pair of helper functions for a __block variable.
|
|
|
|
class ByrefHelpers : public llvm::FoldingSetNode {
|
|
|
|
public:
|
|
|
|
llvm::Constant *CopyHelper;
|
|
|
|
llvm::Constant *DisposeHelper;
|
|
|
|
|
|
|
|
/// The alignment of the field. This is important because
|
|
|
|
/// different offsets to the field within the byref struct need to
|
|
|
|
/// have different helper functions.
|
|
|
|
CharUnits Alignment;
|
|
|
|
|
|
|
|
ByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
|
|
|
|
virtual ~ByrefHelpers();
|
|
|
|
|
|
|
|
void Profile(llvm::FoldingSetNodeID &id) const {
|
|
|
|
id.AddInteger(Alignment.getQuantity());
|
|
|
|
profileImpl(id);
|
|
|
|
}
|
|
|
|
virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
|
|
|
|
|
|
|
|
virtual bool needsCopy() const { return true; }
|
|
|
|
virtual void emitCopy(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *dest, llvm::Value *src) = 0;
|
|
|
|
|
|
|
|
virtual bool needsDispose() const { return true; }
|
|
|
|
virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache;
|
2011-02-08 16:22:06 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Fetches the global unique block count.
|
2011-02-23 06:38:33 +08:00
|
|
|
int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
|
2012-06-27 00:06:38 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Fetches the type of a generic block descriptor.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *getBlockDescriptorType();
|
2011-02-08 16:22:06 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// The type of a generic block literal.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *getGenericBlockLiteralType();
|
2011-02-08 16:22:06 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Gets the address of a block which requires no captures.
|
2011-02-08 16:22:06 +08:00
|
|
|
llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *);
|
2010-04-25 05:23:59 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a pointer to a constant CFString object for the given string.
|
2009-04-01 21:55:36 +08:00
|
|
|
llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
|
2014-05-09 09:34:38 +08:00
|
|
|
|
|
|
|
/// Return a pointer to a constant NSString object for the given string. Or a
|
|
|
|
/// user defined String object as defined via
|
2010-10-20 01:19:29 +08:00
|
|
|
/// -fconstant-string-class=class_name option.
|
|
|
|
llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal);
|
2008-02-11 08:02:17 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a constant array for the given string.
|
2011-11-01 10:23:42 +08:00
|
|
|
llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a pointer to a constant array for the given string literal.
|
2014-07-11 06:18:36 +08:00
|
|
|
llvm::GlobalVariable *
|
|
|
|
GetAddrOfConstantStringFromLiteral(const StringLiteral *S);
|
2008-08-11 04:25:57 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a pointer to a constant array for the given ObjCEncodeExpr node.
|
2014-07-11 06:18:36 +08:00
|
|
|
llvm::GlobalVariable *
|
|
|
|
GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns a pointer to a character array containing the literal and a
|
|
|
|
/// terminating '\0' character. The result has pointer to array type.
|
2008-10-18 05:56:50 +08:00
|
|
|
///
|
2009-02-14 03:12:34 +08:00
|
|
|
/// \param GlobalName If provided, the name to use for the global (if one is
|
|
|
|
/// created).
|
2014-07-11 06:18:36 +08:00
|
|
|
llvm::GlobalVariable *
|
|
|
|
GetAddrOfConstantCString(const std::string &Str,
|
|
|
|
const char *GlobalName = nullptr,
|
|
|
|
unsigned Alignment = 0);
|
2011-11-23 06:48:32 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns a pointer to a constant global variable for the given file-scope
|
|
|
|
/// compound literal expression.
|
2011-11-23 06:48:32 +08:00
|
|
|
llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
|
2013-06-05 08:46:14 +08:00
|
|
|
|
|
|
|
/// \brief Returns a pointer to a global variable representing a temporary
|
|
|
|
/// with static or thread storage duration.
|
|
|
|
llvm::Constant *GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
|
|
|
|
const Expr *Inner);
|
|
|
|
|
2011-08-10 01:23:49 +08:00
|
|
|
/// \brief Retrieve the record type that describes the state of an
|
|
|
|
/// Objective-C fast enumeration loop (for..in).
|
|
|
|
QualType getObjCFastEnumerationStateType();
|
2014-09-09 00:01:27 +08:00
|
|
|
|
2014-09-16 03:34:18 +08:00
|
|
|
// Produce code for this constructor/destructor. This method doesn't try
|
|
|
|
// to apply any ABI rules about which other constructors/destructors
|
|
|
|
// are needed or if they are alias to each other.
|
|
|
|
llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
|
|
|
|
StructorType Type);
|
|
|
|
|
2014-09-11 23:42:06 +08:00
|
|
|
/// Return the address of the constructor/destructor of the given type.
|
2014-09-09 00:01:27 +08:00
|
|
|
llvm::GlobalValue *
|
|
|
|
getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type,
|
|
|
|
const CGFunctionInfo *FnInfo = nullptr,
|
|
|
|
llvm::FunctionType *FnType = nullptr,
|
|
|
|
bool DontDefer = false);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Given a builtin id for a function like "__builtin_fabsf", return a
|
|
|
|
/// Function* for "fabsf".
|
2009-09-14 12:33:21 +08:00
|
|
|
llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
|
|
|
|
unsigned BuiltinID);
|
2008-08-14 07:20:05 +08:00
|
|
|
|
2013-05-05 08:41:58 +08:00
|
|
|
llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit code for a single top level declaration.
|
2008-08-16 07:26:23 +08:00
|
|
|
void EmitTopLevelDecl(Decl *D);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2014-08-05 02:41:51 +08:00
|
|
|
/// \brief Stored a deferred empty coverage mapping for an unused
|
|
|
|
/// and thus uninstrumented top level declaration.
|
|
|
|
void AddDeferredUnusedCoverageMapping(Decl *D);
|
|
|
|
|
|
|
|
/// \brief Remove the deferred empty coverage mapping as this
|
|
|
|
/// declaration is actually instrumented.
|
|
|
|
void ClearUnusedCoverageMapping(const Decl *D);
|
|
|
|
|
|
|
|
/// \brief Emit all the deferred coverage mappings
|
|
|
|
/// for the uninstrumented functions.
|
|
|
|
void EmitDeferredUnusedCoverageMappings();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Tell the consumer that this variable has been instantiated.
|
2012-03-08 23:51:03 +08:00
|
|
|
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
|
2012-03-05 18:54:55 +08:00
|
|
|
|
2013-04-06 13:00:46 +08:00
|
|
|
/// \brief If the declaration has internal linkage but is inside an
|
|
|
|
/// extern "C" linkage specification, prepare to emit an alias for it
|
|
|
|
/// to the expected name.
|
|
|
|
template<typename SomeDecl>
|
|
|
|
void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
|
|
|
|
|
2014-03-07 06:15:10 +08:00
|
|
|
/// Add a global to a list to be added to the llvm.used metadata.
|
|
|
|
void addUsedGlobal(llvm::GlobalValue *GV);
|
|
|
|
|
|
|
|
/// Add a global to a list to be added to the llvm.compiler.used metadata.
|
|
|
|
void addCompilerUsedGlobal(llvm::GlobalValue *GV);
|
2009-02-14 04:29:50 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Add a destructor and object to add to the C++ global destructor function.
|
2010-06-19 13:52:45 +08:00
|
|
|
void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
|
|
|
|
CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
|
|
|
|
}
|
2010-03-20 12:15:41 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Create a new runtime function with the specified type and name.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty,
|
2011-07-20 14:58:45 +08:00
|
|
|
StringRef Name,
|
2013-01-31 08:30:05 +08:00
|
|
|
llvm::AttributeSet ExtraAttrs =
|
|
|
|
llvm::AttributeSet());
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Create a new runtime global variable with the specified type and name.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
|
2011-07-20 14:58:45 +08:00
|
|
|
StringRef Name);
|
2008-10-01 08:49:24 +08:00
|
|
|
|
2010-07-16 08:00:15 +08:00
|
|
|
///@name Custom Blocks Runtime Interfaces
|
|
|
|
///@{
|
|
|
|
|
|
|
|
llvm::Constant *getNSConcreteGlobalBlock();
|
|
|
|
llvm::Constant *getNSConcreteStackBlock();
|
|
|
|
llvm::Constant *getBlockObjectAssign();
|
|
|
|
llvm::Constant *getBlockObjectDispose();
|
|
|
|
|
|
|
|
///@}
|
|
|
|
|
2013-03-23 14:43:35 +08:00
|
|
|
llvm::Constant *getLLVMLifetimeStartFn();
|
|
|
|
llvm::Constant *getLLVMLifetimeEndFn();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
// Make sure that this type is translated.
|
2011-03-24 00:29:39 +08:00
|
|
|
void UpdateCompletedType(const TagDecl *TD);
|
2009-02-18 02:43:32 +08:00
|
|
|
|
2011-02-03 16:15:49 +08:00
|
|
|
llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Try to emit the initializer for the given declaration as a constant;
|
|
|
|
/// returns 0 if the expression cannot be emitted as a constant.
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Constant *EmitConstantInit(const VarDecl &D,
|
|
|
|
CodeGenFunction *CGF = nullptr);
|
2012-01-14 12:30:29 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Try to emit the given expression as a constant; returns 0 if the
|
|
|
|
/// expression cannot be emitted as a constant.
|
2009-04-08 12:48:15 +08:00
|
|
|
llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
|
2014-05-21 13:09:00 +08:00
|
|
|
CodeGenFunction *CGF = nullptr);
|
2009-02-18 02:43:32 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the given constant value as a constant, in the type's scalar
|
|
|
|
/// representation.
|
2012-01-14 12:30:29 +08:00
|
|
|
llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
|
2014-05-21 13:09:00 +08:00
|
|
|
CodeGenFunction *CGF = nullptr);
|
2012-01-14 12:30:29 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the given constant value as a constant, in the type's memory
|
|
|
|
/// representation.
|
2012-03-03 07:27:11 +08:00
|
|
|
llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
|
|
|
|
QualType DestType,
|
2014-05-21 13:09:00 +08:00
|
|
|
CodeGenFunction *CGF = nullptr);
|
2012-03-03 07:27:11 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the result of value-initializing the given type, i.e. a null
|
|
|
|
/// expression of the given type. This is usually, but not always, an LLVM
|
|
|
|
/// null constant.
|
2009-04-14 05:47:26 +08:00
|
|
|
llvm::Constant *EmitNullConstant(QualType T);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a null constant appropriate for zero-initializing a base class with
|
|
|
|
/// the given type. This is usually, but not always, an LLVM null constant.
|
2011-10-14 10:27:24 +08:00
|
|
|
llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit a general error that something can't be done.
|
2012-03-31 03:44:53 +08:00
|
|
|
void Error(SourceLocation loc, StringRef error);
|
2011-03-18 10:56:14 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Print out an error that codegen doesn't support the specified stmt yet.
|
2013-08-20 05:02:26 +08:00
|
|
|
void ErrorUnsupported(const Stmt *S, const char *Type);
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Print out an error that codegen doesn't support the specified decl yet.
|
2013-08-20 05:02:26 +08:00
|
|
|
void ErrorUnsupported(const Decl *D, const char *Type);
|
2008-05-22 08:50:06 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set the attributes on the LLVM function for the given decl and function
|
|
|
|
/// info. This applies attributes necessary for handling the ABI as well as
|
|
|
|
/// user specified attributes like section.
|
2009-04-17 08:48:04 +08:00
|
|
|
void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
|
|
|
|
const CGFunctionInfo &FI);
|
2008-09-05 07:41:35 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set the LLVM function attributes (sext, zext, etc).
|
2009-04-14 15:08:30 +08:00
|
|
|
void SetLLVMFunctionAttributes(const Decl *D,
|
|
|
|
const CGFunctionInfo &Info,
|
|
|
|
llvm::Function *F);
|
2008-09-10 08:41:16 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set the LLVM function attributes which only apply to a function
|
2014-08-16 04:04:40 +08:00
|
|
|
/// definition.
|
2009-04-14 16:05:55 +08:00
|
|
|
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff the given type uses 'sret' when used as a return type.
|
2010-07-15 07:39:36 +08:00
|
|
|
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff the given type uses an argument slot when 'sret' is used
|
|
|
|
/// as a return type.
|
2014-03-29 21:28:05 +08:00
|
|
|
bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff the given type uses 'fpret' when used as a return type.
|
2010-07-15 07:39:36 +08:00
|
|
|
bool ReturnTypeUsesFPRet(QualType ResultType);
|
2008-09-10 08:41:16 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff the given type uses 'fp2ret' when used as a return type.
|
2011-11-01 00:27:11 +08:00
|
|
|
bool ReturnTypeUsesFP2Ret(QualType ResultType);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Get the LLVM attributes and calling convention to use for a particular
|
|
|
|
/// function type.
|
2009-09-12 08:59:20 +08:00
|
|
|
///
|
|
|
|
/// \param Info - The function type information.
|
|
|
|
/// \param TargetDecl - The decl these attributes are being constructed
|
|
|
|
/// for. If supplied the attributes applied to this decl may contribute to the
|
|
|
|
/// function attributes and calling convention.
|
|
|
|
/// \param PAL [out] - On return, the attribute list to use.
|
|
|
|
/// \param CallingConv [out] - On return, the LLVM calling convention to use.
|
2009-02-03 06:03:45 +08:00
|
|
|
void ConstructAttributeList(const CGFunctionInfo &Info,
|
|
|
|
const Decl *TargetDecl,
|
2009-09-12 08:59:20 +08:00
|
|
|
AttributeListType &PAL,
|
2013-02-22 08:13:35 +08:00
|
|
|
unsigned &CallingConv,
|
|
|
|
bool AttrOnCallSite);
|
2008-09-10 08:41:16 +08:00
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
StringRef getMangledName(GlobalDecl GD);
|
2014-06-06 06:10:59 +08:00
|
|
|
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
|
2009-04-22 01:11:58 +08:00
|
|
|
|
|
|
|
void EmitTentativeDefinition(const VarDecl *D);
|
2009-08-01 02:25:34 +08:00
|
|
|
|
Rework when and how vtables are emitted, by tracking where vtables are
"used" (e.g., we will refer to the vtable in the generated code) and
when they are defined (i.e., because we've seen the key function
definition). Previously, we were effectively tracking "potential
definitions" rather than uses, so we were a bit too eager about emitting
vtables for classes without key functions.
The new scheme:
- For every use of a vtable, Sema calls MarkVTableUsed() to indicate
the use. For example, this occurs when calling a virtual member
function of the class, defining a constructor of that class type,
dynamic_cast'ing from that type to a derived class, casting
to/through a virtual base class, etc.
- For every definition of a vtable, Sema calls MarkVTableUsed() to
indicate the definition. This happens at the end of the translation
unit for classes whose key function has been defined (so we can
delay computation of the key function; see PR6564), and will also
occur with explicit template instantiation definitions.
- For every vtable defined/used, we mark all of the virtual member
functions of that vtable as defined/used, unless we know that the key
function is in another translation unit. This instantiates virtual
member functions when needed.
- At the end of the translation unit, Sema tells CodeGen (via the
ASTConsumer) which vtables must be defined (CodeGen will define
them) and which may be used (for which CodeGen will define the
vtables lazily).
From a language perspective, both the old and the new schemes are
permissible: we're allowed to instantiate virtual member functions
whenever we want per the standard. However, all other C++ compilers
were more lazy than we were, and our eagerness was both a performance
issue (we instantiated too much) and a portability problem (we broke
Boost test cases, which now pass).
Notes:
(1) There's a ton of churn in the tests, because the order in which
vtables get emitted to IR has changed. I've tried to isolate some of
the larger tests from these issues.
(2) Some diagnostics related to
implicitly-instantiated/implicitly-defined virtual member functions
have moved to the point of first use/definition. It's better this
way.
(3) I could use a review of the places where we MarkVTableUsed, to
see if I missed any place where the language effectively requires a
vtable.
Fixes PR7114 and PR6564.
llvm-svn: 103718
2010-05-14 00:44:06 +08:00
|
|
|
void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the RTTI descriptors for the builtin types.
|
2013-09-27 22:48:01 +08:00
|
|
|
void EmitFundamentalRTTIDescriptors();
|
|
|
|
|
2013-05-08 21:44:39 +08:00
|
|
|
/// \brief Appends Opts to the "Linker Options" metadata value.
|
|
|
|
void AppendLinkerOptions(StringRef Opts);
|
|
|
|
|
2013-06-04 17:13:21 +08:00
|
|
|
/// \brief Appends a detect mismatch command to the linker options.
|
2013-06-04 10:07:14 +08:00
|
|
|
void AddDetectMismatch(StringRef Name, StringRef Value);
|
|
|
|
|
2013-05-08 21:44:39 +08:00
|
|
|
/// \brief Appends a dependent lib to the "Linker Options" metadata value.
|
|
|
|
void AddDependentLib(StringRef Lib);
|
|
|
|
|
2013-06-06 01:49:37 +08:00
|
|
|
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
|
2010-02-19 09:32:20 +08:00
|
|
|
|
2014-05-08 22:46:46 +08:00
|
|
|
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
|
|
|
|
F->setLinkage(getFunctionLinkage(GD));
|
2010-05-25 12:30:21 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the appropriate linkage for the vtable, VTT, and type information
|
|
|
|
/// of the given class.
|
2011-01-24 10:04:33 +08:00
|
|
|
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
|
2010-01-26 21:48:07 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the store size, in character units, of the given LLVM type.
|
2011-07-18 12:24:23 +08:00
|
|
|
CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
|
2010-10-28 00:21:54 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns LLVM linkage for a declarator.
|
2014-04-29 06:17:59 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes
|
2014-05-15 03:54:53 +08:00
|
|
|
getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
|
2014-05-28 09:52:23 +08:00
|
|
|
bool IsConstantVariable);
|
2014-04-29 06:17:59 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns LLVM linkage for a declarator.
|
2014-04-29 06:17:59 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes
|
|
|
|
getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
|
|
|
|
|
2011-09-10 06:41:49 +08:00
|
|
|
/// Emit all the global annotations.
|
|
|
|
void EmitGlobalAnnotations();
|
|
|
|
|
|
|
|
/// Emit an annotation string.
|
2013-01-13 03:30:44 +08:00
|
|
|
llvm::Constant *EmitAnnotationString(StringRef Str);
|
2011-09-10 06:41:49 +08:00
|
|
|
|
|
|
|
/// Emit the annotation's translation unit.
|
|
|
|
llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
|
|
|
|
|
|
|
|
/// Emit the annotation line number.
|
|
|
|
llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Generate the llvm::ConstantStruct which contains the annotation
|
|
|
|
/// information for a given GlobalValue. The annotation struct is
|
2011-09-10 06:41:49 +08:00
|
|
|
/// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
|
|
|
|
/// GlobalValue being annotated. The second field is the constant string
|
|
|
|
/// created from the AnnotateAttr's annotation. The third field is a constant
|
|
|
|
/// string containing the name of the translation unit. The fourth field is
|
|
|
|
/// the line number in the file of the annotated value declaration.
|
|
|
|
llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
|
|
|
|
const AnnotateAttr *AA,
|
|
|
|
SourceLocation L);
|
|
|
|
|
|
|
|
/// Add global annotations that are set on D, for the global GV. Those
|
|
|
|
/// annotations are emitted during finalization of the LLVM code.
|
|
|
|
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
|
|
|
|
|
2014-07-10 03:40:08 +08:00
|
|
|
const SanitizerBlacklist &getSanitizerBlacklist() const {
|
|
|
|
return SanitizerBL;
|
2013-01-18 19:30:38 +08:00
|
|
|
}
|
|
|
|
|
2014-08-02 05:35:28 +08:00
|
|
|
SanitizerMetadata *getSanitizerMetadata() {
|
|
|
|
return SanitizerMD.get();
|
|
|
|
}
|
2014-07-03 00:54:41 +08:00
|
|
|
|
2013-01-26 06:31:03 +08:00
|
|
|
void addDeferredVTable(const CXXRecordDecl *RD) {
|
|
|
|
DeferredVTables.push_back(RD);
|
|
|
|
}
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit code for a singal global function or var decl. Forward declarations
|
|
|
|
/// are emitted lazily.
|
[ms-cxxabi] Emit linkonce complete dtors in TUs that need them
Based on Peter Collingbourne's destructor patches.
Prior to this change, clang was considering ?1 to be the complete
destructor and the base destructor, which was wrong. This lead to
crashes when clang tried to emit two LLVM functions with the same name.
In this ABI, TUs with non-inline dtors might not emit a complete
destructor. They are emitted as inline thunks in TUs that need them,
and they always delegate to the base dtors of the complete class and its
virtual bases. This change uses the DeferredDecls machinery to emit
complete dtors as needed.
Currently in clang try body destructors can catch exceptions thrown by
virtual base destructors. In the Microsoft C++ ABI, clang may not have
the destructor definition, in which case clang won't wrap the virtual
virtual base destructor calls in a try-catch. Diagnosing this in user
code is TODO.
Finally, for classes that don't use virtual inheritance, MSVC always
calls the base destructor (?1) directly. This is a useful code size
optimization that avoids emitting lots of extra thunks or aliases.
Implementing it also means our existing tests continue to pass, and is
consistent with MSVC's output.
We can do the same for Itanium by tweaking GetAddrOfCXXDestructor, but
it will require further testing.
Reviewers: rjmccall
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1066
llvm-svn: 186828
2013-07-22 21:51:44 +08:00
|
|
|
void EmitGlobal(GlobalDecl D);
|
|
|
|
|
2014-09-16 02:46:13 +08:00
|
|
|
bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
|
|
|
|
bool InEveryTU);
|
|
|
|
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
|
|
|
|
|
|
|
|
/// Set attributes for a global definition.
|
|
|
|
void setFunctionDefinitionAttributes(const FunctionDecl *D,
|
|
|
|
llvm::Function *F);
|
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
llvm::GlobalValue *GetGlobalValue(StringRef Ref);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-09-16 23:18:21 +08:00
|
|
|
/// Set attributes which are common to any form of a global definition (alias,
|
|
|
|
/// Objective-C method, function, global variable).
|
|
|
|
///
|
|
|
|
/// NOTE: This should only be called for definitions.
|
|
|
|
void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
|
|
|
|
|
2014-09-20 06:06:24 +08:00
|
|
|
/// Set attributes which must be preserved by an alias. This includes common
|
|
|
|
/// attributes (i.e. it includes a call to SetCommonAttributes).
|
|
|
|
///
|
|
|
|
/// NOTE: This should only be called for definitions.
|
|
|
|
void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
|
|
|
|
|
2014-09-16 23:18:21 +08:00
|
|
|
void addReplacement(StringRef Name, llvm::Constant *C);
|
|
|
|
private:
|
|
|
|
|
2013-12-09 12:29:47 +08:00
|
|
|
llvm::Constant *
|
|
|
|
GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D,
|
|
|
|
bool ForVTable, bool DontDefer = false,
|
|
|
|
llvm::AttributeSet ExtraAttrs = llvm::AttributeSet());
|
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::PointerType *PTy,
|
2014-05-23 07:33:27 +08:00
|
|
|
const VarDecl *D);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-14 02:45:53 +08:00
|
|
|
void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
|
2014-05-06 04:21:03 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set function attributes for a function declaration.
|
2010-02-06 10:44:09 +08:00
|
|
|
void SetFunctionAttributes(GlobalDecl GD,
|
2009-05-26 09:22:57 +08:00
|
|
|
llvm::Function *F,
|
|
|
|
bool IsIncompleteFunction);
|
2008-06-08 23:45:52 +08:00
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
|
2009-02-19 15:15:39 +08:00
|
|
|
|
2013-12-10 00:01:03 +08:00
|
|
|
void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
|
2008-07-30 07:18:29 +08:00
|
|
|
void EmitGlobalVarDefinition(const VarDecl *D);
|
2010-03-20 07:29:14 +08:00
|
|
|
void EmitAliasDefinition(GlobalDecl GD);
|
2008-08-26 16:29:31 +08:00
|
|
|
void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
|
2010-04-29 05:28:56 +08:00
|
|
|
void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
|
2010-10-28 00:21:54 +08:00
|
|
|
|
2009-04-15 23:55:24 +08:00
|
|
|
// C++ related functions.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-01 08:58:25 +08:00
|
|
|
void EmitNamespace(const NamespaceDecl *D);
|
2009-04-02 13:55:18 +08:00
|
|
|
void EmitLinkageSpec(const LinkageSpecDecl *D);
|
2013-05-10 07:16:27 +08:00
|
|
|
void CompleteDIClassType(const CXXMethodDecl* D);
|
2009-04-15 23:55:24 +08:00
|
|
|
|
2013-04-20 00:42:07 +08:00
|
|
|
/// \brief Emit the function that initializes C++ thread_local variables.
|
|
|
|
void EmitCXXThreadLocalInitFunc();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the function that initializes C++ globals.
|
2009-08-09 07:24:23 +08:00
|
|
|
void EmitCXXGlobalInitFunc();
|
2010-01-08 08:50:11 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the function that destroys C++ globals.
|
2010-03-20 12:15:41 +08:00
|
|
|
void EmitCXXGlobalDtorFunc();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the function that initializes the specified global (if PerformInit is
|
|
|
|
/// true) and registers its destructor.
|
2010-11-06 17:44:32 +08:00
|
|
|
void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
|
2012-02-14 06:16:19 +08:00
|
|
|
llvm::GlobalVariable *Addr,
|
|
|
|
bool PerformInit);
|
2010-01-08 08:50:11 +08:00
|
|
|
|
2014-07-22 08:53:05 +08:00
|
|
|
void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
|
|
|
|
llvm::Function *InitFunc, InitSegAttr *ISA);
|
|
|
|
|
2008-08-01 08:01:51 +08:00
|
|
|
// FIXME: Hardcoding priority here is gross.
|
2014-05-24 05:13:45 +08:00
|
|
|
void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
|
|
|
|
llvm::Constant *AssociatedData = 0);
|
|
|
|
void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
|
2008-08-01 08:01:51 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Generates a global array of functions and priorities using the given list
|
|
|
|
/// and name. This array will have appending linkage and is suitable for use
|
|
|
|
/// as a LLVM constructor or destructor array.
|
2008-08-01 08:01:51 +08:00
|
|
|
void EmitCtorList(const CtorList &Fns, const char *GlobalName);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the RTTI descriptors for the given type.
|
2010-03-27 10:52:14 +08:00
|
|
|
void EmitFundamentalRTTIDescriptor(QualType Type);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit any needed decls for which code generation was deferred.
|
2012-11-15 22:28:07 +08:00
|
|
|
void EmitDeferred();
|
2009-02-14 04:29:50 +08:00
|
|
|
|
2013-11-06 05:37:29 +08:00
|
|
|
/// Call replaceAllUsesWith on all pairs in Replacements.
|
|
|
|
void applyReplacements();
|
|
|
|
|
2013-10-23 03:26:13 +08:00
|
|
|
void checkAliases();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit any vtables which we deferred and still have a use for.
|
2013-01-26 06:31:03 +08:00
|
|
|
void EmitDeferredVTables();
|
|
|
|
|
2014-03-07 06:15:10 +08:00
|
|
|
/// Emit the llvm.used and llvm.compiler.used metadata.
|
|
|
|
void emitLLVMUsed();
|
2008-10-01 08:49:24 +08:00
|
|
|
|
2013-01-15 04:53:57 +08:00
|
|
|
/// \brief Emit the link options introduced by imported modules.
|
|
|
|
void EmitModuleLinkOptions();
|
|
|
|
|
2013-04-06 13:00:46 +08:00
|
|
|
/// \brief Emit aliases for internal-linkage declarations inside "C" language
|
|
|
|
/// linkage specifications, giving them the "expected" name where possible.
|
|
|
|
void EmitStaticExternCAliases();
|
|
|
|
|
2010-07-07 07:57:41 +08:00
|
|
|
void EmitDeclMetadata();
|
|
|
|
|
2013-10-17 03:28:50 +08:00
|
|
|
/// \brief Emit the Clang version as llvm.ident metadata.
|
|
|
|
void EmitVersionIdentMetadata();
|
|
|
|
|
2014-07-03 17:30:33 +08:00
|
|
|
/// Emits target specific Metadata for global declarations.
|
|
|
|
void EmitTargetMetadata();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
|
|
|
|
/// .gcda files in a way that persists in .bc files.
|
2011-05-05 08:08:20 +08:00
|
|
|
void EmitCoverageFile();
|
2011-05-05 04:46:58 +08:00
|
|
|
|
2012-10-11 18:13:44 +08:00
|
|
|
/// Emits the initializer for a uuidof string.
|
2014-09-09 00:26:36 +08:00
|
|
|
llvm::Constant *EmitUuidofInitializer(StringRef uuidstr);
|
2012-10-11 18:13:44 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Determine if the given decl can be emitted lazily; this is only relevant
|
|
|
|
/// for definitions. The given decl must be either a function or var decl.
|
2009-02-14 05:18:01 +08:00
|
|
|
bool MayDeferGeneration(const ValueDecl *D);
|
2010-09-16 14:16:50 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Check whether we can use a "simpler", more core exceptions personality
|
|
|
|
/// function.
|
2010-09-16 14:16:50 +08:00
|
|
|
void SimplifyPersonality();
|
2007-05-24 14:29:05 +08:00
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|