18 using namespace clang;
19 using namespace CodeGen;
21 static llvm::GlobalVariable *
25 llvm::GlobalVariable::LinkageTypes
Linkage,
26 llvm::DenseMap<BaseSubobject, uint64_t> &AddressPoints) {
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());
54 *e =
Builder.getVTTVTables().end(); i != e; ++i) {
55 VTableAddressPoints.push_back(VTableAddressPointsMapTy());
57 VTableAddressPoints.back()));
62 *e =
Builder.getVTTComponents().end(); i != e; ++i) {
64 llvm::GlobalVariable *VTable = VTables[i->VTableIndex];
65 uint64_t AddressPoint;
71 assert(AddressPoint != 0 &&
"Did not find vtable address point!");
73 AddressPoint = VTableAddressPoints[i->VTableIndex].lookup(i->VTableBase);
74 assert(AddressPoint != 0 &&
"Did not find ctor vtable address point!");
78 llvm::ConstantInt::get(Int32Ty, 0),
79 llvm::ConstantInt::get(Int32Ty, AddressPoint)
82 llvm::Constant *Init = llvm::ConstantExpr::getInBoundsGetElementPtr(
83 VTable->getValueType(), VTable, Idxs);
85 Init = llvm::ConstantExpr::getBitCast(Init, Int8PtrTy);
87 VTTComponents.push_back(Init);
90 llvm::Constant *Init = llvm::ConstantArray::get(ArrayType, VTTComponents);
92 VTT->setInitializer(Init);
95 VTT->setLinkage(Linkage);
98 VTT->setComdat(CGM.
getModule().getOrInsertComdat(VTT->getName()));
105 assert(RD->
getNumVBases() &&
"Only classes with virtual bases need a VTT");
108 llvm::raw_svector_ostream Out(OutName);
110 .mangleCXXVTT(RD, Out);
111 StringRef
Name = OutName.str();
121 llvm::GlobalVariable *GV =
124 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
130 BaseSubobjectPairTy ClassSubobjectPair(RD, Base);
133 if (I != SubVTTIndicies.end())
138 for (llvm::DenseMap<BaseSubobject, uint64_t>::const_iterator I =
139 Builder.getSubVTTIndicies().begin(),
140 E =
Builder.getSubVTTIndicies().end(); I !=
E; ++
I) {
142 BaseSubobjectPairTy ClassSubobjectPair(RD, I->first);
144 SubVTTIndicies.insert(std::make_pair(ClassSubobjectPair, I->second));
147 I = SubVTTIndicies.find(ClassSubobjectPair);
148 assert(I != SubVTTIndicies.end() &&
"Did not find index!");
157 SecondaryVirtualPointerIndices.find(std::make_pair(RD, Base));
159 if (I != SecondaryVirtualPointerIndices.end())
165 for (llvm::DenseMap<BaseSubobject, uint64_t>::const_iterator I =
166 Builder.getSecondaryVirtualPointerIndices().begin(),
167 E =
Builder.getSecondaryVirtualPointerIndices().end(); I !=
E; ++
I) {
168 std::pair<const CXXRecordDecl *, BaseSubobject> Pair =
169 std::make_pair(RD, I->first);
171 SecondaryVirtualPointerIndices.insert(std::make_pair(Pair, I->second));
174 I = SecondaryVirtualPointerIndices.find(std::make_pair(RD, Base));
175 assert(I != SecondaryVirtualPointerIndices.end() &&
"Did not find index!");
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...
llvm::Module & getModule() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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...
uint64_t getAddressPoint(BaseSubobject Base) const
CharUnits - This is an opaque type for sizes expressed in character units.
ItaniumVTableContext & getItaniumVTableContext()
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const
Set the visibility for the given LLVM GlobalValue.
detail::InMemoryDirectory::const_iterator I
CGCXXABI & getCXXABI() const
const CXXRecordDecl * getBase() const
ASTContext & getContext() const
llvm::IntegerType * Int32Ty
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage)
Will return a global variable of the given type.
The l-value was considered opaque, so the alignment was determined from a type.
const TemplateArgument * iterator
llvm::GlobalVariable * GetAddrOfVTT(const CXXRecordDecl *RD)
GetAddrOfVTT - Get the address of the VTT for the given record decl.
CharUnits getBaseOffset() const
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.
bool isZero() const
isZero - Test whether the quantity equals zero.
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...
detail::InMemoryDirectory::const_iterator E
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.
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
Represents a C++ struct/union/class.
static llvm::GlobalVariable * GetAddrOfVTTVTable(CodeGenVTables &CGVT, CodeGenModule &CGM, const CXXRecordDecl *MostDerivedClass, const VTTVTable &VTable, llvm::GlobalVariable::LinkageTypes Linkage, llvm::DenseMap< BaseSubobject, uint64_t > &AddressPoints)
BoundNodesTreeBuilder *const Builder
BaseSubobject getBaseSubobject() const
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
bool supportsCOMDAT() const