================ @@ -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()); ---------------- Lancern wrote:
I'm not quite sure whether this logic is really necessary here. I did a quick git history check and found that this logic was introduced in https://github.com/llvm/clangir/commit/2a187076dc16773e9243c0d3d5187be72e3d6f41 . Seems like it has to do with `__atomic_load_n` and it's not necessary in this patch. I removed it and will reconsider it when upstreaming that atomic op. https://github.com/llvm/llvm-project/pull/153814 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits