[cfe-commits] r148336 - in /cfe/trunk/lib/CodeGen: CGCXXABI.cpp CGCXXABI.h CGExprConstant.cpp ItaniumCXXABI.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Tue Jan 17 13:42:19 PST 2012
Author: rsmith
Date: Tue Jan 17 15:42:19 2012
New Revision: 148336
URL: http://llvm.org/viewvc/llvm-project?rev=148336&view=rev
Log:
Remove constant member pointer support from Expr-based constant emission now
that APValue-based constant emission knows how to emit member pointers.
Modified:
cfe/trunk/lib/CodeGen/CGCXXABI.cpp
cfe/trunk/lib/CodeGen/CGCXXABI.h
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.cpp?rev=148336&r1=148335&r2=148336&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.cpp Tue Jan 17 15:42:19 2012
@@ -90,11 +90,6 @@
}
llvm::Constant *
-CGCXXABI::EmitMemberPointerConversion(llvm::Constant *C, const CastExpr *E) {
- return GetBogusMemberPointer(CGM, E->getType());
-}
-
-llvm::Constant *
CGCXXABI::EmitNullMemberPointer(const MemberPointerType *MPT) {
return GetBogusMemberPointer(CGM, QualType(MPT, 0));
}
Modified: cfe/trunk/lib/CodeGen/CGCXXABI.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.h?rev=148336&r1=148335&r2=148336&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.h Tue Jan 17 15:42:19 2012
@@ -106,11 +106,6 @@
const CastExpr *E,
llvm::Value *Src);
- /// Perform a derived-to-base or base-to-derived member pointer
- /// conversion on a constant member pointer.
- virtual llvm::Constant *EmitMemberPointerConversion(llvm::Constant *C,
- const CastExpr *E);
-
/// Return true if the given member pointer can be zero-initialized
/// (in the C++ sense) with an LLVM zeroinitializer.
virtual bool isZeroInitializable(const MemberPointerType *MPT);
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=148336&r1=148335&r2=148336&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Jan 17 15:42:19 2012
@@ -535,7 +535,11 @@
//===----------------------------------------------------------------------===//
// ConstExprEmitter
//===----------------------------------------------------------------------===//
-
+
+/// This class only needs to handle two cases:
+/// 1) Literals (this is used by APValue emission to emit literals).
+/// 2) Arrays, structs and unions (outside C++11 mode, we don't currently
+/// constant fold these types).
class ConstExprEmitter :
public StmtVisitor<ConstExprEmitter, llvm::Constant*> {
CodeGenModule &CGM;
@@ -571,13 +575,6 @@
return Visit(E->getInitializer());
}
- llvm::Constant *VisitUnaryAddrOf(UnaryOperator *E) {
- if (E->getType()->isMemberPointerType())
- return CGM.getMemberPointerConstant(E);
-
- return 0;
- }
-
llvm::Constant *VisitCastExpr(CastExpr* E) {
Expr *subExpr = E->getSubExpr();
llvm::Constant *C = CGM.EmitConstantExpr(subExpr, subExpr->getType(), CGF);
@@ -614,14 +611,6 @@
llvm::StructType::get(C->getType()->getContext(), Types, false);
return llvm::ConstantStruct::get(STy, Elts);
}
- case CK_NullToMemberPointer: {
- const MemberPointerType *MPT = E->getType()->getAs<MemberPointerType>();
- return CGM.getCXXABI().EmitNullMemberPointer(MPT);
- }
-
- case CK_DerivedToBaseMemberPointer:
- case CK_BaseToDerivedMemberPointer:
- return CGM.getCXXABI().EmitMemberPointerConversion(C, E);
case CK_LValueToRValue:
case CK_AtomicToNonAtomic:
@@ -633,22 +622,22 @@
// These will never be supported.
case CK_ObjCObjectLValueCast:
- case CK_ToVoid:
- case CK_Dynamic:
case CK_ARCProduceObject:
case CK_ARCConsumeObject:
case CK_ARCReclaimReturnedObject:
case CK_ARCExtendBlockObject:
- case CK_LValueBitCast:
return 0;
- // These might need to be supported for constexpr.
+ // These don't need to be handled here because Evaluate knows how to
+ // evaluate them in the cases where they can be folded.
+ case CK_ToVoid:
+ case CK_Dynamic:
+ case CK_LValueBitCast:
+ case CK_NullToMemberPointer:
+ case CK_DerivedToBaseMemberPointer:
+ case CK_BaseToDerivedMemberPointer:
case CK_UserDefinedConversion:
case CK_ConstructorConversion:
- return 0;
-
- // These don't need to be handled here because Evaluate knows how to
- // evaluate all scalar expressions which can be constant-evaluated.
case CK_CPointerToObjCPointerCast:
case CK_BlockPointerToObjCPointerCast:
case CK_AnyPointerToBlockPointerCast:
Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=148336&r1=148335&r2=148336&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Tue Jan 17 15:42:19 2012
@@ -74,9 +74,6 @@
const CastExpr *E,
llvm::Value *Src);
- llvm::Constant *EmitMemberPointerConversion(llvm::Constant *C,
- const CastExpr *E);
-
llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
@@ -342,9 +339,6 @@
assert(E->getCastKind() == CK_DerivedToBaseMemberPointer ||
E->getCastKind() == CK_BaseToDerivedMemberPointer);
- if (isa<llvm::Constant>(Src))
- return EmitMemberPointerConversion(cast<llvm::Constant>(Src), E);
-
CGBuilderTy &Builder = CGF.Builder;
const MemberPointerType *SrcTy =
@@ -402,84 +396,6 @@
}
llvm::Constant *
-ItaniumCXXABI::EmitMemberPointerConversion(llvm::Constant *C,
- const CastExpr *E) {
- const MemberPointerType *SrcTy =
- E->getSubExpr()->getType()->getAs<MemberPointerType>();
- const MemberPointerType *DestTy =
- E->getType()->getAs<MemberPointerType>();
-
- bool DerivedToBase =
- E->getCastKind() == CK_DerivedToBaseMemberPointer;
-
- const CXXRecordDecl *DerivedDecl;
- if (DerivedToBase)
- DerivedDecl = SrcTy->getClass()->getAsCXXRecordDecl();
- else
- DerivedDecl = DestTy->getClass()->getAsCXXRecordDecl();
-
- // Calculate the offset to the base class.
- llvm::Constant *Offset =
- CGM.GetNonVirtualBaseClassOffset(DerivedDecl,
- E->path_begin(),
- E->path_end());
- // If there's no offset, we're done.
- if (!Offset) return C;
-
- // If the source is a member data pointer, we have to do a null
- // check and then add the offset. In the common case, we can fold
- // away the offset.
- if (SrcTy->isMemberDataPointer()) {
- assert(C->getType() == getPtrDiffTy());
-
- // If it's a constant int, just create a new constant int.
- if (llvm::ConstantInt *CI = dyn_cast<llvm::ConstantInt>(C)) {
- int64_t Src = CI->getSExtValue();
-
- // Null converts to null.
- if (Src == -1) return CI;
-
- // Otherwise, just add the offset.
- int64_t OffsetV = cast<llvm::ConstantInt>(Offset)->getSExtValue();
- int64_t Dst = (DerivedToBase ? Src - OffsetV : Src + OffsetV);
- return llvm::ConstantInt::get(CI->getType(), Dst, /*signed*/ true);
- }
-
- // Otherwise, we have to form a constant select expression.
- llvm::Constant *Null = llvm::Constant::getAllOnesValue(C->getType());
-
- llvm::Constant *IsNull =
- llvm::ConstantExpr::getICmp(llvm::ICmpInst::ICMP_EQ, C, Null);
-
- llvm::Constant *Dst;
- if (DerivedToBase)
- Dst = llvm::ConstantExpr::getNSWSub(C, Offset);
- else
- Dst = llvm::ConstantExpr::getNSWAdd(C, Offset);
-
- return llvm::ConstantExpr::getSelect(IsNull, Null, Dst);
- }
-
- // The this-adjustment is left-shifted by 1 on ARM.
- if (IsARM) {
- int64_t OffsetV = cast<llvm::ConstantInt>(Offset)->getSExtValue();
- OffsetV <<= 1;
- Offset = llvm::ConstantInt::get(Offset->getType(), OffsetV);
- }
-
- llvm::ConstantStruct *CS = cast<llvm::ConstantStruct>(C);
-
- llvm::Constant *Values[2] = { CS->getOperand(0), 0 };
- if (DerivedToBase)
- Values[1] = llvm::ConstantExpr::getSub(CS->getOperand(1), Offset);
- else
- Values[1] = llvm::ConstantExpr::getAdd(CS->getOperand(1), Offset);
-
- return llvm::ConstantStruct::get(CS->getType(), Values);
-}
-
-
-llvm::Constant *
ItaniumCXXABI::EmitNullMemberPointer(const MemberPointerType *MPT) {
llvm::Type *ptrdiff_t = getPtrDiffTy();
More information about the cfe-commits
mailing list