Skip to content

Commit 6a02e42

Browse files
committed
Merge from 'main' to 'sycl-web' (20 commits)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/BackendUtil.cpp
2 parents b21f70e + e93b5f5 commit 6a02e42

File tree

113 files changed

+1990
-465
lines changed

Some content is hidden

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

113 files changed

+1990
-465
lines changed

clang/docs/HLSL/FunctionCalls.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,23 @@ Clang Implementation
157157
of the changes in the prototype implementation are restoring Clang-3.7 code
158158
that was previously modified to its original state.
159159

160-
The implementation in clang depends on two new AST nodes and minor extensions to
161-
Clang's existing support for Objective-C write-back arguments. The goal of this
162-
design is to capture the semantic details of HLSL function calls in the AST, and
163-
minimize the amount of magic that needs to occur during IR generation.
164-
165-
The two new AST nodes are ``HLSLArrayTemporaryExpr`` and ``HLSLOutParamExpr``,
166-
which respectively represent the temporaries used for passing arrays by value
167-
and the temporaries created for function outputs.
160+
The implementation in clang adds a new non-decaying array type, a new AST node
161+
to represent output parameters, and minor extensions to Clang's existing support
162+
for Objective-C write-back arguments. The goal of this design is to capture the
163+
semantic details of HLSL function calls in the AST, and minimize the amount of
164+
magic that needs to occur during IR generation.
168165

169166
Array Temporaries
170167
-----------------
171168

172-
The ``HLSLArrayTemporaryExpr`` represents temporary values for input
173-
constant-sized array arguments. This applies for all constant-sized array
174-
arguments regardless of whether or not the parameter is constant-sized or
175-
unsized.
169+
The new ``ArrayParameterType`` is a sub-class of ``ConstantArrayType``
170+
inheriting all the behaviors and methods of the parent except that it does not
171+
decay to a pointer during overload resolution or template type deduction.
172+
173+
An argument of ``ConstantArrayType`` can be implicitly converted to an
174+
equivalent non-decayed ``ArrayParameterType`` if the underlying canonical
175+
``ConstantArrayType`` is the same. This occurs during overload resolution
176+
instead of array to pointer decay.
176177

177178
.. code-block:: c++
178179

@@ -193,7 +194,7 @@ In the example above, the following AST is generated for the call to
193194
CallExpr 'void'
194195
|-ImplicitCastExpr 'void (*)(float [4])' <FunctionToPointerDecay>
195196
| `-DeclRefExpr 'void (float [4])' lvalue Function 'SizedArray' 'void (float [4])'
196-
`-HLSLArrayTemporaryExpr 'float [4]'
197+
`-ImplicitCastExpr 'float [4]' <HLSLArrayRValue>
197198
`-DeclRefExpr 'float [4]' lvalue Var 'arr' 'float [4]'
198199
199200
In the example above, the following AST is generated for the call to
@@ -204,7 +205,7 @@ In the example above, the following AST is generated for the call to
204205
CallExpr 'void'
205206
|-ImplicitCastExpr 'void (*)(float [])' <FunctionToPointerDecay>
206207
| `-DeclRefExpr 'void (float [])' lvalue Function 'UnsizedArray' 'void (float [])'
207-
`-HLSLArrayTemporaryExpr 'float [4]'
208+
`-ImplicitCastExpr 'float [4]' <HLSLArrayRValue>
208209
`-DeclRefExpr 'float [4]' lvalue Var 'arr' 'float [4]'
209210
210211
In both of these cases the argument expression is of known array size so we can
@@ -236,7 +237,7 @@ An expected AST should be something like:
236237
CallExpr 'void'
237238
|-ImplicitCastExpr 'void (*)(float [])' <FunctionToPointerDecay>
238239
| `-DeclRefExpr 'void (float [])' lvalue Function 'UnsizedArray' 'void (float [])'
239-
`-HLSLArrayTemporaryExpr 'float [4]'
240+
`-ImplicitCastExpr 'float [4]' <HLSLArrayRValue>
240241
`-DeclRefExpr 'float [4]' lvalue Var 'arr' 'float [4]'
241242
242243
Out Parameter Temporaries

clang/include/clang/AST/ASTContext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
260260
ASTContext&>
261261
SubstTemplateTemplateParmPacks;
262262

263+
mutable llvm::ContextualFoldingSet<ArrayParameterType, ASTContext &>
264+
ArrayParameterTypes;
265+
263266
/// The set of nested name specifiers.
264267
///
265268
/// This set is managed by the NestedNameSpecifier class.
@@ -1372,6 +1375,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
13721375
/// type to the decayed type.
13731376
QualType getDecayedType(QualType Orig, QualType Decayed) const;
13741377

1378+
/// Return the uniqued reference to a specified array parameter type from the
1379+
/// original array type.
1380+
QualType getArrayParameterType(QualType Ty) const;
1381+
13751382
/// Return the uniqued reference to the atomic type for the specified
13761383
/// type.
13771384
QualType getAtomicType(QualType T) const;

clang/include/clang/AST/OperationKinds.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ CAST_OPERATION(IntToOCLSampler)
364364
// Truncate a vector type by dropping elements from the end (HLSL only).
365365
CAST_OPERATION(HLSLVectorTruncation)
366366

367+
// Non-decaying array RValue cast (HLSL only).
368+
CAST_OPERATION(HLSLArrayRValue)
369+
367370
//===- Binary Operations -------------------------------------------------===//
368371
// Operators listed in order of precedence.
369372
// Note that additions to this should also update the StmtVisitor class,

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,12 @@ DEF_TRAVERSE_TYPE(ConstantArrayType, {
993993
TRY_TO(TraverseStmt(const_cast<Expr*>(T->getSizeExpr())));
994994
})
995995

996+
DEF_TRAVERSE_TYPE(ArrayParameterType, {
997+
TRY_TO(TraverseType(T->getElementType()));
998+
if (T->getSizeExpr())
999+
TRY_TO(TraverseStmt(const_cast<Expr *>(T->getSizeExpr())));
1000+
})
1001+
9961002
DEF_TRAVERSE_TYPE(IncompleteArrayType,
9971003
{ TRY_TO(TraverseType(T->getElementType())); })
9981004

@@ -1260,6 +1266,11 @@ DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
12601266
TRY_TO(TraverseArrayTypeLocHelper(TL));
12611267
})
12621268

1269+
DEF_TRAVERSE_TYPELOC(ArrayParameterType, {
1270+
TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1271+
TRY_TO(TraverseArrayTypeLocHelper(TL));
1272+
})
1273+
12631274
DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
12641275
TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
12651276
TRY_TO(TraverseArrayTypeLocHelper(TL));

clang/include/clang/AST/Type.h

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
23002300
bool isConstantArrayType() const;
23012301
bool isIncompleteArrayType() const;
23022302
bool isVariableArrayType() const;
2303+
bool isArrayParameterType() const;
23032304
bool isDependentSizedArrayType() const;
23042305
bool isRecordType() const;
23052306
bool isClassType() const;
@@ -3344,14 +3345,15 @@ class ArrayType : public Type, public llvm::FoldingSetNode {
33443345
return T->getTypeClass() == ConstantArray ||
33453346
T->getTypeClass() == VariableArray ||
33463347
T->getTypeClass() == IncompleteArray ||
3347-
T->getTypeClass() == DependentSizedArray;
3348+
T->getTypeClass() == DependentSizedArray ||
3349+
T->getTypeClass() == ArrayParameter;
33483350
}
33493351
};
33503352

33513353
/// Represents the canonical version of C arrays with a specified constant size.
33523354
/// For example, the canonical type for 'int A[4 + 4*100]' is a
33533355
/// ConstantArrayType where the element type is 'int' and the size is 404.
3354-
class ConstantArrayType final : public ArrayType {
3356+
class ConstantArrayType : public ArrayType {
33553357
friend class ASTContext; // ASTContext creates these.
33563358

33573359
struct ExternalSize {
@@ -3392,6 +3394,19 @@ class ConstantArrayType final : public ArrayType {
33923394
const Expr *SzExpr, ArraySizeModifier SzMod,
33933395
unsigned Qual);
33943396

3397+
protected:
3398+
ConstantArrayType(TypeClass Tc, const ConstantArrayType *ATy, QualType Can)
3399+
: ArrayType(Tc, ATy->getElementType(), Can, ATy->getSizeModifier(),
3400+
ATy->getIndexTypeQualifiers().getAsOpaqueValue(), nullptr) {
3401+
ConstantArrayTypeBits.HasExternalSize =
3402+
ATy->ConstantArrayTypeBits.HasExternalSize;
3403+
if (!ConstantArrayTypeBits.HasExternalSize) {
3404+
ConstantArrayTypeBits.SizeWidth = ATy->ConstantArrayTypeBits.SizeWidth;
3405+
Size = ATy->Size;
3406+
} else
3407+
SizePtr = ATy->SizePtr;
3408+
}
3409+
33953410
public:
33963411
/// Return the constant array size as an APInt.
33973412
llvm::APInt getSize() const {
@@ -3463,7 +3478,22 @@ class ConstantArrayType final : public ArrayType {
34633478
ArraySizeModifier SizeMod, unsigned TypeQuals);
34643479

34653480
static bool classof(const Type *T) {
3466-
return T->getTypeClass() == ConstantArray;
3481+
return T->getTypeClass() == ConstantArray ||
3482+
T->getTypeClass() == ArrayParameter;
3483+
}
3484+
};
3485+
3486+
/// Represents a constant array type that does not decay to a pointer when used
3487+
/// as a function parameter.
3488+
class ArrayParameterType : public ConstantArrayType {
3489+
friend class ASTContext; // ASTContext creates these.
3490+
3491+
ArrayParameterType(const ConstantArrayType *ATy, QualType CanTy)
3492+
: ConstantArrayType(ArrayParameter, ATy, CanTy) {}
3493+
3494+
public:
3495+
static bool classof(const Type *T) {
3496+
return T->getTypeClass() == ArrayParameter;
34673497
}
34683498
};
34693499

@@ -7195,7 +7225,8 @@ inline bool QualType::isCanonicalAsParam() const {
71957225
if (T->isVariablyModifiedType() && T->hasSizedVLAType())
71967226
return false;
71977227

7198-
return !isa<FunctionType>(T) && !isa<ArrayType>(T);
7228+
return !isa<FunctionType>(T) &&
7229+
(!isa<ArrayType>(T) || isa<ArrayParameterType>(T));
71997230
}
72007231

72017232
inline bool QualType::isConstQualified() const {
@@ -7460,6 +7491,10 @@ inline bool Type::isVariableArrayType() const {
74607491
return isa<VariableArrayType>(CanonicalType);
74617492
}
74627493

7494+
inline bool Type::isArrayParameterType() const {
7495+
return isa<ArrayParameterType>(CanonicalType);
7496+
}
7497+
74637498
inline bool Type::isDependentSizedArrayType() const {
74647499
return isa<DependentSizedArrayType>(CanonicalType);
74657500
}
@@ -7841,7 +7876,7 @@ inline bool Type::isTypedefNameType() const {
78417876

78427877
/// Determines whether this type can decay to a pointer type.
78437878
inline bool Type::canDecayToPointerType() const {
7844-
return isFunctionType() || isArrayType();
7879+
return isFunctionType() || (isArrayType() && !isArrayParameterType());
78457880
}
78467881

78477882
inline bool Type::hasPointerRepresentation() const {

clang/include/clang/AST/TypeLoc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,11 @@ class ConstantArrayTypeLoc :
16111611
ConstantArrayType> {
16121612
};
16131613

1614+
/// Wrapper for source info for array parameter types.
1615+
class ArrayParameterTypeLoc
1616+
: public InheritingConcreteTypeLoc<
1617+
ConstantArrayTypeLoc, ArrayParameterTypeLoc, ArrayParameterType> {};
1618+
16141619
class IncompleteArrayTypeLoc :
16151620
public InheritingConcreteTypeLoc<ArrayTypeLoc,
16161621
IncompleteArrayTypeLoc,

clang/include/clang/AST/TypeProperties.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ let Class = ConstantArrayType in {
136136
}]>;
137137
}
138138

139+
let Class = ArrayParameterType in {
140+
def : Creator<[{ return ctx.getAdjustedParameterType(
141+
ctx.getConstantArrayType(elementType,sizeValue,
142+
size,sizeModifier,
143+
indexQualifiers.getCVRQualifiers())); }]>;
144+
}
145+
139146
let Class = IncompleteArrayType in {
140147
def : Creator<[{
141148
return ctx.getIncompleteArrayType(elementType, sizeModifier,

clang/include/clang/Basic/TypeNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def ConstantArrayType : TypeNode<ArrayType>;
6464
def IncompleteArrayType : TypeNode<ArrayType>;
6565
def VariableArrayType : TypeNode<ArrayType>;
6666
def DependentSizedArrayType : TypeNode<ArrayType>, AlwaysDependent;
67+
def ArrayParameterType : TypeNode<ConstantArrayType>;
6768
def DependentSizedExtVectorType : TypeNode<Type>, AlwaysDependent;
6869
def DependentAddressSpaceType : TypeNode<Type>, AlwaysDependent;
6970
def VectorType : TypeNode<Type>;

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8723,6 +8723,7 @@ def _SLASH_Fi : CLCompileJoined<"Fi">,
87238723
def _SLASH_Fo : CLCompileJoined<"Fo">,
87248724
HelpText<"Set output object file (with /c)">,
87258725
MetaVarName<"<file or dir/>">;
8726+
def _SLASH_Fo_COLON : CLCompileJoined<"Fo:">, Alias<_SLASH_Fo>;
87268727
def _SLASH_guard : CLJoined<"guard:">,
87278728
HelpText<"Enable Control Flow Guard with /guard:cf, or only the table with /guard:cf,nochecks. "
87288729
"Enable EH Continuation Guard with /guard:ehcont">;

clang/include/clang/Sema/Overload.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ class Sema;
198198
/// HLSL vector truncation.
199199
ICK_HLSL_Vector_Truncation,
200200

201+
/// HLSL non-decaying array rvalue cast.
202+
ICK_HLSL_Array_RValue,
203+
201204
/// The number of conversion kinds
202205
ICK_Num_Conversion_Kinds,
203206
};

clang/include/clang/Sema/Sema.h

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "clang/AST/NSAPI.h"
3434
#include "clang/AST/PrettyPrinter.h"
3535
#include "clang/AST/StmtCXX.h"
36-
#include "clang/AST/StmtOpenACC.h"
3736
#include "clang/AST/StmtOpenMP.h"
3837
#include "clang/AST/TypeLoc.h"
3938
#include "clang/AST/TypeOrdering.h"
@@ -43,7 +42,6 @@
4342
#include "clang/Basic/DiagnosticSema.h"
4443
#include "clang/Basic/ExpressionTraits.h"
4544
#include "clang/Basic/Module.h"
46-
#include "clang/Basic/OpenACCKinds.h"
4745
#include "clang/Basic/OpenCLOptions.h"
4846
#include "clang/Basic/OpenMPKinds.h"
4947
#include "clang/Basic/PragmaKinds.h"
@@ -184,6 +182,7 @@ class Preprocessor;
184182
class PseudoDestructorTypeStorage;
185183
class PseudoObjectExpr;
186184
class QualType;
185+
class SemaOpenACC;
187186
class StandardConversionSequence;
188187
class Stmt;
189188
class StringLiteral;
@@ -654,9 +653,8 @@ class Sema final {
654653
// 37. Name Lookup for RISC-V Vector Intrinsic (SemaRISCVVectorLookup.cpp)
655654
// 38. CUDA (SemaCUDA.cpp)
656655
// 39. HLSL Constructs (SemaHLSL.cpp)
657-
// 40. OpenACC Constructs (SemaOpenACC.cpp)
658-
// 41. OpenMP Directives and Clauses (SemaOpenMP.cpp)
659-
// 42. SYCL Constructs (SemaSYCL.cpp)
656+
// 40. OpenMP Directives and Clauses (SemaOpenMP.cpp)
657+
// 41. SYCL Constructs (SemaSYCL.cpp)
660658

661659
/// \name Semantic Analysis
662660
/// Implementations are in Sema.cpp
@@ -1407,6 +1405,11 @@ class Sema final {
14071405
/// CurContext - This is the current declaration context of parsing.
14081406
DeclContext *CurContext;
14091407

1408+
SemaOpenACC &OpenACC() {
1409+
assert(OpenACCPtr);
1410+
return *OpenACCPtr;
1411+
}
1412+
14101413
protected:
14111414
friend class Parser;
14121415
friend class InitializationSequence;
@@ -1437,6 +1440,8 @@ class Sema final {
14371440

14381441
mutable IdentifierInfo *Ident_super;
14391442

1443+
std::unique_ptr<SemaOpenACC> OpenACCPtr;
1444+
14401445
///@}
14411446

14421447
//
@@ -13808,56 +13813,6 @@ class Sema final {
1380813813
//
1380913814
//
1381013815

13811-
/// \name OpenACC Constructs
13812-
/// Implementations are in SemaOpenACC.cpp
13813-
///@{
13814-
13815-
public:
13816-
/// Called after parsing an OpenACC Clause so that it can be checked.
13817-
bool ActOnOpenACCClause(OpenACCClauseKind ClauseKind,
13818-
SourceLocation StartLoc);
13819-
13820-
/// Called after the construct has been parsed, but clauses haven't been
13821-
/// parsed. This allows us to diagnose not-implemented, as well as set up any
13822-
/// state required for parsing the clauses.
13823-
void ActOnOpenACCConstruct(OpenACCDirectiveKind K, SourceLocation StartLoc);
13824-
13825-
/// Called after the directive, including its clauses, have been parsed and
13826-
/// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES
13827-
/// happen before any associated declarations or statements have been parsed.
13828-
/// This function is only called when we are parsing a 'statement' context.
13829-
bool ActOnStartOpenACCStmtDirective(OpenACCDirectiveKind K,
13830-
SourceLocation StartLoc);
13831-
13832-
/// Called after the directive, including its clauses, have been parsed and
13833-
/// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES
13834-
/// happen before any associated declarations or statements have been parsed.
13835-
/// This function is only called when we are parsing a 'Decl' context.
13836-
bool ActOnStartOpenACCDeclDirective(OpenACCDirectiveKind K,
13837-
SourceLocation StartLoc);
13838-
/// Called when we encounter an associated statement for our construct, this
13839-
/// should check legality of the statement as it appertains to this Construct.
13840-
StmtResult ActOnOpenACCAssociatedStmt(OpenACCDirectiveKind K,
13841-
StmtResult AssocStmt);
13842-
13843-
/// Called after the directive has been completely parsed, including the
13844-
/// declaration group or associated statement.
13845-
StmtResult ActOnEndOpenACCStmtDirective(OpenACCDirectiveKind K,
13846-
SourceLocation StartLoc,
13847-
SourceLocation EndLoc,
13848-
StmtResult AssocStmt);
13849-
/// Called after the directive has been completely parsed, including the
13850-
/// declaration group or associated statement.
13851-
DeclGroupRef ActOnEndOpenACCDeclDirective();
13852-
13853-
///@}
13854-
13855-
//
13856-
//
13857-
// -------------------------------------------------------------------------
13858-
//
13859-
//
13860-
1386113816
/// \name OpenMP Directives and Clauses
1386213817
/// Implementations are in SemaOpenMP.cpp
1386313818
///@{

0 commit comments

Comments
 (0)