[clang] 3e9b6ad - [ARM] Move ARM::parseBranchProtection into ARMTargetParserCommon
Archibald Elliott via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 25 03:34:02 PST 2022
Author: Archibald Elliott
Date: 2022-11-25T11:33:53Z
New Revision: 3e9b6adfc7caa8cc376b78c98069f2c0c6ae3fff
URL: https://github.com/llvm/llvm-project/commit/3e9b6adfc7caa8cc376b78c98069f2c0c6ae3fff
DIFF: https://github.com/llvm/llvm-project/commit/3e9b6adfc7caa8cc376b78c98069f2c0c6ae3fff.diff
LOG: [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
Added:
Modified:
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Basic/Targets/ARM.h
clang/lib/Driver/ToolChains/Clang.cpp
llvm/include/llvm/Support/ARMTargetParserCommon.h
llvm/include/llvm/Support/TargetParser.h
llvm/lib/Support/ARMTargetParserCommon.cpp
llvm/lib/Support/TargetParser.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index d85a21397abc1..1221b84676d9b 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -18,6 +18,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/Support/ARMTargetParserCommon.h"
using namespace clang;
using namespace clang::targets;
diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h
index 74c7aad97690d..6d2eb866444d4 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -16,7 +16,6 @@
#include "OSTargets.h"
#include "clang/Basic/TargetBuiltins.h"
#include "llvm/Support/AArch64TargetParser.h"
-#include "llvm/Support/TargetParser.h"
namespace clang {
namespace targets {
diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index e85336b6e32f9..897073eca7eb5 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -17,9 +17,9 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/ADT/Triple.h"
-#include "llvm/Support/Compiler.h"
#include "llvm/Support/ARMTargetParser.h"
-#include "llvm/Support/TargetParser.h"
+#include "llvm/Support/ARMTargetParserCommon.h"
+#include "llvm/Support/Compiler.h"
namespace clang {
namespace targets {
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index fcf99c88d4c2c..765e766c39524 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -44,6 +44,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Option/ArgList.h"
+#include "llvm/Support/ARMTargetParserCommon.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Compression.h"
@@ -51,7 +52,6 @@
#include "llvm/Support/Host.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
-#include "llvm/Support/TargetParser.h"
#include "llvm/Support/YAMLParser.h"
#include <cctype>
diff --git a/llvm/include/llvm/Support/ARMTargetParserCommon.h b/llvm/include/llvm/Support/ARMTargetParserCommon.h
index 3db8646e26fd8..a21a9d7f1c67c 100644
--- a/llvm/include/llvm/Support/ARMTargetParserCommon.h
+++ b/llvm/include/llvm/Support/ARMTargetParserCommon.h
@@ -37,6 +37,15 @@ ISAKind parseArchISA(StringRef Arch);
// Little/Big endian
EndianKind parseArchEndian(StringRef Arch);
+struct ParsedBranchProtection {
+ StringRef Scope;
+ StringRef Key;
+ bool BranchTargetEnforcement;
+};
+
+bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
+ StringRef &Err);
+
} // namespace ARM
} // namespace llvm
#endif
diff --git a/llvm/include/llvm/Support/TargetParser.h b/llvm/include/llvm/Support/TargetParser.h
index 39222b02e21ad..bf954b909cf2f 100644
--- a/llvm/include/llvm/Support/TargetParser.h
+++ b/llvm/include/llvm/Support/TargetParser.h
@@ -182,19 +182,6 @@ void fillValidTuneCPUArchList(SmallVectorImpl<StringRef> &Values, bool IsRV64);
bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector<StringRef> &Features);
} // namespace RISCV
-
-namespace ARM {
-struct ParsedBranchProtection {
- StringRef Scope;
- StringRef Key;
- bool BranchTargetEnforcement;
-};
-
-bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
- StringRef &Err);
-
-} // namespace ARM
-
} // namespace llvm
#endif
diff --git a/llvm/lib/Support/ARMTargetParserCommon.cpp b/llvm/lib/Support/ARMTargetParserCommon.cpp
index 1cbf6e1d4818a..8650261cf5f10 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 a7eccb67e6df8..1f45f117dd44e 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;
-}
More information about the cfe-commits
mailing list