xref: /llvm-project/llvm/lib/TargetParser/LoongArchTargetParser.cpp (revision 19834b4623fd1e7ae5185ed76031b407c3fa7a47)
1 //===-- LoongArchTargetParser - Parser for LoongArch features --*- C++ -*-====//
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 //
9 // This file implements a target parser to recognise LoongArch hardware features
10 // such as CPU/ARCH and extension names.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/TargetParser/LoongArchTargetParser.h"
15 
16 using namespace llvm;
17 using namespace llvm::LoongArch;
18 
19 const FeatureInfo AllFeatures[] = {
20 #define LOONGARCH_FEATURE(NAME, KIND) {NAME, KIND},
21 #include "llvm/TargetParser/LoongArchTargetParser.def"
22 };
23 
24 const ArchInfo AllArchs[] = {
25 #define LOONGARCH_ARCH(NAME, KIND, FEATURES)                                   \
26   {NAME, LoongArch::ArchKind::KIND, FEATURES},
27 #include "llvm/TargetParser/LoongArchTargetParser.def"
28 };
29 
30 bool LoongArch::isValidArchName(StringRef Arch) {
31   for (const auto A : AllArchs)
32     if (A.Name == Arch)
33       return true;
34   return false;
35 }
36 
37 bool LoongArch::getArchFeatures(StringRef Arch,
38                                 std::vector<StringRef> &Features) {
39   for (const auto A : AllArchs) {
40     if (A.Name == Arch) {
41       for (const auto F : AllFeatures)
42         if ((A.Features & F.Kind) == F.Kind)
43           Features.push_back(F.Name);
44       return true;
45     }
46   }
47 
48   if (Arch == "la64v1.0" || Arch == "la64v1.1") {
49     Features.push_back("+64bit");
50     Features.push_back("+d");
51     Features.push_back("+lsx");
52     Features.push_back("+ual");
53     if (Arch == "la64v1.1") {
54       Features.push_back("+frecipe");
55       Features.push_back("+lam-bh");
56       Features.push_back("+lamcas");
57       Features.push_back("+ld-seq-sa");
58       Features.push_back("+div32");
59       Features.push_back("+scq");
60     }
61     return true;
62   }
63 
64   return false;
65 }
66 
67 bool LoongArch::isValidCPUName(StringRef Name) { return isValidArchName(Name); }
68 
69 void LoongArch::fillValidCPUList(SmallVectorImpl<StringRef> &Values) {
70   for (const auto A : AllArchs)
71     Values.emplace_back(A.Name);
72 }
73 
74 StringRef LoongArch::getDefaultArch(bool Is64Bit) {
75   // TODO: use a real 32-bit arch name.
76   return Is64Bit ? "loongarch64" : "";
77 }
78