Skip to content

Commit bc2d824

Browse files
Erich Keaneabhinavgaba
Erich Keane
authored andcommitted
Merge from 'main' to 'sycl-web' (intel#12)
Resolved by reverting: eba69b5 Reimplement __builtin_unique_stable_name- And applying: 70281ea [SYCL] Unique stable name rebase (intel#3835) CONFLICT (content): Merge conflict in clang/lib/Sema/SemaTemplateInstantiateDecl.cpp CONFLICT (content): Merge conflict in clang/lib/Sema/SemaSYCL.cpp CONFLICT (content): Merge conflict in clang/lib/Sema/SemaExpr.cpp CONFLICT (content): Merge conflict in clang/lib/Parse/ParseExpr.cpp CONFLICT (content): Merge conflict in clang/lib/Basic/IdentifierTable.cpp CONFLICT (content): Merge conflict in clang/lib/AST/ItaniumMangle.cpp CONFLICT (content): Merge conflict in clang/include/clang/Sema/Sema.h CONFLICT (content): Merge conflict in clang/include/clang/Parse/Parser.h CONFLICT (content): Merge conflict in clang/include/clang/Basic/TokenKinds.def CONFLICT (content): Merge conflict in clang/include/clang/AST/Mangle.h CONFLICT (content): Merge conflict in clang/docs/LanguageExtensions.rst
2 parents 8bd8d76 + eba69b5 commit bc2d824

File tree

1,697 files changed

+100048
-83666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,697 files changed

+100048
-83666
lines changed

clang-tools-extra/clangd/ClangdServer.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
7575
const CanonicalIncludes &CanonIncludes) override {
7676
if (FIndex)
7777
FIndex->updatePreamble(Path, Version, Ctx, std::move(PP), CanonIncludes);
78-
if (ServerCallbacks)
79-
ServerCallbacks->onSemanticsMaybeChanged(Path);
8078
}
8179

8280
void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override {
@@ -105,6 +103,11 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
105103
ServerCallbacks->onFileUpdated(File, Status);
106104
}
107105

106+
void onPreamblePublished(PathRef File) override {
107+
if (ServerCallbacks)
108+
ServerCallbacks->onSemanticsMaybeChanged(File);
109+
}
110+
108111
private:
109112
FileIndex *FIndex;
110113
ClangdServer::Callbacks *ServerCallbacks;

clang-tools-extra/clangd/TUScheduler.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ void PreambleThread::build(Request Req) {
909909
ASTPeer.updatePreamble(std::move(Req.CI), std::move(Req.Inputs),
910910
LatestBuild, std::move(Req.CIDiags),
911911
std::move(Req.WantDiags));
912+
Callbacks.onPreamblePublished(FileName);
912913
});
913914

914915
if (!LatestBuild || Inputs.ForceRebuild) {

clang-tools-extra/clangd/TUScheduler.h

+5
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ class ParsingCallbacks {
169169

170170
/// Called whenever the TU status is updated.
171171
virtual void onFileUpdated(PathRef File, const TUStatus &Status) {}
172+
173+
/// Preamble for the TU have changed. This might imply new semantics (e.g.
174+
/// different highlightings). Any actions on the file are guranteed to see new
175+
/// preamble after the callback.
176+
virtual void onPreamblePublished(PathRef File) {}
172177
};
173178

174179
/// Handles running tasks for ClangdServer and managing the resources (e.g.,

clang/cmake/caches/Fuchsia-stage2.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ if(FUCHSIA_SDK)
145145
set(FUCHSIA_x86_64-unknown-fuchsia_NAME x64)
146146
set(FUCHSIA_riscv64-unknown-fuchsia_NAME riscv64)
147147
foreach(target i386-unknown-fuchsia;x86_64-unknown-fuchsia;aarch64-unknown-fuchsia;riscv64-unknown-fuchsia)
148-
set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} -I${FUCHSIA_SDK}/pkg/fdio/include")
148+
set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target} -I${FUCHSIA_SDK}/pkg/sync/include -I${FUCHSIA_SDK}/pkg/fdio/include")
149149
set(FUCHSIA_${target}_LINKER_FLAGS "-L${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/lib")
150150
set(FUCHSIA_${target}_SYSROOT "${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/sysroot")
151151
endforeach()

clang/docs/LanguageExtensions.rst

+29-19
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ correctly in any circumstances. It can be used if:
17941794
metaprogramming algorithms to be able to specify/detect types generically.
17951795
17961796
- the generated kernel binary does not contain indirect calls because they
1797-
are eliminated using compiler optimizations e.g. devirtualization.
1797+
are eliminated using compiler optimizations e.g. devirtualization.
17981798
17991799
- the selected target supports the function pointer like functionality e.g.
18001800
most CPU targets.
@@ -2404,29 +2404,39 @@ argument.
24042404
int *pb =__builtin_preserve_access_index(&v->c[3].b);
24052405
__builtin_preserve_access_index(v->j);
24062406
2407-
``__builtin_unique_stable_name``
2408-
--------------------------------
2407+
``__builtin_sycl_unique_stable_name``
2408+
-------------------------------------
24092409
2410-
``__builtin_unique_stable_name()`` is a builtin that takes a type or expression and
2411-
produces a string literal containing a unique name for the type (or type of the
2412-
expression) that is stable across split compilations.
2410+
``__builtin_sycl_unique_stable_name()`` is a builtin that takes a type and
2411+
produces a string literal containing a unique name for the type that is stable
2412+
across split compilations, mainly to support SYCL/Data Parallel C++ language.
24132413
24142414
In cases where the split compilation needs to share a unique token for a type
24152415
across the boundary (such as in an offloading situation), this name can be used
2416-
for lookup purposes.
2416+
for lookup purposes, such as in the SYCL Integration Header.
2417+
2418+
The value of this builtin is computed entirely at compile time, so it can be
2419+
used in constant expressions. This value encodes lambda functions based on a
2420+
stable numbering order in which they appear in their local declaration contexts.
2421+
Once this builtin is evaluated in a constexpr context, it is erroneous to use
2422+
it in an instantiation which changes its value.
2423+
2424+
In order to produce the unique name, the current implementation of the bultin
2425+
uses Itanium mangling even if the host compilation uses a different name
2426+
mangling scheme at runtime. The mangler marks all the lambdas required to name
2427+
the SYCL kernel and emits a stable local ordering of the respective lambdas,
2428+
starting from ``10000``. The initial value of ``10000`` serves as an obvious
2429+
differentiator from ordinary lambda mangling numbers but does not serve any
2430+
other purpose and may change in the future. The resulting pattern is
2431+
demanglable. When non-lambda types are passed to the builtin, the mangler emits
2432+
their usual pattern without any special treatment.
2433+
2434+
**Syntax**:
24172435
2418-
This builtin is superior to RTTI for this purpose for two reasons. First, this
2419-
value is computed entirely at compile time, so it can be used in constant
2420-
expressions. Second, this value encodes lambda functions based on line-number
2421-
rather than the order in which it appears in a function. This is valuable
2422-
because it is stable in cases where an unrelated lambda is introduced
2423-
conditionally in the same function.
2436+
.. code-block:: c
24242437
2425-
The current implementation of this builtin uses a slightly modified Itanium
2426-
Mangler to produce the unique name. The lambda ordinal is replaced with one or
2427-
more line/column pairs in the format ``LINE->COL``, separated with a ``~``
2428-
character. Typically, only one pair will be included, however in the case of
2429-
macro expansions the entire macro expansion stack is expressed.
2438+
// Computes a unique stable name for the given type.
2439+
constexpr const char * __builtin_sycl_unique_stable_name( type-id );
24302440
24312441
Multiprecision Arithmetic Builtins
24322442
----------------------------------
@@ -2622,7 +2632,7 @@ Guaranteed inlined copy
26222632
``__builtin_memcpy_inline`` has been designed as a building block for efficient
26232633
``memcpy`` implementations. It is identical to ``__builtin_memcpy`` but also
26242634
guarantees not to call any external functions. See LLVM IR `llvm.memcpy.inline
2625-
<https://llvm.org/docs/LangRef.html#llvm-memcpy-inline-intrinsic>`_ intrinsic
2635+
<https://llvm.org/docs/LangRef.html#llvm-memcpy-inline-intrinsic>`_ intrinsic
26262636
for more information.
26272637
26282638
This is useful to implement a custom version of ``memcpy``, implement a

clang/include/clang/AST/ASTContext.h

+28
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class DynTypedNode;
103103
class DynTypedNodeList;
104104
class Expr;
105105
class GlobalDecl;
106+
class ItaniumMangleContext;
106107
class MangleContext;
107108
class MangleNumberingContext;
108109
class MaterializeTemporaryExpr;
@@ -2360,6 +2361,12 @@ class ASTContext : public RefCountedBase<ASTContext> {
23602361
/// If \p T is null pointer, assume the target in ASTContext.
23612362
MangleContext *createMangleContext(const TargetInfo *T = nullptr);
23622363

2364+
/// Creates a device mangle context to correctly mangle lambdas in a mixed
2365+
/// architecture compile by setting the lambda mangling number source to the
2366+
/// DeviceLambdaManglingNumber. Currently this asserts that the TargetInfo
2367+
/// (from the AuxTargetInfo) is a an itanium target.
2368+
MangleContext *createDeviceMangleContext(const TargetInfo &T);
2369+
23632370
void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
23642371
SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const;
23652372

@@ -3163,10 +3170,31 @@ OPT_LIST(V)
31633170

31643171
StringRef getCUIDHash() const;
31653172

3173+
void AddSYCLKernelNamingDecl(const CXXRecordDecl *RD);
3174+
bool IsSYCLKernelNamingDecl(const NamedDecl *RD) const;
3175+
unsigned GetSYCLKernelNamingIndex(const NamedDecl *RD);
3176+
/// A SourceLocation to store whether we have evaluated a kernel name already,
3177+
/// and where it happened. If so, we need to diagnose an illegal use of the
3178+
/// builtin.
3179+
llvm::MapVector<const SYCLUniqueStableNameExpr *, std::string>
3180+
SYCLUniqueStableNameEvaluatedValues;
3181+
31663182
private:
31673183
/// All OMPTraitInfo objects live in this collection, one per
31683184
/// `pragma omp [begin] declare variant` directive.
31693185
SmallVector<std::unique_ptr<OMPTraitInfo>, 4> OMPTraitInfoVector;
3186+
3187+
/// A list of the (right now just lambda decls) declarations required to
3188+
/// name all the SYCL kernels in the translation unit, so that we can get the
3189+
/// correct kernel name, as well as implement
3190+
/// __builtin_sycl_unique_stable_name.
3191+
llvm::DenseMap<const DeclContext *,
3192+
llvm::SmallPtrSet<const CXXRecordDecl *, 4>>
3193+
SYCLKernelNamingTypes;
3194+
std::unique_ptr<ItaniumMangleContext> SYCLKernelFilterContext;
3195+
void FilterSYCLKernelNamingDecls(
3196+
const CXXRecordDecl *RD,
3197+
llvm::SmallVectorImpl<const CXXRecordDecl *> &Decls);
31703198
};
31713199

31723200
/// Insertion operator for diagnostics.

clang/include/clang/AST/ComputeDependence.h

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class MaterializeTemporaryExpr;
7878
class CXXFoldExpr;
7979
class TypeTraitExpr;
8080
class ConceptSpecializationExpr;
81+
class SYCLUniqueStableNameExpr;
8182
class PredefinedExpr;
8283
class CallExpr;
8384
class OffsetOfExpr;
@@ -165,6 +166,7 @@ ExprDependence computeDependence(TypeTraitExpr *E);
165166
ExprDependence computeDependence(ConceptSpecializationExpr *E,
166167
bool ValueDependent);
167168

169+
ExprDependence computeDependence(SYCLUniqueStableNameExpr *E);
168170
ExprDependence computeDependence(PredefinedExpr *E);
169171
ExprDependence computeDependence(CallExpr *E, llvm::ArrayRef<Expr *> PreArgs);
170172
ExprDependence computeDependence(OffsetOfExpr *E);

clang/include/clang/AST/Expr.h

+60-67
Original file line numberDiff line numberDiff line change
@@ -1948,17 +1948,13 @@ class StringLiteral final
19481948
/// [C99 6.4.2.2] - A predefined identifier such as __func__.
19491949
class PredefinedExpr final
19501950
: public Expr,
1951-
private llvm::TrailingObjects<PredefinedExpr, Stmt *, Expr *,
1952-
TypeSourceInfo *> {
1951+
private llvm::TrailingObjects<PredefinedExpr, Stmt *> {
19531952
friend class ASTStmtReader;
19541953
friend TrailingObjects;
19551954

19561955
// PredefinedExpr is optionally followed by a single trailing
19571956
// "Stmt *" for the predefined identifier. It is present if and only if
19581957
// hasFunctionName() is true and is always a "StringLiteral *".
1959-
// It can also be followed by a Expr* in the case of a
1960-
// __builtin_unique_stable_name with an expression, or TypeSourceInfo * if
1961-
// __builtin_unique_stable_name with a type.
19621958

19631959
public:
19641960
enum IdentKind {
@@ -1971,18 +1967,12 @@ class PredefinedExpr final
19711967
PrettyFunction,
19721968
/// The same as PrettyFunction, except that the
19731969
/// 'virtual' keyword is omitted for virtual member functions.
1974-
PrettyFunctionNoVirtual,
1975-
UniqueStableNameType,
1976-
UniqueStableNameExpr,
1970+
PrettyFunctionNoVirtual
19771971
};
19781972

19791973
private:
19801974
PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
19811975
StringLiteral *SL);
1982-
PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
1983-
TypeSourceInfo *Info);
1984-
PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
1985-
Expr *E);
19861976

19871977
explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
19881978

@@ -1995,39 +1985,10 @@ class PredefinedExpr final
19951985
*getTrailingObjects<Stmt *>() = SL;
19961986
}
19971987

1998-
void setTypeSourceInfo(TypeSourceInfo *Info) {
1999-
assert(!hasFunctionName() && getIdentKind() == UniqueStableNameType &&
2000-
"TypeSourceInfo only valid for UniqueStableName of a Type");
2001-
*getTrailingObjects<TypeSourceInfo *>() = Info;
2002-
}
2003-
2004-
void setExpr(Expr *E) {
2005-
assert(!hasFunctionName() && getIdentKind() == UniqueStableNameExpr &&
2006-
"TypeSourceInfo only valid for UniqueStableName of n Expression.");
2007-
*getTrailingObjects<Expr *>() = E;
2008-
}
2009-
2010-
size_t numTrailingObjects(OverloadToken<Stmt *>) const {
2011-
return hasFunctionName();
2012-
}
2013-
2014-
size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
2015-
return getIdentKind() == UniqueStableNameType && !hasFunctionName();
2016-
}
2017-
size_t numTrailingObjects(OverloadToken<Expr *>) const {
2018-
return getIdentKind() == UniqueStableNameExpr && !hasFunctionName();
2019-
}
2020-
20211988
public:
20221989
/// Create a PredefinedExpr.
20231990
static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
20241991
QualType FNTy, IdentKind IK, StringLiteral *SL);
2025-
static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
2026-
QualType FNTy, IdentKind IK, StringLiteral *SL,
2027-
TypeSourceInfo *Info);
2028-
static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
2029-
QualType FNTy, IdentKind IK, StringLiteral *SL,
2030-
Expr *E);
20311992

20321993
/// Create an empty PredefinedExpr.
20331994
static PredefinedExpr *CreateEmpty(const ASTContext &Ctx,
@@ -2052,38 +2013,12 @@ class PredefinedExpr final
20522013
: nullptr;
20532014
}
20542015

2055-
TypeSourceInfo *getTypeSourceInfo() {
2056-
assert(!hasFunctionName() && getIdentKind() == UniqueStableNameType &&
2057-
"TypeSourceInfo only valid for UniqueStableName of a Type");
2058-
return *getTrailingObjects<TypeSourceInfo *>();
2059-
}
2060-
2061-
const TypeSourceInfo *getTypeSourceInfo() const {
2062-
assert(!hasFunctionName() && getIdentKind() == UniqueStableNameType &&
2063-
"TypeSourceInfo only valid for UniqueStableName of a Type");
2064-
return *getTrailingObjects<TypeSourceInfo *>();
2065-
}
2066-
2067-
Expr *getExpr() {
2068-
assert(!hasFunctionName() && getIdentKind() == UniqueStableNameExpr &&
2069-
"TypeSourceInfo only valid for UniqueStableName of n Expression.");
2070-
return *getTrailingObjects<Expr *>();
2071-
}
2072-
2073-
const Expr *getExpr() const {
2074-
assert(!hasFunctionName() && getIdentKind() == UniqueStableNameExpr &&
2075-
"TypeSourceInfo only valid for UniqueStableName of n Expression.");
2076-
return *getTrailingObjects<Expr *>();
2077-
}
2078-
20792016
static StringRef getIdentKindName(IdentKind IK);
20802017
StringRef getIdentKindName() const {
20812018
return getIdentKindName(getIdentKind());
20822019
}
20832020

20842021
static std::string ComputeName(IdentKind IK, const Decl *CurrentDecl);
2085-
static std::string ComputeName(ASTContext &Context, IdentKind IK,
2086-
const QualType Ty);
20872022

20882023
SourceLocation getBeginLoc() const { return getLocation(); }
20892024
SourceLocation getEndLoc() const { return getLocation(); }
@@ -2104,6 +2039,64 @@ class PredefinedExpr final
21042039
}
21052040
};
21062041

2042+
// This represents a use of the __builtin_sycl_unique_stable_name, which takes a
2043+
// type-id, and at CodeGen time emits a unique string representation of the
2044+
// type in a way that permits us to properly encode information about the SYCL
2045+
// kernels.
2046+
class SYCLUniqueStableNameExpr final : public Expr {
2047+
friend class ASTStmtReader;
2048+
SourceLocation OpLoc, LParen, RParen;
2049+
TypeSourceInfo *TypeInfo;
2050+
2051+
SYCLUniqueStableNameExpr(EmptyShell Empty, QualType ResultTy);
2052+
SYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen,
2053+
SourceLocation RParen, QualType ResultTy,
2054+
TypeSourceInfo *TSI);
2055+
2056+
void setTypeSourceInfo(TypeSourceInfo *Ty) { TypeInfo = Ty; }
2057+
2058+
void setLocation(SourceLocation L) { OpLoc = L; }
2059+
void setLParenLocation(SourceLocation L) { LParen = L; }
2060+
void setRParenLocation(SourceLocation L) { RParen = L; }
2061+
2062+
public:
2063+
TypeSourceInfo *getTypeSourceInfo() { return TypeInfo; }
2064+
2065+
const TypeSourceInfo *getTypeSourceInfo() const { return TypeInfo; }
2066+
2067+
static SYCLUniqueStableNameExpr *
2068+
Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen,
2069+
SourceLocation RParen, TypeSourceInfo *TSI);
2070+
2071+
static SYCLUniqueStableNameExpr *CreateEmpty(const ASTContext &Ctx);
2072+
2073+
SourceLocation getBeginLoc() const { return getLocation(); }
2074+
SourceLocation getEndLoc() const { return RParen; }
2075+
SourceLocation getLocation() const { return OpLoc; }
2076+
SourceLocation getLParenLocation() const { return LParen; }
2077+
SourceLocation getRParenLocation() const { return RParen; }
2078+
2079+
static bool classof(const Stmt *T) {
2080+
return T->getStmtClass() == SYCLUniqueStableNameExprClass;
2081+
}
2082+
2083+
// Iterators
2084+
child_range children() {
2085+
return child_range(child_iterator(), child_iterator());
2086+
}
2087+
2088+
const_child_range children() const {
2089+
return const_child_range(const_child_iterator(), const_child_iterator());
2090+
}
2091+
2092+
// Convenience function to generate the name of the currently stored type.
2093+
std::string ComputeName(ASTContext &Context) const;
2094+
2095+
// Get the generated name of the type. Note that this only works after all
2096+
// kernels have been instantiated.
2097+
static std::string ComputeName(ASTContext &Context, QualType Ty);
2098+
};
2099+
21072100
/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This
21082101
/// AST node is only formed if full location information is requested.
21092102
class ParenExpr : public Expr {

clang/include/clang/AST/JSONNodeDumper.h

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class JSONNodeDumper
263263
void VisitBlockDecl(const BlockDecl *D);
264264

265265
void VisitDeclRefExpr(const DeclRefExpr *DRE);
266+
void VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E);
266267
void VisitPredefinedExpr(const PredefinedExpr *PE);
267268
void VisitUnaryOperator(const UnaryOperator *UO);
268269
void VisitBinaryOperator(const BinaryOperator *BO);

0 commit comments

Comments
 (0)