[cfe-commits] r66391 - /cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Fariborz Jahanian
fjahanian at apple.com
Sun Mar 8 13:18:37 PDT 2009
Author: fjahanian
Date: Sun Mar 8 15:18:37 2009
New Revision: 66391
URL: http://llvm.org/viewvc/llvm-project?rev=66391&view=rev
Log:
Code refactoring. No functional change.
Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=66391&r1=66390&r2=66391&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sun Mar 8 15:18:37 2009
@@ -425,6 +425,10 @@
/// description, creating an empty one if it has not been
/// defined. The return value has type ProtocolPtrTy.
llvm::Constant *GetProtocolRef(const ObjCProtocolDecl *PD);
+
+ /// GetIvarBaseOffset - returns ivars byte offset.
+ uint64_t GetIvarBaseOffset(const llvm::StructLayout *Layout,
+ FieldDecl *Field);
public:
CGObjCCommonMac(CodeGen::CodeGenModule &cgm) : CGM(cgm)
@@ -1706,13 +1710,7 @@
const RecordDecl *RD = GetFirstIvarInRecord(OID, ifield, pfield);
for (RecordDecl::field_iterator e = RD->field_end(); ifield != e; ++ifield) {
FieldDecl *Field = *ifield;
- unsigned Offset;
- if (Field->isBitField())
- // Bit field staring offset is cached in FieldInfo[Field].
- Offset = CGM.getTypes().getLLVMFieldNo(Field);
- else
- Offset = Layout->getElementOffset(CGM.getTypes().
- getLLVMFieldNo(Field));
+ uint64_t Offset = GetIvarBaseOffset(Layout, Field);
if (Field->getIdentifier())
Ivar[0] = GetMethodVarName(Field->getIdentifier());
else
@@ -1830,6 +1828,14 @@
return Method;
}
+uint64_t CGObjCCommonMac::GetIvarBaseOffset(const llvm::StructLayout *Layout,
+ FieldDecl *Field) {
+ return Field->isBitField()
+ ? CGM.getTypes().getLLVMFieldNo(Field)
+ : Layout->getElementOffset(
+ CGM.getTypes().getLLVMFieldNo(Field));
+}
+
llvm::Function *CGObjCMac::ModuleInitFunction() {
// Abuse this interface function as a place to finalize.
FinishModule();
@@ -2272,10 +2278,7 @@
const llvm::StructLayout *Layout =
CGM.getTargetData().getStructLayout(cast<llvm::StructType>(InterfaceLTy));
FieldDecl *Field = Interface->lookupFieldDeclForIvar(CGM.getContext(), Ivar);
- uint64_t Offset =
- Field->isBitField() ? CGM.getTypes().getLLVMFieldNo(Field) :
- Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
-
+ uint64_t Offset = GetIvarBaseOffset(Layout, Field);
return llvm::ConstantInt::get(
CGM.getTypes().ConvertType(CGM.getContext().LongTy),
Offset);
@@ -3847,17 +3850,12 @@
const llvm::Type *FieldTy =
CGM.getTypes().ConvertTypeForMem(Field->getType());
unsigned Size = CGM.getTargetData().getTypePaddedSize(FieldTy);
- uint64_t Offset =
- Field->isBitField() ? CGM.getTypes().getLLVMFieldNo(Field) :
- Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
- InstanceSize = Offset + Size;
+ InstanceSize = GetIvarBaseOffset(Layout, Field) + Size;
if (firstField == RD->field_end())
InstanceStart = InstanceSize;
else {
Field = *firstField;
- InstanceStart =
- Field->isBitField() ? CGM.getTypes().getLLVMFieldNo(Field) :
- Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
+ InstanceStart = GetIvarBaseOffset(Layout, Field);
}
}
}
@@ -4160,13 +4158,7 @@
for (RecordDecl::field_iterator e = RD->field_end(); i != e; ++i) {
FieldDecl *Field = *i;
- unsigned long offset;
- if (Field->isBitField())
- // Bit field starting offset is cached in FieldInfo[Field].
- offset = CGM.getTypes().getLLVMFieldNo(Field);
- else
- offset = Layout->getElementOffset(CGM.getTypes().
- getLLVMFieldNo(Field));
+ uint64_t offset = GetIvarBaseOffset(Layout, Field);
const ObjCIvarDecl *ivarDecl = *I++;
Ivar[0] = EmitIvarOffsetVar(ID->getClassInterface(), ivarDecl, offset);
if (Field->getIdentifier())
More information about the cfe-commits
mailing list