llvm.org GIT mirror llvm / d0f1843
update_mir_test_checks: Support adding checks for vreg classes This is a temporary hack to support adding checks for the "registers:" block of mir functions. This is necessary to convert a number of tests so that there's less churn when we change the MIR printer to put the vreg classes on defs instead of in their own block. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316134 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 3 years ago
1 changed file(s) with 24 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
4040 r'^ *(?P{0}(?:, {0})*) '
4141 r'= (?P[A-Zt][A-Za-z0-9_]+)'.format(VREG_RE.pattern))
4242 PREFIX_DATA_RE = re.compile(r'^ *(;|bb.[0-9].*: *$|[a-z]+:( |$)|$)')
43 VREG_CLASS_RE = re.compile(r'^ *- *{ id: ([0-9]+), class: ([a-z0-9_]+)', re.M)
4344
4445 MIR_FUNC_RE = re.compile(
4546 r'^---$'
4647 r'\n'
4748 r'^ *name: *(?P[A-Za-z0-9_.-]+)$'
49 r'(?:.*?(?P^ *registers: *(?:\n *- {[^\n]+$)*))?'
4850 r'.*?'
4951 r'^ *body: *\|\n'
5052 r'(?P.*?)\n'
189191 warn('Found conflicting asm for prefix: {}'.format(prefix),
190192 test_file=test)
191193 func_dict[prefix][func] = body
194 func_dict[prefix]['{}:vregs'.format(func)] = m.group('vregs')
192195
193196
194197 def add_checks_for_function(test, output_lines, run_list, func_dict, func_name,
195 single_bb, verbose=False):
198 add_vreg_checks, single_bb, verbose=False):
196199 printed_prefixes = set()
197200 for run in run_list:
198201 for prefix in run.prefixes:
205208 # output_lines.append('')
206209 printed_prefixes.add(prefix)
207210 log('Adding {} lines for {}'.format(prefix, func_name), verbose)
211 vregs = None
212 if add_vreg_checks:
213 vregs = func_dict[prefix]['{}:vregs'.format(func_name)]
208214 add_check_lines(test, output_lines, prefix, func_name, single_bb,
209 func_dict[prefix][func_name].splitlines())
215 func_dict[prefix][func_name].splitlines(), vregs)
210216 break
211217 return output_lines
212218
213219
214220 def add_check_lines(test, output_lines, prefix, func_name, single_bb,
215 func_body):
221 func_body, vreg_data):
216222 if single_bb:
217223 # Don't bother checking the basic block label for a single BB
218224 func_body.pop(0)
228234 check = '{:>{}}; {}'.format('', indent, prefix)
229235
230236 output_lines.append('{}-LABEL: name: {}'.format(check, func_name))
237
238 if vreg_data:
239 output_lines.append('{}: registers:'.format(check))
240 for m in VREG_CLASS_RE.finditer(vreg_data):
241 output_lines.append('{}-NEXT: id: {}, class: {}'.format(
242 check, m.group(1), m.group(2)))
231243
232244 vreg_map = {}
233245 for func_line in func_body:
286298 return True
287299
288300
289 def update_test_file(llc, test, remove_common_prefixes=False, verbose=False):
301 def update_test_file(llc, test, remove_common_prefixes=False,
302 add_vreg_checks=False, verbose=False):
290303 log('Scanning for RUN lines in test file: {}'.format(test), verbose)
291304 with open(test) as fd:
292305 input_lines = [l.rstrip() for l in fd]
359372 continue
360373 state = 'function body'
361374 add_checks_for_function(test, output_lines, run_list,
362 func_dict, func_name, single_bb=False,
363 verbose=verbose)
375 func_dict, func_name, add_vreg_checks,
376 single_bb=False, verbose=verbose)
364377 elif state == 'function prefix':
365378 m = PREFIX_DATA_RE.match(input_line)
366379 if not m:
367380 state = 'function body'
368381 add_checks_for_function(test, output_lines, run_list,
369 func_dict, func_name, single_bb=True,
370 verbose=verbose)
382 func_dict, func_name, add_vreg_checks,
383 single_bb=True, verbose=verbose)
371384
372385 if should_add_line_to_output(input_line, prefix_set):
373386 output_lines.append(input_line)
394407 parser.add_argument('--remove-common-prefixes', action='store_true',
395408 help='Remove existing check lines whose prefixes are '
396409 'shared between multiple commands')
410 parser.add_argument('--add-vreg-checks', action='store_true',
411 help='Add checks for the "registers:" block')
397412 parser.add_argument('tests', nargs='+')
398413 args = parser.parse_args()
399414
400415 for test in args.tests:
401416 try:
402417 update_test_file(args.llc, test, args.remove_common_prefixes,
403 verbose=args.verbose)
418 args.add_vreg_checks, verbose=args.verbose)
404419 except Exception:
405420 warn('Error processing file', test_file=test)
406421 raise