[llvm] 8d798ea - [LoongArch] Add "32bit" target feature
Xiaodong Liu via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 5 17:29:31 PST 2023
Author: Xiaodong Liu
Date: 2023-01-06T09:28:55+08:00
New Revision: 8d798eab16ca3ab38d42f097d059c4cf9d8b23e7
URL: https://github.com/llvm/llvm-project/commit/8d798eab16ca3ab38d42f097d059c4cf9d8b23e7
DIFF: https://github.com/llvm/llvm-project/commit/8d798eab16ca3ab38d42f097d059c4cf9d8b23e7.diff
LOG: [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
Added:
llvm/test/CodeGen/LoongArch/feature-32bit.ll
Modified:
llvm/lib/Target/LoongArch/LoongArch.td
llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
llvm/lib/Target/LoongArch/LoongArchSubtarget.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/LoongArch/LoongArch.td b/llvm/lib/Target/LoongArch/LoongArch.td
index dd85b11ac9ec2..7e5c3563f39a2 100644
--- a/llvm/lib/Target/LoongArch/LoongArch.td
+++ b/llvm/lib/Target/LoongArch/LoongArch.td
@@ -17,6 +17,9 @@ include "llvm/Target/Target.td"
def Feature64Bit
: SubtargetFeature<"64bit", "HasLA64", "true",
"LA64 Basic Integer and Privilege Instruction Set">;
+def Feature32Bit
+ : SubtargetFeature<"32bit", "HasLA32", "true",
+ "LA32 Basic Integer and Privilege Instruction Set">;
def IsLA64
: Predicate<"Subtarget->is64Bit()">,
AssemblerPredicate<(all_of Feature64Bit),
@@ -124,7 +127,7 @@ include "LoongArchInstrInfo.td"
// LoongArch processors supported.
//===----------------------------------------------------------------------===//
-def : ProcessorModel<"generic-la32", NoSchedModel, []>;
+def : ProcessorModel<"generic-la32", NoSchedModel, [Feature32Bit]>;
def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit]>;
// Support generic for compatibility with other targets. The triple will be used
diff --git a/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp b/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
index 6edf59c9f7d10..d8850f656d52f 100644
--- a/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
@@ -39,6 +39,15 @@ LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(
GRLen = 64;
}
+ if (HasLA32 == HasLA64)
+ report_fatal_error("Please use one feature of 32bit and 64bit.");
+
+ if (Is64Bit && HasLA32)
+ report_fatal_error("Feature 32bit should be used for loongarch32 target.");
+
+ if (!Is64Bit && HasLA64)
+ report_fatal_error("Feature 64bit should be used for loongarch64 target.");
+
// TODO: ILP32{S,F} LP64{S,F}
TargetABI = Is64Bit ? LoongArchABI::ABI_LP64D : LoongArchABI::ABI_ILP32D;
return *this;
diff --git a/llvm/lib/Target/LoongArch/LoongArchSubtarget.h b/llvm/lib/Target/LoongArch/LoongArchSubtarget.h
index 4b049bbf59ead..aa87638e47e97 100644
--- a/llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ b/llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -31,6 +31,7 @@ class StringRef;
class LoongArchSubtarget : public LoongArchGenSubtargetInfo {
virtual void anchor();
+ bool HasLA32 = false;
bool HasLA64 = false;
bool HasBasicF = false;
bool HasBasicD = false;
diff --git a/llvm/test/CodeGen/LoongArch/feature-32bit.ll b/llvm/test/CodeGen/LoongArch/feature-32bit.ll
new file mode 100644
index 0000000000000..ef3cbd9895037
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/feature-32bit.ll
@@ -0,0 +1,5 @@
+; RUN: llc --mtriple=loongarch64 --mattr=help 2>&1 | FileCheck %s
+; RUN: llc --mtriple=loongarch32 --mattr=help 2>&1 | FileCheck %s
+
+; CHECK: Available features for this target:
+; CHECK: 32bit - LA32 Basic Integer and Privilege Instruction Set.
More information about the llvm-commits
mailing list