[Intel-xe] [PATCH v2 00/11] Start register cleanup
Lucas De Marchi
lucas.demarchi at intel.com
Fri Feb 17 06:19:34 UTC 2023
On Thu, Feb 16, 2023 at 04:52:15PM -0800, Lucas De Marchi wrote:
>Start cleaning up the register definitions used in xe.
>This removes dependency on the following registers:
>
> - intel_engine_regs.h
> - intel_gt_regs.h
> - intel_lrc_reg.h
> - intel_gpu_commands.h
> - i915_reg.h
> - intel_mchbar_regs.h
>
>The includes on the display/ part are left as is since there is still
>some more work to do to detangle dependencies. Other than from the
>display/ files, xe still depends on:
>
> - i915_reg_defs.h
> - display/intel_display_core.h
> - display/ext/intel_device_info.h
> - display/ext/intel_pch.h
>
>The first one are the generic defines used for defining the registers.
>They probably can be split and part of them copied to include/drm to be
>shared across the drivers. The last 3 are expected to be cleaned up
>together with the rest of the display.
>
>This series started by doing it manually with a few greps, migrated in
>the middle to do by "remove the include, parse the warnings from the
>compile and use that to generate the header" and finished with a small
>python script with clang. There may be some inconsistencies how the
fwiw this is the quick hack script I used (helper.py only exports a
git() wrapper). It does ~90% of the job -
just couldn't find a way to make it recurse into the macros - we'd need
the preprocessed header, but then the values would not be valid.
------8<------------
#!/usr/bin/python3
import sys
import clang.cindex
import helpers
FILE = sys.argv[1]
file_data = open(FILE, "r").readlines()
macros_instantiated = []
macros = dict()
macros_prereq = []
def is_used_by_xe(macro):
return helpers.git(["grep", "-q", f"\\b{macro}\\b", "--", "drivers/gpu/drm/xe/", ":(exclude)drivers/gpu/drm/xe/display/ext/"], check=False).returncode == 0
def print_source(node):
sline = node.extent.start.line
eline = node.extent.end.line
ecolumn = node.extent.end.column
line = sline
while line < eline:
print(file_data[line - 1].rstrip())
line += 1
print(file_data[line - 1][:ecolumn].rstrip())
def recurse(node):
if node.kind == clang.cindex.CursorKind.MACRO_DEFINITION and str(node.location.file) == FILE:
macros[node.spelling] = node
if is_used_by_xe(node.spelling):
print_source(node)
elif node.kind == clang.cindex.CursorKind.MACRO_INSTANTIATION and str(node.location.file) == FILE:
macros_instantiated.append(node)
for c in node.get_children():
recurse(c)
index = clang.cindex.Index.create()
root = index.parse(FILE,
options=clang.cindex.TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD |
clang.cindex.TranslationUnit.PARSE_INCOMPLETE |
clang.cindex.TranslationUnit.PARSE_SKIP_FUNCTION_BODIES)
recurse(root.cursor)
for node in macros_instantiated:
if node.spelling in macros:
macros_prereq.append(macros[node.spelling])
macros_prereq.sort(key=lambda x: x.location.line)
if len(macros_prereq):
print("\n\n/* move me up */\n\n")
for node in macros_prereq:
print_source(node)
More information about the Intel-xe
mailing list