Skip to content

Commit ff7f99b

Browse files
committed
Merge "merge main into amd-staging" into amd-staging
2 parents 12436fe + 032c594 commit ff7f99b

File tree

192 files changed

+9145
-1897
lines changed

Some content is hidden

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

192 files changed

+9145
-1897
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12668,19 +12668,19 @@ def err_acc_size_expr_value
1266812668
: Error<
1266912669
"OpenACC 'tile' clause size expression must be %select{an asterisk "
1267012670
"or a constant expression|positive integer value, evaluated to %1}0">;
12671-
def err_acc_invalid_in_collapse_loop
12672-
: Error<"%select{OpenACC '%1' construct|while loop|do loop}0 cannot appear "
12673-
"in intervening code of a 'loop' with a 'collapse' clause">;
12674-
def note_acc_collapse_clause_here
12675-
: Note<"active 'collapse' clause defined here">;
12676-
def err_acc_collapse_multiple_loops
12671+
def err_acc_invalid_in_loop
12672+
: Error<"%select{OpenACC '%2' construct|while loop|do loop}0 cannot appear "
12673+
"in intervening code of a 'loop' with a '%1' clause">;
12674+
def note_acc_active_clause_here
12675+
: Note<"active '%0' clause defined here">;
12676+
def err_acc_clause_multiple_loops
1267712677
: Error<"more than one for-loop in a loop associated with OpenACC 'loop' "
12678-
"construct with a 'collapse' clause">;
12679-
def err_acc_collapse_insufficient_loops
12680-
: Error<"'collapse' clause specifies a loop count greater than the number "
12678+
"construct with a '%select{collapse|tile}0' clause">;
12679+
def err_acc_insufficient_loops
12680+
: Error<"'%0' clause specifies a loop count greater than the number "
1268112681
"of available loops">;
12682-
def err_acc_collapse_intervening_code
12683-
: Error<"inner loops must be tightly nested inside a 'collapse' clause on "
12682+
def err_acc_intervening_code
12683+
: Error<"inner loops must be tightly nested inside a '%0' clause on "
1268412684
"a 'loop' construct">;
1268512685

1268612686
// AMDGCN builtins diagnostics

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,10 +1200,11 @@ def cxx_isystem : JoinedOrSeparate<["-"], "cxx-isystem">, Group<clang_i_Group>,
12001200
def c : Flag<["-"], "c">, Flags<[NoXarchOption]>,
12011201
Visibility<[ClangOption, FlangOption]>, Group<Action_Group>,
12021202
HelpText<"Only run preprocess, compile, and assemble steps">;
1203-
defm convergent_functions : BoolFOption<"convergent-functions",
1204-
LangOpts<"ConvergentFunctions">, DefaultFalse,
1205-
NegFlag<SetFalse, [], [ClangOption], "Assume all functions may be convergent.">,
1206-
PosFlag<SetTrue, [], [ClangOption, CC1Option]>>;
1203+
def fconvergent_functions : Flag<["-"], "fconvergent-functions">,
1204+
Visibility<[ClangOption, CC1Option]>,
1205+
HelpText< "Assume all functions may be convergent.">;
1206+
def fno_convergent_functions : Flag<["-"], "fno-convergent-functions">,
1207+
Visibility<[ClangOption, CC1Option]>;
12071208

12081209
// Common offloading options
12091210
let Group = offload_Group in {

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ class SemaOpenACC : public SemaBase {
4242
/// above collection.
4343
bool InsideComputeConstruct = false;
4444

45+
/// Certain clauses care about the same things that aren't specific to the
46+
/// individual clause, but can be shared by a few, so store them here. All
47+
/// require a 'no intervening constructs' rule, so we know they are all from
48+
/// the same 'place'.
49+
struct LoopCheckingInfo {
50+
/// Records whether we've seen the top level 'for'. We already diagnose
51+
/// later that the 'top level' is a for loop, so we use this to suppress the
52+
/// 'collapse inner loop not a 'for' loop' diagnostic.
53+
LLVM_PREFERRED_TYPE(bool)
54+
unsigned TopLevelLoopSeen : 1;
55+
56+
/// Records whether this 'tier' of the loop has already seen a 'for' loop,
57+
/// used to diagnose if there are multiple 'for' loops at any one level.
58+
LLVM_PREFERRED_TYPE(bool)
59+
unsigned CurLevelHasLoopAlready : 1;
60+
} LoopInfo{/*TopLevelLoopSeen=*/false, /*CurLevelHasLoopAlready=*/false};
61+
4562
/// The 'collapse' clause requires quite a bit of checking while
4663
/// parsing/instantiating its body, so this structure/object keeps all of the
4764
/// necessary information as we do checking. This should rarely be directly
@@ -59,25 +76,27 @@ class SemaOpenACC : public SemaBase {
5976
/// else it should be 'N' minus the current depth traversed.
6077
std::optional<llvm::APSInt> CurCollapseCount;
6178

62-
/// Records whether we've seen the top level 'for'. We already diagnose
63-
/// later that the 'top level' is a for loop, so we use this to suppress the
64-
/// 'collapse inner loop not a 'for' loop' diagnostic.
65-
LLVM_PREFERRED_TYPE(bool)
66-
unsigned TopLevelLoopSeen : 1;
67-
68-
/// Records whether this 'tier' of the loop has already seen a 'for' loop,
69-
/// used to diagnose if there are multiple 'for' loops at any one level.
70-
LLVM_PREFERRED_TYPE(bool)
71-
unsigned CurLevelHasLoopAlready : 1;
72-
7379
/// Records whether we've hit a CurCollapseCount of '0' on the way down,
7480
/// which allows us to diagnose if the value of 'N' is too large for the
7581
/// current number of 'for' loops.
76-
LLVM_PREFERRED_TYPE(bool)
77-
unsigned CollapseDepthSatisfied : 1;
78-
} CollapseInfo{nullptr, std::nullopt, /*TopLevelLoopSeen=*/false,
79-
/*CurLevelHasLoopAlready=*/false,
80-
/*CollapseDepthSatisfied=*/true};
82+
bool CollapseDepthSatisfied = true;
83+
} CollapseInfo;
84+
85+
/// The 'tile' clause requires a bit of additional checking as well, so like
86+
/// the `CollapseCheckingInfo`, ensure we maintain information here too.
87+
struct TileCheckingInfo {
88+
OpenACCTileClause *ActiveTile = nullptr;
89+
90+
/// This is the number of expressions on a 'tile' clause. This doesn't have
91+
/// to be an APSInt because it isn't the result of a constexpr, just by our
92+
/// own counting of elements.
93+
std::optional<unsigned> CurTileCount;
94+
95+
/// Records whether we've hit a 'CurTileCount' of '0' on the wya down,
96+
/// which allows us to diagnose if the number of arguments is too large for
97+
/// the current number of 'for' loops.
98+
bool TileDepthSatisfied = true;
99+
} TileInfo;
81100

82101
public:
83102
// Redeclaration of the version in OpenACCClause.h.
@@ -537,12 +556,15 @@ class SemaOpenACC : public SemaBase {
537556
/// into a loop (for, etc) inside the construct.
538557
class LoopInConstructRAII {
539558
SemaOpenACC &SemaRef;
559+
LoopCheckingInfo OldLoopInfo;
540560
CollapseCheckingInfo OldCollapseInfo;
561+
TileCheckingInfo OldTileInfo;
541562
bool PreserveDepth;
542563

543564
public:
544565
LoopInConstructRAII(SemaOpenACC &SemaRef, bool PreserveDepth = true)
545-
: SemaRef(SemaRef), OldCollapseInfo(SemaRef.CollapseInfo),
566+
: SemaRef(SemaRef), OldLoopInfo(SemaRef.LoopInfo),
567+
OldCollapseInfo(SemaRef.CollapseInfo), OldTileInfo(SemaRef.TileInfo),
546568
PreserveDepth(PreserveDepth) {}
547569
~LoopInConstructRAII() {
548570
// The associated-statement level of this should NOT preserve this, as it
@@ -551,12 +573,20 @@ class SemaOpenACC : public SemaBase {
551573
bool CollapseDepthSatisified =
552574
PreserveDepth ? SemaRef.CollapseInfo.CollapseDepthSatisfied
553575
: OldCollapseInfo.CollapseDepthSatisfied;
576+
bool TileDepthSatisfied = PreserveDepth
577+
? SemaRef.TileInfo.TileDepthSatisfied
578+
: OldTileInfo.TileDepthSatisfied;
554579
bool CurLevelHasLoopAlready =
555-
PreserveDepth ? SemaRef.CollapseInfo.CurLevelHasLoopAlready
556-
: OldCollapseInfo.CurLevelHasLoopAlready;
580+
PreserveDepth ? SemaRef.LoopInfo.CurLevelHasLoopAlready
581+
: OldLoopInfo.CurLevelHasLoopAlready;
582+
583+
SemaRef.LoopInfo = OldLoopInfo;
557584
SemaRef.CollapseInfo = OldCollapseInfo;
585+
SemaRef.TileInfo = OldTileInfo;
586+
558587
SemaRef.CollapseInfo.CollapseDepthSatisfied = CollapseDepthSatisified;
559-
SemaRef.CollapseInfo.CurLevelHasLoopAlready = CurLevelHasLoopAlready;
588+
SemaRef.TileInfo.TileDepthSatisfied = TileDepthSatisfied;
589+
SemaRef.LoopInfo.CurLevelHasLoopAlready = CurLevelHasLoopAlready;
560590
}
561591
};
562592

@@ -577,6 +607,9 @@ class SemaOpenACC : public SemaBase {
577607
void SetCollapseInfoBeforeAssociatedStmt(
578608
ArrayRef<const OpenACCClause *> UnInstClauses,
579609
ArrayRef<OpenACCClause *> Clauses);
610+
void SetTileInfoBeforeAssociatedStmt(
611+
ArrayRef<const OpenACCClause *> UnInstClauses,
612+
ArrayRef<OpenACCClause *> Clauses);
580613
~AssociatedStmtRAII();
581614
};
582615
};

clang/lib/AST/ByteCode/Descriptor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ static void ctorArrayDesc(Block *B, std::byte *Ptr, bool IsConst,
103103
Desc->IsConst = IsConst || D->IsConst;
104104
Desc->IsFieldMutable = IsMutable || D->IsMutable;
105105
Desc->InUnion = InUnion;
106+
Desc->IsArrayElement = true;
106107

107108
if (auto Fn = D->ElemDesc->CtorFn)
108109
Fn(B, ElemLoc, Desc->IsConst, Desc->IsFieldMutable, IsActive,
@@ -408,6 +409,8 @@ QualType Descriptor::getType() const {
408409
QualType Descriptor::getElemQualType() const {
409410
assert(isArray());
410411
QualType T = getType();
412+
if (T->isPointerOrReferenceType())
413+
return T->getPointeeType();
411414
if (const auto *AT = T->getAsArrayTypeUnsafe())
412415
return AT->getElementType();
413416
if (const auto *CT = T->getAs<ComplexType>())

clang/lib/AST/ByteCode/Descriptor.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,16 @@ struct InlineDescriptor {
9696
/// Flag indicating if the field is mutable (if in a record).
9797
LLVM_PREFERRED_TYPE(bool)
9898
unsigned IsFieldMutable : 1;
99+
/// Flag indicating if the field is an element of a composite array.
100+
LLVM_PREFERRED_TYPE(bool)
101+
unsigned IsArrayElement : 1;
99102

100103
const Descriptor *Desc;
101104

102105
InlineDescriptor(const Descriptor *D)
103106
: Offset(sizeof(InlineDescriptor)), IsConst(false), IsInitialized(false),
104-
IsBase(false), IsActive(false), IsFieldMutable(false), Desc(D) {}
107+
IsBase(false), IsActive(false), IsFieldMutable(false),
108+
IsArrayElement(false), Desc(D) {}
105109

106110
void dump() const { dump(llvm::errs()); }
107111
void dump(llvm::raw_ostream &OS) const;

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,10 @@ bool handleFixedPointOverflow(InterpState &S, CodePtr OpPC,
14061406
return S.noteUndefinedBehavior();
14071407
}
14081408

1409+
// https://github.com/llvm/llvm-project/issues/102513
1410+
#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
1411+
#pragma optimize("", off)
1412+
#endif
14091413
bool Interpret(InterpState &S, APValue &Result) {
14101414
// The current stack frame when we started Interpret().
14111415
// This is being used by the ops to determine wheter
@@ -1430,6 +1434,10 @@ bool Interpret(InterpState &S, APValue &Result) {
14301434
}
14311435
}
14321436
}
1437+
// https://github.com/llvm/llvm-project/issues/102513
1438+
#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
1439+
#pragma optimize("", on)
1440+
#endif
14331441

14341442
} // namespace interp
14351443
} // namespace clang

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,22 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
204204
Path.push_back(APValue::LValuePathEntry(
205205
{Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false}));
206206

207-
if (const auto *FD = dyn_cast<FieldDecl>(Ptr.getFieldDesc()->asDecl()))
207+
if (const auto *FD =
208+
dyn_cast_if_present<FieldDecl>(Ptr.getFieldDesc()->asDecl()))
208209
Offset += getFieldOffset(FD);
209210

210211
Ptr = Ptr.getBase();
211212
} else if (Ptr.isArrayElement()) {
213+
Ptr = Ptr.expand();
212214
unsigned Index;
213215
if (Ptr.isOnePastEnd())
214216
Index = Ptr.getArray().getNumElems();
215217
else
216218
Index = Ptr.getIndex();
217219

218-
Offset += (Index * ASTCtx.getTypeSizeInChars(Ptr.getType()));
220+
QualType ElemType = Ptr.getFieldDesc()->getElemQualType();
221+
Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
222+
219223
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
220224
Ptr = Ptr.getArray();
221225
} else {

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,18 @@ class Pointer {
420420
}
421421
/// Checks if the pointer points to an array.
422422
bool isArrayElement() const {
423-
if (isBlockPointer())
424-
return inArray() && asBlockPointer().Base != Offset;
423+
if (!isBlockPointer())
424+
return false;
425+
426+
const BlockPointer &BP = asBlockPointer();
427+
if (inArray() && BP.Base != Offset)
428+
return true;
429+
430+
// Might be a narrow()'ed element in a composite array.
431+
// Check the inline descriptor.
432+
if (BP.Base >= sizeof(InlineDescriptor) && getInlineDesc()->IsArrayElement)
433+
return true;
434+
425435
return false;
426436
}
427437
/// Pointer points directly to a block.

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
850850
for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects()) {
851851
if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
852852
Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
853+
else if (Fe.Effect.kind() == FunctionEffect::Kind::Blocking)
854+
Fn->addFnAttr(llvm::Attribute::SanitizeRealtimeUnsafe);
853855
}
854856

855857
// Apply fuzzing attribute to the function.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6369,8 +6369,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
63696369
options::OPT_fno_unique_internal_linkage_names);
63706370
Args.addOptInFlag(CmdArgs, options::OPT_funique_basic_block_section_names,
63716371
options::OPT_fno_unique_basic_block_section_names);
6372-
Args.addOptInFlag(CmdArgs, options::OPT_fconvergent_functions,
6373-
options::OPT_fno_convergent_functions);
63746372

63756373
if (Arg *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
63766374
options::OPT_fno_split_machine_functions)) {
@@ -6387,6 +6385,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
63876385
Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
63886386
options::OPT_finstrument_functions_after_inlining,
63896387
options::OPT_finstrument_function_entry_bare);
6388+
Args.AddLastArg(CmdArgs, options::OPT_fconvergent_functions,
6389+
options::OPT_fno_convergent_functions);
63906390

63916391
// NVPTX/AMDGCN doesn't support PGO or coverage. There's no runtime support
63926392
// for sampling, overhead of call arc collection is way too high and there's

clang/lib/Driver/ToolChains/ZOS.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ void ZOS::addClangTargetOptions(const ArgList &DriverArgs,
3737
options::OPT_fno_aligned_allocation))
3838
CC1Args.push_back("-faligned-alloc-unavailable");
3939

40+
if (DriverArgs.hasFlag(options::OPT_fxl_pragma_pack,
41+
options::OPT_fno_xl_pragma_pack, true))
42+
CC1Args.push_back("-fxl-pragma-pack");
43+
4044
// Pass "-fno-sized-deallocation" only when the user hasn't manually enabled
4145
// or disabled sized deallocations.
4246
if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,10 +3695,10 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
36953695
if (Opts.Blocks && !(Opts.OpenCL && Opts.OpenCLVersion == 200))
36963696
GenerateArg(Consumer, OPT_fblocks);
36973697

3698-
if (Opts.ConvergentFunctions &&
3699-
!(Opts.OpenCL || (Opts.CUDA && Opts.CUDAIsDevice) || Opts.SYCLIsDevice ||
3700-
Opts.HLSL))
3698+
if (Opts.ConvergentFunctions)
37013699
GenerateArg(Consumer, OPT_fconvergent_functions);
3700+
else
3701+
GenerateArg(Consumer, OPT_fno_convergent_functions);
37023702

37033703
if (Opts.NoBuiltin && !Opts.Freestanding)
37043704
GenerateArg(Consumer, OPT_fno_builtin);
@@ -4167,9 +4167,12 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
41674167
Opts.Blocks = Args.hasArg(OPT_fblocks) || (Opts.OpenCL
41684168
&& Opts.OpenCLVersion == 200);
41694169

4170-
Opts.ConvergentFunctions = Args.hasArg(OPT_fconvergent_functions) ||
4171-
Opts.OpenCL || (Opts.CUDA && Opts.CUDAIsDevice) ||
4172-
Opts.SYCLIsDevice || Opts.HLSL;
4170+
bool HasConvergentOperations = Opts.OpenMPIsTargetDevice || Opts.OpenCL ||
4171+
Opts.CUDAIsDevice || Opts.SYCLIsDevice ||
4172+
Opts.HLSL || T.isAMDGPU() || T.isNVPTX();
4173+
Opts.ConvergentFunctions =
4174+
Args.hasFlag(OPT_fconvergent_functions, OPT_fno_convergent_functions,
4175+
HasConvergentOperations);
41734176

41744177
Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
41754178
if (!Opts.NoBuiltin)
@@ -4224,9 +4227,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
42244227
Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_enable_irbuilder);
42254228
bool IsTargetSpecified =
42264229
Opts.OpenMPIsTargetDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ);
4227-
Opts.ConvergentFunctions =
4228-
Opts.ConvergentFunctions || Opts.OpenMPIsTargetDevice;
4229-
42304230
if (Opts.OpenMP || Opts.OpenMPSimd) {
42314231
if (int Version = getLastArgIntValue(
42324232
Args, OPT_fopenmp_version_EQ,

clang/lib/Parse/ParsePragma.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,7 @@ void PragmaGCCVisibilityHandler::HandlePragma(Preprocessor &PP,
21262126
// pack '(' [integer] ')'
21272127
// pack '(' 'show' ')'
21282128
// pack '(' ('push' | 'pop') [',' identifier] [, integer] ')'
2129+
// pack '(' 'packed' | 'full' | 'twobyte' | 'reset' ')' with -fzos-extensions
21292130
void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21302131
PragmaIntroducer Introducer,
21312132
Token &PackTok) {
@@ -2155,10 +2156,35 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21552156
? Sema::PSK_Push_Set
21562157
: Sema::PSK_Set;
21572158
} else if (Tok.is(tok::identifier)) {
2159+
// Map pragma pack options to pack (integer).
2160+
auto MapPack = [&](const char *Literal) {
2161+
Action = Sema::PSK_Push_Set;
2162+
Alignment = Tok;
2163+
Alignment.setKind(tok::numeric_constant);
2164+
Alignment.setLiteralData(Literal);
2165+
Alignment.setLength(1);
2166+
};
2167+
21582168
const IdentifierInfo *II = Tok.getIdentifierInfo();
21592169
if (II->isStr("show")) {
21602170
Action = Sema::PSK_Show;
21612171
PP.Lex(Tok);
2172+
} else if (II->isStr("packed") && PP.getLangOpts().ZOSExt) {
2173+
// #pragma pack(packed) is the same as #pragma pack(1)
2174+
MapPack("1");
2175+
PP.Lex(Tok);
2176+
} else if (II->isStr("full") && PP.getLangOpts().ZOSExt) {
2177+
// #pragma pack(full) is the same as #pragma pack(4)
2178+
MapPack("4");
2179+
PP.Lex(Tok);
2180+
} else if (II->isStr("twobyte") && PP.getLangOpts().ZOSExt) {
2181+
// #pragma pack(twobyte) is the same as #pragma pack(2)
2182+
MapPack("2");
2183+
PP.Lex(Tok);
2184+
} else if (II->isStr("reset") && PP.getLangOpts().ZOSExt) {
2185+
// #pragma pack(reset) is the same as #pragma pack(pop) on XL
2186+
Action = Sema::PSK_Pop;
2187+
PP.Lex(Tok);
21622188
} else {
21632189
if (II->isStr("push")) {
21642190
Action = Sema::PSK_Push;

0 commit comments

Comments
 (0)