Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register a toy back-end #94

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ set(LLVM_ALL_TARGETS
RISCV
Sparc
SystemZ
Toy
WebAssembly
X86
XCore
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/ADT/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/BinaryFormat/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Support/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ subdirectories =
RISCV
Sparc
SystemZ
Toy
WebAssembly
X86
XCore
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/Toy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_llvm_target(ToyCodeGen
ToyTargetMachine.cpp
)

add_subdirectory(MCTargetDesc)
add_subdirectory(TargetInfo)
31 changes: 31 additions & 0 deletions llvm/lib/Target/Toy/LLVMBuild.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions llvm/lib/Target/Toy/MCTargetDesc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_llvm_component_library(LLVMToyDesc
ToyMCTargetDesc.cpp
)
22 changes: 22 additions & 0 deletions llvm/lib/Target/Toy/MCTargetDesc/LLVMBuild.txt
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions llvm/lib/Target/Toy/MCTargetDesc/ToyMCTargetDesc.cpp
Original file line number Diff line number Diff line change
@@ -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.
}
3 changes: 3 additions & 0 deletions llvm/lib/Target/Toy/TargetInfo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_llvm_component_library(LLVMToyInfo
ToyTargetInfo.cpp
)
22 changes: 22 additions & 0 deletions llvm/lib/Target/Toy/TargetInfo/LLVMBuild.txt
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions llvm/lib/Target/Toy/TargetInfo/ToyTargetInfo.cpp
Original file line number Diff line number Diff line change
@@ -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<Triple::toy, /*HasJIT=*/false> X(getTheToyTarget(), "toy",
"Toy", "Toy");
}
20 changes: 20 additions & 0 deletions llvm/lib/Target/Toy/TargetInfo/ToyTargetInfo.h
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions llvm/lib/Target/Toy/ToyTargetMachine.cpp
Original file line number Diff line number Diff line change
@@ -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<ToyTargetMachine> X(getTheToyTarget());
}

static std::string computeDataLayout() {
// TODO: Appropriately fill-up this stub function later
return "";
}

static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> 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<Reloc::Model> &RM,
Optional<CodeModel::Model> &CM, CodeGenOpt::Level &OL, bool &JIT)
: LLVMTargetMachine(T, computeDataLayout(), TT, CPU, FS, Options,
getEffectiveRelocModel(RM),
getEffectiveToyCodeModel(), OL) {
}

ToyTargetMachine::~ToyTargetMachine() {}
34 changes: 34 additions & 0 deletions llvm/lib/Target/Toy/ToyTargetMachine.h
Original file line number Diff line number Diff line change
@@ -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<Reloc::Model> &RM, Optional<CodeModel::Model> &CM,
CodeGenOpt::Level &OL, bool &JIT);

~ToyTargetMachine() override;
};

} // end namespace llvm

#endif