Refactored code gen for ivar access in preparation for

objc2 nonfragile ivar access code gen.

llvm-svn: 63541
This commit is contained in:
Fariborz Jahanian 2009-02-02 20:02:29 +00:00
parent dab7be8774
commit 9f84b78ac1
4 changed files with 51 additions and 1 deletions

View File

@ -1034,7 +1034,8 @@ LValue CodeGenFunction::EmitLValueForIvar(llvm::Value *BaseValue,
return EmitLValueForBitfield(BaseValue, const_cast<FieldDecl *>(Field),
CVRQualifiers, Index);
}
llvm::Value *V = Builder.CreateStructGEP(BaseValue, Index, "tmp");
llvm::Value *V = CGM.getObjCRuntime().EmitObjCValueForIvar(*this,
BaseValue, Ivar, Field, CVRQualifiers);
LValue LV = LValue::MakeAddr(V, Ivar->getType().getCVRQualifiers()|CVRQualifiers);
SetVarDeclObjCAttribute(getContext(), Ivar, Ivar->getType(), LV);
LValue::SetObjCIvar(LV, true);

View File

@ -140,6 +140,11 @@ 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,
llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
unsigned CVRQualifiers);
};
} // end anonymous namespace
@ -1028,6 +1033,17 @@ void CGObjCGNU::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
return;
}
llvm::Value *CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
unsigned 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;
}
CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){
return new CGObjCGNU(CGM);
}

View File

@ -549,6 +549,12 @@ private:
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,
llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
unsigned CVRQualifiers);
};
class CGObjCNonFragileABIMac : public CGObjCCommonMac {
@ -669,6 +675,13 @@ public:
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
llvm::Value *src, llvm::Value *dest)
{ return; }
virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
unsigned CVRQualifiers)
{ return 0; }
};
} // end anonymous namespace
@ -2097,6 +2110,19 @@ void CGObjCMac::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
return;
}
/// EmitObjCValueForIvar - Code Gen for ivar reference.
///
llvm::Value *CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
unsigned 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;
}
/* *** Private Interface *** */
/// EmitImageInfo - Emit the image info marker used to encode some module

View File

@ -47,6 +47,7 @@ namespace CodeGen {
class ObjCMethodDecl;
class ObjCProtocolDecl;
class Selector;
class ObjCIvarDecl;
namespace CodeGen {
class CodeGenModule;
@ -155,6 +156,12 @@ public:
llvm::Value *src, llvm::Value *dest) = 0;
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
llvm::Value *src, llvm::Value *dest) = 0;
virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
llvm::Value *BaseValue,
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
unsigned CVRQualifiers) = 0;
};
/// Creates an instance of an Objective-C runtime class.