Skip to content

[mlir][Affine] Handle null parent op in getAffineParallelInductionVarOwner #142025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Affine/IR/AffineOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,7 @@ AffineParallelOp mlir::affine::getAffineParallelInductionVarOwner(Value val) {
if (!ivArg || !ivArg.getOwner())
return nullptr;
Operation *containingOp = ivArg.getOwner()->getParentOp();
auto parallelOp = dyn_cast<AffineParallelOp>(containingOp);
auto parallelOp = dyn_cast_if_present<AffineParallelOp>(containingOp);
if (parallelOp && llvm::is_contained(parallelOp.getIVs(), val))
return parallelOp;
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: mlir-opt -test-memref-to-llvm-with-transforms %s | FileCheck %s

// Checks that the program does not crash. The functionality of the pattern is
// already checked in test/Dialect/MemRef/*.mlir

func.func @subview_folder(%arg0: memref<100x100xf32>, %arg1: index, %arg2: index, %arg3: index, %arg4: index) -> memref<?x?xf32, strided<[100, 1], offset: ?>> {
%subview = memref.subview %arg0[%arg1, %arg2] [%arg3, %arg4] [1, 1] : memref<100x100xf32> to memref<?x?xf32, strided<[100, 1], offset: ?>>
return %subview : memref<?x?xf32, strided<[100, 1], offset: ?>>
}
// CHECK-LABEL: llvm.func @subview_folder
1 change: 1 addition & 0 deletions mlir/test/lib/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(ConvertToSPIRV)
add_subdirectory(FuncToLLVM)
add_subdirectory(MathToVCIX)
add_subdirectory(MemRefToLLVM)
add_subdirectory(VectorToSPIRV)
21 changes: 21 additions & 0 deletions mlir/test/lib/Conversion/MemRefToLLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Exclude tests from libMLIR.so
add_mlir_library(MLIRTestMemRefToLLVMWithTransforms
TestMemRefToLLVMWithTransforms.cpp

EXCLUDE_FROM_LIBMLIR

LINK_LIBS PUBLIC
MLIRTestDialect
)
mlir_target_link_libraries(MLIRTestFuncToLLVM PUBLIC
MLIRLLVMCommonConversion
MLIRLLVMDialect
MLIRMemRefTransforms
MLIRPass
)

target_include_directories(MLIRTestFuncToLLVM
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../Dialect/Test
${CMAKE_CURRENT_BINARY_DIR}/../../Dialect/Test
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//===- TestMemRefToLLVMWithTransforms.cpp ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
#include "mlir/Conversion/LLVMCommon/LoweringOptions.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/MemRef/Transforms/Transforms.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass/Pass.h"

using namespace mlir;

namespace {

struct TestMemRefToLLVMWithTransforms
: public PassWrapper<TestMemRefToLLVMWithTransforms,
OperationPass<ModuleOp>> {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMemRefToLLVMWithTransforms)

void getDependentDialects(DialectRegistry &registry) const final {
registry.insert<LLVM::LLVMDialect>();
}

StringRef getArgument() const final {
return "test-memref-to-llvm-with-transforms";
}

StringRef getDescription() const final {
return "Tests conversion of MemRef dialects + `func.func` to LLVM dialect "
"with MemRef transforms.";
}

void runOnOperation() override {
MLIRContext *ctx = &getContext();
LowerToLLVMOptions options(ctx);
LLVMTypeConverter typeConverter(ctx, options);
RewritePatternSet patterns(ctx);
memref::populateExpandStridedMetadataPatterns(patterns);
populateFuncToLLVMConversionPatterns(typeConverter, patterns);
LLVMConversionTarget target(getContext());
if (failed(applyPartialConversion(getOperation(), target,
std::move(patterns))))
signalPassFailure();
}
};

} // namespace

namespace mlir::test {
void registerTestMemRefToLLVMWithTransforms() {
PassRegistration<TestMemRefToLLVMWithTransforms>();
}
} // namespace mlir::test
1 change: 1 addition & 0 deletions mlir/tools/mlir-opt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ if(MLIR_INCLUDE_TESTS)
MLIRMathTestPasses
MLIRTestMathToVCIX
MLIRMemRefTestPasses
MLIRTestMemRefToLLVMWithTransforms
MLIRMeshTest
MLIRNVGPUTestPasses
MLIRSCFTestPasses
Expand Down
2 changes: 2 additions & 0 deletions mlir/tools/mlir-opt/mlir-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void registerTestMathToVCIXPass();
void registerTestIrdlTestDialectConversionPass();
void registerTestMemRefDependenceCheck();
void registerTestMemRefStrideCalculation();
void registerTestMemRefToLLVMWithTransforms();
void registerTestMeshReshardingSpmdizationPass();
void registerTestMeshSimplificationsPass();
void registerTestMultiBuffering();
Expand Down Expand Up @@ -277,6 +278,7 @@ void registerTestPasses() {
mlir::test::registerTestMathToVCIXPass();
mlir::test::registerTestMemRefDependenceCheck();
mlir::test::registerTestMemRefStrideCalculation();
mlir::test::registerTestMemRefToLLVMWithTransforms();
mlir::test::registerTestMeshReshardingSpmdizationPass();
mlir::test::registerTestMeshSimplificationsPass();
mlir::test::registerTestMultiBuffering();
Expand Down
Loading