[cfe-commits] r91590 - in /cfe/trunk/lib/CodeGen: CGException.cpp CGExprCXX.cpp CGRTTI.cpp CGVtable.cpp CodeGenModule.h
Anders Carlsson
andersca at mac.com
Wed Dec 16 23:09:17 PST 2009
Author: andersca
Date: Thu Dec 17 01:09:17 2009
New Revision: 91590
URL: http://llvm.org/viewvc/llvm-project?rev=91590&view=rev
Log:
Rename GetAddrOfRTTI to GetAddrOfRTTIDescriptor. Remove the overload that takes a CXXRecordDecl since we were just creating a QualType from it anyway.
Modified:
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CGRTTI.cpp
cfe/trunk/lib/CodeGen/CGVtable.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=91590&r1=91589&r2=91590&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Thu Dec 17 01:09:17 2009
@@ -284,7 +284,7 @@
// Now throw the exception.
const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(getLLVMContext());
- llvm::Constant *TypeInfo = CGM.GetAddrOfRTTI(ThrowType);
+ llvm::Constant *TypeInfo = CGM.GetAddrOfRTTIDescriptor(ThrowType);
llvm::Constant *Dtor = llvm::Constant::getNullValue(Int8PtrTy);
if (getInvokeDest()) {
@@ -367,7 +367,7 @@
for (unsigned i = 0; i < Proto->getNumExceptions(); ++i) {
QualType Ty = Proto->getExceptionType(i);
- llvm::Value *EHType = CGM.GetAddrOfRTTI(Ty.getNonReferenceType());
+ llvm::Value *EHType = CGM.GetAddrOfRTTIDescriptor(Ty.getNonReferenceType());
SelectorArgs.push_back(EHType);
}
if (Proto->getNumExceptions())
@@ -506,9 +506,9 @@
const CXXCatchStmt *C = S.getHandler(i);
VarDecl *CatchParam = C->getExceptionDecl();
if (CatchParam) {
- llvm::Value *EHType
- = CGM.GetAddrOfRTTI(C->getCaughtType().getNonReferenceType());
- SelectorArgs.push_back(EHType);
+ llvm::Value *EHTypeInfo
+ = CGM.GetAddrOfRTTIDescriptor(C->getCaughtType().getNonReferenceType());
+ SelectorArgs.push_back(EHTypeInfo);
} else {
// null indicates catch all
SelectorArgs.push_back(Null);
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=91590&r1=91589&r2=91590&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Thu Dec 17 01:09:17 2009
@@ -426,9 +426,12 @@
QualType Ty = E->getType();
const llvm::Type *LTy = ConvertType(Ty)->getPointerTo();
- if (E->isTypeOperand())
- return Builder.CreateBitCast(CGM.GetAddrOfRTTI(E->getTypeOperand()), LTy);
-
+ if (E->isTypeOperand()) {
+ llvm::Constant *TypeInfo =
+ CGM.GetAddrOfRTTIDescriptor(E->getTypeOperand());
+ return Builder.CreateBitCast(TypeInfo, LTy);
+ }
+
Expr *subE = E->getExprOperand();
Ty = subE->getType();
CanQualType CanTy = CGM.getContext().getCanonicalType(Ty);
@@ -468,24 +471,23 @@
V = Builder.CreateConstInBoundsGEP1_64(V, -1ULL);
V = Builder.CreateLoad(V);
return V;
- }
- return Builder.CreateBitCast(CGM.GetAddrOfRTTI(RD), LTy);
+ }
}
- return Builder.CreateBitCast(CGM.GetAddrOfRTTI(Ty), LTy);
+ return Builder.CreateBitCast(CGM.GetAddrOfRTTIDescriptor(Ty), LTy);
}
llvm::Value *CodeGenFunction::EmitDynamicCast(llvm::Value *V,
const CXXDynamicCastExpr *DCE) {
- QualType CastTy = DCE->getTypeAsWritten();
- QualType InnerType = CastTy->getPointeeType();
- QualType ArgTy = DCE->getSubExpr()->getType();
- const llvm::Type *LArgTy = ConvertType(ArgTy);
+ QualType SrcTy = DCE->getSubExpr()->getType();
+ QualType DestTy = DCE->getTypeAsWritten();
+ QualType InnerType = DestTy->getPointeeType();
+
const llvm::Type *LTy = ConvertType(DCE->getType());
bool CanBeZero = false;
bool ToVoid = false;
bool ThrowOnBad = false;
- if (CastTy->isPointerType()) {
+ if (DestTy->isPointerType()) {
// FIXME: if PointerType->hasAttr<NonNullAttr>(), we don't set this
CanBeZero = true;
if (InnerType->isVoidType())
@@ -495,14 +497,13 @@
ThrowOnBad = true;
}
- CXXRecordDecl *SrcTy;
- QualType Ty = ArgTy;
- if (ArgTy.getTypePtr()->isPointerType()
- || ArgTy.getTypePtr()->isReferenceType())
- Ty = Ty.getTypePtr()->getPointeeType();
- CanQualType CanTy = CGM.getContext().getCanonicalType(Ty);
- Ty = CanTy.getUnqualifiedType();
- SrcTy = cast<CXXRecordDecl>(Ty->getAs<RecordType>()->getDecl());
+ if (SrcTy->isPointerType() || SrcTy->isReferenceType())
+ SrcTy = SrcTy->getPointeeType();
+ SrcTy = SrcTy.getUnqualifiedType();
+
+ if (DestTy->isPointerType())
+ DestTy = DestTy->getPointeeType();
+ DestTy = DestTy.getUnqualifiedType();
llvm::BasicBlock *ContBlock = createBasicBlock();
llvm::BasicBlock *NullBlock = 0;
@@ -510,15 +511,13 @@
if (CanBeZero) {
NonZeroBlock = createBasicBlock();
NullBlock = createBasicBlock();
- llvm::Value *Zero = llvm::Constant::getNullValue(LArgTy);
- Builder.CreateCondBr(Builder.CreateICmpNE(V, Zero),
- NonZeroBlock, NullBlock);
+ Builder.CreateCondBr(Builder.CreateIsNotNull(V), NonZeroBlock, NullBlock);
EmitBlock(NonZeroBlock);
}
llvm::BasicBlock *BadCastBlock = 0;
- const llvm::Type *PtrDiffTy = ConvertType(getContext().getSizeType());
+ const llvm::Type *PtrDiffTy = ConvertType(getContext().getPointerDiffType());
// See if this is a dynamic_cast(void*)
if (ToVoid) {
@@ -542,27 +541,25 @@
ArgTys.push_back(PtrToInt8Ty);
ArgTys.push_back(PtrDiffTy);
FTy = llvm::FunctionType::get(ResultType, ArgTys, false);
- CXXRecordDecl *DstTy;
- Ty = CastTy.getTypePtr()->getPointeeType();
- CanTy = CGM.getContext().getCanonicalType(Ty);
- Ty = CanTy.getUnqualifiedType();
- DstTy = cast<CXXRecordDecl>(Ty->getAs<RecordType>()->getDecl());
// FIXME: Calculate better hint.
llvm::Value *hint = llvm::ConstantInt::get(PtrDiffTy, -1ULL);
- llvm::Value *SrcArg = CGM.GetAddrOfRTTI(SrcTy);
- llvm::Value *DstArg = CGM.GetAddrOfRTTI(DstTy);
+
+ assert(SrcTy->isRecordType() && "Src type must be record type!");
+ assert(DestTy->isRecordType() && "Dest type must be record type!");
+
+ llvm::Value *SrcArg = CGM.GetAddrOfRTTIDescriptor(SrcTy);
+ llvm::Value *DestArg = CGM.GetAddrOfRTTIDescriptor(DestTy);
+
V = Builder.CreateBitCast(V, PtrToInt8Ty);
V = Builder.CreateCall4(CGM.CreateRuntimeFunction(FTy, "__dynamic_cast"),
- V, SrcArg, DstArg, hint);
+ V, SrcArg, DestArg, hint);
V = Builder.CreateBitCast(V, LTy);
if (ThrowOnBad) {
BadCastBlock = createBasicBlock();
- llvm::Value *Zero = llvm::Constant::getNullValue(LTy);
- Builder.CreateCondBr(Builder.CreateICmpNE(V, Zero),
- ContBlock, BadCastBlock);
+ Builder.CreateCondBr(Builder.CreateIsNotNull(V), ContBlock, BadCastBlock);
EmitBlock(BadCastBlock);
/// Call __cxa_bad_cast
ResultType = llvm::Type::getVoidTy(VMContext);
Modified: cfe/trunk/lib/CodeGen/CGRTTI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRTTI.cpp?rev=91590&r1=91589&r2=91590&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRTTI.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRTTI.cpp Thu Dec 17 01:09:17 2009
@@ -46,6 +46,10 @@
TI_ContainingClassIncomplete = 0x10
};
+ /// GetAddrOfExternalRTTIDescriptor - Returns the constant for the RTTI
+ /// descriptor of the given type.
+ llvm::Constant *GetAddrOfExternalRTTIDescriptor(QualType Ty);
+
public:
RTTIBuilder(CodeGenModule &cgm)
: CGM(cgm), VMContext(cgm.getModule().getContext()),
@@ -124,29 +128,6 @@
return llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), c);
}
- llvm::Constant *BuildTypeRef(QualType Ty) {
- llvm::Constant *C;
-
- llvm::SmallString<256> OutName;
- CGM.getMangleContext().mangleCXXRTTI(Ty, OutName);
- llvm::StringRef Name = OutName.str();
-
- C = CGM.getModule().getGlobalVariable(Name);
- if (C)
- return llvm::ConstantExpr::getBitCast(C, Int8PtrTy);
-
- llvm::GlobalVariable::LinkageTypes linktype;
- linktype = llvm::GlobalValue::ExternalLinkage;;
-
- C = new llvm::GlobalVariable(CGM.getModule(), Int8PtrTy, true, linktype,
- 0, Name);
- return llvm::ConstantExpr::getBitCast(C, Int8PtrTy);
- }
-
- llvm::Constant *Buildclass_type_infoRef(const CXXRecordDecl *RD) {
- return BuildTypeRef(CGM.getContext().getTagDeclType(RD));
- }
-
/// CalculateFlags - Calculate the flags for the __vmi_class_type_info
/// datastructure. 1 for non-diamond repeated inheritance, 2 for a dimond
/// shaped class.
@@ -256,9 +237,10 @@
const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
+ QualType BaseType = i->getType();
const CXXRecordDecl *Base =
- cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
- Info.push_back(CGM.GetAddrOfRTTI(Base));
+ cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl());
+ Info.push_back(CGM.GetAddrOfRTTIDescriptor(BaseType));
if (simple)
break;
int64_t offset;
@@ -412,7 +394,7 @@
case Type::Builtin: {
// We expect all type_info objects for builtin types to be in the library.
- return BuildTypeRef(Ty);
+ return GetAddrOfExternalRTTIDescriptor(Ty);
}
case Type::Pointer: {
@@ -421,7 +403,7 @@
Q.removeConst();
// T* and const T* for all builtin types T are expected in the library.
if (isa<BuiltinType>(PTy) && Q.empty())
- return BuildTypeRef(Ty);
+ return GetAddrOfExternalRTTIDescriptor(Ty);
return BuildPointerType(Ty);
}
@@ -456,7 +438,8 @@
return Buildclass_type_info(RD, llvm::GlobalValue::ExternalLinkage);
// Otherwise, we just want a reference to the type info.
- return Buildclass_type_infoRef(RD);
+ QualType Ty = CGM.getContext().getTagDeclType(RD);
+ return GetAddrOfExternalRTTIDescriptor(Ty);
}
// If there is no key function (or if the record doesn't have any virtual
@@ -467,16 +450,25 @@
};
}
-llvm::Constant *CodeGenModule::GetAddrOfRTTI(const CXXRecordDecl *RD) {
- if (!getContext().getLangOptions().RTTI) {
- const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext);
- return llvm::Constant::getNullValue(Int8PtrTy);
+llvm::Constant *RTTIBuilder::GetAddrOfExternalRTTIDescriptor(QualType Ty) {
+ // Mangle the RTTI name.
+ llvm::SmallString<256> OutName;
+ CGM.getMangleContext().mangleCXXRTTI(Ty, OutName);
+ llvm::StringRef Name = OutName.str();
+
+ // Look for an existing global variable.
+ llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name);
+
+ if (!GV) {
+ // Create a new global variable.
+ GV = new llvm::GlobalVariable(CGM.getModule(), Int8PtrTy, /*Constant=*/true,
+ llvm::GlobalValue::ExternalLinkage, 0, Name);
}
- return RTTIBuilder(*this).BuildClassTypeInfo(RD);
+ return llvm::ConstantExpr::getBitCast(GV, Int8PtrTy);
}
-llvm::Constant *CodeGenModule::GetAddrOfRTTI(QualType Ty) {
+llvm::Constant *CodeGenModule::GetAddrOfRTTIDescriptor(QualType Ty) {
if (!getContext().getLangOptions().RTTI) {
const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext);
return llvm::Constant::getNullValue(Int8PtrTy);
Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=91590&r1=91589&r2=91590&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Thu Dec 17 01:09:17 2009
@@ -202,8 +202,10 @@
Extern(!l->isInAnonymousNamespace()),
LLVMPointerWidth(cgm.getContext().Target.getPointerWidth(0)) {
Ptr8Ty = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0);
- if (BuildVtable)
- rtti = CGM.GetAddrOfRTTI(MostDerivedClass);
+ if (BuildVtable) {
+ QualType ClassType = CGM.getContext().getTagDeclType(MostDerivedClass);
+ rtti = CGM.GetAddrOfRTTIDescriptor(ClassType);
+ }
}
// getVtableComponents - Returns a reference to the vtable components.
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=91590&r1=91589&r2=91590&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Dec 17 01:09:17 2009
@@ -212,12 +212,9 @@
llvm::Constant *GetAddrOfFunction(GlobalDecl GD,
const llvm::Type *Ty = 0);
- /// GetAddrOfRTTI - Get the address of the RTTI structure for the given type.
- llvm::Constant *GetAddrOfRTTI(QualType Ty);
-
- /// GetAddrOfRTTI - Get the address of the RTTI structure for the given record
- /// decl.
- llvm::Constant *GetAddrOfRTTI(const CXXRecordDecl *RD);
+ /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor
+ /// for the given type.
+ llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty);
llvm::Constant *GetAddrOfThunk(GlobalDecl GD,
const ThunkAdjustment &ThisAdjustment);
More information about the cfe-commits
mailing list