Skip to content

Commit

Permalink
[clang] Refactor Builtins.def to be a tablegen file (#68324)
Browse files Browse the repository at this point in the history
This makes the builtins list quite a bit more verbose, but IMO this is a
huge win in terms of readability.
  • Loading branch information
philnik777 committed Jan 24, 2024
1 parent cd7ea4e commit 4a58284
Show file tree
Hide file tree
Showing 23 changed files with 5,089 additions and 1,774 deletions.
17 changes: 10 additions & 7 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6410,7 +6410,7 @@ class AtomicExpr : public Expr {
enum AtomicOp {
#define BUILTIN(ID, TYPE, ATTRS)
#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
#include "clang/Basic/Builtins.def"
#include "clang/Basic/Builtins.inc"
// Avoid trailing comma
BI_First = 0
};
Expand Down Expand Up @@ -6476,7 +6476,7 @@ class AtomicExpr : public Expr {
#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
case AO##ID: \
return #ID;
#include "clang/Basic/Builtins.def"
#include "clang/Basic/Builtins.inc"
}
llvm_unreachable("not an atomic operator?");
}
Expand Down Expand Up @@ -6505,8 +6505,8 @@ class AtomicExpr : public Expr {
}

bool isOpenCL() const {
return getOp() >= AO__opencl_atomic_init &&
getOp() <= AO__opencl_atomic_fetch_max;
return getOp() >= AO__opencl_atomic_compare_exchange_strong &&
getOp() <= AO__opencl_atomic_store;
}

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

0 comments on commit 4a58284

Please sign in to comment.