[clang] [CIR] Add support for atomic-to-non-atomic cast (PR #193784)
Sirui Mu via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 24 07:45:37 PDT 2026
================
@@ -189,6 +201,38 @@ Address AtomicInfo::convertToAtomicIntPointer(Address addr) const {
return castToAtomicIntPointer(addr);
}
+RValue AtomicInfo::emitAtomicLoad(AggValueSlot resultSlot, SourceLocation loc,
+ bool asValue, cir::MemOrder order,
+ bool isVolatile) {
+ // Check whether we should use a library call.
+ if (shouldUseLibCall()) {
+ assert(!cir::MissingFeatures::atomicUseLibCall());
+ cgf.cgm.errorNYI(loc, "emitAtomicLoad: emit atomic lib call");
+ return RValue::get(nullptr);
+ }
+
+ // Okay, we're doing this natively.
+ mlir::Value loadOp = emitAtomicLoadOp(order, isVolatile);
+
+ // If we're ignoring an aggregate return, don't do anything.
+ if (getEvaluationKind() == TEK_Aggregate && resultSlot.isIgnored())
+ return RValue::getAggregate(Address::invalid(), false);
+
+ // Okay, turn that back into the original value or atomic (for non-simple
+ // lvalues) type.
+ return convertToValueOrAtomic(loadOp, resultSlot, loc, asValue);
+}
+
+mlir::Value AtomicInfo::emitAtomicLoadOp(cir::MemOrder order, bool isVolatile) {
+ Address addr = getAtomicAddress();
----------------
Lancern wrote:
I just have a quick skimming through what we already have in `CIRGenAtomic.cpp`, and I found a lot of similar code for bypassing LLVM IR constraints. I think we could post-pone all those processing until LowerToLLVM, but obviously that deserves a series of additional patches. For now my priority is to remove NYI paths within atomic related stuff, so I'm going to mimic what OGCG is doing here and add the `shouldCastToInt` check back.
https://github.com/llvm/llvm-project/pull/193784
More information about the cfe-commits
mailing list