Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 38ad4f4

Browse files
committed
Propagate CharUnits into ObjC CodeGen. No intended functional change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167431 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 04fd382 commit 38ad4f4

File tree

4 files changed

+66
-66
lines changed

4 files changed

+66
-66
lines changed

lib/CodeGen/CGObjCGNU.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -2083,7 +2083,7 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
20832083
Context.getObjCEncodingForType(IVD->getType(), TypeStr);
20842084
IvarTypes.push_back(MakeConstantString(TypeStr));
20852085
// Get the offset
2086-
uint64_t BaseOffset = ComputeIvarBaseOffset(CGM, OID, IVD);
2086+
uint64_t BaseOffset = ComputeIvarBaseOffset(CGM, OID, IVD).getQuantity();
20872087
uint64_t Offset = BaseOffset;
20882088
if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
20892089
Offset = BaseOffset - superInstanceSize;
@@ -2655,7 +2655,7 @@ llvm::GlobalVariable *CGObjCGNU::ObjCIvarOffsetVariable(
26552655
// description.
26562656
if (!CGM.getContext().getObjCImplementation(
26572657
const_cast<ObjCInterfaceDecl *>(ID)))
2658-
Offset = ComputeIvarBaseOffset(CGM, ID, Ivar);
2658+
Offset = ComputeIvarBaseOffset(CGM, ID, Ivar).getQuantity();
26592659

26602660
llvm::ConstantInt *OffsetGuess = llvm::ConstantInt::get(Int32Ty, Offset,
26612661
/*isSigned*/true);
@@ -2728,8 +2728,9 @@ llvm::Value *CGObjCGNU::EmitIvarOffset(CodeGenFunction &CGF,
27282728
Offset = CGF.Builder.CreateZExtOrBitCast(Offset, PtrDiffTy);
27292729
return Offset;
27302730
}
2731-
uint64_t Offset = ComputeIvarBaseOffset(CGF.CGM, Interface, Ivar);
2732-
return llvm::ConstantInt::get(PtrDiffTy, Offset, /*isSigned*/true);
2731+
CharUnits Offset = ComputeIvarBaseOffset(CGF.CGM, Interface, Ivar);
2732+
return llvm::ConstantInt::get(PtrDiffTy, Offset.getQuantity(),
2733+
/*isSigned*/true);
27332734
}
27342735

27352736
CGObjCRuntime *

lib/CodeGen/CGObjCMac.cpp

+45-46
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,9 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime {
736736
// FIXME - accessibility
737737
class GC_IVAR {
738738
public:
739-
unsigned ivar_bytepos;
739+
CharUnits ivar_bytepos;
740740
unsigned ivar_size;
741-
GC_IVAR(unsigned bytepos = 0, unsigned size = 0)
741+
GC_IVAR(CharUnits bytepos = CharUnits::Zero(), unsigned size = 0)
742742
: ivar_bytepos(bytepos), ivar_size(size) {}
743743

744744
// Allow sorting based on byte pos.
@@ -933,13 +933,13 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime {
933933
llvm::Constant *BuildIvarLayoutBitmap(std::string &BitMap);
934934

935935
void BuildAggrIvarRecordLayout(const RecordType *RT,
936-
unsigned int BytePos, bool ForStrongLayout,
936+
CharUnits BytePos, bool ForStrongLayout,
937937
bool &HasUnion);
938938
void BuildAggrIvarLayout(const ObjCImplementationDecl *OI,
939939
const llvm::StructLayout *Layout,
940940
const RecordDecl *RD,
941941
ArrayRef<const FieldDecl*> RecFields,
942-
unsigned int BytePos, bool ForStrongLayout,
942+
CharUnits BytePos, bool ForStrongLayout,
943943
bool &HasUnion);
944944

945945
Qualifiers::ObjCLifetime getBlockCaptureLifetime(QualType QT);
@@ -1324,7 +1324,7 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
13241324

13251325
llvm::Constant *EmitIvarOffsetVar(const ObjCInterfaceDecl *ID,
13261326
const ObjCIvarDecl *Ivar,
1327-
unsigned long int offset);
1327+
CharUnits offset);
13281328

13291329
/// GetOrEmitProtocol - Get the protocol object for the given
13301330
/// declaration, emitting it if necessary. The return value has type
@@ -1893,7 +1893,7 @@ llvm::Constant *CGObjCCommonMac::BuildGCBlockLayout(CodeGenModule &CGM,
18931893

18941894
// __isa is the first field in block descriptor and must assume by runtime's
18951895
// convention that it is GC'able.
1896-
IvarsInfo.push_back(GC_IVAR(0, 1));
1896+
IvarsInfo.push_back(GC_IVAR(CharUnits::Zero(), 1));
18971897

18981898
const BlockDecl *blockDecl = blockInfo.getBlockDecl();
18991899

@@ -1915,7 +1915,8 @@ llvm::Constant *CGObjCCommonMac::BuildGCBlockLayout(CodeGenModule &CGM,
19151915
// Ignore constant captures.
19161916
if (capture.isConstant()) continue;
19171917

1918-
uint64_t fieldOffset = layout->getElementOffset(capture.getIndex());
1918+
CharUnits fieldOffset =
1919+
CharUnits::fromQuantity(layout->getElementOffset(capture.getIndex()));
19191920

19201921
// __block variables are passed by their descriptor address.
19211922
if (ci->isByRef()) {
@@ -3226,7 +3227,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID,
32263227
GetMethodVarName(IVD->getIdentifier()),
32273228
GetMethodVarType(IVD),
32283229
llvm::ConstantInt::get(ObjCTypes.IntTy,
3229-
ComputeIvarBaseOffset(CGM, OID, IVD))
3230+
ComputeIvarBaseOffset(CGM, OID, IVD).getQuantity())
32303231
};
32313232
Ivars.push_back(llvm::ConstantStruct::get(ObjCTypes.IvarTy, Ivar));
32323233
}
@@ -4172,10 +4173,8 @@ LValue CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
41724173
llvm::Value *CGObjCMac::EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
41734174
const ObjCInterfaceDecl *Interface,
41744175
const ObjCIvarDecl *Ivar) {
4175-
uint64_t Offset = ComputeIvarBaseOffset(CGM, Interface, Ivar);
4176-
return llvm::ConstantInt::get(
4177-
CGM.getTypes().ConvertType(CGM.getContext().LongTy),
4178-
Offset);
4176+
CharUnits Offset = ComputeIvarBaseOffset(CGM, Interface, Ivar);
4177+
return llvm::ConstantInt::get(ObjCTypes.LongTy, Offset.getQuantity());
41794178
}
41804179

41814180
/* *** Private Interface *** */
@@ -4397,7 +4396,7 @@ llvm::Constant *CGObjCCommonMac::GetIvarLayoutName(IdentifierInfo *Ident,
43974396
}
43984397

43994398
void CGObjCCommonMac::BuildAggrIvarRecordLayout(const RecordType *RT,
4400-
unsigned int BytePos,
4399+
CharUnits BytePos,
44014400
bool ForStrongLayout,
44024401
bool &HasUnion) {
44034402
const RecordDecl *RD = RT->getDecl();
@@ -4418,37 +4417,37 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI,
44184417
const llvm::StructLayout *Layout,
44194418
const RecordDecl *RD,
44204419
ArrayRef<const FieldDecl*> RecFields,
4421-
unsigned int BytePos, bool ForStrongLayout,
4420+
CharUnits BytePos, bool ForStrongLayout,
44224421
bool &HasUnion) {
44234422
bool IsUnion = (RD && RD->isUnion());
44244423
uint64_t MaxUnionIvarSize = 0;
44254424
uint64_t MaxSkippedUnionIvarSize = 0;
44264425
const FieldDecl *MaxField = 0;
44274426
const FieldDecl *MaxSkippedField = 0;
44284427
const FieldDecl *LastFieldBitfieldOrUnnamed = 0;
4429-
uint64_t MaxFieldOffset = 0;
4430-
uint64_t MaxSkippedFieldOffset = 0;
4431-
uint64_t LastBitfieldOrUnnamedOffset = 0;
4432-
uint64_t FirstFieldDelta = 0;
4428+
CharUnits MaxFieldOffset = CharUnits::Zero();
4429+
CharUnits MaxSkippedFieldOffset = CharUnits::Zero();
4430+
CharUnits LastBitfieldOrUnnamedOffset = CharUnits::Zero();
4431+
CharUnits FirstFieldDelta = CharUnits::Zero();
44334432

44344433
if (RecFields.empty())
44354434
return;
44364435
unsigned WordSizeInBits = CGM.getContext().getTargetInfo().getPointerWidth(0);
44374436
unsigned ByteSizeInBits = CGM.getContext().getTargetInfo().getCharWidth();
44384437
if (!RD && CGM.getLangOpts().ObjCAutoRefCount) {
4439-
const FieldDecl *FirstField = RecFields[0];
4440-
FirstFieldDelta =
4441-
ComputeIvarBaseOffset(CGM, OI, cast<ObjCIvarDecl>(FirstField));
4438+
const ObjCIvarDecl *FirstField = cast<ObjCIvarDecl>(RecFields[0]);
4439+
FirstFieldDelta = ComputeIvarBaseOffset(CGM, OI, FirstField);
44424440
}
44434441

44444442
for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
44454443
const FieldDecl *Field = RecFields[i];
4446-
uint64_t FieldOffset;
4444+
CharUnits FieldOffset;
44474445
if (RD) {
44484446
// Note that 'i' here is actually the field index inside RD of Field,
44494447
// although this dependency is hidden.
44504448
const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
4451-
FieldOffset = (RL.getFieldOffset(i) / ByteSizeInBits) - FirstFieldDelta;
4449+
FieldOffset = CGM.getContext().toCharUnitsFromBits(RL.getFieldOffset(i)) -
4450+
FirstFieldDelta;
44524451
} else
44534452
FieldOffset =
44544453
ComputeIvarBaseOffset(CGM, OI, cast<ObjCIvarDecl>(Field)) - FirstFieldDelta;
@@ -4500,7 +4499,7 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI,
45004499
uint64_t ElIx = 1;
45014500
for (int FirstIndex = IvarsInfo.size() - 1,
45024501
FirstSkIndex = SkipIvars.size() - 1 ;ElIx < ElCount; ElIx++) {
4503-
uint64_t Size = CGM.getContext().getTypeSize(RT)/ByteSizeInBits;
4502+
CharUnits Size = CGM.getContext().getTypeSizeInChars(RT);
45044503
for (int i = OldIndex+1; i <= FirstIndex; ++i)
45054504
IvarsInfo.push_back(GC_IVAR(IvarsInfo[i].ivar_bytepos + Size*ElIx,
45064505
IvarsInfo[i].ivar_size));
@@ -4583,23 +4582,18 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI,
45834582
/// two containers, IvarsInfo and SkipIvars which are assumed to be
45844583
/// filled already by the caller.
45854584
llvm::Constant *CGObjCCommonMac::BuildIvarLayoutBitmap(std::string &BitMap) {
4586-
unsigned int WordsToScan, WordsToSkip;
45874585
llvm::Type *PtrTy = CGM.Int8PtrTy;
45884586

45894587
// Build the string of skip/scan nibbles
45904588
SmallVector<SKIP_SCAN, 32> SkipScanIvars;
4591-
unsigned int WordSize =
4592-
CGM.getTypes().getDataLayout().getTypeAllocSize(PtrTy);
4593-
if (IvarsInfo[0].ivar_bytepos == 0) {
4594-
WordsToSkip = 0;
4595-
WordsToScan = IvarsInfo[0].ivar_size;
4596-
} else {
4597-
WordsToSkip = IvarsInfo[0].ivar_bytepos/WordSize;
4598-
WordsToScan = IvarsInfo[0].ivar_size;
4599-
}
4589+
CharUnits WordSize = CharUnits::fromQuantity(
4590+
CGM.getTypes().getDataLayout().getTypeAllocSize(PtrTy));
4591+
unsigned WordsToSkip = IvarsInfo[0].ivar_bytepos/WordSize;
4592+
unsigned WordsToScan = IvarsInfo[0].ivar_size;
4593+
46004594
for (unsigned int i=1, Last=IvarsInfo.size(); i != Last; i++) {
4601-
unsigned int TailPrevGCObjC =
4602-
IvarsInfo[i-1].ivar_bytepos + IvarsInfo[i-1].ivar_size * WordSize;
4595+
CharUnits TailPrevGCObjC =
4596+
IvarsInfo[i-1].ivar_bytepos + IvarsInfo[i-1].ivar_size * WordSize;
46034597
if (IvarsInfo[i].ivar_bytepos == TailPrevGCObjC) {
46044598
// consecutive 'scanned' object pointers.
46054599
WordsToScan += IvarsInfo[i].ivar_size;
@@ -4631,17 +4625,21 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayoutBitmap(std::string &BitMap) {
46314625

46324626
if (!SkipIvars.empty()) {
46334627
unsigned int LastIndex = SkipIvars.size()-1;
4634-
int LastByteSkipped =
4635-
SkipIvars[LastIndex].ivar_bytepos + SkipIvars[LastIndex].ivar_size;
4628+
// FIXME: Shouldn't be using CharUnits::One here; what are the units of
4629+
// ivar_size?
4630+
CharUnits LastByteSkipped =
4631+
SkipIvars[LastIndex].ivar_bytepos +
4632+
SkipIvars[LastIndex].ivar_size * CharUnits::One();
46364633
LastIndex = IvarsInfo.size()-1;
4637-
int LastByteScanned =
4638-
IvarsInfo[LastIndex].ivar_bytepos +
4639-
IvarsInfo[LastIndex].ivar_size * WordSize;
4634+
CharUnits LastByteScanned =
4635+
IvarsInfo[LastIndex].ivar_bytepos +
4636+
IvarsInfo[LastIndex].ivar_size * WordSize;
46404637
// Compute number of bytes to skip at the tail end of the last ivar scanned.
46414638
if (LastByteSkipped > LastByteScanned) {
4642-
unsigned int TotalWords = (LastByteSkipped + (WordSize -1)) / WordSize;
4639+
unsigned int TotalWords =
4640+
(LastByteSkipped + (WordSize - CharUnits::One())) / WordSize;
46434641
SKIP_SCAN SkScan;
4644-
SkScan.skip = TotalWords - (LastByteScanned/WordSize);
4642+
SkScan.skip = TotalWords - LastByteScanned / WordSize;
46454643
SkScan.scan = 0;
46464644
SkipScanIvars.push_back(SkScan);
46474645
}
@@ -4754,7 +4752,8 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout(
47544752
SkipIvars.clear();
47554753
IvarsInfo.clear();
47564754

4757-
BuildAggrIvarLayout(OMD, 0, 0, RecFields, 0, ForStrongLayout, hasUnion);
4755+
BuildAggrIvarLayout(OMD, 0, 0, RecFields, CharUnits::Zero(),
4756+
ForStrongLayout, hasUnion);
47584757
if (IvarsInfo.empty())
47594758
return llvm::Constant::getNullValue(PtrTy);
47604759
// Sort on byte position in case we encounterred a union nested in
@@ -6022,10 +6021,10 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const ObjCInterfaceDecl *ID,
60226021
llvm::Constant *
60236022
CGObjCNonFragileABIMac::EmitIvarOffsetVar(const ObjCInterfaceDecl *ID,
60246023
const ObjCIvarDecl *Ivar,
6025-
unsigned long int Offset) {
6024+
CharUnits Offset) {
60266025
llvm::GlobalVariable *IvarOffsetGV = ObjCIvarOffsetVariable(ID, Ivar);
60276026
IvarOffsetGV->setInitializer(llvm::ConstantInt::get(ObjCTypes.LongTy,
6028-
Offset));
6027+
Offset.getQuantity()));
60296028
IvarOffsetGV->setAlignment(
60306029
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.LongTy));
60316030

lib/CodeGen/CGObjCRuntime.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ static uint64_t LookupFieldBitOffset(CodeGen::CodeGenModule &CGM,
6464
return RL->getFieldOffset(Index);
6565
}
6666

67-
uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
68-
const ObjCInterfaceDecl *OID,
69-
const ObjCIvarDecl *Ivar) {
70-
return LookupFieldBitOffset(CGM, OID, 0, Ivar) /
71-
CGM.getContext().getCharWidth();
67+
CharUnits CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
68+
const ObjCInterfaceDecl *OID,
69+
const ObjCIvarDecl *Ivar) {
70+
return CGM.getContext().toCharUnitsFromBits(
71+
LookupFieldBitOffset(CGM, OID, 0, Ivar));
7272
}
7373

74-
uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
75-
const ObjCImplementationDecl *OID,
76-
const ObjCIvarDecl *Ivar) {
77-
return LookupFieldBitOffset(CGM, OID->getClassInterface(), OID, Ivar) /
78-
CGM.getContext().getCharWidth();
74+
CharUnits CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
75+
const ObjCImplementationDecl *OID,
76+
const ObjCIvarDecl *Ivar) {
77+
return CGM.getContext().toCharUnitsFromBits(
78+
LookupFieldBitOffset(CGM, OID->getClassInterface(), OID, Ivar));
7979
}
8080

8181
LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,

lib/CodeGen/CGObjCRuntime.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ class CGObjCRuntime {
7676
///
7777
/// The latter overload is suitable for computing the offset of a
7878
/// sythesized ivar.
79-
uint64_t ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
80-
const ObjCInterfaceDecl *OID,
81-
const ObjCIvarDecl *Ivar);
82-
uint64_t ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
83-
const ObjCImplementationDecl *OID,
84-
const ObjCIvarDecl *Ivar);
79+
CharUnits ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
80+
const ObjCInterfaceDecl *OID,
81+
const ObjCIvarDecl *Ivar);
82+
CharUnits ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
83+
const ObjCImplementationDecl *OID,
84+
const ObjCIvarDecl *Ivar);
8585

8686
LValue EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
8787
const ObjCInterfaceDecl *OID,

0 commit comments

Comments
 (0)