blob: 1d98bed4b2aa4d24e68255a99364ed44f6be708a [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
Anders Carlssonb73a5be2009-11-26 02:49:32 +000020namespace llvm {
21 class Constant;
22}
23
Anders Carlssondbd920c2009-10-11 22:13:54 +000024namespace clang {
25 class CXXMethodDecl;
26 class CXXRecordDecl;
27
28namespace CodeGen {
29 class CodeGenModule;
Anders Carlssona94822e2009-11-26 02:32:05 +000030
31/// ThunkAdjustment - Virtual and non-virtual adjustment for thunks.
32struct ThunkAdjustment {
33 ThunkAdjustment(int64_t NonVirtual, int64_t Virtual)
34 : NonVirtual(NonVirtual),
35 Virtual(Virtual) { }
Anders Carlssondbd920c2009-10-11 22:13:54 +000036
Anders Carlssona94822e2009-11-26 02:32:05 +000037 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 Carlssondbd920c2009-10-11 22:13:54 +000052class 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 Carlssona0fdd912009-11-13 17:08:56 +000057 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVtableIndicesTy;
Anders Carlssondbd920c2009-10-11 22:13:54 +000058 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 Stump380dd752009-11-10 07:44:33 +000067
68 llvm::DenseMap<const CXXRecordDecl *, llvm::Constant *> Vtables;
Anders Carlssondbd920c2009-10-11 22:13:54 +000069public:
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 Carlssona0fdd912009-11-13 17:08:56 +000076 int64_t getMethodVtableIndex(GlobalDecl GD);
Anders Carlssondbd920c2009-10-11 22:13:54 +000077
Mike Stumpab28c132009-10-13 22:54:56 +000078 /// 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 Carlssondbd920c2009-10-11 22:13:54 +000083 int64_t getVirtualBaseOffsetIndex(const CXXRecordDecl *RD,
84 const CXXRecordDecl *VBase);
Mike Stump380dd752009-11-10 07:44:33 +000085
Mike Stump8cfcb522009-11-11 20:26:26 +000086 llvm::Constant *getVtable(const CXXRecordDecl *RD);
87 llvm::Constant *getCtorVtable(const CXXRecordDecl *RD,
88 const CXXRecordDecl *Class, uint64_t Offset);
Mike Stump58588942009-11-19 01:08:19 +000089 /// 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 Carlssondbd920c2009-10-11 22:13:54 +000093};
94
95}
96}
97#endif