Skip to content

Commit b7ec5b5

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:c16adb0dcb1f into amd-gfx:0d8d0068a932
Local branch amd-gfx 0d8d006 Fix build warning in SIInsertWaterfall Remote branch main c16adb0 [mlir][Target][NVPTX] Add fatbin support to NVPTX compilation. (llvm#65398)
2 parents 0d8d006 + c16adb0 commit b7ec5b5

File tree

44 files changed

+1712
-204
lines changed

Some content is hidden

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

44 files changed

+1712
-204
lines changed

clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "clang/Basic/LangOptions.h"
2727
#include "clang/Basic/SourceLocation.h"
2828
#include "clang/Format/Format.h"
29+
#include "clang/Lex/HeaderSearchOptions.h"
2930
#include "clang/Lex/Preprocessor.h"
3031
#include "clang/Tooling/Core/Replacement.h"
3132
#include "clang/Tooling/Inclusions/HeaderIncludes.h"
@@ -119,6 +120,8 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
119120
MainFileDecls.push_back(D);
120121
}
121122
llvm::DenseSet<include_cleaner::Symbol> SeenSymbols;
123+
const DirectoryEntry *ResourceDir =
124+
PP->getHeaderSearchInfo().getModuleMap().getBuiltinDir();
122125
// FIXME: Find a way to have less code duplication between include-cleaner
123126
// analysis implementation and the below code.
124127
walkUsed(MainFileDecls, RecordedPreprocessor.MacroReferences, &RecordedPI,
@@ -141,8 +144,11 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
141144
bool Satisfied = false;
142145
for (const include_cleaner::Header &H : Providers) {
143146
if (H.kind() == include_cleaner::Header::Physical &&
144-
H.physical() == MainFile)
147+
(H.physical() == MainFile ||
148+
H.physical()->getDir() == ResourceDir)) {
145149
Satisfied = true;
150+
continue;
151+
}
146152

147153
for (const include_cleaner::Include *I :
148154
RecordedPreprocessor.Includes.match(H)) {
@@ -159,7 +165,7 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
159165
std::vector<const include_cleaner::Include *> Unused;
160166
for (const include_cleaner::Include &I :
161167
RecordedPreprocessor.Includes.all()) {
162-
if (Used.contains(&I) || !I.Resolved)
168+
if (Used.contains(&I) || !I.Resolved || I.Resolved->getDir() == ResourceDir)
163169
continue;
164170
if (RecordedPI.shouldKeep(*I.Resolved))
165171
continue;

clang-tools-extra/clangd/IncludeCleaner.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ bool mayConsiderUnused(const Inclusion &Inc, ParsedAST &AST,
7575
auto FE = AST.getSourceManager().getFileManager().getFileRef(
7676
AST.getIncludeStructure().getRealPath(HID));
7777
assert(FE);
78+
if (FE->getDir() == AST.getPreprocessor()
79+
.getHeaderSearchInfo()
80+
.getModuleMap()
81+
.getBuiltinDir())
82+
return false;
7883
if (PI && PI->shouldKeep(*FE))
7984
return false;
8085
// FIXME(kirillbobyrev): We currently do not support the umbrella headers.
@@ -392,6 +397,10 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) {
392397
std::vector<MissingIncludeDiagInfo> MissingIncludes;
393398
llvm::DenseSet<IncludeStructure::HeaderID> Used;
394399
trace::Span Tracer("include_cleaner::walkUsed");
400+
const DirectoryEntry *ResourceDir = AST.getPreprocessor()
401+
.getHeaderSearchInfo()
402+
.getModuleMap()
403+
.getBuiltinDir();
395404
include_cleaner::walkUsed(
396405
AST.getLocalTopLevelDecls(), /*MacroRefs=*/Macros,
397406
AST.getPragmaIncludes().get(), AST.getPreprocessor(),
@@ -400,7 +409,8 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) {
400409
bool Satisfied = false;
401410
for (const auto &H : Providers) {
402411
if (H.kind() == include_cleaner::Header::Physical &&
403-
(H.physical() == MainFile || H.physical() == PreamblePatch)) {
412+
(H.physical() == MainFile || H.physical() == PreamblePatch ||
413+
H.physical()->getLastRef().getDir() == ResourceDir)) {
404414
Satisfied = true;
405415
continue;
406416
}

clang-tools-extra/clangd/test/include-cleaner-batch-fix.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
# RUN: rm -rf %t
66
# RUN: mkdir -p %t/clangd
77
# RUN: cp -r %S/Inputs/include-cleaner %t/include
8+
# RUN: echo '-I%t/include' > %t/compile_flags.txt
89
# Create a config file enabling include-cleaner features.
910
# RUN: echo $'Diagnostics:\n UnusedIncludes: Strict\n MissingIncludes: Strict' >> %t/clangd/config.yaml
1011

11-
# RUN: env XDG_CONFIG_HOME=%t clangd -lit-test -enable-config --resource-dir=%t < %s | FileCheck -strict-whitespace %s
12+
# RUN: env XDG_CONFIG_HOME=%t clangd -lit-test -enable-config --compile-commands-dir=%t < %s | FileCheck -strict-whitespace %s
1213
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"workspace":{"workspaceEdit":{"documentChanges":true, "changeAnnotationSupport":{"groupsOnLabel":true}}}},"trace":"off"}}
1314
---
1415
{

clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,29 @@ TEST(IncludeCleaner, VerbatimEquivalence) {
574574
EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
575575
}
576576

577+
TEST(IncludeCleaner, ResourceDirIsIgnored) {
578+
auto TU = TestTU::withCode(R"cpp(
579+
#include <amintrin.h>
580+
#include <imintrin.h>
581+
void baz() {
582+
bar();
583+
}
584+
)cpp");
585+
TU.ExtraArgs.push_back("-resource-dir");
586+
TU.ExtraArgs.push_back(testPath("resources"));
587+
TU.AdditionalFiles["resources/include/amintrin.h"] = guard("");
588+
TU.AdditionalFiles["resources/include/imintrin.h"] = guard(R"cpp(
589+
#include <emintrin.h>
590+
)cpp");
591+
TU.AdditionalFiles["resources/include/emintrin.h"] = guard(R"cpp(
592+
void bar();
593+
)cpp");
594+
auto AST = TU.build();
595+
auto Findings = computeIncludeCleanerFindings(AST);
596+
EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
597+
EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
598+
}
599+
577600
} // namespace
578601
} // namespace clangd
579602
} // namespace clang

clang-tools-extra/include-cleaner/lib/Analysis.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang-include-cleaner/Types.h"
1414
#include "clang/AST/Decl.h"
1515
#include "clang/AST/DeclBase.h"
16+
#include "clang/Basic/DirectoryEntry.h"
1617
#include "clang/Basic/FileEntry.h"
1718
#include "clang/Basic/SourceManager.h"
1819
#include "clang/Format/Format.h"
@@ -86,12 +87,17 @@ analyze(llvm::ArrayRef<Decl *> ASTRoots,
8687
llvm::StringSet<> Missing;
8788
if (!HeaderFilter)
8889
HeaderFilter = [](llvm::StringRef) { return false; };
90+
const DirectoryEntry *ResourceDir =
91+
PP.getHeaderSearchInfo().getModuleMap().getBuiltinDir();
8992
walkUsed(ASTRoots, MacroRefs, PI, PP,
9093
[&](const SymbolReference &Ref, llvm::ArrayRef<Header> Providers) {
9194
bool Satisfied = false;
9295
for (const Header &H : Providers) {
93-
if (H.kind() == Header::Physical && H.physical() == MainFile)
96+
if (H.kind() == Header::Physical &&
97+
(H.physical() == MainFile ||
98+
H.physical()->getDir() == ResourceDir)) {
9499
Satisfied = true;
100+
}
95101
for (const Include *I : Inc.match(H)) {
96102
Used.insert(I);
97103
Satisfied = true;
@@ -107,7 +113,8 @@ analyze(llvm::ArrayRef<Decl *> ASTRoots,
107113
AnalysisResults Results;
108114
for (const Include &I : Inc.all()) {
109115
if (Used.contains(&I) || !I.Resolved ||
110-
HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()))
116+
HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()) ||
117+
I.Resolved->getFileEntry().getDir() == ResourceDir)
111118
continue;
112119
if (PI) {
113120
if (PI->shouldKeep(*I.Resolved))

clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,31 @@ TEST_F(AnalyzeTest, NoCrashWhenUnresolved) {
271271
EXPECT_THAT(Results.Unused, testing::IsEmpty());
272272
}
273273

274+
TEST_F(AnalyzeTest, ResourceDirIsIgnored) {
275+
Inputs.ExtraArgs.push_back("-resource-dir");
276+
Inputs.ExtraArgs.push_back("resources");
277+
Inputs.ExtraArgs.push_back("-internal-isystem");
278+
Inputs.ExtraArgs.push_back("resources/include");
279+
Inputs.Code = R"cpp(
280+
#include <amintrin.h>
281+
#include <imintrin.h>
282+
void baz() {
283+
bar();
284+
}
285+
)cpp";
286+
Inputs.ExtraFiles["resources/include/amintrin.h"] = guard("");
287+
Inputs.ExtraFiles["resources/include/emintrin.h"] = guard(R"cpp(
288+
void bar();
289+
)cpp");
290+
Inputs.ExtraFiles["resources/include/imintrin.h"] = guard(R"cpp(
291+
#include <emintrin.h>
292+
)cpp");
293+
TestAST AST(Inputs);
294+
auto Results = analyze({}, {}, PP.Includes, &PI, AST.preprocessor());
295+
EXPECT_THAT(Results.Unused, testing::IsEmpty());
296+
EXPECT_THAT(Results.Missing, testing::IsEmpty());
297+
}
298+
274299
TEST(FixIncludes, Basic) {
275300
llvm::StringRef Code = R"cpp(#include "d.h"
276301
#include "a.h"

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,8 +2535,9 @@ class AnnotatingParser {
25352535
return TT_BinaryOperator;
25362536

25372537
if (!NextToken ||
2538-
NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_noexcept, tok::comma,
2539-
tok::r_paren, TT_RequiresClause) ||
2538+
NextToken->isOneOf(tok::arrow, tok::equal, tok::comma, tok::r_paren,
2539+
TT_RequiresClause) ||
2540+
(NextToken->is(tok::kw_noexcept) && !IsExpression) ||
25402541
NextToken->canBePointerOrReferenceQualifier() ||
25412542
(NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) {
25422543
return TT_PointerOrReference;

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
273273
ASSERT_EQ(Tokens.size(), 19u) << Tokens;
274274
EXPECT_TOKEN(Tokens[5], tok::ampamp, TT_BinaryOperator);
275275

276+
Tokens =
277+
annotate("auto foo() noexcept(noexcept(bar()) && "
278+
"trait<std::decay_t<decltype(bar())>> && noexcept(baz())) {}");
279+
EXPECT_EQ(Tokens.size(), 38u) << Tokens;
280+
EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_BinaryOperator);
281+
EXPECT_TOKEN(Tokens[27], tok::ampamp, TT_BinaryOperator);
282+
276283
FormatStyle Style = getLLVMStyle();
277284
Style.TypeNames.push_back("MYI");
278285
Tokens = annotate("if (MYI *p{nullptr})", Style);

flang/lib/Lower/OpenMP.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3666,12 +3666,18 @@ void Fortran::lower::genThreadprivateOp(
36663666
currentLocation, symValue.getType(), symValue);
36673667
} else {
36683668
mlir::Value symValue = converter.getSymbolAddress(sym);
3669-
mlir::Operation *op = symValue.getDefiningOp();
3669+
36703670
// The symbol may be use-associated multiple times, and nothing needs to be
36713671
// done after the original symbol is mapped to the threadprivatized value
36723672
// for the first time. Use the threadprivatized value directly.
3673+
mlir::Operation *op;
3674+
if (auto declOp = symValue.getDefiningOp<hlfir::DeclareOp>())
3675+
op = declOp.getMemref().getDefiningOp();
3676+
else
3677+
op = symValue.getDefiningOp();
36733678
if (mlir::isa<mlir::omp::ThreadprivateOp>(op))
36743679
return;
3680+
36753681
symThreadprivateValue = firOpBuilder.create<mlir::omp::ThreadprivateOp>(
36763682
currentLocation, symValue.getType(), symValue);
36773683
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
! This test checks lowering of OpenMP Threadprivate Directive.
2+
! Test for threadprivate variable double use in use association.
3+
4+
!RUN: %flang_fc1 -emit-hlfir -flang-experimental-hlfir -fopenmp %s -o - | FileCheck %s
5+
!RUN: bbc -emit-hlfir -fopenmp %s -o - | FileCheck %s
6+
7+
! CHECK-LABEL: fir.global @_QMmEx : i32
8+
module m
9+
integer :: x
10+
!$omp threadprivate(x)
11+
end
12+
13+
! CHECK-LABEL: func.func @_QMm2Ptest() {
14+
! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QMmEx) : !fir.ref<i32>
15+
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QMmEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
16+
! CHECK: %[[VAL_2:.*]] = omp.threadprivate %[[VAL_1]]#1 : !fir.ref<i32> -> !fir.ref<i32>
17+
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "_QMmEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
18+
! CHECK: fir.call @_QPbar(%[[VAL_3]]#1) {{.*}}: (!fir.ref<i32>) -> ()
19+
! CHECK: return
20+
! CHECK: }
21+
22+
! CHECK-LABEL: func.func @_QMm2FtestPinternal_test() {
23+
! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QMmEx) : !fir.ref<i32>
24+
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QMmEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
25+
! CHECK: %[[VAL_2:.*]] = omp.threadprivate %[[VAL_1]]#1 : !fir.ref<i32> -> !fir.ref<i32>
26+
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "_QMmEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
27+
! CHECK: fir.call @_QPbar(%[[VAL_3]]#1) {{.*}}: (!fir.ref<i32>) -> ()
28+
! CHECK: return
29+
! CHECK: }
30+
31+
module m2
32+
use m
33+
contains
34+
subroutine test()
35+
use m
36+
call bar(x)
37+
contains
38+
subroutine internal_test()
39+
use m
40+
call bar(x)
41+
end
42+
end
43+
end

llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ class CombinerHelper {
255255
/// Replace \p MI with a concat_vectors with \p Ops.
256256
void applyCombineShuffleVector(MachineInstr &MI,
257257
const ArrayRef<Register> Ops);
258+
bool matchShuffleToExtract(MachineInstr &MI);
259+
void applyShuffleToExtract(MachineInstr &MI);
258260

259261
/// Optimize memcpy intrinsics et al, e.g. constant len calls.
260262
/// /p MaxLen if non-zero specifies the max length of a mem libcall to inline.
@@ -449,6 +451,10 @@ class CombinerHelper {
449451
/// Delete \p MI and replace all of its uses with \p Replacement.
450452
void replaceSingleDefInstWithReg(MachineInstr &MI, Register Replacement);
451453

454+
/// @brief Replaces the shift amount in \p MI with ShiftAmt % BW
455+
/// @param MI
456+
void applyFunnelShiftConstantModulo(MachineInstr &MI);
457+
452458
/// Return true if \p MOP1 and \p MOP2 are register operands are defined by
453459
/// equivalent instructions.
454460
bool matchEqualDefs(const MachineOperand &MOP1, const MachineOperand &MOP2);
@@ -461,6 +467,10 @@ class CombinerHelper {
461467
/// equal to \p C.
462468
bool matchConstantFPOp(const MachineOperand &MOP, double C);
463469

470+
/// @brief Checks if constant at \p ConstIdx is larger than \p MI 's bitwidth
471+
/// @param ConstIdx Index of the constant
472+
bool matchConstantLargerBitWidth(MachineInstr &MI, unsigned ConstIdx);
473+
464474
/// Optimize (cond ? x : x) -> x
465475
bool matchSelectSameVal(MachineInstr &MI);
466476

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 473822
19+
#define LLVM_MAIN_REVISION 473831
2020

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

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ def propagate_undef_shuffle_mask: GICombineRule<
353353
[{ return Helper.matchUndefShuffleVectorMask(*${root}); }]),
354354
(apply [{ Helper.replaceInstWithUndef(*${root}); }])>;
355355

356+
// Replace a G_SHUFFLE_VECTOR with a G_EXTRACT_VECTOR_ELT.
357+
def shuffle_to_extract: GICombineRule<
358+
(defs root:$root),
359+
(match (wip_match_opcode G_SHUFFLE_VECTOR):$root,
360+
[{ return Helper.matchShuffleToExtract(*${root}); }]),
361+
(apply [{ Helper.applyShuffleToExtract(*${root}); }])>;
362+
356363
// Replace an insert/extract element of an out of bounds index with undef.
357364
def insert_extract_vec_elt_out_of_bounds : GICombineRule<
358365
(defs root:$root),
@@ -848,6 +855,28 @@ def funnel_shift_to_rotate : GICombineRule<
848855
(apply [{ Helper.applyFunnelShiftToRotate(*${root}); }])
849856
>;
850857

858+
// Fold fshr x, y, 0 -> y
859+
def funnel_shift_right_zero: GICombineRule<
860+
(defs root:$root),
861+
(match (G_FSHR $x, $y, $z, 0):$root),
862+
(apply (COPY $x, $z))
863+
>;
864+
865+
// Fold fshl x, y, 0 -> x
866+
def funnel_shift_left_zero: GICombineRule<
867+
(defs root:$root),
868+
(match (G_FSHL $x, $y, $z, 0):$root),
869+
(apply (COPY $x, $y))
870+
>;
871+
872+
// Fold fsh(l/r) x, y, C -> fsh(l/r) x, y, C % bw
873+
def funnel_shift_overshift: GICombineRule<
874+
(defs root:$root),
875+
(match (wip_match_opcode G_FSHL, G_FSHR):$root,
876+
[{ return Helper.matchConstantLargerBitWidth(*${root}, 3); }]),
877+
(apply [{ Helper.applyFunnelShiftConstantModulo(*${root}); }])
878+
>;
879+
851880
def rotate_out_of_range : GICombineRule<
852881
(defs root:$root),
853882
(match (wip_match_opcode G_ROTR, G_ROTL):$root,
@@ -886,7 +915,10 @@ def bitfield_extract_from_and : GICombineRule<
886915
(apply [{ Helper.applyBuildFn(*${root}, ${info}); }])>;
887916

888917
def funnel_shift_combines : GICombineGroup<[funnel_shift_from_or_shift,
889-
funnel_shift_to_rotate]>;
918+
funnel_shift_to_rotate,
919+
funnel_shift_right_zero,
920+
funnel_shift_left_zero,
921+
funnel_shift_overshift]>;
890922

891923
def bitfield_extract_from_sext_inreg : GICombineRule<
892924
(defs root:$root, build_fn_matchinfo:$info),

0 commit comments

Comments
 (0)