Skip to content

Commit bec7b16

Browse files
committed
[M68k](3/8) Skeleton and target description files
- Infrastructure for the target (i.e. build files, target triple etc.) - All of the target description TableGen file Authors: myhsu, m4yers, glaubitz Differential Revision: https://reviews.llvm.org/D88389
1 parent 6dcc325 commit bec7b16

21 files changed

+3756
-0
lines changed

llvm/cmake/config-ix.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ elseif (LLVM_NATIVE_ARCH MATCHES "riscv32")
452452
set(LLVM_NATIVE_ARCH RISCV)
453453
elseif (LLVM_NATIVE_ARCH MATCHES "riscv64")
454454
set(LLVM_NATIVE_ARCH RISCV)
455+
elseif (LLVM_NATIVE_ARCH STREQUAL "m68k")
456+
set(LLVM_NATIVE_ARCH M68k)
455457
else ()
456458
message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
457459
endif ()

llvm/include/llvm/ADT/Triple.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Triple {
5858
bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian)
5959
csky, // CSKY: csky
6060
hexagon, // Hexagon: hexagon
61+
m68k, // M68k: Motorola 680x0 family
6162
mips, // MIPS: mips, mipsallegrex, mipsr6
6263
mipsel, // MIPSEL: mipsel, mipsallegrexe, mipsr6el
6364
mips64, // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6

llvm/lib/Support/Triple.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ StringRef Triple::getArchTypeName(ArchType Kind) {
4444
case lanai: return "lanai";
4545
case le32: return "le32";
4646
case le64: return "le64";
47+
case m68k: return "m68k";
4748
case mips64: return "mips64";
4849
case mips64el: return "mips64el";
4950
case mips: return "mips";
@@ -105,6 +106,8 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) {
105106
case ppc:
106107
case ppcle: return "ppc";
107108

109+
case m68k: return "m68k";
110+
108111
case mips:
109112
case mipsel:
110113
case mips64:
@@ -281,6 +284,7 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
281284
.Case("armeb", armeb)
282285
.Case("avr", avr)
283286
.StartsWith("bpf", BPFArch)
287+
.Case("m68k", m68k)
284288
.Case("mips", mips)
285289
.Case("mipsel", mipsel)
286290
.Case("mips64", mips64)
@@ -419,6 +423,7 @@ static Triple::ArchType parseArch(StringRef ArchName) {
419423
.Case("thumb", Triple::thumb)
420424
.Case("thumbeb", Triple::thumbeb)
421425
.Case("avr", Triple::avr)
426+
.Case("m68k", Triple::m68k)
422427
.Case("msp430", Triple::msp430)
423428
.Cases("mips", "mipseb", "mipsallegrex", "mipsisa32r6",
424429
"mipsr6", Triple::mips)
@@ -704,6 +709,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
704709
case Triple::lanai:
705710
case Triple::le32:
706711
case Triple::le64:
712+
case Triple::m68k:
707713
case Triple::mips64:
708714
case Triple::mips64el:
709715
case Triple::mips:
@@ -1277,6 +1283,7 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
12771283
case llvm::Triple::kalimba:
12781284
case llvm::Triple::lanai:
12791285
case llvm::Triple::le32:
1286+
case llvm::Triple::m68k:
12801287
case llvm::Triple::mips:
12811288
case llvm::Triple::mipsel:
12821289
case llvm::Triple::nvptx:
@@ -1361,6 +1368,7 @@ Triple Triple::get32BitArchVariant() const {
13611368
case Triple::kalimba:
13621369
case Triple::lanai:
13631370
case Triple::le32:
1371+
case Triple::m68k:
13641372
case Triple::mips:
13651373
case Triple::mipsel:
13661374
case Triple::nvptx:
@@ -1413,6 +1421,7 @@ Triple Triple::get64BitArchVariant() const {
14131421
case Triple::hexagon:
14141422
case Triple::kalimba:
14151423
case Triple::lanai:
1424+
case Triple::m68k:
14161425
case Triple::msp430:
14171426
case Triple::r600:
14181427
case Triple::shave:
@@ -1537,6 +1546,7 @@ Triple Triple::getLittleEndianArchVariant() const {
15371546
case Triple::lanai:
15381547
case Triple::sparcv9:
15391548
case Triple::systemz:
1549+
case Triple::m68k:
15401550

15411551
// ARM is intentionally unsupported here, changing the architecture would
15421552
// drop any arch suffixes.

llvm/lib/Target/M68k/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
add_llvm_component_group(M68k)
2+
3+
set(LLVM_TARGET_DEFINITIONS M68k.td)
4+
5+
tablegen(LLVM M68kGenRegisterInfo.inc -gen-register-info)
6+
tablegen(LLVM M68kGenInstrInfo.inc -gen-instr-info)
7+
tablegen(LLVM M68kGenSubtargetInfo.inc -gen-subtarget)
8+
tablegen(LLVM M68kGenMCCodeBeads.inc -gen-code-beads)
9+
tablegen(LLVM M68kGenMCPseudoLowering.inc -gen-pseudo-lowering)
10+
tablegen(LLVM M68kGenDAGISel.inc -gen-dag-isel)
11+
tablegen(LLVM M68kGenCallingConv.inc -gen-callingconv)
12+
tablegen(LLVM M68kGenAsmWriter.inc -gen-asm-writer)
13+
14+
add_public_tablegen_target(M68kCommonTableGen)
15+
16+
add_llvm_target(M68kCodeGen
17+
M68kTargetMachine.cpp
18+
19+
LINK_COMPONENTS
20+
Analysis
21+
AsmPrinter
22+
CodeGen
23+
Core
24+
MC
25+
SelectionDAG
26+
Support
27+
Target
28+
M68kDesc
29+
M68kInfo
30+
31+
ADD_TO_COMPONENT
32+
M68k
33+
)
34+
35+
add_subdirectory(TargetInfo)
36+
add_subdirectory(MCTargetDesc)

llvm/lib/Target/M68k/M68k.td

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//===-- M68k.td - Motorola 680x0 target definitions ------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// This is a target description file for the Motorola 680x0 family, referred
11+
/// to here as the "M68k" architecture.
12+
///
13+
//===----------------------------------------------------------------------===//
14+
15+
include "llvm/Target/Target.td"
16+
17+
//===----------------------------------------------------------------------===//
18+
// M68k Subtarget features
19+
//===----------------------------------------------------------------------===//
20+
21+
def FeatureISA00
22+
: SubtargetFeature<"isa-68000", "SubtargetKind", "M00",
23+
"Is M68000 ISA supported">;
24+
25+
def FeatureISA10
26+
: SubtargetFeature<"isa-68010", "SubtargetKind", "M10",
27+
"Is M68010 ISA supported",
28+
[ FeatureISA00 ]>;
29+
30+
def FeatureISA20
31+
: SubtargetFeature<"isa-68020", "SubtargetKind", "M20",
32+
"Is M68020 ISA supported",
33+
[ FeatureISA10 ]>;
34+
35+
def FeatureISA30
36+
: SubtargetFeature<"isa-68030", "SubtargetKind", "M30",
37+
"Is M68030 ISA supported",
38+
[ FeatureISA20 ]>;
39+
40+
def FeatureISA40
41+
: SubtargetFeature<"isa-68040", "SubtargetKind", "M40",
42+
"Is M68040 ISA supported",
43+
[ FeatureISA30 ]>;
44+
45+
def FeatureISA60
46+
: SubtargetFeature<"isa-68060", "SubtargetKind", "M60",
47+
"Is M68060 ISA supported",
48+
[ FeatureISA40 ]>;
49+
50+
//===----------------------------------------------------------------------===//
51+
// M68k processors supported.
52+
//===----------------------------------------------------------------------===//
53+
54+
include "M68kSchedule.td"
55+
56+
class Proc<string Name, list<SubtargetFeature> Features>
57+
: ProcessorModel<Name, GenericM68kModel, Features>;
58+
59+
def : Proc<"generic", [ FeatureISA00 ]>;
60+
def : Proc<"M68000", [ FeatureISA00 ]>;
61+
def : Proc<"M68010", [ FeatureISA10 ]>;
62+
def : Proc<"M68020", [ FeatureISA20 ]>;
63+
def : Proc<"M68030", [ FeatureISA30 ]>;
64+
def : Proc<"M68040", [ FeatureISA40 ]>;
65+
def : Proc<"M68060", [ FeatureISA60 ]>;
66+
67+
//===----------------------------------------------------------------------===//
68+
// Register File Description
69+
//===----------------------------------------------------------------------===//
70+
71+
include "M68kRegisterInfo.td"
72+
73+
//===----------------------------------------------------------------------===//
74+
// Instruction Descriptions
75+
//===----------------------------------------------------------------------===//
76+
77+
include "M68kInstrInfo.td"
78+
79+
def M68kInstrInfo : InstrInfo;
80+
81+
//===----------------------------------------------------------------------===//
82+
// Calling Conventions
83+
//===----------------------------------------------------------------------===//
84+
85+
include "M68kCallingConv.td"
86+
87+
//===----------------------------------------------------------------------===//
88+
// Target
89+
//===----------------------------------------------------------------------===//
90+
91+
def M68k : Target {
92+
let InstructionSet = M68kInstrInfo;
93+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//===-- M68kCallingConv.td - Calling Conventions for M68k --*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// This describes the calling conventions for the M68k architectures. These
11+
/// conventions assume Int to be 4 bytes and 4 byte aligned.
12+
///
13+
//===----------------------------------------------------------------------===//
14+
15+
// TODO Verify C convention follows SysV M68K ABI
16+
17+
class CCIfSubtarget<string F, CCAction A>
18+
: CCIf<!strconcat("static_cast<const M68kSubtarget &>"
19+
"(State.getMachineFunction().getSubtarget()).", F), A>;
20+
21+
//===----------------------------------------------------------------------===//
22+
// Return Value Calling Conventions
23+
//===----------------------------------------------------------------------===//
24+
25+
/// Return-value conventions common to all M68k CC's.
26+
def RetCC_M68kCommon : CallingConv<[
27+
]>;
28+
29+
/// M68k C return convention.
30+
/// TODO: Return via address register
31+
def RetCC_M68k_C : CallingConv<[
32+
CCIfType<[i1], CCPromoteToType<i8>>,
33+
CCIfType<[i8], CCAssignToReg<[BD0, BD1]>>,
34+
CCIfType<[i16], CCAssignToReg<[WD0, WD1]>>,
35+
CCIfType<[i32], CCAssignToReg<[D0, D1]>>,
36+
CCDelegateTo<RetCC_M68kCommon>
37+
]>;
38+
39+
/// M68k fastcc return convention.
40+
/// This convention allows to return up to 16 bytes in registers which can be
41+
/// split among 16 1-byte values or used for a single 16-byte value.
42+
/// TODO: Verify its functionality and write tests
43+
def RetCC_M68k_Fast : CallingConv<[
44+
CCIfType<[i1], CCPromoteToType<i8>>,
45+
CCIfType<[i8], CCAssignToReg<[BD0, BD1]>>,
46+
CCIfType<[i16], CCAssignToReg<[WD0, WD1, WA0, WA1]>>,
47+
CCIfType<[i32], CCAssignToReg<[D0, D1, A0, A1]>>,
48+
CCDelegateTo<RetCC_M68kCommon>
49+
]>;
50+
51+
/// This is the root return-value convention for the M68k backend.
52+
def RetCC_M68k : CallingConv<[
53+
CCIfCC<"CallingConv::Fast", CCDelegateTo<RetCC_M68k_Fast>>,
54+
CCDelegateTo<RetCC_M68k_C>
55+
]>;
56+
57+
//===----------------------------------------------------------------------===//
58+
// M68k C Calling Convention
59+
//===----------------------------------------------------------------------===//
60+
61+
/// CC_M68k_Common - In all M68k calling conventions, extra integers and FP
62+
/// values are spilled on the stack.
63+
def CC_M68k_Common : CallingConv<[
64+
/// Handles byval parameters.
65+
CCIfByVal<CCPassByVal<4, 4>>,
66+
67+
/// Integer values get stored in stack slots that are 4 bytes in
68+
/// size and 4-byte aligned.
69+
CCIfType<[i32], CCAssignToStack<4, 4>>
70+
]>;
71+
72+
def CC_M68k_Fast : CallingConv<[
73+
/// Promote i1/i8/i16 arguments to i32.
74+
CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
75+
76+
/// The 'nest' parameter, if any, is passed in A1.
77+
CCIfNest<CCAssignToReg<[A1]>>, // FIXME verify if this is correct
78+
79+
/// Since M68k uses %An for pointers and we want them be passed in regs
80+
/// too we have to use custom function.
81+
CCIfType<[i32], CCCustom<"CC_M68k_Any_AssignToReg">>,
82+
83+
/// Otherwise, same as everything else.
84+
CCDelegateTo<CC_M68k_Common>
85+
]>;
86+
87+
def CC_M68k_C : CallingConv<[
88+
/// Promote i1/i8/i16 arguments to i32.
89+
CCIfType<[i1, i8, i16], CCPromoteToType<i32>>,
90+
91+
/// The 'nest' parameter, if any, is passed in A1.
92+
CCIfNest<CCAssignToReg<[A1]>>, // FIXME verify if this is correct
93+
94+
/// Use registers only if 'inreg' used and the call is not vararg
95+
CCIfNotVarArg<CCIfInReg<CCIfType<[i32], CCAssignToReg<[D0, D1]>>>>,
96+
97+
// TODO: Support for 'sret'
98+
99+
/// Otherwise, same as everything else.
100+
CCDelegateTo<CC_M68k_Common>
101+
]>;
102+
103+
/// This is the root argument convention for the M68k backend.
104+
def CC_M68k : CallingConv<[
105+
CCIfCC<"CallingConv::Fast", CCDelegateTo<CC_M68k_Fast>>,
106+
CCDelegateTo<CC_M68k_C>
107+
]>;
108+
109+
//===----------------------------------------------------------------------===//
110+
// Callee-saved Registers.
111+
//===----------------------------------------------------------------------===//
112+
113+
def CSR_NoRegs : CalleeSavedRegs<(add)>;
114+
115+
// A5 - BP
116+
// A6 - FP
117+
def CSR_STD : CalleeSavedRegs<(add D2, D3, D4, D5, D6, D7,
118+
A2, A3, A4, A5, A6)>;
119+

0 commit comments

Comments
 (0)