[Mlir-commits] [mlir] [mlir][llvm] Add support for memset.inline (PR #115711)
Tobias Gysi
llvmlistbot at llvm.org
Tue Nov 12 04:28:23 PST 2024
================
@@ -904,6 +904,79 @@ std::optional<uint64_t> getStaticMemIntrLen(LLVM::MemcpyInlineOp op) {
return memIntrLen.getZExtValue();
}
+/// Returns the length of the given memory intrinsic in bytes if it can be known
+/// at compile-time on a best-effort basis, nothing otherwise.
+/// Because MemsetInlineOp has its length encoded as an attribute, this requires
+/// specialized handling.
+template <>
+std::optional<uint64_t> getStaticMemIntrLen(LLVM::MemsetInlineOp op) {
+ APInt memIntrLen = op.getLen();
+ if (memIntrLen.getBitWidth() > 64)
+ return {};
+ return memIntrLen.getZExtValue();
+}
+
+/// Returns an integer attribute representing the length of a memset intrinsic
+template <class MemsetIntr>
+IntegerAttr createMemsetLenAttr(MemsetIntr op) {
+ IntegerAttr memsetLenAttr;
+ bool successfulMatch =
+ matchPattern(op.getLen(), m_Constant<IntegerAttr>(&memsetLenAttr));
+ (void)successfulMatch;
+ assert(successfulMatch);
+ return memsetLenAttr;
+}
+
+/// Returns an integer attribute representing the length of a memset intrinsic
+/// Because MemsetInlineOp has its length encoded as an attribute, this requires
+/// specialized handling.
+template <>
+IntegerAttr createMemsetLenAttr(LLVM::MemsetInlineOp op) {
+ return op.getLenAttr();
+}
+
+/// Template function to create memset intrinsic
+template <class MemsetIntr>
+void createMemsetIntr(OpBuilder &builder, MemsetIntr toReplace,
+ IntegerAttr memsetLenAttr, uint64_t newMemsetSize,
+ DenseMap<Attribute, MemorySlot> &subslots,
+ Attribute index);
+
+/// Create memset intrinsic
+/// This is specialized for MemsetOp
+template <>
+void createMemsetIntr(OpBuilder &builder, LLVM::MemsetOp toReplace,
+ IntegerAttr memsetLenAttr, uint64_t newMemsetSize,
+ DenseMap<Attribute, MemorySlot> &subslots,
+ Attribute index) {
+ Value newMemsetSizeValue =
+ builder
+ .create<LLVM::ConstantOp>(
+ toReplace.getLen().getLoc(),
+ IntegerAttr::get(memsetLenAttr.getType(), newMemsetSize))
+ .getResult();
+
+ builder.create<LLVM::MemsetOp>(toReplace.getLoc(), subslots.at(index).ptr,
+ toReplace.getVal(), newMemsetSizeValue,
+ toReplace.getIsVolatile());
+}
+
+/// Create memset intrinsic
+/// This is specialized for MemsetInlineOp
+template <>
+void createMemsetIntr(OpBuilder &builder, LLVM::MemsetInlineOp toReplace,
+ IntegerAttr memsetLenAttr, uint64_t newMemsetSize,
+ DenseMap<Attribute, MemorySlot> &subslots,
+ Attribute index) {
+
----------------
gysit wrote:
```suggestion
```
nit: drop newline
https://github.com/llvm/llvm-project/pull/115711
More information about the Mlir-commits
mailing list