From 3e9b6adfc7caa8cc376b78c98069f2c0c6ae3fff Mon Sep 17 00:00:00 2001 From: Archibald Elliott Date: Fri, 18 Nov 2022 13:15:49 +0000 Subject: [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 --- llvm/lib/Support/ARMTargetParserCommon.cpp | 49 ++++++++++++++++++++++++++++++ llvm/lib/Support/TargetParser.cpp | 48 ----------------------------- 2 files changed, 49 insertions(+), 48 deletions(-) (limited to 'llvm/lib/Support') 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 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 = ""; + 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 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 = ""; - else - Err = Opt; - return false; - } - - return true; -} -- cgit v1.1