@@ -326,13 +326,62 @@ mlir::Value CIRGenFunction::emitStoreThroughBitfieldLValue(RValue src,
326326 return {};
327327}
328328
329+ RValue CIRGenFunction::emitLoadOfBitfieldLValue (LValue lv, SourceLocation loc) {
330+ const CIRGenBitFieldInfo &info = lv.getBitFieldInfo ();
331+
332+ // Get the output type.
333+ mlir::Type resLTy = convertType (lv.getType ());
334+ Address ptr = lv.getBitFieldAddress ();
335+
336+ assert (!cir::MissingFeatures::armComputeVolatileBitfields ());
337+
338+ mlir::Value field = builder.createGetBitfield (
339+ getLoc (loc), resLTy, ptr.getPointer (), ptr.getElementType (), info,
340+ lv.isVolatile (), false );
341+ assert (!cir::MissingFeatures::opLoadEmitScalarRangeCheck () && " NYI" );
342+ return RValue::get (field);
343+ }
344+
345+ Address CIRGenFunction::getAddrOfBitFieldStorage (LValue base,
346+ const FieldDecl *field,
347+ mlir::Type fieldType,
348+ unsigned index) {
349+ mlir::Location loc = getLoc (field->getLocation ());
350+ cir::PointerType fieldPtr = cir::PointerType::get (fieldType);
351+ cir::GetMemberOp sea = getBuilder ().createGetMember (
352+ loc, fieldPtr, base.getPointer (), field->getName (), index);
353+ return Address (sea, CharUnits::One ());
354+ }
355+
356+ LValue CIRGenFunction::emitLValueForBitField (LValue base,
357+ const FieldDecl *field) {
358+ LValueBaseInfo baseInfo = base.getBaseInfo ();
359+ const CIRGenRecordLayout &layout =
360+ cgm.getTypes ().getCIRGenRecordLayout (field->getParent ());
361+ const CIRGenBitFieldInfo &info = layout.getBitFieldInfo (field);
362+ assert (!cir::MissingFeatures::armComputeVolatileBitfields ());
363+ assert (!cir::MissingFeatures::preservedAccessIndexRegion ());
364+ unsigned idx = layout.getCIRFieldNo (field);
365+
366+ Address addr = getAddrOfBitFieldStorage (base, field, info.storageType , idx);
367+
368+ mlir::Location loc = getLoc (field->getLocation ());
369+ if (addr.getElementType () != info.storageType )
370+ addr = builder.createElementBitCast (loc, addr, info.storageType );
371+
372+ QualType fieldType =
373+ field->getType ().withCVRQualifiers (base.getVRQualifiers ());
374+ // TODO(cir): Support TBAA for bit fields.
375+ assert (!cir::MissingFeatures::opTBAA ());
376+ LValueBaseInfo fieldBaseInfo (baseInfo.getAlignmentSource ());
377+ return LValue::makeBitfield (addr, info, fieldType, fieldBaseInfo);
378+ }
379+
329380LValue CIRGenFunction::emitLValueForField (LValue base, const FieldDecl *field) {
330381 LValueBaseInfo baseInfo = base.getBaseInfo ();
331382
332- if (field->isBitField ()) {
333- cgm.errorNYI (field->getSourceRange (), " emitLValueForField: bitfield" );
334- return LValue ();
335- }
383+ if (field->isBitField ())
384+ return emitLValueForBitField (base, field);
336385
337386 QualType fieldType = field->getType ();
338387 const RecordDecl *rec = field->getParent ();
@@ -460,6 +509,9 @@ RValue CIRGenFunction::emitLoadOfLValue(LValue lv, SourceLocation loc) {
460509 assert (!lv.getType ()->isFunctionType ());
461510 assert (!(lv.getType ()->isConstantMatrixType ()) && " not implemented" );
462511
512+ if (lv.isBitField ())
513+ return emitLoadOfBitfieldLValue (lv, loc);
514+
463515 if (lv.isSimple ())
464516 return RValue::get (emitLoadOfScalar (lv, loc));
465517
0 commit comments