簡易檢索 / 詳目顯示

研究生: 蘇敬傑
Su, Jing-Jie
論文名稱: 基於LLVM架構的半自動編譯研究與實現
Research and Implementation of Semi-automatic Compilation Based on the LLVM Framework
指導教授: 周哲民
Jou, Jer-Min
學位類別: 碩士
Master
系所名稱: 電機資訊學院 - 電機工程學系
Department of Electrical Engineering
論文出版年: 2021
畢業學年度: 109
語文別: 中文
論文頁數: 53
中文關鍵詞: 編譯器 、RISC-V 、LLVM 、後端移植 、指令集
外文關鍵詞: compiler, RISC-V, LLVM, back-end porting, instruction set
相關次數: 點閱:137  下載:0 
分享至:
查詢本校圖書館目錄 查詢臺灣博碩士論文知識加值系統 勘誤回報
  • 如今,對嵌入式處理器的需求隨著應用的變化而有所不同,因此處理器架構需要相應地改變,或者需要擴展指令集架構(ISA)。採用RISC作為開源指令集架構的RISC-V處理器已經逐漸成為取代基於ARM處理器的選擇。自從引入LLVM後,它幾乎總是被用來開發新的架構或移植嵌入式系統的編譯器後端。隨著LLVM功能的不斷增加,如何提高編譯器後端的品質和模組化是值得探討的。
    本文重點介紹了TableGen工具在LLVM後端架構中的應用,其對目標暫存器和目標指令集.td(target description)檔的描述,以及後端編譯器的構建過程,分析了後端代碼生成過程,並在構建過程中完成了對目標機器系統屬性的描述。由於每個目標架構中的暫存器和指令集的描述都使用了TableGen的語法和結構,在本文最後,可以在現有架構下增加擴展指令集。
    最後,本文將以32位元整數RISC-V架構為例,實現暫存器、堆疊佈局、指令描述等;完成組合語言輸出,用模擬器測試,以保證編譯器的準確性。

    Nowadays, the demand for embedded processors varies with the application, so the processor architecture needs to be changed accordingly, or the instruction set architecture (ISA) needs to be extended. The RISC-V processor, which uses RISC as the open source instruction set architecture, has gradually become the choice to replace the ARM-based processors. Since the introduction of LLVM, it is almost always used to develop a new architecture or to port the compiler backend of an embedded system. With the increasing functionality of LLVM, it is worthwhile to explore how to improve the quality and modularity of the compiler backend.
    In this paper, we focus on the use of the TableGen tool in the LLVM backend architecture, its description of the target registers and the target instruction set file.td (target description), and the construction process of the backend compiler, analyzing the backend code generation process and completing the description of the properties of the target machine system during the construction process. Since the description of registers and instruction sets in each target architecture uses the syntax and structure of TableGen, after this paper, it is possible to add extended instruction sets under the existing architecture.
    Finally, in this paper, we will use the 32-bit integer RISC-V architecture as an example to realize the register, stack layout, instruction description, etc.; we will complete the assembly language output and use the simulator to test it to ensure the accuracy of the compiler.

    摘要 I SUMMARY II INTRODUCTION III METHODS IV RESULTS VI CONCLUSION X 誌謝 XI 目錄 XII 表目錄 XV 圖目錄 XVI 第一章 緒論 1 1.1研究背景 1 1.2研究動機與目的 2 1.3論文架構 3 第二章 背景知識與相關研究 4 2.1 LLVM簡介 4 2.1.1 LLVM編譯器架構 4 2.1.2 LLVM IR 5 2.1.3 LLVM前端 6 2.1.4 LLVM中間端 7 2.1.5 LLVM後端 8 2.2 RISC-V簡介 8 第三章 LLVM後端移植策略 9 3.1 TableGen工具 10 3.1.1 TableGen基本功能 10 3.1.2 TableGen語法規則 11 3.2 後端移植介面 12 3.2.1 全域描述類 12 3.2.2 暫存器描述類 13 3.2.3 指令集類 16 3.2.4 指令選擇類 18 3.2.5 組譯輸出類 20 3.3 後端代碼生成機制 21 3.3.1 指令選擇 21 3.3.2 暫存器分配 22 3.3.3 代碼發送 24 第四章 RISC-V後端移植實現 26 4.1 RISC-V的體系結構 26 4.1.1 指令集架構 26 4.1.2 暫存器組態 29 4.1.3 存儲器空間 30 4.1.4 尋址方式 30 4.2 RISC-V的編譯器後端設計 30 4.2.1 RISC-V的資料表示 31 4.2.2 堆疊幀佈局 31 4.3 RISC-V後端移植實現 32 4.3.1 全域描述實現 33 4.3.2 暫存器描述實現 33 4.3.3 指令集描述實現 35 4.3.4 指令變換實現 37 4.3.5 目標機器指令選擇流程 39 4.3.6 組譯輸出實現 41 4.3.7 編譯器整合 42 第五章 實驗結果與分析 44 5.1 實驗環境 44 5.2 實驗方法與結果分析 44 5.2.1 使用llc進行編譯測試 45 5.2.2 使用clang進行編譯測試 48 第六章 結論與未來展望 51 參考文獻 52

    [1] Asanovic, Krste, and Andrew Waterman. "The RISC-V Instruction Set Manual." Privileged Architecture, Document Version 20190608-Priv-MSU-Ratified. Vol. 2. RISC-V Foundation, 2019.
    [2] Chung-Shu, Chen. "Tutorial: Creating an LLVM Backend for the Cpu0 Architecture." 2021.
    [3] Adve, Vikram, et al. "LLVA: A low-level virtual instruction set architecture." Proceedings. 36th Annual IEEE/ACM International Symposium on Microarchitecture, 2003. MICRO-36.. IEEE, 2003.
    [4] Lattner, Chris, and Vikram Adve. "LLVM: A compilation framework for lifelong program analysis & transformation." International Symposium on Code Generation and Optimization, 2004. CGO 2004. IEEE, 2004.
    [5] Lattner, Chris. "Introduction to the llvm compiler infrastructure." Itanium conference and expo. 2006.
    [6] Lattner, Chris. "LLVM and Clang: Next generation compiler technology." The BSD conference. Vol. 5. 2008.
    [7] Lattner, Chris. "Intro to the LLVM MC Project." 2010.
    [8] Lopes, Bruno Cardoso, and Rafael Auler. Getting started with LLVM core libraries. Packt Publishing Ltd, 2014.
    [9] Sarda, Suyog, and Mayur Pandey. LLVM Cookbook. Packt Publishing Ltd, 2015.
    [10] "User Guides." User Guides - LLVM 13 Documentation. Web. 22 Sept. 2021.
    [11] Cytron, Ron, et al. "Efficiently computing static single assignment form and the control dependence graph." ACM Transactions on Programming Languages and Systems (TOPLAS) 13.4 (1991): 451-490. 1991.
    [12] Chang, Pokai. "The LLVM Compiler Infrastructure." 14 June 2017. Web. 22 Sept. 2021.
    [13] 劉俊波。基於LLVM的編譯器移植中關鍵技術研究。中國南開大學。2012。
    [14] 董峰。LLVM編譯系統結構分析與後端移植。上海交通大學。2007。
    [15] 夏睿傑、陳躍躍、孫海燕、陽柳、王霽、廖坤、李燦。基於LLVM架構的Matrix2 DSP後端移植及其浮點數據比較指令的實現。第十八屆電腦工程與工藝年會暨第四屆微處理器技術論壇論文集。2014。

    無法下載圖示
    校外:不公開
    電子論文及紙本論文均尚未授權公開
    QR CODE