[Mlir-commits] [mlir] b1e3989 - [MLIR][SPIRVToLLVM] Support of volatile/nontemporal memory access in load/store
George Mitenkov
llvmlistbot at llvm.org
Tue Jul 28 22:46:35 PDT 2020
Author: George Mitenkov
Date: 2020-07-29T08:45:40+03:00
New Revision: b1e398920f7372db3ebfeeb219d4538d235c7efb
URL: https://github.com/llvm/llvm-project/commit/b1e398920f7372db3ebfeeb219d4538d235c7efb
DIFF: https://github.com/llvm/llvm-project/commit/b1e398920f7372db3ebfeeb219d4538d235c7efb.diff
LOG: [MLIR][SPIRVToLLVM] Support of volatile/nontemporal memory access in load/store
This patch adds support of Volatile and Nontemporal
memory accesses to `spv.Load` and `spv.Store`. These attributes are
modelled with a `volatile` and `nontemporal` flags.
Reviewed By: antiagainst
Differential Revision: https://reviews.llvm.org/D84739
Added:
Modified:
mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
mlir/test/Conversion/SPIRVToLLVM/memory-ops-to-llvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
index 12aa6573ef37..161fda0fc353 100644
--- a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
+++ b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
@@ -189,18 +189,20 @@ static Value createI32ConstantOf(Location loc, PatternRewriter &rewriter,
static LogicalResult replaceWithLoadOrStore(Operation *op,
ConversionPatternRewriter &rewriter,
LLVMTypeConverter &typeConverter,
- unsigned alignment) {
+ unsigned alignment, bool isVolatile,
+ bool isNonTemporal) {
if (auto loadOp = dyn_cast<spirv::LoadOp>(op)) {
auto dstType = typeConverter.convertType(loadOp.getType());
if (!dstType)
return failure();
- rewriter.replaceOpWithNewOp<LLVM::LoadOp>(loadOp, dstType, loadOp.ptr(),
- alignment);
+ rewriter.replaceOpWithNewOp<LLVM::LoadOp>(
+ loadOp, dstType, loadOp.ptr(), alignment, isVolatile, isNonTemporal);
return success();
}
auto storeOp = cast<spirv::StoreOp>(op);
rewriter.replaceOpWithNewOp<LLVM::StoreOp>(storeOp, storeOp.value(),
- storeOp.ptr(), alignment);
+ storeOp.ptr(), alignment,
+ isVolatile, isNonTemporal);
return success();
}
@@ -594,19 +596,31 @@ class LoadStorePattern : public SPIRVToLLVMConversion<SPIRVop> {
LogicalResult
matchAndRewrite(SPIRVop op, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const override {
- if (op.memory_access().hasValue() &&
- op.memory_access().getValue() != spirv::MemoryAccess::None) {
- auto memoryAccess = op.memory_access().getValue();
- if (memoryAccess == spirv::MemoryAccess::Aligned) {
- unsigned alignment = op.alignment().getValue().getZExtValue();
- replaceWithLoadOrStore(op, rewriter, this->typeConverter, alignment);
- return success();
- }
+
+ if (!op.memory_access().hasValue()) {
+ replaceWithLoadOrStore(op, rewriter, this->typeConverter, /*alignment=*/0,
+ /*isVolatile=*/false, /*isNonTemporal=*/ false);
+ return success();
+ }
+ auto memoryAccess = op.memory_access().getValue();
+ switch (memoryAccess) {
+ case spirv::MemoryAccess::Aligned:
+ case spirv::MemoryAccess::None:
+ case spirv::MemoryAccess::Nontemporal:
+ case spirv::MemoryAccess::Volatile: {
+ unsigned alignment = memoryAccess == spirv::MemoryAccess::Aligned
+ ? op.alignment().getValue().getZExtValue()
+ : 0;
+ bool isNonTemporal = memoryAccess == spirv::MemoryAccess::Nontemporal;
+ bool isVolatile = memoryAccess == spirv::MemoryAccess::Volatile;
+ replaceWithLoadOrStore(op, rewriter, this->typeConverter, alignment,
+ isVolatile, isNonTemporal);
+ return success();
+ }
+ default:
// There is no support of other memory access attributes.
return failure();
}
- replaceWithLoadOrStore(op, rewriter, this->typeConverter, 0);
- return success();
}
};
diff --git a/mlir/test/Conversion/SPIRVToLLVM/memory-ops-to-llvm.mlir b/mlir/test/Conversion/SPIRVToLLVM/memory-ops-to-llvm.mlir
index 362c702e8d3c..f717948f8069 100644
--- a/mlir/test/Conversion/SPIRVToLLVM/memory-ops-to-llvm.mlir
+++ b/mlir/test/Conversion/SPIRVToLLVM/memory-ops-to-llvm.mlir
@@ -25,6 +25,20 @@ func @load_with_alignment() {
return
}
+func @load_volatile() {
+ %0 = spv.Variable : !spv.ptr<f32, Function>
+ // CHECK: %{{.*}} = llvm.load volatile %{{.*}} : !llvm<"float*">
+ %1 = spv.Load "Function" %0 ["Volatile"] : f32
+ return
+}
+
+func @load_nontemporal() {
+ %0 = spv.Variable : !spv.ptr<f32, Function>
+ // CHECK: %{{.*}} = llvm.load %{{.*}} {nontemporal} : !llvm<"float*">
+ %1 = spv.Load "Function" %0 ["Nontemporal"] : f32
+ return
+}
+
//===----------------------------------------------------------------------===//
// spv.Store
//===----------------------------------------------------------------------===//
@@ -50,6 +64,20 @@ func @store_with_alignment(%arg0 : f32) -> () {
return
}
+func @store_volatile(%arg0 : f32) -> () {
+ %0 = spv.Variable : !spv.ptr<f32, Function>
+ // CHECK: llvm.store volatile %{{.*}}, %{{.*}} : !llvm<"float*">
+ spv.Store "Function" %0, %arg0 ["Volatile"] : f32
+ return
+}
+
+func @store_nontemporal(%arg0 : f32) -> () {
+ %0 = spv.Variable : !spv.ptr<f32, Function>
+ // CHECK: llvm.store %{{.*}}, %{{.*}} {nontemporal} : !llvm<"float*">
+ spv.Store "Function" %0, %arg0 ["Nontemporal"] : f32
+ return
+}
+
//===----------------------------------------------------------------------===//
// spv.Variable
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list