计算机工程与应用 ›› 2017, Vol. 53 ›› Issue (3): 41-46.DOI: 10.3778/j.issn.1002-8331.1505-0129

• 理论与研发 • 上一篇    下一篇

基于LLVM的函数内联优化技术研究

郭振华,吴艳霞,安龙飞,张国印,卢文祥   

  1. 哈尔滨工程大学 计算机科学与技术学院,哈尔滨 150001
  • 出版日期:2017-02-01 发布日期:2017-05-11

Study on function inlining optimization technologies based on LLVM

GUO Zhenhua, WU Yanxia, AN Longfei, ZHANG Guoyin, LU Wenxiang   

  1. College of Computer Science and Technology, Harbin Engineering University, Harbin 150001, China
  • Online:2017-02-01 Published:2017-05-11

摘要: 函数内联(Function Inlining)是使用函数体代替函数调用的一种编译优化技术。LLVM中原生的内联模型只根据函数体的大小来判断函数内联与否,而没有考虑函数的调用次数和后续的优化。针对这个问题,提出了基于函数调用次数(NFC)和考虑后续循环合并(BLF)的新内联模型。首先,通过NFC模型对被多次调用的函数进行内联,进而减少更多因函数调用而产生的额外消耗。其次,通过BLF模型能够识别出进行内联后可以进一步进行循环合并优化的函数,为后续循环合并优化提供支持。实验结果表明,提出的函数内联优化技术是可行的,测试程序平均加速比为1.52%。

关键词: 编译优化, 函数内联, 调用次数, 循环合并, 加速比

Abstract: Function inlining is a compile optimization technique, that is using the body of a function instead of the call site. LLVM’s original inline model considers the factor of the size of the function, but not considers the factor of execution frequency and potential optimization opportunities. In this paper, a new inline model, considers both execution frequency and potential optimization opportunities, proposed to avoid drawbacks of original inline model. The NFC model, can reduce consumption generated by calling more function calls, by inlining functions repeatedly called. The BLF model provides supports for the subsequent optimization for loop fusion, by inlining functions. In the experiment, function inlining optimization model proposed by this paper is effective. Average speedup ratio of test program is 1.52%.

Key words: compiler optimization, function inline, Number of Function be Called(NFC), Benefit for Loop Fusion(BLF), speedup