summaryrefslogtreecommitdiff
path: root/tool/transform_mjit_header.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2020-05-17 21:55:41 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2020-05-17 22:21:31 -0700
commit0e5a58b6bf6aae72b6290a8d68e0a1b6d9eb4f79 (patch)
treeb301289b562b6a5856e6940136b47c610feb41a2 /tool/transform_mjit_header.rb
parentc0cd474d4ffedb1eeb49505f53c0727a008bdd3e (diff)
Mark some JIT-ed functions as COLDFUNC
Put some functions which are unlikely to be called on JIT in .text.unlikely section to improve hot code's locality.
Diffstat (limited to 'tool/transform_mjit_header.rb')
-rw-r--r--tool/transform_mjit_header.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/tool/transform_mjit_header.rb b/tool/transform_mjit_header.rb
index 3e6aa6e0d0..4a7e59d526 100644
--- a/tool/transform_mjit_header.rb
+++ b/tool/transform_mjit_header.rb
@@ -27,7 +27,9 @@ module MJITHeader
# These macros are relied on this script's transformation
PREFIXED_MACROS = [
'ALWAYS_INLINE',
+ 'COLDFUNC',
'inline',
+ 'RBIMPL_ATTR_COLD',
]
# For MinGW's ras.h. Those macros have its name in its definition and can't be preprocessed multiple times.
@@ -62,6 +64,15 @@ module MJITHeader
'vm_opt_not',
]
+ COLD_FUNCTIONS = %w[
+ setup_parameters_complex
+ vm_call_iseq_setup
+ vm_call_iseq_setup_2
+ vm_call_iseq_setup_tailcall
+ vm_call_method_each_type
+ vm_ic_update
+ ]
+
# Return start..stop of last decl in CODE ending STOP
def self.find_decl(code, stop)
level = 0
@@ -254,6 +265,11 @@ while (decl_range = MJITHeader.find_decl(code, stop_pos))
if MJITHeader::IGNORED_FUNCTIONS.include?(decl_name) && /#{MJITHeader::FUNC_HEADER_REGEXP}{/.match(decl)
transform_logs[:def_to_decl] << decl_name
code[decl_range] = decl.sub(/{.+}/m, ';')
+ elsif MJITHeader::COLD_FUNCTIONS.include?(decl_name) && match = /#{MJITHeader::FUNC_HEADER_REGEXP}{/.match(decl)
+ header = match[0].sub(/{\z/, '').strip
+ header = "static #{header.sub(/\A((static|inline) )+/, '')}"
+ decl[match.begin(0)...match.end(0)] = '{' # remove header
+ code[decl_range] = "\nCOLDFUNC #{header} #{decl}"
elsif MJITHeader::ALWAYS_INLINED_FUNCTIONS.include?(decl_name) && match = /#{MJITHeader::FUNC_HEADER_REGEXP}{/.match(decl)
header = match[0].sub(/{\z/, '').strip
header = "static inline #{header.sub(/\A((static|inline) )+/, '')}"