Skip to content

Commit

Permalink
Integrate LLVM at 73f11ac (#19941)
Browse files Browse the repository at this point in the history
We had previously cherry-picked
llvm/llvm-project@73f11ac
in #19939.

Now we're integrating up to that commit, so it's no longer a
cherry-pick.

Reverting llvm/llvm-project#125789 because it
breaks TorchToTosa, in torch-mlir. We will need to wait for this to be
resolved in torch-mlir, then simultaneously bump torch-mlir and drop the
revert.

Chery-pick a Bazel fix:
llvm/llvm-project@4df287a

---------

Signed-off-by: Benoit Jacob <[email protected]>
  • Loading branch information
bjacob authored Feb 10, 2025
1 parent 0781072 commit e4c683f
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 17 deletions.
2 changes: 2 additions & 0 deletions compiler/src/iree/compiler/Codegen/LLVMCPU/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ iree_compiler_cc_library(
"@llvm-project//mlir:TransformDialect",
"@llvm-project//mlir:TransformUtils",
"@llvm-project//mlir:Transforms",
"@llvm-project//mlir:UBDialect",
"@llvm-project//mlir:UBToLLVM",
"@llvm-project//mlir:ValueBoundsOpInterface",
"@llvm-project//mlir:VectorDialect",
"@llvm-project//mlir:VectorToArmSME",
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/iree/compiler/Codegen/LLVMCPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ iree_cc_library(
MLIRTransformDialect
MLIRTransformUtils
MLIRTransforms
MLIRUBDialect
MLIRUBToLLVM
MLIRValueBoundsOpInterface
MLIRVectorDialect
MLIRVectorToArmSME
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/iree/compiler/Codegen/LLVMCPU/ConvertToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h"
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
#include "mlir/Conversion/TosaToArith/TosaToArith.h"
#include "mlir/Conversion/UBToLLVM/UBToLLVM.h"
#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
#include "mlir/Conversion/VectorToSCF/VectorToSCF.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
Expand Down Expand Up @@ -1058,9 +1059,9 @@ void ConvertToLLVMPass::runOnOperation() {
vector::populateVectorStepLoweringPatterns(patterns);
populateVectorToLLVMConversionPatterns(typeConverter, patterns,
reassociateFpReductions);
ub::populateUBToLLVMConversionPatterns(typeConverter, patterns);
vector::populateVectorTransferLoweringPatterns(patterns,
/*maxTransferRank=*/1);

if (isAArch64(targetAttr) &&
(hasAnySVEFeature(targetAttr) || hasSMEFeature(targetAttr))) {
populateArmSVELegalizeForLLVMExportPatterns(typeConverter, patterns);
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/iree/compiler/Codegen/LLVMGPU/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ iree_compiler_cc_library(
"@llvm-project//mlir:TransformDialect",
"@llvm-project//mlir:TransformUtils",
"@llvm-project//mlir:Transforms",
"@llvm-project//mlir:UBDialect",
"@llvm-project//mlir:UBToLLVM",
"@llvm-project//mlir:ValueBoundsOpInterface",
"@llvm-project//mlir:VectorDialect",
"@llvm-project//mlir:VectorToGPU",
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/iree/compiler/Codegen/LLVMGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ iree_cc_library(
MLIRTransformDialect
MLIRTransformUtils
MLIRTransforms
MLIRUBDialect
MLIRUBToLLVM
MLIRValueBoundsOpInterface
MLIRVectorDialect
MLIRVectorToGPU
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/iree/compiler/Codegen/LLVMGPU/ConvertToNVVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
#include "mlir/Conversion/NVGPUToNVVM/NVGPUToNVVM.h"
#include "mlir/Conversion/NVVMToLLVM/NVVMToLLVM.h"
#include "mlir/Conversion/UBToLLVM/UBToLLVM.h"
#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arith/Transforms/Passes.h"
#include "mlir/Dialect/GPU/Transforms/Passes.h"
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
#include "mlir/Dialect/MemRef/Transforms/Transforms.h"
#include "mlir/Dialect/NVGPU/IR/NVGPUDialect.h"
#include "mlir/Dialect/UB/IR/UBOps.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/Dialect/Vector/Transforms/LoweringPatterns.h"
#include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
Expand All @@ -53,7 +55,7 @@ struct ConvertToNVVMPass final
void getDependentDialects(DialectRegistry &registry) const override {
registry
.insert<gpu::GPUDialect, IREE::GPU::IREEGPUDialect, LLVM::LLVMDialect,
NVVM::NVVMDialect, affine::AffineDialect>();
NVVM::NVVMDialect, affine::AffineDialect, ub::UBDialect>();
}
void runOnOperation() override {
ModuleOp m = getOperation();
Expand Down Expand Up @@ -161,6 +163,7 @@ struct ConvertToNVVMPass final
populateGpuToNVVMConversionPatterns(converter, llvmPatterns);
populateNVGPUToNVVMConversionPatterns(converter, llvmPatterns);
populateGpuWMMAToNVVMConversionPatterns(converter, llvmPatterns);
ub::populateUBToLLVMConversionPatterns(converter, llvmPatterns);

/// Target specification.
LLVMConversionTarget target(getContext());
Expand Down
10 changes: 7 additions & 3 deletions compiler/src/iree/compiler/Codegen/LLVMGPU/ConvertToROCDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
#include "mlir/Conversion/UBToLLVM/UBToLLVM.h"
#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
#include "mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h"
#include "mlir/Dialect/Arith/Transforms/Passes.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/GPU/Transforms/Passes.h"
#include "mlir/Dialect/LLVMIR/ROCDLDialect.h"
#include "mlir/Dialect/MemRef/Transforms/Transforms.h"
#include "mlir/Dialect/UB/IR/UBOps.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/Dialect/Vector/Transforms/LoweringPatterns.h"
#include "mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h"
Expand Down Expand Up @@ -99,9 +101,9 @@ struct ConvertToROCDLPass final
ConvertToROCDLPass>::ConvertToROCDLPassBase;

void getDependentDialects(DialectRegistry &registry) const override {
registry
.insert<IREE::GPU::IREEGPUDialect, LLVM::LLVMDialect,
ROCDL::ROCDLDialect, amdgpu::AMDGPUDialect, gpu::GPUDialect>();
registry.insert<IREE::GPU::IREEGPUDialect, LLVM::LLVMDialect,
ROCDL::ROCDLDialect, amdgpu::AMDGPUDialect, gpu::GPUDialect,
ub::UBDialect>();
}
void runOnOperation() override {
ModuleOp m = getOperation();
Expand Down Expand Up @@ -238,6 +240,8 @@ struct ConvertToROCDLPass final
LLVMConversionTarget target(getContext());
populateFuncToLLVMFuncOpConversionPattern(converter, llvmPatterns);
configureGpuToROCDLConversionLegality(target);
ub::populateUBToLLVMConversionPatterns(converter, llvmPatterns);

if (failed(applyPartialConversion(m, target, std::move(llvmPatterns))))
signalPassFailure();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-llvmgpu-vector-lowering))" --split-input-file %s | FileCheck %s
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-llvmgpu-vector-lowering,canonicalize,cse))" --split-input-file %s | FileCheck %s

module {
func.func @broadcast_read_lowering(%arg0: memref<4096x32xf16>) -> vector<1x8xf16> {
Expand All @@ -11,9 +11,8 @@ module {
}
// CHECK-LABEL: func.func @broadcast_read_lowering
// CHECK-SAME: (%[[ARG0:.+]]: memref<4096x32xf16>)
// CHECK: %[[INIT:.+]] = arith.constant dense<0.000000e+00> : vector<1x8xf16>
// CHECK: %[[LOAD:.+]] = vector.load %[[ARG0]]{{.*}} : memref<4096x32xf16>
// CHECK: %[[ELEM:.+]] = vector.extract %[[LOAD]][0] : f16 from vector<1xf16>
// CHECK: %[[SPLAT:.+]] = vector.splat %[[ELEM]] : vector<8xf16>
// CHECK: %[[INSERT:.+]] = vector.insert %[[SPLAT]], %[[INIT]] [0] : vector<8xf16> into vector<1x8xf16>
// CHECK: %[[INSERT:.+]] = vector.broadcast %[[SPLAT]] : vector<8xf16> to vector<1x8xf16>
// CHECK: return %[[INSERT]]
1 change: 1 addition & 0 deletions compiler/src/iree/compiler/Codegen/SPIRV/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ iree_compiler_cc_library(
"@llvm-project//mlir:TransformDialect",
"@llvm-project//mlir:TransformUtils",
"@llvm-project//mlir:Transforms",
"@llvm-project//mlir:UBToSPIRV",
"@llvm-project//mlir:VectorDialect",
"@llvm-project//mlir:VectorInterfaces",
"@llvm-project//mlir:VectorToGPU",
Expand Down
1 change: 1 addition & 0 deletions compiler/src/iree/compiler/Codegen/SPIRV/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ iree_cc_library(
MLIRTransformDialect
MLIRTransformUtils
MLIRTransforms
MLIRUBToSPIRV
MLIRVectorDialect
MLIRVectorInterfaces
MLIRVectorToGPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
#include "mlir/Conversion/SCFToSPIRV/SCFToSPIRV.h"
#include "mlir/Conversion/TensorToSPIRV/TensorToSPIRV.h"
#include "mlir/Conversion/UBToSPIRV/UBToSPIRV.h"
#include "mlir/Conversion/VectorToSPIRV/VectorToSPIRV.h"
#include "mlir/Dialect/Arith/Transforms/Passes.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
Expand Down Expand Up @@ -656,6 +657,8 @@ void ConvertToSPIRVPass::runOnOperation() {
// Pull in builtin func to spirv.func conversion.
populateBuiltinFuncToSPIRVPatterns(typeConverter, patterns);

ub::populateUBToSPIRVConversionPatterns(typeConverter, patterns);

// Add IREE HAL interface op conversions.
patterns.add<
HALInterfaceLoadConstantConverter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: iree-opt --split-input-file \
// RUN: --pass-pipeline='builtin.module(func.func(iree-codegen-generic-vectorization,iree-spirv-initial-vector-lowering,iree-codegen-optimize-tensor-insert-extract-slices,iree-spirv-final-vector-lowering))' \
// RUN: --pass-pipeline='builtin.module(func.func(iree-codegen-generic-vectorization,iree-spirv-initial-vector-lowering,iree-codegen-optimize-tensor-insert-extract-slices,iree-spirv-final-vector-lowering,canonicalize,cse))' \
// RUN: %s | FileCheck %s

func.func @add(%lhs: tensor<2x8xf32>, %rhs: tensor<2x8xf32>) -> tensor<2x8xf32> {
Expand Down Expand Up @@ -48,7 +48,7 @@ func.func @transpose_leading_one_dim(%input: tensor<4x1x1xf32>) -> tensor<1x1x4x
// CHECK-DAG: %[[C1:.+]] = arith.constant 1 : index
// CHECK-DAG: %[[C2:.+]] = arith.constant 2 : index
// CHECK-DAG: %[[C3:.+]] = arith.constant 3 : index
// CHECK-DAG: %[[ZERO:.+]] = arith.constant dense<0.000000e+00> : vector<4xf32>
// CHECK-DAG: %[[ZERO:.+]] = ub.poison : vector<4xf32>

// CHECK: %[[R0:.+]] = vector.transfer_read %[[INPUT]][%[[C0]], %[[C0]], %[[C0]]]{{.+}} : tensor<4x1x1xf32>, vector<1xf32>
// CHECK: %[[R1:.+]] = vector.transfer_read %[[INPUT]][%[[C1]], %[[C0]], %[[C0]]]{{.+}} : tensor<4x1x1xf32>, vector<1xf32>
Expand Down Expand Up @@ -93,7 +93,7 @@ func.func @transpose_add(%lhs: tensor<4x2xf32>, %rhs: tensor<2xf32>) -> tensor<2
// CHECK-DAG: %[[C2:.+]] = arith.constant 2 : index
// CHECK-DAG: %[[C3:.+]] = arith.constant 3 : index

// CHECK-DAG: %[[OINIT:.+]] = arith.constant dense<0.000000e+00> : vector<4xf32>
// CHECK-DAG: %[[OINIT:.+]] = ub.poison : vector<4xf32>

// CHECK: %[[LHS0:.+]] = vector.transfer_read %[[LHS]][%[[C0]], %[[C0]]]{{.+}} : tensor<4x2xf32>, vector<2xf32>
// CHECK: %[[LHS1:.+]] = vector.transfer_read %[[LHS]][%[[C1]], %[[C0]]]{{.+}} : tensor<4x2xf32>, vector<2xf32>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: iree-opt --split-input-file \
// RUN: --pass-pipeline='builtin.module(func.func(iree-codegen-generic-vectorization,iree-spirv-initial-vector-lowering,iree-codegen-optimize-tensor-insert-extract-slices,iree-spirv-final-vector-lowering))' \
// RUN: --pass-pipeline='builtin.module(func.func(iree-codegen-generic-vectorization,iree-spirv-initial-vector-lowering,iree-codegen-optimize-tensor-insert-extract-slices,iree-spirv-final-vector-lowering,canonicalize,cse))' \
// RUN: %s | FileCheck %s

func.func @matmul_1x4x4(%lhs: tensor<1x4xf32>, %rhs: tensor<4x4xf32>, %init: tensor<1x4xf32>) -> tensor<1x4xf32> {
Expand Down Expand Up @@ -139,9 +139,7 @@ func.func @matmul_broadcast_add(%init: tensor<1x8xf32>, %a: tensor<1x8xf32>, %b:
// CHECK: %[[EXT0:.+]] = vector.extract %[[READ]][0] : f32 from vector<1xf32>
// CHECK: %[[BCST0:.+]] = vector.splat %[[EXT0]] : vector<4xf32>
// CHECK: %[[ADD0:.+]] = arith.addf %{{.+}}, %[[BCST0]] : vector<4xf32>
// CHECK: %[[EXT1:.+]] = vector.extract %[[READ]][0] : f32 from vector<1xf32>
// CHECK: %[[BCST1:.+]] = vector.splat %[[EXT1]] : vector<4xf32>
// CHECK: %[[ADD1:.+]] = arith.addf %{{.+}}, %[[BCST1]] : vector<4xf32>
// CHECK: %[[ADD1:.+]] = arith.addf %{{.+}}, %[[BCST0]] : vector<4xf32>
// CHECK: %[[WRITE0:.+]] = vector.transfer_write %[[ADD0]], %[[INIT]][%[[C0]], %[[C0]]]
// CHECK: %[[WRITE1:.+]] = vector.transfer_write %[[ADD1]], %[[WRITE0]][%[[C0]], %[[C4]]]
// CHECK: return %[[WRITE1]]
Expand Down Expand Up @@ -287,7 +285,7 @@ func.func @matmul_4x4x4_i8_to_i32_dot_prod(%lhs: tensor<4x4xi8>, %rhs : tensor<4
// CHECK-SAME: (%[[LHS:.+]]: tensor<4x4xi8>, %[[RHS:.+]]: tensor<4x4xi8>)
// CHECK-DAG: %[[C0I8:.+]] = arith.constant 0 : i8
// CHECK-DAG: %[[C0I32:.+]] = arith.constant 0 : i32
// CHECK-DAG: %[[V4I8:.+]] = arith.constant dense<0> : vector<4xi8>
// CHECK-DAG: %[[V4I8:.+]] = ub.poison : vector<4xi8>
// CHECK-DAG: %[[V4I32:.+]] = arith.constant dense<0> : vector<4xi32>
// CHECK-DAG: %[[V1I32:.+]] = arith.constant dense<0> : vector<1xi32>
// CHECK-DAG: %[[IDX0:.+]] = arith.constant 0 : index
Expand Down
2 changes: 1 addition & 1 deletion third_party/llvm-project
Submodule llvm-project updated 305 files

0 comments on commit e4c683f

Please sign in to comment.