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">;
34
35// Single Precision floating point
36def FeatureBasicF
37    : SubtargetFeature<"f", "HasBasicF", "true",
38                       "'F' (Single-Precision Floating-Point)">;
39def HasBasicF
40    : Predicate<"Subtarget->hasBasicF()">,
41      AssemblerPredicate<(all_of FeatureBasicF),
42                         "'F' (Single-Precision Floating-Point)">;
43
44// Double Precision floating point
45def FeatureBasicD
46    : SubtargetFeature<"d", "HasBasicD", "true",
47                       "'D' (Double-Precision Floating-Point)",
48                       [FeatureBasicF]>;
49def HasBasicD
50    : Predicate<"Subtarget->hasBasicD()">,
51      AssemblerPredicate<(all_of FeatureBasicD),
52                         "'D' (Double-Precision Floating-Point)">;
53
54// Loongson SIMD eXtension (LSX)
55def FeatureExtLSX
56    : SubtargetFeature<"lsx", "HasExtLSX", "true",
57                       "'LSX' (Loongson SIMD Extension)", [FeatureBasicD]>;
58def HasExtLSX
59    : Predicate<"Subtarget->hasExtLSX()">,
60      AssemblerPredicate<(all_of FeatureExtLSX),
61                         "'LSX' (Loongson SIMD Extension)">;
62
63// Loongson Advanced SIMD eXtension (LASX)
64def FeatureExtLASX
65    : SubtargetFeature<"lasx", "HasExtLASX", "true",
66                       "'LASX' (Loongson Advanced SIMD Extension)",
67                       [FeatureExtLSX]>;
68def HasExtLASX
69    : Predicate<"Subtarget->hasExtLASX()">,
70      AssemblerPredicate<(all_of FeatureExtLASX),
71                         "'LASX' (Loongson Advanced SIMD Extension)">;
72
73// Loongson VirtualiZation (LVZ)
74def FeatureExtLVZ
75    : SubtargetFeature<"lvz", "HasExtLVZ", "true",
76                       "'LVZ' (Loongson Virtualization Extension)">;
77def HasExtLVZ
78    : Predicate<"Subtarget->hasExtLVZ()">,
79      AssemblerPredicate<(all_of FeatureExtLVZ),
80                         "'LVZ' (Loongson Virtualization Extension)">;
81
82// Loongson Binary Translation (LBT)
83def FeatureExtLBT
84    : SubtargetFeature<"lbt", "HasExtLBT", "true",
85                       "'LBT' (Loongson Binary Translation Extension)">;
86def HasExtLBT
87    : Predicate<"Subtarget->hasExtLBT()">,
88      AssemblerPredicate<(all_of FeatureExtLBT),
89                         "'LBT' (Loongson Binary Translation Extension)">;
90
91// Expand la.global as la.pcrel
92def LaGlobalWithPcrel
93    : SubtargetFeature<"la-global-with-pcrel", "HasLaGlobalWithPcrel", "true",
94                       "Expand la.global as la.pcrel">;
95def HasLaGlobalWithPcrel
96    : Predicate<"Subtarget->hasLaGlobalWithPcrel()">,
97      AssemblerPredicate<(all_of LaGlobalWithPcrel),
98                         "Expand la.global as la.pcrel">;
99
100// Expand la.global as la.abs
101def LaGlobalWithAbs
102    : SubtargetFeature<"la-global-with-abs", "HasLaGlobalWithAbs", "true",
103                       "Expand la.global as la.abs">;
104def HasLaGlobalWithAbs
105    : Predicate<"Subtarget->hasLaGlobalWithAbs()">,
106      AssemblerPredicate<(all_of LaGlobalWithAbs),
107                         "Expand la.global as la.abs">;
108
109// Expand la.local as la.abs
110def LaLocalWithAbs
111    : SubtargetFeature<"la-local-with-abs", "HasLaLocalWithAbs", "true",
112                       "Expand la.local as la.abs">;
113def HasLaLocalWithAbs
114    : Predicate<"Subtarget->hasLaLocalWithAbs()">,
115      AssemblerPredicate<(all_of LaLocalWithAbs),
116                         "Expand la.local as la.abs">;
117
118//===----------------------------------------------------------------------===//
119// Registers, instruction descriptions ...
120//===----------------------------------------------------------------------===//
121
122include "LoongArchRegisterInfo.td"
123include "LoongArchCallingConv.td"
124include "LoongArchInstrInfo.td"
125
126//===----------------------------------------------------------------------===//
127// LoongArch processors supported.
128//===----------------------------------------------------------------------===//
129
130def : ProcessorModel<"generic-la32", NoSchedModel, [Feature32Bit]>;
131def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit]>;
132
133// Support generic for compatibility with other targets. The triple will be used
134// to change to the appropriate la32/la64 version.
135def : ProcessorModel<"generic", NoSchedModel, []>;
136
137def : ProcessorModel<"la464", NoSchedModel, [Feature64Bit,
138                                             FeatureExtLASX,
139                                             FeatureExtLVZ,
140                                             FeatureExtLBT]>;
141
142//===----------------------------------------------------------------------===//
143// Define the LoongArch target.
144//===----------------------------------------------------------------------===//
145
146def LoongArchInstrInfo : InstrInfo {
147  // guess mayLoad, mayStore, and hasSideEffects
148  // This option is a temporary migration help. It will go away.
149  let guessInstructionProperties = 1;
150}
151
152def LoongArchAsmParser : AsmParser {
153  let ShouldEmitMatchRegisterAltName = 1;
154  let AllowDuplicateRegisterNames = 1;
155}
156
157def LoongArchAsmParserVariant : AsmParserVariant {
158  int Variant = 0;
159  // Recognize hard coded registers.
160  string RegisterPrefix = "$";
161}
162
163def LoongArchAsmWriter : AsmWriter {
164  int PassSubtarget = 1;
165}
166
167def LoongArch : Target {
168  let InstructionSet = LoongArchInstrInfo;
169  let AssemblyParsers = [LoongArchAsmParser];
170  let AssemblyParserVariants = [LoongArchAsmParserVariant];
171  let AssemblyWriters = [LoongArchAsmWriter];
172  let AllowRegisterRenaming = 1;
173}
174