Skip to content

Commit 8d798ea

Browse files
committed
[LoongArch] Add "32bit" target feature
There are a few intrinsics or instructions on LoongArch that are only appropriate for loongarch32 target. So the feature "32bit" is added to implement it. Reviewed By: SixWeining Differential Revision: https://reviews.llvm.org/D140872
1 parent f70d17f commit 8d798ea

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

llvm/lib/Target/LoongArch/LoongArch.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ include "llvm/Target/Target.td"
1717
def Feature64Bit
1818
: SubtargetFeature<"64bit", "HasLA64", "true",
1919
"LA64 Basic Integer and Privilege Instruction Set">;
20+
def Feature32Bit
21+
: SubtargetFeature<"32bit", "HasLA32", "true",
22+
"LA32 Basic Integer and Privilege Instruction Set">;
2023
def IsLA64
2124
: Predicate<"Subtarget->is64Bit()">,
2225
AssemblerPredicate<(all_of Feature64Bit),
@@ -124,7 +127,7 @@ include "LoongArchInstrInfo.td"
124127
// LoongArch processors supported.
125128
//===----------------------------------------------------------------------===//
126129

127-
def : ProcessorModel<"generic-la32", NoSchedModel, []>;
130+
def : ProcessorModel<"generic-la32", NoSchedModel, [Feature32Bit]>;
128131
def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit]>;
129132

130133
// Support generic for compatibility with other targets. The triple will be used

llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(
3939
GRLen = 64;
4040
}
4141

42+
if (HasLA32 == HasLA64)
43+
report_fatal_error("Please use one feature of 32bit and 64bit.");
44+
45+
if (Is64Bit && HasLA32)
46+
report_fatal_error("Feature 32bit should be used for loongarch32 target.");
47+
48+
if (!Is64Bit && HasLA64)
49+
report_fatal_error("Feature 64bit should be used for loongarch64 target.");
50+
4251
// TODO: ILP32{S,F} LP64{S,F}
4352
TargetABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
4453
return *this;

llvm/lib/Target/LoongArch/LoongArchSubtarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class StringRef;
3131

3232
class LoongArchSubtarget : public LoongArchGenSubtargetInfo {
3333
virtual void anchor();
34+
bool HasLA32 = false;
3435
bool HasLA64 = false;
3536
bool HasBasicF = false;
3637
bool HasBasicD = false;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; RUN: llc --mtriple=loongarch64 --mattr=help 2>&1 | FileCheck %s
2+
; RUN: llc --mtriple=loongarch32 --mattr=help 2>&1 | FileCheck %s
3+
4+
; CHECK: Available features for this target:
5+
; CHECK: 32bit - LA32 Basic Integer and Privilege Instruction Set.

0 commit comments

Comments
 (0)