干擾感知的函式內嵌用於縮減程式大小
InterferenceAware Function Inlining for Code Size Reduction
摘要
減少程式大小是現今業界關注的一個重要問題,其中一種實現方式是透過編譯器對
函式呼叫進行函式內嵌。然而,像 GCC 和 LLVM 這類現代編譯器所使用的啟發式演
算法可能會產生次優的結果。我們可以利用自動調諧工具來解決這個問題。先前的一
個研究提出了局部內嵌自動調諧工具,透過調整函式內嵌的決定,在 SPEC2017 上和
LLVM Oz 比較,可以獲得 4.9% 的程式縮減。然而,局部內嵌自動調諧工具也有其侷
限性。它獨立地判斷每個函式呼叫的函式內嵌決策並將它們合併以得到整體的函式內
聯決策,這樣的做法在某些情下可能會產生問題,原因在於不同的函式呼叫之間可能
存在干擾,這種干擾可能增加調諧所需要的時間以及程式的大小。此外,我們發現在
大多數情況下,對一個函式呼叫進行函式內嵌通常只會影響附近的函式呼叫,我們將
這樣的關係稱為” 鄰居”。利用這個發現,我們可以大大減少調諧工具所需要的編譯次
數,並利用多核 CPU 將大型模組 (LLVM module) 的調諧平行化。我們提出了干擾感知
內嵌自動調諧工具來解決干擾的問題並加速調諧的過程。干擾感知內嵌自動調諧工具
的核心概念在於判斷內嵌決定時會考慮到之前所做的內嵌決定,並利用函式呼叫之間
的鄰居關係來改善調諧時間。實驗結果顯示,與局部內嵌自動調諧工具相比,干擾感
知內嵌自動調諧工具在 SPEC2017 上平均可以達到 0.3% 的程式縮減 (最高可達 1.4%) 以
及 2.9 倍的調諧時間加速 (對於耗時的調諧任務可達 3.7 倍)。
函式呼叫進行函式內嵌。然而,像 GCC 和 LLVM 這類現代編譯器所使用的啟發式演
算法可能會產生次優的結果。我們可以利用自動調諧工具來解決這個問題。先前的一
個研究提出了局部內嵌自動調諧工具,透過調整函式內嵌的決定,在 SPEC2017 上和
LLVM Oz 比較,可以獲得 4.9% 的程式縮減。然而,局部內嵌自動調諧工具也有其侷
限性。它獨立地判斷每個函式呼叫的函式內嵌決策並將它們合併以得到整體的函式內
聯決策,這樣的做法在某些情下可能會產生問題,原因在於不同的函式呼叫之間可能
存在干擾,這種干擾可能增加調諧所需要的時間以及程式的大小。此外,我們發現在
大多數情況下,對一個函式呼叫進行函式內嵌通常只會影響附近的函式呼叫,我們將
這樣的關係稱為” 鄰居”。利用這個發現,我們可以大大減少調諧工具所需要的編譯次
數,並利用多核 CPU 將大型模組 (LLVM module) 的調諧平行化。我們提出了干擾感知
內嵌自動調諧工具來解決干擾的問題並加速調諧的過程。干擾感知內嵌自動調諧工具
的核心概念在於判斷內嵌決定時會考慮到之前所做的內嵌決定,並利用函式呼叫之間
的鄰居關係來改善調諧時間。實驗結果顯示,與局部內嵌自動調諧工具相比,干擾感
知內嵌自動調諧工具在 SPEC2017 上平均可以達到 0.3% 的程式縮減 (最高可達 1.4%) 以
及 2.9 倍的調諧時間加速 (對於耗時的調諧任務可達 3.7 倍)。
Reducing code size is a significant concern in today’s industry, and one approach to achieve
this goal is by inlining function calls using a compiler. However, modern compilers, such as
GCC and LLVM, employ heuristics that can sometime result in suboptimal outcomes. To ad
dress this issue, autotuners have been introduced. One such tuner, known as the “local inlining
autotuner,” was proposed in prior research. This autotuner can achieve a 4.9% reduction in
code size compared to LLVM Oz on SPEC2017 by finetuning function inlining decisions.
Nevertheless, the local inlining autotuner has its limitations. It finetunes each function inlin
ing decision separately and then combines them to obtain the final function inlining decisions.
This approach can lead to problems in some cases due to potential interference between function
calls, resulting in longer tuning times and larger code sizes. Moreover, we found that, in most
cases, the impact of inlining a function call only affects nearby function calls, which we refer to
as “neighbors.” By leveraging this fact, we can significantly reduce the amount of recompilation
required by the tuner and make use of multicore CPUs by parallelizing the tuning process for
large modules. We propose an improved autotuner for function inlining called “interference
aware inlining autotuner” to address the interference problem and expedite the tuning process.
The central concept behind the interferenceaware inlining autotuner is to consider the effect of
inlining a function call when making subsequent decision and exploit the neighbor relationship
between function calls to enhance tuning efficiency. Experiments have demonstrated that the
interferenceaware autotuner achieved a 0.3% smaller code size (up to 1.4%) and 2.9x faster
tuning time (3.7x on timeconsuming tuning tasks) on average on SPEC2017 compared to the
local inlining autotuner.
this goal is by inlining function calls using a compiler. However, modern compilers, such as
GCC and LLVM, employ heuristics that can sometime result in suboptimal outcomes. To ad
dress this issue, autotuners have been introduced. One such tuner, known as the “local inlining
autotuner,” was proposed in prior research. This autotuner can achieve a 4.9% reduction in
code size compared to LLVM Oz on SPEC2017 by finetuning function inlining decisions.
Nevertheless, the local inlining autotuner has its limitations. It finetunes each function inlin
ing decision separately and then combines them to obtain the final function inlining decisions.
This approach can lead to problems in some cases due to potential interference between function
calls, resulting in longer tuning times and larger code sizes. Moreover, we found that, in most
cases, the impact of inlining a function call only affects nearby function calls, which we refer to
as “neighbors.” By leveraging this fact, we can significantly reduce the amount of recompilation
required by the tuner and make use of multicore CPUs by parallelizing the tuning process for
large modules. We propose an improved autotuner for function inlining called “interference
aware inlining autotuner” to address the interference problem and expedite the tuning process.
The central concept behind the interferenceaware inlining autotuner is to consider the effect of
inlining a function call when making subsequent decision and exploit the neighbor relationship
between function calls to enhance tuning efficiency. Experiments have demonstrated that the
interferenceaware autotuner achieved a 0.3% smaller code size (up to 1.4%) and 2.9x faster
tuning time (3.7x on timeconsuming tuning tasks) on average on SPEC2017 compared to the
local inlining autotuner.