Difference between revisions of "NaplesPU LLVM Documentation"

From NaplesPU Documentation
Jump to: navigation, search
Line 2: Line 2:
 
The nu+ backend is contained in the '''NuPlus''' folder under "compiler/lib/Target" directory. It contains several files, each implementing a specific class of the LLVM Framework.
 
The nu+ backend is contained in the '''NuPlus''' folder under "compiler/lib/Target" directory. It contains several files, each implementing a specific class of the LLVM Framework.
  
An LLVM backend is constructed on two types of file, C++ and TableGen source files. Refer to section [[TableGen | TableGen]] to get a detailed explanation of it.
+
An LLVM backend is constructed on two types of file, C++ and TableGen source files. Refer to section [[Nu+ LLVM Documentation:TableGen | TableGen]] to get a detailed explanation of it.
  
 
== Required reading ==
 
== Required reading ==

Revision as of 19:36, 30 March 2019

The main task of the backend is to generate nu+ assembly code from the LLVM IR obtained by the Clang frontend. It also handles object representation of classes needed to create the assembler and the disassembler. The nu+ backend is contained in the NuPlus folder under "compiler/lib/Target" directory. It contains several files, each implementing a specific class of the LLVM Framework.

An LLVM backend is constructed on two types of file, C++ and TableGen source files. Refer to section TableGen to get a detailed explanation of it.

Required reading

Before working on LLVM, you should be familiar with some things. In particular:

  1. Basic Blocks
  2. SSA (Static Single Assignment) form
  3. AST (Abstract Syntax tree)
  4. DAG Direct Acyclic Graph.

In addition to general aspects about compilers, it is recommended to review the following topics:

  1. LLVM architecture
  2. LLVM Intermediate Representation
  3. Tablegen

See the following textbook for other informations Getting Started with LLVM Core Libraries and LLVM Cookbook.

See also this article to get an overview of the main CodeGenerator phases.

TableGen

TableGen is a record-oriented language used to describe the target-specific information. It is written by the LLVM team in order to simplify the back-end development and to avoid potential code redundancy. For example, by using TableGen, if some feature of the target-specific register file changes, you do not need to modify different files wherever the register appears but you need only to modify the .td file that contains its definition. Actually, the TableGen is used to define instruction formats, instructions, registers, pattern-matching DAGs, instruction selection matching order, calling conventions, and target platform properties.

The files implemented in the nu+ backend are:

  • NuPlus.td, used to describe a target and to instruct LLVM about the names of the classes used for each of the framework component.
  • NuPlusRegisterInfo.td, contains the definition of the nu+ register file.
  • NuPlusCallingConv.td, used to define the calling conventions to use when a function is called.
  • NuPlusInstrFormats.td and NuPlusInstrInfo.td, defining the instructions supported by the nu+ architecture and the patterns LLVM must use to translate the LLVM IR in nu+ asm.

After compiling LLVM, TableGen will translate these .td files generating the .inc files located in build/lib/Target/NuPlus.

C++ classes implementation

Inside the AsmParser folder:

Inside the Disassembler folder:

Inside the InstPrinter folder:

Inside the MCTargetDesc folder:

Case studies