clang API Documentation
00001 //===--- CGVTables.h - Emit LLVM Code for C++ vtables -----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This contains code dealing with C++ code generation of virtual tables. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_LIB_CODEGEN_CGVTABLES_H 00015 #define LLVM_CLANG_LIB_CODEGEN_CGVTABLES_H 00016 00017 #include "clang/AST/BaseSubobject.h" 00018 #include "clang/AST/CharUnits.h" 00019 #include "clang/AST/GlobalDecl.h" 00020 #include "clang/AST/VTableBuilder.h" 00021 #include "clang/Basic/ABI.h" 00022 #include "llvm/ADT/DenseMap.h" 00023 #include "llvm/IR/GlobalVariable.h" 00024 00025 namespace clang { 00026 class CXXRecordDecl; 00027 00028 namespace CodeGen { 00029 class CodeGenModule; 00030 00031 class CodeGenVTables { 00032 CodeGenModule &CGM; 00033 00034 VTableContextBase *VTContext; 00035 00036 /// VTableAddressPointsMapTy - Address points for a single vtable. 00037 typedef llvm::DenseMap<BaseSubobject, uint64_t> VTableAddressPointsMapTy; 00038 00039 typedef std::pair<const CXXRecordDecl *, BaseSubobject> BaseSubobjectPairTy; 00040 typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t> SubVTTIndiciesMapTy; 00041 00042 /// SubVTTIndicies - Contains indices into the various sub-VTTs. 00043 SubVTTIndiciesMapTy SubVTTIndicies; 00044 00045 typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t> 00046 SecondaryVirtualPointerIndicesMapTy; 00047 00048 /// SecondaryVirtualPointerIndices - Contains the secondary virtual pointer 00049 /// indices. 00050 SecondaryVirtualPointerIndicesMapTy SecondaryVirtualPointerIndices; 00051 00052 /// emitThunk - Emit a single thunk. 00053 void emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, bool ForVTable); 00054 00055 /// maybeEmitThunkForVTable - Emit the given thunk for the vtable if needed by 00056 /// the ABI. 00057 void maybeEmitThunkForVTable(GlobalDecl GD, const ThunkInfo &Thunk); 00058 00059 public: 00060 /// CreateVTableInitializer - Create a vtable initializer for the given record 00061 /// decl. 00062 /// \param Components - The vtable components; this is really an array of 00063 /// VTableComponents. 00064 llvm::Constant *CreateVTableInitializer( 00065 const CXXRecordDecl *RD, const VTableComponent *Components, 00066 unsigned NumComponents, const VTableLayout::VTableThunkTy *VTableThunks, 00067 unsigned NumVTableThunks, llvm::Constant *RTTI); 00068 00069 CodeGenVTables(CodeGenModule &CGM); 00070 00071 ItaniumVTableContext &getItaniumVTableContext() { 00072 return *cast<ItaniumVTableContext>(VTContext); 00073 } 00074 00075 MicrosoftVTableContext &getMicrosoftVTableContext() { 00076 return *cast<MicrosoftVTableContext>(VTContext); 00077 } 00078 00079 /// getSubVTTIndex - Return the index of the sub-VTT for the base class of the 00080 /// given record decl. 00081 uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base); 00082 00083 /// getSecondaryVirtualPointerIndex - Return the index in the VTT where the 00084 /// virtual pointer for the given subobject is located. 00085 uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD, 00086 BaseSubobject Base); 00087 00088 /// getAddressPoint - Get the address point of the given subobject in the 00089 /// class decl. 00090 uint64_t getAddressPoint(BaseSubobject Base, const CXXRecordDecl *RD); 00091 00092 /// GenerateConstructionVTable - Generate a construction vtable for the given 00093 /// base subobject. 00094 llvm::GlobalVariable * 00095 GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base, 00096 bool BaseIsVirtual, 00097 llvm::GlobalVariable::LinkageTypes Linkage, 00098 VTableAddressPointsMapTy& AddressPoints); 00099 00100 00101 /// GetAddrOfVTT - Get the address of the VTT for the given record decl. 00102 llvm::GlobalVariable *GetAddrOfVTT(const CXXRecordDecl *RD); 00103 00104 /// EmitVTTDefinition - Emit the definition of the given vtable. 00105 void EmitVTTDefinition(llvm::GlobalVariable *VTT, 00106 llvm::GlobalVariable::LinkageTypes Linkage, 00107 const CXXRecordDecl *RD); 00108 00109 /// EmitThunks - Emit the associated thunks for the given global decl. 00110 void EmitThunks(GlobalDecl GD); 00111 00112 /// GenerateClassData - Generate all the class data required to be 00113 /// generated upon definition of a KeyFunction. This includes the 00114 /// vtable, the RTTI data structure (if RTTI is enabled) and the VTT 00115 /// (if the class has virtual bases). 00116 void GenerateClassData(const CXXRecordDecl *RD); 00117 00118 bool isVTableExternal(const CXXRecordDecl *RD); 00119 }; 00120 00121 } // end namespace CodeGen 00122 } // end namespace clang 00123 #endif