Skip to content

Commit 69f62a0

Browse files
committed
merge main into amd-staging
Change-Id: Id0b4149c9d730a84fc55bc3ed2bf205f54788576
2 parents 0d906ed + 458a315 commit 69f62a0

File tree

140 files changed

+3708
-1657
lines changed

Some content is hidden

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

140 files changed

+3708
-1657
lines changed

bolt/docs/CommandLineArgumentReference.md

Lines changed: 89 additions & 138 deletions
Large diffs are not rendered by default.

bolt/docs/generate_doc.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env python3
2+
# A tool to parse the output of `llvm-bolt --help-hidden` and update the
3+
# documentation in CommandLineArgumentReference.md automatically.
4+
# Run from the directory in which this file is located to update the docs.
5+
6+
import subprocess
7+
from textwrap import wrap
8+
9+
LINE_LIMIT = 80
10+
11+
12+
def wrap_text(text, indent, limit=LINE_LIMIT):
13+
wrapped_lines = wrap(text, width=limit - len(indent))
14+
wrapped_text = ("\n" + indent).join(wrapped_lines)
15+
return wrapped_text
16+
17+
18+
def add_info(sections, section, option, description):
19+
indent = " "
20+
wrapped_description = "\n".join(
21+
[
22+
wrap_text(line, indent) if len(line) > LINE_LIMIT else line
23+
for line in description
24+
]
25+
)
26+
sections[section].append((option, indent + wrapped_description))
27+
28+
29+
def parse_bolt_options(output):
30+
section_headers = [
31+
"Generic options:",
32+
"Output options:",
33+
"BOLT generic options:",
34+
"BOLT optimization options:",
35+
"BOLT options in relocation mode:",
36+
"BOLT instrumentation options:",
37+
"BOLT printing options:",
38+
]
39+
40+
sections = {key: [] for key in section_headers}
41+
current_section, prev_section = None, None
42+
option, description = None, []
43+
44+
for line in output.split("\n"):
45+
cleaned_line = line.strip()
46+
47+
if cleaned_line.casefold() in map(str.casefold, section_headers):
48+
if prev_section != None: # Save last option from prev section
49+
add_info(sections, current_section, option, description)
50+
option, description = None, []
51+
52+
cleaned_line = cleaned_line.split()
53+
# Apply lowercase to all words except the first one
54+
cleaned_line = [cleaned_line[0]] + [
55+
word.lower() for word in cleaned_line[1:]
56+
]
57+
# Join the words back together into a string
58+
cleaned_line = " ".join(cleaned_line)
59+
60+
current_section = cleaned_line
61+
prev_section = current_section
62+
continue
63+
64+
if cleaned_line.startswith("-"):
65+
if option and description:
66+
# Join description lines, adding an extra newline for
67+
# sub-options that start with '='
68+
add_info(sections, current_section, option, description)
69+
option, description = None, []
70+
71+
parts = cleaned_line.split(" ", 1)
72+
if len(parts) > 1:
73+
option = parts[0].strip()
74+
descr = parts[1].strip()
75+
descr = descr[2].upper() + descr[3:]
76+
description = [descr]
77+
if option.startswith("--print") or option.startswith("--time"):
78+
current_section = "BOLT printing options:"
79+
elif prev_section != None:
80+
current_section = prev_section
81+
continue
82+
83+
if cleaned_line.startswith("="):
84+
parts = cleaned_line.split(maxsplit=1)
85+
# Split into two parts: sub-option and description
86+
if len(parts) == 2:
87+
# Rejoin with a single space
88+
cleaned_line = parts[0] + " " + parts[1].rstrip()
89+
description.append(cleaned_line)
90+
elif cleaned_line: # Multiline description continuation
91+
description.append(cleaned_line)
92+
93+
add_info(sections, current_section, option, description)
94+
return sections
95+
96+
97+
def generate_markdown(sections):
98+
markdown_lines = [
99+
"# BOLT - a post-link optimizer developed to speed up large applications\n",
100+
"## SYNOPSIS\n",
101+
"`llvm-bolt <executable> [-o outputfile] <executable>.bolt "
102+
"[-data=perf.fdata] [options]`\n",
103+
"## OPTIONS",
104+
]
105+
106+
for section, options in sections.items():
107+
markdown_lines.append(f"\n### {section}")
108+
if section == "BOLT instrumentation options:":
109+
markdown_lines.append(
110+
f"\n`llvm-bolt <executable> -instrument"
111+
" [-o outputfile] <instrumented-executable>`"
112+
)
113+
for option, desc in options:
114+
markdown_lines.append(f"\n- `{option}`\n")
115+
# Split description into lines to handle sub-options
116+
desc_lines = desc.split("\n")
117+
for line in desc_lines:
118+
if line.startswith("="):
119+
# Sub-option: correct formatting with bullet
120+
sub_option, sub_desc = line[1:].split(" ", 1)
121+
markdown_lines.append(f" - `{sub_option}`: {sub_desc[4:]}")
122+
else:
123+
# Regular line of description
124+
if line[2:].startswith("<"):
125+
line = line.replace("<", "").replace(">", "")
126+
markdown_lines.append(f"{line}")
127+
128+
return "\n".join(markdown_lines)
129+
130+
131+
def main():
132+
try:
133+
help_output = subprocess.run(
134+
["llvm-bolt", "--help-hidden"], capture_output=True, text=True, check=True
135+
).stdout
136+
except subprocess.CalledProcessError as e:
137+
print("Failed to execute llvm-bolt --help:")
138+
print(e)
139+
return
140+
141+
sections = parse_bolt_options(help_output)
142+
markdown = generate_markdown(sections)
143+
144+
with open("CommandLineArgumentReference.md", "w") as md_file:
145+
md_file.write(markdown)
146+
147+
148+
if __name__ == "__main__":
149+
main()

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static cl::opt<bool> CreateDebugNames(
352352

353353
static cl::opt<bool>
354354
DebugSkeletonCu("debug-skeleton-cu",
355-
cl::desc("prints out offsetrs for abbrev and debu_info of "
355+
cl::desc("prints out offsets for abbrev and debug_info of "
356356
"Skeleton CUs that get patched."),
357357
cl::ZeroOrMore, cl::Hidden, cl::init(false),
358358
cl::cat(BoltCategory));

clang/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ on the Clang forums:
2323
https://discourse.llvm.org/c/clang/
2424

2525
If you find a bug in Clang, please file it in the LLVM bug tracker:
26-
http://llvm.org/bugs/
26+
https://github.com/llvm/llvm-project/issues

clang/docs/UsersManual.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,9 +4430,9 @@ To generate SPIR-V binaries, Clang uses the external ``llvm-spirv`` tool from th
44304430
Prior to the generation of SPIR-V binary with Clang, ``llvm-spirv``
44314431
should be built or installed. Please refer to `the following instructions
44324432
<https://github.com/KhronosGroup/SPIRV-LLVM-Translator#build-instructions>`_
4433-
for more details. Clang will expect the ``llvm-spirv`` executable to
4434-
be present in the ``PATH`` environment variable. Clang uses ``llvm-spirv``
4435-
with `the widely adopted assembly syntax package
4433+
for more details. Clang will look for ``llvm-spirv-<LLVM-major-version>`` and
4434+
``llvm-spirv`` executables, in this order, in the ``PATH`` environment variable.
4435+
Clang uses ``llvm-spirv`` with `the widely adopted assembly syntax package
44364436
<https://github.com/KhronosGroup/SPIRV-LLVM-Translator/#build-with-spirv-tools>`_.
44374437

44384438
`The versioning

clang/docs/analyzer/checkers.rst

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,17 +3135,42 @@ alpha.unix
31353135
alpha.unix.BlockInCriticalSection (C)
31363136
"""""""""""""""""""""""""""""""""""""
31373137
Check for calls to blocking functions inside a critical section.
3138-
Applies to: ``lock, unlock, sleep, getc, fgets, read, recv, pthread_mutex_lock,``
3139-
`` pthread_mutex_unlock, mtx_lock, mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock``
3138+
Blocking functions detected by this checker: ``sleep, getc, fgets, read, recv``.
3139+
Critical section handling functions modelled by this checker: ``lock, unlock, pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_unlock, mtx_lock, mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock``.
31403140
31413141
.. code-block:: c
31423142
3143-
void test() {
3144-
std::mutex m;
3145-
m.lock();
3146-
sleep(3); // warn: a blocking function sleep is called inside a critical
3147-
// section
3148-
m.unlock();
3143+
void pthread_lock_example(pthread_mutex_t *m) {
3144+
pthread_mutex_lock(m); // note: entering critical section here
3145+
sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
3146+
pthread_mutex_unlock(m);
3147+
}
3148+
3149+
.. code-block:: cpp
3150+
3151+
void overlapping_critical_sections(mtx_t *m1, std::mutex &m2) {
3152+
std::lock_guard lg{m2}; // note: entering critical section here
3153+
mtx_lock(m1); // note: entering critical section here
3154+
sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
3155+
mtx_unlock(m1);
3156+
sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
3157+
// still inside of the critical section of the std::lock_guard
3158+
}
3159+
3160+
**Limitations**
3161+
3162+
* The ``trylock`` and ``timedlock`` versions of acquiring locks are currently assumed to always succeed.
3163+
This can lead to false positives.
3164+
3165+
.. code-block:: c
3166+
3167+
void trylock_example(pthread_mutex_t *m) {
3168+
if (pthread_mutex_trylock(m) == 0) { // assume trylock always succeeds
3169+
sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
3170+
pthread_mutex_unlock(m);
3171+
} else {
3172+
sleep(10); // false positive: Incorrect warning about blocking function inside critical section.
3173+
}
31493174
}
31503175
31513176
.. _alpha-unix-Chroot:

clang/include/clang/Basic/CustomizableOptional.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,6 @@ template <typename T> class CustomizableOptional {
9797
template <typename U> T value_or(U &&alt) && {
9898
return has_value() ? std::move(operator*()) : std::forward<U>(alt);
9999
}
100-
101-
// Allow conversion to std::optional<T>.
102-
explicit operator std::optional<T> &() const & {
103-
return *this ? **this : std::optional<T>();
104-
}
105-
explicit operator std::optional<T> &&() const && {
106-
return *this ? std::move(**this) : std::optional<T>();
107-
}
108100
};
109101

110102
template <typename T>

clang/lib/Driver/ToolChains/SPIRV.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88
#include "SPIRV.h"
99
#include "CommonArgs.h"
10+
#include "clang/Basic/Version.h"
1011
#include "clang/Driver/Compilation.h"
1112
#include "clang/Driver/Driver.h"
1213
#include "clang/Driver/InputInfo.h"
@@ -32,8 +33,15 @@ void SPIRV::constructTranslateCommand(Compilation &C, const Tool &T,
3233

3334
CmdArgs.append({"-o", Output.getFilename()});
3435

35-
const char *Exec =
36-
C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
36+
// Try to find "llvm-spirv-<LLVM_VERSION_MAJOR>". Otherwise, fall back to
37+
// plain "llvm-spirv".
38+
using namespace std::string_literals;
39+
auto VersionedTool = "llvm-spirv-"s + std::to_string(LLVM_VERSION_MAJOR);
40+
std::string ExeCand = T.getToolChain().GetProgramPath(VersionedTool.c_str());
41+
if (!llvm::sys::fs::can_execute(ExeCand))
42+
ExeCand = T.getToolChain().GetProgramPath("llvm-spirv");
43+
44+
const char *Exec = C.getArgs().MakeArgString(ExeCand);
3745
C.addCommand(std::make_unique<Command>(JA, T, ResponseFileSupport::None(),
3846
Exec, CmdArgs, Input, Output));
3947
}

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,27 @@ bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind,
246246
return false;
247247
}
248248

249+
case OpenACCClauseKind::DeviceType:
250+
case OpenACCClauseKind::DType:
251+
switch (DirectiveKind) {
252+
case OpenACCDirectiveKind::Parallel:
253+
case OpenACCDirectiveKind::Serial:
254+
case OpenACCDirectiveKind::Kernels:
255+
case OpenACCDirectiveKind::Data:
256+
case OpenACCDirectiveKind::Init:
257+
case OpenACCDirectiveKind::Shutdown:
258+
case OpenACCDirectiveKind::Set:
259+
case OpenACCDirectiveKind::Update:
260+
case OpenACCDirectiveKind::Loop:
261+
case OpenACCDirectiveKind::Routine:
262+
case OpenACCDirectiveKind::ParallelLoop:
263+
case OpenACCDirectiveKind::SerialLoop:
264+
case OpenACCDirectiveKind::KernelsLoop:
265+
return true;
266+
default:
267+
return false;
268+
}
269+
249270
default:
250271
// Do nothing so we can go to the 'unimplemented' diagnostic instead.
251272
return true;

clang/test/Analysis/block-in-critical-section.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ ssize_t read(int fd, void *buf, size_t count);
3636
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
3737

3838
struct pthread_mutex_t;
39-
void pthread_mutex_lock(pthread_mutex_t *mutex);
40-
void pthread_mutex_trylock(pthread_mutex_t *mutex);
41-
void pthread_mutex_unlock(pthread_mutex_t *mutex);
39+
int pthread_mutex_lock(pthread_mutex_t *mutex);
40+
int pthread_mutex_trylock(pthread_mutex_t *mutex);
41+
int pthread_mutex_unlock(pthread_mutex_t *mutex);
4242

4343
struct mtx_t;
44-
void mtx_lock(mtx_t *mutex);
45-
void mtx_timedlock(mtx_t *mutex);
46-
void mtx_trylock(mtx_t *mutex);
47-
void mtx_unlock(mtx_t *mutex);
44+
int mtx_lock(mtx_t *mutex);
45+
int mtx_timedlock(mtx_t *mutex);
46+
int mtx_trylock(mtx_t *mutex);
47+
int mtx_unlock(mtx_t *mutex);
4848

4949
// global params for dummy function calls
5050
FILE *stream;
@@ -292,3 +292,20 @@ void testBlockInCriticalSectionUniqueLockNested() {
292292
testBlockInCriticalSectionUniqueLock(); // expected-note {{Calling 'testBlockInCriticalSectionUniqueLock'}}
293293
sleep(1); // no-warning
294294
}
295+
296+
void testTrylockCurrentlyFalsePositive(pthread_mutex_t *m) {
297+
// expected-note@+4 {{Assuming the condition is true}}
298+
// expected-note@+3 {{Taking true branch}}
299+
// expected-note@+2 {{Assuming the condition is false}}
300+
// expected-note@+1 {{Taking false branch}}
301+
if (pthread_mutex_trylock(m) == 0) { // expected-note 2 {{Entering critical section here}}
302+
// FIXME: we are entering the critical section only in the true branch
303+
sleep(10); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
304+
// expected-note@-1 {{Call to blocking function 'sleep' inside of critical section}}
305+
pthread_mutex_unlock(m);
306+
} else {
307+
sleep(10); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
308+
// expected-note@-1 {{Call to blocking function 'sleep' inside of critical section}}
309+
// FIXME: this is a false positive, the lock was not acquired
310+
}
311+
}

clang/test/C/C11/n1464.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// expected-no-diagnostics
3+
4+
/* WG14 N1464: ???
5+
* Creation of complex value
6+
*/
7+
8+
// The paper is about the CMPLX macros, which Clang supports via the
9+
// __builtin_complex builtin function. Test the basic functionality.
10+
_Static_assert(__builtin_complex(5.0, 2.0) == 5.0 + 1.0j * 2.0, "");
11+
_Static_assert(__builtin_complex(5.0f, 2.0f) == 5.0f + 1.0j * 2.0f, "");
12+
_Static_assert(__builtin_complex(5.0L, 2.0L) == 5.0L + 1.0j * 2.0L, "");
13+
14+
// Test the edge case involving NaN or infinity.
15+
#define INF(type) (type)__builtin_inf()
16+
#define NAN(type) (type)__builtin_nan("")
17+
_Static_assert(__builtin_complex(5.0f, INF(float)) != 5.0f + 1.0j * INF(float), "");
18+
_Static_assert(__builtin_complex(5.0, INF(double)) != 5.0 + 1.0j * INF(double), "");
19+
_Static_assert(__builtin_complex(5.0L, INF(long double)) != 5.0L + 1.0j * INF(long double), "");
20+
_Static_assert(__builtin_complex(5.0f, NAN(float)) != 5.0f + 1.0j * NAN(float), "");
21+
_Static_assert(__builtin_complex(5.0, NAN(double)) != 5.0 + 1.0j * NAN(double), "");
22+
_Static_assert(__builtin_complex(5.0L, NAN(long double)) != 5.0L + 1.0j * NAN(long double), "");

clang/test/Driver/amdgpu-macros.cl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx10_1_generic -DFAMILY=GFX10
136136
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx10-3-generic %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx10_3_generic -DFAMILY=GFX10
137137
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx11_generic -DFAMILY=GFX11
138+
// RUN: %clang -E -dM -target amdgcn -mcpu=gfx12-generic %s 2>&1 | FileCheck --check-prefixes=ARCH-GCN,FAST_FMAF %s -DWAVEFRONT_SIZE=32 -DCPU=gfx12_generic -DFAMILY=GFX12
138139

139140
// ARCH-GCN-DAG: #define FP_FAST_FMA 1
140141

clang/test/Driver/amdgpu-mcpu.cl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
// RUN: %clang -### -target amdgcn -mcpu=gfx10-1-generic %s 2>&1 | FileCheck --check-prefix=GFX10_1_GENERIC %s
120120
// RUN: %clang -### -target amdgcn -mcpu=gfx10-3-generic %s 2>&1 | FileCheck --check-prefix=GFX10_3_GENERIC %s
121121
// RUN: %clang -### -target amdgcn -mcpu=gfx11-generic %s 2>&1 | FileCheck --check-prefix=GFX11_GENERIC %s
122+
// RUN: %clang -### -target amdgcn -mcpu=gfx12-generic %s 2>&1 | FileCheck --check-prefix=GFX12_GENERIC %s
122123

123124
// GCNDEFAULT-NOT: -target-cpu
124125
// GFX600: "-target-cpu" "gfx600"
@@ -170,3 +171,4 @@
170171
// GFX10_1_GENERIC: "-target-cpu" "gfx10-1-generic"
171172
// GFX10_3_GENERIC: "-target-cpu" "gfx10-3-generic"
172173
// GFX11_GENERIC: "-target-cpu" "gfx11-generic"
174+
// GFX12_GENERIC: "-target-cpu" "gfx12-generic"

0 commit comments

Comments
 (0)