18 using namespace clang;
19 using namespace CodeGen;
21 static llvm::GlobalVariable *
25 llvm::GlobalVariable::LinkageTypes
Linkage,
27 if (VTable.
getBase() == MostDerivedClass) {
29 "Most derived class vtable must have a zero offset!");
43 llvm::GlobalVariable::LinkageTypes
Linkage,
49 llvm::ArrayType::get(Int8PtrTy, Builder.getVTTComponents().size());
53 for (
const VTTVTable *i = Builder.getVTTVTables().begin(),
54 *e = Builder.getVTTVTables().end(); i != e; ++i) {
55 VTableAddressPoints.push_back(VTableAddressPointsMapTy());
57 VTableAddressPoints.back()));
61 for (
const VTTComponent *i = Builder.getVTTComponents().begin(),
62 *e = Builder.getVTTComponents().end(); i != e; ++i) {
63 const VTTVTable &VTTVT = Builder.getVTTVTables()[i->VTableIndex];
64 llvm::GlobalVariable *VTable = VTables[i->VTableIndex];
72 AddressPoint = VTableAddressPoints[i->VTableIndex].lookup(i->VTableBase);
74 "Did not find ctor vtable address point!");
78 llvm::ConstantInt::get(Int32Ty, 0),
79 llvm::ConstantInt::get(Int32Ty, AddressPoint.
VTableIndex),
83 llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr(
84 VTable->getValueType(), VTable, Idxs,
true,
87 Init = llvm::ConstantExpr::getBitCast(Init, Int8PtrTy);
89 VTTComponents.push_back(Init);
92 llvm::Constant *Init = llvm::ConstantArray::get(ArrayType, VTTComponents);
94 VTT->setInitializer(Init);
97 VTT->setLinkage(Linkage);
100 VTT->setComdat(CGM.
getModule().getOrInsertComdat(VTT->getName()));
107 assert(RD->
getNumVBases() &&
"Only classes with virtual bases need a VTT");
110 llvm::raw_svector_ostream Out(OutName);
112 .mangleCXXVTT(RD, Out);
113 StringRef Name = OutName.str();
121 llvm::ArrayType::get(CGM.
Int8PtrTy, Builder.getVTTComponents().size());
126 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
132 BaseSubobjectPairTy ClassSubobjectPair(RD, Base);
134 SubVTTIndiciesMapTy::iterator I = SubVTTIndicies.find(ClassSubobjectPair);
135 if (I != SubVTTIndicies.end())
140 for (llvm::DenseMap<BaseSubobject, uint64_t>::const_iterator I =
141 Builder.getSubVTTIndicies().begin(),
142 E = Builder.getSubVTTIndicies().end(); I != E; ++I) {
144 BaseSubobjectPairTy ClassSubobjectPair(RD, I->first);
146 SubVTTIndicies.insert(std::make_pair(ClassSubobjectPair, I->second));
149 I = SubVTTIndicies.find(ClassSubobjectPair);
150 assert(I != SubVTTIndicies.end() &&
"Did not find index!");
158 SecondaryVirtualPointerIndicesMapTy::iterator I =
159 SecondaryVirtualPointerIndices.find(std::make_pair(RD, Base));
161 if (I != SecondaryVirtualPointerIndices.end())
167 for (llvm::DenseMap<BaseSubobject, uint64_t>::const_iterator I =
168 Builder.getSecondaryVirtualPointerIndices().begin(),
169 E = Builder.getSecondaryVirtualPointerIndices().end(); I != E; ++I) {
170 std::pair<const CXXRecordDecl *, BaseSubobject> Pair =
171 std::make_pair(RD, I->first);
173 SecondaryVirtualPointerIndices.insert(std::make_pair(Pair, I->second));
176 I = SecondaryVirtualPointerIndices.find(std::make_pair(RD, Base));
177 assert(I != SecondaryVirtualPointerIndices.end() &&
"Did not find index!");
static llvm::GlobalVariable * GetAddrOfVTTVTable(CodeGenVTables &CGVT, CodeGenModule &CGM, const CXXRecordDecl *MostDerivedClass, const VTTVTable &VTable, llvm::GlobalVariable::LinkageTypes Linkage, VTableLayout::AddressPointsMapTy &AddressPoints)
const llvm::DataLayout & getDataLayout() const
void EmitVTTDefinition(llvm::GlobalVariable *VTT, llvm::GlobalVariable::LinkageTypes Linkage, const CXXRecordDecl *RD)
EmitVTTDefinition - Emit the definition of the given vtable.
External linkage, which indicates that the entity can be referred to from other translation units...
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
AddressPointLocation getAddressPoint(BaseSubobject Base) const
bool isZero() const
isZero - Test whether the quantity equals zero.
unsigned AddressPointIndex
bool supportsCOMDAT() const
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base)
getSubVTTIndex - Return the index of the sub-VTT for the base class of the given record decl...
CharUnits - This is an opaque type for sizes expressed in character units.
const CXXRecordDecl * getBase() const
ItaniumVTableContext & getItaniumVTableContext()
llvm::IntegerType * Int32Ty
ASTContext & getContext() const
The l-value was considered opaque, so the alignment was determined from a type.
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
llvm::GlobalVariable * GetAddrOfVTT(const CXXRecordDecl *RD)
GetAddrOfVTT - Get the address of the VTT for the given record decl.
MangleContext & getMangleContext()
Gets the mangle context.
llvm::GlobalVariable * GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base, bool BaseIsVirtual, llvm::GlobalVariable::LinkageTypes Linkage, VTableAddressPointsMapTy &AddressPoints)
GenerateConstructionVTable - Generate a construction vtable for the given base subobject.
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
virtual llvm::GlobalVariable * getAddrOfVTable(const CXXRecordDecl *RD, CharUnits VPtrOffset)=0
Get the address of the vtable for the given record decl which should be used for the vptr at the give...
llvm::Module & getModule() const
uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD, BaseSubobject Base)
getSecondaryVirtualPointerIndex - Return the index in the VTT where the virtual pointer for the given...
llvm::PointerType * Int8PtrTy
Class for building VTT layout information.
BaseSubobject getBaseSubobject() const
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
llvm::DenseMap< BaseSubobject, AddressPointLocation > AddressPointsMapTy
Represents a C++ struct/union/class.
CGCXXABI & getCXXABI() const
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage, unsigned Alignment)
Will return a global variable of the given type.
CharUnits getBaseOffset() const