Skip to content

Commit 841efe8

Browse files
committed
NFC: ExtractIRForPassTest.py: add tool path option and -hlsl-passes-pause
Adds a -t or --tool-path option for specifying the directory containing dxc and dxopt tools and improves error handling for missing tools. Also adds -hlsl-passes-pause to the suggested test RUN line after the target pass, since this is needed to update the metadata in the resulting checked IR, when a pass might impact HLModule or DxilModule state.
1 parent 348fc78 commit 841efe8

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

utils/hct/ExtractIRForPassTest.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"""
2121

2222
import os
23+
import shutil
2324
import sys
2425
import subprocess
2526
import tempfile
@@ -30,6 +31,14 @@ def ParseArgs():
3031
parser = argparse.ArgumentParser(
3132
formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__
3233
)
34+
parser.add_argument(
35+
"-t",
36+
"--tool-path",
37+
dest="tool_path",
38+
metavar="<tool-path>",
39+
default="",
40+
help="directory containing dxc and dxopt executables",
41+
)
3342
parser.add_argument(
3443
"-p",
3544
dest="desired_pass",
@@ -110,17 +119,32 @@ def GetTempFilename(*args, **kwargs):
110119

111120

112121
def main(args):
122+
dxc_path = "dxc"
123+
dxopt_path = "dxopt"
124+
if args.tool_path:
125+
dxc_path = os.path.join(args.tool_path, dxc_path)
126+
dxopt_path = os.path.join(args.tool_path, dxopt_path)
127+
if not os.path.isfile(dxc_path) or not os.path.isfile(dxopt_path):
128+
raise FileNotFoundError(
129+
f"dxc not found at {dxc_path}. Use -t to specify path to dxc and dxopt."
130+
)
131+
else:
132+
# If no tool path is specified, check if dxc and dxopt are in PATH
133+
if not shutil.which(dxc_path) or not shutil.which(dxopt_path):
134+
raise FileNotFoundError(
135+
"dxc or dxopt not found in PATH. Use -t to specify path to dxc and dxopt."
136+
)
113137
try:
114138
# 1. Gets the pass list for an HLSL compilation using -Odump
115-
cmd = ["dxc", "/Odump", args.hlsl_file] + args.compilation_options
139+
cmd = [dxc_path, "/Odump", args.hlsl_file] + args.compilation_options
116140
# print(cmd)
117141
all_passes = subprocess.check_output(cmd, text=True)
118142
all_passes = all_passes.splitlines()
119143

120144
# 2. Compiles HLSL with -fcgl and outputs to intermediate IR
121145
fcgl_file = GetTempFilename(".ll")
122146
cmd = [
123-
"dxc",
147+
dxc_path,
124148
"-fcgl",
125149
"-Fc",
126150
fcgl_file,
@@ -143,20 +167,20 @@ def main(args):
143167

144168
# 4. Invokes dxopt to run passes on -fcgl output and write bitcode result
145169
bitcode_file = GetTempFilename(".bc")
146-
cmd = ["dxopt", "-o=" + bitcode_file, fcgl_file] + passes_before
170+
cmd = [dxopt_path, "-o=" + bitcode_file, fcgl_file] + passes_before
147171
# print(cmd)
148172
subprocess.check_call(cmd)
149173

150174
# 5. Disassembles bitcode to .ll file for use as a test
151175
temp_out = GetTempFilename(".ll")
152-
cmd = ["dxc", "/dumpbin", "-Fc", temp_out, bitcode_file]
176+
cmd = [dxc_path, "/dumpbin", "-Fc", temp_out, bitcode_file]
153177
# print(cmd)
154178
subprocess.check_call(cmd)
155179

156180
# 6. Inserts RUN line with -hlsl-passes-resume and desired pass
157181
with open(args.output_file, "wt") as f:
158182
f.write(
159-
"; RUN: %dxopt %s -hlsl-passes-resume -{} -S | FileCheck %s\n\n".format(
183+
"; RUN: %dxopt %s -hlsl-passes-resume -{} -hlsl-passes-pause -S | FileCheck %s\n\n".format(
160184
args.desired_pass
161185
)
162186
)

0 commit comments

Comments
 (0)