diff options
author | Archibald Elliott <archibald.elliott@arm.com> | 2022-11-18 13:15:49 +0000 |
---|---|---|
committer | Archibald Elliott <archibald.elliott@arm.com> | 2022-11-25 11:33:53 +0000 |
commit | 3e9b6adfc7caa8cc376b78c98069f2c0c6ae3fff (patch) | |
tree | d589911e7423a38979f81d9479381473fe34b8c3 /llvm/lib | |
parent | 6fd0ae39be79bdb686e4cc966e4cdee9950e2645 (diff) | |
download | llvm-3e9b6adfc7caa8cc376b78c98069f2c0c6ae3fff.zip llvm-3e9b6adfc7caa8cc376b78c98069f2c0c6ae3fff.tar.gz llvm-3e9b6adfc7caa8cc376b78c98069f2c0c6ae3fff.tar.bz2 |
[ARM] Move ARM::parseBranchProtection into ARMTargetParserCommon
This should live with the Arm targets, given they have target-specific
target parsers.
Differential Revision: https://reviews.llvm.org/D137835
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/ARMTargetParserCommon.cpp | 49 | ||||
-rw-r--r-- | llvm/lib/Support/TargetParser.cpp | 48 |
2 files changed, 49 insertions, 48 deletions
diff --git a/llvm/lib/Support/ARMTargetParserCommon.cpp b/llvm/lib/Support/ARMTargetParserCommon.cpp index 1cbf6e1..8650261 100644 --- a/llvm/lib/Support/ARMTargetParserCommon.cpp +++ b/llvm/lib/Support/ARMTargetParserCommon.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/ARMTargetParserCommon.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringSwitch.h" using namespace llvm; @@ -130,3 +131,51 @@ ARM::EndianKind ARM::parseArchEndian(StringRef Arch) { return EndianKind::INVALID; } + +// Parse a branch protection specification, which has the form +// standard | none | [bti,pac-ret[+b-key,+leaf]*] +// 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) { + PBP = {"none", "a_key", false}; + if (Spec == "none") + return true; // defaults are ok + + if (Spec == "standard") { + PBP.Scope = "non-leaf"; + PBP.BranchTargetEnforcement = true; + 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"; + else + break; + } + continue; + } + if (Opt == "") + Err = "<empty>"; + else + Err = Opt; + return false; + } + + return true; +} diff --git a/llvm/lib/Support/TargetParser.cpp b/llvm/lib/Support/TargetParser.cpp index a7eccb6..1f45f11 100644 --- a/llvm/lib/Support/TargetParser.cpp +++ b/llvm/lib/Support/TargetParser.cpp @@ -337,51 +337,3 @@ bool getCPUFeaturesExceptStdExt(CPUKind Kind, } // namespace RISCV } // namespace llvm - -// Parse a branch protection specification, which has the form -// standard | none | [bti,pac-ret[+b-key,+leaf]*] -// 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) { - PBP = {"none", "a_key", false}; - if (Spec == "none") - return true; // defaults are ok - - if (Spec == "standard") { - PBP.Scope = "non-leaf"; - PBP.BranchTargetEnforcement = true; - 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"; - else - break; - } - continue; - } - if (Opt == "") - Err = "<empty>"; - else - Err = Opt; - return false; - } - - return true; -} |