ir-gen for nonfragile ivar bitfield access (objc2 nonfragile abi).

llvm-svn: 63644
This commit is contained in:
Fariborz Jahanian 2009-02-03 19:03:09 +00:00
parent d564353193
commit 712bfa6478
5 changed files with 70 additions and 57 deletions

View File

@ -850,8 +850,8 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
LValue CodeGenFunction::EmitLValueForBitfield(llvm::Value* BaseValue, LValue CodeGenFunction::EmitLValueForBitfield(llvm::Value* BaseValue,
FieldDecl* Field, FieldDecl* Field,
unsigned CVRQualifiers, unsigned CVRQualifiers) {
unsigned idx) { unsigned idx = CGM.getTypes().getLLVMFieldNo(Field);
// FIXME: CodeGenTypes should expose a method to get the appropriate // FIXME: CodeGenTypes should expose a method to get the appropriate
// type for FieldTy (the appropriate type is ABI-dependent). // type for FieldTy (the appropriate type is ABI-dependent).
const llvm::Type *FieldTy = CGM.getTypes().ConvertTypeForMem(Field->getType()); const llvm::Type *FieldTy = CGM.getTypes().ConvertTypeForMem(Field->getType());
@ -877,11 +877,10 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
bool isUnion, bool isUnion,
unsigned CVRQualifiers) unsigned CVRQualifiers)
{ {
unsigned idx = CGM.getTypes().getLLVMFieldNo(Field);
if (Field->isBitField()) 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"); llvm::Value *V = Builder.CreateStructGEP(BaseValue, idx, "tmp");
// Match union field type. // Match union field type.
@ -1028,19 +1027,12 @@ LValue CodeGenFunction::EmitLValueForIvar(QualType ObjectTy,
// See comment in EmitIvarOffset. // See comment in EmitIvarOffset.
if (CGM.getObjCRuntime().LateBoundIVars()) if (CGM.getObjCRuntime().LateBoundIVars())
assert(0 && "late-bound ivars are unsupported"); 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()) { LValue LV = CGM.getObjCRuntime().EmitObjCValueForIvar(*this,
return EmitLValueForBitfield(BaseValue, const_cast<FieldDecl *>(Field), ObjectTy,
CVRQualifiers, Index); BaseValue, Ivar, Field,
} CVRQualifiers);
llvm::Value *V = CGM.getObjCRuntime().EmitObjCValueForIvar(*this,
ObjectTy,
BaseValue, Ivar, Field, CVRQualifiers);
LValue LV = LValue::MakeAddr(V, Ivar->getType().getCVRQualifiers()|CVRQualifiers);
SetVarDeclObjCAttribute(getContext(), Ivar, Ivar->getType(), LV); SetVarDeclObjCAttribute(getContext(), Ivar, Ivar->getType(), LV);
LValue::SetObjCIvar(LV, true);
return LV; return LV;
} }

View File

@ -140,12 +140,12 @@ public:
llvm::Value *src, llvm::Value *dest); llvm::Value *src, llvm::Value *dest);
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
llvm::Value *src, llvm::Value *dest); llvm::Value *src, llvm::Value *dest);
virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
QualType ObjectTy, QualType ObjectTy,
llvm::Value *BaseValue, llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar, const ObjCIvarDecl *Ivar,
const FieldDecl *Field, const FieldDecl *Field,
unsigned CVRQualifiers); unsigned CVRQualifiers);
}; };
} // end anonymous namespace } // end anonymous namespace
@ -1037,16 +1037,22 @@ void CGObjCGNU::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
return; return;
} }
llvm::Value *CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, LValue CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
QualType ObjectTy, QualType ObjectTy,
llvm::Value *BaseValue, llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar, const ObjCIvarDecl *Ivar,
const FieldDecl *Field, const FieldDecl *Field,
unsigned CVRQualifiers) { unsigned CVRQualifiers) {
if (Ivar->isBitField())
return CGF.EmitLValueForBitfield(BaseValue, const_cast<FieldDecl *>(Field),
CVRQualifiers);
// TODO: Add a special case for isa (index 0) // TODO: Add a special case for isa (index 0)
unsigned Index = CGM.getTypes().getLLVMFieldNo(Field); unsigned Index = CGM.getTypes().getLLVMFieldNo(Field);
llvm::Value *V = CGF.Builder.CreateStructGEP(BaseValue, Index, "tmp"); 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){ CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){

View File

@ -550,12 +550,12 @@ private:
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
llvm::Value *src, llvm::Value *dest); llvm::Value *src, llvm::Value *dest);
virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
QualType ObjectTy, QualType ObjectTy,
llvm::Value *BaseValue, llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar, const ObjCIvarDecl *Ivar,
const FieldDecl *Field, const FieldDecl *Field,
unsigned CVRQualifiers); unsigned CVRQualifiers);
}; };
class CGObjCNonFragileABIMac : public CGObjCCommonMac { class CGObjCNonFragileABIMac : public CGObjCCommonMac {
@ -676,12 +676,12 @@ public:
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
llvm::Value *src, llvm::Value *dest) llvm::Value *src, llvm::Value *dest)
{ return; } { return; }
virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
QualType ObjectTy, QualType ObjectTy,
llvm::Value *BaseValue, llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar, const ObjCIvarDecl *Ivar,
const FieldDecl *Field, const FieldDecl *Field,
unsigned CVRQualifiers); unsigned CVRQualifiers);
}; };
} // end anonymous namespace } // end anonymous namespace
@ -2113,16 +2113,22 @@ void CGObjCMac::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
/// EmitObjCValueForIvar - Code Gen for ivar reference. /// EmitObjCValueForIvar - Code Gen for ivar reference.
/// ///
llvm::Value *CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, LValue CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
QualType ObjectTy, QualType ObjectTy,
llvm::Value *BaseValue, llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar, const ObjCIvarDecl *Ivar,
const FieldDecl *Field, const FieldDecl *Field,
unsigned CVRQualifiers) { unsigned CVRQualifiers) {
if (Ivar->isBitField())
return CGF.EmitLValueForBitfield(BaseValue, const_cast<FieldDecl *>(Field),
CVRQualifiers);
// TODO: Add a special case for isa (index 0) // TODO: Add a special case for isa (index 0)
unsigned Index = CGM.getTypes().getLLVMFieldNo(Field); unsigned Index = CGM.getTypes().getLLVMFieldNo(Field);
llvm::Value *V = CGF.Builder.CreateStructGEP(BaseValue, Index, "tmp"); 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 *** */ /* *** Private Interface *** */
@ -4100,7 +4106,7 @@ CGObjCNonFragileABIMac::GetMethodDescriptionConstant(const ObjCMethodDecl *MD) {
/// (type *)((char *)base + _OBJC_IVAR_$_.ivar; /// (type *)((char *)base + _OBJC_IVAR_$_.ivar;
/// @encode /// @encode
/// ///
llvm::Value *CGObjCNonFragileABIMac::EmitObjCValueForIvar( LValue CGObjCNonFragileABIMac::EmitObjCValueForIvar(
CodeGen::CodeGenFunction &CGF, CodeGen::CodeGenFunction &CGF,
QualType ObjectTy, QualType ObjectTy,
llvm::Value *BaseValue, llvm::Value *BaseValue,
@ -4125,6 +4131,7 @@ llvm::Value *CGObjCNonFragileABIMac::EmitObjCValueForIvar(
0, 0,
ExternalName, ExternalName,
&CGM.getModule()); &CGM.getModule());
// (char *) BaseValue // (char *) BaseValue
llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue,
ObjCTypes.Int8PtrTy); ObjCTypes.Int8PtrTy);
@ -4136,7 +4143,15 @@ llvm::Value *CGObjCNonFragileABIMac::EmitObjCValueForIvar(
CGM.getTypes().ConvertType(Ivar->getType()); CGM.getTypes().ConvertType(Ivar->getType());
llvm::Type *ptrIvarTy = llvm::PointerType::getUnqual(IvarTy); llvm::Type *ptrIvarTy = llvm::PointerType::getUnqual(IvarTy);
V = CGF.Builder.CreateBitCast(V, ptrIvarTy); V = CGF.Builder.CreateBitCast(V, ptrIvarTy);
return V;
if (Ivar->isBitField())
return CGF.EmitLValueForBitfield(V, const_cast<FieldDecl *>(Field),
CVRQualifiers);
LValue LV = LValue::MakeAddr(V,
Ivar->getType().getCVRQualifiers()|CVRQualifiers);
LValue::SetObjCIvar(LV, true);
return LV;
} }
/* *** */ /* *** */

View File

@ -157,12 +157,12 @@ public:
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
llvm::Value *src, llvm::Value *dest) = 0; llvm::Value *src, llvm::Value *dest) = 0;
virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
QualType ObjectTy, QualType ObjectTy,
llvm::Value *BaseValue, llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar, const ObjCIvarDecl *Ivar,
const FieldDecl *Field, const FieldDecl *Field,
unsigned CVRQualifiers) = 0; unsigned CVRQualifiers) = 0;
}; };
/// Creates an instance of an Objective-C runtime class. /// Creates an instance of an Objective-C runtime class.

View File

@ -531,7 +531,7 @@ public:
unsigned CVRQualifiers); unsigned CVRQualifiers);
LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field, LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field,
unsigned CVRQualifiers, unsigned idx); unsigned CVRQualifiers);
LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E); LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E);