xref: /freebsd/contrib/llvm-project/llvm/lib/Target/LoongArch/LoongArch.td (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1//===-- LoongArch.td - Describe the LoongArch Target -------*- 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
9include "llvm/Target/Target.td"
10
11//===----------------------------------------------------------------------===//
12// LoongArch subtarget features and instruction predicates.
13//===----------------------------------------------------------------------===//
14
15// LoongArch is divided into two versions, the 32-bit version (LA32) and the
16// 64-bit version (LA64).
17def Feature64Bit
18    : SubtargetFeature<"64bit", "HasLA64", "true",
19                       "LA64 Basic Integer and Privilege Instruction Set">;
20def Feature32Bit
21    : SubtargetFeature<"32bit", "HasLA32", "true",
22                       "LA32 Basic Integer and Privilege Instruction Set">;
23def IsLA64
24    : Predicate<"Subtarget->is64Bit()">,
25      AssemblerPredicate<(all_of Feature64Bit),
26                         "LA64 Basic Integer and Privilege Instruction Set">;
27def IsLA32
28    : Predicate<"!Subtarget->is64Bit()">,
29      AssemblerPredicate<(all_of(not Feature64Bit)),
30                         "LA32 Basic Integer and Privilege Instruction Set">;
31
32defvar LA32 = DefaultMode;
33def LA64 : HwMode<"+64bit", [IsLA64]>;
34
35// Single Precision floating point
36def FeatureBasicF
37    : SubtargetFeature<"f", "HasBasicF", "true",
38                       "'F' (Single-Precision Floating-Point)">;
39def HasBasicF : Predicate<"Subtarget->hasBasicF()">;
40
41// Double Precision floating point
42def FeatureBasicD
43    : SubtargetFeature<"d", "HasBasicD", "true",
44                       "'D' (Double-Precision Floating-Point)",
45                       [FeatureBasicF]>;
46def HasBasicD : Predicate<"Subtarget->hasBasicD()">;
47
48// Loongson SIMD eXtension (LSX)
49def FeatureExtLSX
50    : SubtargetFeature<"lsx", "HasExtLSX", "true",
51                       "'LSX' (Loongson SIMD Extension)", [FeatureBasicD]>;
52def HasExtLSX : Predicate<"Subtarget->hasExtLSX()">;
53
54// Loongson Advanced SIMD eXtension (LASX)
55def FeatureExtLASX
56    : SubtargetFeature<"lasx", "HasExtLASX", "true",
57                       "'LASX' (Loongson Advanced SIMD Extension)",
58                       [FeatureExtLSX]>;
59def HasExtLASX : Predicate<"Subtarget->hasExtLASX()">;
60
61// Loongson VirtualiZation (LVZ)
62def FeatureExtLVZ
63    : SubtargetFeature<"lvz", "HasExtLVZ", "true",
64                       "'LVZ' (Loongson Virtualization Extension)">;
65def HasExtLVZ : Predicate<"Subtarget->hasExtLVZ()">;
66
67// Loongson Binary Translation (LBT)
68def FeatureExtLBT
69    : SubtargetFeature<"lbt", "HasExtLBT", "true",
70                       "'LBT' (Loongson Binary Translation Extension)">;
71def HasExtLBT : Predicate<"Subtarget->hasExtLBT()">;
72
73// Expand la.global as la.pcrel
74def LaGlobalWithPcrel
75    : SubtargetFeature<"la-global-with-pcrel", "HasLaGlobalWithPcrel", "true",
76                       "Expand la.global as la.pcrel">;
77def HasLaGlobalWithPcrel
78    : Predicate<"Subtarget->hasLaGlobalWithPcrel()">,
79      AssemblerPredicate<(all_of LaGlobalWithPcrel),
80                         "Expand la.global as la.pcrel">;
81
82// Expand la.global as la.abs
83def LaGlobalWithAbs
84    : SubtargetFeature<"la-global-with-abs", "HasLaGlobalWithAbs", "true",
85                       "Expand la.global as la.abs">;
86def HasLaGlobalWithAbs
87    : Predicate<"Subtarget->hasLaGlobalWithAbs()">,
88      AssemblerPredicate<(all_of LaGlobalWithAbs),
89                         "Expand la.global as la.abs">;
90
91// Expand la.local as la.abs
92def LaLocalWithAbs
93    : SubtargetFeature<"la-local-with-abs", "HasLaLocalWithAbs", "true",
94                       "Expand la.local as la.abs">;
95def HasLaLocalWithAbs
96    : Predicate<"Subtarget->hasLaLocalWithAbs()">,
97      AssemblerPredicate<(all_of LaLocalWithAbs),
98                         "Expand la.local as la.abs">;
99
100// Unaligned memory access
101def FeatureUAL
102    : SubtargetFeature<"ual", "HasUAL", "true",
103                       "Allow memory accesses to be unaligned">;
104
105//===----------------------------------------------------------------------===//
106// Registers, instruction descriptions ...
107//===----------------------------------------------------------------------===//
108
109include "LoongArchRegisterInfo.td"
110include "LoongArchCallingConv.td"
111include "LoongArchInstrInfo.td"
112
113//===----------------------------------------------------------------------===//
114// LoongArch processors supported.
115//===----------------------------------------------------------------------===//
116
117def : ProcessorModel<"generic-la32", NoSchedModel, [Feature32Bit]>;
118def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit, FeatureUAL]>;
119
120// Generic 64-bit processor with double-precision floating-point support.
121def : ProcessorModel<"loongarch64", NoSchedModel, [Feature64Bit,
122                                                   FeatureUAL,
123                                                   FeatureBasicD]>;
124
125// Support generic for compatibility with other targets. The triple will be used
126// to change to the appropriate la32/la64 version.
127def : ProcessorModel<"generic", NoSchedModel, []>;
128
129def : ProcessorModel<"la464", NoSchedModel, [Feature64Bit,
130                                             FeatureUAL,
131                                             FeatureExtLASX,
132                                             FeatureExtLVZ,
133                                             FeatureExtLBT]>;
134
135//===----------------------------------------------------------------------===//
136// Define the LoongArch target.
137//===----------------------------------------------------------------------===//
138
139def LoongArchInstrInfo : InstrInfo {
140  let guessInstructionProperties = 0;
141}
142
143def LoongArchAsmParser : AsmParser {
144  let ShouldEmitMatchRegisterAltName = 1;
145  let AllowDuplicateRegisterNames = 1;
146}
147
148def LoongArchAsmParserVariant : AsmParserVariant {
149  int Variant = 0;
150  // Recognize hard coded registers.
151  string RegisterPrefix = "$";
152}
153
154def LoongArchAsmWriter : AsmWriter {
155  int PassSubtarget = 1;
156}
157
158def LoongArch : Target {
159  let InstructionSet = LoongArchInstrInfo;
160  let AssemblyParsers = [LoongArchAsmParser];
161  let AssemblyParserVariants = [LoongArchAsmParserVariant];
162  let AssemblyWriters = [LoongArchAsmWriter];
163  let AllowRegisterRenaming = 1;
164}
165