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] Handle __sync_nand_and_fetch #1351

Merged
merged 4 commits into from
Feb 19, 2025
Merged
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
1 change: 0 additions & 1 deletion clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ struct MissingFeatures {
static bool emitConstrainedFPCall() { return false; }
static bool emitEmptyRecordCheck() { return false; }
static bool isPPC_FP128Ty() { return false; }
static bool emitBinaryAtomicPostHasInvert() { return false; }
static bool createLaunderInvariantGroup() { return false; }

// Inline assembly
Expand Down
15 changes: 7 additions & 8 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,21 +293,19 @@ static RValue emitBinaryAtomic(CIRGenFunction &CGF, cir::AtomicFetchKind kind,

static RValue emitBinaryAtomicPost(CIRGenFunction &cgf,
cir::AtomicFetchKind atomicOpkind,
const CallExpr *e,
cir::BinOpKind binopKind) {
const CallExpr *e, cir::BinOpKind binopKind,
bool invert = false) {
mlir::Value val;
mlir::Type valueType;
clang::QualType typ = e->getType();
mlir::Value result =
makeBinaryAtomicValue(cgf, atomicOpkind, e, &val, &valueType);
clang::CIRGen::CIRGenBuilderTy &builder = cgf.getBuilder();
result = builder.create<cir::BinOp>(result.getLoc(), binopKind, result, val);
if (invert)
result = builder.create<cir::UnaryOp>(result.getLoc(),
cir::UnaryOpKind::Not, result);
result = emitFromInt(cgf, result, typ, valueType);
// FIXME: Some callers of this function expect the result to be inverted,
// which would need invert flag passed in and do the inversion here like
// traditional clang code gen does. When we implment those caller builtins
// we should implement the inversion here.
assert(!MissingFeatures::emitBinaryAtomicPostHasInvert());
return RValue::get(result);
}

Expand Down Expand Up @@ -1841,7 +1839,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__sync_nand_and_fetch_4:
case Builtin::BI__sync_nand_and_fetch_8:
case Builtin::BI__sync_nand_and_fetch_16:
llvm_unreachable("BI__sync_nand_and_fetch like NYI");
return emitBinaryAtomicPost(*this, cir::AtomicFetchKind::Nand, E,
cir::BinOpKind::And, true);

case Builtin::BI__sync_val_compare_and_swap_1:
case Builtin::BI__sync_val_compare_and_swap_2:
Expand Down
Loading
Loading