From 712bfa64788fcb98e3bce3beaa3203a451a498fe Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 3 Feb 2009 19:03:09 +0000 Subject: [PATCH] ir-gen for nonfragile ivar bitfield access (objc2 nonfragile abi). llvm-svn: 63644 --- clang/lib/CodeGen/CGExpr.cpp | 24 ++++-------- clang/lib/CodeGen/CGObjCGNU.cpp | 32 +++++++++------- clang/lib/CodeGen/CGObjCMac.cpp | 57 ++++++++++++++++++----------- clang/lib/CodeGen/CGObjCRuntime.h | 12 +++--- clang/lib/CodeGen/CodeGenFunction.h | 2 +- 5 files changed, 70 insertions(+), 57 deletions(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 4f8bd46b5242..f085127da2ab 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -850,8 +850,8 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) { LValue CodeGenFunction::EmitLValueForBitfield(llvm::Value* BaseValue, FieldDecl* Field, - unsigned CVRQualifiers, - unsigned idx) { + unsigned CVRQualifiers) { + unsigned idx = CGM.getTypes().getLLVMFieldNo(Field); // FIXME: CodeGenTypes should expose a method to get the appropriate // type for FieldTy (the appropriate type is ABI-dependent). const llvm::Type *FieldTy = CGM.getTypes().ConvertTypeForMem(Field->getType()); @@ -877,11 +877,10 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue, bool isUnion, unsigned CVRQualifiers) { - unsigned idx = CGM.getTypes().getLLVMFieldNo(Field); - if (Field->isBitField()) - return EmitLValueForBitfield(BaseValue, Field, CVRQualifiers, idx); + return EmitLValueForBitfield(BaseValue, Field, CVRQualifiers); + unsigned idx = CGM.getTypes().getLLVMFieldNo(Field); llvm::Value *V = Builder.CreateStructGEP(BaseValue, idx, "tmp"); // Match union field type. @@ -1028,19 +1027,12 @@ LValue CodeGenFunction::EmitLValueForIvar(QualType ObjectTy, // See comment in EmitIvarOffset. if (CGM.getObjCRuntime().LateBoundIVars()) assert(0 && "late-bound ivars are unsupported"); - // TODO: Add a special case for isa (index 0) - unsigned Index = CGM.getTypes().getLLVMFieldNo(Field); - if (Ivar->isBitField()) { - return EmitLValueForBitfield(BaseValue, const_cast(Field), - CVRQualifiers, Index); - } - llvm::Value *V = CGM.getObjCRuntime().EmitObjCValueForIvar(*this, - ObjectTy, - BaseValue, Ivar, Field, CVRQualifiers); - LValue LV = LValue::MakeAddr(V, Ivar->getType().getCVRQualifiers()|CVRQualifiers); + LValue LV = CGM.getObjCRuntime().EmitObjCValueForIvar(*this, + ObjectTy, + BaseValue, Ivar, Field, + CVRQualifiers); SetVarDeclObjCAttribute(getContext(), Ivar, Ivar->getType(), LV); - LValue::SetObjCIvar(LV, true); return LV; } diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index d3b57b0e9afa..bd1ba68cdef1 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -140,12 +140,12 @@ public: llvm::Value *src, llvm::Value *dest); virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dest); - virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, - QualType ObjectTy, - llvm::Value *BaseValue, - const ObjCIvarDecl *Ivar, - const FieldDecl *Field, - unsigned CVRQualifiers); + virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, + QualType ObjectTy, + llvm::Value *BaseValue, + const ObjCIvarDecl *Ivar, + const FieldDecl *Field, + unsigned CVRQualifiers); }; } // end anonymous namespace @@ -1037,16 +1037,22 @@ void CGObjCGNU::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, return; } -llvm::Value *CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, - QualType ObjectTy, - llvm::Value *BaseValue, - const ObjCIvarDecl *Ivar, - const FieldDecl *Field, - unsigned CVRQualifiers) { +LValue CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, + QualType ObjectTy, + llvm::Value *BaseValue, + const ObjCIvarDecl *Ivar, + const FieldDecl *Field, + unsigned CVRQualifiers) { + if (Ivar->isBitField()) + return CGF.EmitLValueForBitfield(BaseValue, const_cast(Field), + CVRQualifiers); // TODO: Add a special case for isa (index 0) unsigned Index = CGM.getTypes().getLLVMFieldNo(Field); llvm::Value *V = CGF.Builder.CreateStructGEP(BaseValue, Index, "tmp"); - return V; + LValue LV = LValue::MakeAddr(V, + Ivar->getType().getCVRQualifiers()|CVRQualifiers); + LValue::SetObjCIvar(LV, true); + return LV; } CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){ diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index c7af972e9a76..06343f80c941 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -550,12 +550,12 @@ private: virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dest); - virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, - QualType ObjectTy, - llvm::Value *BaseValue, - const ObjCIvarDecl *Ivar, - const FieldDecl *Field, - unsigned CVRQualifiers); + virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, + QualType ObjectTy, + llvm::Value *BaseValue, + const ObjCIvarDecl *Ivar, + const FieldDecl *Field, + unsigned CVRQualifiers); }; class CGObjCNonFragileABIMac : public CGObjCCommonMac { @@ -676,12 +676,12 @@ public: virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dest) { return; } - virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, - QualType ObjectTy, - llvm::Value *BaseValue, - const ObjCIvarDecl *Ivar, - const FieldDecl *Field, - unsigned CVRQualifiers); + virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, + QualType ObjectTy, + llvm::Value *BaseValue, + const ObjCIvarDecl *Ivar, + const FieldDecl *Field, + unsigned CVRQualifiers); }; } // end anonymous namespace @@ -2113,16 +2113,22 @@ void CGObjCMac::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, /// EmitObjCValueForIvar - Code Gen for ivar reference. /// -llvm::Value *CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, - QualType ObjectTy, - llvm::Value *BaseValue, - const ObjCIvarDecl *Ivar, - const FieldDecl *Field, - unsigned CVRQualifiers) { +LValue CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, + QualType ObjectTy, + llvm::Value *BaseValue, + const ObjCIvarDecl *Ivar, + const FieldDecl *Field, + unsigned CVRQualifiers) { + if (Ivar->isBitField()) + return CGF.EmitLValueForBitfield(BaseValue, const_cast(Field), + CVRQualifiers); // TODO: Add a special case for isa (index 0) unsigned Index = CGM.getTypes().getLLVMFieldNo(Field); llvm::Value *V = CGF.Builder.CreateStructGEP(BaseValue, Index, "tmp"); - return V; + LValue LV = LValue::MakeAddr(V, + Ivar->getType().getCVRQualifiers()|CVRQualifiers); + LValue::SetObjCIvar(LV, true); + return LV; } /* *** Private Interface *** */ @@ -4100,7 +4106,7 @@ CGObjCNonFragileABIMac::GetMethodDescriptionConstant(const ObjCMethodDecl *MD) { /// (type *)((char *)base + _OBJC_IVAR_$_.ivar; /// @encode /// -llvm::Value *CGObjCNonFragileABIMac::EmitObjCValueForIvar( +LValue CGObjCNonFragileABIMac::EmitObjCValueForIvar( CodeGen::CodeGenFunction &CGF, QualType ObjectTy, llvm::Value *BaseValue, @@ -4125,6 +4131,7 @@ llvm::Value *CGObjCNonFragileABIMac::EmitObjCValueForIvar( 0, ExternalName, &CGM.getModule()); + // (char *) BaseValue llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, ObjCTypes.Int8PtrTy); @@ -4136,7 +4143,15 @@ llvm::Value *CGObjCNonFragileABIMac::EmitObjCValueForIvar( CGM.getTypes().ConvertType(Ivar->getType()); llvm::Type *ptrIvarTy = llvm::PointerType::getUnqual(IvarTy); V = CGF.Builder.CreateBitCast(V, ptrIvarTy); - return V; + + if (Ivar->isBitField()) + return CGF.EmitLValueForBitfield(V, const_cast(Field), + CVRQualifiers); + + LValue LV = LValue::MakeAddr(V, + Ivar->getType().getCVRQualifiers()|CVRQualifiers); + LValue::SetObjCIvar(LV, true); + return LV; } /* *** */ diff --git a/clang/lib/CodeGen/CGObjCRuntime.h b/clang/lib/CodeGen/CGObjCRuntime.h index ade77af1561b..c85e9debb6e1 100644 --- a/clang/lib/CodeGen/CGObjCRuntime.h +++ b/clang/lib/CodeGen/CGObjCRuntime.h @@ -157,12 +157,12 @@ public: virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, llvm::Value *dest) = 0; - virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, - QualType ObjectTy, - llvm::Value *BaseValue, - const ObjCIvarDecl *Ivar, - const FieldDecl *Field, - unsigned CVRQualifiers) = 0; + virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, + QualType ObjectTy, + llvm::Value *BaseValue, + const ObjCIvarDecl *Ivar, + const FieldDecl *Field, + unsigned CVRQualifiers) = 0; }; /// Creates an instance of an Objective-C runtime class. diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 31b2c4e4e408..0e6660c686a0 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -531,7 +531,7 @@ public: unsigned CVRQualifiers); LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field, - unsigned CVRQualifiers, unsigned idx); + unsigned CVRQualifiers); LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E);