[clang] [llvm] [Clang][LoongArch] Support target attribute for function (PR #140700)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 20 19:43:21 PDT 2025
================
@@ -388,6 +388,51 @@ bool LoongArchTargetInfo::handleTargetFeatures(
return true;
}
+ParsedTargetAttr
+LoongArchTargetInfo::parseTargetAttr(StringRef Features) const {
+ ParsedTargetAttr Ret;
+ if (Features == "default")
+ return Ret;
+ SmallVector<StringRef, 1> AttrFeatures;
+ Features.split(AttrFeatures, ",");
+
+ for (auto &Feature : AttrFeatures) {
+ Feature = Feature.trim();
+
+ if (Feature.starts_with("arch=")) {
----------------
tangaac wrote:
It's recommended to use use a helper function to handle the types of features. Like below.
If it's ok to define a FeatureKind enum, that would be even better.
~~~c++
static std::pair<llvm::StringRef, llvm::StringRef> getFeatureTypeAndValue(llvm::StringRef Feature) {
auto Split = Feature.split("=");
if (!Split.second.empty())
return {Split.first.trim(), Split.second.trim()};
if (Feature.starts_with("no-"))
return {"no", Feature.drop_front(3).trim()};
return {"feature", Feature.trim()};
}
~~~
~~~c++
for (auto &Feature : AttrFeatures) {
Feature = Feature.trim();
auto [Kind, Value] = getFeatureTypeAndValue(Feature);
if (Kind == "arch") {
} else if (Kind == "tune") {
} ..
}
~~~
https://github.com/llvm/llvm-project/pull/140700
More information about the cfe-commits
mailing list