[llvm] [clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

Sam Tebbs via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 30 05:51:12 PST 2024


================
@@ -814,6 +821,93 @@ Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
                           /*allowHigherAlign*/ false);
 }
 
+class SMEAttributes {
+public:
+  bool IsStreaming = false;
+  bool IsStreamingBody = false;
+  bool IsStreamingCompatible = false;
+  bool HasNewZA = false;
+
+  SMEAttributes(const FunctionDecl *F) {
+    if (F->hasAttr<ArmLocallyStreamingAttr>())
+      IsStreamingBody = true;
+    if (auto *NewAttr = F->getAttr<ArmNewAttr>()) {
+      if (NewAttr->isNewZA())
+        HasNewZA = true;
+    }
+    if (const auto *T = F->getType()->getAs<FunctionProtoType>()) {
+      if (T->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask)
+        IsStreaming = true;
+      if (T->getAArch64SMEAttributes() &
+          FunctionType::SME_PStateSMCompatibleMask)
+        IsStreamingCompatible = true;
+    }
+  }
+
+  bool hasStreamingBody() const { return IsStreamingBody; }
+  bool hasStreamingInterface() const { return IsStreaming; }
+  bool hasStreamingCompatibleInterface() const { return IsStreamingCompatible; }
+  bool hasStreamingInterfaceOrBody() const {
+    return hasStreamingBody() || hasStreamingInterface();
+  }
+  bool hasNonStreamingInterface() const {
+    return !hasStreamingInterface() && !hasStreamingCompatibleInterface();
+  }
+  bool hasNonStreamingInterfaceAndBody() const {
+    return hasNonStreamingInterface() && !hasStreamingBody();
+  }
+
+  bool requiresSMChange(const SMEAttributes Callee,
+                        bool BodyOverridesInterface = false) {
+    // If the transition is not through a call (e.g. when considering inlining)
+    // and Callee has a streaming body, then we can ignore the interface of
+    // Callee.
+    if (BodyOverridesInterface && Callee.hasStreamingBody()) {
+      return !hasStreamingInterfaceOrBody();
+    }
+
+    if (Callee.hasStreamingCompatibleInterface())
+      return false;
+
+    if (hasStreamingCompatibleInterface())
+      return true;
+
+    // Both non-streaming
+    if (hasNonStreamingInterfaceAndBody() && Callee.hasNonStreamingInterface())
+      return false;
+
+    // Both streaming
+    if (hasStreamingInterfaceOrBody() && Callee.hasStreamingInterface())
+      return false;
+
+    return Callee.hasStreamingInterface();
+  }
+
+  bool hasNewZABody() { return HasNewZA; }
+  bool requiresLazySave() const { return HasNewZA; }
----------------
SamTebbs33 wrote:

Thanks, I've now removed the lazy save checking to loosen that restriction.

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


More information about the cfe-commits mailing list