blob: 78ae670cf35af9c421078ee5fd79c9acb897de17 [file] [log] [blame]
Anders Carlsson2bb27f52009-10-11 22:13:54 +00001//===--- 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 Carlssonfb4dda42009-11-13 17:08:56 +000018#include "GlobalDecl.h"
Anders Carlsson2bb27f52009-10-11 22:13:54 +000019
20namespace clang {
21 class CXXMethodDecl;
22 class CXXRecordDecl;
23
24namespace CodeGen {
25 class CodeGenModule;
26
27class CGVtableInfo {
28 CodeGenModule &CGM;
29
30 /// MethodVtableIndices - Contains the index (relative to the vtable address
31 /// point) where the function pointer for a virtual function is stored.
Anders Carlssonfb4dda42009-11-13 17:08:56 +000032 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVtableIndicesTy;
Anders Carlsson2bb27f52009-10-11 22:13:54 +000033 MethodVtableIndicesTy MethodVtableIndices;
34
35 typedef std::pair<const CXXRecordDecl *,
36 const CXXRecordDecl *> ClassPairTy;
37
38 /// VirtualBaseClassIndicies - Contains the index into the vtable where the
39 /// offsets for virtual bases of a class are stored.
40 typedef llvm::DenseMap<ClassPairTy, int64_t> VirtualBaseClassIndiciesTy;
41 VirtualBaseClassIndiciesTy VirtualBaseClassIndicies;
Mike Stumpd846d082009-11-10 07:44:33 +000042
43 llvm::DenseMap<const CXXRecordDecl *, llvm::Constant *> Vtables;
Anders Carlsson2bb27f52009-10-11 22:13:54 +000044public:
45 CGVtableInfo(CodeGenModule &CGM)
46 : CGM(CGM) { }
47
48 /// getMethodVtableIndex - Return the index (relative to the vtable address
49 /// point) where the function pointer for the given virtual function is
50 /// stored.
Anders Carlssonfb4dda42009-11-13 17:08:56 +000051 int64_t getMethodVtableIndex(GlobalDecl GD);
Anders Carlsson2bb27f52009-10-11 22:13:54 +000052
Mike Stump28431212009-10-13 22:54:56 +000053 /// getVirtualBaseOffsetIndex - Return the index (relative to the vtable
54 /// address point) where the offset of the virtual base that contains the
55 /// given Base is stored, otherwise, if no virtual base contains the given
56 /// class, return 0. Base must be a virtual base class or an unambigious
57 /// base.
Anders Carlsson2bb27f52009-10-11 22:13:54 +000058 int64_t getVirtualBaseOffsetIndex(const CXXRecordDecl *RD,
59 const CXXRecordDecl *VBase);
Mike Stumpd846d082009-11-10 07:44:33 +000060
Mike Stumpeac45592009-11-11 20:26:26 +000061 llvm::Constant *getVtable(const CXXRecordDecl *RD);
62 llvm::Constant *getCtorVtable(const CXXRecordDecl *RD,
63 const CXXRecordDecl *Class, uint64_t Offset);
Mike Stump1a139f82009-11-19 01:08:19 +000064 /// GenerateClassData - Generate all the class data requires to be generated
65 /// upon definition of a KeyFunction. This includes the vtable, the
66 /// rtti data structure and the VTT.
67 void GenerateClassData(const CXXRecordDecl *RD);
Anders Carlsson2bb27f52009-10-11 22:13:54 +000068};
69
70}
71}
72#endif