[llvm] [NFC][LLVM] Refactor Autoupgrade function attributes from Module attributes. (PR #84494)

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 8 12:11:50 PST 2024


================
@@ -5185,62 +5185,40 @@ static bool isModuleAttributeSet(Module &M, const StringRef &ModAttr) {
   return Attr && Attr->getZExtValue();
 }
 
-// Copy an attribute from module to the function if exists.
-// First value of the pair is used when the module attribute is not zero
-// the second otherwise.
-static void
-CopyModuleAttributeToFunction(Function &F, StringRef FnAttrName,
-                              StringRef ModAttrName,
-                              std::pair<StringRef, StringRef> Values) {
-  if (F.hasFnAttribute(FnAttrName))
-    return;
-  F.addFnAttr(FnAttrName, isModuleAttributeSet(*F.getParent(), ModAttrName)
-                              ? Values.first
-                              : Values.second);
-}
-
-// Copy a boolean attribute from module to the function if exists.
-// Module attribute treated false if zero otherwise true.
-static void CopyModuleAttributeToFunction(Function &F, StringRef AttrName) {
-  CopyModuleAttributeToFunction(
-      F, AttrName, AttrName,
-      std::make_pair<StringRef, StringRef>("true", "false"));
-}
-
-// Copy an attribute from module to the function if exists.
-// First value of the pair is used when the module attribute is not zero
-// the second otherwise.
-static void
-CopyModuleAttributeToFunction(Function &F, StringRef AttrName,
-                              std::pair<StringRef, StringRef> Values) {
-  CopyModuleAttributeToFunction(F, AttrName, AttrName, Values);
-}
-
 void llvm::CopyModuleAttrToFunctions(Module &M) {
   Triple T(M.getTargetTriple());
   if (!T.isThumb() && !T.isARM() && !T.isAArch64())
     return;
 
+  StringRef SignTypeValue = "none";
+  if (isModuleAttributeSet(M, "sign-return-address"))
+    SignTypeValue = "non-leaf";
+  if (isModuleAttributeSet(M, "sign-return-address-all"))
----------------
DanielKristofKiss wrote:

sign-return-address 0 / sign-return-address-all 0 -> "none"
sign-return-address 0 / sign-return-address-all 0 -> "non-leaf"
sign-return-address 1 / sign-return-address-all 1 -> "all"
sign-return-address 0 / sign-return-address-all 1 -> "invalid".  - on my list of missing validations.

I didn't find they not a just 0,1,2 are used for the module values with direct "none", "non-leaf", or "all" mapping.

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


More information about the llvm-commits mailing list