Skip to content

Commit 3f2aa1d

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3237)
2 parents a42eb5e + afa9520 commit 3f2aa1d

File tree

256 files changed

+10280
-12797
lines changed

Some content is hidden

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

256 files changed

+10280
-12797
lines changed

bolt/utils/nfc-check-setup.py

Lines changed: 102 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import sys
88
import textwrap
99

10+
msg_prefix = "\n> NFC-Mode:"
11+
1012
def get_relevant_bolt_changes(dir: str) -> str:
1113
# Return a list of bolt source changes that are relevant to testing.
1214
all_changes = subprocess.run(
@@ -42,14 +44,32 @@ def get_git_ref_or_rev(dir: str) -> str:
4244
cmd_rev = "git rev-parse --short HEAD"
4345
return subprocess.check_output(shlex.split(cmd_rev), cwd=dir, text=True).strip()
4446

47+
def switch_back(
48+
switch_back: bool, stash: bool, source_dir: str, old_ref: str, new_ref: str
49+
):
50+
# Switch back to the current revision if needed and inform the user of where
51+
# the HEAD is. Must be called after checking out the previous commit on all
52+
# exit paths.
53+
if switch_back:
54+
print(f"{msg_prefix} Switching back to current revision..")
55+
if stash:
56+
subprocess.run(shlex.split("git stash pop"), cwd=source_dir)
57+
subprocess.run(shlex.split(f"git checkout {old_ref}"), cwd=source_dir)
58+
else:
59+
print(
60+
f"The repository {source_dir} has been switched from {old_ref} "
61+
f"to {new_ref}. Local changes were stashed. Switch back using\n\t"
62+
f"git checkout {old_ref}\n"
63+
)
4564

4665
def main():
4766
parser = argparse.ArgumentParser(
4867
description=textwrap.dedent(
4968
"""
50-
This script builds two versions of BOLT (with the current and
51-
previous revision) and sets up symlink for llvm-bolt-wrapper.
52-
Passes the options through to llvm-bolt-wrapper.
69+
This script builds two versions of BOLT:
70+
llvm-bolt.new, using the current revision, and llvm-bolt.old using
71+
the previous revision. These can be used to check whether the
72+
current revision changes BOLT's functional behavior.
5373
"""
5474
)
5575
)
@@ -59,6 +79,12 @@ def main():
5979
default=os.getcwd(),
6080
help="Path to BOLT build directory, default is current " "directory",
6181
)
82+
parser.add_argument(
83+
"--create-wrapper",
84+
default=False,
85+
action="store_true",
86+
help="Sets up llvm-bolt as a symlink to llvm-bolt-wrapper. Passes the options through to llvm-bolt-wrapper.",
87+
)
6288
parser.add_argument(
6389
"--check-bolt-sources",
6490
default=False,
@@ -76,28 +102,42 @@ def main():
76102
default="HEAD^",
77103
help="Revision to checkout to compare vs HEAD",
78104
)
105+
106+
# When creating a wrapper, pass any unknown arguments to it. Otherwise, die.
79107
args, wrapper_args = parser.parse_known_args()
80-
bolt_path = f"{args.build_dir}/bin/llvm-bolt"
108+
if not args.create_wrapper and len(wrapper_args) > 0:
109+
parser.parse_args()
81110

111+
# Find the repo directory.
82112
source_dir = None
83-
# find the repo directory
84-
with open(f"{args.build_dir}/CMakeCache.txt") as f:
85-
for line in f:
86-
m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
87-
if m:
88-
source_dir = m.groups()[0]
89-
if not source_dir:
90-
sys.exit("Source directory is not found")
91-
92-
script_dir = os.path.dirname(os.path.abspath(__file__))
93-
wrapper_path = f"{script_dir}/llvm-bolt-wrapper.py"
94-
# build the current commit
113+
try:
114+
CMCacheFilename = f"{args.build_dir}/CMakeCache.txt"
115+
with open(CMCacheFilename) as f:
116+
for line in f:
117+
m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
118+
if m:
119+
source_dir = m.groups()[0]
120+
if not source_dir:
121+
raise Exception(f"Source directory not found: '{CMCacheFilename}'")
122+
except Exception as e:
123+
sys.exit(e)
124+
125+
# Clean the previous llvm-bolt if it exists.
126+
bolt_path = f"{args.build_dir}/bin/llvm-bolt"
127+
if os.path.exists(bolt_path):
128+
os.remove(bolt_path)
129+
130+
# Build the current commit.
131+
print(f"{msg_prefix} Building current revision..")
95132
subprocess.run(
96133
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
97134
)
98-
# rename llvm-bolt
135+
136+
if not os.path.exists(bolt_path):
137+
sys.exit(f"Failed to build the current revision: '{bolt_path}'")
138+
139+
# Rename llvm-bolt and memorize the old hash for logging.
99140
os.replace(bolt_path, f"{bolt_path}.new")
100-
# memorize the old hash for logging
101141
old_ref = get_git_ref_or_rev(source_dir)
102142

103143
if args.check_bolt_sources:
@@ -110,7 +150,7 @@ def main():
110150
print(f"BOLT source changes were found:\n{file_changes}")
111151
open(marker, "a").close()
112152

113-
# determine whether a stash is needed
153+
# Determine whether a stash is needed.
114154
stash = subprocess.run(
115155
shlex.split("git status --porcelain"),
116156
cwd=source_dir,
@@ -119,42 +159,59 @@ def main():
119159
text=True,
120160
).stdout
121161
if stash:
122-
# save local changes before checkout
162+
# Save local changes before checkout.
123163
subprocess.run(shlex.split("git stash push -u"), cwd=source_dir)
124-
# check out the previous/cmp commit
164+
165+
# Check out the previous/cmp commit and get its commit hash for logging.
125166
subprocess.run(shlex.split(f"git checkout -f {args.cmp_rev}"), cwd=source_dir)
126-
# get the parent commit hash for logging
127167
new_ref = get_git_ref_or_rev(source_dir)
128-
# build the previous commit
168+
169+
# Build the previous commit.
170+
print(f"{msg_prefix} Building previous revision..")
129171
subprocess.run(
130172
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
131173
)
132-
# rename llvm-bolt
174+
175+
# Rename llvm-bolt.
176+
if not os.path.exists(bolt_path):
177+
print(f"Failed to build the previous revision: '{bolt_path}'")
178+
switch_back(args.switch_back, stash, source_dir, old_ref, new_ref)
179+
sys.exit(1)
133180
os.replace(bolt_path, f"{bolt_path}.old")
134-
# set up llvm-bolt-wrapper.ini
135-
ini = subprocess.check_output(
136-
shlex.split(f"{wrapper_path} {bolt_path}.old {bolt_path}.new") + wrapper_args,
137-
text=True,
181+
182+
# Symlink llvm-bolt-wrapper
183+
if args.create_wrapper:
184+
print(f"{msg_prefix} Creating llvm-bolt wrapper..")
185+
script_dir = os.path.dirname(os.path.abspath(__file__))
186+
wrapper_path = f"{script_dir}/llvm-bolt-wrapper.py"
187+
try:
188+
# Set up llvm-bolt-wrapper.ini
189+
ini = subprocess.check_output(
190+
shlex.split(f"{wrapper_path} {bolt_path}.old {bolt_path}.new")
191+
+ wrapper_args,
192+
text=True,
193+
)
194+
with open(f"{args.build_dir}/bin/llvm-bolt-wrapper.ini", "w") as f:
195+
f.write(ini)
196+
os.symlink(wrapper_path, bolt_path)
197+
except Exception as e:
198+
print("Failed to create a wrapper:\n" + str(e))
199+
switch_back(args.switch_back, stash, source_dir, old_ref, new_ref)
200+
sys.exit(1)
201+
202+
switch_back(args.switch_back, stash, source_dir, old_ref, new_ref)
203+
204+
print(
205+
f"{msg_prefix} Completed!\nBuild directory {args.build_dir} is ready for"
206+
" NFC-Mode comparison between the two revisions."
138207
)
139-
with open(f"{args.build_dir}/bin/llvm-bolt-wrapper.ini", "w") as f:
140-
f.write(ini)
141-
# symlink llvm-bolt-wrapper
142-
os.symlink(wrapper_path, bolt_path)
143-
if args.switch_back:
144-
if stash:
145-
subprocess.run(shlex.split("git stash pop"), cwd=source_dir)
146-
subprocess.run(shlex.split(f"git checkout {old_ref}"), cwd=source_dir)
147-
else:
208+
209+
if args.create_wrapper:
148210
print(
149-
f"The repository {source_dir} has been switched from {old_ref} "
150-
f"to {new_ref}. Local changes were stashed. Switch back using\n\t"
151-
f"git checkout {old_ref}\n"
211+
"Can run BOLT tests using:\n"
212+
"\tbin/llvm-lit -sv tools/bolt/test\nor\n"
213+
"\tbin/llvm-lit -sv tools/bolttests"
152214
)
153-
print(
154-
f"Build directory {args.build_dir} is ready to run BOLT tests, e.g.\n"
155-
"\tbin/llvm-lit -sv tools/bolt/test\nor\n"
156-
"\tbin/llvm-lit -sv tools/bolttests"
157-
)
158215

159216

160217
if __name__ == "__main__":

clang/cmake/caches/Fuchsia-stage2-instrumented.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ set(CLANG_BOOTSTRAP_CMAKE_ARGS
4343
${EXTRA_ARGS}
4444
-C ${CMAKE_CURRENT_LIST_DIR}/Fuchsia-stage2.cmake
4545
CACHE STRING "")
46+
47+
# Do not use LLVM build for generating PGO data.
48+
set(CLANG_PGO_TRAINING_USE_LLVM_BUILD OFF CACHE BOOL "")

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,8 +4201,8 @@ the configuration (without a prefix: ``Auto``).
42014201
* ``""`` means "arbitrary suffix"
42024202
* ``"$"`` means "no suffix"
42034203

4204-
For example, if configured to ``"(_test)?$"``, then a header a.h would be seen
4205-
as the "main" include in both a.cc and a_test.cc.
4204+
For example, if configured to ``"(_test)?$"``, then a header a.h would be
4205+
seen as the "main" include in both a.cc and a_test.cc.
42064206

42074207
.. _IncludeIsMainSourceRegex:
42084208

clang/include/clang/Tooling/Inclusions/IncludeStyle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ struct IncludeStyle {
126126
/// * ``""`` means "arbitrary suffix"
127127
/// * ``"$"`` means "no suffix"
128128
///
129-
/// For example, if configured to ``"(_test)?$"``, then a header a.h would be seen
130-
/// as the "main" include in both a.cc and a_test.cc.
129+
/// For example, if configured to ``"(_test)?$"``, then a header a.h would be
130+
/// seen as the "main" include in both a.cc and a_test.cc.
131131
/// \version 3.9
132132
std::string IncludeIsMainRegex;
133133

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,15 @@ bool ARMTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
623623
LDREX = LDREX_W;
624624
break;
625625
case 7:
626+
case 8:
626627
if (ArchProfile == llvm::ARM::ProfileKind::M)
627628
LDREX = LDREX_W | LDREX_H | LDREX_B;
628629
else
629630
LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B;
630631
break;
631-
case 8:
632632
case 9:
633+
assert(ArchProfile != llvm::ARM::ProfileKind::M &&
634+
"No Armv9-M architectures defined");
633635
LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B;
634636
}
635637

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -904,35 +904,6 @@ Driver::OpenMPRuntimeKind Driver::getOpenMPRuntime(const ArgList &Args) const {
904904
return RT;
905905
}
906906

907-
static llvm::Triple getSYCLDeviceTriple(StringRef TargetArch) {
908-
SmallVector<StringRef, 5> SYCLAlias = {"spir", "spir64", "spirv", "spirv32",
909-
"spirv64"};
910-
if (llvm::is_contained(SYCLAlias, TargetArch)) {
911-
llvm::Triple TargetTriple;
912-
TargetTriple.setArchName(TargetArch);
913-
TargetTriple.setVendor(llvm::Triple::UnknownVendor);
914-
TargetTriple.setOS(llvm::Triple::UnknownOS);
915-
return TargetTriple;
916-
}
917-
return llvm::Triple(TargetArch);
918-
}
919-
920-
static bool addSYCLDefaultTriple(Compilation &C,
921-
SmallVectorImpl<llvm::Triple> &SYCLTriples) {
922-
// Check current set of triples to see if the default has already been set.
923-
for (const auto &SYCLTriple : SYCLTriples) {
924-
if (SYCLTriple.getSubArch() == llvm::Triple::NoSubArch &&
925-
SYCLTriple.isSPIROrSPIRV())
926-
return false;
927-
}
928-
// Add the default triple as it was not found.
929-
llvm::Triple DefaultTriple = getSYCLDeviceTriple(
930-
C.getDefaultToolChain().getTriple().isArch32Bit() ? "spirv32"
931-
: "spirv64");
932-
SYCLTriples.insert(SYCLTriples.begin(), DefaultTriple);
933-
return true;
934-
}
935-
936907
// Handles `native` offload architectures by using the 'offload-arch' utility.
937908
static llvm::SmallVector<std::string>
938909
getSystemOffloadArchs(Compilation &C, Action::OffloadKind Kind) {
@@ -954,7 +925,8 @@ getSystemOffloadArchs(Compilation &C, Action::OffloadKind Kind) {
954925
<< Action::GetOffloadKindName(Kind) << StdoutOrErr.takeError()
955926
<< "--offload-arch";
956927
return GPUArchs;
957-
} else if ((*StdoutOrErr)->getBuffer().empty()) {
928+
}
929+
if ((*StdoutOrErr)->getBuffer().empty()) {
958930
C.getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
959931
<< Action::GetOffloadKindName(Kind) << "No GPU detected in the system"
960932
<< "--offload-arch";
@@ -1090,8 +1062,8 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
10901062
(C.getInputArgs().hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
10911063
options::OPT_fno_openmp, false) &&
10921064
(C.getInputArgs().hasArg(options::OPT_offload_targets_EQ) ||
1093-
(C.getInputArgs().hasArg(options::OPT_offload_arch_EQ)) &&
1094-
!(IsCuda || IsHIP)));
1065+
(C.getInputArgs().hasArg(options::OPT_offload_arch_EQ) &&
1066+
!(IsCuda || IsHIP))));
10951067

10961068
llvm::DenseSet<Action::OffloadKind> Kinds;
10971069
const std::pair<bool, Action::OffloadKind> ActiveKinds[] = {
@@ -4906,7 +4878,7 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
49064878
if (Kind == Action::OFK_SYCL && Phase == phases::Assemble)
49074879
continue;
49084880

4909-
auto TCAndArch = TCAndArchs.begin();
4881+
auto *TCAndArch = TCAndArchs.begin();
49104882
for (Action *&A : DeviceActions) {
49114883
if (A->getType() == types::TY_Nothing)
49124884
continue;
@@ -4946,7 +4918,7 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
49464918
A = C.MakeAction<LinkJobAction>(LinkerInput, types::TY_Image);
49474919
}
49484920

4949-
auto TCAndArch = TCAndArchs.begin();
4921+
auto *TCAndArch = TCAndArchs.begin();
49504922
for (Action *A : DeviceActions) {
49514923
DDeps.add(*A, *TCAndArch->first, TCAndArch->second.data(), Kind);
49524924
OffloadAction::DeviceDependences DDep;

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,6 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
694694
NeedCRTs)
695695
CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTEnd)));
696696

697-
if (TC.getTriple().isRISCV())
698-
CmdArgs.push_back("-X");
699-
700697
// The R_ARM_TARGET2 relocation must be treated as R_ARM_REL32 on arm*-*-elf
701698
// and arm*-*-eabi (the default is R_ARM_GOT_PREL, used on arm*-*-linux and
702699
// arm*-*-*bsd).

clang/lib/Format/BreakableToken.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
namespace clang {
2626
namespace format {
2727

28-
static constexpr StringRef Blanks = " \t\v\f\r";
28+
static constexpr StringRef Blanks(" \t\v\f\r");
2929

3030
static StringRef getLineCommentIndentPrefix(StringRef Comment,
3131
const FormatStyle &Style) {
@@ -513,7 +513,7 @@ BreakableBlockComment::BreakableBlockComment(
513513
Decoration = "";
514514
}
515515
for (size_t i = 1, e = Content.size(); i < e && !Decoration.empty(); ++i) {
516-
const StringRef &Text = Content[i];
516+
const StringRef Text(Content[i]);
517517
if (i + 1 == e) {
518518
// If the last line is empty, the closing "*/" will have a star.
519519
if (Text.empty())

clang/lib/Format/IntegerLiteralSeparatorFixer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace format {
1919

2020
enum class Base { Binary, Decimal, Hex, Other };
2121

22-
static Base getBase(const StringRef IntegerLiteral) {
22+
static Base getBase(StringRef IntegerLiteral) {
2323
assert(IntegerLiteral.size() > 1);
2424

2525
if (IntegerLiteral[0] > '0') {
@@ -164,8 +164,8 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
164164
return {Result, 0};
165165
}
166166

167-
bool IntegerLiteralSeparatorFixer::checkSeparator(
168-
const StringRef IntegerLiteral, int DigitsPerGroup) const {
167+
bool IntegerLiteralSeparatorFixer::checkSeparator(StringRef IntegerLiteral,
168+
int DigitsPerGroup) const {
169169
assert(DigitsPerGroup > 0);
170170

171171
int I = 0;
@@ -184,7 +184,7 @@ bool IntegerLiteralSeparatorFixer::checkSeparator(
184184
return true;
185185
}
186186

187-
std::string IntegerLiteralSeparatorFixer::format(const StringRef IntegerLiteral,
187+
std::string IntegerLiteralSeparatorFixer::format(StringRef IntegerLiteral,
188188
int DigitsPerGroup,
189189
int DigitCount,
190190
bool RemoveSeparator) const {

clang/lib/Format/IntegerLiteralSeparatorFixer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class IntegerLiteralSeparatorFixer {
2626
const FormatStyle &Style);
2727

2828
private:
29-
bool checkSeparator(const StringRef IntegerLiteral, int DigitsPerGroup) const;
30-
std::string format(const StringRef IntegerLiteral, int DigitsPerGroup,
29+
bool checkSeparator(StringRef IntegerLiteral, int DigitsPerGroup) const;
30+
std::string format(StringRef IntegerLiteral, int DigitsPerGroup,
3131
int DigitCount, bool RemoveSeparator) const;
3232

3333
char Separator;

0 commit comments

Comments
 (0)