Difference between revisions of "NaplesPU LLVM Documentation"

From NaplesPU Documentation
Jump to: navigation, search
(Tablegen files)
m
Line 9: Line 9:
 
# [https://en.wikipedia.org/wiki/Directed_acyclic_graph '''DAG''' Direct Acyclic Graph].
 
# [https://en.wikipedia.org/wiki/Directed_acyclic_graph '''DAG''' Direct Acyclic Graph].
  
In addition to general aspects about compilers, it is recommended to read about:
+
In addition to general aspects about compilers, it is recommended to review the following topics:
 
#[http://www.aosabook.org/en/llvm.html '''LLVM architecture''']
 
#[http://www.aosabook.org/en/llvm.html '''LLVM architecture''']
 
#[http://llvm.org/docs/LangRef.html '''LLVM Intermediate Representation''']  
 
#[http://llvm.org/docs/LangRef.html '''LLVM Intermediate Representation''']  
Line 16: Line 16:
 
See the following textbook for other informations [http://books.tarsoit.com/Getting%20Started%20with%20LLVM%20Core%20Libraries.pdf Getting Started with LLVM Core Libraries] and [https://github.com/iBreaker/book/blob/master/LLVM%20Cookbook.pdf LLVM Cookbook].
 
See the following textbook for other informations [http://books.tarsoit.com/Getting%20Started%20with%20LLVM%20Core%20Libraries.pdf Getting Started with LLVM Core Libraries] and [https://github.com/iBreaker/book/blob/master/LLVM%20Cookbook.pdf LLVM Cookbook].
  
See also [https://eli.thegreenplace.net/2012/11/24/life-of-an-instruction-in-llvm this article] to have an overview of the main CodeGenerator phases.
+
See also [https://eli.thegreenplace.net/2012/11/24/life-of-an-instruction-in-llvm this article] to get an overview of the main CodeGenerator phases.
  
 
== Tablegen files ==
 
== Tablegen files ==
  
These files describe, through the [http://llvm.org/docs/TableGen/index.html Tablegen] description language, the target architecture like the register file, the instruction set and the calling conventions. The classes defined in the following files are derived from one or more base classes which, forming an inheritance hierarchy. The list of base classes, including some internal documentation, is provided in the '''Target.td''' file or in the other files located in the ''compiler/include/llvm/Target/'' folder.  
+
These files describe, through the [http://llvm.org/docs/TableGen/index.html Tablegen] description language, the target architecture like the register file, the instruction set and the calling conventions. The classes defined in the following files are derived from one or more base classes which form an inheritance hierarchy. The list of base classes, including some internal documentation, is provided in the '''Target.td''' file or in the other files located in the ''compiler/include/llvm/Target/'' folder.  
  
 
The files implemented in the nu+ backend are:
 
The files implemented in the nu+ backend are:
Line 27: Line 27:
 
*[[NuPlusRegisterInfo.td | NuPlusRegisterInfo.td]], contains the definition of the nu+ register file.
 
*[[NuPlusRegisterInfo.td | NuPlusRegisterInfo.td]], contains the definition of the nu+ register file.
 
*[[NuPlusCallingConv.td | NuPlusCallingConv.td]], used to define the calling conventions to use when a function is called.  
 
*[[NuPlusCallingConv.td | NuPlusCallingConv.td]], used to define the calling conventions to use when a function is called.  
*[[NuPlusInstrFormats.td | NuPlusInstrFormats.td]] and [[NuPlusInstrInfo.td | NuPlusInstrInfo.td]], define the instructions supported by the nu+ architecture and the pattern LLVM must use to translate the LLVM IR in nu+ asm.
+
*[[NuPlusInstrFormats.td | NuPlusInstrFormats.td]] and [[NuPlusInstrInfo.td | NuPlusInstrInfo.td]], defining the instructions supported by the nu+ architecture and the patterns LLVM must use to translate the LLVM IR in nu+ asm.
  
 
== C++ classes implementation ==
 
== C++ classes implementation ==

Revision as of 15:45, 4 June 2018

The main task of the backend is to generate nu+ assembly code from the LLVM IR obtained by the Clang frontend. However the LLVM framework provides also base classes that can be used to create an assembler and a 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. There are both tablegen and C++ classes.

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 files

These files describe, through the Tablegen description language, the target architecture like the register file, the instruction set and the calling conventions. The classes defined in the following files are derived from one or more base classes which form an inheritance hierarchy. The list of base classes, including some internal documentation, is provided in the Target.td file or in the other files located in the compiler/include/llvm/Target/ folder.

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.

C++ classes implementation

in MCTargetDesc

in InstPrinter

in Disassembler

in AsmParser