[llvm] Use Module level target-abi to assign target features for codegenerated functions. (PR #100833)

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 7 12:14:14 PST 2025


================
@@ -387,6 +388,25 @@ Function *Function::Create(FunctionType *Ty, LinkageTypes Linkage,
   return Create(Ty, Linkage, M.getDataLayout().getProgramAddressSpace(), N, &M);
 }
 
+StringRef Function::getDefaultTargetFeatures(const StringRef TargetABI) {
+  Triple T(getParent()->getTargetTriple());
+  StringRef attr = "";
+  if (T.isRISCV64()) {
+    if (TargetABI.equals_insensitive("lp64d"))
+      attr = "+d";
+    else if (TargetABI.equals_insensitive("lp64f"))
+      attr = "+f";
+    else if (TargetABI.equals_insensitive("lp64q"))
+      attr = "+q";
+  } else if (T.isRISCV32() && TargetABI.contains("ilp32f")) {
+    attr = "+f";
+  } else if (T.isARM() || T.isThumb()) {
+    attr = "+thumb-mode";
----------------
pcc wrote:

> maybe that's why this pass adds "+thumb-mode"

Yes, exactly.

> And maybe a separate patch to add +thumb-mode in clang.

Yes, that would need to come at the same time as removing the code in this pass that adds `+thumb-mode` as it looks like that's the only thing that's fixing the potentially incorrect features currently coming from the frontend.

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


More information about the llvm-commits mailing list