22#
33# SPDX-License-Identifier: Apache-2.0
44
5- import logging
5+ import warnings
66
77from llvmlite import binding as ll
88from llvmlite import ir as llvmir
@@ -31,7 +31,9 @@ def _optimize_functions(self, ll_module):
3131
3232 @property
3333 def inline_threshold (self ):
34- """The inlining threshold value to be used to optimize the final library"""
34+ """
35+ The inlining threshold value to be used to optimize the final library.
36+ """
3537 if hasattr (self , "_inline_threshold" ):
3638 return self ._inline_threshold
3739 else :
@@ -41,11 +43,17 @@ def inline_threshold(self):
4143 def inline_threshold (self , value : int ):
4244 """Returns the current inlining threshold level for the library."""
4345 if value < 0 or value > 3 :
44- logging . warning (
46+ warnings . warn (
4547 "Unsupported inline threshold. Set a value between 0 and 3"
4648 )
4749 self ._inline_threshold = 0
4850 else :
51+ if value == 3 :
52+ warnings .warn (
53+ "Due to an existing compiler bug, setting INLINE_THRESHOLD "
54+ f"to { value } can lead to incorrect code generation on "
55+ "certain devices."
56+ )
4957 self ._inline_threshold = value
5058
5159 def _optimize_final_module (self ):
@@ -55,44 +63,20 @@ def _optimize_final_module(self):
5563 # Make optimization level depending on config.DPEX_OPT variable
5664 pmb .opt_level = config .DPEX_OPT
5765 if config .DPEX_OPT > 2 :
58- logging . warning (
66+ warnings . warn (
5967 "Setting NUMBA_DPEX_OPT greater than 2 known to cause issues "
6068 + "related to very aggressive optimizations that leads to "
6169 + "broken code."
6270 )
6371
6472 pmb .disable_unit_at_a_time = False
6573
66- if config .INLINE_THRESHOLD is not None :
67- # Check if a decorator-level inline threshold was set and use that
68- # instead of the global configuration.
69- if (
70- hasattr (self , "_inline_threshold" )
71- and self ._inline_threshold > 0
72- and self ._inline_threshold <= 3
73- ):
74- logging .warning (
75- "Setting INLINE_THRESHOLD leads to very aggressive "
76- + "optimizations that may produce incorrect binary."
77- )
78- pmb .inlining_threshold = self ._inline_threshold
79- elif not hasattr (self , "_inline_threshold" ):
80- logging .warning (
81- "Setting INLINE_THRESHOLD leads to very aggressive "
82- + "optimizations that may produce incorrect binary."
83- )
84- pmb .inlining_threshold = config .INLINE_THRESHOLD
85- else :
86- if (
87- hasattr (self , "_inline_threshold" )
88- and self ._inline_threshold > 0
89- and self ._inline_threshold <= 3
90- ):
91- logging .warning (
92- "Setting INLINE_THRESHOLD leads to very aggressive "
93- + "optimizations that may produce incorrect binary."
94- )
95- pmb .inlining_threshold = self ._inline_threshold
74+ # The PassManagerBuilder's inlining_threshold property is set only when
75+ # inline_threshold is g.t. 0. Doing otherwise, *i.e.*, setting the
76+ # pmb.inlining_threshold to 0 will lead to at minimum `alwaysinline`
77+ # pass to run.
78+ if self .inline_threshold > 0 :
79+ pmb .inlining_threshold = self .inline_threshold
9680
9781 pmb .disable_unroll_loops = True
9882 pmb .loop_vectorize = False
0 commit comments