diff --git a/llvm/CODE_OWNERS.TXT b/llvm/CODE_OWNERS.TXT --- a/llvm/CODE_OWNERS.TXT +++ b/llvm/CODE_OWNERS.TXT @@ -150,6 +150,10 @@ E: me@dylanmckay.io D: AVR Backend +N: Simon Moll +E: simon.moll@emea.nec.com +D: VE Backend + N: Tim Northover E: t.p.northover@gmail.com D: AArch64 backend, misc ARM backend diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -95,7 +95,8 @@ wasm64, // WebAssembly with 64-bit pointers renderscript32, // 32-bit RenderScript renderscript64, // 64-bit RenderScript - LastArchType = renderscript64 + ve, // NEC SX-Aurora Vector Engine + LastArchType = ve }; enum SubArchType { NoSubArch, @@ -730,6 +731,11 @@ return getArch() == Triple::riscv32 || getArch() == Triple::riscv64; } + /// Tests whether the target is VE + bool isVE() const { + return getArch() == Triple::ve; + } + /// Tests whether the target supports comdat bool supportsCOMDAT() const { return !isOSBinFormatMachO(); diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/lib/Support/Triple.cpp @@ -70,6 +70,7 @@ case wasm64: return "wasm64"; case renderscript32: return "renderscript32"; case renderscript64: return "renderscript64"; + case ve: return "ve"; } llvm_unreachable("Invalid ArchType!"); @@ -144,6 +145,8 @@ case riscv32: case riscv64: return "riscv"; + + case ve: return "ve"; } } @@ -315,6 +318,7 @@ .Case("wasm64", wasm64) .Case("renderscript32", renderscript32) .Case("renderscript64", renderscript64) + .Case("ve", ve) .Default(UnknownArch); } @@ -443,6 +447,7 @@ .Case("wasm64", Triple::wasm64) .Case("renderscript32", Triple::renderscript32) .Case("renderscript64", Triple::renderscript64) + .Case("ve", Triple::ve) .Default(Triple::UnknownArch); // Some architectures require special parsing logic just to compute the @@ -701,6 +706,7 @@ case Triple::tcele: case Triple::thumbeb: case Triple::xcore: + case Triple::ve: return Triple::ELF; case Triple::ppc: @@ -1284,6 +1290,7 @@ case llvm::Triple::spir64: case llvm::Triple::wasm64: case llvm::Triple::renderscript64: + case llvm::Triple::ve: return 64; } llvm_unreachable("Invalid architecture value"); @@ -1312,6 +1319,7 @@ case Triple::msp430: case Triple::systemz: case Triple::ppc64le: + case Triple::ve: T.setArch(UnknownArch); break; @@ -1404,6 +1412,7 @@ case Triple::x86_64: case Triple::wasm64: case Triple::renderscript64: + case Triple::ve: // Already 64-bit. break; @@ -1462,6 +1471,7 @@ case Triple::xcore: case Triple::renderscript32: case Triple::renderscript64: + case Triple::ve: // ARM is intentionally unsupported here, changing the architecture would // drop any arch suffixes. @@ -1553,6 +1563,7 @@ case Triple::tcele: case Triple::renderscript32: case Triple::renderscript64: + case Triple::ve: return true; default: return false; diff --git a/llvm/lib/Target/LLVMBuild.txt b/llvm/lib/Target/LLVMBuild.txt --- a/llvm/lib/Target/LLVMBuild.txt +++ b/llvm/lib/Target/LLVMBuild.txt @@ -36,6 +36,7 @@ WebAssembly X86 XCore + VE ; This is a special group whose required libraries are extended (by llvm-build) ; with the best execution engine (the native JIT, if available, or the diff --git a/llvm/lib/Target/VE/CMakeLists.txt b/llvm/lib/Target/VE/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/CMakeLists.txt @@ -0,0 +1,8 @@ +set(LLVM_TARGET_DEFINITIONS VE.td) + +add_llvm_target(VECodeGen + VETargetMachine.cpp + ) + +add_subdirectory(TargetInfo) +add_subdirectory(MCTargetDesc) diff --git a/llvm/lib/Target/VE/LLVMBuild.txt b/llvm/lib/Target/VE/LLVMBuild.txt new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/LLVMBuild.txt @@ -0,0 +1,33 @@ +;===- ./lib/Target/VE/LLVMBuild.txt ----------------------------*- Conf -*--===; +; +; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +; See https://llvm.org/LICENSE.txt for license information. +; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[common] +subdirectories = MCTargetDesc TargetInfo + +[component_0] +type = TargetGroup +name = VE +parent = Target +has_asmparser = 0 +has_asmprinter = 0 + +[component_1] +type = Library +name = VECodeGen +parent = VE +required_libraries = Analysis AsmPrinter CodeGen Core MC SelectionDAG + VEDesc VEInfo Support Target +add_to_library_groups = VE diff --git a/llvm/lib/Target/VE/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/VE/MCTargetDesc/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/MCTargetDesc/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_library(LLVMVEDesc + VEMCTargetDesc.cpp + ) diff --git a/llvm/lib/Target/VE/MCTargetDesc/LLVMBuild.txt b/llvm/lib/Target/VE/MCTargetDesc/LLVMBuild.txt new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/MCTargetDesc/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./lib/Target/VE/MCTargetDesc/LLVMBuild.txt ---------------*- Conf -*--===; +; +; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +; See https://llvm.org/LICENSE.txt for license information. +; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = VEDesc +parent = VE +required_libraries = MC VEInfo Support +add_to_library_groups = VE diff --git a/llvm/lib/Target/VE/MCTargetDesc/VEMCTargetDesc.h b/llvm/lib/Target/VE/MCTargetDesc/VEMCTargetDesc.h new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/MCTargetDesc/VEMCTargetDesc.h @@ -0,0 +1,27 @@ +//===-- VEMCTargetDesc.h - VE Target Descriptions ---------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file provides VE specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_VE_MCTARGETDESC_VEMCTARGETDESC_H +#define LLVM_LIB_TARGET_VE_MCTARGETDESC_VEMCTARGETDESC_H + +#include "llvm/Support/DataTypes.h" + +#include + +namespace llvm { + +class Target; +Target &getTheVETarget(); + +} // end llvm namespace + +#endif diff --git a/llvm/lib/Target/VE/MCTargetDesc/VEMCTargetDesc.cpp b/llvm/lib/Target/VE/MCTargetDesc/VEMCTargetDesc.cpp new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/MCTargetDesc/VEMCTargetDesc.cpp @@ -0,0 +1,19 @@ +//===-- VEMCTargetDesc.cpp - VE Target Descriptions -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file provides VE specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#include "VEMCTargetDesc.h" + +using namespace llvm; + +extern "C" void LLVMInitializeVETargetMC() { + // TODO +} diff --git a/llvm/lib/Target/VE/TargetInfo/CMakeLists.txt b/llvm/lib/Target/VE/TargetInfo/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/TargetInfo/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_component_library(LLVMVEInfo + VETargetInfo.cpp + ) diff --git a/llvm/lib/Target/VE/TargetInfo/LLVMBuild.txt b/llvm/lib/Target/VE/TargetInfo/LLVMBuild.txt new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/TargetInfo/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./lib/Target/VE/TargetInfo/LLVMBuild.txt -----------------*- Conf -*--===; +; +; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +; See https://llvm.org/LICENSE.txt for license information. +; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = VEInfo +parent = VE +required_libraries = Support +add_to_library_groups = VE diff --git a/llvm/lib/Target/VE/TargetInfo/VETargetInfo.cpp b/llvm/lib/Target/VE/TargetInfo/VETargetInfo.cpp new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/TargetInfo/VETargetInfo.cpp @@ -0,0 +1,23 @@ +//===-- VETargetInfo.cpp - VE Target Implementation -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "VE.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/TargetRegistry.h" + +using namespace llvm; + +Target &llvm::getTheVETarget() { + static Target TheVETarget; + return TheVETarget; +} + +extern "C" void LLVMInitializeVETargetInfo() { + RegisterTarget X(getTheVETarget(), "ve", + "VE", "VE"); +} diff --git a/llvm/lib/Target/VE/VE.h b/llvm/lib/Target/VE/VE.h new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/VE.h @@ -0,0 +1,19 @@ +//===-- VE.h - Top-level interface for VE representation --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file contains the entry points for global functions defined in the LLVM +// VE back-end. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_VE_VE_H +#define LLVM_LIB_TARGET_VE_VE_H + +#include "MCTargetDesc/VEMCTargetDesc.h" + +#endif diff --git a/llvm/lib/Target/VE/VETargetMachine.h b/llvm/lib/Target/VE/VETargetMachine.h new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/VETargetMachine.h @@ -0,0 +1,31 @@ +//===-- VETargetMachine.h - Define TargetMachine for VE ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file declares the VE specific subclass of TargetMachine. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_VE_VETARGETMACHINE_H +#define LLVM_LIB_TARGET_VE_VETARGETMACHINE_H + +#include "llvm/Target/TargetMachine.h" + +namespace llvm { + +class VETargetMachine : public LLVMTargetMachine { +public: + VETargetMachine(const Target &T, const Triple &TT, StringRef CPU, + StringRef FS, const TargetOptions &Options, + Optional RM, Optional CM, + CodeGenOpt::Level OL, bool JIT); + ~VETargetMachine() override; +}; + +} // namespace llvm + +#endif diff --git a/llvm/lib/Target/VE/VETargetMachine.cpp b/llvm/lib/Target/VE/VETargetMachine.cpp new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/VE/VETargetMachine.cpp @@ -0,0 +1,62 @@ +//===-- VETargetMachine.cpp - Define TargetMachine for VE -----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// +//===----------------------------------------------------------------------===// + +#include "VETargetMachine.h" +#include "VE.h" +#include "llvm/Support/TargetRegistry.h" + +using namespace llvm; + +#define DEBUG_TYPE "ve" + +extern "C" void LLVMInitializeVETarget() { + // Register the target. + RegisterTargetMachine X(getTheVETarget()); +} + +static std::string computeDataLayout(const Triple &T) { + // Aurora VE is little endian + std::string Ret = "e"; + + // Use ELF mangling + Ret += "-m:e"; + + // Alignments for 64 bit integers. + Ret += "-i64:64"; + + // VE supports 32 bit and 64 bits integer on registers + Ret += "-n32:64"; + + // Stack alignment is 64 bits + Ret += "-S64"; + + return Ret; +} + +static Reloc::Model getEffectiveRelocModel(Optional RM) { + if (!RM.hasValue()) + return Reloc::Static; + return *RM; +} + +/// Create an Aurora VE architecture model +VETargetMachine::VETargetMachine( + const Target &T, const Triple &TT, StringRef CPU, StringRef FS, + const TargetOptions &Options, Optional RM, + Optional CM, CodeGenOpt::Level OL, bool JIT) + : LLVMTargetMachine( + T, computeDataLayout(TT), TT, CPU, FS, Options, + getEffectiveRelocModel(RM), + getEffectiveCodeModel(CM, CodeModel::Small), + OL) +{} + +VETargetMachine::~VETargetMachine() {} diff --git a/llvm/test/CodeGen/VE/lit.local.cfg b/llvm/test/CodeGen/VE/lit.local.cfg new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/VE/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'VE' in config.root.targets: + config.unsupported = True diff --git a/llvm/test/CodeGen/VE/target_support.ll b/llvm/test/CodeGen/VE/target_support.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/VE/target_support.ll @@ -0,0 +1,2 @@ +; RUN: llc --version | FileCheck %s +; CHECK: ve - VE diff --git a/llvm/unittests/ADT/TripleTest.cpp b/llvm/unittests/ADT/TripleTest.cpp --- a/llvm/unittests/ADT/TripleTest.cpp +++ b/llvm/unittests/ADT/TripleTest.cpp @@ -312,6 +312,12 @@ EXPECT_EQ(Triple::AMDPAL, T.getOS()); EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("ve-unknown-linux"); + EXPECT_EQ(Triple::ve, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::Linux, T.getOS()); + EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("riscv32-unknown-unknown"); EXPECT_EQ(Triple::riscv32, T.getArch()); EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); @@ -715,6 +721,8 @@ Triple::normalize("i686-linux")); // i686-pc-linux-gnu EXPECT_EQ("arm-none-unknown-eabi", Triple::normalize("arm-none-eabi")); // arm-none-eabi + EXPECT_EQ("ve-unknown-linux", + Triple::normalize("ve-linux")); // ve-linux EXPECT_EQ("wasm32-unknown-wasi", Triple::normalize("wasm32-wasi")); // wasm32-unknown-wasi EXPECT_EQ("wasm64-unknown-wasi",