NaplesPU Tools

From NaplesPU Documentation
Revision as of 16:17, 12 September 2017 by Edo (talk | contribs)
Jump to: navigation, search

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.