Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic setup for getting raw LLVM remarks output #9601

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions numba/core/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 18,7 @@
from numba.core.errors import NumbaInvalidConfigWarning
from numba.misc.inspection import disassemble_elf_to_cfg
from numba.misc.llvm_pass_timings import PassTimingsCollection

from numba.core.targetconfig import TargetConfig

_x86arch = frozenset(['x86', 'i386', 'i486', 'i586', 'i686', 'i786',
'i886', 'i986'])
Expand Down Expand Up @@ -672,14 672,29 @@ def _optimize_final_module(self):
with self._recorded_timings.record(cheap_name):
# A cheaper optimisation pass is run first to try and get as many
# refops into the same function as possible via inlining
self._codegen._mpm_cheap.run(self._final_module)
if config.LLVM_REMARKS:
res_cheap, yml_string_cheap = self._codegen._mpm_cheap.run_with_remarks(self._final_module)
else:
res_cheap = self._codegen._mpm_cheap.run(self._final_module)
# Refop pruning is then run on the heavily inlined function
if not config.LLVM_REFPRUNE_PASS:
self._final_module = remove_redundant_nrt_refct(self._final_module)
full_name = "Module passes (full optimization)"
with self._recorded_timings.record(full_name):
# The full optimisation suite is then run on the refop pruned IR
self._codegen._mpm_full.run(self._final_module)
if config.LLVM_REMARKS:
res_full, yml_string_full = self._codegen._mpm_full.run_with_remarks(self._final_module)
else:
res_full = self._codegen._mpm_full.run(self._final_module)

if config.LLVM_REMARKS:
if config.LLVM_REMARKS_FILE:
with open(config.LLVM_REMARKS_FILE, "a") as f:
f.write(yml_string_cheap)
f.write(yml_string_full)
else:
print(yml_string_cheap)
print(yml_string_full)

def _get_module_for_linking(self):
"""
Expand Down
6 changes: 6 additions & 0 deletions numba/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 573,12 @@ def which_gdb(path_or_bin):
"NUMBA_LLVM_REFPRUNE_FLAGS", str,
"all" if LLVM_REFPRUNE_PASS else "",
)
LLVM_REMARKS = _readenv(
"NUMBA_LLVM_REMARKS", int, 0,
)
LLVM_REMARKS_FILE = _readenv(
"NUMBA_LLVM_REMARKS_FILE", str, "",
)

# llvmlite memory manager
USE_LLVMLITE_MEMORY_MANAGER = _readenv(
Expand Down
2 changes: 1 addition & 1 deletion numba/core/lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 57,7 @@ def __init__(self, context, library, fndesc, func_ir, metadata=None):

# Debuginfo
dibuildercls = (self.context.DIBuilder
if self.context.enable_debuginfo
if self.context.enable_debuginfo or config.LLVM_REMARKS
else debuginfo.DummyDIBuilder)

# debuginfo def location
Expand Down
1 change: 1 addition & 0 deletions numba/experimental/remarks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
from .remarks import RemarksInterface
Loading
Loading