[llvm] [llvm][AArch64] Autoupgrade function attributes from Module attributes. (PR #80640)

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 09:02:04 PST 2024


================
@@ -5155,7 +5155,51 @@ struct StrictFPUpgradeVisitor : public InstVisitor<StrictFPUpgradeVisitor> {
 };
 } // namespace
 
-void llvm::UpgradeFunctionAttributes(Function &F) {
+// Check if the module attribute is present and not zero.
+static bool isModuleAttributeSet(const Module *M, const StringRef &ModAttr) {
+  if (const auto *Attr =
+          mdconst::extract_or_null<ConstantInt>(M->getModuleFlag(ModAttr)))
+    if (Attr->getZExtValue())
+      return true;
+  return 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 FnAttrName,
+                              StringRef ModAttrName,
+                              std::pair<StringRef, StringRef> Values) {
+  Module *M = F.getParent();
+  assert(M && "Missing module");
+  if (F.hasFnAttribute(FnAttrName))
+    return;
+  if (isModuleAttributeSet(M, ModAttrName))
+    F.addFnAttr(FnAttrName, Values.first);
+  else
+    F.addFnAttr(FnAttrName, Values.second);
----------------
nickdesaulniers wrote:

Does a ternary statement make this more concise?

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


More information about the llvm-commits mailing list