Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -5493,7 +5493,7 @@ def CIR_AtomicClearOp : CIR_Op<"atomic.clear"> {
}];
}

def CIR_AtomicFence : CIR_Op<"atomic.fence"> {
def CIR_AtomicFenceOp : CIR_Op<"atomic.fence"> {
let summary = "Atomic thread fence";
let description = [{
C/C++ Atomic thread fence synchronization primitive. Implements the builtin
Expand Down
25 changes: 13 additions & 12 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ static RValue emitBuiltinBitOp(CIRGenFunction &cgf, const CallExpr *e,
return RValue::get(result);
}

static mlir::Value makeAtomicFenceValue(CIRGenFunction &cgf,
const CallExpr *expr,
cir::SyncScopeKind syncScope) {
static void emitAtomicFenceOp(CIRGenFunction &cgf, const CallExpr *expr,
cir::SyncScopeKind syncScope) {
CIRGenBuilderTy &builder = cgf.getBuilder();
mlir::Value orderingVal = cgf.emitScalarExpr(expr->getArg(0));

Expand All @@ -72,19 +71,19 @@ static mlir::Value makeAtomicFenceValue(CIRGenFunction &cgf,
// TODO(cir): Emit code to switch on `orderingVal`,
// and creating the fence op for valid values.
cgf.cgm.errorNYI("Variable atomic fence ordering");
return {};
return;
}

auto constOrderingAttr = constOrdering.getValueAttr<cir::IntAttr>();
assert(constOrderingAttr && "Expected integer constant for ordering");

auto ordering = static_cast<cir::MemOrder>(constOrderingAttr.getUInt());

cir::AtomicFence::create(
cir::AtomicFenceOp::create(
builder, cgf.getLoc(expr->getSourceRange()), ordering,
cir::SyncScopeKindAttr::get(&cgf.getMLIRContext(), syncScope));

return {};
return;
}

namespace {
Expand Down Expand Up @@ -1010,12 +1009,14 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
case Builtin::BI__atomic_test_and_set:
case Builtin::BI__atomic_clear:
return errorBuiltinNYI(*this, e, builtinID);
case Builtin::BI__atomic_thread_fence:
return RValue::get(
makeAtomicFenceValue(*this, e, cir::SyncScopeKind::System));
case Builtin::BI__atomic_signal_fence:
return RValue::get(
makeAtomicFenceValue(*this, e, cir::SyncScopeKind::SingleThread));
case Builtin::BI__atomic_thread_fence: {
emitAtomicFenceOp(*this, e, cir::SyncScopeKind::System);
return RValue::get(nullptr);
}
case Builtin::BI__atomic_signal_fence: {
emitAtomicFenceOp(*this, e, cir::SyncScopeKind::SingleThread);
return RValue::get(nullptr);
}
case Builtin::BI__c11_atomic_thread_fence:
case Builtin::BI__c11_atomic_signal_fence:
case Builtin::BI__scoped_atomic_thread_fence:
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ mlir::LogicalResult CIRToLLVMAtomicClearOpLowering::matchAndRewrite(
return mlir::success();
}

mlir::LogicalResult CIRToLLVMAtomicFenceLowering::matchAndRewrite(
cir::AtomicFence op, OpAdaptor adaptor,
mlir::LogicalResult CIRToLLVMAtomicFenceOpLowering::matchAndRewrite(
cir::AtomicFenceOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
mlir::LLVM::AtomicOrdering llvmOrder = getLLVMMemOrder(adaptor.getOrdering());

Expand Down