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 | #include "llvm/ADT/SmallVector.h" |
16 | |
17 | using namespace llvm; |
18 | using namespace llvm::LoongArch; |
19 | |
20 | const FeatureInfo AllFeatures[] = { |
21 | #define LOONGARCH_FEATURE(NAME, KIND) {NAME, KIND}, |
22 | #include "llvm/TargetParser/LoongArchTargetParser.def" |
23 | }; |
24 | |
25 | const ArchInfo AllArchs[] = { |
26 | #define LOONGARCH_ARCH(NAME, KIND, FEATURES) \ |
27 | {NAME, LoongArch::ArchKind::KIND, FEATURES}, |
28 | #include "llvm/TargetParser/LoongArchTargetParser.def" |
29 | }; |
30 | |
31 | bool LoongArch::isValidArchName(StringRef Arch) { |
32 | for (const auto A : AllArchs) |
33 | if (A.Name == Arch) |
34 | return true; |
35 | return false; |
36 | } |
37 | |
38 | bool LoongArch::isValidFeatureName(StringRef Feature) { |
39 | if (Feature.starts_with(Prefix: "+" ) || Feature.starts_with(Prefix: "-" )) |
40 | return false; |
41 | for (const auto &F : AllFeatures) { |
42 | StringRef CanonicalName = |
43 | F.Name.starts_with(Prefix: "+" ) ? F.Name.drop_front() : F.Name; |
44 | if (CanonicalName == Feature) |
45 | return true; |
46 | } |
47 | return false; |
48 | } |
49 | |
50 | bool LoongArch::getArchFeatures(StringRef Arch, |
51 | std::vector<StringRef> &Features) { |
52 | for (const auto A : AllArchs) { |
53 | if (A.Name == Arch) { |
54 | for (const auto F : AllFeatures) |
55 | if ((A.Features & F.Kind) == F.Kind) |
56 | Features.push_back(x: F.Name); |
57 | return true; |
58 | } |
59 | } |
60 | |
61 | if (Arch == "la64v1.0" || Arch == "la64v1.1" ) { |
62 | Features.push_back(x: "+64bit" ); |
63 | Features.push_back(x: "+d" ); |
64 | Features.push_back(x: "+lsx" ); |
65 | Features.push_back(x: "+ual" ); |
66 | if (Arch == "la64v1.1" ) { |
67 | Features.push_back(x: "+frecipe" ); |
68 | Features.push_back(x: "+lam-bh" ); |
69 | Features.push_back(x: "+lamcas" ); |
70 | Features.push_back(x: "+ld-seq-sa" ); |
71 | Features.push_back(x: "+div32" ); |
72 | Features.push_back(x: "+scq" ); |
73 | } |
74 | return true; |
75 | } |
76 | |
77 | return false; |
78 | } |
79 | |
80 | bool LoongArch::isValidCPUName(StringRef Name) { return isValidArchName(Arch: Name); } |
81 | |
82 | void LoongArch::fillValidCPUList(SmallVectorImpl<StringRef> &Values) { |
83 | for (const auto A : AllArchs) |
84 | Values.emplace_back(Args: A.Name); |
85 | } |
86 | |
87 | StringRef LoongArch::getDefaultArch(bool Is64Bit) { |
88 | // TODO: use a real 32-bit arch name. |
89 | return Is64Bit ? "loongarch64" : "" ; |
90 | } |
91 | |