diff options
author | Andrei Golubev <andrey.golubev@intel.com> | 2024-01-26 15:27:51 +0200 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2024-01-29 10:29:59 -0800 |
commit | 3df71e5a3f5d5fb9436c53c298e5426f729288e2 (patch) | |
tree | ca8ef9690907f95bc1c6f60823ca77b7e4f97d35 /mlir | |
parent | 2c3214135ffa8e3f9ab61d12521637532126f368 (diff) | |
download | llvm-3df71e5a3f5d5fb9436c53c298e5426f729288e2.zip llvm-3df71e5a3f5d5fb9436c53c298e5426f729288e2.tar.gz llvm-3df71e5a3f5d5fb9436c53c298e5426f729288e2.tar.bz2 |
[mlir][LLVM] Use int32_t to indirectly construct GEPArg (#79562)
GEPArg can only be constructed from int32_t and mlir::Value. Explicitly
cast other types (e.g. unsigned, size_t) to int32_t to avoid narrowing
conversion warnings on MSVC. Some recent examples of such are:
```
mlir\lib\Dialect\LLVMIR\Transforms\TypeConsistency.cpp: error C2398:
Element '1': conversion from 'size_t' to 'T' requires a narrowing
conversion
with
[
T=mlir::LLVM::GEPArg
]
mlir\lib\Dialect\LLVMIR\Transforms\TypeConsistency.cpp: error C2398:
Element '1': conversion from 'unsigned int' to 'T' requires a narrowing
conversion
with
[
T=mlir::LLVM::GEPArg
]
```
Co-authored-by: Nikita Kudriavtsev <nikita.kudriavtsev@intel.com>
(cherry picked from commit 89cd345667a5f8f4c37c621fd8abe8d84e85c050)
Diffstat (limited to 'mlir')
-rw-r--r-- | mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp | 3 | ||||
-rw-r--r-- | mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp | 9 | ||||
-rw-r--r-- | mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp | 9 |
3 files changed, 12 insertions, 9 deletions
diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp index ae2bd8e..73d418c 100644 --- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp +++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp @@ -529,7 +529,8 @@ LogicalResult GPUPrintfOpToVPrintfLowering::matchAndRewrite( /*alignment=*/0); for (auto [index, arg] : llvm::enumerate(args)) { Value ptr = rewriter.create<LLVM::GEPOp>( - loc, ptrType, structType, tempAlloc, ArrayRef<LLVM::GEPArg>{0, index}); + loc, ptrType, structType, tempAlloc, + ArrayRef<LLVM::GEPArg>{0, static_cast<int32_t>(index)}); rewriter.create<LLVM::StoreOp>(loc, arg, ptr); } std::array<Value, 2> printfArgs = {stringStart, tempAlloc}; diff --git a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp index f853d5c..78d4e80 100644 --- a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp +++ b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp @@ -1041,13 +1041,14 @@ Value ConvertLaunchFuncOpToGpuRuntimeCallPattern::generateParamsArray( auto arrayPtr = builder.create<LLVM::AllocaOp>( loc, llvmPointerType, llvmPointerType, arraySize, /*alignment=*/0); for (const auto &en : llvm::enumerate(arguments)) { + const auto index = static_cast<int32_t>(en.index()); Value fieldPtr = builder.create<LLVM::GEPOp>(loc, llvmPointerType, structType, structPtr, - ArrayRef<LLVM::GEPArg>{0, en.index()}); + ArrayRef<LLVM::GEPArg>{0, index}); builder.create<LLVM::StoreOp>(loc, en.value(), fieldPtr); - auto elementPtr = builder.create<LLVM::GEPOp>( - loc, llvmPointerType, llvmPointerType, arrayPtr, - ArrayRef<LLVM::GEPArg>{en.index()}); + auto elementPtr = + builder.create<LLVM::GEPOp>(loc, llvmPointerType, llvmPointerType, + arrayPtr, ArrayRef<LLVM::GEPArg>{index}); builder.create<LLVM::StoreOp>(loc, fieldPtr, elementPtr); } return arrayPtr; diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp index 72f9295..b25c831 100644 --- a/mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp +++ b/mlir/lib/Dialect/LLVMIR/Transforms/TypeConsistency.cpp @@ -488,7 +488,8 @@ static void splitVectorStore(const DataLayout &dataLayout, Location loc, // Other patterns will turn this into a type-consistent GEP. auto gepOp = rewriter.create<GEPOp>( loc, address.getType(), rewriter.getI8Type(), address, - ArrayRef<GEPArg>{storeOffset + index * elementSize}); + ArrayRef<GEPArg>{ + static_cast<int32_t>(storeOffset + index * elementSize)}); rewriter.create<StoreOp>(loc, extractOp, gepOp); } @@ -524,9 +525,9 @@ static void splitIntegerStore(const DataLayout &dataLayout, Location loc, // We create an `i8` indexed GEP here as that is the easiest (offset is // already known). Other patterns turn this into a type-consistent GEP. - auto gepOp = - rewriter.create<GEPOp>(loc, address.getType(), rewriter.getI8Type(), - address, ArrayRef<GEPArg>{currentOffset}); + auto gepOp = rewriter.create<GEPOp>( + loc, address.getType(), rewriter.getI8Type(), address, + ArrayRef<GEPArg>{static_cast<int32_t>(currentOffset)}); rewriter.create<StoreOp>(loc, valueToStore, gepOp); // No need to care about padding here since we already checked previously |