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