Skip to content

Commit

Permalink
[CIR][CIRGen] Add alignment attribute to AtomicCmpXchg
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasqueX committed Feb 8, 2025
1 parent a7383c9 commit dce891f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 1 deletion.
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,
DefaultValuedAttr<I64Attr, "0">:$alignment,
UnitAttr:$weak,
UnitAttr:$is_volatile);

Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/CodeGen/CIRGenAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ static void emitAtomicCmpXchg(CIRGenFunction &CGF, AtomicExpr *E, bool IsWeak,
auto cmpxchg = builder.create<cir::AtomicCmpXchg>(
loc, Expected.getType(), boolTy, Ptr.getPointer(), Expected, Desired,
SuccessOrder, FailureOrder);
cmpxchg.setAlignment(Ptr.getAlignment().getAsAlign().value());
cmpxchg.setIsVolatile(E->isVolatile());
cmpxchg.setWeak(IsWeak);

Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ static mlir::Value MakeAtomicCmpXchgValue(CIRGenFunction &cgf,
destAddr.getPointer(), cmpVal, newVal,
cir::MemOrder::SequentiallyConsistent,
cir::MemOrder::SequentiallyConsistent);
op.setAlignment(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

0 comments on commit dce891f

Please sign in to comment.