[Mlir-commits] [mlir] [mlir][spirv] Use `AttrTypeReplacer` in map-memref-storage-class. NFC. (PR #80055)
Lei Zhang
llvmlistbot at llvm.org
Tue Jan 30 13:47:53 PST 2024
================
@@ -335,23 +287,25 @@ class MapMemRefStorageClassPass final
MLIRContext *context = &getContext();
Operation *op = getOperation();
+ spirv::MemorySpaceToStorageClassMap spaceToStorage = memorySpaceMap;
if (spirv::TargetEnvAttr attr = spirv::lookupTargetEnv(op)) {
spirv::TargetEnv targetEnv(attr);
if (targetEnv.allows(spirv::Capability::Kernel)) {
- memorySpaceMap = spirv::mapMemorySpaceToOpenCLStorageClass;
+ spaceToStorage = spirv::mapMemorySpaceToOpenCLStorageClass;
} else if (targetEnv.allows(spirv::Capability::Shader)) {
- memorySpaceMap = spirv::mapMemorySpaceToVulkanStorageClass;
+ spaceToStorage = spirv::mapMemorySpaceToVulkanStorageClass;
}
}
- std::unique_ptr<ConversionTarget> target =
- spirv::getMemorySpaceToStorageClassTarget(*context);
- spirv::MemorySpaceToStorageClassConverter converter(memorySpaceMap);
-
- RewritePatternSet patterns(context);
- spirv::populateMemorySpaceToStorageClassPatterns(converter, patterns);
+ spirv::MemorySpaceToStorageClassConverter converter(spaceToStorage);
+ // Perform the replacement.
+ spirv::convertMemRefTypesAndAttrs(op, converter);
- if (failed(applyFullConversion(op, *target, std::move(patterns))))
+ // Only perform the conversion to check that there are no illegal ops
+ // remaining. Do not attempt to convert anything.
+ if (failed(applyFullConversion(
+ op, *spirv::getMemorySpaceToStorageClassTarget(*context),
+ RewritePatternSet{context})))
----------------
antiagainst wrote:
Yeah an explicit walk looks better to me--it's simpler and clearer so easy to understand. also we avoid the overhead of conversion framework.
https://github.com/llvm/llvm-project/pull/80055
More information about the Mlir-commits
mailing list