John McCall | bda0d6b | 2011-03-27 09:00:25 +0000 | [diff] [blame] | 1 | //===--- CGVTables.h - Emit LLVM Code for C++ vtables -----------*- C++ -*-===// |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code dealing with C++ code generation of virtual tables. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CLANG_CODEGEN_CGVTABLE_H |
| 15 | #define CLANG_CODEGEN_CGVTABLE_H |
| 16 | |
Peter Collingbourne | 33446f1 | 2011-09-26 01:56:16 +0000 | [diff] [blame] | 17 | #include "clang/AST/BaseSubobject.h" |
Ken Dyck | 4230d52 | 2011-03-24 01:21:01 +0000 | [diff] [blame] | 18 | #include "clang/AST/CharUnits.h" |
Peter Collingbourne | fd05ca0 | 2011-06-14 04:02:39 +0000 | [diff] [blame] | 19 | #include "clang/AST/GlobalDecl.h" |
Peter Collingbourne | 2401846 | 2011-09-26 01:57:12 +0000 | [diff] [blame] | 20 | #include "clang/AST/VTableBuilder.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/Basic/ABI.h" |
| 22 | #include "llvm/ADT/DenseMap.h" |
Chandler Carruth | 3b844ba | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 23 | #include "llvm/IR/GlobalVariable.h" |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 24 | |
| 25 | namespace clang { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 26 | class CXXRecordDecl; |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 27 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 28 | namespace CodeGen { |
| 29 | class CodeGenModule; |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 30 | |
Peter Collingbourne | 1d2b317 | 2011-09-26 01:56:30 +0000 | [diff] [blame] | 31 | class CodeGenVTables { |
| 32 | CodeGenModule &CGM; |
| 33 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 34 | VTableContextBase *VTContext; |
| 35 | |
Anders Carlsson | 2c822f1 | 2010-03-26 03:56:54 +0000 | [diff] [blame] | 36 | /// VTableAddressPointsMapTy - Address points for a single vtable. |
| 37 | typedef llvm::DenseMap<BaseSubobject, uint64_t> VTableAddressPointsMapTy; |
| 38 | |
Peter Collingbourne | 84fcc48 | 2011-09-26 01:56:41 +0000 | [diff] [blame] | 39 | typedef std::pair<const CXXRecordDecl *, BaseSubobject> BaseSubobjectPairTy; |
Anders Carlsson | 3855a07 | 2010-05-03 00:55:11 +0000 | [diff] [blame] | 40 | typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t> SubVTTIndiciesMapTy; |
Anders Carlsson | e1dcc22 | 2010-03-26 04:23:58 +0000 | [diff] [blame] | 41 | |
| 42 | /// SubVTTIndicies - Contains indices into the various sub-VTTs. |
| 43 | SubVTTIndiciesMapTy SubVTTIndicies; |
| 44 | |
Anders Carlsson | 3855a07 | 2010-05-03 00:55:11 +0000 | [diff] [blame] | 45 | typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t> |
Anders Carlsson | e1dcc22 | 2010-03-26 04:23:58 +0000 | [diff] [blame] | 46 | SecondaryVirtualPointerIndicesMapTy; |
| 47 | |
| 48 | /// SecondaryVirtualPointerIndices - Contains the secondary virtual pointer |
| 49 | /// indices. |
| 50 | SecondaryVirtualPointerIndicesMapTy SecondaryVirtualPointerIndices; |
Anders Carlsson | c997d42 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 51 | |
Timur Iskhodzhanov | 2cb17a0 | 2013-10-09 09:23:58 +0000 | [diff] [blame] | 52 | /// emitThunk - Emit a single thunk. |
| 53 | void emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, bool ForVTable); |
Anders Carlsson | 14e82fd | 2011-02-06 18:31:40 +0000 | [diff] [blame] | 54 | |
Timur Iskhodzhanov | 2cb17a0 | 2013-10-09 09:23:58 +0000 | [diff] [blame] | 55 | /// maybeEmitThunkForVTable - Emit the given thunk for the vtable if needed by |
| 56 | /// the ABI. |
| 57 | void maybeEmitThunkForVTable(GlobalDecl GD, const ThunkInfo &Thunk); |
Anders Carlsson | 14e82fd | 2011-02-06 18:31:40 +0000 | [diff] [blame] | 58 | |
Timur Iskhodzhanov | a53d7a0 | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 59 | public: |
Anders Carlsson | 0d1407e | 2010-03-25 15:26:28 +0000 | [diff] [blame] | 60 | /// CreateVTableInitializer - Create a vtable initializer for the given record |
| 61 | /// decl. |
| 62 | /// \param Components - The vtable components; this is really an array of |
| 63 | /// VTableComponents. |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 64 | llvm::Constant *CreateVTableInitializer( |
| 65 | const CXXRecordDecl *RD, const VTableComponent *Components, |
| 66 | unsigned NumComponents, const VTableLayout::VTableThunkTy *VTableThunks, |
| 67 | unsigned NumVTableThunks, llvm::Constant *RTTI); |
Anders Carlsson | 2c822f1 | 2010-03-26 03:56:54 +0000 | [diff] [blame] | 68 | |
Peter Collingbourne | 1d2b317 | 2011-09-26 01:56:30 +0000 | [diff] [blame] | 69 | CodeGenVTables(CodeGenModule &CGM); |
| 70 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 71 | ItaniumVTableContext &getItaniumVTableContext() { |
| 72 | return *cast<ItaniumVTableContext>(VTContext); |
| 73 | } |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 74 | |
Timur Iskhodzhanov | 5f0db58 | 2013-11-05 15:54:58 +0000 | [diff] [blame] | 75 | MicrosoftVTableContext &getMicrosoftVTableContext() { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 76 | return *cast<MicrosoftVTableContext>(VTContext); |
Timur Iskhodzhanov | 5f0db58 | 2013-11-05 15:54:58 +0000 | [diff] [blame] | 77 | } |
Timur Iskhodzhanov | 8f189a9 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 78 | |
Anders Carlsson | c997d42 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 79 | /// getSubVTTIndex - Return the index of the sub-VTT for the base class of the |
| 80 | /// given record decl. |
Anders Carlsson | c11bb21 | 2010-05-02 23:53:25 +0000 | [diff] [blame] | 81 | uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base); |
Anders Carlsson | c997d42 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 82 | |
Anders Carlsson | e1dcc22 | 2010-03-26 04:23:58 +0000 | [diff] [blame] | 83 | /// getSecondaryVirtualPointerIndex - Return the index in the VTT where the |
| 84 | /// virtual pointer for the given subobject is located. |
| 85 | uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD, |
| 86 | BaseSubobject Base); |
| 87 | |
Anders Carlsson | 64c9eca | 2010-03-29 02:08:26 +0000 | [diff] [blame] | 88 | /// getAddressPoint - Get the address point of the given subobject in the |
| 89 | /// class decl. |
| 90 | uint64_t getAddressPoint(BaseSubobject Base, const CXXRecordDecl *RD); |
| 91 | |
Anders Carlsson | ff143f8 | 2010-03-25 00:35:49 +0000 | [diff] [blame] | 92 | /// GenerateConstructionVTable - Generate a construction vtable for the given |
| 93 | /// base subobject. |
| 94 | llvm::GlobalVariable * |
| 95 | GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base, |
| 96 | bool BaseIsVirtual, |
John McCall | bda0d6b | 2011-03-27 09:00:25 +0000 | [diff] [blame] | 97 | llvm::GlobalVariable::LinkageTypes Linkage, |
Anders Carlsson | 2c822f1 | 2010-03-26 03:56:54 +0000 | [diff] [blame] | 98 | VTableAddressPointsMapTy& AddressPoints); |
Anders Carlsson | 1cbce12 | 2011-01-29 19:16:51 +0000 | [diff] [blame] | 99 | |
| 100 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 101 | /// GetAddrOfVTT - Get the address of the VTT for the given record decl. |
Anders Carlsson | 1cbce12 | 2011-01-29 19:16:51 +0000 | [diff] [blame] | 102 | llvm::GlobalVariable *GetAddrOfVTT(const CXXRecordDecl *RD); |
| 103 | |
| 104 | /// EmitVTTDefinition - Emit the definition of the given vtable. |
| 105 | void EmitVTTDefinition(llvm::GlobalVariable *VTT, |
| 106 | llvm::GlobalVariable::LinkageTypes Linkage, |
| 107 | const CXXRecordDecl *RD); |
Rafael Espindola | bbf58bb | 2010-03-10 02:19:29 +0000 | [diff] [blame] | 108 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 109 | /// EmitThunks - Emit the associated thunks for the given global decl. |
| 110 | void EmitThunks(GlobalDecl GD); |
| 111 | |
John McCall | d5617ee | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 112 | /// GenerateClassData - Generate all the class data required to be |
| 113 | /// generated upon definition of a KeyFunction. This includes the |
| 114 | /// vtable, the RTTI data structure (if RTTI is enabled) and the VTT |
| 115 | /// (if the class has virtual bases). |
| 116 | void GenerateClassData(const CXXRecordDecl *RD); |
| 117 | |
| 118 | bool isVTableExternal(const CXXRecordDecl *RD); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 119 | }; |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 120 | |
Anders Carlsson | 1bb6099 | 2010-01-14 02:29:07 +0000 | [diff] [blame] | 121 | } // end namespace CodeGen |
| 122 | } // end namespace clang |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 123 | #endif |