[LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)
[llvm-project.git] / llvm / utils / UpdateTestChecks / asm.py
blobf150098eaaeef48f589e782c17d7e66ecfc2e408
1 from __future__ import print_function
2 import re
3 import sys
5 from . import common
7 if sys.version_info[0] > 2:
9 class string:
10 expandtabs = str.expandtabs
12 else:
13 import string
15 # RegEx: this is where the magic happens.
17 ##### Assembly parser
19 # The set of per-arch regular expressions define several groups.
20 # The required groups are "func" (function name) and "body" (body of the function).
21 # Although some backends require some additional groups like: "directives"
22 # and "func_name_separator"
24 ASM_FUNCTION_X86_RE = re.compile(
25 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*(@"?(?P=func)"?| -- Begin function (?P=func))\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?'
26 r"(?:\.L(?P=func)\$local:\n)?" # drop .L<func>$local:
27 r"(?:\s*\.type\s+\.L(?P=func)\$local,@function\n)?" # drop .type .L<func>$local
28 r"(?:[ \t]*(?:\.cfi_startproc|\.cfi_personality|\.cfi_lsda|\.seh_proc|\.seh_handler)\b[^\n]*\n)*" # drop optional cfi
29 r"(?P<body>^##?[ \t]+[^:]+:.*?)\s*"
30 r"^\s*(?:[^:\n]+?:\s*\n\s*\.size|\.cfi_endproc|\.globl|\.comm|\.(?:sub)?section|#+ -- End function)",
31 flags=(re.M | re.S),
34 ASM_FUNCTION_ARM_RE = re.compile(
35 r"^(?P<func>[0-9a-zA-Z_$]+):\n" # f: (name of function)
36 r"(?:\.L(?P=func)\$local:\n)?" # drop .L<func>$local:
37 r"(?:\s*\.type\s+\.L(?P=func)\$local,@function\n)?" # drop .type .L<func>$local
38 r"\s+\.fnstart\n" # .fnstart
39 r"(?P<body>.*?)" # (body of the function)
40 r"^.Lfunc_end[0-9]+:", # .Lfunc_end0: or # -- End function
41 flags=(re.M | re.S),
44 ASM_FUNCTION_AARCH64_RE = re.compile(
45 r'^_?(?P<func>[^:]+):[ \t]*\/\/[ \t]*@"?(?P=func)"?( (Function|Tail Call))?\n'
46 r"(?:[ \t]+.cfi_startproc\n)?" # drop optional cfi noise
47 r"(?P<body>.*?)\n"
48 # This list is incomplete
49 r"^\s*(\.Lfunc_end[0-9]+|// -- End function)",
50 flags=(re.M | re.S),
53 ASM_FUNCTION_AMDGPU_RE = re.compile(
54 r"\.type\s+_?(?P<func>[^,\n]+),@function\n"
55 r'^_?(?P=func):(?:[ \t]*;+[ \t]*@"?(?P=func)"?)?\n'
56 r"(?P<body>.*?)\n" # (body of the function)
57 # This list is incomplete
58 r"^\s*(\.Lfunc_end[0-9]+:\n|\.section)",
59 flags=(re.M | re.S),
62 ASM_FUNCTION_BPF_RE = re.compile(
63 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n'
64 r"(?:[ \t]+.cfi_startproc\n|.seh_proc[^\n]+\n)?" # drop optional cfi
65 r"(?P<body>.*?)\s*"
66 r".Lfunc_end[0-9]+:\n",
67 flags=(re.M | re.S),
70 ASM_FUNCTION_HEXAGON_RE = re.compile(
71 r'^_?(?P<func>[^:]+):[ \t]*//[ \t]*@"?(?P=func)"?\n[^:]*?'
72 r"(?P<body>.*?)\n" # (body of the function)
73 # This list is incomplete
74 r".Lfunc_end[0-9]+:\n",
75 flags=(re.M | re.S),
78 ASM_FUNCTION_M68K_RE = re.compile(
79 r'^_?(?P<func>[^:]+):[ \t]*;[ \t]*@"?(?P=func)"?\n'
80 r'(?:\.L(?P=func)\$local:\n)?' # drop .L<func>$local:
81 r'(?:[ \t]+\.type[ \t]+\.L(?P=func)\$local,@function\n)?' # drop .type .L<func>$local,@function
82 r'(?P<body>.*?)\s*' # (body of the function)
83 r'.Lfunc_end[0-9]+:\n',
84 flags=(re.M | re.S))
86 ASM_FUNCTION_MIPS_RE = re.compile(
87 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n[^:]*?' # f: (name of func)
88 r"(?:\s*\.?Ltmp[^:\n]*:\n)?[^:]*?" # optional .Ltmp<N> for EH
89 r"(?:^[ \t]+\.(frame|f?mask|set).*?\n)+" # Mips+LLVM standard asm prologue
90 r"(?P<body>.*?)\n" # (body of the function)
91 # Mips+LLVM standard asm epilogue
92 r"(?:(^[ \t]+\.set[^\n]*?\n)*^[ \t]+\.end.*?\n)"
93 r"(\$|\.L)func_end[0-9]+:\n", # $func_end0: (mips32 - O32) or
94 # .Lfunc_end0: (mips64 - NewABI)
95 flags=(re.M | re.S),
98 ASM_FUNCTION_MSP430_RE = re.compile(
99 r'^_?(?P<func>[^:]+):[ \t]*;+[ \t]*@"?(?P=func)"?\n[^:]*?'
100 r"(?P<body>.*?)\n"
101 r"(\$|\.L)func_end[0-9]+:\n", # $func_end0:
102 flags=(re.M | re.S),
105 ASM_FUNCTION_AVR_RE = re.compile(
106 r'^_?(?P<func>[^:]+):[ \t]*;+[ \t]*@"?(?P=func)"?\n[^:]*?'
107 r"(?P<body>.*?)\n"
108 r".Lfunc_end[0-9]+:\n",
109 flags=(re.M | re.S),
112 ASM_FUNCTION_PPC_RE = re.compile(
113 r"#[ \-\t]*Begin function (?P<func>[^.:]+)\n"
114 r".*?"
115 r'^[_.]?(?P=func):(?:[ \t]*#+[ \t]*@"?(?P=func)"?)?\n'
116 r"(?:^[^#]*\n)*"
117 r"(?P<body>.*?)\n"
118 # This list is incomplete
119 r"(?:^[ \t]*(?:\.(?:long|quad|v?byte)[ \t]+[^\n]+)\n)*"
120 r"(?:\.Lfunc_end|L\.\.(?P=func))[0-9]+:\n",
121 flags=(re.M | re.S),
124 ASM_FUNCTION_RISCV_RE = re.compile(
125 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n'
126 r"(?:\s*\.?L(?P=func)\$local:\n)?" # optional .L<func>$local: due to -fno-semantic-interposition
127 r"(?:\s*\.type\s+\.?L(?P=func)\$local,@function\n)?" # optional .type .L<func>$local
128 r"(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?"
129 r"(?P<body>^##?[ \t]+[^:]+:.*?)\s*"
130 r".Lfunc_end[0-9]+:\n",
131 flags=(re.M | re.S),
134 ASM_FUNCTION_LANAI_RE = re.compile(
135 r'^_?(?P<func>[^:]+):[ \t]*!+[ \t]*@"?(?P=func)"?\n'
136 r"(?:[ \t]+.cfi_startproc\n)?" # drop optional cfi noise
137 r"(?P<body>.*?)\s*"
138 r".Lfunc_end[0-9]+:\n",
139 flags=(re.M | re.S),
142 ASM_FUNCTION_SPARC_RE = re.compile(
143 r'^_?(?P<func>[^:]+):[ \t]*!+[ \t]*@"?(?P=func)"?\n'
144 r"(?P<body>.*?)\s*"
145 r".Lfunc_end[0-9]+:\n",
146 flags=(re.M | re.S),
149 ASM_FUNCTION_SYSTEMZ_RE = re.compile(
150 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n'
151 r"(?:[ \t]+.cfi_startproc\n)?"
152 r"(?P<body>.*?)\n"
153 r".Lfunc_end[0-9]+:\n",
154 flags=(re.M | re.S),
157 ASM_FUNCTION_AARCH64_DARWIN_RE = re.compile(
158 r'^_(?P<func>[^:]+):[ \t]*;[ \t]@"?(?P=func)"?\n'
159 r"([ \t]*.cfi_startproc\n[\s]*)?"
160 r"(?P<body>.*?)"
161 r"([ \t]*.cfi_endproc\n[\s]*)?"
162 r"^[ \t]*;[ \t]--[ \t]End[ \t]function",
163 flags=(re.M | re.S),
166 ASM_FUNCTION_ARM_DARWIN_RE = re.compile(
167 r"@[ \t]--[ \t]Begin[ \t]function[ \t](?P<func>[^ \t]+?)\n"
168 r"^[ \t]*\.globl[ \t]*_(?P=func)[ \t]*"
169 r"(?P<directives>.*?)"
170 r"^_(?P=func):\n[ \t]*"
171 r"(?P<body>.*?)"
172 r"^[ \t]*@[ \t]--[ \t]End[ \t]function",
173 flags=(re.M | re.S),
176 ASM_FUNCTION_ARM_MACHO_RE = re.compile(
177 r"^_(?P<func>[^:]+):[ \t]*\n"
178 r"([ \t]*.cfi_startproc\n[ \t]*)?"
179 r"(?P<body>.*?)\n"
180 r"[ \t]*\.cfi_endproc\n",
181 flags=(re.M | re.S),
184 ASM_FUNCTION_THUMBS_DARWIN_RE = re.compile(
185 r"^_(?P<func>[^:]+):\n" r"(?P<body>.*?)\n" r"[ \t]*\.data_region\n",
186 flags=(re.M | re.S),
189 ASM_FUNCTION_THUMB_DARWIN_RE = re.compile(
190 r"^_(?P<func>[^:]+):\n" r"(?P<body>.*?)\n" r"^[ \t]*@[ \t]--[ \t]End[ \t]function",
191 flags=(re.M | re.S),
194 ASM_FUNCTION_ARM_IOS_RE = re.compile(
195 r"^_(?P<func>[^:]+):\n" r"(?P<body>.*?)" r"^[ \t]*@[ \t]--[ \t]End[ \t]function",
196 flags=(re.M | re.S),
199 ASM_FUNCTION_WASM_RE = re.compile(
200 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n'
201 r"(?P<body>.*?)\n"
202 r"^\s*(\.Lfunc_end[0-9]+:\n|end_function)",
203 flags=(re.M | re.S),
206 # We parse the function name from OpName, and grab the variable name 'var'
207 # for this function. Then we match that when the variable is assigned with
208 # OpFunction and match its body.
209 ASM_FUNCTION_SPIRV_RE = re.compile(
210 r'OpName (?P<var>%[0-9]+) "(?P<func>[^"]+)(?P<func_name_separator>)".*(?P<body>(?P=var) = OpFunction.+?OpFunctionEnd)',
211 flags=(re.M | re.S),
214 ASM_FUNCTION_VE_RE = re.compile(
215 r"^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n"
216 r"(?:\s*\.?L(?P=func)\$local:\n)?" # optional .L<func>$local: due to -fno-semantic-interposition
217 r"(?:\s*\.type\s+\.?L(?P=func)\$local,@function\n)?" # optional .type .L<func>$local
218 r"(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?"
219 r"(?P<body>^##?[ \t]+[^:]+:.*?)\s*"
220 r".Lfunc_end[0-9]+:\n",
221 flags=(re.M | re.S),
224 ASM_FUNCTION_CSKY_RE = re.compile(
225 r"^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?"
226 r"(?P<body>^##?[ \t]+[^:]+:.*?)\s*"
227 r".Lfunc_end[0-9]+:\n",
228 flags=(re.M | re.S),
231 ASM_FUNCTION_NVPTX_RE = re.compile(
232 # function attributes and retval
233 # .visible .func (.param .align 16 .b8 func_retval0[32])
234 # r'^(\.visible\s+)?\.func\s+(\([^\)]*\)\s*)?'
235 r"^(\.(func|visible|weak|entry|noreturn|extern)\s+)+(\([^\)]*\)\s*)?"
236 # function name
237 r"(?P<func>[^\(\n]+)"
238 # function name separator (opening brace)
239 r"(?P<func_name_separator>\()"
240 # function parameters
242 # .param .align 16 .b8 callee_St8x4_param_0[32]
243 # ) // -- Begin function callee_St8x4
244 r"[^\)]*\)(\s*//[^\n]*)?\n"
245 # function body
246 r"(?P<body>.*?)\n"
247 # function body end marker
248 r"\s*// -- End function",
249 flags=(re.M | re.S),
252 ASM_FUNCTION_LOONGARCH_RE = re.compile(
253 r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@"?(?P=func)"?\n'
254 r"(?:\s*\.?Lfunc_begin[^:\n]*:\n)?[^:]*?"
255 r"(?P<body>^##?[ \t]+[^:]+:.*?)\s*"
256 r".Lfunc_end[0-9]+:\n",
257 flags=(re.M | re.S),
260 SCRUB_X86_SHUFFLES_RE = re.compile(
261 r"^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = .*)$", flags=re.M
264 SCRUB_X86_SHUFFLES_NO_MEM_RE = re.compile(
265 r"^(\s*\w+) [^#\n]+#+ ((?:[xyz]mm\d+|mem)( \{%k\d+\}( \{z\})?)? = (?!.*(?:mem)).*)$",
266 flags=re.M,
269 SCRUB_X86_SPILL_RELOAD_RE = re.compile(
270 r"-?\d+\(%([er])[sb]p\)(.*(?:Spill|Reload))$", flags=re.M
272 SCRUB_X86_SP_RE = re.compile(r"\d+\(%(esp|rsp)\)")
273 SCRUB_X86_RIP_RE = re.compile(r"[.\w]+\(%rip\)")
274 SCRUB_X86_LCP_RE = re.compile(r"\.?LCPI[0-9]+_[0-9]+")
275 SCRUB_X86_RET_RE = re.compile(r"ret[l|q]")
278 def scrub_asm_x86(asm, args):
279 # Scrub runs of whitespace out of the assembly, but leave the leading
280 # whitespace in place.
281 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
282 # Expand the tabs used for indentation.
283 asm = string.expandtabs(asm, 2)
285 # Detect shuffle asm comments and hide the operands in favor of the comments.
286 if getattr(args, "no_x86_scrub_mem_shuffle", True):
287 asm = SCRUB_X86_SHUFFLES_NO_MEM_RE.sub(r"\1 {{.*#+}} \2", asm)
288 else:
289 asm = SCRUB_X86_SHUFFLES_RE.sub(r"\1 {{.*#+}} \2", asm)
291 # Detect stack spills and reloads and hide their exact offset and whether
292 # they used the stack pointer or frame pointer.
293 asm = SCRUB_X86_SPILL_RELOAD_RE.sub(r"{{[-0-9]+}}(%\1{{[sb]}}p)\2", asm)
294 if getattr(args, "x86_scrub_sp", True):
295 # Generically match the stack offset of a memory operand.
296 asm = SCRUB_X86_SP_RE.sub(r"{{[0-9]+}}(%\1)", asm)
297 if getattr(args, "x86_scrub_rip", False):
298 # Generically match a RIP-relative memory operand.
299 asm = SCRUB_X86_RIP_RE.sub(r"{{.*}}(%rip)", asm)
300 # Generically match a LCP symbol.
301 asm = SCRUB_X86_LCP_RE.sub(r"{{\.?LCPI[0-9]+_[0-9]+}}", asm)
302 if getattr(args, "extra_scrub", False):
303 # Avoid generating different checks for 32- and 64-bit because of 'retl' vs 'retq'.
304 asm = SCRUB_X86_RET_RE.sub(r"ret{{[l|q]}}", asm)
305 # Strip kill operands inserted into the asm.
306 asm = common.SCRUB_KILL_COMMENT_RE.sub("", asm)
307 # Strip trailing whitespace.
308 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
309 return asm
312 def scrub_asm_amdgpu(asm, args):
313 # Scrub runs of whitespace out of the assembly, but leave the leading
314 # whitespace in place.
315 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
316 # Expand the tabs used for indentation.
317 asm = string.expandtabs(asm, 2)
318 # Strip trailing whitespace.
319 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
320 return asm
323 def scrub_asm_arm_eabi(asm, args):
324 # Scrub runs of whitespace out of the assembly, but leave the leading
325 # whitespace in place.
326 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
327 # Expand the tabs used for indentation.
328 asm = string.expandtabs(asm, 2)
329 # Strip kill operands inserted into the asm.
330 asm = common.SCRUB_KILL_COMMENT_RE.sub("", asm)
331 # Strip trailing whitespace.
332 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
333 return asm
336 def scrub_asm_bpf(asm, args):
337 # Scrub runs of whitespace out of the assembly, but leave the leading
338 # whitespace in place.
339 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
340 # Expand the tabs used for indentation.
341 asm = string.expandtabs(asm, 2)
342 # Strip trailing whitespace.
343 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
344 return asm
347 def scrub_asm_hexagon(asm, args):
348 # Scrub runs of whitespace out of the assembly, but leave the leading
349 # whitespace in place.
350 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
351 # Expand the tabs used for indentation.
352 asm = string.expandtabs(asm, 2)
353 # Strip trailing whitespace.
354 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
355 return asm
358 def scrub_asm_powerpc(asm, args):
359 # Scrub runs of whitespace out of the assembly, but leave the leading
360 # whitespace in place.
361 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
362 # Expand the tabs used for indentation.
363 asm = string.expandtabs(asm, 2)
364 # Strip unimportant comments, but leave the token '#' in place.
365 asm = common.SCRUB_LOOP_COMMENT_RE.sub(r"#", asm)
366 # Strip trailing whitespace.
367 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
368 # Strip the tailing token '#', except the line only has token '#'.
369 asm = common.SCRUB_TAILING_COMMENT_TOKEN_RE.sub(r"", asm)
370 return asm
373 def scrub_asm_m68k(asm, args):
374 # Scrub runs of whitespace out of the assembly, but leave the leading
375 # whitespace in place.
376 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
377 # Expand the tabs used for indentation.
378 asm = string.expandtabs(asm, 2)
379 # Strip trailing whitespace.
380 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
381 return asm
384 def scrub_asm_mips(asm, args):
385 # Scrub runs of whitespace out of the assembly, but leave the leading
386 # whitespace in place.
387 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
388 # Expand the tabs used for indentation.
389 asm = string.expandtabs(asm, 2)
390 # Strip trailing whitespace.
391 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
392 return asm
395 def scrub_asm_msp430(asm, args):
396 # Scrub runs of whitespace out of the assembly, but leave the leading
397 # whitespace in place.
398 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
399 # Expand the tabs used for indentation.
400 asm = string.expandtabs(asm, 2)
401 # Strip trailing whitespace.
402 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
403 return asm
406 def scrub_asm_avr(asm, args):
407 # Scrub runs of whitespace out of the assembly, but leave the leading
408 # whitespace in place.
409 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
410 # Expand the tabs used for indentation.
411 asm = string.expandtabs(asm, 2)
412 # Strip trailing whitespace.
413 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
414 return asm
417 def scrub_asm_riscv(asm, args):
418 # Scrub runs of whitespace out of the assembly, but leave the leading
419 # whitespace in place.
420 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
421 # Expand the tabs used for indentation.
422 asm = string.expandtabs(asm, 2)
423 # Strip trailing whitespace.
424 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
425 return asm
428 def scrub_asm_lanai(asm, args):
429 # Scrub runs of whitespace out of the assembly, but leave the leading
430 # whitespace in place.
431 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
432 # Expand the tabs used for indentation.
433 asm = string.expandtabs(asm, 2)
434 # Strip trailing whitespace.
435 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
436 return asm
439 def scrub_asm_sparc(asm, args):
440 # Scrub runs of whitespace out of the assembly, but leave the leading
441 # whitespace in place.
442 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
443 # Expand the tabs used for indentation.
444 asm = string.expandtabs(asm, 2)
445 # Strip trailing whitespace.
446 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
447 return asm
450 def scrub_asm_spirv(asm, args):
451 # Scrub runs of whitespace out of the assembly, but leave the leading
452 # whitespace in place.
453 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
454 # Expand the tabs used for indentation.
455 asm = string.expandtabs(asm, 2)
456 # Strip trailing whitespace.
457 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
458 return asm
461 def scrub_asm_systemz(asm, args):
462 # Scrub runs of whitespace out of the assembly, but leave the leading
463 # whitespace in place.
464 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
465 # Expand the tabs used for indentation.
466 asm = string.expandtabs(asm, 2)
467 # Strip trailing whitespace.
468 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
469 return asm
472 def scrub_asm_wasm(asm, args):
473 # Scrub runs of whitespace out of the assembly, but leave the leading
474 # whitespace in place.
475 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
476 # Expand the tabs used for indentation.
477 asm = string.expandtabs(asm, 2)
478 # Strip trailing whitespace.
479 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
480 return asm
483 def scrub_asm_ve(asm, args):
484 # Scrub runs of whitespace out of the assembly, but leave the leading
485 # whitespace in place.
486 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
487 # Expand the tabs used for indentation.
488 asm = string.expandtabs(asm, 2)
489 # Strip trailing whitespace.
490 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
491 return asm
494 def scrub_asm_csky(asm, args):
495 # Scrub runs of whitespace out of the assembly, but leave the leading
496 # whitespace in place.
497 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
498 # Expand the tabs used for indentation.
499 asm = string.expandtabs(asm, 2)
500 # Strip kill operands inserted into the asm.
501 asm = common.SCRUB_KILL_COMMENT_RE.sub("", asm)
502 # Strip trailing whitespace.
503 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
504 return asm
507 def scrub_asm_nvptx(asm, args):
508 # Scrub runs of whitespace out of the assembly, but leave the leading
509 # whitespace in place.
510 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
511 # Expand the tabs used for indentation.
512 asm = string.expandtabs(asm, 2)
513 # Strip trailing whitespace.
514 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
515 return asm
518 def scrub_asm_loongarch(asm, args):
519 # Scrub runs of whitespace out of the assembly, but leave the leading
520 # whitespace in place.
521 asm = common.SCRUB_WHITESPACE_RE.sub(r" ", asm)
522 # Expand the tabs used for indentation.
523 asm = string.expandtabs(asm, 2)
524 # Strip trailing whitespace.
525 asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r"", asm)
526 return asm
529 # Returns a tuple of a scrub function and a function regex. Scrub function is
530 # used to alter function body in some way, for example, remove trailing spaces.
531 # Function regex is used to match function name, body, etc. in raw llc output.
532 def get_run_handler(triple):
533 target_handlers = {
534 "i686": (scrub_asm_x86, ASM_FUNCTION_X86_RE),
535 "x86": (scrub_asm_x86, ASM_FUNCTION_X86_RE),
536 "i386": (scrub_asm_x86, ASM_FUNCTION_X86_RE),
537 "arm64_32": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
538 "aarch64": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
539 "aarch64-apple-darwin": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
540 "aarch64-apple-ios": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
541 "bpf": (scrub_asm_bpf, ASM_FUNCTION_BPF_RE),
542 "bpfel": (scrub_asm_bpf, ASM_FUNCTION_BPF_RE),
543 "bpfeb": (scrub_asm_bpf, ASM_FUNCTION_BPF_RE),
544 "hexagon": (scrub_asm_hexagon, ASM_FUNCTION_HEXAGON_RE),
545 "r600": (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE),
546 "amdgcn": (scrub_asm_amdgpu, ASM_FUNCTION_AMDGPU_RE),
547 "arm": (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),
548 "arm64": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
549 "arm64e": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
550 "arm64ec": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_RE),
551 "arm64-apple-ios": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
552 "arm64-apple-macosx": (scrub_asm_arm_eabi, ASM_FUNCTION_AARCH64_DARWIN_RE),
553 "armv7-apple-ios": (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE),
554 "armv7-apple-darwin": (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_DARWIN_RE),
555 "thumb": (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_RE),
556 "thumb-macho": (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_MACHO_RE),
557 "thumbv5-macho": (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_MACHO_RE),
558 "thumbv7s-apple-darwin": (scrub_asm_arm_eabi, ASM_FUNCTION_THUMBS_DARWIN_RE),
559 "thumbv7-apple-darwin": (scrub_asm_arm_eabi, ASM_FUNCTION_THUMB_DARWIN_RE),
560 "thumbv7-apple-ios": (scrub_asm_arm_eabi, ASM_FUNCTION_ARM_IOS_RE),
561 "m68k": (scrub_asm_m68k, ASM_FUNCTION_M68K_RE),
562 "mips": (scrub_asm_mips, ASM_FUNCTION_MIPS_RE),
563 "msp430": (scrub_asm_msp430, ASM_FUNCTION_MSP430_RE),
564 "avr": (scrub_asm_avr, ASM_FUNCTION_AVR_RE),
565 "ppc32": (scrub_asm_powerpc, ASM_FUNCTION_PPC_RE),
566 "ppc64": (scrub_asm_powerpc, ASM_FUNCTION_PPC_RE),
567 "powerpc": (scrub_asm_powerpc, ASM_FUNCTION_PPC_RE),
568 "riscv32": (scrub_asm_riscv, ASM_FUNCTION_RISCV_RE),
569 "riscv64": (scrub_asm_riscv, ASM_FUNCTION_RISCV_RE),
570 "lanai": (scrub_asm_lanai, ASM_FUNCTION_LANAI_RE),
571 "sparc": (scrub_asm_sparc, ASM_FUNCTION_SPARC_RE),
572 "spirv32": (scrub_asm_spirv, ASM_FUNCTION_SPIRV_RE),
573 "spirv64": (scrub_asm_spirv, ASM_FUNCTION_SPIRV_RE),
574 "s390x": (scrub_asm_systemz, ASM_FUNCTION_SYSTEMZ_RE),
575 "wasm32": (scrub_asm_wasm, ASM_FUNCTION_WASM_RE),
576 "wasm64": (scrub_asm_wasm, ASM_FUNCTION_WASM_RE),
577 "ve": (scrub_asm_ve, ASM_FUNCTION_VE_RE),
578 "csky": (scrub_asm_csky, ASM_FUNCTION_CSKY_RE),
579 "nvptx": (scrub_asm_nvptx, ASM_FUNCTION_NVPTX_RE),
580 "loongarch32": (scrub_asm_loongarch, ASM_FUNCTION_LOONGARCH_RE),
581 "loongarch64": (scrub_asm_loongarch, ASM_FUNCTION_LOONGARCH_RE),
583 handler = None
584 best_prefix = ""
585 for prefix, s in target_handlers.items():
586 if triple.startswith(prefix) and len(prefix) > len(best_prefix):
587 handler = s
588 best_prefix = prefix
590 if handler is None:
591 raise KeyError("Triple %r is not supported" % (triple))
593 return handler
596 ##### Generator of assembly CHECK lines
599 def add_checks(
600 output_lines,
601 comment_marker,
602 prefix_list,
603 func_dict,
604 func_name,
605 ginfo: common.GeneralizerInfo,
606 global_vars_seen_dict,
607 is_filtered,
609 # Label format is based on ASM string.
610 check_label_format = "{} %s-LABEL: %s%s%s%s".format(comment_marker)
611 return common.add_checks(
612 output_lines,
613 comment_marker,
614 prefix_list,
615 func_dict,
616 func_name,
617 check_label_format,
618 ginfo,
619 global_vars_seen_dict,
620 is_filtered=is_filtered,