Skip to content

Commit bd53c0b

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:21627236363d629f6a5b820f45a6071371e4b8db into amd-gfx:842efb6db236
Local branch amd-gfx 842efb6 Merged main:e0bd8d3485075d24ecff2b4f5d9e2117853bd08b into amd-gfx:44ce984e8f2a Remote branch main 2162723 [MLIR][XeGPU] Updates XeGPU TensorDescAttr and Refine Gather/Scatter definition. (llvm#109144)
2 parents 842efb6 + 2162723 commit bd53c0b

Some content is hidden

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

49 files changed

+882
-549
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ struct SegmentInfo {
7171
uint64_t FileOffset; /// Offset in the file.
7272
uint64_t FileSize; /// Size in file.
7373
uint64_t Alignment; /// Alignment of the segment.
74+
bool IsExecutable; /// Is the executable bit set on the Segment?
7475

7576
void print(raw_ostream &OS) const {
76-
OS << "SegmentInfo { Address: 0x"
77-
<< Twine::utohexstr(Address) << ", Size: 0x"
78-
<< Twine::utohexstr(Size) << ", FileOffset: 0x"
77+
OS << "SegmentInfo { Address: 0x" << Twine::utohexstr(Address)
78+
<< ", Size: 0x" << Twine::utohexstr(Size) << ", FileOffset: 0x"
7979
<< Twine::utohexstr(FileOffset) << ", FileSize: 0x"
8080
<< Twine::utohexstr(FileSize) << ", Alignment: 0x"
81-
<< Twine::utohexstr(Alignment) << "}";
81+
<< Twine::utohexstr(Alignment) << ", " << (IsExecutable ? "x" : " ")
82+
<< "}";
8283
};
8384
};
8485

bolt/lib/Core/BinaryContext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,9 @@ BinaryContext::getBaseAddressForMapping(uint64_t MMapAddress,
20212021
// Find a segment with a matching file offset.
20222022
for (auto &KV : SegmentMapInfo) {
20232023
const SegmentInfo &SegInfo = KV.second;
2024+
// Only consider executable segments.
2025+
if (!SegInfo.IsExecutable)
2026+
continue;
20242027
// FileOffset is got from perf event,
20252028
// and it is equal to alignDown(SegInfo.FileOffset, pagesize).
20262029
// If the pagesize is not equal to SegInfo.Alignment.

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,8 @@ std::error_code DataAggregator::parseMMapEvents() {
20432043
// size of the mapping, but we know it should not exceed the segment
20442044
// alignment value. Hence we are performing an approximate check.
20452045
return SegInfo.Address >= MMapInfo.MMapAddress &&
2046-
SegInfo.Address - MMapInfo.MMapAddress < SegInfo.Alignment;
2046+
SegInfo.Address - MMapInfo.MMapAddress < SegInfo.Alignment &&
2047+
SegInfo.IsExecutable;
20472048
});
20482049
if (!MatchFound) {
20492050
errs() << "PERF2BOLT-WARNING: ignoring mapping of " << NameToUse

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,9 @@ Error RewriteInstance::discoverStorage() {
526526
NextAvailableOffset = std::max(NextAvailableOffset,
527527
Phdr.p_offset + Phdr.p_filesz);
528528

529-
BC->SegmentMapInfo[Phdr.p_vaddr] = SegmentInfo{Phdr.p_vaddr,
530-
Phdr.p_memsz,
531-
Phdr.p_offset,
532-
Phdr.p_filesz,
533-
Phdr.p_align};
529+
BC->SegmentMapInfo[Phdr.p_vaddr] = SegmentInfo{
530+
Phdr.p_vaddr, Phdr.p_memsz, Phdr.p_offset,
531+
Phdr.p_filesz, Phdr.p_align, ((Phdr.p_flags & ELF::PF_X) != 0)};
534532
if (BC->TheTriple->getArch() == llvm::Triple::x86_64 &&
535533
Phdr.p_vaddr >= BinaryContext::KernelStartX86_64)
536534
BC->IsLinuxKernel = true;

bolt/unittests/Core/BinaryContext.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,14 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
160160
TEST_P(BinaryContextTester, BaseAddress) {
161161
// Check that base address calculation is correct for a binary with the
162162
// following segment layout:
163-
BC->SegmentMapInfo[0] = SegmentInfo{0, 0x10e8c2b4, 0, 0x10e8c2b4, 0x1000};
163+
BC->SegmentMapInfo[0] =
164+
SegmentInfo{0, 0x10e8c2b4, 0, 0x10e8c2b4, 0x1000, true};
164165
BC->SegmentMapInfo[0x10e8d2b4] =
165-
SegmentInfo{0x10e8d2b4, 0x3952faec, 0x10e8c2b4, 0x3952faec, 0x1000};
166+
SegmentInfo{0x10e8d2b4, 0x3952faec, 0x10e8c2b4, 0x3952faec, 0x1000, true};
166167
BC->SegmentMapInfo[0x4a3bddc0] =
167-
SegmentInfo{0x4a3bddc0, 0x148e828, 0x4a3bbdc0, 0x148e828, 0x1000};
168+
SegmentInfo{0x4a3bddc0, 0x148e828, 0x4a3bbdc0, 0x148e828, 0x1000, true};
168169
BC->SegmentMapInfo[0x4b84d5e8] =
169-
SegmentInfo{0x4b84d5e8, 0x294f830, 0x4b84a5e8, 0x3d3820, 0x1000};
170+
SegmentInfo{0x4b84d5e8, 0x294f830, 0x4b84a5e8, 0x3d3820, 0x1000, true};
170171

171172
std::optional<uint64_t> BaseAddress =
172173
BC->getBaseAddressForMapping(0x7f13f5556000, 0x10e8c000);
@@ -181,13 +182,13 @@ TEST_P(BinaryContextTester, BaseAddress2) {
181182
// Check that base address calculation is correct for a binary if the
182183
// alignment in ELF file are different from pagesize.
183184
// The segment layout is as follows:
184-
BC->SegmentMapInfo[0] = SegmentInfo{0, 0x2177c, 0, 0x2177c, 0x10000};
185+
BC->SegmentMapInfo[0] = SegmentInfo{0, 0x2177c, 0, 0x2177c, 0x10000, true};
185186
BC->SegmentMapInfo[0x31860] =
186-
SegmentInfo{0x31860, 0x370, 0x21860, 0x370, 0x10000};
187+
SegmentInfo{0x31860, 0x370, 0x21860, 0x370, 0x10000, true};
187188
BC->SegmentMapInfo[0x41c20] =
188-
SegmentInfo{0x41c20, 0x1f8, 0x21c20, 0x1f8, 0x10000};
189+
SegmentInfo{0x41c20, 0x1f8, 0x21c20, 0x1f8, 0x10000, true};
189190
BC->SegmentMapInfo[0x54e18] =
190-
SegmentInfo{0x54e18, 0x51, 0x24e18, 0x51, 0x10000};
191+
SegmentInfo{0x54e18, 0x51, 0x24e18, 0x51, 0x10000, true};
191192

192193
std::optional<uint64_t> BaseAddress =
193194
BC->getBaseAddressForMapping(0xaaaaea444000, 0x21000);
@@ -197,3 +198,22 @@ TEST_P(BinaryContextTester, BaseAddress2) {
197198
BaseAddress = BC->getBaseAddressForMapping(0xaaaaea444000, 0x11000);
198199
ASSERT_FALSE(BaseAddress.has_value());
199200
}
201+
202+
TEST_P(BinaryContextTester, BaseAddressSegmentsSmallerThanAlignment) {
203+
// Check that the correct segment is used to compute the base address
204+
// when multiple segments are close together in the ELF file (closer
205+
// than the required alignment in the process space).
206+
// See https://github.com/llvm/llvm-project/issues/109384
207+
BC->SegmentMapInfo[0] = SegmentInfo{0, 0x1d1c, 0, 0x1d1c, 0x10000, false};
208+
BC->SegmentMapInfo[0x11d40] =
209+
SegmentInfo{0x11d40, 0x11e0, 0x1d40, 0x11e0, 0x10000, true};
210+
BC->SegmentMapInfo[0x22f20] =
211+
SegmentInfo{0x22f20, 0x10e0, 0x2f20, 0x1f0, 0x10000, false};
212+
BC->SegmentMapInfo[0x33110] =
213+
SegmentInfo{0x33110, 0x89, 0x3110, 0x88, 0x10000, false};
214+
215+
std::optional<uint64_t> BaseAddress =
216+
BC->getBaseAddressForMapping(0xaaaaaaab1000, 0x1000);
217+
ASSERT_TRUE(BaseAddress.has_value());
218+
ASSERT_EQ(*BaseAddress, 0xaaaaaaaa0000ULL);
219+
}

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ Attribute Changes in Clang
273273
not change the behaviour of the compiler, as this was true for previous
274274
versions.
275275

276+
- Fix a bug where clang doesn't automatically apply the ``[[gsl::Owner]]`` or
277+
``[[gsl::Pointer]]`` to STL explicit template specialization decls. (#GH109442)
278+
276279
Improvements to Clang's diagnostics
277280
-----------------------------------
278281

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12587,8 +12587,7 @@ void ASTContext::forEachMultiversionedFunctionVersion(
1258712587
FD->getDeclContext()->getRedeclContext()->lookup(FD->getDeclName())) {
1258812588
FunctionDecl *CurFD = CurDecl->getAsFunction()->getMostRecentDecl();
1258912589
if (CurFD && hasSameType(CurFD->getType(), FD->getType()) &&
12590-
!SeenDecls.contains(CurFD)) {
12591-
SeenDecls.insert(CurFD);
12590+
SeenDecls.insert(CurFD).second) {
1259212591
Pred(CurFD);
1259312592
}
1259412593
}

clang/lib/Frontend/Rewrite/RewriteObjC.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,21 +4358,21 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
43584358
for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) {
43594359
DeclRefExpr *Exp = InnerBlockDeclRefs[i];
43604360
ValueDecl *VD = Exp->getDecl();
4361-
if (!VD->hasAttr<BlocksAttr>() && !BlockByCopyDeclsPtrSet.count(VD)) {
4361+
if (!VD->hasAttr<BlocksAttr>() &&
4362+
BlockByCopyDeclsPtrSet.insert(VD).second) {
43624363
// We need to save the copied-in variables in nested
43634364
// blocks because it is needed at the end for some of the API
43644365
// generations. See SynthesizeBlockLiterals routine.
43654366
InnerDeclRefs.push_back(Exp);
43664367
countOfInnerDecls++;
43674368
BlockDeclRefs.push_back(Exp);
4368-
BlockByCopyDeclsPtrSet.insert(VD);
43694369
BlockByCopyDecls.push_back(VD);
43704370
}
4371-
if (VD->hasAttr<BlocksAttr>() && !BlockByRefDeclsPtrSet.count(VD)) {
4371+
if (VD->hasAttr<BlocksAttr>() &&
4372+
BlockByRefDeclsPtrSet.insert(VD).second) {
43724373
InnerDeclRefs.push_back(Exp);
43734374
countOfInnerDecls++;
43744375
BlockDeclRefs.push_back(Exp);
4375-
BlockByRefDeclsPtrSet.insert(VD);
43764376
BlockByRefDecls.push_back(VD);
43774377
}
43784378
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8631,6 +8631,7 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
86318631
return SkipBody->Previous;
86328632

86338633
Specialization->setInvalidDecl(Invalid);
8634+
inferGslOwnerPointerAttribute(Specialization);
86348635
return Specialization;
86358636
}
86368637

clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class vector {
2727
static_assert(sizeof(vector<int>), ""); // Force instantiation.
2828
static_assert(sizeof(vector<int>::iterator), ""); // Force instantiation.
2929

30+
template <>
31+
class vector<bool> {};
32+
// CHECK: ClassTemplateSpecializationDecl {{.*}} vector
33+
// CHECK: OwnerAttr {{.*}}
34+
3035
// If std::container::iterator is a using declaration, attributes are inferred
3136
// for the underlying class.
3237
template <typename T>
@@ -173,6 +178,18 @@ class reference_wrapper;
173178
class some_unknown_type;
174179
// CHECK: CXXRecordDecl {{.*}} some_unknown_type
175180

181+
using size_t = unsigned;
182+
inline constexpr size_t dynamic_extent = -1;
183+
template <typename _Tp, size_t _Extent = dynamic_extent>
184+
class span;
185+
// CHECK: CXXRecordDecl {{.*}} span
186+
// CHECK: PointerAttr {{.*}}
187+
188+
189+
template <typename _Tp>
190+
struct span<_Tp, dynamic_extent> {};
191+
// CHECK: ClassTemplatePartialSpecializationDecl {{.*}} span
192+
// CHECK: PointerAttr {{.*}}
176193
} // namespace std
177194

178195
namespace user {

compiler-rt/lib/rtsan/rtsan_interceptors.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ INTERCEPTOR(int, open, const char *path, int oflag, ...) {
6464
// O_NONBLOCK
6565
__rtsan_notify_intercepted_call("open");
6666

67-
va_list args;
68-
va_start(args, oflag);
69-
const mode_t mode = va_arg(args, int);
70-
va_end(args);
67+
if (OpenReadsVaArgs(oflag)) {
68+
va_list args;
69+
va_start(args, oflag);
70+
const mode_t mode = va_arg(args, int);
71+
va_end(args);
72+
return REAL(open)(path, oflag, mode);
73+
}
7174

72-
const int result = REAL(open)(path, oflag, mode);
73-
return result;
75+
return REAL(open)(path, oflag);
7476
}
7577

7678
#if SANITIZER_INTERCEPT_OPEN64
@@ -79,13 +81,15 @@ INTERCEPTOR(int, open64, const char *path, int oflag, ...) {
7981
// O_NONBLOCK
8082
__rtsan_notify_intercepted_call("open64");
8183

82-
va_list args;
83-
va_start(args, oflag);
84-
const mode_t mode = va_arg(args, int);
85-
va_end(args);
84+
if (OpenReadsVaArgs(oflag)) {
85+
va_list args;
86+
va_start(args, oflag);
87+
const mode_t mode = va_arg(args, int);
88+
va_end(args);
89+
return REAL(open64)(path, oflag, mode);
90+
}
8691

87-
const int result = REAL(open64)(path, oflag, mode);
88-
return result;
92+
return REAL(open64)(path, oflag);
8993
}
9094
#define RTSAN_MAYBE_INTERCEPT_OPEN64 INTERCEPT_FUNCTION(open64)
9195
#else
@@ -97,13 +101,15 @@ INTERCEPTOR(int, openat, int fd, const char *path, int oflag, ...) {
97101
// O_NONBLOCK
98102
__rtsan_notify_intercepted_call("openat");
99103

100-
va_list args;
101-
va_start(args, oflag);
102-
mode_t mode = va_arg(args, int);
103-
va_end(args);
104+
if (OpenReadsVaArgs(oflag)) {
105+
va_list args;
106+
va_start(args, oflag);
107+
const mode_t mode = va_arg(args, int);
108+
va_end(args);
109+
return REAL(openat)(fd, path, oflag, mode);
110+
}
104111

105-
const int result = REAL(openat)(fd, path, oflag, mode);
106-
return result;
112+
return REAL(openat)(fd, path, oflag);
107113
}
108114

109115
#if SANITIZER_INTERCEPT_OPENAT64
@@ -112,13 +118,15 @@ INTERCEPTOR(int, openat64, int fd, const char *path, int oflag, ...) {
112118
// O_NONBLOCK
113119
__rtsan_notify_intercepted_call("openat64");
114120

115-
va_list args;
116-
va_start(args, oflag);
117-
mode_t mode = va_arg(args, int);
118-
va_end(args);
121+
if (OpenReadsVaArgs(oflag)) {
122+
va_list args;
123+
va_start(args, oflag);
124+
const mode_t mode = va_arg(args, int);
125+
va_end(args);
126+
return REAL(openat64)(fd, path, oflag, mode);
127+
}
119128

120-
const int result = REAL(openat64)(fd, path, oflag, mode);
121-
return result;
129+
return REAL(openat64)(fd, path, oflag);
122130
}
123131
#define RTSAN_MAYBE_INTERCEPT_OPENAT64 INTERCEPT_FUNCTION(openat64)
124132
#else

compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,15 @@ bool ShouldMockFailureToOpen(const char *path) {
353353
internal_strncmp(path, "/proc/", 6) == 0;
354354
}
355355

356-
#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_GO
356+
bool OpenReadsVaArgs(int oflag) {
357+
# ifdef O_TMPFILE
358+
return (oflag & (O_CREAT | O_TMPFILE)) != 0;
359+
# else
360+
return (oflag & O_CREAT) != 0;
361+
# endif
362+
}
363+
364+
# if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_GO
357365
int GetNamedMappingFd(const char *name, uptr size, int *flags) {
358366
if (!common_flags()->decorate_proc_maps || !name)
359367
return -1;

compiler-rt/lib/sanitizer_common/sanitizer_posix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ bool IsStateDetached(int state);
108108
fd_t ReserveStandardFds(fd_t fd);
109109

110110
bool ShouldMockFailureToOpen(const char *path);
111+
bool OpenReadsVaArgs(int oflag);
111112

112113
// Create a non-file mapping with a given /proc/self/maps name.
113114
uptr MmapNamed(void *addr, uptr length, int prot, int flags, const char *name);

compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,13 +1680,23 @@ TSAN_INTERCEPTOR(int, fstat64, int fd, void *buf) {
16801680
#endif
16811681

16821682
TSAN_INTERCEPTOR(int, open, const char *name, int oflag, ...) {
1683-
va_list ap;
1684-
va_start(ap, oflag);
1685-
mode_t mode = va_arg(ap, int);
1686-
va_end(ap);
1683+
mode_t mode = 0;
1684+
if (OpenReadsVaArgs(oflag)) {
1685+
va_list ap;
1686+
va_start(ap, oflag);
1687+
mode = va_arg(ap, int);
1688+
va_end(ap);
1689+
}
1690+
16871691
SCOPED_TSAN_INTERCEPTOR(open, name, oflag, mode);
16881692
READ_STRING(thr, pc, name, 0);
1689-
int fd = REAL(open)(name, oflag, mode);
1693+
1694+
int fd;
1695+
if (OpenReadsVaArgs(oflag))
1696+
fd = REAL(open)(name, oflag, mode);
1697+
else
1698+
fd = REAL(open)(name, oflag);
1699+
16901700
if (fd >= 0)
16911701
FdFileCreate(thr, pc, fd);
16921702
return fd;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ class CombinerHelper {
600600
bool matchRotateOutOfRange(MachineInstr &MI);
601601
void applyRotateOutOfRange(MachineInstr &MI);
602602

603+
bool matchUseVectorTruncate(MachineInstr &MI, Register &MatchInfo);
604+
void applyUseVectorTruncate(MachineInstr &MI, Register &MatchInfo);
605+
603606
/// \returns true if a G_ICMP instruction \p MI can be replaced with a true
604607
/// or false constant based off of KnownBits information.
605608
bool matchICmpToTrueFalseKnownBits(MachineInstr &MI, int64_t &MatchInfo);

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 512720
19+
#define LLVM_MAIN_REVISION 512734
2020

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

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,13 @@ def insert_vector_elt_oob : GICombineRule<
15051505
[{ return Helper.matchInsertVectorElementOOB(*${root}, ${matchinfo}); }]),
15061506
(apply [{ Helper.applyBuildFn(*${root}, ${matchinfo}); }])>;
15071507

1508+
// Combine v8i8 (buildvector i8 (trunc(unmerge)), i8 (trunc), i8 (trunc), i8 (trunc), undef, undef, undef, undef)
1509+
def combine_use_vector_truncate : GICombineRule<
1510+
(defs root:$root, register_matchinfo:$matchinfo),
1511+
(match (G_BUILD_VECTOR $dst, GIVariadic<>:$unused):$root,
1512+
[{ return Helper.matchUseVectorTruncate(*${root}, ${matchinfo}); }]),
1513+
(apply [{ Helper.applyUseVectorTruncate(*${root}, ${matchinfo}); }])>;
1514+
15081515
def add_of_vscale : GICombineRule<
15091516
(defs root:$root, build_fn_matchinfo:$matchinfo),
15101517
(match (G_VSCALE $left, $imm1),
@@ -1912,7 +1919,8 @@ def all_combines : GICombineGroup<[integer_reassoc_combines, trivial_combines,
19121919
sub_add_reg, select_to_minmax,
19131920
fsub_to_fneg, commute_constant_to_rhs, match_ands, match_ors,
19141921
combine_concat_vector, match_addos,
1915-
sext_trunc, zext_trunc, prefer_sign_combines, combine_shuffle_concat]>;
1922+
sext_trunc, zext_trunc, prefer_sign_combines, combine_shuffle_concat,
1923+
combine_use_vector_truncate]>;
19161924

19171925
// A combine group used to for prelegalizer combiners at -O0. The combines in
19181926
// this group have been selected based on experiments to balance code size and

0 commit comments

Comments
 (0)