[cfe-commits] r63578 - in /cfe/trunk/lib/CodeGen: CGExpr.cpp CGObjC.cpp CGObjCGNU.cpp CGObjCMac.cpp CGObjCRuntime.h CodeGenFunction.h
Fariborz Jahanian
fjahanian at apple.com
Mon Feb 2 16:09:52 PST 2009
Author: fjahanian
Date: Mon Feb 2 18:09:52 2009
New Revision: 63578
URL: http://llvm.org/viewvc/llvm-project?rev=63578&view=rev
Log:
objc2's ir-gen for nonfragile ivar access.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=63578&r1=63577&r2=63578&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Feb 2 18:09:52 2009
@@ -1020,7 +1020,8 @@
Offset);
}
-LValue CodeGenFunction::EmitLValueForIvar(llvm::Value *BaseValue,
+LValue CodeGenFunction::EmitLValueForIvar(QualType ObjectTy,
+ llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
unsigned CVRQualifiers) {
@@ -1035,6 +1036,7 @@
CVRQualifiers, Index);
}
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);
@@ -1047,19 +1049,22 @@
llvm::Value *BaseValue = 0;
const Expr *BaseExpr = E->getBase();
unsigned CVRQualifiers = 0;
+ QualType ObjectTy;
if (E->isArrow()) {
BaseValue = EmitScalarExpr(BaseExpr);
const PointerType *PTy =
cast<PointerType>(getContext().getCanonicalType(BaseExpr->getType()));
- CVRQualifiers = PTy->getPointeeType().getCVRQualifiers();
+ ObjectTy = PTy->getPointeeType();
+ CVRQualifiers = ObjectTy.getCVRQualifiers();
} else {
LValue BaseLV = EmitLValue(BaseExpr);
// FIXME: this isn't right for bitfields.
BaseValue = BaseLV.getAddress();
- CVRQualifiers = BaseExpr->getType().getCVRQualifiers();
+ ObjectTy = BaseExpr->getType();
+ CVRQualifiers = ObjectTy.getCVRQualifiers();
}
- return EmitLValueForIvar(BaseValue, E->getDecl(),
+ return EmitLValueForIvar(ObjectTy, BaseValue, E->getDecl(),
getContext().getFieldDecl(E), CVRQualifiers);
}
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=63578&r1=63577&r2=63578&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Mon Feb 2 18:09:52 2009
@@ -194,7 +194,8 @@
} else {
FieldDecl *Field =
IMP->getClassInterface()->lookupFieldDeclForIvar(getContext(), Ivar);
- LValue LV = EmitLValueForIvar(LoadObjCSelf(), Ivar, Field, 0);
+ LValue LV = EmitLValueForIvar(TypeOfSelfObject(),
+ LoadObjCSelf(), Ivar, Field, 0);
if (hasAggregateLLVMType(Ivar->getType())) {
EmitAggregateCopy(ReturnValue, LV.getAddress(), Ivar->getType());
}
@@ -294,6 +295,14 @@
return Builder.CreateLoad(LocalDeclMap[OMD->getSelfDecl()], "self");
}
+QualType CodeGenFunction::TypeOfSelfObject() {
+ const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl);
+ ImplicitParamDecl *selfDecl = OMD->getSelfDecl();
+ const PointerType *PTy =
+ cast<PointerType>(getContext().getCanonicalType(selfDecl->getType()));
+ return PTy->getPointeeType();
+}
+
RValue CodeGenFunction::EmitObjCPropertyGet(const Expr *Exp) {
// FIXME: Split it into two separate routines.
if (const ObjCPropertyRefExpr *E = dyn_cast<ObjCPropertyRefExpr>(Exp)) {
Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=63578&r1=63577&r2=63578&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Mon Feb 2 18:09:52 2009
@@ -141,6 +141,7 @@
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,
@@ -1037,6 +1038,7 @@
}
llvm::Value *CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
+ QualType ObjectTy,
llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=63578&r1=63577&r2=63578&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon Feb 2 18:09:52 2009
@@ -551,6 +551,7 @@
llvm::Value *src, llvm::Value *dest);
virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
+ QualType ObjectTy,
llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
@@ -676,12 +677,11 @@
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)
- { return 0; }
-
+ unsigned CVRQualifiers);
};
} // end anonymous namespace
@@ -2114,6 +2114,7 @@
/// EmitObjCValueForIvar - Code Gen for ivar reference.
///
llvm::Value *CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
+ QualType ObjectTy,
llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
@@ -3755,15 +3756,16 @@
std::string ExternalName("\01_OBJC_IVAR_$_" + ID->getNameAsString() + '.'
+ Ivar->getNameAsString());
- llvm::Constant *Init = llvm::ConstantInt::get(ObjCTypes.IntTy, Offset);
+ llvm::Constant *Init = llvm::ConstantInt::get(ObjCTypes.LongTy, Offset);
llvm::GlobalVariable *IvarOffsetGV =
CGM.getModule().getGlobalVariable(ExternalName);
if (IvarOffsetGV) {
// ivar offset symbol already built due to user code referencing it.
IvarOffsetGV->setAlignment(
- CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.Int8PtrTy));
+ CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.LongTy));
IvarOffsetGV->setInitializer(Init);
+ IvarOffsetGV->setSection("__DATA, __objc_const");
UsedGlobals.push_back(IvarOffsetGV);
return IvarOffsetGV;
}
@@ -3776,7 +3778,7 @@
ExternalName,
&CGM.getModule());
IvarOffsetGV->setAlignment(
- CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.Int8PtrTy));
+ CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.LongTy));
// @private and @package have hidden visibility.
bool globalVisibility = (Ivar->getAccessControl() == ObjCIvarDecl::Public ||
Ivar->getAccessControl() == ObjCIvarDecl::Protected);
@@ -3789,10 +3791,7 @@
IvarOffsetGV->setSection("__DATA, __objc_const");
UsedGlobals.push_back(IvarOffsetGV);
-
- return llvm::ConstantExpr::getBitCast(
- IvarOffsetGV,
- llvm::PointerType::getUnqual(ObjCTypes.LongTy));
+ return IvarOffsetGV;
}
/// EmitIvarList - Emit the ivar list for the given
@@ -4094,6 +4093,52 @@
Desc[2] = llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy);
return llvm::ConstantStruct::get(ObjCTypes.MethodTy, Desc);
}
+
+/// EmitObjCValueForIvar - Code Gen for nonfragile ivar reference.
+/// This code gen. amounts to generating code for:
+/// @code
+/// (type *)((char *)base + _OBJC_IVAR_$_.ivar;
+/// @encode
+///
+llvm::Value *CGObjCNonFragileABIMac::EmitObjCValueForIvar(
+ CodeGen::CodeGenFunction &CGF,
+ QualType ObjectTy,
+ llvm::Value *BaseValue,
+ const ObjCIvarDecl *Ivar,
+ const FieldDecl *Field,
+ unsigned CVRQualifiers) {
+ assert(ObjectTy->isObjCInterfaceType() &&
+ "CGObjCNonFragileABIMac::EmitObjCValueForIvar");
+ NamedDecl *ID = ObjectTy->getAsObjCInterfaceType()->getDecl();
+ // NOTE. This name must match one in EmitIvarOffsetVar.
+ // FIXME. Consolidate into one naming routine.
+ std::string ExternalName("\01_OBJC_IVAR_$_" + ID->getNameAsString() + '.'
+ + Ivar->getNameAsString());
+
+ llvm::GlobalVariable *IvarOffsetGV =
+ CGM.getModule().getGlobalVariable(ExternalName);
+ if (!IvarOffsetGV)
+ IvarOffsetGV =
+ new llvm::GlobalVariable(ObjCTypes.LongTy,
+ false,
+ llvm::GlobalValue::ExternalLinkage,
+ 0,
+ ExternalName,
+ &CGM.getModule());
+ // (char *) BaseValue
+ llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue,
+ ObjCTypes.Int8PtrTy);
+ llvm::Value *Offset = CGF.Builder.CreateLoad(IvarOffsetGV);
+ // (char*)BaseValue + Offset_symbol
+ V = CGF.Builder.CreateGEP(V, Offset, "add.ptr");
+ // (type *)((char*)BaseValue + Offset_symbol)
+ const llvm::Type *IvarTy =
+ CGM.getTypes().ConvertType(Ivar->getType());
+ llvm::Type *ptrIvarTy = llvm::PointerType::getUnqual(IvarTy);
+ V = CGF.Builder.CreateBitCast(V, ptrIvarTy);
+ return V;
+}
+
/* *** */
CodeGen::CGObjCRuntime *
Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.h?rev=63578&r1=63577&r2=63578&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.h Mon Feb 2 18:09:52 2009
@@ -158,6 +158,7 @@
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,
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=63578&r1=63577&r2=63578&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Feb 2 18:09:52 2009
@@ -233,6 +233,10 @@
/// LoadObjCSelf - Load the value of self. This function is only
/// valid while generating code for an Objective-C method.
llvm::Value *LoadObjCSelf();
+
+ /// TypeOfSelfObject
+ /// Return type of object that this self represents.
+ QualType TypeOfSelfObject();
/// isObjCPointerType - Return true if the specificed AST type will map onto
/// some Objective-C pointer type.
@@ -521,7 +525,8 @@
const ObjCIvarDecl *Ivar);
LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
bool isUnion, unsigned CVRQualifiers);
- LValue EmitLValueForIvar(llvm::Value* Base, const ObjCIvarDecl *Ivar,
+ LValue EmitLValueForIvar(QualType ObjectTy,
+ llvm::Value* Base, const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
unsigned CVRQualifiers);
More information about the cfe-commits
mailing list