Skip to content

Commit 0477ebb

Browse files
committed
merge main into amd-staging
Change-Id: Ib6edc1bc19753be990e148197d453a229cab8a66
2 parents 6a31211 + 37f42cf commit 0477ebb

File tree

56 files changed

+799
-445
lines changed

Some content is hidden

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

56 files changed

+799
-445
lines changed

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ Improvements to clang-tidy
112112
the configuration options of the `Clang Static Analyzer Checks
113113
<https://clang.llvm.org/docs/analyzer/checkers.html>`_.
114114

115+
- Improved :program:`clang-tidy` by accepting parameters file in command line.
116+
115117
- Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise
116118
happening on certain platforms when interrupting the script.
117119

118-
- Improved :program:`clang-tidy` by accepting parameters file in command line.
119-
120120
- Removed :program:`clang-tidy`'s global options for most of checks. All options
121121
are changed to local options except `IncludeStyle`, `StrictMode` and
122122
`IgnoreMacros`. Global scoped `StrictMode` and `IgnoreMacros` are deprecated
@@ -292,7 +292,7 @@ Changes in existing checks
292292
overloaded ``operator new`` and ``operator delete``.
293293

294294
- Improved :doc:`modernize-avoid-c-arrays
295-
<clang-tidy/checks/modernize/avoid-c-arrays>` check to suggest using
295+
<clang-tidy/checks/modernize/avoid-c-arrays>` check to suggest using
296296
``std::span`` as a replacement for parameters of incomplete C array type in
297297
C++20 and ``std::array`` or ``std::vector`` before C++20.
298298

clang/bindings/python/clang/cindex.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,10 @@ def spelling(self):
27012701
"""Retrieve the spelling of this Type."""
27022702
return _CXString.from_result(conf.lib.clang_getTypeSpelling(self))
27032703

2704+
def pretty_printed(self, policy):
2705+
"""Pretty-prints this Type with the given PrintingPolicy"""
2706+
return _CXString.from_result(conf.lib.clang_getTypePrettyPrinted(self, policy))
2707+
27042708
def __eq__(self, other):
27052709
if type(other) != type(self):
27062710
return False
@@ -3955,6 +3959,7 @@ def set_property(self, property, value):
39553959
("clang_getTypedefDeclUnderlyingType", [Cursor], Type),
39563960
("clang_getTypedefName", [Type], _CXString),
39573961
("clang_getTypeKindSpelling", [c_uint], _CXString),
3962+
("clang_getTypePrettyPrinted", [Type, PrintingPolicy], _CXString),
39583963
("clang_getTypeSpelling", [Type], _CXString),
39593964
("clang_hashCursor", [Cursor], c_uint),
39603965
("clang_isAttribute", [CursorKind], bool),

clang/bindings/python/tests/cindex/test_type.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import os
22

3-
from clang.cindex import Config, CursorKind, RefQualifierKind, TranslationUnit, TypeKind
3+
from clang.cindex import (
4+
Config,
5+
CursorKind,
6+
PrintingPolicy,
7+
PrintingPolicyProperty,
8+
RefQualifierKind,
9+
TranslationUnit,
10+
TypeKind,
11+
)
412

513
if "CLANG_LIBRARY_PATH" in os.environ:
614
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
@@ -517,3 +525,12 @@ class Template {
517525
# Variable without a template argument.
518526
cursor = get_cursor(tu, "bar")
519527
self.assertEqual(cursor.get_num_template_arguments(), -1)
528+
529+
def test_pretty(self):
530+
tu = get_tu("struct X {}; X x;", lang="cpp")
531+
f = get_cursor(tu, "x")
532+
533+
pp = PrintingPolicy.create(f)
534+
self.assertEqual(f.type.get_canonical().pretty_printed(pp), "X")
535+
pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False)
536+
self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X")

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,8 @@ libclang
12161216
--------
12171217
- Add ``clang_isBeforeInTranslationUnit``. Given two source locations, it determines
12181218
whether the first one comes strictly before the second in the source code.
1219+
- Add ``clang_getTypePrettyPrinted``. It allows controlling the PrintingPolicy used
1220+
to pretty-print a type.
12191221

12201222
Static Analyzer
12211223
---------------
@@ -1356,10 +1358,13 @@ Sanitizers
13561358
Python Binding Changes
13571359
----------------------
13581360
- Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``.
1359-
- Added bindings for ``clang_getCursorPrettyPrinted`` and related functions,
1360-
which allow changing the formatting of pretty-printed code.
1361-
- Added binding for ``clang_Cursor_isAnonymousRecordDecl``, which allows checking if
1362-
a declaration is an anonymous union or anonymous struct.
1361+
- Added ``Cursor.pretty_printed``, a binding for ``clang_getCursorPrettyPrinted``,
1362+
and related functions, which allow changing the formatting of pretty-printed code.
1363+
- Added ``Cursor.is_anonymous_record_decl``, a binding for
1364+
``clang_Cursor_isAnonymousRecordDecl``, which allows checking if a
1365+
declaration is an anonymous union or anonymous struct.
1366+
- Added ``Type.pretty_printed`, a binding for ``clang_getTypePrettyPrinted``,
1367+
which allows changing the formatting of pretty-printed types.
13631368

13641369
OpenMP Support
13651370
--------------

clang/docs/UsersManual.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,38 @@ indexed format, regardeless whether it is produced by frontend or the IR pass.
30353035
overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported
30363036
by the target, or ``single`` otherwise.
30373037

3038+
.. option:: -ftemporal-profile
3039+
3040+
Enables the temporal profiling extension for IRPGO to improve startup time by
3041+
reducing ``.text`` section page faults. To do this, we instrument function
3042+
timestamps to measure when each function is called for the first time and use
3043+
this data to generate a function order to improve startup.
3044+
3045+
The profile is generated as normal.
3046+
3047+
.. code-block:: console
3048+
3049+
$ clang++ -O2 -fprofile-generate -ftemporal-profile code.cc -o code
3050+
$ ./code
3051+
$ llvm-profdata merge -o code.profdata yyy/zzz
3052+
3053+
Using the resulting profile, we can generate a function order to pass to the
3054+
linker via `--symbol-ordering-file` for ELF or `-order_file` for Mach-O.
3055+
3056+
.. code-block:: console
3057+
3058+
$ llvm-profdata order code.profdata -o code.orderfile
3059+
$ clang++ -O2 -Wl,--symbol-ordering-file=code.orderfile code.cc -o code
3060+
3061+
Or the profile can be passed to LLD directly.
3062+
3063+
.. code-block:: console
3064+
3065+
$ clang++ -O2 -fuse-ld=lld -Wl,--irpgo-profile=code.profdata,--bp-startup-sort=function code.cc -o code
3066+
3067+
For more information, please read the RFC:
3068+
https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068
3069+
30383070
Fine Tuning Profile Collection
30393071
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30403072

clang/include/clang-c/Index.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4182,6 +4182,14 @@ CINDEX_LINKAGE void clang_PrintingPolicy_dispose(CXPrintingPolicy Policy);
41824182
CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor,
41834183
CXPrintingPolicy Policy);
41844184

4185+
/**
4186+
* Pretty-print the underlying type using a custom printing policy.
4187+
*
4188+
* If the type is invalid, an empty string is returned.
4189+
*/
4190+
CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT,
4191+
CXPrintingPolicy cxPolicy);
4192+
41854193
/**
41864194
* Retrieve the display name for the entity referenced by this cursor.
41874195
*

clang/include/clang/Basic/Sanitizers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ struct SanitizerSet {
171171
return static_cast<bool>(Mask & K);
172172
}
173173

174+
bool has(SanitizerKind::SanitizerOrdinal O) const {
175+
return has(SanitizerMask::bitPosToMask(O));
176+
}
177+
174178
/// Check if one or more sanitizers are enabled.
175179
bool hasOneOf(SanitizerMask K) const { return static_cast<bool>(Mask & K); }
176180

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,9 @@ def fprofile_generate_cold_function_coverage : Flag<["-"], "fprofile-generate-co
18011801
def fprofile_generate_cold_function_coverage_EQ : Joined<["-"], "fprofile-generate-cold-function-coverage=">,
18021802
Group<f_Group>, Visibility<[ClangOption, CLOption]>, MetaVarName<"<directory>">,
18031803
HelpText<"Generate instrumented code to collect coverage info for cold functions into <directory>/default.profraw (overridden by LLVM_PROFILE_FILE env var)">;
1804+
def ftemporal_profile : Flag<["-"], "ftemporal-profile">,
1805+
Group<f_Group>, Visibility<[ClangOption, CLOption]>,
1806+
HelpText<"Generate instrumented code to collect temporal information">;
18041807
def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
18051808
Group<f_Group>, Visibility<[ClangOption, CLOption]>,
18061809
HelpText<"Generate instrumented code to collect execution counts into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
@@ -1896,7 +1899,7 @@ defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
18961899
" pseudo probes for sample profiling">>;
18971900
def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
18981901
Group<f_Group>, Visibility<[ClangOption, CC1Option, CLOption]>,
1899-
HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var). Deprecated, please use temporal profiling.">;
1902+
HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var). Deprecated, please use -ftemporal-profile">;
19001903
def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
19011904
Group<f_Group>, Visibility<[ClangOption, CC1Option, CLOption]>,
19021905
HelpText<"Filename defining the list of functions/files to instrument. "

clang/lib/Basic/Targets.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -726,31 +726,31 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
726726
case llvm::Triple::csky:
727727
switch (os) {
728728
case llvm::Triple::Linux:
729-
return std::make_unique<LinuxTargetInfo<CSKYTargetInfo>>(Triple, Opts);
729+
return std::make_unique<LinuxTargetInfo<CSKYTargetInfo>>(Triple, Opts);
730730
default:
731-
return std::make_unique<CSKYTargetInfo>(Triple, Opts);
731+
return std::make_unique<CSKYTargetInfo>(Triple, Opts);
732732
}
733733
case llvm::Triple::loongarch32:
734734
switch (os) {
735735
case llvm::Triple::Linux:
736-
return std::make_unique<LinuxTargetInfo<LoongArch32TargetInfo>>(Triple,
737-
Opts);
736+
return std::make_unique<LinuxTargetInfo<LoongArch32TargetInfo>>(Triple,
737+
Opts);
738738
case llvm::Triple::FreeBSD:
739739
return std::make_unique<FreeBSDTargetInfo<LoongArch32TargetInfo>>(Triple,
740740
Opts);
741741
default:
742-
return std::make_unique<LoongArch32TargetInfo>(Triple, Opts);
742+
return std::make_unique<LoongArch32TargetInfo>(Triple, Opts);
743743
}
744744
case llvm::Triple::loongarch64:
745745
switch (os) {
746746
case llvm::Triple::Linux:
747-
return std::make_unique<LinuxTargetInfo<LoongArch64TargetInfo>>(Triple,
748-
Opts);
747+
return std::make_unique<LinuxTargetInfo<LoongArch64TargetInfo>>(Triple,
748+
Opts);
749749
case llvm::Triple::FreeBSD:
750750
return std::make_unique<FreeBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
751751
Opts);
752752
default:
753-
return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
753+
return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
754754
}
755755

756756
case llvm::Triple::xtensa:

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
447447
case llvm::Triple::sparcv9:
448448
this->MCountName = "_mcount";
449449
break;
450-
case llvm::Triple::riscv32:
451450
case llvm::Triple::riscv64:
452451
break;
453452
}

0 commit comments

Comments
 (0)