透過您的圖書館登入
IP:18.119.107.161
  • 學位論文

基於LLVM之動態語言預先編譯架構

LLVM-based AOT Compilation for Dynamic Languages

指導教授 : 游逸平

摘要


本研究旨在建立一個針對動態語言的通用預先編譯架構。由於動態語言提供使用者較為靈活的設計特性,在特定領域一直受到開發者歡迎,近年來更成為與許多應用的核心語言,因而其執行效能對使用者操作體驗有重大影響。目前已有許多相關研究試圖改善個別語言的執行效能,然而由於動態語言的程式結構與型別資訊須經由直譯器動態解析,因而最佳化與編譯流程需依賴個別直譯器實作,而無法如靜態語言建立一通用編譯分析架構。 本研究實作基於LLVM此一靜態語言編譯分析架構,針對其IR作延伸使其能表現前端動態語言之語意,並且能支援動態型別與物件之程式模型。在此架構上實作型別分析流程,以靜態分析方法將型別資訊紀錄於IR結構上,最後將具有完整型別資訊且能夠被靜態編譯的程式轉換成標準LLVM IR此靜態表現形式,能夠直接應用其他現有最佳化技術。本研究主要貢獻在於將靜態型別分析流程抽象化,使單一分析流程能較容易被應用於其他動態語言。基於一共同架構上,分析流程之實作能夠被重複利用,而不用針對各種語言重複實作。 本研究以JavaScript作為第一個前端語言,並將產生的LLVM IR轉成Asm.js以測試對網頁應用的效能改進,實驗結果顯示在能夠被編譯的benchmark程式中,效能提升最高可達45%。

關鍵字

預先編譯 型別分析 JavaScript LLVM

並列摘要


Dynamic languages are good for fast development cycles and prototyping, and are now mainstream choices for application development. However, the poor performance of dynamic languages is usually a concern. There have been many studies on improving the performance of dynamic languages. Many of them share common features, but very few of their implementations can be reused because they highly depend on the runtime system. In this thesis we propose an LLVM-based ahead-of-time compilation framework, which can be considered a common infrastructure for language implementation, for dynamic languages. We extend the LLVM IR with a modified type representation and several high-level operations in order to represent dynamic features in dynamic languages. In addition, a type analysis method was implemented based on the framework, and with sufficient type information from the analysis, the code generator can map the extended IR back to LLVM IR. We evaluated the performance by comparing JavaScript programs with Asm.js programs that are compiled from the LLVM IR emitted by the proposed framework.Experiments show that, in some cases, Asm.js can get up to 45% of performance gain. Although due to the limitation of single analysis method, the framework still require some hint from programmers, the main contribution of this work is on the code reusing capability. With this framework as a common infrastructure, the developers from different language community can work together and reuse the code from each other.

參考文獻


[24] Todd A. Proebsting, Gregg Townsend, Patrick Bridges, John H. Hartman, Tim Newsham, and Scott A. Watterson. Toba: Java for applications – a way ahead of time (wat) compiler, 1997.
[10] John Aycock. A brief history of just-in-time. ACM Computing Surveys, 35:97–113, 2003.
[11] Poyu Chen and Yi-Ping You. JSComp : A Static Compiler for Hybrid Execution of JavaScript Programs. (July), 2014.
[12] David Flanagan. JavaScript : the definitive guide. O’Reilly, Sebastopol, CA, 2006.
[21] Francisco Ortin, Miguel A Labrador, and Jose M Redondo. A hybrid class- and prototype-based object model to support language-neutral structural intercession. Information and Software Technology, 56(2):199–219, 2014.

延伸閱讀