@@ -58,6 +58,28 @@ static RValue emitBuiltinBitOp(CIRGenFunction &cgf, const CallExpr *e,
5858 return RValue::get (result);
5959}
6060
61+ static mlir::Value makeAtomicFenceValue (CIRGenFunction &cgf,
62+ const CallExpr *expr,
63+ cir::MemScopeKind syncScope) {
64+ auto &builder = cgf.getBuilder ();
65+ mlir::Value orderingVal = cgf.emitScalarExpr (expr->getArg (0 ));
66+
67+ auto constOrdering = orderingVal.getDefiningOp <cir::ConstantOp>();
68+ if (!constOrdering)
69+ llvm_unreachable (" NYI: variable ordering not supported" );
70+
71+ if (auto constOrderingAttr = constOrdering.getValueAttr <cir::IntAttr>()) {
72+ cir::MemOrder ordering =
73+ static_cast <cir::MemOrder>(constOrderingAttr.getUInt ());
74+
75+ cir::AtomicFence::create (
76+ builder, cgf.getLoc (expr->getSourceRange ()), ordering,
77+ cir::MemScopeKindAttr::get (&cgf.getMLIRContext (), syncScope));
78+ }
79+
80+ return {};
81+ }
82+
6183RValue CIRGenFunction::emitRotate (const CallExpr *e, bool isRotateLeft) {
6284 mlir::Value input = emitScalarExpr (e->getArg (0 ));
6385 mlir::Value amount = emitScalarExpr (e->getArg (1 ));
@@ -520,6 +542,23 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
520542 cir::PrefetchOp::create (builder, loc, address, locality, isWrite);
521543 return RValue::get (nullptr );
522544 }
545+ case Builtin::BI__c11_atomic_is_lock_free:
546+ llvm_unreachable (" BI__c11_atomic_is_lock_free NYI" );
547+ case Builtin::BI__atomic_is_lock_free:
548+ llvm_unreachable (" BI__atomic_is_lock_free NYI" );
549+ case Builtin::BI__atomic_test_and_set:
550+ llvm_unreachable (" BI__atomic_test_and_set NYI" );
551+ case Builtin::BI__atomic_clear:
552+ llvm_unreachable (" BI__atomic_clear NYI" );
553+ case Builtin::BI__atomic_thread_fence:
554+ return RValue::get (
555+ makeAtomicFenceValue (*this , e, cir::MemScopeKind::System));
556+ case Builtin::BI__atomic_signal_fence:
557+ return RValue::get (
558+ makeAtomicFenceValue (*this , e, cir::MemScopeKind::SingleThread));
559+ case Builtin::BI__c11_atomic_thread_fence:
560+ case Builtin::BI__c11_atomic_signal_fence:
561+ llvm_unreachable (" BI__c11_atomic_thread_fence like NYI" );
523562 }
524563
525564 // If this is an alias for a lib function (e.g. __builtin_sin), emit
0 commit comments