21
21
#include " clang/AST/GlobalDecl.h"
22
22
#include " clang/Basic/Builtins.h"
23
23
#include " clang/CIR/Dialect/IR/CIRDialect.h"
24
- #include " clang/CIR/Dialect/IR/CIROpsEnums.h"
25
24
#include " clang/CIR/Dialect/IR/CIRTypes.h"
26
25
#include " llvm/Support/Casting.h"
27
26
#include " llvm/Support/ErrorHandling.h"
@@ -129,7 +128,6 @@ static Address buildPointerWithAlignment(const Expr *E,
129
128
if (PtrTy->getPointeeType ()->isVoidType ())
130
129
break ;
131
130
assert (!UnimplementedFeature::tbaa ());
132
-
133
131
LValueBaseInfo InnerBaseInfo;
134
132
Address Addr = CGF.buildPointerWithAlignment (
135
133
CE->getSubExpr (), &InnerBaseInfo, IsKnownNonNull);
@@ -213,78 +211,13 @@ static Address buildPointerWithAlignment(const Expr *E,
213
211
return Address (CGF.buildScalarExpr (E), Align);
214
212
}
215
213
216
- // / Helper method to check if the underlying ABI is AAPCS
217
- static bool isAAPCS (const TargetInfo &TargetInfo) {
218
- return TargetInfo.getABI ().starts_with (" aapcs" );
219
- }
220
-
221
- Address CIRGenFunction::getAddrOfField (LValue base, const FieldDecl *field,
222
- unsigned index) {
223
- if (index == 0 )
224
- return base.getAddress ();
225
-
226
- auto loc = getLoc (field->getLocation ());
227
- auto fieldType = convertType (field->getType ());
228
- auto fieldPtr =
229
- mlir::cir::PointerType::get (getBuilder ().getContext (), fieldType);
230
- auto sea = getBuilder ().createGetMember (
231
- loc, fieldPtr, base.getPointer (), field->getName (), index );
232
-
233
- return Address (sea, CharUnits::One ());
234
- }
235
-
236
- static bool useVolatileForBitField (const CIRGenModule &cgm, LValue base,
237
- const CIRGenBitFieldInfo &info,
238
- const FieldDecl *field) {
239
- return isAAPCS (cgm.getTarget ()) && cgm.getCodeGenOpts ().AAPCSBitfieldWidth &&
240
- info.VolatileStorageSize != 0 &&
241
- field->getType ()
242
- .withCVRQualifiers (base.getVRQualifiers ())
243
- .isVolatileQualified ();
244
- }
245
-
246
- LValue CIRGenFunction::buildLValueForBitField (LValue base,
247
- const FieldDecl *field) {
248
-
249
- LValueBaseInfo BaseInfo = base.getBaseInfo ();
250
- const RecordDecl *rec = field->getParent ();
251
- auto &layout = CGM.getTypes ().getCIRGenRecordLayout (field->getParent ());
252
- auto &info = layout.getBitFieldInfo (field);
253
- auto useVolatile = useVolatileForBitField (CGM, base, info, field);
254
- unsigned Idx = layout.getCIRFieldNo (field);
255
-
256
- if (useVolatile ||
257
- (IsInPreservedAIRegion ||
258
- (getDebugInfo () && rec->hasAttr <BPFPreserveAccessIndexAttr>()))) {
259
- llvm_unreachable (" NYI" );
260
- }
261
-
262
- Address Addr = getAddrOfField (base, field, Idx);
263
-
264
- const unsigned SS = useVolatile ? info.VolatileStorageSize : info.StorageSize ;
265
-
266
- // Get the access type.
267
- mlir::Type FieldIntTy = builder.getUIntNTy (SS);
268
-
269
- auto loc = getLoc (field->getLocation ());
270
- if (Addr.getElementType () != FieldIntTy)
271
- Addr = builder.createElementBitCast (loc, Addr, FieldIntTy);
272
-
273
- QualType fieldType =
274
- field->getType ().withCVRQualifiers (base.getVRQualifiers ());
275
-
276
- assert (!UnimplementedFeature::tbaa () && " NYI TBAA for bit fields" );
277
- LValueBaseInfo FieldBaseInfo (BaseInfo.getAlignmentSource ());
278
- return LValue::MakeBitfield (Addr, info, fieldType, FieldBaseInfo);
279
- }
280
-
281
214
LValue CIRGenFunction::buildLValueForField (LValue base,
282
215
const FieldDecl *field) {
283
-
284
216
LValueBaseInfo BaseInfo = base.getBaseInfo ();
285
217
286
- if (field->isBitField ())
287
- return buildLValueForBitField (base, field);
218
+ if (field->isBitField ()) {
219
+ llvm_unreachable (" NYI" );
220
+ }
288
221
289
222
// Fields of may-alias structures are may-alais themselves.
290
223
// FIXME: this hould get propagated down through anonymous structs and unions.
@@ -583,55 +516,12 @@ void CIRGenFunction::buildStoreOfScalar(mlir::Value value, LValue lvalue,
583
516
// / method emits the address of the lvalue, then loads the result as an rvalue,
584
517
// / returning the rvalue.
585
518
RValue CIRGenFunction::buildLoadOfLValue (LValue LV, SourceLocation Loc) {
519
+ assert (LV.isSimple () && " not implemented" );
586
520
assert (!LV.getType ()->isFunctionType ());
587
521
assert (!(LV.getType ()->isConstantMatrixType ()) && " not implemented" );
588
522
589
- if (LV.isBitField ())
590
- return buildLoadOfBitfieldLValue (LV, Loc);
591
-
592
- if (LV.isSimple ())
593
- return RValue::get (buildLoadOfScalar (LV, Loc));
594
- llvm_unreachable (" NYI" );
595
- }
596
-
597
- RValue CIRGenFunction::buildLoadOfBitfieldLValue (LValue LV,
598
- SourceLocation Loc) {
599
- const CIRGenBitFieldInfo &Info = LV.getBitFieldInfo ();
600
-
601
- // Get the output type.
602
- mlir::Type ResLTy = convertType (LV.getType ());
603
- Address Ptr = LV.getBitFieldAddress ();
604
- mlir::Value Val = builder.createLoad (getLoc (Loc), Ptr );
605
- auto ValWidth = Val.getType ().cast <IntType>().getWidth ();
606
-
607
- bool UseVolatile = LV.isVolatileQualified () &&
608
- Info.VolatileStorageSize != 0 && isAAPCS (CGM.getTarget ());
609
- const unsigned Offset = UseVolatile ? Info.VolatileOffset : Info.Offset ;
610
- const unsigned StorageSize =
611
- UseVolatile ? Info.VolatileStorageSize : Info.StorageSize ;
612
-
613
- if (Info.IsSigned ) {
614
- assert (static_cast <unsigned >(Offset + Info.Size ) <= StorageSize);
615
-
616
- mlir::Type typ = builder.getSIntNTy (ValWidth);
617
- Val = builder.createIntCast (Val, typ);
618
-
619
- unsigned HighBits = StorageSize - Offset - Info.Size ;
620
- if (HighBits)
621
- Val = builder.createShiftLeft (Val, HighBits);
622
- if (Offset + HighBits)
623
- Val = builder.createShiftRight (Val, Offset + HighBits);
624
- } else {
625
- if (Offset)
626
- Val = builder.createShiftRight (Val, Offset);
627
-
628
- if (static_cast <unsigned >(Offset) + Info.Size < StorageSize)
629
- Val = builder.createAnd (Val,
630
- llvm::APInt::getLowBitsSet (ValWidth, Info.Size ));
631
- }
632
- Val = builder.createIntCast (Val, ResLTy);
633
- assert (!UnimplementedFeature::emitScalarRangeCheck () && " NYI" );
634
- return RValue::get (Val);
523
+ // Everything needs a load.
524
+ return RValue::get (buildLoadOfScalar (LV, Loc));
635
525
}
636
526
637
527
void CIRGenFunction::buildStoreThroughLValue (RValue Src, LValue Dst) {
@@ -654,81 +544,6 @@ void CIRGenFunction::buildStoreThroughLValue(RValue Src, LValue Dst) {
654
544
buildStoreOfScalar (Src.getScalarVal (), Dst);
655
545
}
656
546
657
- void CIRGenFunction::buildStoreThroughBitfieldLValue (RValue Src, LValue Dst,
658
- mlir::Value &Result) {
659
- const CIRGenBitFieldInfo &Info = Dst.getBitFieldInfo ();
660
- mlir::Type ResLTy = getTypes ().convertTypeForMem (Dst.getType ());
661
- Address Ptr = Dst.getBitFieldAddress ();
662
-
663
- // Get the source value, truncated to the width of the bit-field.
664
- mlir::Value SrcVal = Src.getScalarVal ();
665
-
666
- // Cast the source to the storage type and shift it into place.
667
- SrcVal = builder.createIntCast (SrcVal, Ptr .getElementType ());
668
- auto SrcWidth = SrcVal.getType ().cast <IntType>().getWidth ();
669
- mlir::Value MaskedVal = SrcVal;
670
-
671
- const bool UseVolatile =
672
- CGM.getCodeGenOpts ().AAPCSBitfieldWidth && Dst.isVolatileQualified () &&
673
- Info.VolatileStorageSize != 0 && isAAPCS (CGM.getTarget ());
674
- const unsigned StorageSize =
675
- UseVolatile ? Info.VolatileStorageSize : Info.StorageSize ;
676
- const unsigned Offset = UseVolatile ? Info.VolatileOffset : Info.Offset ;
677
- // See if there are other bits in the bitfield's storage we'll need to load
678
- // and mask together with source before storing.
679
- if (StorageSize != Info.Size ) {
680
- assert (StorageSize > Info.Size && " Invalid bitfield size." );
681
-
682
- mlir::Value Val = buildLoadOfScalar (Dst, Dst.getPointer ().getLoc ());
683
-
684
- // Mask the source value as needed.
685
- if (!hasBooleanRepresentation (Dst.getType ()))
686
- SrcVal = builder.createAnd (
687
- SrcVal, llvm::APInt::getLowBitsSet (SrcWidth, Info.Size ));
688
-
689
- MaskedVal = SrcVal;
690
- if (Offset)
691
- SrcVal = builder.createShiftLeft (SrcVal, Offset);
692
-
693
- // Mask out the original value.
694
- Val = builder.createAnd (
695
- Val, ~llvm::APInt::getBitsSet (SrcWidth, Offset, Offset + Info.Size ));
696
-
697
- // Or together the unchanged values and the source value.
698
- SrcVal = builder.createOr (Val, SrcVal);
699
-
700
- } else {
701
- // According to the AACPS:
702
- // When a volatile bit-field is written, and its container does not overlap
703
- // with any non-bit-field member, its container must be read exactly once
704
- // and written exactly once using the access width appropriate to the type
705
- // of the container. The two accesses are not atomic.
706
- llvm_unreachable (" volatile bit-field is not implemented for the AACPS" );
707
- }
708
-
709
- // Write the new value back out.
710
- // TODO: constant matrix type, volatile, no init, non temporal, TBAA
711
- buildStoreOfScalar (SrcVal, Ptr , Dst.isVolatileQualified (), Dst.getType (),
712
- Dst.getBaseInfo (), false , false );
713
-
714
- // Return the new value of the bit-field.
715
- mlir::Value ResultVal = MaskedVal;
716
- ResultVal = builder.createIntCast (ResultVal, ResLTy);
717
-
718
- // Sign extend the value if needed.
719
- if (Info.IsSigned ) {
720
- assert (Info.Size <= StorageSize);
721
- unsigned HighBits = StorageSize - Info.Size ;
722
-
723
- if (HighBits) {
724
- ResultVal = builder.createShiftLeft (ResultVal, HighBits);
725
- ResultVal = builder.createShiftRight (ResultVal, HighBits);
726
- }
727
- }
728
-
729
- Result = buildFromMemory (ResultVal, Dst.getType ());
730
- }
731
-
732
547
static LValue buildGlobalVarDeclLValue (CIRGenFunction &CGF, const Expr *E,
733
548
const VarDecl *VD) {
734
549
QualType T = E->getType ();
@@ -952,13 +767,7 @@ LValue CIRGenFunction::buildBinaryOperatorLValue(const BinaryOperator *E) {
952
767
LValue LV = buildLValue (E->getLHS ());
953
768
954
769
SourceLocRAIIObject Loc{*this , getLoc (E->getSourceRange ())};
955
- if (LV.isBitField ()) {
956
- mlir::Value result;
957
- buildStoreThroughBitfieldLValue (RV, LV, result);
958
- } else {
959
- buildStoreThroughLValue (RV, LV);
960
- }
961
-
770
+ buildStoreThroughLValue (RV, LV);
962
771
assert (!getContext ().getLangOpts ().OpenMP &&
963
772
" last priv cond not implemented" );
964
773
return LV;
@@ -2394,13 +2203,6 @@ mlir::Value CIRGenFunction::buildAlloca(StringRef name, QualType ty,
2394
2203
2395
2204
mlir::Value CIRGenFunction::buildLoadOfScalar (LValue lvalue,
2396
2205
SourceLocation Loc) {
2397
- return buildLoadOfScalar (lvalue.getAddress (), lvalue.isVolatile (),
2398
- lvalue.getType (), getLoc (Loc), lvalue.getBaseInfo (),
2399
- lvalue.isNontemporal ());
2400
- }
2401
-
2402
- mlir::Value CIRGenFunction::buildLoadOfScalar (LValue lvalue,
2403
- mlir::Location Loc) {
2404
2206
return buildLoadOfScalar (lvalue.getAddress (), lvalue.isVolatile (),
2405
2207
lvalue.getType (), Loc, lvalue.getBaseInfo (),
2406
2208
lvalue.isNontemporal ());
@@ -2418,14 +2220,6 @@ mlir::Value CIRGenFunction::buildLoadOfScalar(Address Addr, bool Volatile,
2418
2220
QualType Ty, SourceLocation Loc,
2419
2221
LValueBaseInfo BaseInfo,
2420
2222
bool isNontemporal) {
2421
- return buildLoadOfScalar (Addr, Volatile, Ty, getLoc (Loc), BaseInfo,
2422
- isNontemporal);
2423
- }
2424
-
2425
- mlir::Value CIRGenFunction::buildLoadOfScalar (Address Addr, bool Volatile,
2426
- QualType Ty, mlir::Location Loc,
2427
- LValueBaseInfo BaseInfo,
2428
- bool isNontemporal) {
2429
2223
// TODO(CIR): this has fallen out of sync with codegen
2430
2224
2431
2225
// Atomic operations have to be done on integral types
@@ -2435,14 +2229,15 @@ mlir::Value CIRGenFunction::buildLoadOfScalar(Address Addr, bool Volatile,
2435
2229
}
2436
2230
2437
2231
mlir::cir::LoadOp Load = builder.create <mlir::cir::LoadOp>(
2438
- Loc, Addr.getElementType (), Addr.getPointer ());
2232
+ getLoc ( Loc) , Addr.getElementType (), Addr.getPointer ());
2439
2233
2440
2234
if (isNontemporal) {
2441
2235
llvm_unreachable (" NYI" );
2442
2236
}
2443
-
2444
- assert (!UnimplementedFeature::tbaa () && " NYI" );
2445
- assert (!UnimplementedFeature::emitScalarRangeCheck () && " NYI" );
2237
+
2238
+ // TODO: TBAA
2239
+
2240
+ // TODO: buildScalarRangeCheck
2446
2241
2447
2242
return buildFromMemory (Load, Ty);
2448
2243
}
0 commit comments