[PATCH] D140872: [LoongArch] Add "32bit" target feature

Xiaodong Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 2 22:15:05 PST 2023


XiaodongLoong created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
XiaodongLoong requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140872

Files:
  llvm/lib/Target/LoongArch/LoongArch.td
  llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/test/CodeGen/LoongArch/feature-32bit.ll


Index: llvm/test/CodeGen/LoongArch/feature-32bit.ll
===================================================================
--- /dev/null
+++ 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.
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -31,6 +31,7 @@
 
 class LoongArchSubtarget : public LoongArchGenSubtargetInfo {
   virtual void anchor();
+  bool HasLA32 = false;
   bool HasLA64 = false;
   bool HasBasicF = false;
   bool HasBasicD = false;
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp
@@ -39,6 +39,16 @@
     GRLen = 64;
   }
 
+  if (HasLA32 && HasLA64)
+    report_fatal_error(
+        "Features 32bit and 64bit should be mutually exclusive.");
+
+  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;
Index: llvm/lib/Target/LoongArch/LoongArch.td
===================================================================
--- llvm/lib/Target/LoongArch/LoongArch.td
+++ llvm/lib/Target/LoongArch/LoongArch.td
@@ -17,6 +17,9 @@
 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 @@
 // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140872.485922.patch
Type: text/x-patch
Size: 2663 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230103/88bae0e0/attachment.bin>


More information about the llvm-commits mailing list