[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
This commit is contained in:
parent
6fd0ae39be
commit
3e9b6adfc7
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue