================ @@ -5133,6 +5133,135 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Builder.SetInsertPoint(ContBB); return RValue::get(nullptr); } + case Builtin::BI__scoped_atomic_thread_fence: { + auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic); + + Value *Order = EmitScalarExpr(E->getArg(0)); + Value *Scope = EmitScalarExpr(E->getArg(1)); + if (isa<llvm::ConstantInt>(Order) && isa<llvm::ConstantInt>(Scope)) { + int Ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); + int Scp = cast<llvm::ConstantInt>(Scope)->getZExtValue(); + SyncScope SS = ScopeModel->isValid(Scp) + ? ScopeModel->map(Scp) + : ScopeModel->map(ScopeModel->getFallBackValue()); + switch (Ord) { + case 0: // memory_order_relaxed + default: // invalid order + break; + case 1: // memory_order_consume + case 2: // memory_order_acquire + Builder.CreateFence( + llvm::AtomicOrdering::Acquire, + getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS, + llvm::AtomicOrdering::Acquire, + getLLVMContext())); + break; + case 3: // memory_order_release + Builder.CreateFence( + llvm::AtomicOrdering::Release, + getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS, + llvm::AtomicOrdering::Release, + getLLVMContext())); + break; + case 4: // memory_order_acq_rel + Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, + getTargetHooks().getLLVMSyncScopeID( + getLangOpts(), SS, + llvm::AtomicOrdering::AcquireRelease, + getLLVMContext())); + break; + case 5: // memory_order_seq_cst + Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, + getTargetHooks().getLLVMSyncScopeID( + getLangOpts(), SS, + llvm::AtomicOrdering::SequentiallyConsistent, + getLLVMContext())); + break; + } + return RValue::get(nullptr); + } + + llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", CurFn); + + llvm::DenseMap<llvm::BasicBlock *, llvm::AtomicOrdering> OrderBBs; + if (isa<llvm::ConstantInt>(Order)) { + int Ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); ---------------- arsenm wrote:
dyn_cast https://github.com/llvm/llvm-project/pull/115545 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits