Skip to content

Commit 27154ac

Browse files
authored
[CIR][CIRGen] Handle __sync_nand_and_fetch (#1351)
The final part of #1273.
1 parent 4e4e4b4 commit 27154ac

File tree

3 files changed

+140
-50
lines changed

3 files changed

+140
-50
lines changed

Diff for: clang/include/clang/CIR/MissingFeatures.h

-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ struct MissingFeatures {
247247
static bool emitConstrainedFPCall() { return false; }
248248
static bool emitEmptyRecordCheck() { return false; }
249249
static bool isPPC_FP128Ty() { return false; }
250-
static bool emitBinaryAtomicPostHasInvert() { return false; }
251250
static bool createLaunderInvariantGroup() { return false; }
252251

253252
// Inline assembly

Diff for: clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,19 @@ static RValue emitBinaryAtomic(CIRGenFunction &CGF, cir::AtomicFetchKind kind,
293293

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

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

18461845
case Builtin::BI__sync_val_compare_and_swap_1:
18471846
case Builtin::BI__sync_val_compare_and_swap_2:

0 commit comments

Comments
 (0)