[前][次][番号順一覧][スレッド一覧]

ruby-changes:61284

From: Takashi <ko1@a...>
Date: Mon, 18 May 2020 14:22:31 +0900 (JST)
Subject: [ruby-changes:61284] 0e5a58b6bf (master): Mark some JIT-ed functions as COLDFUNC

https://git.ruby-lang.org/ruby.git/commit/?id=0e5a58b6bf

From 0e5a58b6bf6aae72b6290a8d68e0a1b6d9eb4f79 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Sun, 17 May 2020 21:55:41 -0700
Subject: 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.

diff --git a/tool/transform_mjit_header.rb b/tool/transform_mjit_header.rb
index 3e6aa6e..4a7e59d 100644
--- a/tool/transform_mjit_header.rb
+++ b/tool/transform_mjit_header.rb
@@ -27,7 +27,9 @@ module MJITHeader https://github.com/ruby/ruby/blob/trunk/tool/transform_mjit_header.rb#L27
   # 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 https://github.com/ruby/ruby/blob/trunk/tool/transform_mjit_header.rb#L64
     '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)) https://github.com/ruby/ruby/blob/trunk/tool/transform_mjit_header.rb#L265
   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) )+/, '')}"
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]