@@ -736,9 +736,9 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime {
736
736
// FIXME - accessibility
737
737
class GC_IVAR {
738
738
public:
739
- unsigned ivar_bytepos;
739
+ CharUnits ivar_bytepos;
740
740
unsigned ivar_size;
741
- GC_IVAR (unsigned bytepos = 0 , unsigned size = 0 )
741
+ GC_IVAR (CharUnits bytepos = CharUnits::Zero() , unsigned size = 0 )
742
742
: ivar_bytepos(bytepos), ivar_size(size) {}
743
743
744
744
// Allow sorting based on byte pos.
@@ -933,13 +933,13 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime {
933
933
llvm::Constant *BuildIvarLayoutBitmap (std::string &BitMap);
934
934
935
935
void BuildAggrIvarRecordLayout (const RecordType *RT,
936
- unsigned int BytePos, bool ForStrongLayout,
936
+ CharUnits BytePos, bool ForStrongLayout,
937
937
bool &HasUnion);
938
938
void BuildAggrIvarLayout (const ObjCImplementationDecl *OI,
939
939
const llvm::StructLayout *Layout,
940
940
const RecordDecl *RD,
941
941
ArrayRef<const FieldDecl*> RecFields,
942
- unsigned int BytePos, bool ForStrongLayout,
942
+ CharUnits BytePos, bool ForStrongLayout,
943
943
bool &HasUnion);
944
944
945
945
Qualifiers::ObjCLifetime getBlockCaptureLifetime (QualType QT);
@@ -1324,7 +1324,7 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
1324
1324
1325
1325
llvm::Constant *EmitIvarOffsetVar (const ObjCInterfaceDecl *ID,
1326
1326
const ObjCIvarDecl *Ivar,
1327
- unsigned long int offset);
1327
+ CharUnits offset);
1328
1328
1329
1329
// / GetOrEmitProtocol - Get the protocol object for the given
1330
1330
// / declaration, emitting it if necessary. The return value has type
@@ -1893,7 +1893,7 @@ llvm::Constant *CGObjCCommonMac::BuildGCBlockLayout(CodeGenModule &CGM,
1893
1893
1894
1894
// __isa is the first field in block descriptor and must assume by runtime's
1895
1895
// convention that it is GC'able.
1896
- IvarsInfo.push_back (GC_IVAR (0 , 1 ));
1896
+ IvarsInfo.push_back (GC_IVAR (CharUnits::Zero () , 1 ));
1897
1897
1898
1898
const BlockDecl *blockDecl = blockInfo.getBlockDecl ();
1899
1899
@@ -1915,7 +1915,8 @@ llvm::Constant *CGObjCCommonMac::BuildGCBlockLayout(CodeGenModule &CGM,
1915
1915
// Ignore constant captures.
1916
1916
if (capture.isConstant ()) continue ;
1917
1917
1918
- uint64_t fieldOffset = layout->getElementOffset (capture.getIndex ());
1918
+ CharUnits fieldOffset =
1919
+ CharUnits::fromQuantity (layout->getElementOffset (capture.getIndex ()));
1919
1920
1920
1921
// __block variables are passed by their descriptor address.
1921
1922
if (ci->isByRef ()) {
@@ -3226,7 +3227,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID,
3226
3227
GetMethodVarName (IVD->getIdentifier ()),
3227
3228
GetMethodVarType (IVD),
3228
3229
llvm::ConstantInt::get (ObjCTypes.IntTy ,
3229
- ComputeIvarBaseOffset (CGM, OID, IVD))
3230
+ ComputeIvarBaseOffset (CGM, OID, IVD). getQuantity () )
3230
3231
};
3231
3232
Ivars.push_back (llvm::ConstantStruct::get (ObjCTypes.IvarTy , Ivar));
3232
3233
}
@@ -4172,10 +4173,8 @@ LValue CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
4172
4173
llvm::Value *CGObjCMac::EmitIvarOffset (CodeGen::CodeGenFunction &CGF,
4173
4174
const ObjCInterfaceDecl *Interface,
4174
4175
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 ());
4179
4178
}
4180
4179
4181
4180
/* *** Private Interface *** */
@@ -4397,7 +4396,7 @@ llvm::Constant *CGObjCCommonMac::GetIvarLayoutName(IdentifierInfo *Ident,
4397
4396
}
4398
4397
4399
4398
void CGObjCCommonMac::BuildAggrIvarRecordLayout (const RecordType *RT,
4400
- unsigned int BytePos,
4399
+ CharUnits BytePos,
4401
4400
bool ForStrongLayout,
4402
4401
bool &HasUnion) {
4403
4402
const RecordDecl *RD = RT->getDecl ();
@@ -4418,37 +4417,37 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI,
4418
4417
const llvm::StructLayout *Layout,
4419
4418
const RecordDecl *RD,
4420
4419
ArrayRef<const FieldDecl*> RecFields,
4421
- unsigned int BytePos, bool ForStrongLayout,
4420
+ CharUnits BytePos, bool ForStrongLayout,
4422
4421
bool &HasUnion) {
4423
4422
bool IsUnion = (RD && RD->isUnion ());
4424
4423
uint64_t MaxUnionIvarSize = 0 ;
4425
4424
uint64_t MaxSkippedUnionIvarSize = 0 ;
4426
4425
const FieldDecl *MaxField = 0 ;
4427
4426
const FieldDecl *MaxSkippedField = 0 ;
4428
4427
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 () ;
4433
4432
4434
4433
if (RecFields.empty ())
4435
4434
return ;
4436
4435
unsigned WordSizeInBits = CGM.getContext ().getTargetInfo ().getPointerWidth (0 );
4437
4436
unsigned ByteSizeInBits = CGM.getContext ().getTargetInfo ().getCharWidth ();
4438
4437
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);
4442
4440
}
4443
4441
4444
4442
for (unsigned i = 0 , e = RecFields.size (); i != e; ++i) {
4445
4443
const FieldDecl *Field = RecFields[i];
4446
- uint64_t FieldOffset;
4444
+ CharUnits FieldOffset;
4447
4445
if (RD) {
4448
4446
// Note that 'i' here is actually the field index inside RD of Field,
4449
4447
// although this dependency is hidden.
4450
4448
const ASTRecordLayout &RL = CGM.getContext ().getASTRecordLayout (RD);
4451
- FieldOffset = (RL.getFieldOffset (i) / ByteSizeInBits) - FirstFieldDelta;
4449
+ FieldOffset = CGM.getContext ().toCharUnitsFromBits (RL.getFieldOffset (i)) -
4450
+ FirstFieldDelta;
4452
4451
} else
4453
4452
FieldOffset =
4454
4453
ComputeIvarBaseOffset (CGM, OI, cast<ObjCIvarDecl>(Field)) - FirstFieldDelta;
@@ -4500,7 +4499,7 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI,
4500
4499
uint64_t ElIx = 1 ;
4501
4500
for (int FirstIndex = IvarsInfo.size () - 1 ,
4502
4501
FirstSkIndex = SkipIvars.size () - 1 ;ElIx < ElCount; ElIx++) {
4503
- uint64_t Size = CGM.getContext ().getTypeSize (RT)/ByteSizeInBits ;
4502
+ CharUnits Size = CGM.getContext ().getTypeSizeInChars (RT);
4504
4503
for (int i = OldIndex+1 ; i <= FirstIndex; ++i)
4505
4504
IvarsInfo.push_back (GC_IVAR (IvarsInfo[i].ivar_bytepos + Size *ElIx,
4506
4505
IvarsInfo[i].ivar_size ));
@@ -4583,23 +4582,18 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI,
4583
4582
// / two containers, IvarsInfo and SkipIvars which are assumed to be
4584
4583
// / filled already by the caller.
4585
4584
llvm::Constant *CGObjCCommonMac::BuildIvarLayoutBitmap (std::string &BitMap) {
4586
- unsigned int WordsToScan, WordsToSkip;
4587
4585
llvm::Type *PtrTy = CGM.Int8PtrTy ;
4588
4586
4589
4587
// Build the string of skip/scan nibbles
4590
4588
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
+
4600
4594
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;
4603
4597
if (IvarsInfo[i].ivar_bytepos == TailPrevGCObjC) {
4604
4598
// consecutive 'scanned' object pointers.
4605
4599
WordsToScan += IvarsInfo[i].ivar_size ;
@@ -4631,17 +4625,21 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayoutBitmap(std::string &BitMap) {
4631
4625
4632
4626
if (!SkipIvars.empty ()) {
4633
4627
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 ();
4636
4633
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;
4640
4637
// Compute number of bytes to skip at the tail end of the last ivar scanned.
4641
4638
if (LastByteSkipped > LastByteScanned) {
4642
- unsigned int TotalWords = (LastByteSkipped + (WordSize -1 )) / WordSize;
4639
+ unsigned int TotalWords =
4640
+ (LastByteSkipped + (WordSize - CharUnits::One ())) / WordSize;
4643
4641
SKIP_SCAN SkScan;
4644
- SkScan.skip = TotalWords - ( LastByteScanned/ WordSize) ;
4642
+ SkScan.skip = TotalWords - LastByteScanned / WordSize;
4645
4643
SkScan.scan = 0 ;
4646
4644
SkipScanIvars.push_back (SkScan);
4647
4645
}
@@ -4754,7 +4752,8 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout(
4754
4752
SkipIvars.clear ();
4755
4753
IvarsInfo.clear ();
4756
4754
4757
- BuildAggrIvarLayout (OMD, 0 , 0 , RecFields, 0 , ForStrongLayout, hasUnion);
4755
+ BuildAggrIvarLayout (OMD, 0 , 0 , RecFields, CharUnits::Zero (),
4756
+ ForStrongLayout, hasUnion);
4758
4757
if (IvarsInfo.empty ())
4759
4758
return llvm::Constant::getNullValue (PtrTy);
4760
4759
// Sort on byte position in case we encounterred a union nested in
@@ -6022,10 +6021,10 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const ObjCInterfaceDecl *ID,
6022
6021
llvm::Constant *
6023
6022
CGObjCNonFragileABIMac::EmitIvarOffsetVar (const ObjCInterfaceDecl *ID,
6024
6023
const ObjCIvarDecl *Ivar,
6025
- unsigned long int Offset) {
6024
+ CharUnits Offset) {
6026
6025
llvm::GlobalVariable *IvarOffsetGV = ObjCIvarOffsetVariable (ID, Ivar);
6027
6026
IvarOffsetGV->setInitializer (llvm::ConstantInt::get (ObjCTypes.LongTy ,
6028
- Offset));
6027
+ Offset. getQuantity () ));
6029
6028
IvarOffsetGV->setAlignment (
6030
6029
CGM.getDataLayout ().getABITypeAlignment (ObjCTypes.LongTy ));
6031
6030
0 commit comments