diff --git a/llvm/lib/Target/LoongArch/LoongArch.td b/llvm/lib/Target/LoongArch/LoongArch.td --- a/llvm/lib/Target/LoongArch/LoongArch.td +++ b/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 diff --git a/llvm/lib/Target/LoongArch/LoongArchSubtarget.h b/llvm/lib/Target/LoongArch/LoongArchSubtarget.h --- a/llvm/lib/Target/LoongArch/LoongArchSubtarget.h +++ b/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; diff --git a/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp b/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp --- a/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp +++ b/llvm/lib/Target/LoongArch/LoongArchSubtarget.cpp @@ -39,6 +39,15 @@ 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/test/CodeGen/LoongArch/feature-32bit.ll b/llvm/test/CodeGen/LoongArch/feature-32bit.ll new file mode 100644 --- /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.