Skip to content

Commit 4a58284

Browse files
authored
[clang] Refactor Builtins.def to be a tablegen file (#68324)
This makes the builtins list quite a bit more verbose, but IMO this is a huge win in terms of readability.
1 parent cd7ea4e commit 4a58284

23 files changed

+5089
-1774
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6410,7 +6410,7 @@ class AtomicExpr : public Expr {
64106410
enum AtomicOp {
64116411
#define BUILTIN(ID, TYPE, ATTRS)
64126412
#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
6413-
#include "clang/Basic/Builtins.def"
6413+
#include "clang/Basic/Builtins.inc"
64146414
// Avoid trailing comma
64156415
BI_First = 0
64166416
};
@@ -6476,7 +6476,7 @@ class AtomicExpr : public Expr {
64766476
#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
64776477
case AO##ID: \
64786478
return #ID;
6479-
#include "clang/Basic/Builtins.def"
6479+
#include "clang/Basic/Builtins.inc"
64806480
}
64816481
llvm_unreachable("not an atomic operator?");
64826482
}
@@ -6505,8 +6505,8 @@ class AtomicExpr : public Expr {
65056505
}
65066506

65076507
bool isOpenCL() const {
6508-
return getOp() >= AO__opencl_atomic_init &&
6509-
getOp() <= AO__opencl_atomic_fetch_max;
6508+
return getOp() >= AO__opencl_atomic_compare_exchange_strong &&
6509+
getOp() <= AO__opencl_atomic_store;
65106510
}
65116511

65126512
SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
@@ -6531,11 +6531,14 @@ class AtomicExpr : public Expr {
65316531
/// \return empty atomic scope model if the atomic op code does not have
65326532
/// scope operand.
65336533
static std::unique_ptr<AtomicScopeModel> getScopeModel(AtomicOp Op) {
6534-
if (Op >= AO__opencl_atomic_load && Op <= AO__opencl_atomic_fetch_max)
6534+
// FIXME: Allow grouping of builtins to be able to only check >= and <=
6535+
if (Op >= AO__opencl_atomic_compare_exchange_strong &&
6536+
Op <= AO__opencl_atomic_store && Op != AO__opencl_atomic_init)
65356537
return AtomicScopeModel::create(AtomicScopeModelKind::OpenCL);
6536-
else if (Op >= AO__hip_atomic_load && Op <= AO__hip_atomic_fetch_max)
6538+
if (Op >= AO__hip_atomic_compare_exchange_strong &&
6539+
Op <= AO__hip_atomic_store)
65376540
return AtomicScopeModel::create(AtomicScopeModelKind::HIP);
6538-
else if (Op >= AO__scoped_atomic_load && Op <= AO__scoped_atomic_fetch_max)
6541+
if (Op >= AO__scoped_atomic_add_fetch && Op <= AO__scoped_atomic_xor_fetch)
65396542
return AtomicScopeModel::create(AtomicScopeModelKind::Generic);
65406543
return AtomicScopeModel::create(AtomicScopeModelKind::None);
65416544
}

0 commit comments

Comments
 (0)