blob: f9ddf44284b1d86b6a5fc7a72850045f96bb5624 [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;
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 Carlssona0fdd912009-11-13 17:08:56 +000032 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVtableIndicesTy;
Anders Carlssondbd920c2009-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 Stump380dd752009-11-10 07:44:33 +000042
43 llvm::DenseMap<const CXXRecordDecl *, llvm::Constant *> Vtables;
Anders Carlssondbd920c2009-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 Carlssona0fdd912009-11-13 17:08:56 +000051 int64_t getMethodVtableIndex(GlobalDecl GD);
Anders Carlssondbd920c2009-10-11 22:13:54 +000052
Mike Stumpab28c132009-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 Carlssondbd920c2009-10-11 22:13:54 +000058 int64_t getVirtualBaseOffsetIndex(const CXXRecordDecl *RD,
59 const CXXRecordDecl *VBase);
Mike Stump380dd752009-11-10 07:44:33 +000060
Mike Stump8cfcb522009-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);
Anders Carlssondbd920c2009-10-11 22:13:54 +000064};
65
66}
67}
68#endif