blob: af718b36328e510a33c8c38b75526758b2795d3c [file] [log] [blame]
Anders Carlssondbd920c2009-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 Carlssona0fdd912009-11-13 17:08:56 +000018#include "GlobalDecl.h"
Anders Carlssondbd920c2009-10-11 22:13:54 +000019
20namespace clang {
21 class CXXMethodDecl;
22 class CXXRecordDecl;
23
24namespace CodeGen {
25 class CodeGenModule;
Anders Carlssona94822e2009-11-26 02:32:05 +000026
27/// ThunkAdjustment - Virtual and non-virtual adjustment for thunks.
28struct ThunkAdjustment {
29 ThunkAdjustment(int64_t NonVirtual, int64_t Virtual)
30 : NonVirtual(NonVirtual),
31 Virtual(Virtual) { }
Anders Carlssondbd920c2009-10-11 22:13:54 +000032
Anders Carlssona94822e2009-11-26 02:32:05 +000033 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 Carlssondbd920c2009-10-11 22:13:54 +000048class 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 Carlssona0fdd912009-11-13 17:08:56 +000053 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVtableIndicesTy;
Anders Carlssondbd920c2009-10-11 22:13:54 +000054 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 Stump380dd752009-11-10 07:44:33 +000063
64 llvm::DenseMap<const CXXRecordDecl *, llvm::Constant *> Vtables;
Anders Carlssondbd920c2009-10-11 22:13:54 +000065public:
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 Carlssona0fdd912009-11-13 17:08:56 +000072 int64_t getMethodVtableIndex(GlobalDecl GD);
Anders Carlssondbd920c2009-10-11 22:13:54 +000073
Mike Stumpab28c132009-10-13 22:54:56 +000074 /// 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 Carlssondbd920c2009-10-11 22:13:54 +000079 int64_t getVirtualBaseOffsetIndex(const CXXRecordDecl *RD,
80 const CXXRecordDecl *VBase);
Mike Stump380dd752009-11-10 07:44:33 +000081
Mike Stump8cfcb522009-11-11 20:26:26 +000082 llvm::Constant *getVtable(const CXXRecordDecl *RD);
83 llvm::Constant *getCtorVtable(const CXXRecordDecl *RD,
84 const CXXRecordDecl *Class, uint64_t Offset);
Mike Stump58588942009-11-19 01:08:19 +000085 /// 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 Carlssondbd920c2009-10-11 22:13:54 +000089};
90
91}
92}
93#endif