Skip to content

Commit 9c94f39

Browse files
committed
Merge upstream LLVM into amd-gfx12
2 parents 489ea59 + 597f3c1 commit 9c94f39

File tree

535 files changed

+25478
-19035
lines changed

Some content is hidden

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

535 files changed

+25478
-19035
lines changed

bolt/utils/nfc-check-setup.py

Lines changed: 80 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,30 @@ def get_git_ref_or_rev(dir: str) -> str:
4242
cmd_rev = "git rev-parse --short HEAD"
4343
return subprocess.check_output(shlex.split(cmd_rev), cwd=dir, text=True).strip()
4444

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

4663
def main():
4764
parser = argparse.ArgumentParser(
4865
description=textwrap.dedent(
4966
"""
5067
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.
68+
previous revision).
5369
"""
5470
)
5571
)
@@ -59,6 +75,12 @@ def main():
5975
default=os.getcwd(),
6076
help="Path to BOLT build directory, default is current " "directory",
6177
)
78+
parser.add_argument(
79+
"--create-wrapper",
80+
default=False,
81+
action="store_true",
82+
help="Sets up llvm-bolt as a symlink to llvm-bolt-wrapper. Passes the options through to llvm-bolt-wrapper.",
83+
)
6284
parser.add_argument(
6385
"--check-bolt-sources",
6486
default=False,
@@ -76,25 +98,40 @@ def main():
7698
default="HEAD^",
7799
help="Revision to checkout to compare vs HEAD",
78100
)
101+
102+
# When creating a wrapper, pass any unknown arguments to it. Otherwise, die.
79103
args, wrapper_args = parser.parse_known_args()
80-
bolt_path = f"{args.build_dir}/bin/llvm-bolt"
104+
if not args.create_wrapper and len(wrapper_args) > 0:
105+
parser.parse_args()
81106

82-
source_dir = None
83107
# 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"
108+
source_dir = None
109+
try:
110+
CMCacheFilename = f"{args.build_dir}/CMakeCache.txt"
111+
with open(CMCacheFilename) as f:
112+
for line in f:
113+
m = re.match(r"LLVM_SOURCE_DIR:STATIC=(.*)", line)
114+
if m:
115+
source_dir = m.groups()[0]
116+
if not source_dir:
117+
raise Exception(f"Source directory not found: '{CMCacheFilename}'")
118+
except Exception as e:
119+
sys.exit(e)
120+
121+
# clean the previous llvm-bolt if it exists
122+
bolt_path = f"{args.build_dir}/bin/llvm-bolt"
123+
if os.path.exists(bolt_path):
124+
os.remove(bolt_path)
125+
94126
# build the current commit
127+
print("NFC-Setup: Building current revision..")
95128
subprocess.run(
96129
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
97130
)
131+
132+
if not os.path.exists(bolt_path):
133+
sys.exit(f"Failed to build the current revision: '{bolt_path}'")
134+
98135
# rename llvm-bolt
99136
os.replace(bolt_path, f"{bolt_path}.new")
100137
# memorize the old hash for logging
@@ -125,31 +162,42 @@ def main():
125162
subprocess.run(shlex.split(f"git checkout -f {args.cmp_rev}"), cwd=source_dir)
126163
# get the parent commit hash for logging
127164
new_ref = get_git_ref_or_rev(source_dir)
165+
128166
# build the previous commit
167+
print("NFC-Setup: Building previous revision..")
129168
subprocess.run(
130169
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
131170
)
171+
132172
# rename llvm-bolt
173+
if not os.path.exists(bolt_path):
174+
print(f"Failed to build the previous revision: '{bolt_path}'")
175+
switch_back(args.switch_back, stash, source_dir, old_ref, new_ref)
176+
sys.exit(1)
133177
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,
138-
)
139-
with open(f"{args.build_dir}/bin/llvm-bolt-wrapper.ini", "w") as f:
140-
f.write(ini)
178+
141179
# 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:
148-
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"
152-
)
180+
if args.create_wrapper:
181+
script_dir = os.path.dirname(os.path.abspath(__file__))
182+
wrapper_path = f"{script_dir}/llvm-bolt-wrapper.py"
183+
try:
184+
# set up llvm-bolt-wrapper.ini
185+
ini = subprocess.check_output(
186+
shlex.split(f"{wrapper_path} {bolt_path}.old {bolt_path}.new")
187+
+ wrapper_args,
188+
text=True,
189+
)
190+
with open(f"{args.build_dir}/bin/llvm-bolt-wrapper.ini", "w") as f:
191+
f.write(ini)
192+
# symlink llvm-bolt-wrapper
193+
os.symlink(wrapper_path, bolt_path)
194+
except Exception as e:
195+
print("Failed to create a wrapper:\n" + str(e))
196+
switch_back(args.switch_back, stash, source_dir, old_ref, new_ref)
197+
sys.exit(1)
198+
199+
switch_back(args.switch_back, stash, source_dir, old_ref, new_ref)
200+
153201
print(
154202
f"Build directory {args.build_dir} is ready to run BOLT tests, e.g.\n"
155203
"\tbin/llvm-lit -sv tools/bolt/test\nor\n"

0 commit comments

Comments
 (0)