[clang] [llvm] [Clang][LoongArch] Support target attribute for function (PR #140700)

via cfe-commits cfe-commits at lists.llvm.org
Wed May 21 20:21:23 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:

I believe that the previous approach was essentially off-the-cuff, done whichever way was most convenient.

If someone were to implement the same functionality for other architectures as well, they would find three pieces of code with very poor style.

To leave behind code that is more ergonomic for future developers, at the very least, the logic for handling features should be separated and handled individually.

```c++
auto handleArch = [&](StringRef Feature) { ... }
auto handleTune = [&](StringRef Feature) { ... }

if(feature.startwith("arch=") handleArch(feature)
else (feature.startwith("tune=") handleTune(feature)
else if ( ... ) ...
else {

}

```



https://github.com/llvm/llvm-project/pull/140700


More information about the cfe-commits mailing list