diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 9bbcba069c1d8..10e30858b0983 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -299,6 +299,7 @@ set(LLVM_ALL_TARGETS RISCV Sparc SystemZ + Toy WebAssembly X86 XCore diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h index 76a754d671fb6..cb308e2a666c2 100644 --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -91,6 +91,7 @@ class Triple { kalimba, // Kalimba: generic kalimba shave, // SHAVE: Movidius vector VLIW processors lanai, // Lanai: Lanai 32-bit + toy, // TOY: Experiment with LLVM backend architecture wasm32, // WebAssembly with 32-bit pointers wasm64, // WebAssembly with 64-bit pointers renderscript32, // 32-bit RenderScript diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h index caab91da9c839..1248d7e4edc36 100644 --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -311,6 +311,8 @@ enum { EM_RISCV = 243, // RISC-V EM_LANAI = 244, // Lanai 32-bit processor EM_BPF = 247, // Linux kernel bpf virtual machine + + EM_TOY = 347, // Experiment with LLVM backend architecture }; // Object file classes. diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp index 2c480c1094a5c..bdde15ebc03c9 100644 --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/lib/Support/Triple.cpp @@ -65,6 +65,7 @@ StringRef Triple::getArchTypeName(ArchType Kind) { case tcele: return "tcele"; case thumb: return "thumb"; case thumbeb: return "thumbeb"; + case toy: return "toy"; case ve: return "ve"; case wasm32: return "wasm32"; case wasm64: return "wasm64"; @@ -135,6 +136,8 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) { case hsail: case hsail64: return "hsail"; + case toy: return "toy"; + case spir: case spir64: return "spir"; case kalimba: return "kalimba"; @@ -307,6 +310,7 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) { .Case("amdil64", amdil64) .Case("hsail", hsail) .Case("hsail64", hsail64) + .Case("toy", toy) .Case("spir", spir) .Case("spir64", spir64) .Case("kalimba", kalimba) @@ -436,6 +440,7 @@ static Triple::ArchType parseArch(StringRef ArchName) { .Case("amdil64", Triple::amdil64) .Case("hsail", Triple::hsail) .Case("hsail64", Triple::hsail64) + .Case("toy", Triple::toy) .Case("spir", Triple::spir) .Case("spir64", Triple::spir64) .StartsWith("kalimba", Triple::kalimba) @@ -704,6 +709,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { case Triple::tce: case Triple::tcele: case Triple::thumbeb: + case Triple::toy: case Triple::ve: case Triple::xcore: return Triple::ELF; @@ -1264,6 +1270,7 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) { case llvm::Triple::tcele: case llvm::Triple::thumb: case llvm::Triple::thumbeb: + case llvm::Triple::toy: case llvm::Triple::wasm32: case llvm::Triple::x86: case llvm::Triple::xcore: @@ -1347,6 +1354,7 @@ Triple Triple::get32BitArchVariant() const { case Triple::tcele: case Triple::thumb: case Triple::thumbeb: + case Triple::toy: case Triple::wasm32: case Triple::x86: case Triple::xcore: @@ -1387,6 +1395,7 @@ Triple Triple::get64BitArchVariant() const { case Triple::sparcel: case Triple::tce: case Triple::tcele: + case Triple::toy: case Triple::xcore: T.setArch(UnknownArch); break; @@ -1465,6 +1474,7 @@ Triple Triple::getBigEndianArchVariant() const { case Triple::shave: case Triple::spir64: case Triple::spir: + case Triple::toy: case Triple::wasm32: case Triple::wasm64: case Triple::x86: @@ -1557,6 +1567,7 @@ bool Triple::isLittleEndian() const { case Triple::spir: case Triple::tcele: case Triple::thumb: + case Triple::toy: case Triple::ve: case Triple::wasm32: case Triple::wasm64: diff --git a/llvm/lib/Target/LLVMBuild.txt b/llvm/lib/Target/LLVMBuild.txt index 7403f7713a9f6..be717006bfab8 100644 --- a/llvm/lib/Target/LLVMBuild.txt +++ b/llvm/lib/Target/LLVMBuild.txt @@ -33,6 +33,7 @@ subdirectories = RISCV Sparc SystemZ + Toy WebAssembly X86 XCore diff --git a/llvm/lib/Target/Toy/CMakeLists.txt b/llvm/lib/Target/Toy/CMakeLists.txt new file mode 100644 index 0000000000000..fd91a097b4552 --- /dev/null +++ b/llvm/lib/Target/Toy/CMakeLists.txt @@ -0,0 +1,6 @@ +add_llvm_target(ToyCodeGen + ToyTargetMachine.cpp + ) + +add_subdirectory(MCTargetDesc) +add_subdirectory(TargetInfo) diff --git a/llvm/lib/Target/Toy/LLVMBuild.txt b/llvm/lib/Target/Toy/LLVMBuild.txt new file mode 100644 index 0000000000000..5acebbb5bab62 --- /dev/null +++ b/llvm/lib/Target/Toy/LLVMBuild.txt @@ -0,0 +1,31 @@ +;===- ./lib/Target/Toy/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 = Toy +parent = Target + +[component_1] +type = Library +name = ToyCodeGen +parent = Toy +required_libraries = AsmPrinter CodeGen Core MC SelectionDAG + ToyDesc ToyInfo Support Target +add_to_library_groups = Toy diff --git a/llvm/lib/Target/Toy/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/Toy/MCTargetDesc/CMakeLists.txt new file mode 100644 index 0000000000000..c91319c5d99e8 --- /dev/null +++ b/llvm/lib/Target/Toy/MCTargetDesc/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_component_library(LLVMToyDesc + ToyMCTargetDesc.cpp + ) diff --git a/llvm/lib/Target/Toy/MCTargetDesc/LLVMBuild.txt b/llvm/lib/Target/Toy/MCTargetDesc/LLVMBuild.txt new file mode 100644 index 0000000000000..526c60c8bdb93 --- /dev/null +++ b/llvm/lib/Target/Toy/MCTargetDesc/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./lib/Target/Toy/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 = ToyDesc +parent = Toy +required_libraries = MC ToyInfo Support +add_to_library_groups = Toy diff --git a/llvm/lib/Target/Toy/MCTargetDesc/ToyMCTargetDesc.cpp b/llvm/lib/Target/Toy/MCTargetDesc/ToyMCTargetDesc.cpp new file mode 100644 index 0000000000000..4b6428425c39d --- /dev/null +++ b/llvm/lib/Target/Toy/MCTargetDesc/ToyMCTargetDesc.cpp @@ -0,0 +1,20 @@ +//===-- ToyMCTargetDesc.cpp - Toy 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 Toy specific target descriptions. +// +//===----------------------------------------------------------------------===// + +#include "TargetInfo/ToyTargetInfo.h" +using namespace llvm; + +extern "C" void LLVMInitializeToyTargetMC() { + // TODO: We need this stub function definition during target registration, + // otherwise we get an undefined symbol error. Appropriately fill-up this stub + // function later. +} diff --git a/llvm/lib/Target/Toy/TargetInfo/CMakeLists.txt b/llvm/lib/Target/Toy/TargetInfo/CMakeLists.txt new file mode 100644 index 0000000000000..2699ee8e1e12f --- /dev/null +++ b/llvm/lib/Target/Toy/TargetInfo/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_component_library(LLVMToyInfo + ToyTargetInfo.cpp + ) diff --git a/llvm/lib/Target/Toy/TargetInfo/LLVMBuild.txt b/llvm/lib/Target/Toy/TargetInfo/LLVMBuild.txt new file mode 100644 index 0000000000000..9f247df10076c --- /dev/null +++ b/llvm/lib/Target/Toy/TargetInfo/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./lib/Target/Toy/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 = ToyInfo +parent = Toy +required_libraries = Support +add_to_library_groups = Toy diff --git a/llvm/lib/Target/Toy/TargetInfo/ToyTargetInfo.cpp b/llvm/lib/Target/Toy/TargetInfo/ToyTargetInfo.cpp new file mode 100644 index 0000000000000..d07e21c659ab2 --- /dev/null +++ b/llvm/lib/Target/Toy/TargetInfo/ToyTargetInfo.cpp @@ -0,0 +1,21 @@ +//===-- ToyTargetInfo.cpp - Toy 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 "TargetInfo/ToyTargetInfo.h" +#include "llvm/Support/TargetRegistry.h" +using namespace llvm; + +Target &llvm::getTheToyTarget() { + static Target TheToyTarget; + return TheToyTarget; +} + +extern "C" void LLVMInitializeToyTargetInfo() { + RegisterTarget X(getTheToyTarget(), "toy", + "Toy", "Toy"); +} diff --git a/llvm/lib/Target/Toy/TargetInfo/ToyTargetInfo.h b/llvm/lib/Target/Toy/TargetInfo/ToyTargetInfo.h new file mode 100644 index 0000000000000..9fbf6ef05ac33 --- /dev/null +++ b/llvm/lib/Target/Toy/TargetInfo/ToyTargetInfo.h @@ -0,0 +1,20 @@ +//===-- ToyTargetInfo.h - Toy Target Implementation -------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_TOY_TARGETINFO_TOYTARGETINFO_H +#define LLVM_LIB_TARGET_TOY_TARGETINFO_TOYTARGETINFO_H + +namespace llvm { + +class Target; + +Target &getTheToyTarget(); + +} // namespace llvm + +#endif // LLVM_LIB_TARGET_TOY_TARGETINFO_TOYTARGETINFO_H diff --git a/llvm/lib/Target/Toy/ToyTargetMachine.cpp b/llvm/lib/Target/Toy/ToyTargetMachine.cpp new file mode 100644 index 0000000000000..670f62cfb4c85 --- /dev/null +++ b/llvm/lib/Target/Toy/ToyTargetMachine.cpp @@ -0,0 +1,47 @@ +//===-- ToyTargetMachine.cpp - Define TargetMachine for Toy ---------------===// +// +// 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 "ToyTargetMachine.h" +#include "TargetInfo/ToyTargetInfo.h" +#include "llvm/Support/TargetRegistry.h" +using namespace llvm; + +extern "C" void LLVMInitializeToyTarget() { + // Register the target. + RegisterTargetMachine X(getTheToyTarget()); +} + +static std::string computeDataLayout() { + // TODO: Appropriately fill-up this stub function later + return ""; +} + +static Reloc::Model getEffectiveRelocModel(Optional RM) { + // TODO: Appropriately fill-up this stub function later + return *RM; +} + +static CodeModel::Model getEffectiveToyCodeModel() { + // TODO: Appropriately fill-up this stub function later + return CodeModel::Small; +} + +ToyTargetMachine::ToyTargetMachine( + // TODO: Appropriately fill-up this stub constructor later + 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, CPU, FS, Options, + getEffectiveRelocModel(RM), + getEffectiveToyCodeModel(), OL) { +} + +ToyTargetMachine::~ToyTargetMachine() {} diff --git a/llvm/lib/Target/Toy/ToyTargetMachine.h b/llvm/lib/Target/Toy/ToyTargetMachine.h new file mode 100644 index 0000000000000..6e3224d1f90ab --- /dev/null +++ b/llvm/lib/Target/Toy/ToyTargetMachine.h @@ -0,0 +1,34 @@ +//===-- ToyTargetMachine.h - Define TargetMachine for Toy -------*- 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 Toy specific subclass of TargetMachine. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_TOY_TOYTARGETMACHINE_H +#define LLVM_LIB_TARGET_TOY_TOYTARGETMACHINE_H + +#include "llvm/Target/TargetMachine.h" + +namespace llvm { + +// TODO: Appropriately define this stub class later +class ToyTargetMachine : public LLVMTargetMachine { + +public: + ToyTargetMachine(const Target &T, const Triple &TT, StringRef &CPU, + StringRef &FS, const TargetOptions &Options, + Optional &RM, Optional &CM, + CodeGenOpt::Level &OL, bool &JIT); + + ~ToyTargetMachine() override; +}; + +} // end namespace llvm + +#endif