Some refactoring of Ivar offset code gen.
in preparation for nonfragile ivar offset work.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64225 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index 8cee0f0..b41f76d 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -146,6 +146,9 @@
const ObjCIvarDecl *Ivar,
const FieldDecl *Field,
unsigned CVRQualifiers);
+ virtual llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
+ ObjCInterfaceDecl *Interface,
+ const ObjCIvarDecl *Ivar);
};
} // end anonymous namespace
@@ -1035,6 +1038,23 @@
return LV;
}
+llvm::Value *CGObjCGNU::EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
+ ObjCInterfaceDecl *Interface,
+ const ObjCIvarDecl *Ivar) {
+ const llvm::Type *InterfaceLTy =
+ CGM.getTypes().ConvertType(
+ CGM.getContext().getObjCInterfaceType(Interface));
+ const llvm::StructLayout *Layout =
+ CGM.getTargetData().getStructLayout(cast<llvm::StructType>(InterfaceLTy));
+ FieldDecl *Field = Interface->lookupFieldDeclForIvar(CGM.getContext(), Ivar);
+ uint64_t Offset =
+ Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
+
+ return llvm::ConstantInt::get(
+ CGM.getTypes().ConvertType(CGM.getContext().LongTy),
+ Offset);
+}
+
CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){
return new CGObjCGNU(CGM);
}