Skip to content

[CIR] Implement ::verify for cir.atomic.xchg and cir.atomic.cmp_xchg #1431

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

Merged
merged 4 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -5481,7 +5481,7 @@ def AtomicXchg : CIR_Op<"atomic.xchg", [AllTypesMatch<["result", "val"]>]> {
`:` type($result) attr-dict
}];

let hasVerifier = 0;
let hasVerifier = 1;
}

def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg",
Expand Down Expand Up @@ -5524,7 +5524,7 @@ def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg",
`:` `(` type($old) `,` type($cmp) `)` attr-dict
}];

let hasVerifier = 0;
let hasVerifier = 1;
}

def MemScope_SingleThread : I32EnumAttrCase<"MemScope_SingleThread",
Expand Down
32 changes: 32 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,38 @@ LogicalResult cir::ContinueOp::verify() {
return success();
}

//===----------------------------------------------------------------------===//
// AtomicXchg
//===----------------------------------------------------------------------===//
LogicalResult cir::AtomicXchg::verify() {
const auto& tps = this->getOperation()->getOperandTypes();

const auto& tp0 = mlir::dyn_cast<cir::PointerType>(tps[0]);
const auto& tp1 = tps[1];

if(tp0.getPointee() != tp1)
return emitOpError("atomic ptr type and xchg val must match");

return success();
}


//===----------------------------------------------------------------------===//
// AtomicCmpXchg
//===----------------------------------------------------------------------===//
LogicalResult cir::AtomicCmpXchg::verify() {
const auto& tps = this->getOperation()->getOperandTypes();

const auto& tp0 = mlir::dyn_cast<cir::PointerType>(tps[0]);
const auto& tp1 = tps[1];
const auto& tp2 = tps[2];

if(tp0.getPointee() != tp1 or tp0.getPointee() != tp2)
return emitOpError("atomic ptr type and cmp_xchg expected and desired types must match");

return success();
}

//===----------------------------------------------------------------------===//
// CastOp
//===----------------------------------------------------------------------===//
Expand Down