Rename GetAddrOfRTTI to GetAddrOfRTTIDescriptor. Remove the overload that takes a CXXRecordDecl since we were just creating a QualType from it anyway.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91590 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index 7f827cc..6a3b8bf 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -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);