[llvm] [Attributor] Pack out arguments into a struct (PR #119267)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 1 08:18:48 PST 2025


================
@@ -6469,6 +6469,54 @@ struct AADenormalFPMath
   static const char ID;
 };
 
+/// An abstract attribute for converting out arguments into struct elements.
+struct AAConvertOutArgument
+    : public StateWrapper<BooleanState, AbstractAttribute> {
+  using Base = StateWrapper<BooleanState, AbstractAttribute>;
+
+  AAConvertOutArgument(const IRPosition &IRP, Attributor &A) : Base(IRP) {}
+
+  /// Create an abstract attribute view for the position \p IRP.
+  static AAConvertOutArgument &createForPosition(const IRPosition &IRP,
+                                                 Attributor &A);
+
+  /// See AbstractAttribute::getName()
+  const std::string getName() const override { return "AAConvertOutArgument"; }
+
+  /// Return true if convertible is assumed.
+  bool isAssumedConvertible() const { return getAssumed(); }
+
+  /// Return true if convertible is known.
+  bool isKnownConvertible() const { return getKnown(); }
+
+  /// See AbstractAttribute::getIdAddr()
+  const char *getIdAddr() const override { return &ID; }
+
+  /// This function should return true if the type of the \p AA is
+  /// AADenormalFPMath.
+  static bool classof(const AbstractAttribute *AA) {
+    return (AA->getIdAddr() == &ID);
+  }
+
+  /// Unique ID (due to the unique address)
+  static const char ID;
+
+protected:
+  static bool isEligibleArgumentType(Type *Ty) { return Ty->isPointerTy(); }
+
+  static bool isEligibleArgument(const Argument &Arg, Attributor &A,
+                                 const AbstractAttribute &AA) {
+    if (!isEligibleArgumentType(Arg.getType()))
+      return false;
+
+    const IRPosition &ArgPos = IRPosition::argument(Arg);
+    auto *AAMem = A.getAAFor<AAMemoryBehavior>(AA, ArgPos, DepClassTy::NONE);
+
+    return Arg.hasNoAliasAttr() && AAMem && AAMem->isKnownWriteOnly() &&
----------------
elhewaty wrote:

@arsenm, in the following example does `ptr %dts` have any aliases in `@foo`? as `AANoAlias->isKnownNoAlias()` returns false.

```
define internal i1 @foo(ptr %dst) {
entry:
  store i32 42, ptr %dst
  ret i1 true
}


define i1 @fee(i32 %x, i32 %y) {
  %ptr = alloca i32
  %a = call i1 @foo(ptr %ptr, i32 %y)
  %b = load i32, ptr %ptr
  %c = icmp sle i32 %b, %x
  %xor = xor i1 %a, %c
  ret i1 %xor
}
```

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


More information about the llvm-commits mailing list