2022-10-23 22:19:49 +01:00
|
|
|
//===---------------- ARMTargetParserCommon ---------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Code that is common to ARMTargetParser and AArch64TargetParser.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
[Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
component into a new LLVM Component called "TargetParser". This
potentially enables using tablegen to maintain this information, as
is shown in https://reviews.llvm.org/D137517. This cannot currently
be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
information in the TargetParser:
- `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
the current Host machine for info about it, primarily to support
getting the host triple, but also for `-mcpu=native` support in e.g.
Clang. This is fairly tightly intertwined with the information in
`X86TargetParser.h`, so keeping them in the same component makes
sense.
- `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
the target triple parser and representation. This is very intertwined
with the Arm target parser, because the arm architecture version
appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.
And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM
Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.
If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.
Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 10:24:02 +00:00
|
|
|
#include "llvm/TargetParser/ARMTargetParserCommon.h"
|
2022-11-18 13:15:49 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2022-10-23 22:19:49 +01:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
StringRef ARM::getArchSynonym(StringRef Arch) {
|
|
|
|
return StringSwitch<StringRef>(Arch)
|
|
|
|
.Case("v5", "v5t")
|
|
|
|
.Case("v5e", "v5te")
|
|
|
|
.Case("v6j", "v6")
|
|
|
|
.Case("v6hl", "v6k")
|
|
|
|
.Cases("v6m", "v6sm", "v6s-m", "v6-m")
|
|
|
|
.Cases("v6z", "v6zk", "v6kz")
|
|
|
|
.Cases("v7", "v7a", "v7hl", "v7l", "v7-a")
|
|
|
|
.Case("v7r", "v7-r")
|
|
|
|
.Case("v7m", "v7-m")
|
|
|
|
.Case("v7em", "v7e-m")
|
|
|
|
.Cases("v8", "v8a", "v8l", "aarch64", "arm64", "v8-a")
|
|
|
|
.Case("v8.1a", "v8.1-a")
|
|
|
|
.Case("v8.2a", "v8.2-a")
|
|
|
|
.Case("v8.3a", "v8.3-a")
|
|
|
|
.Case("v8.4a", "v8.4-a")
|
|
|
|
.Case("v8.5a", "v8.5-a")
|
|
|
|
.Case("v8.6a", "v8.6-a")
|
|
|
|
.Case("v8.7a", "v8.7-a")
|
|
|
|
.Case("v8.8a", "v8.8-a")
|
2022-11-16 09:47:55 +00:00
|
|
|
.Case("v8.9a", "v8.9-a")
|
2022-10-23 22:19:49 +01:00
|
|
|
.Case("v8r", "v8-r")
|
|
|
|
.Cases("v9", "v9a", "v9-a")
|
|
|
|
.Case("v9.1a", "v9.1-a")
|
|
|
|
.Case("v9.2a", "v9.2-a")
|
|
|
|
.Case("v9.3a", "v9.3-a")
|
2022-11-16 09:47:55 +00:00
|
|
|
.Case("v9.4a", "v9.4-a")
|
2023-11-16 15:38:32 +00:00
|
|
|
.Case("v9.5a", "v9.5-a")
|
2022-10-23 22:19:49 +01:00
|
|
|
.Case("v8m.base", "v8-m.base")
|
|
|
|
.Case("v8m.main", "v8-m.main")
|
|
|
|
.Case("v8.1m.main", "v8.1-m.main")
|
|
|
|
.Default(Arch);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef ARM::getCanonicalArchName(StringRef Arch) {
|
|
|
|
size_t offset = StringRef::npos;
|
|
|
|
StringRef A = Arch;
|
|
|
|
StringRef Error = "";
|
|
|
|
|
|
|
|
// Begins with "arm" / "thumb", move past it.
|
2023-12-11 21:01:36 -08:00
|
|
|
if (A.starts_with("arm64_32"))
|
2022-10-23 22:19:49 +01:00
|
|
|
offset = 8;
|
2023-12-11 21:01:36 -08:00
|
|
|
else if (A.starts_with("arm64e"))
|
2022-10-23 22:19:49 +01:00
|
|
|
offset = 6;
|
2023-12-11 21:01:36 -08:00
|
|
|
else if (A.starts_with("arm64"))
|
2022-10-23 22:19:49 +01:00
|
|
|
offset = 5;
|
2023-12-11 21:01:36 -08:00
|
|
|
else if (A.starts_with("aarch64_32"))
|
2022-10-23 22:19:49 +01:00
|
|
|
offset = 10;
|
2023-12-11 21:01:36 -08:00
|
|
|
else if (A.starts_with("arm"))
|
2022-10-23 22:19:49 +01:00
|
|
|
offset = 3;
|
2023-12-11 21:01:36 -08:00
|
|
|
else if (A.starts_with("thumb"))
|
2022-10-23 22:19:49 +01:00
|
|
|
offset = 5;
|
2023-12-11 21:01:36 -08:00
|
|
|
else if (A.starts_with("aarch64")) {
|
2022-10-23 22:19:49 +01:00
|
|
|
offset = 7;
|
|
|
|
// AArch64 uses "_be", not "eb" suffix.
|
|
|
|
if (A.contains("eb"))
|
|
|
|
return Error;
|
|
|
|
if (A.substr(offset, 3) == "_be")
|
|
|
|
offset += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ex. "armebv7", move past the "eb".
|
|
|
|
if (offset != StringRef::npos && A.substr(offset, 2) == "eb")
|
|
|
|
offset += 2;
|
|
|
|
// Or, if it ends with eb ("armv7eb"), chop it off.
|
2023-12-11 21:01:36 -08:00
|
|
|
else if (A.ends_with("eb"))
|
2022-10-23 22:19:49 +01:00
|
|
|
A = A.substr(0, A.size() - 2);
|
|
|
|
// Trim the head
|
|
|
|
if (offset != StringRef::npos)
|
|
|
|
A = A.substr(offset);
|
|
|
|
|
|
|
|
// Empty string means offset reached the end, which means it's valid.
|
|
|
|
if (A.empty())
|
|
|
|
return Arch;
|
|
|
|
|
|
|
|
// Only match non-marketing names
|
|
|
|
if (offset != StringRef::npos) {
|
|
|
|
// Must start with 'vN'.
|
|
|
|
if (A.size() >= 2 && (A[0] != 'v' || !std::isdigit(A[1])))
|
|
|
|
return Error;
|
|
|
|
// Can't have an extra 'eb'.
|
|
|
|
if (A.contains("eb"))
|
|
|
|
return Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arch will either be a 'v' name (v7a) or a marketing name (xscale).
|
|
|
|
return A;
|
|
|
|
}
|
2022-11-14 12:36:23 +00:00
|
|
|
|
|
|
|
ARM::ISAKind ARM::parseArchISA(StringRef Arch) {
|
|
|
|
return StringSwitch<ISAKind>(Arch)
|
|
|
|
.StartsWith("aarch64", ISAKind::AARCH64)
|
|
|
|
.StartsWith("arm64", ISAKind::AARCH64)
|
|
|
|
.StartsWith("thumb", ISAKind::THUMB)
|
|
|
|
.StartsWith("arm", ISAKind::ARM)
|
|
|
|
.Default(ISAKind::INVALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
ARM::EndianKind ARM::parseArchEndian(StringRef Arch) {
|
2023-12-11 21:01:36 -08:00
|
|
|
if (Arch.starts_with("armeb") || Arch.starts_with("thumbeb") ||
|
|
|
|
Arch.starts_with("aarch64_be"))
|
2022-11-14 12:36:23 +00:00
|
|
|
return EndianKind::BIG;
|
|
|
|
|
2023-12-11 21:01:36 -08:00
|
|
|
if (Arch.starts_with("arm") || Arch.starts_with("thumb")) {
|
|
|
|
if (Arch.ends_with("eb"))
|
2022-11-14 12:36:23 +00:00
|
|
|
return EndianKind::BIG;
|
|
|
|
else
|
|
|
|
return EndianKind::LITTLE;
|
|
|
|
}
|
|
|
|
|
2023-12-11 21:01:36 -08:00
|
|
|
if (Arch.starts_with("aarch64") || Arch.starts_with("aarch64_32"))
|
2022-11-14 12:36:23 +00:00
|
|
|
return EndianKind::LITTLE;
|
|
|
|
|
|
|
|
return EndianKind::INVALID;
|
|
|
|
}
|
2022-11-18 13:15:49 +00:00
|
|
|
|
|
|
|
// Parse a branch protection specification, which has the form
|
2023-12-21 18:16:30 +00:00
|
|
|
// standard | none | [bti,pac-ret[+b-key,+leaf,+pc]*]
|
2022-11-18 13:15:49 +00:00
|
|
|
// Returns true on success, with individual elements of the specification
|
|
|
|
// returned in `PBP`. Returns false in error, with `Err` containing
|
|
|
|
// an erroneous part of the spec.
|
|
|
|
bool ARM::parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
|
|
|
|
StringRef &Err) {
|
2024-01-11 21:35:04 +08:00
|
|
|
PBP = {"none", "a_key", false, false, false};
|
2022-11-18 13:15:49 +00:00
|
|
|
if (Spec == "none")
|
|
|
|
return true; // defaults are ok
|
|
|
|
|
|
|
|
if (Spec == "standard") {
|
|
|
|
PBP.Scope = "non-leaf";
|
|
|
|
PBP.BranchTargetEnforcement = true;
|
2024-01-11 12:53:23 +00:00
|
|
|
PBP.GuardedControlStack = true;
|
2022-11-18 13:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<StringRef, 4> Opts;
|
|
|
|
Spec.split(Opts, "+");
|
|
|
|
for (int I = 0, E = Opts.size(); I != E; ++I) {
|
|
|
|
StringRef Opt = Opts[I].trim();
|
|
|
|
if (Opt == "bti") {
|
|
|
|
PBP.BranchTargetEnforcement = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Opt == "pac-ret") {
|
|
|
|
PBP.Scope = "non-leaf";
|
|
|
|
for (; I + 1 != E; ++I) {
|
|
|
|
StringRef PACOpt = Opts[I + 1].trim();
|
|
|
|
if (PACOpt == "leaf")
|
|
|
|
PBP.Scope = "all";
|
|
|
|
else if (PACOpt == "b-key")
|
|
|
|
PBP.Key = "b_key";
|
2023-12-21 18:16:30 +00:00
|
|
|
else if (PACOpt == "pc")
|
|
|
|
PBP.BranchProtectionPAuthLR = true;
|
2022-11-18 13:15:49 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2024-01-11 12:53:23 +00:00
|
|
|
if (Opt == "gcs") {
|
|
|
|
PBP.GuardedControlStack = true;
|
|
|
|
continue;
|
|
|
|
}
|
2022-11-18 13:15:49 +00:00
|
|
|
if (Opt == "")
|
|
|
|
Err = "<empty>";
|
|
|
|
else
|
|
|
|
Err = Opt;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|