[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))
----------------
nickdesaulniers wrote:
If this is the only use of `M` consider sinking it into the use-site and skipping the assert.
```c
if (isModuleAttributeSet(F.getParent(), ModAttrName))
```
or, if you feel the assert is necessary, sink this closer to the use.
```c
if (F.hasFnAttribute(FnAttrName))
return;
Module *M = F.getParent();
assert(M && "Missing module");
if (isModuleAttributeSet(M, ModAttrName))
```
https://github.com/llvm/llvm-project/pull/80640
More information about the llvm-commits
mailing list