Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][CIRGen] Add alignment attribute to AtomicCmpXchg #1327

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -5390,6 +5390,7 @@ def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg",
CIR_AnyType:$desired,
Arg<MemOrder, "success memory order">:$succ_order,
Arg<MemOrder, "failure memory order">:$fail_order,
OptionalAttr<I64Attr>:$alignment,
FantasqueX marked this conversation as resolved.
Show resolved Hide resolved
UnitAttr:$weak,
UnitAttr:$is_volatile);

Expand Down
4 changes: 3 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ static void emitAtomicCmpXchg(CIRGenFunction &CGF, AtomicExpr *E, bool IsWeak,
auto boolTy = builder.getBoolTy();
auto cmpxchg = builder.create<cir::AtomicCmpXchg>(
loc, Expected.getType(), boolTy, Ptr.getPointer(), Expected, Desired,
SuccessOrder, FailureOrder);
cir::MemOrderAttr::get(&CGF.getMLIRContext(), SuccessOrder),
cir::MemOrderAttr::get(&CGF.getMLIRContext(), FailureOrder),
builder.getI64IntegerAttr(Ptr.getAlignment().getAsAlign().value()));
cmpxchg.setIsVolatile(E->isVolatile());
cmpxchg.setWeak(IsWeak);

Expand Down
5 changes: 3 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ static mlir::Value MakeAtomicCmpXchgValue(CIRGenFunction &cgf,
auto op = builder.create<cir::AtomicCmpXchg>(
cgf.getLoc(expr->getSourceRange()), cmpVal.getType(), builder.getBoolTy(),
destAddr.getPointer(), cmpVal, newVal,
cir::MemOrder::SequentiallyConsistent,
cir::MemOrder::SequentiallyConsistent);
MemOrderAttr::get(&cgf.getMLIRContext(), cir::MemOrder::SequentiallyConsistent),
MemOrderAttr::get(&cgf.getMLIRContext(), cir::MemOrder::SequentiallyConsistent),
builder.getI64IntegerAttr(destAddr.getAlignment().getAsAlign().value()));

return returnBool ? op.getResult(1) : op.getResult(0);
}
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3197,6 +3197,7 @@ mlir::LogicalResult CIRToLLVMAtomicCmpXchgLowering::matchAndRewrite(
op.getLoc(), adaptor.getPtr(), expected, desired,
getLLVMAtomicOrder(adaptor.getSuccOrder()),
getLLVMAtomicOrder(adaptor.getFailOrder()));
cmpxchg.setAlignment(adaptor.getAlignment());
cmpxchg.setWeak(adaptor.getWeak());
cmpxchg.setVolatile_(adaptor.getIsVolatile());

Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/atomic-xchg-field.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void structAtomicExchange(unsigned referenceCount, wPtr item) {
// LLVM: store i32
// LLVM: %[[EXP:.*]] = load i32
// LLVM: %[[DES:.*]] = load i32
// LLVM: %[[RES:.*]] = cmpxchg weak ptr %9, i32 %[[EXP]], i32 %[[DES]] seq_cst seq_cst
// LLVM: %[[RES:.*]] = cmpxchg weak ptr %9, i32 %[[EXP]], i32 %[[DES]] seq_cst seq_cst, align 8
// LLVM: %[[OLD:.*]] = extractvalue { i32, i1 } %[[RES]], 0
// LLVM: %[[CMP:.*]] = extractvalue { i32, i1 } %[[RES]], 1
// LLVM: %[[FAIL:.*]] = xor i1 %[[CMP]], true
Expand Down
Loading