aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.h')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h100
1 files changed, 72 insertions, 28 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index 618e2f857b07..47dc6f415b60 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -25,9 +25,10 @@
#include "clang/Basic/ABI.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/Module.h"
-#include "clang/Basic/SanitizerBlacklist.h"
+#include "clang/Basic/NoSanitizeList.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/XRayLists.h"
+#include "clang/Lex/PreprocessorOptions.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -72,7 +73,6 @@ class VarDecl;
class LangOptions;
class CodeGenOptions;
class HeaderSearchOptions;
-class PreprocessorOptions;
class DiagnosticsEngine;
class AnnotateAttr;
class CXXDestructorDecl;
@@ -103,17 +103,17 @@ enum ForDefinition_t : bool {
ForDefinition = true
};
-struct OrderGlobalInits {
+struct OrderGlobalInitsOrStermFinalizers {
unsigned int priority;
unsigned int lex_order;
- OrderGlobalInits(unsigned int p, unsigned int l)
+ OrderGlobalInitsOrStermFinalizers(unsigned int p, unsigned int l)
: priority(p), lex_order(l) {}
- bool operator==(const OrderGlobalInits &RHS) const {
+ bool operator==(const OrderGlobalInitsOrStermFinalizers &RHS) const {
return priority == RHS.priority && lex_order == RHS.lex_order;
}
- bool operator<(const OrderGlobalInits &RHS) const {
+ bool operator<(const OrderGlobalInitsOrStermFinalizers &RHS) const {
return std::tie(priority, lex_order) <
std::tie(RHS.priority, RHS.lex_order);
}
@@ -210,6 +210,9 @@ struct ObjCEntrypoints {
/// void clang.arc.use(...);
llvm::Function *clang_arc_use;
+
+ /// void clang.arc.noop.use(...);
+ llvm::Function *clang_arc_noop_use;
};
/// This class records statistics on instrumentation based profiling.
@@ -308,6 +311,7 @@ private:
const TargetInfo &Target;
std::unique_ptr<CGCXXABI> ABI;
llvm::LLVMContext &VMContext;
+ std::string ModuleNameHash = "";
std::unique_ptr<CodeGenTBAA> TBAA;
@@ -453,7 +457,8 @@ private:
/// that we don't re-emit the initializer.
llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
- typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
+ typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
+ GlobalInitData;
struct GlobalInitPriorityCmp {
bool operator()(const GlobalInitData &LHS,
@@ -469,10 +474,26 @@ private:
/// Global destructor functions and arguments that need to run on termination.
/// When UseSinitAndSterm is set, it instead contains sterm finalizer
/// functions, which also run on unloading a shared library.
- std::vector<
- std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH, llvm::Constant *>>
+ typedef std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
+ llvm::Constant *>
+ CXXGlobalDtorsOrStermFinalizer_t;
+ SmallVector<CXXGlobalDtorsOrStermFinalizer_t, 8>
CXXGlobalDtorsOrStermFinalizers;
+ typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
+ StermFinalizerData;
+
+ struct StermFinalizerPriorityCmp {
+ bool operator()(const StermFinalizerData &LHS,
+ const StermFinalizerData &RHS) const {
+ return LHS.first.priority < RHS.first.priority;
+ }
+ };
+
+ /// Global variables with sterm finalizers whose order of initialization is
+ /// set by init_priority attribute.
+ SmallVector<StermFinalizerData, 8> PrioritizedCXXStermFinalizers;
+
/// The complete set of modules that has been imported.
llvm::SetVector<clang::Module *> ImportedModules;
@@ -583,6 +604,8 @@ public:
/// Return true iff an Objective-C runtime has been configured.
bool hasObjCRuntime() { return !!ObjCRuntime; }
+ const std::string &getModuleNameHash() const { return ModuleNameHash; }
+
/// Return a reference to the configured OpenCL runtime.
CGOpenCLRuntime &getOpenCLRuntime() {
assert(OpenCLRuntime != nullptr);
@@ -832,6 +855,13 @@ public:
/// space, target-specific global or constant address space may be returned.
LangAS GetGlobalVarAddressSpace(const VarDecl *D);
+ /// Return the AST address space of constant literal, which is used to emit
+ /// the constant literal as global variable in LLVM IR.
+ /// Note: This is not necessarily the address space of the constant literal
+ /// in AST. For address space agnostic language, e.g. C++, constant literal
+ /// in AST is always in default address space.
+ LangAS GetGlobalConstantAddressSpace() const;
+
/// 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 created
/// with the specified type instead of whatever the normal requested type
@@ -843,13 +873,6 @@ public:
ForDefinition_t IsForDefinition
= NotForDefinition);
- /// Return the AST address space of string literal, which is used to emit
- /// the string literal as global variable in LLVM IR.
- /// Note: This is not necessarily the address space of the string literal
- /// in AST. For address space agnostic language, e.g. C++, string literal
- /// in AST is always in default address space.
- LangAS getStringLiteralAddressSpace() const;
-
/// 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.
llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
@@ -1051,6 +1074,9 @@ public:
/// Add a global to a list to be added to the llvm.compiler.used metadata.
void addCompilerUsedGlobal(llvm::GlobalValue *GV);
+ /// Add a global to a list to be added to the llvm.compiler.used metadata.
+ void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV);
+
/// Add a destructor and object to add to the C++ global destructor function.
void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object) {
CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
@@ -1069,6 +1095,14 @@ public:
AddGlobalDtor(StermFinalizer, Priority);
}
+ void AddCXXPrioritizedStermFinalizerEntry(llvm::Function *StermFinalizer,
+ int Priority) {
+ OrderGlobalInitsOrStermFinalizers Key(Priority,
+ PrioritizedCXXStermFinalizers.size());
+ PrioritizedCXXStermFinalizers.push_back(
+ std::make_pair(Key, StermFinalizer));
+ }
+
/// Create or return a runtime function declaration with the specified type
/// and name. If \p AssumeConvergent is true, the call will have the
/// convergent attribute added.
@@ -1130,7 +1164,7 @@ public:
/// Set the LLVM function attributes (sext, zext, etc).
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info,
- llvm::Function *F);
+ llvm::Function *F, bool IsThunk);
/// Set the LLVM function attributes which only apply to a function
/// definition.
@@ -1166,7 +1200,7 @@ public:
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
CGCalleeInfo CalleeInfo,
llvm::AttributeList &Attrs, unsigned &CallingConv,
- bool AttrOnCallSite);
+ bool AttrOnCallSite, bool IsThunk);
/// Adds attributes to F according to our CodeGenOptions and LangOptions, as
/// though we had emitted it ourselves. We remove any attributes on F that
@@ -1264,12 +1298,11 @@ public:
/// annotations are emitted during finalization of the LLVM code.
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
- bool isInSanitizerBlacklist(SanitizerMask Kind, llvm::Function *Fn,
- SourceLocation Loc) const;
+ bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
+ SourceLocation Loc) const;
- bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
- QualType Ty,
- StringRef Category = StringRef()) const;
+ bool isInNoSanitizeList(llvm::GlobalVariable *GV, SourceLocation Loc,
+ QualType Ty, StringRef Category = StringRef()) const;
/// Imbue XRay attributes to a function, applying the always/never attribute
/// lists in the process. Returns true if we did imbue attributes this way,
@@ -1323,6 +1356,10 @@ public:
/// \param D Requires declaration
void EmitOMPRequiresDecl(const OMPRequiresDecl *D);
+ /// Emit a code for the allocate directive.
+ /// \param D The allocate declaration
+ void EmitOMPAllocateDecl(const OMPAllocateDecl *D);
+
/// Returns whether the given record has hidden LTO visibility and therefore
/// may participate in (single-module) CFI and whole-program vtable
/// optimization.
@@ -1369,6 +1406,10 @@ public:
void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD,
llvm::Function *F);
+ /// Whether this function's return type has no side effects, and thus may
+ /// be trivially discarded if it is unused.
+ bool MayDropFunctionReturn(const ASTContext &Context, QualType ReturnType);
+
/// Returns whether this module needs the "all-vtables" type identifier.
bool NeedAllVtablesTypeId() const;
@@ -1420,6 +1461,10 @@ public:
TBAAAccessInfo *TBAAInfo = nullptr);
bool stopAutoInit();
+ /// Print the postfix for externalized static variable for single source
+ /// offloading languages CUDA and HIP.
+ void printPostfixForExternalizedStaticVar(llvm::raw_ostream &OS) const;
+
private:
llvm::Constant *GetOrCreateLLVMFunction(
StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
@@ -1432,11 +1477,10 @@ private:
const FunctionDecl *FD);
void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD);
- llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
- llvm::PointerType *PTy,
- const VarDecl *D,
- ForDefinition_t IsForDefinition
- = NotForDefinition);
+ llvm::Constant *
+ GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
+ unsigned AddrSpace, const VarDecl *D,
+ ForDefinition_t IsForDefinition = NotForDefinition);
bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
llvm::AttrBuilder &AttrBuilder);