22 #include "llvm/Support/Format.h"
23 #include "llvm/Transforms/Utils/Cloning.h"
27 using namespace clang;
28 using namespace CodeGen;
31 : CGM(CGM), VTContext(CGM.getContext().getVTableContext()) {}
39 llvm::raw_svector_ostream Out(Name);
47 return GetOrCreateLLVMFunction(Name, Ty, GD,
true,
52 const ThunkInfo &Thunk, llvm::Function *Fn) {
57 llvm::Function *ThunkFn,
bool ForVTable,
68 ThunkFn->setComdat(CGM.
getModule().getOrInsertComdat(ThunkFn->getName()));
76 (isa<PointerType>(typeL) && isa<PointerType>(typeR)) ||
77 (isa<ReferenceType>(typeL) && isa<ReferenceType>(typeR))));
87 llvm::BasicBlock *AdjustNull =
nullptr;
88 llvm::BasicBlock *AdjustNotNull =
nullptr;
89 llvm::BasicBlock *AdjustEnd =
nullptr;
99 CGF.
Builder.CreateCondBr(IsNull, AdjustNull, AdjustNotNull);
106 Address(ReturnValue, ClassAlign),
109 if (NullCheckValue) {
110 CGF.
Builder.CreateBr(AdjustEnd);
112 CGF.
Builder.CreateBr(AdjustEnd);
115 llvm::PHINode *PHI = CGF.
Builder.CreatePHI(ReturnValue->getType(), 2);
116 PHI->addIncoming(ReturnValue, AdjustNotNull);
117 PHI->addIncoming(llvm::Constant::getNullValue(ReturnValue->getType()),
147 QualType ResultType = FPT->getReturnType();
153 llvm::Function *BaseFn = cast<llvm::Function>(Callee);
156 llvm::ValueToValueMapTy VMap;
157 llvm::Function *NewFn = llvm::CloneFunction(BaseFn, VMap);
158 Fn->replaceAllUsesWith(NewFn);
160 Fn->eraseFromParent();
167 llvm::Function::arg_iterator AI = Fn->arg_begin();
174 llvm::BasicBlock *EntryBB = &Fn->front();
175 llvm::BasicBlock::iterator ThisStore =
176 std::find_if(EntryBB->begin(), EntryBB->end(), [&](llvm::Instruction &
I) {
177 return isa<llvm::StoreInst>(
I) &&
180 assert(ThisStore != EntryBB->end() &&
181 "Store of this should be in entry block?");
183 Builder.SetInsertPoint(&*ThisStore);
186 ThisStore->setOperand(0, AdjustedThisPtr);
190 for (llvm::BasicBlock &BB : *Fn) {
191 llvm::Instruction *T = BB.getTerminator();
192 if (isa<llvm::ReturnInst>(T)) {
194 T->eraseFromParent();
229 if (isa<CXXDestructorDecl>(MD))
241 CXXThisValue = CXXABIThisValue;
258 "Please use a new CGF for this thunk");
273 MD,
"non-trivial argument copy for return-adjusting thunk");
284 if (isa<CXXDestructorDecl>(MD))
288 unsigned PrefixArgs = CallArgs.size() - 1;
302 assert(isa<CXXDestructorDecl>(MD) ||
303 similar(CallFnInfo.getReturnInfo(), CallFnInfo.getReturnType(),
307 assert(
similar(CallFnInfo.arg_begin()[i].info,
308 CallFnInfo.arg_begin()[i].type,
326 llvm::Instruction *CallOrInvoke;
333 else if (llvm::CallInst* Call = dyn_cast<llvm::CallInst>(CallOrInvoke))
334 Call->setTailCallKind(llvm::CallInst::TCK_Tail);
354 for (llvm::Argument &A :
CurFn->args())
362 llvm::Type *ThisType = Args[ThisArgNo]->getType();
363 if (ThisType != AdjustedThisPtr->getType())
365 Args[ThisArgNo] = AdjustedThisPtr;
367 assert(ThisAI.
isInAlloca() &&
"this is passed directly or inalloca");
369 llvm::Type *ThisType = ThisAddr.getElementType();
370 if (ThisType != AdjustedThisPtr->getType())
377 llvm::CallInst *Call =
Builder.CreateCall(CalleePtr, Args);
378 Call->setTailCallKind(llvm::CallInst::TCK_MustTail);
382 llvm::AttributeList Attrs;
385 Call->setAttributes(Attrs);
386 Call->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
388 if (Call->getType()->isVoidTy())
421 llvm::GlobalValue *Entry;
424 if (llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(C)) {
425 assert(CE->getOpcode() == llvm::Instruction::BitCast);
426 Entry = cast<llvm::GlobalValue>(CE->getOperand(0));
428 Entry = cast<llvm::GlobalValue>(C);
433 if (Entry->getType()->getElementType() !=
435 llvm::GlobalValue *OldThunkFn = Entry;
438 assert(OldThunkFn->isDeclaration() &&
439 "Shouldn't replace non-declaration");
442 OldThunkFn->setName(StringRef());
446 if (!OldThunkFn->use_empty()) {
447 llvm::Constant *NewPtrForOldDecl =
448 llvm::ConstantExpr::getBitCast(Entry, OldThunkFn->getType());
449 OldThunkFn->replaceAllUsesWith(NewPtrForOldDecl);
453 OldThunkFn->eraseFromParent();
456 llvm::Function *ThunkFn = cast<llvm::Function>(Entry);
458 bool UseAvailableExternallyLinkage = ForVTable && ABIHasKeyFunctions;
460 if (!ThunkFn->isDeclaration()) {
461 if (!ABIHasKeyFunctions || UseAvailableExternallyLinkage) {
472 if (ThunkFn->isVarArg()) {
478 if (UseAvailableExternallyLinkage)
490 void CodeGenVTables::maybeEmitThunkForVTable(
GlobalDecl GD,
506 emitThunk(GD, Thunk,
true);
521 if (!ThunkInfoVector)
524 for (
const ThunkInfo& Thunk : *ThunkInfoVector)
525 emitThunk(GD, Thunk,
false);
528 void CodeGenVTables::addVTableComponent(
530 unsigned idx, llvm::Constant *rtti,
unsigned &nextVTableThunkIndex) {
533 auto addOffsetConstant = [&](
CharUnits offset) {
534 builder.
add(llvm::ConstantExpr::getIntToPtr(
535 llvm::ConstantInt::get(CGM.
PtrDiffTy, offset.getQuantity()),
539 switch (component.getKind()) {
541 return addOffsetConstant(component.getVCallOffset());
544 return addOffsetConstant(component.getVBaseOffset());
547 return addOffsetConstant(component.getOffsetToTop());
550 return builder.
add(llvm::ConstantExpr::getBitCast(rtti, CGM.
Int8PtrTy));
558 switch (component.getKind()) {
560 llvm_unreachable(
"Unexpected vtable component kind");
562 GD = component.getFunctionDecl();
581 ? MD->
hasAttr<CUDADeviceAttr>()
582 : (MD->
hasAttr<CUDAHostAttr>() || !MD->
hasAttr<CUDADeviceAttr>());
588 auto getSpecialVirtualFn = [&](StringRef name) {
589 llvm::FunctionType *fnTy =
590 llvm::FunctionType::get(CGM.
VoidTy,
false);
592 if (
auto f = dyn_cast<llvm::Function>(fn))
593 f->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
594 return llvm::ConstantExpr::getBitCast(fn, CGM.
Int8PtrTy);
597 llvm::Constant *fnPtr;
600 if (cast<CXXMethodDecl>(GD.
getDecl())->isPure()) {
604 fnPtr = PureVirtualFn;
607 }
else if (cast<CXXMethodDecl>(GD.
getDecl())->isDeleted()) {
608 if (!DeletedVirtualFn)
611 fnPtr = DeletedVirtualFn;
614 }
else if (nextVTableThunkIndex < layout.
vtable_thunks().size() &&
616 auto &thunkInfo = layout.
vtable_thunks()[nextVTableThunkIndex].second;
618 maybeEmitThunkForVTable(GD, thunkInfo);
619 nextVTableThunkIndex++;
628 fnPtr = llvm::ConstantExpr::getBitCast(fnPtr, CGM.
Int8PtrTy);
637 llvm_unreachable(
"Unexpected vtable component kind");
642 for (
unsigned i = 0, e = layout.
getNumVTables(); i != e; ++i) {
651 llvm::Constant *rtti) {
652 unsigned nextVTableThunkIndex = 0;
653 for (
unsigned i = 0, e = layout.
getNumVTables(); i != e; ++i) {
657 for (
unsigned i = thisIndex; i != nextIndex; ++i) {
658 addVTableComponent(vtableElem, layout, i, rtti, nextVTableThunkIndex);
660 vtableElem.finishAndAddTo(builder);
664 llvm::GlobalVariable *
668 llvm::GlobalVariable::LinkageTypes
Linkage,
669 VTableAddressPointsMapTy& AddressPoints) {
671 DI->completeClassData(Base.
getBase());
673 std::unique_ptr<VTableLayout> VTLayout(
678 AddressPoints = VTLayout->getAddressPoints();
682 llvm::raw_svector_ostream Out(OutName);
686 StringRef
Name = OutName.str();
695 if (Linkage == llvm::GlobalVariable::AvailableExternallyLinkage)
699 llvm::GlobalVariable *VTable =
704 VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
713 components.finishAndSetAsInitializer(VTable);
729 llvm::GlobalVariable::LinkageTypes
737 if (keyFunction && !RD->
hasAttr<DLLImportAttr>()) {
742 keyFunction = cast<CXXMethodDecl>(def);
747 assert((def || CodeGenOpts.OptimizationLevel > 0 ||
749 "Shouldn't query vtable linkage without key function, "
750 "optimizations, or debug info");
751 if (!def && CodeGenOpts.OptimizationLevel > 0)
752 return llvm::GlobalVariable::AvailableExternallyLinkage;
756 llvm::GlobalVariable::LinkOnceODRLinkage :
763 llvm::GlobalVariable::LinkOnceODRLinkage :
768 llvm::GlobalVariable::WeakODRLinkage :
772 llvm_unreachable(
"Should not have been asked to emit this");
781 llvm::GlobalVariable::LinkageTypes DiscardableODRLinkage =
782 llvm::GlobalValue::LinkOnceODRLinkage;
783 llvm::GlobalVariable::LinkageTypes NonDiscardableODRLinkage =
784 llvm::GlobalValue::WeakODRLinkage;
785 if (RD->
hasAttr<DLLExportAttr>()) {
787 DiscardableODRLinkage = NonDiscardableODRLinkage;
788 }
else if (RD->
hasAttr<DLLImportAttr>()) {
790 DiscardableODRLinkage = llvm::GlobalVariable::AvailableExternallyLinkage;
791 NonDiscardableODRLinkage = llvm::GlobalVariable::AvailableExternallyLinkage;
798 return DiscardableODRLinkage;
804 return DiscardableODRLinkage;
806 ? llvm::GlobalVariable::AvailableExternallyLinkage
810 return NonDiscardableODRLinkage;
813 llvm_unreachable(
"Invalid TemplateSpecializationKind!");
829 DI->completeClassData(RD);
848 assert(RD->
isDynamicClass() &&
"Non-dynamic classes have no VTable.");
875 return !keyFunction->
hasBody();
894 void CodeGenModule::EmitDeferredVTables() {
898 size_t savedSize = DeferredVTables.size();
904 else if (shouldOpportunisticallyEmitVTables())
905 OpportunisticVTables.push_back(RD);
907 assert(savedSize == DeferredVTables.size() &&
908 "deferred extra vtables during vtable emission?");
909 DeferredVTables.clear();
917 if (RD->
hasAttr<LTOVisibilityPublicAttr>() || RD->
hasAttr<UuidAttr>())
931 auto *D = cast<Decl>(DC);
933 if (isa<TranslationUnitDecl>(DC->getRedeclContext())) {
934 if (
auto *ND = dyn_cast<NamespaceDecl>(D))
936 if (II->isStr(
"std") || II->isStr(
"stdext"))
954 typedef std::pair<const CXXRecordDecl *, unsigned> BSEntry;
955 std::vector<BSEntry> BitsetEntries;
958 BitsetEntries.push_back(
959 std::make_pair(AP.first.getBase(),
961 AP.second.AddressPointIndex));
964 std::sort(BitsetEntries.begin(), BitsetEntries.end(),
965 [
this](
const BSEntry &E1,
const BSEntry &E2) {
970 llvm::raw_string_ostream O1(S1);
972 QualType(E1.first->getTypeForDecl(), 0), O1);
976 llvm::raw_string_ostream O2(S2);
978 QualType(E2.first->getTypeForDecl(), 0), O2);
986 return E1.second < E2.second;
989 for (
auto BitsetEntry : BitsetEntries)
ReturnValueSlot - Contains the address where the return value of a function can be stored...
static const Decl * getCanonicalDecl(const Decl *D)
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
External linkage, which indicates that the entity can be referred to from other translation units...
A (possibly-)qualified type.
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI)
Return true iff the given type uses 'sret' when used as a return type.
CodeGenTypes & getTypes()
CanQualType getReturnType() const
virtual void EmitReturnFromThunk(CodeGenFunction &CGF, RValue RV, QualType ResultType)
llvm::Module & getModule() const
llvm::LLVMContext & getLLVMContext()
virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params)=0
Insert any ABI-specific implicit parameters into the parameter list for a function.
The standard implementation of ConstantInitBuilder used in Clang.
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
FunctionType - C99 6.7.5.3 - Function Declarators.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
virtual const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD)
virtual llvm::Value * performThisAdjustment(CodeGenFunction &CGF, Address This, const ThisAdjustment &TA)=0
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
llvm::Value * LoadCXXThis()
LoadCXXThis - Load the value of 'this'.
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
virtual StringRef GetDeletedVirtualCallName()=0
Gets the deleted virtual member call name.
llvm::Function * GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk)
bool isFuncTypeConvertible(const FunctionType *FT)
isFuncTypeConvertible - Utility to check whether a function type can be converted to an LLVM type (i...
bool HasHiddenLTOVisibility(const CXXRecordDecl *RD)
Returns whether the given record has hidden LTO visibility and therefore may participate in (single-m...
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
Objects with "hidden" visibility are not seen by the dynamic linker.
CGDebugInfo * getModuleDebugInfo()
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
ParmVarDecl - Represents a parameter to a function.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
Visibility getVisibility() const
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body (definition).
One of these records is kept for each identifier that is lexed.
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
static bool shouldEmitAvailableExternallyVTable(const CodeGenModule &CGM, const CXXRecordDecl *RD)
static void setThunkVisibility(CodeGenModule &CGM, const CXXMethodDecl *MD, const ThunkInfo &Thunk, llvm::Function *Fn)
bool isReferenceType() const
llvm::Type * getVTableType(const VTableLayout &layout)
Returns the type of a vtable with the given layout.
The this pointer adjustment as well as an optional return adjustment for a thunk. ...
const Decl * getDecl() const
Linkage getLinkage() const
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
static bool hasScalarEvaluationKind(QualType T)
const TargetInfo & getTargetInfo() const
virtual void emitVTableDefinitions(CodeGenVTables &CGVT, const CXXRecordDecl *RD)=0
Emits the VTable definitions required for the given record type.
const LangOptions & getLangOpts() const
CharUnits - This is an opaque type for sizes expressed in character units.
QualType getReturnType() const
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs, unsigned &CallingConv, bool AttrOnCallSite)
Get the LLVM attributes and calling convention to use for a particular function type.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
void addNullPointer(llvm::PointerType *ptrTy)
Add a null pointer of a specific type.
unsigned getCallingConvention() const
getCallingConvention - Return the user specified calling convention, which has been translated into a...
virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const =0
Determine whether it's possible to emit a vtable for RD, even though we do not know that the vtable h...
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
ItaniumVTableContext & getItaniumVTableContext()
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const
Set the visibility for the given LLVM GlobalValue.
detail::InMemoryDirectory::const_iterator I
const CGFunctionInfo & arrangeGlobalDeclaration(GlobalDecl GD)
param_iterator param_begin()
llvm::Constant * CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false)
Create a new runtime function with the specified type and name.
Represents a prototype with parameter type info, e.g.
ArrayBuilder beginArray(llvm::Type *eltTy=nullptr)
const TargetInfo & getTarget() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, SourceLocation loc)
EmitDelegateCallArg - We are performing a delegate call; that is, the current function is delegating ...
bool isVTableExternal(const CXXRecordDecl *RD)
At this point in the translation unit, does it appear that can we rely on the vtable being defined el...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
const CXXRecordDecl * getBase() const
getBase - Returns the base class declaration.
static void setThunkProperties(CodeGenModule &CGM, const ThunkInfo &Thunk, llvm::Function *ThunkFn, bool ForVTable, GlobalDecl GD)
llvm::Value * getPointer() const
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
ArrayRef< VTableThunkTy > vtable_thunks() const
static bool similar(const ABIArgInfo &infoL, CanQualType typeL, const ABIArgInfo &infoR, CanQualType typeR)
CXXDtorType getDtorType() const
CGCXXABI & getCXXABI() const
bool usesInAlloca() const
Return true if this function uses inalloca arguments.
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
Represents a C++ destructor within a class.
virtual StringRef GetPureVirtualCallName()=0
Gets the pure virtual member call function.
ASTContext & getContext() const
void add(RValue rvalue, QualType type, bool needscopy=false)
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
bool hasKeyFunctions() const
Does this ABI use key functions? If so, class data such as the vtable is emitted with strong linkage ...
size_t getVTableSize(size_t i) const
DeclContext * getParent()
getParent - Returns the containing DeclContext.
virtual bool HasThisReturn(GlobalDecl GD) const
Returns true if the given constructor or destructor is one of the kinds that the ABI says returns 'th...
bool isExternallyVisible(Linkage L)
bool isExternallyVisible() const
void add(llvm::Constant *value)
Add a new value to this initializer.
unsigned getRegParm() const
This template specialization was implicitly instantiated from a template.
virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, GlobalDecl GD, CallArgList &CallArgs)
size_t getNumVTables() const
void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset, const CXXRecordDecl *RD)
Create and attach type metadata for the given vtable.
void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk)
Generate a thunk for the given method.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
GlobalDecl - represents a global declaration.
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage)
Will return a global variable of the given type.
llvm::Constant * GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk)
Get the address of the thunk for the given global decl.
The l-value was considered opaque, so the alignment was determined from a type.
virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, const ThisAdjustment &ThisAdjustment, raw_ostream &)=0
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
ASTContext & getContext() const
Encodes a location in the source.
Represents a static or instance method of a struct/union/class.
ArrayRef< ParmVarDecl * > parameters() const
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
CodeGenVTables(CodeGenModule &CGM)
ArrayRef< VTableComponent > vtable_components() const
void createVTableInitializer(ConstantStructBuilder &builder, const VTableLayout &layout, llvm::Constant *rtti)
Add vtable components for the given vtable layout to the given global initializer.
const CodeGenOptions & getCodeGenOpts() const
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
const LangOptions & getLangOpts() const
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
const T * castAs() const
Member-template castAs<specific type>.
virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD)=0
Emit any tables needed to implement virtual inheritance.
All available information about a concrete callee.
MangleContext & getMangleContext()
Gets the mangle context.
This template specialization was instantiated from a template due to an explicit instantiation defini...
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
const CGFunctionInfo * CurFnInfo
bool isDynamicClass() const
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.
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
virtual void mangleTypeName(QualType T, raw_ostream &)=0
Generates a unique string for an externally visible type for use with TBAA or type uniquing...
bool isSRetAfterThis() const
FunctionArgList - Type for representing both the decl and type of parameters to a function...
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
ThisAdjustment This
The this pointer adjustment.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
size_t getVTableOffset(size_t i) const
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable, const VTableLayout &VTLayout)
Emit type metadata for the given vtable using the given layout.
This template specialization was instantiated from a template due to an explicit instantiation declar...
void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params)
Build a parameter variable suitable for 'this'.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
void EmitThunks(GlobalDecl GD)
EmitThunks - Emit the associated thunks for the given global decl.
param_iterator param_end()
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class...
const T * getAs() const
Member-template getAs<specific type>'.
StructBuilder beginStruct(llvm::StructType *structTy=nullptr)
This template specialization was declared or defined by an explicit specialization (C++ [temp...
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
llvm::PointerType * Int8PtrTy
static bool shouldEmitVTableAtEndOfTranslationUnit(CodeGenModule &CGM, const CXXRecordDecl *RD)
Given that we're currently at the end of the translation unit, and we've emitted a reference to the v...
void GenerateClassData(const CXXRecordDecl *RD)
GenerateClassData - Generate all the class data required to be generated upon definition of a KeyFunc...
ReturnAdjustment Return
The return adjustment.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
ABIArgInfo & getReturnInfo()
void StartThunk(llvm::Function *Fn, GlobalDecl GD, const CGFunctionInfo &FnInfo)
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
Address LoadCXXThisAddress()
llvm::Type * GetFunctionTypeForVTable(GlobalDecl GD)
GetFunctionTypeForVTable - Get the LLVM function type for use in a vtable, given a CXXMethodDecl...
llvm::IntegerType * PtrDiffTy
void EmitCallAndReturnForThunk(llvm::Constant *Callee, const ThunkInfo *Thunk)
static RValue PerformReturnAdjustment(CodeGenFunction &CGF, QualType ResultType, RValue RV, const ThunkInfo &Thunk)
const CXXMethodDecl * getCurrentKeyFunction(const CXXRecordDecl *RD)
Get our current best idea for the key function of the given record decl, or NULL if there isn't one...
Represents a C++ struct/union/class.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
virtual void mangleThunk(const CXXMethodDecl *MD, const ThunkInfo &Thunk, raw_ostream &)=0
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
A helper class of ConstantInitBuilder, used for building constant struct initializers.
bool AutoreleaseResult
In ARC, whether we should autorelease the return value.
const_arg_iterator arg_begin() const
A pointer to the deleting destructor.
static RValue get(llvm::Value *V)
unsigned arg_size() const
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional, const FunctionDecl *FD)
Compute the arguments required by the given formal prototype, given that there may be some additional...
const llvm::Triple & getTriple() const
virtual llvm::Value * performReturnAdjustment(CodeGenFunction &CGF, Address Ret, const ReturnAdjustment &RA)=0
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
const AddressPointsMapTy & getAddressPoints() const
CodeGenVTables & getVTables()
CharUnits getBaseOffset() const
getBaseOffset - Returns the base class offset.
SourceLocation getLocation() const
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
CallArgList - Type for representing both the value and type of arguments in a call.
const CGFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const FunctionProtoType *type, RequiredArgs required, unsigned numPrefixArgs)
Arrange a call to a C++ method, passing the given arguments.
A pointer to the complete destructor.
A helper class of ConstantInitBuilder, used for building constant array initializers.
An entry that is never used.
virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable, GlobalDecl GD, bool ReturnAdjustment)=0
bool supportsCOMDAT() const
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::Instruction **callOrInvoke=nullptr)
EmitCall - Generate a call of the given function, expecting the given result type, and using the given argument list which specifies both the LLVM arguments and the types they were derived from.
void EmitVTable(CXXRecordDecl *Class)
This is a callback from Sema to tell us that that a particular vtable is required to be emitted in th...
void EmitMustTailThunk(const CXXMethodDecl *MD, llvm::Value *AdjustedThisPtr, llvm::Value *Callee)
Emit a musttail call for a thunk with a potentially adjusted this pointer.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.