Difference between revisions of "NaplesPU Tools"

From NaplesPU Documentation
Jump to: navigation, search
Line 3: Line 3:
  
 
==== CMakeLists.txt ====
 
==== CMakeLists.txt ====
<syntaxhighlight lang="java" line='line'>
+
<syntaxhighlight lang="cpp" line='line'>
 
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
 
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
 
set(CMAKE_INSTALL_PREFIX "/usr/local/llvm-nuplus/" CACHE PATH "NuPlusLLVM install prefix" FORCE)
 
set(CMAKE_INSTALL_PREFIX "/usr/local/llvm-nuplus/" CACHE PATH "NuPlusLLVM install prefix" FORCE)
Line 10: Line 10:
 
This specifies the installation path that, in our case, is: "/usr/local/llvm-nuplus/".
 
This specifies the installation path that, in our case, is: "/usr/local/llvm-nuplus/".
  
<syntaxhighlight lang="java" line='line'>
+
<syntaxhighlight lang="cpp" line='line'>
 
set(LLVM_ALL_TARGETS
 
set(LLVM_ALL_TARGETS
 
   AArch64
 
   AArch64
Line 30: Line 30:
 
The target name should be added to the LLVM_ALL_TARGETS list.
 
The target name should be added to the LLVM_ALL_TARGETS list.
  
<syntaxhighlight lang="java" line='line'>
+
<syntaxhighlight lang="cpp" line='line'>
 
set(LLVM_TARGETS_TO_BUILD "NuPlus" CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
 
set(LLVM_TARGETS_TO_BUILD "NuPlus" CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
 
</syntaxhighlight>
 
</syntaxhighlight>
 
In a standard version of llvm, the LLVM_TARGETS_TO_BUILD variable is set to "all" in order to compile llvm with all the provided target backends. In out custom compiler, we set this variable to "NuPlus". In this way the compiler is built just targeting the NuPlus architecture.
 
In a standard version of llvm, the LLVM_TARGETS_TO_BUILD variable is set to "all" in order to compile llvm with all the provided target backends. In out custom compiler, we set this variable to "NuPlus". In this way the compiler is built just targeting the NuPlus architecture.
  
<syntaxhighlight lang="java" line='line'>
+
<syntaxhighlight lang="cpp" line='line'>
 
set(LLVM_DEFAULT_TARGET_TRIPLE "nuplus-none-none" CACHE STRING "Default target for which LLVM will generate code." )
 
set(LLVM_DEFAULT_TARGET_TRIPLE "nuplus-none-none" CACHE STRING "Default target for which LLVM will generate code." )
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 41: Line 41:
  
 
==== cmake/config-ix.cmake ====
 
==== cmake/config-ix.cmake ====
<syntaxhighlight lang="java" line='line'>
+
<syntaxhighlight lang="cpp" line='line'>
 
if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
 
if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
 
   set(LLVM_NATIVE_ARCH X86)
 
   set(LLVM_NATIVE_ARCH X86)
Line 50: Line 50:
  
 
==== include/llvm/ADT/Triple.h ====
 
==== include/llvm/ADT/Triple.h ====
<syntaxhighlight lang="java" line='line'>
+
<syntaxhighlight lang="cpp" line='line'>
 
enum ArchType {
 
enum ArchType {
 
     UnknownArch,
 
     UnknownArch,
Line 59: Line 59:
 
We add NuPlus to the ArchType list.
 
We add NuPlus to the ArchType list.
  
==== include/llvm/ADT/Triple.h ====
+
==== include/llvm/IR/Intrinsics.td ====
<syntaxhighlight lang="java" line='line'>
+
<syntaxhighlight lang="cpp" line='line'>
enum ArchType {
+
include "llvm/IR/IntrinsicsNuPlus.td"
    UnknownArch,
 
    arm,            // ARM (little endian): arm, armv.*, xscale
 
    ...
 
    nuplus,        // NuPlus
 
 
</syntaxhighlight>
 
</syntaxhighlight>
We add NuPlus to the ArchType list.
+
In order to use target-specific intrinsics, we include the path to IntrinsicsNuPlus.td, i.e. the file containing the NuPlus intrinsics.

Revision as of 17:17, 12 September 2017

A new backend for llvm needs to be added and registered. After registration, llvm tools are able to lookup and use the new target at runtime. In the following, we will show which files are involved in the registration phase and which changes are required.

CMakeLists.txt

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
	set(CMAKE_INSTALL_PREFIX "/usr/local/llvm-nuplus/" CACHE PATH "NuPlusLLVM install prefix" FORCE)
endif()

This specifies the installation path that, in our case, is: "/usr/local/llvm-nuplus/".

set(LLVM_ALL_TARGETS
  AArch64
  AMDGPU
  ARM
  BPF
  Hexagon
  Mips
  MSP430
  NVPTX
  PowerPC
  Sparc
  SystemZ
  X86
  XCore
  NuPlus
  )

The target name should be added to the LLVM_ALL_TARGETS list.

set(LLVM_TARGETS_TO_BUILD "NuPlus" CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")

In a standard version of llvm, the LLVM_TARGETS_TO_BUILD variable is set to "all" in order to compile llvm with all the provided target backends. In out custom compiler, we set this variable to "NuPlus". In this way the compiler is built just targeting the NuPlus architecture.

set(LLVM_DEFAULT_TARGET_TRIPLE "nuplus-none-none" CACHE STRING "Default target for which LLVM will generate code." )

Finally, we remove the possibility of targeting a different architecture then NuPlus.

cmake/config-ix.cmake

if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
  set(LLVM_NATIVE_ARCH X86)
...
elseif (LLVM_NATIVE_ARCH MATCHES "nuplus")
  set(LLVM_NATIVE_ARCH NuPlus)

include/llvm/ADT/Triple.h

enum ArchType {
    UnknownArch,
    arm,            // ARM (little endian): arm, armv.*, xscale
    ...
    nuplus,         // NuPlus

We add NuPlus to the ArchType list.

include/llvm/IR/Intrinsics.td

include "llvm/IR/IntrinsicsNuPlus.td"

In order to use target-specific intrinsics, we include the path to IntrinsicsNuPlus.td, i.e. the file containing the NuPlus intrinsics.