[clang] [CIR] Add atomic load and store operations (PR #153814)
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 15 14:56:45 PDT 2025
================
@@ -187,12 +244,85 @@ void AtomicInfo::emitCopyIntoMemory(RValue rvalue) const {
}
}
+static void emitAtomicOp(CIRGenFunction &cgf, AtomicExpr *expr, Address dest,
+ Address ptr, Address val1, uint64_t size,
+ cir::MemOrder order) {
+ std::unique_ptr<AtomicScopeModel> scopeModel = expr->getScopeModel();
+ if (scopeModel) {
+ assert(!cir::MissingFeatures::atomicScope());
+ cgf.cgm.errorNYI(expr->getSourceRange(), "emitAtomicOp: atomic scope");
+ return;
+ }
+
+ assert(!cir::MissingFeatures::atomicSyncScopeID());
+
+ CIRGenBuilderTy &builder = cgf.getBuilder();
+ mlir::Location loc = cgf.getLoc(expr->getSourceRange());
+ auto orderAttr = cir::MemOrderAttr::get(builder.getContext(), order);
+
+ switch (expr->getOp()) {
+ default:
+ cgf.cgm.errorNYI(expr->getSourceRange(), "emitAtomicOp: expr op NYI");
+ break;
+
+ case AtomicExpr::AO__c11_atomic_init:
+ llvm_unreachable("already handled!");
+
+ case AtomicExpr::AO__c11_atomic_load:
+ case AtomicExpr::AO__atomic_load: {
+ cir::LoadOp load =
+ builder.createLoad(loc, ptr, /*isVolatile=*/expr->isVolatile());
+
+ assert(!cir::MissingFeatures::atomicSyncScopeID());
+
+ load->setAttr("mem_order", orderAttr);
+
+ // TODO(cir): this logic should be part of createStore, but doing so
+ // currently breaks CodeGen/union.cpp and CodeGen/union.cpp.
+ auto ptrTy = mlir::cast<cir::PointerType>(dest.getPointer().getType());
----------------
bcardosolopes wrote:
Is this a good time to make such change to createStore? Might be cargo cult a this point.
https://github.com/llvm/llvm-project/pull/153814
More information about the cfe-commits
mailing list