LLVM 22.0.0git
LoongArchTargetParser.cpp
Go to the documentation of this file.
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
16
17using namespace llvm;
18using namespace llvm::LoongArch;
19
21#define LOONGARCH_FEATURE(NAME, KIND) {NAME, KIND},
22#include "llvm/TargetParser/LoongArchTargetParser.def"
23};
24
25const ArchInfo AllArchs[] = {
26#define LOONGARCH_ARCH(NAME, KIND, FEATURES) \
27 {NAME, LoongArch::ArchKind::KIND, FEATURES},
28#include "llvm/TargetParser/LoongArchTargetParser.def"
29};
30
32 for (const auto A : AllArchs)
33 if (A.Name == Arch)
34 return true;
35 return false;
36}
37
39 if (Feature.starts_with("+") || Feature.starts_with("-"))
40 return false;
41 for (const auto &F : AllFeatures) {
42 StringRef CanonicalName =
43 F.Name.starts_with("+") ? F.Name.drop_front() : F.Name;
44 if (CanonicalName == Feature)
45 return true;
46 }
47 return false;
48}
49
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(F.Name);
57 return true;
58 }
59 }
60
61 if (Arch == "la64v1.0" || Arch == "la64v1.1") {
62 Features.push_back("+64bit");
63 Features.push_back("+d");
64 Features.push_back("+lsx");
65 Features.push_back("+ual");
66 if (Arch == "la64v1.1") {
67 Features.push_back("+frecipe");
68 Features.push_back("+lam-bh");
69 Features.push_back("+lamcas");
70 Features.push_back("+ld-seq-sa");
71 Features.push_back("+div32");
72 Features.push_back("+scq");
73 }
74 return true;
75 }
76
77 return false;
78}
79
81
83 for (const auto A : AllArchs)
84 Values.emplace_back(A.Name);
85}
86
88 // TODO: use a real 32-bit arch name.
89 return Is64Bit ? "loongarch64" : "";
90}
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
const FeatureInfo AllFeatures[]
const ArchInfo AllArchs[]
#define F(x, y, z)
Definition MD5.cpp:55
This file defines the SmallVector class.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:261
LLVM_ABI StringRef getDefaultArch(bool Is64Bit)
LLVM_ABI bool getArchFeatures(StringRef Arch, std::vector< StringRef > &Features)
LLVM_ABI bool isValidCPUName(StringRef TuneCPU)
LLVM_ABI bool isValidFeatureName(StringRef Feature)
LLVM_ABI bool isValidArchName(StringRef Arch)
LLVM_ABI void fillValidCPUList(SmallVectorImpl< StringRef > &Values)
This is an optimization pass for GlobalISel generic memory operations.