blob: 7ad42b59fb6e5ebdf3729f78fdf26be47f02dc50 [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"
18
19namespace clang {
20 class CXXMethodDecl;
21 class CXXRecordDecl;
22
23namespace CodeGen {
24 class CodeGenModule;
25
26class CGVtableInfo {
27 CodeGenModule &CGM;
28
29 /// MethodVtableIndices - Contains the index (relative to the vtable address
30 /// point) where the function pointer for a virtual function is stored.
31 typedef llvm::DenseMap<const CXXMethodDecl *, int64_t> MethodVtableIndicesTy;
32 MethodVtableIndicesTy MethodVtableIndices;
33
34 typedef std::pair<const CXXRecordDecl *,
35 const CXXRecordDecl *> ClassPairTy;
36
37 /// VirtualBaseClassIndicies - Contains the index into the vtable where the
38 /// offsets for virtual bases of a class are stored.
39 typedef llvm::DenseMap<ClassPairTy, int64_t> VirtualBaseClassIndiciesTy;
40 VirtualBaseClassIndiciesTy VirtualBaseClassIndicies;
Mike Stump380dd752009-11-10 07:44:33 +000041
42 llvm::DenseMap<const CXXRecordDecl *, llvm::Constant *> Vtables;
Anders Carlssondbd920c2009-10-11 22:13:54 +000043public:
44 CGVtableInfo(CodeGenModule &CGM)
45 : CGM(CGM) { }
46
47 /// getMethodVtableIndex - Return the index (relative to the vtable address
48 /// point) where the function pointer for the given virtual function is
49 /// stored.
50 int64_t getMethodVtableIndex(const CXXMethodDecl *MD);
51
Mike Stumpab28c132009-10-13 22:54:56 +000052 /// getVirtualBaseOffsetIndex - Return the index (relative to the vtable
53 /// address point) where the offset of the virtual base that contains the
54 /// given Base is stored, otherwise, if no virtual base contains the given
55 /// class, return 0. Base must be a virtual base class or an unambigious
56 /// base.
Anders Carlssondbd920c2009-10-11 22:13:54 +000057 int64_t getVirtualBaseOffsetIndex(const CXXRecordDecl *RD,
58 const CXXRecordDecl *VBase);
Mike Stump380dd752009-11-10 07:44:33 +000059
Mike Stump8cfcb522009-11-11 20:26:26 +000060 llvm::Constant *getVtable(const CXXRecordDecl *RD);
61 llvm::Constant *getCtorVtable(const CXXRecordDecl *RD,
62 const CXXRecordDecl *Class, uint64_t Offset);
Anders Carlssondbd920c2009-10-11 22:13:54 +000063};
64
65}
66}
67#endif