Skip to content

Commit 064a5f8

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:934efd2c9b94 into amd-gfx:848775231186
Local branch amd-gfx 8487752 Merged main:a9e3d232a520 into amd-gfx:83aac6195804 Remote branch main 934efd2 Revert "[Bazel] Fix llvm-exegesis build post 12b0ab2"
2 parents 8487752 + 934efd2 commit 064a5f8

File tree

27 files changed

+1228
-70
lines changed

27 files changed

+1228
-70
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,8 @@ def warn_pragma_acc_unimplemented_clause_parsing
13641364
def err_acc_invalid_directive
13651365
: Error<"invalid OpenACC directive '%select{%1|%1 %2}0'">;
13661366
def err_acc_missing_directive : Error<"expected OpenACC directive">;
1367+
def err_acc_invalid_open_paren
1368+
: Error<"expected clause-list or newline in OpenACC directive">;
13671369

13681370
// OpenMP support.
13691371
def warn_pragma_omp_ignored : Warning<

clang/include/clang/Basic/OpenACCKinds.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ enum class OpenACCDirectiveKind {
5555
Update,
5656
// FIXME: wait construct.
5757

58-
// FIXME: routine construct.
58+
// Procedure Calls in Compute Regions.
59+
Routine,
5960

6061
// Invalid.
6162
Invalid,

clang/include/clang/Parse/Parser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,9 +3532,14 @@ class Parser : public CodeCompletionHandler {
35323532
/// Placeholder for now, should just ignore the directives after emitting a
35333533
/// diagnostic. Eventually will be split into a few functions to parse
35343534
/// different situations.
3535+
public:
35353536
DeclGroupPtrTy ParseOpenACCDirectiveDecl();
35363537
StmtResult ParseOpenACCDirectiveStmt();
35373538

3539+
private:
3540+
void ParseOpenACCDirective();
3541+
ExprResult ParseOpenACCRoutineName();
3542+
35383543
private:
35393544
//===--------------------------------------------------------------------===//
35403545
// C++ 14: Templates [temp]

clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,25 @@ static Value &widenDistinctValues(QualType Type, Value &Prev,
157157
Environment &CurrentEnv,
158158
Environment::ValueModel &Model) {
159159
// Boolean-model widening.
160-
if (isa<BoolValue>(&Prev)) {
161-
assert(isa<BoolValue>(Current));
162-
// Widen to Top, because we know they are different values. If previous was
163-
// already Top, re-use that to (implicitly) indicate that no change occured.
160+
if (auto *PrevBool = dyn_cast<BoolValue>(&Prev)) {
161+
// If previous value was already Top, re-use that to (implicitly) indicate
162+
// that no change occurred.
164163
if (isa<TopBoolValue>(Prev))
165164
return Prev;
165+
166+
// We may need to widen to Top, but before we do so, check whether both
167+
// values are implied to be either true or false in the current environment.
168+
// In that case, we can simply return a literal instead.
169+
auto &CurBool = cast<BoolValue>(Current);
170+
bool TruePrev = PrevEnv.proves(PrevBool->formula());
171+
bool TrueCur = CurrentEnv.proves(CurBool.formula());
172+
if (TruePrev && TrueCur)
173+
return CurrentEnv.getBoolLiteralValue(true);
174+
if (!TruePrev && !TrueCur &&
175+
PrevEnv.proves(PrevEnv.arena().makeNot(PrevBool->formula())) &&
176+
CurrentEnv.proves(CurrentEnv.arena().makeNot(CurBool.formula())))
177+
return CurrentEnv.getBoolLiteralValue(false);
178+
166179
return CurrentEnv.makeTopBoolValue();
167180
}
168181

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(StringRef Name) {
4646
.Case("host_data", OpenACCDirectiveKind::HostData)
4747
.Case("loop", OpenACCDirectiveKind::Loop)
4848
.Case("atomic", OpenACCDirectiveKind::Atomic)
49+
.Case("routine", OpenACCDirectiveKind::Routine)
4950
.Case("declare", OpenACCDirectiveKind::Declare)
5051
.Case("init", OpenACCDirectiveKind::Init)
5152
.Case("shutdown", OpenACCDirectiveKind::Shutdown)
@@ -97,6 +98,8 @@ bool isOpenACCDirectiveKind(OpenACCDirectiveKind Kind, StringRef Tok) {
9798

9899
case OpenACCDirectiveKind::Atomic:
99100
return Tok == "atomic";
101+
case OpenACCDirectiveKind::Routine:
102+
return Tok == "routine";
100103
case OpenACCDirectiveKind::Declare:
101104
return Tok == "declare";
102105
case OpenACCDirectiveKind::Init:
@@ -232,32 +235,87 @@ void ParseOpenACCClauseList(Parser &P) {
232235
P.Diag(P.getCurToken(), diag::warn_pragma_acc_unimplemented_clause_parsing);
233236
}
234237

235-
void ParseOpenACCDirective(Parser &P) {
236-
OpenACCDirectiveKind DirKind = ParseOpenACCDirectiveKind(P);
238+
} // namespace
239+
240+
// Routine has an optional paren-wrapped name of a function in the local scope.
241+
// We parse the name, emitting any diagnostics
242+
ExprResult Parser::ParseOpenACCRoutineName() {
243+
244+
ExprResult Res;
245+
if (getLangOpts().CPlusPlus) {
246+
Res = ParseCXXIdExpression(/*isAddressOfOperand=*/false);
247+
} else {
248+
// There isn't anything quite the same as ParseCXXIdExpression for C, so we
249+
// need to get the identifier, then call into Sema ourselves.
250+
251+
if (expectIdentifier())
252+
return ExprError();
253+
254+
Token FuncName = getCurToken();
255+
UnqualifiedId Name;
256+
CXXScopeSpec ScopeSpec;
257+
SourceLocation TemplateKWLoc;
258+
Name.setIdentifier(FuncName.getIdentifierInfo(), ConsumeToken());
259+
260+
// Ensure this is a valid identifier. We don't accept causing implicit
261+
// function declarations per the spec, so always claim to not have trailing
262+
// L Paren.
263+
Res = Actions.ActOnIdExpression(getCurScope(), ScopeSpec, TemplateKWLoc,
264+
Name, /*HasTrailingLParen=*/false,
265+
/*isAddressOfOperand=*/false);
266+
}
267+
268+
return getActions().CorrectDelayedTyposInExpr(Res);
269+
}
270+
271+
void Parser::ParseOpenACCDirective() {
272+
OpenACCDirectiveKind DirKind = ParseOpenACCDirectiveKind(*this);
237273

238274
// Once we've parsed the construct/directive name, some have additional
239275
// specifiers that need to be taken care of. Atomic has an 'atomic-clause'
240276
// that needs to be parsed.
241277
if (DirKind == OpenACCDirectiveKind::Atomic)
242-
ParseOpenACCAtomicKind(P);
278+
ParseOpenACCAtomicKind(*this);
279+
280+
// We've successfully parsed the construct/directive name, however a few of
281+
// the constructs have optional parens that contain further details.
282+
BalancedDelimiterTracker T(*this, tok::l_paren,
283+
tok::annot_pragma_openacc_end);
284+
285+
if (!T.consumeOpen()) {
286+
switch (DirKind) {
287+
default:
288+
Diag(T.getOpenLocation(), diag::err_acc_invalid_open_paren);
289+
T.skipToEnd();
290+
break;
291+
case OpenACCDirectiveKind::Routine: {
292+
ExprResult RoutineName = ParseOpenACCRoutineName();
293+
// If the routine name is invalid, just skip until the closing paren to
294+
// recover more gracefully.
295+
if (RoutineName.isInvalid())
296+
T.skipToEnd();
297+
else
298+
T.consumeClose();
299+
break;
300+
}
301+
}
302+
}
243303

244304
// Parses the list of clauses, if present.
245-
ParseOpenACCClauseList(P);
305+
ParseOpenACCClauseList(*this);
246306

247-
P.Diag(P.getCurToken(), diag::warn_pragma_acc_unimplemented);
248-
P.SkipUntil(tok::annot_pragma_openacc_end);
307+
Diag(getCurToken(), diag::warn_pragma_acc_unimplemented);
308+
SkipUntil(tok::annot_pragma_openacc_end);
249309
}
250310

251-
} // namespace
252-
253311
// Parse OpenACC directive on a declaration.
254312
Parser::DeclGroupPtrTy Parser::ParseOpenACCDirectiveDecl() {
255313
assert(Tok.is(tok::annot_pragma_openacc) && "expected OpenACC Start Token");
256314

257315
ParsingOpenACCDirectiveRAII DirScope(*this);
258316
ConsumeAnnotationToken();
259317

260-
ParseOpenACCDirective(*this);
318+
ParseOpenACCDirective();
261319

262320
return nullptr;
263321
}
@@ -269,7 +327,7 @@ StmtResult Parser::ParseOpenACCDirectiveStmt() {
269327
ParsingOpenACCDirectiveRAII DirScope(*this);
270328
ConsumeAnnotationToken();
271329

272-
ParseOpenACCDirective(*this);
330+
ParseOpenACCDirective();
273331

274332
return StmtEmpty();
275333
}

clang/test/ParserOpenACC/parse-constructs.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ void func() {
1616
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1717
#pragma acc parallel clause list
1818
for(;;){}
19+
// expected-error@+3{{expected clause-list or newline in OpenACC directive}}
1920
// expected-warning@+2{{OpenACC clause parsing not yet implemented}}
2021
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
2122
#pragma acc parallel() clause list
23+
for(;;){}
24+
// expected-error@+4{{expected clause-list or newline in OpenACC directive}}
25+
// expected-error@+3{{expected ')'}}
26+
// expected-note@+2{{to match this '('}}
27+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
28+
#pragma acc parallel( clause list
2229
for(;;){}
2330
// expected-warning@+2{{OpenACC clause parsing not yet implemented}}
2431
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
@@ -144,3 +151,38 @@ void func() {
144151
#pragma acc update clause list
145152
for(;;){}
146153
}
154+
155+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
156+
#pragma acc routine
157+
void routine_func();
158+
// expected-warning@+2{{OpenACC clause parsing not yet implemented}}
159+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
160+
#pragma acc routine clause list
161+
void routine_func();
162+
163+
// expected-error@+2{{use of undeclared identifier 'func_name'}}
164+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
165+
#pragma acc routine (func_name)
166+
// expected-error@+3{{use of undeclared identifier 'func_name'}}
167+
// expected-warning@+2{{OpenACC clause parsing not yet implemented}}
168+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
169+
#pragma acc routine (func_name) clause list
170+
171+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
172+
#pragma acc routine (routine_func)
173+
// expected-warning@+2{{OpenACC clause parsing not yet implemented}}
174+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
175+
#pragma acc routine (routine_func) clause list
176+
177+
// expected-error@+3{{expected ')'}}
178+
// expected-note@+2{{to match this '('}}
179+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
180+
#pragma acc routine (routine_func())
181+
182+
// expected-error@+2{{expected identifier}}
183+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
184+
#pragma acc routine()
185+
186+
// expected-error@+2{{expected identifier}}
187+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
188+
#pragma acc routine(int)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %clang_cc1 %s -verify -fopenacc
2+
3+
namespace NS {
4+
void foo(); // expected-note{{declared here}}
5+
6+
template<typename T>
7+
void templ(); // expected-note 2{{declared here}}
8+
}
9+
10+
// expected-error@+2{{use of undeclared identifier 'foo'; did you mean 'NS::foo'?}}
11+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
12+
#pragma acc routine(foo)
13+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
14+
#pragma acc routine(NS::foo)
15+
16+
// expected-error@+2{{use of undeclared identifier 'templ'; did you mean 'NS::templ'?}}
17+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
18+
#pragma acc routine(templ)
19+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
20+
#pragma acc routine(NS::templ)
21+
22+
// expected-error@+2{{use of undeclared identifier 'templ'; did you mean 'NS::templ'?}}
23+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
24+
#pragma acc routine(templ<int>)
25+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
26+
#pragma acc routine(NS::templ<int>)
27+
28+
// expected-error@+2{{use of undeclared identifier 'T'}}
29+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
30+
#pragma acc routine(templ<T>)
31+
// expected-error@+2{{use of undeclared identifier 'T'}}
32+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
33+
#pragma acc routine(NS::templ<T>)
34+
35+
// expected-error@+3{{expected ')'}}
36+
// expected-note@+2{{to match this '('}}
37+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
38+
#pragma acc routine (NS::foo())
39+
40+
// expected-error@+2 {{expected unqualified-id}}
41+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
42+
#pragma acc routine()
43+
44+
// expected-error@+2 {{expected unqualified-id}}
45+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
46+
#pragma acc routine(int)

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4167,6 +4167,34 @@ TEST(TransferTest, LoopWithShortCircuitedConditionConverges) {
41674167
ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
41684168
}
41694169

4170+
TEST(TransferTest, LoopCanProveInvariantForBoolean) {
4171+
// Check that we can prove `b` is always false in the loop.
4172+
// This test exercises the logic in `widenDistinctValues()` that preserves
4173+
// information if the boolean can be proved to be either true or false in both
4174+
// the previous and current iteration.
4175+
std::string Code = R"cc(
4176+
int return_int();
4177+
void target() {
4178+
bool b = return_int() == 0;
4179+
if (b) return;
4180+
while (true) {
4181+
b;
4182+
// [[p]]
4183+
b = return_int() == 0;
4184+
if (b) return;
4185+
}
4186+
}
4187+
)cc";
4188+
runDataflow(
4189+
Code,
4190+
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
4191+
ASTContext &ASTCtx) {
4192+
const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
4193+
auto &BVal = getValueForDecl<BoolValue>(ASTCtx, Env, "b");
4194+
EXPECT_TRUE(Env.proves(Env.arena().makeNot(BVal.formula())));
4195+
});
4196+
}
4197+
41704198
TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
41714199
std::string Code = R"(
41724200
union Union {

clang/utils/TableGen/SveEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ void SVEEmitter::createSMEHeader(raw_ostream &OS) {
15711571
OS << "#error \"Big endian is currently not supported for arm_sme_draft_spec_subject_to_change.h\"\n";
15721572
OS << "#endif\n";
15731573

1574-
OS << "#include <arm_sve.h> \n\n";
1574+
OS << "#include <arm_sve.h>\n\n";
15751575

15761576
OS << "/* Function attributes */\n";
15771577
OS << "#define __ai static __inline__ __attribute__((__always_inline__, "

libc/utils/gpu/server/rpc_server.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ struct Server {
7878

7979
port->recv_n(strs, sizes, [&](uint64_t size) { return new char[size]; });
8080
port->send([&](rpc::Buffer *buffer, uint32_t id) {
81-
buffer->data[0] = fwrite(strs[id], 1, sizes[id], files[id]);
81+
flockfile(files[id]);
82+
buffer->data[0] = fwrite_unlocked(strs[id], 1, sizes[id], files[id]);
8283
if (port->get_opcode() == RPC_WRITE_TO_STDOUT_NEWLINE &&
8384
buffer->data[0] == sizes[id])
84-
buffer->data[0] += fwrite("\n", 1, 1, files[id]);
85+
buffer->data[0] += fwrite_unlocked("\n", 1, 1, files[id]);
86+
funlockfile(files[id]);
8587
delete[] reinterpret_cast<uint8_t *>(strs[id]);
8688
});
8789
break;

libcxxabi/test/test_demangle.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// Is long double fp128?
3333
#define LDBL_FP128 (__LDBL_MANT_DIG__ == 113)
3434

35+
// clang-format off
3536
const char* cases[][2] =
3637
{
3738
{"_Z1A", "A"},
@@ -30175,6 +30176,7 @@ const char* cases[][2] =
3017530176
{"_Z2f5IPiEvu16__remove_pointerIT_E", "void f5<int*>(__remove_pointer(int*))"},
3017630177
{"_Z2f5IiEvu14__remove_cvrefIT_E", "void f5<int>(__remove_cvref(int))"},
3017730178
};
30179+
// clang-format on
3017830180

3017930181
const unsigned N = sizeof(cases) / sizeof(cases[0]);
3018030182

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 481796
19+
#define LLVM_MAIN_REVISION 481808
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/include/llvm/Support/GenericDomTreeConstruction.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,12 @@ struct SemiNCAInfo {
304304
auto &WInfo = *NumToInfo[i];
305305
const unsigned SDomNum = NodeToInfo[NumToNode[WInfo.Semi]].DFSNum;
306306
NodePtr WIDomCandidate = WInfo.IDom;
307-
while (NodeToInfo[WIDomCandidate].DFSNum > SDomNum)
308-
WIDomCandidate = NodeToInfo[WIDomCandidate].IDom;
307+
while (true) {
308+
auto &WIDomCandidateInfo = NodeToInfo.find(WIDomCandidate)->second;
309+
if (WIDomCandidateInfo.DFSNum <= SDomNum)
310+
break;
311+
WIDomCandidate = WIDomCandidateInfo.IDom;
312+
}
309313

310314
WInfo.IDom = WIDomCandidate;
311315
}

0 commit comments

Comments
 (0)