Skip to content

Commit 31fb356

Browse files
committed
[Cpu0] Init Cpu0 backend
* Init Cpu0 backend * Remove LLVMBuild.txt and merge into cmake * Replace WantRoot/WantParent SDNode properties with flags, see: llvm#119599
1 parent c1ea05e commit 31fb356

File tree

23 files changed

+818
-0
lines changed

23 files changed

+818
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,6 @@ pythonenv*
7373
/clang/utils/analyzer/projects/*/RefScanBuildResults
7474
# automodapi puts generated documentation files here.
7575
/lldb/docs/python_api/
76+
77+
# pre-commit hooks
78+
.pre-commit-config.yaml

llvm/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ set(LLVM_ALL_TARGETS
491491
WebAssembly
492492
X86
493493
XCore
494+
Cpu0
494495
)
495496

496497
set(LLVM_ALL_EXPERIMENTAL_TARGETS

llvm/cmake/config-ix.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ elseif (LLVM_NATIVE_ARCH STREQUAL "m68k")
512512
set(LLVM_NATIVE_ARCH M68k)
513513
elseif (LLVM_NATIVE_ARCH MATCHES "loongarch")
514514
set(LLVM_NATIVE_ARCH LoongArch)
515+
elseif (LLVM_NATIVE_ARCH MATCHES "cpu0")
516+
set(LLVM_NATIVE_ARCH Cpu0)
515517
else ()
516518
message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
517519
endif ()

llvm/include/llvm/BinaryFormat/ELF.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ enum {
323323
EM_VE = 251, // NEC SX-Aurora VE
324324
EM_CSKY = 252, // C-SKY 32-bit processor
325325
EM_LOONGARCH = 258, // LoongArch
326+
EM_CPU0 = 999, // Tutorial Backend Cpu0
326327
};
327328

328329
// Object file classes.
@@ -1045,6 +1046,19 @@ enum {
10451046
#include "ELFRelocs/Xtensa.def"
10461047
};
10471048

1049+
// Cpu0 Specific e_flags
1050+
enum : unsigned {
1051+
EF_CPU0_NOREORDER = 0x00000001, // Don't reorder instructions
1052+
EF_CPU0_PIC = 0x00000002, // Position independent code
1053+
EF_CPU0_ARCH_32 = 0x50000000, // CPU032 instruction set per linux not elf.h
1054+
EF_CPU0_ARCH = 0xf0000000, // Mask for applying EF_CPU0_ARCH_ variant
1055+
};
1056+
1057+
// ELF Relocation types for Cpu0
1058+
enum {
1059+
#include "ELFRelocs/Cpu0.def"
1060+
};
1061+
10481062
#undef ELF_RELOC
10491063

10501064
// Section header.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef ELF_RELOC
2+
#error "ELF_RELOC must be defined"
3+
#endif
4+
5+
ELF_RELOC(R_CPU0_NONE, 0)
6+
ELF_RELOC(R_CPU0_32, 2)
7+
ELF_RELOC(R_CPU0_HI16, 5)
8+
ELF_RELOC(R_CPU0_LO16, 6)
9+
ELF_RELOC(R_CPU0_GPREL16, 7)
10+
ELF_RELOC(R_CPU0_LITERAL, 8)
11+
ELF_RELOC(R_CPU0_GOT16, 9)
12+
ELF_RELOC(R_CPU0_PC16, 10)
13+
ELF_RELOC(R_CPU0_CALL16, 11)
14+
ELF_RELOC(R_CPU0_GPREL32, 12)
15+
ELF_RELOC(R_CPU0_PC24, 13)
16+
ELF_RELOC(R_CPU0_GOT_HI16, 22)
17+
ELF_RELOC(R_CPU0_GOT_LO16, 23)
18+
ELF_RELOC(R_CPU0_RELGOT, 36)
19+
ELF_RELOC(R_CPU0_TLS_GD, 42)
20+
ELF_RELOC(R_CPU0_TLS_LDM, 43)
21+
ELF_RELOC(R_CPU0_TLS_DTP_HI16, 44)
22+
ELF_RELOC(R_CPU0_TLS_DTP_LO16, 45)
23+
ELF_RELOC(R_CPU0_TLS_GOTTPREL, 46)
24+
ELF_RELOC(R_CPU0_TLS_TPREL32, 47)
25+
ELF_RELOC(R_CPU0_TLS_TP_HI16, 49)
26+
ELF_RELOC(R_CPU0_TLS_TP_LO16, 50)
27+
ELF_RELOC(R_CPU0_GLOB_DAT, 51)
28+
ELF_RELOC(R_CPU0_JUMP_SLOT, 127)

llvm/include/llvm/Object/ELFObjectFile.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,8 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
13471347
return "elf64-ve";
13481348
case ELF::EM_LOONGARCH:
13491349
return "elf64-loongarch";
1350+
case ELF::EM_CPU0:
1351+
return "elf32-cpu0";
13501352
default:
13511353
return "elf64-unknown";
13521354
}
@@ -1448,6 +1450,14 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
14481450
report_fatal_error("Invalid ELFCLASS!");
14491451
}
14501452

1453+
case ELF::EM_CPU0:
1454+
switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1455+
case ELF::ELFCLASS32:
1456+
return IsLittleEndian ? Triple::cpu0el : Triple::cpu0;
1457+
default:
1458+
report_fatal_error("Invalid ELFCLASS!");
1459+
}
1460+
14511461
case ELF::EM_XTENSA:
14521462
return Triple::xtensa;
14531463

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class Triple {
105105
renderscript32, // 32-bit RenderScript
106106
renderscript64, // 64-bit RenderScript
107107
ve, // NEC SX-Aurora Vector Engine
108+
cpu0, // For Tutorial Backend Cpu0
109+
cpu0el,
108110
LastArchType = ve
109111
};
110112
enum SubArchType {

llvm/lib/Object/ELF.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ StringRef llvm::object::getELFRelocationTypeName(uint32_t Machine,
182182
break;
183183
}
184184
break;
185+
case ELF::EM_CPU0:
186+
switch (Type) {
187+
#include "llvm/BinaryFormat/ELFRelocs/Cpu0.def"
188+
default:
189+
break;
190+
}
191+
break;
185192
default:
186193
break;
187194
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
add_llvm_component_group(Cpu0)
2+
3+
set(LLVM_TARGET_DEFINITIONS Cpu0.td)
4+
5+
# Generate Cpu0GenRegisterInfo.inc and Cpu0GenInstrInfo.inc which included by
6+
# your hand code C++ files.
7+
# Cpu0GenRegisterInfo.inc came from Cpu0RegisterInfo.td, Cpu0GenInstrInfo.inc
8+
# came from Cpu0InstrInfo.td.
9+
tablegen(LLVM Cpu0GenRegisterInfo.inc -gen-register-info)
10+
tablegen(LLVM Cpu0GenInstrInfo.inc -gen-instr-info)
11+
tablegen(LLVM Cpu0GenSubtargetInfo.inc -gen-subtarget)
12+
tablegen(LLVM Cpu0GenMCPseudoLowering.inc -gen-pseudo-lowering)
13+
14+
# Cpu0CommonTableGen must be defined
15+
add_public_tablegen_target(Cpu0CommonTableGen)
16+
17+
# Cpu0CodeGen should match LINK_COMPONENTS in CMakeLists.txt
18+
add_llvm_target(Cpu0CodeGen
19+
Cpu0TargetMachine.cpp
20+
21+
LINK_COMPONENTS
22+
Analysis
23+
AsmPrinter
24+
CodeGen
25+
Core
26+
MC
27+
Cpu0Desc
28+
Cpu0Info
29+
SelectionDAG
30+
Support
31+
Target
32+
GlobalISel
33+
34+
ADD_TO_COMPONENT
35+
Cpu0
36+
)
37+
38+
# Should match with "subdirectories = MCTargetDesc TargetInfo" in LLVMBuild.txt
39+
add_subdirectory(TargetInfo)
40+
add_subdirectory(MCTargetDesc)

llvm/lib/Target/Cpu0/Cpu0.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===-- Cpu0.h - Top-level interface for Cpu0 representation ----*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===
9+
//
10+
// This file contains the entry points for global functions defined in
11+
// the LLVM Cpu0 backend.
12+
//
13+
//===----------------------------------------------------------------------===
14+
#ifndef LLVM_LIB_TARGET_CPU0_CPU0_H
15+
#define LLVM_LIB_TARGET_CPU0_CPU0_H
16+
17+
#include "MCTargetDesc/Cpu0MCTargetDesc.h"
18+
#include "llvm/Target/TargetMachine.h"
19+
20+
namespace llvm {
21+
class Cpu0TargetMachine;
22+
class FunctionPass;
23+
} // namespace llvm
24+
25+
#define ENABLE_GPRESTORE // The $gp register caller saved register enable
26+
27+
#endif

0 commit comments

Comments
 (0)