diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
commit | cfca06d7963fa0909f90483b42a6d7d194d01e08 (patch) | |
tree | 209fb2a2d68f8f277793fc8df46c753d31bc853b /clang/lib/CodeGen/CodeGenModule.h | |
parent | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff) |
Notes
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.h')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 102 |
1 files changed, 70 insertions, 32 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 115e754bb392..a6c4a1f7b278 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -26,6 +26,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/Module.h" #include "clang/Basic/SanitizerBlacklist.h" +#include "clang/Basic/TargetInfo.h" #include "clang/Basic/XRayLists.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SetVector.h" @@ -301,6 +302,7 @@ private: const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info. const PreprocessorOptions &PreprocessorOpts; // Only used for debug info. const CodeGenOptions &CodeGenOpts; + unsigned NumAutoVarInit = 0; llvm::Module &TheModule; DiagnosticsEngine &Diags; const TargetInfo &Target; @@ -322,7 +324,6 @@ private: std::unique_ptr<CGObjCRuntime> ObjCRuntime; std::unique_ptr<CGOpenCLRuntime> OpenCLRuntime; std::unique_ptr<CGOpenMPRuntime> OpenMPRuntime; - std::unique_ptr<llvm::OpenMPIRBuilder> OMPBuilder; std::unique_ptr<CGCUDARuntime> CUDARuntime; std::unique_ptr<CGDebugInfo> DebugInfo; std::unique_ptr<ObjCEntrypoints> ObjCData; @@ -395,6 +396,10 @@ private: /// emitted when the translation unit is complete. CtorList GlobalDtors; + /// A unique trailing identifier as a part of sinit/sterm function when + /// UseSinitAndSterm of CXXABI is set as true. + std::string GlobalUniqueModuleId; + /// An ordered map of canonical GlobalDecls to their mangled names. llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames; llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings; @@ -463,9 +468,11 @@ private: SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits; /// 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 *>> - CXXGlobalDtors; + CXXGlobalDtorsOrStermFinalizers; /// The complete set of modules that has been imported. llvm::SetVector<clang::Module *> ImportedModules; @@ -589,9 +596,6 @@ public: return *OpenMPRuntime; } - /// Return a pointer to the configured OpenMPIRBuilder, if any. - llvm::OpenMPIRBuilder *getOpenMPIRBuilder() { return OMPBuilder.get(); } - /// Return a reference to the configured CUDA runtime. CGCUDARuntime &getCUDARuntime() { assert(CUDARuntime != nullptr); @@ -788,6 +792,9 @@ public: /// variable declaration D. void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const; + /// Get LLVM TLS mode from CodeGenOptions. + llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const; + static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) { switch (V) { case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility; @@ -810,11 +817,10 @@ public: llvm::GlobalValue::LinkageTypes Linkage, unsigned Alignment); - llvm::Function * - CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name, - const CGFunctionInfo &FI, - SourceLocation Loc = SourceLocation(), - bool TLS = false); + llvm::Function *CreateGlobalInitOrCleanUpFunction( + llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI, + SourceLocation Loc = SourceLocation(), bool TLS = false, + bool IsExternalLinkage = false); /// Return the AST address space of the underlying global variable for D, as /// determined by its declaration. Normally this is the same as the address @@ -855,8 +861,8 @@ public: /// Get the address of the RTTI descriptor for the given type. llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); - /// Get the address of a uuid descriptor . - ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr* E); + /// Get the address of a GUID. + ConstantAddress GetAddrOfMSGuidDecl(const MSGuidDecl *GD); /// Get the address of the thunk for the given global decl. llvm::Constant *GetAddrOfThunk(StringRef Name, llvm::Type *FnTy, @@ -868,6 +874,17 @@ public: /// Returns the assumed alignment of an opaque pointer to the given class. CharUnits getClassPointerAlignment(const CXXRecordDecl *CD); + /// Returns the minimum object size for an object of the given class type + /// (or a class derived from it). + CharUnits getMinimumClassObjectSize(const CXXRecordDecl *CD); + + /// Returns the minimum object size for an object of the given type. + CharUnits getMinimumObjectSize(QualType Ty) { + if (CXXRecordDecl *RD = Ty->getAsCXXRecordDecl()) + return getMinimumClassObjectSize(RD); + return getContext().getTypeSizeInChars(Ty); + } + /// Returns the assumed alignment of a virtual base of a class. CharUnits getVBaseAlignment(CharUnits DerivedAlign, const CXXRecordDecl *Derived, @@ -1012,6 +1029,9 @@ public: /// for the uninstrumented functions. void EmitDeferredUnusedCoverageMappings(); + /// Emit an alias for "main" if it has no arguments (needed for wasm). + void EmitMainVoidAlias(); + /// Tell the consumer that this variable has been instantiated. void HandleCXXStaticMemberVarInstantiation(VarDecl *VD); @@ -1029,8 +1049,14 @@ public: /// Add a destructor and object to add to the C++ global destructor function. void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object) { - CXXGlobalDtors.emplace_back(DtorFn.getFunctionType(), DtorFn.getCallee(), - Object); + CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(), + DtorFn.getCallee(), Object); + } + + /// Add an sterm finalizer to the C++ global cleanup function. + void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn) { + CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(), + DtorFn.getCallee(), nullptr); } /// Create or return a runtime function declaration with the specified type @@ -1155,7 +1181,11 @@ public: /// on the function more conservative. But it's unsafe to call this on a /// function which relies on particular fast-math attributes for correctness. /// It's up to you to ensure that this is safe. - void AddDefaultFnAttrs(llvm::Function &F); + void addDefaultFunctionDefinitionAttributes(llvm::Function &F); + + /// Like the overload taking a `Function &`, but intended specifically + /// for frontends that want to build on Clang's target-configuration logic. + void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs); StringRef getMangledName(GlobalDecl GD); StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD); @@ -1282,16 +1312,16 @@ public: /// \param D Requires declaration void EmitOMPRequiresDecl(const OMPRequiresDecl *D); - /// Emits the definition of \p OldGD function with body from \p NewGD. - /// Required for proper handling of declare variant directive on the GPU. - void emitOpenMPDeviceFunctionRedefinition(GlobalDecl OldGD, GlobalDecl NewGD, - llvm::GlobalValue *GV); - /// Returns whether the given record has hidden LTO visibility and therefore /// may participate in (single-module) CFI and whole-program vtable /// optimization. bool HasHiddenLTOVisibility(const CXXRecordDecl *RD); + /// Returns whether the given record has public std LTO visibility + /// and therefore may not participate in (single-module) CFI and whole-program + /// vtable optimization. + bool HasLTOVisibilityPublicStd(const CXXRecordDecl *RD); + /// Returns the vcall visibility of the given type. This is the scope in which /// a virtual function call could be made which ends up being dispatched to a /// member function of this class. This scope can be wider than the visibility @@ -1367,6 +1397,15 @@ public: /// \param QT is the clang QualType of the null pointer. llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT); + CharUnits getNaturalTypeAlignment(QualType T, + LValueBaseInfo *BaseInfo = nullptr, + TBAAAccessInfo *TBAAInfo = nullptr, + bool forPointeeType = false); + CharUnits getNaturalPointeeTypeAlignment(QualType T, + LValueBaseInfo *BaseInfo = nullptr, + TBAAAccessInfo *TBAAInfo = nullptr); + bool stopAutoInit(); + private: llvm::Constant *GetOrCreateLLVMFunction( StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable, @@ -1417,8 +1456,8 @@ private: /// Emit the function that initializes C++ globals. void EmitCXXGlobalInitFunc(); - /// Emit the function that destroys C++ globals. - void EmitCXXGlobalDtorFunc(); + /// Emit the function that performs cleanup associated with C++ globals. + void EmitCXXGlobalCleanUpFunc(); /// Emit the function that initializes the specified global (if PerformInit is /// true) and registers its destructor. @@ -1489,8 +1528,9 @@ private: /// Emit the Clang commandline as llvm.commandline metadata. void EmitCommandLineMetadata(); - /// Emits target specific Metadata for global declarations. - void EmitTargetMetadata(); + /// Emit the module flag metadata used to pass options controlling the + /// the backend to LLVM. + void EmitBackendOptionsMetadata(const CodeGenOptions CodeGenOpts); /// Emits OpenCL specific Metadata e.g. OpenCL version. void EmitOpenCLMetadata(); @@ -1499,9 +1539,6 @@ private: /// .gcda files in a way that persists in .bc files. void EmitCoverageFile(); - /// Emits the initializer for a uuidof string. - llvm::Constant *EmitUuidofInitializer(StringRef uuidstr); - /// Determine whether the definition must be emitted; if this returns \c /// false, the definition can be emitted lazily if it's used. bool MustBeEmitted(const ValueDecl *D); @@ -1516,11 +1553,12 @@ private: /// function. void SimplifyPersonality(); - /// Helper function for ConstructAttributeList and AddDefaultFnAttrs. - /// Constructs an AttrList for a function with the given properties. - void ConstructDefaultFnAttrList(StringRef Name, bool HasOptnone, - bool AttrOnCallSite, - llvm::AttrBuilder &FuncAttrs); + /// Helper function for ConstructAttributeList and + /// addDefaultFunctionDefinitionAttributes. Builds a set of function + /// attributes to add to a function with the given properties. + void getDefaultFunctionAttributes(StringRef Name, bool HasOptnone, + bool AttrOnCallSite, + llvm::AttrBuilder &FuncAttrs); llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map, StringRef Suffix); |