Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1 | //===--- CGVtable.h - Emit LLVM Code for C++ vtables ----------------------===// |
| 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 | |
| 17 | #include "llvm/ADT/DenseMap.h" |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 18 | #include "GlobalDecl.h" |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 19 | |
| 20 | namespace clang { |
| 21 | class CXXMethodDecl; |
| 22 | class CXXRecordDecl; |
| 23 | |
| 24 | namespace CodeGen { |
| 25 | class CodeGenModule; |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 26 | |
| 27 | /// ThunkAdjustment - Virtual and non-virtual adjustment for thunks. |
| 28 | struct ThunkAdjustment { |
| 29 | ThunkAdjustment(int64_t NonVirtual, int64_t Virtual) |
| 30 | : NonVirtual(NonVirtual), |
| 31 | Virtual(Virtual) { } |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 32 | |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 33 | ThunkAdjustment() |
| 34 | : NonVirtual(0), Virtual(0) { } |
| 35 | |
| 36 | // isEmpty - Return whether this thunk adjustment is empty. |
| 37 | bool isEmpty() const { |
| 38 | return NonVirtual == 0 && Virtual == 0; |
| 39 | } |
| 40 | |
| 41 | /// NonVirtual - The non-virtual adjustment. |
| 42 | int64_t NonVirtual; |
| 43 | |
| 44 | /// Virtual - The virtual adjustment. |
| 45 | int64_t Virtual; |
| 46 | }; |
| 47 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 48 | class CGVtableInfo { |
| 49 | CodeGenModule &CGM; |
| 50 | |
| 51 | /// MethodVtableIndices - Contains the index (relative to the vtable address |
| 52 | /// point) where the function pointer for a virtual function is stored. |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 53 | typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVtableIndicesTy; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 54 | MethodVtableIndicesTy MethodVtableIndices; |
| 55 | |
| 56 | typedef std::pair<const CXXRecordDecl *, |
| 57 | const CXXRecordDecl *> ClassPairTy; |
| 58 | |
| 59 | /// VirtualBaseClassIndicies - Contains the index into the vtable where the |
| 60 | /// offsets for virtual bases of a class are stored. |
| 61 | typedef llvm::DenseMap<ClassPairTy, int64_t> VirtualBaseClassIndiciesTy; |
| 62 | VirtualBaseClassIndiciesTy VirtualBaseClassIndicies; |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 63 | |
| 64 | llvm::DenseMap<const CXXRecordDecl *, llvm::Constant *> Vtables; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 65 | public: |
| 66 | CGVtableInfo(CodeGenModule &CGM) |
| 67 | : CGM(CGM) { } |
| 68 | |
| 69 | /// getMethodVtableIndex - Return the index (relative to the vtable address |
| 70 | /// point) where the function pointer for the given virtual function is |
| 71 | /// stored. |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 72 | int64_t getMethodVtableIndex(GlobalDecl GD); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 73 | |
Mike Stump | ab28c13 | 2009-10-13 22:54:56 +0000 | [diff] [blame] | 74 | /// getVirtualBaseOffsetIndex - Return the index (relative to the vtable |
| 75 | /// address point) where the offset of the virtual base that contains the |
| 76 | /// given Base is stored, otherwise, if no virtual base contains the given |
| 77 | /// class, return 0. Base must be a virtual base class or an unambigious |
| 78 | /// base. |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 79 | int64_t getVirtualBaseOffsetIndex(const CXXRecordDecl *RD, |
| 80 | const CXXRecordDecl *VBase); |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 81 | |
Mike Stump | 8cfcb52 | 2009-11-11 20:26:26 +0000 | [diff] [blame] | 82 | llvm::Constant *getVtable(const CXXRecordDecl *RD); |
| 83 | llvm::Constant *getCtorVtable(const CXXRecordDecl *RD, |
| 84 | const CXXRecordDecl *Class, uint64_t Offset); |
Mike Stump | 5858894 | 2009-11-19 01:08:19 +0000 | [diff] [blame] | 85 | /// GenerateClassData - Generate all the class data requires to be generated |
| 86 | /// upon definition of a KeyFunction. This includes the vtable, the |
| 87 | /// rtti data structure and the VTT. |
| 88 | void GenerateClassData(const CXXRecordDecl *RD); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } |
| 92 | } |
| 93 | #endif |