Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: I50d288ab82c2268956dd8878fea3e98ddc5d310e
  • Loading branch information
Jenkins committed Sep 7, 2024
2 parents b8605d0 + a0c43be commit 487d0fd
Show file tree
Hide file tree
Showing 36 changed files with 748 additions and 367 deletions.
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/OpenMPKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define LLVM_CLANG_BASIC_OPENMPKINDS_H

#include "clang/Basic/LangOptions.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Frontend/OpenMP/OMPConstants.h"

Expand Down Expand Up @@ -389,5 +390,9 @@ bool isOpenMPInformationalDirective(OpenMPDirectiveKind DKind);
bool isOpenMPCapturingDirective(OpenMPDirectiveKind DKind);
}

template <>
struct llvm::enum_iteration_traits<clang::OpenMPDefaultmapClauseKind> {
static constexpr bool is_iterable = true;
};
#endif

6 changes: 6 additions & 0 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,10 @@ bool Compiler<Emitter>::VisitCXXStdInitializerListExpr(

if (!this->visit(SubExpr))
return false;
if (!this->emitConstUint8(0, E))
return false;
if (!this->emitArrayElemPtrPopUint8(E))
return false;
if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
return false;

Expand All @@ -3334,6 +3338,8 @@ bool Compiler<Emitter>::VisitCXXStdInitializerListExpr(

if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
return false;
if (!this->emitExpandPtr(E))
return false;
if (!this->emitConst(static_cast<APSInt>(ArrayType->getSize()), PT_Uint64, E))
return false;
if (!this->emitArrayElemPtrPop(PT_Uint64, E))
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,9 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
template <PrimType Name, class T = typename PrimConv<Name>::T>
bool AddOffset(InterpState &S, CodePtr OpPC) {
const T &Offset = S.Stk.pop<T>();
const Pointer &Ptr = S.Stk.pop<Pointer>();
Pointer Ptr = S.Stk.pop<Pointer>();
if (Ptr.isBlockPointer())
Ptr = Ptr.expand();
return OffsetHelper<T, ArithOp::Add>(S, OpPC, Offset, Ptr);
}

Expand Down
5 changes: 3 additions & 2 deletions clang/lib/AST/ByteCode/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,8 @@ class Pointer {
if (asBlockPointer().Base != Offset)
return *this;

// If at base, point to an array of base types.
if (isRoot())
return Pointer(Pointee, RootPtrMark, 0);
return Pointer(Pointee, asBlockPointer().Base, asBlockPointer().Base);

// Step into the containing array, if inside one.
unsigned Next = asBlockPointer().Base - getInlineDesc()->Offset;
Expand Down Expand Up @@ -711,8 +710,10 @@ class Pointer {

/// Returns the embedded descriptor preceding a field.
InlineDescriptor *getInlineDesc() const {
assert(isBlockPointer());
assert(asBlockPointer().Base != sizeof(GlobalInlineDescriptor));
assert(asBlockPointer().Base <= asBlockPointer().Pointee->getSize());
assert(asBlockPointer().Base >= sizeof(InlineDescriptor));
return getDescriptor(asBlockPointer().Base);
}

Expand Down
10 changes: 3 additions & 7 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,16 +1125,12 @@ unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(

unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
ArrayRef<const ValueDecl *> Declarations) {
unsigned TotalNum = 0u;
llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
llvm::SmallPtrSet<const ValueDecl *, 8> UniqueDecls;
for (const ValueDecl *D : Declarations) {
const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
if (Cache.count(VD))
continue;
++TotalNum;
Cache.insert(VD);
UniqueDecls.insert(VD);
}
return TotalNum;
return UniqueDecls.size();
}

OMPMapClause *OMPMapClause::Create(
Expand Down
109 changes: 47 additions & 62 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "llvm/ADT/PointerEmbeddedInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Frontend/OpenMP/OMPAssume.h"
Expand Down Expand Up @@ -3707,19 +3708,26 @@ getMapClauseKindFromModifier(OpenMPDefaultmapClauseModifier M,
}

namespace {
struct VariableImplicitInfo {
static const unsigned MapKindNum = OMPC_MAP_unknown;
static const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_unknown + 1;

llvm::SetVector<Expr *> Privates;
llvm::SetVector<Expr *> Firstprivates;
llvm::SetVector<Expr *> Mappings[DefaultmapKindNum][MapKindNum];
llvm::SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
MapModifiers[DefaultmapKindNum];
};

class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
DSAStackTy *Stack;
Sema &SemaRef;
OpenMPDirectiveKind DKind = OMPD_unknown;
bool ErrorFound = false;
bool TryCaptureCXXThisMembers = false;
CapturedStmt *CS = nullptr;
const static unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_unknown + 1;
llvm::SmallVector<Expr *, 4> ImplicitFirstprivate;
llvm::SmallVector<Expr *, 4> ImplicitPrivate;
llvm::SmallVector<Expr *, 4> ImplicitMap[DefaultmapKindNum][OMPC_MAP_delete];
llvm::SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
ImplicitMapModifier[DefaultmapKindNum];

VariableImplicitInfo ImpInfo;
SemaOpenMP::VarsWithInheritedDSAType VarsWithInheritedDSA;
llvm::SmallDenseSet<const ValueDecl *, 4> ImplicitDeclarations;

Expand Down Expand Up @@ -3871,9 +3879,9 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
bool IsModifierPresent = Stack->getDefaultmapModifier(ClauseKind) ==
OMPC_DEFAULTMAP_MODIFIER_present;
if (IsModifierPresent) {
if (!llvm::is_contained(ImplicitMapModifier[ClauseKind],
if (!llvm::is_contained(ImpInfo.MapModifiers[ClauseKind],
OMPC_MAP_MODIFIER_present)) {
ImplicitMapModifier[ClauseKind].push_back(
ImpInfo.MapModifiers[ClauseKind].push_back(
OMPC_MAP_MODIFIER_present);
}
}
Expand Down Expand Up @@ -3913,13 +3921,13 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
IsFirstprivate =
IsFirstprivate || (Stack->mustBeFirstprivate(ClauseKind) && !Res);
if (IsFirstprivate) {
ImplicitFirstprivate.emplace_back(E);
ImpInfo.Firstprivates.insert(E);
} else {
OpenMPDefaultmapClauseModifier M =
Stack->getDefaultmapModifier(ClauseKind);
OpenMPMapClauseKind Kind = getMapClauseKindFromModifier(
M, ClauseKind == OMPC_DEFAULTMAP_aggregate || Res);
ImplicitMap[ClauseKind][Kind].emplace_back(E);
ImpInfo.Mappings[ClauseKind][Kind].insert(E);
}
return;
}
Expand Down Expand Up @@ -3956,9 +3964,9 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
!DVar.RefExpr)) &&
!Stack->isLoopControlVariable(VD).first) {
if (Stack->getDefaultDSA() == DSA_private)
ImplicitPrivate.push_back(E);
ImpInfo.Privates.insert(E);
else
ImplicitFirstprivate.push_back(E);
ImpInfo.Firstprivates.insert(E);
return;
}

Expand Down Expand Up @@ -4015,7 +4023,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
getVariableCategoryFromDecl(SemaRef.getLangOpts(), FD);
OpenMPMapClauseKind Kind = getMapClauseKindFromModifier(
Modifier, /*IsAggregateOrDeclareTarget=*/true);
ImplicitMap[ClauseKind][Kind].emplace_back(E);
ImpInfo.Mappings[ClauseKind][Kind].insert(E);
return;
}

Expand Down Expand Up @@ -4050,7 +4058,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
// expression.
// TODO: try to make it firstprivate.
if (DVar.CKind != OMPC_unknown)
ImplicitFirstprivate.push_back(E);
ImpInfo.Firstprivates.insert(E);
}
return;
}
Expand Down Expand Up @@ -4172,18 +4180,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
}
}
bool isErrorFound() const { return ErrorFound; }
ArrayRef<Expr *> getImplicitFirstprivate() const {
return ImplicitFirstprivate;
}
ArrayRef<Expr *> getImplicitPrivate() const { return ImplicitPrivate; }
ArrayRef<Expr *> getImplicitMap(OpenMPDefaultmapClauseKind DK,
OpenMPMapClauseKind MK) const {
return ImplicitMap[DK][MK];
}
ArrayRef<OpenMPMapModifierKind>
getImplicitMapModifier(OpenMPDefaultmapClauseKind Kind) const {
return ImplicitMapModifier[Kind];
}
const VariableImplicitInfo &getImplicitInfo() const { return ImpInfo; }
const SemaOpenMP::VarsWithInheritedDSAType &getVarsWithInheritedDSA() const {
return VarsWithInheritedDSA;
}
Expand Down Expand Up @@ -6509,69 +6506,56 @@ StmtResult SemaOpenMP::ActOnOpenMPExecutableDirective(
return StmtError();
// Generate list of implicitly defined firstprivate variables.
VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA();
VariableImplicitInfo ImpInfo = DSAChecker.getImplicitInfo();

SmallVector<Expr *, 4> ImplicitFirstprivates(
DSAChecker.getImplicitFirstprivate());
SmallVector<Expr *, 4> ImplicitPrivates(DSAChecker.getImplicitPrivate());
const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_unknown + 1;
SmallVector<Expr *, 4> ImplicitMaps[DefaultmapKindNum][OMPC_MAP_delete];
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
ImplicitMapModifiers[DefaultmapKindNum];
SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers>
ImplicitMapModifiersLoc[DefaultmapKindNum];
ImplicitMapModifiersLoc[VariableImplicitInfo::DefaultmapKindNum];
// Get the original location of present modifier from Defaultmap clause.
SourceLocation PresentModifierLocs[DefaultmapKindNum];
SourceLocation PresentModifierLocs[VariableImplicitInfo::DefaultmapKindNum];
for (OMPClause *C : Clauses) {
if (auto *DMC = dyn_cast<OMPDefaultmapClause>(C))
if (DMC->getDefaultmapModifier() == OMPC_DEFAULTMAP_MODIFIER_present)
PresentModifierLocs[DMC->getDefaultmapKind()] =
DMC->getDefaultmapModifierLoc();
}
for (unsigned VC = 0; VC < DefaultmapKindNum; ++VC) {
auto K = static_cast<OpenMPDefaultmapClauseKind>(VC);
for (unsigned I = 0; I < OMPC_MAP_delete; ++I) {
ArrayRef<Expr *> ImplicitMap =
DSAChecker.getImplicitMap(K, static_cast<OpenMPMapClauseKind>(I));
ImplicitMaps[VC][I].append(ImplicitMap.begin(), ImplicitMap.end());
}
ArrayRef<OpenMPMapModifierKind> ImplicitModifier =
DSAChecker.getImplicitMapModifier(K);
ImplicitMapModifiers[VC].append(ImplicitModifier.begin(),
ImplicitModifier.end());
std::fill_n(std::back_inserter(ImplicitMapModifiersLoc[VC]),
ImplicitModifier.size(), PresentModifierLocs[VC]);

for (OpenMPDefaultmapClauseKind K :
llvm::enum_seq_inclusive<OpenMPDefaultmapClauseKind>(
OpenMPDefaultmapClauseKind(), OMPC_DEFAULTMAP_unknown)) {
std::fill_n(std::back_inserter(ImplicitMapModifiersLoc[K]),
ImpInfo.MapModifiers[K].size(), PresentModifierLocs[K]);
}
// Mark taskgroup task_reduction descriptors as implicitly firstprivate.
for (OMPClause *C : Clauses) {
if (auto *IRC = dyn_cast<OMPInReductionClause>(C)) {
for (Expr *E : IRC->taskgroup_descriptors())
if (E)
ImplicitFirstprivates.emplace_back(E);
ImpInfo.Firstprivates.insert(E);
}
// OpenMP 5.0, 2.10.1 task Construct
// [detach clause]... The event-handle will be considered as if it was
// specified on a firstprivate clause.
if (auto *DC = dyn_cast<OMPDetachClause>(C))
ImplicitFirstprivates.push_back(DC->getEventHandler());
ImpInfo.Firstprivates.insert(DC->getEventHandler());
}
if (!ImplicitFirstprivates.empty()) {
if (!ImpInfo.Firstprivates.empty()) {
if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause(
ImplicitFirstprivates, SourceLocation(), SourceLocation(),
SourceLocation())) {
ImpInfo.Firstprivates.getArrayRef(), SourceLocation(),
SourceLocation(), SourceLocation())) {
ClausesWithImplicit.push_back(Implicit);
ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() !=
ImplicitFirstprivates.size();
ImpInfo.Firstprivates.size();
} else {
ErrorFound = true;
}
}
if (!ImplicitPrivates.empty()) {
if (OMPClause *Implicit =
ActOnOpenMPPrivateClause(ImplicitPrivates, SourceLocation(),
SourceLocation(), SourceLocation())) {
if (!ImpInfo.Privates.empty()) {
if (OMPClause *Implicit = ActOnOpenMPPrivateClause(
ImpInfo.Privates.getArrayRef(), SourceLocation(),
SourceLocation(), SourceLocation())) {
ClausesWithImplicit.push_back(Implicit);
ErrorFound = cast<OMPPrivateClause>(Implicit)->varlist_size() !=
ImplicitPrivates.size();
ImpInfo.Privates.size();
} else {
ErrorFound = true;
}
Expand Down Expand Up @@ -6601,17 +6585,18 @@ StmtResult SemaOpenMP::ActOnOpenMPExecutableDirective(
ClausesWithImplicit.emplace_back(Implicit);
}
}
for (unsigned I = 0, E = DefaultmapKindNum; I < E; ++I) {
for (unsigned I = 0; I < VariableImplicitInfo::DefaultmapKindNum; ++I) {
int ClauseKindCnt = -1;
for (ArrayRef<Expr *> ImplicitMap : ImplicitMaps[I]) {
for (unsigned J = 0; J < VariableImplicitInfo::MapKindNum; ++J) {
ArrayRef<Expr *> ImplicitMap = ImpInfo.Mappings[I][J].getArrayRef();
++ClauseKindCnt;
if (ImplicitMap.empty())
continue;
CXXScopeSpec MapperIdScopeSpec;
DeclarationNameInfo MapperId;
auto K = static_cast<OpenMPMapClauseKind>(ClauseKindCnt);
if (OMPClause *Implicit = ActOnOpenMPMapClause(
nullptr, ImplicitMapModifiers[I], ImplicitMapModifiersLoc[I],
nullptr, ImpInfo.MapModifiers[I], ImplicitMapModifiersLoc[I],
MapperIdScopeSpec, MapperId, K, /*IsMapTypeImplicit=*/true,
SourceLocation(), SourceLocation(), ImplicitMap,
OMPVarListLocTy())) {
Expand Down
55 changes: 55 additions & 0 deletions clang/test/AST/ByteCode/initializer_list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++20 -verify=expected,both %s
// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref,both %s

// both-no-diagnostics

namespace std {
typedef decltype(sizeof(int)) size_t;
template <class _E>
class initializer_list
{
const _E* __begin_;
size_t __size_;

initializer_list(const _E* __b, size_t __s)
: __begin_(__b),
__size_(__s)
{}

public:
typedef _E value_type;
typedef const _E& reference;
typedef const _E& const_reference;
typedef size_t size_type;

typedef const _E* iterator;
typedef const _E* const_iterator;

constexpr initializer_list() : __begin_(nullptr), __size_(0) {}

constexpr size_t size() const {return __size_;}
constexpr const _E* begin() const {return __begin_;}
constexpr const _E* end() const {return __begin_ + __size_;}
};
}

class Thing {
public:
int m = 12;
constexpr Thing(int m) : m(m) {}
constexpr bool operator==(const Thing& that) const {
return this->m == that.m;
}
};

constexpr bool is_contained(std::initializer_list<Thing> Set, const Thing &Element) {
return (*Set.begin() == Element);
}

constexpr int foo() {
const Thing a{12};
const Thing b{14};
return is_contained({a}, b);
}

static_assert(foo() == 0);
9 changes: 9 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,12 @@ add_proxy_header_library(
libc.include.signal
)

add_proxy_header_library(
stack_t
HDRS
stack_t.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.stack_t
libc.include.signal
)

Loading

0 comments on commit 487d0fd

Please sign in to comment.