@@ -330,40 +330,41 @@ Address AtomicInfo::CreateTempAlloca() const {
330
330
return TempAlloca;
331
331
}
332
332
333
- // If the value comes from a ConstOp + IntAttr, retrieve and skip a series
334
- // of casts if necessary.
335
- //
336
- // FIXME(cir): figure out warning issue and move this to CIRBaseBuilder.h
337
- static cir::IntAttr getConstOpIntAttr (mlir::Value v) {
338
- mlir::Operation *op = v.getDefiningOp ();
339
- cir::IntAttr constVal;
340
- while (auto c = dyn_cast<cir::CastOp>(op))
341
- op = c.getOperand ().getDefiningOp ();
342
- if (auto c = dyn_cast<cir::ConstantOp>(op)) {
343
- if (mlir::isa<cir::IntType>(c.getType ()))
344
- constVal = mlir::cast<cir::IntAttr>(c.getValue ());
345
- }
346
- return constVal;
333
+ static mlir::Value stripCasts (mlir::Value value) {
334
+ while (auto castOp = value.getDefiningOp <cir::CastOp>())
335
+ value = castOp.getOperand ();
336
+ return value;
337
+ }
338
+
339
+ static cir::ConstantOp extractConstant (mlir::Value v) {
340
+ return stripCasts (v).getDefiningOp <cir::ConstantOp>();
341
+ }
342
+
343
+ // If the value comes from a ConstOp + IntAttr, retrieve and skip a series of
344
+ // casts if necessary.
345
+ static cir::IntAttr extractIntAttr (mlir::Value v) {
346
+ if (auto c = extractConstant (v))
347
+ return c.getValueAttr <cir::IntAttr>();
348
+ return {};
347
349
}
348
350
349
351
// Inspect a value that is the strong/weak flag for a compare-exchange. If it
350
352
// is a constant of intergral or boolean type, set `val` to the constant's
351
353
// boolean value and return true. Otherwise leave `val` unchanged and return
352
354
// false.
353
355
static bool isCstWeak (mlir::Value weakVal, bool &val) {
354
- mlir::Operation *op = weakVal.getDefiningOp ();
355
- while (auto c = dyn_cast<cir::CastOp>(op)) {
356
- op = c.getOperand ().getDefiningOp ();
357
- }
358
- if (auto c = dyn_cast<cir::ConstantOp>(op)) {
359
- if (mlir::isa<cir::IntType>(c.getType ())) {
360
- val = mlir::cast<cir::IntAttr>(c.getValue ()).getUInt () != 0 ;
356
+ if (auto c = extractConstant (weakVal)) {
357
+ if (auto attr = c.getValueAttr <cir::IntAttr>()) {
358
+ val = attr.getUInt () != 0 ;
361
359
return true ;
362
- } else if (mlir::isa<cir::BoolType>(c.getType ())) {
363
- val = mlir::cast<cir::BoolAttr>(c.getValue ()).getValue ();
360
+ }
361
+
362
+ if (auto attr = c.getValueAttr <cir::BoolAttr>()) {
363
+ val = attr.getValue ();
364
364
return true ;
365
365
}
366
366
}
367
+
367
368
return false ;
368
369
}
369
370
@@ -456,7 +457,7 @@ static void emitAtomicCmpXchgFailureSet(
456
457
cir::MemOrder SuccessOrder, cir::MemScopeKind Scope) {
457
458
458
459
cir::MemOrder FailureOrder;
459
- if (auto ordAttr = getConstOpIntAttr (FailureOrderVal)) {
460
+ if (auto ordAttr = extractIntAttr (FailureOrderVal)) {
460
461
// We should not ever get to a case where the ordering isn't a valid CABI
461
462
// value, but it's hard to enforce that in general.
462
463
auto ord = ordAttr.getUInt ();
@@ -805,7 +806,7 @@ static void emitAtomicOp(CIRGenFunction &CGF, AtomicExpr *Expr, Address Dest,
805
806
}
806
807
807
808
// Handle constant scope.
808
- if (getConstOpIntAttr (Scope)) {
809
+ if (extractIntAttr (Scope)) {
809
810
assert (!cir::MissingFeatures::syncScopeID ());
810
811
llvm_unreachable (" NYI" );
811
812
return ;
@@ -1208,7 +1209,7 @@ RValue CIRGenFunction::emitAtomicExpr(AtomicExpr *E) {
1208
1209
E->getOp () == AtomicExpr::AO__scoped_atomic_load ||
1209
1210
E->getOp () == AtomicExpr::AO__scoped_atomic_load_n;
1210
1211
1211
- if (auto ordAttr = getConstOpIntAttr (Order)) {
1212
+ if (auto ordAttr = extractIntAttr (Order)) {
1212
1213
// We should not ever get to a case where the ordering isn't a valid CABI
1213
1214
// value, but it's hard to enforce that in general.
1214
1215
auto ord = ordAttr.getUInt ();
0 commit comments