Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Flang] Add missing dependent dialects to MLIR passes #139260

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 1 commit into from
May 13, 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
13 changes: 8 additions & 5 deletions flang/include/flang/Optimizer/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def LoopVersioning : Pass<"loop-versioning", "mlir::func::FuncOp"> {
an array has element sized stride. The element sizes stride allows some
loops to be vectorized as well as other loop optimizations.
}];
let dependentDialects = [ "fir::FIROpsDialect" ];
let dependentDialects = [ "fir::FIROpsDialect", "mlir::DLTIDialect" ];
}

def VScaleAttr : Pass<"vscale-attr", "mlir::func::FuncOp"> {
Expand Down Expand Up @@ -436,7 +436,7 @@ def AssumedRankOpConversion : Pass<"fir-assumed-rank-op", "mlir::ModuleOp"> {
def CUFOpConversion : Pass<"cuf-convert", "mlir::ModuleOp"> {
let summary = "Convert some CUF operations to runtime calls";
let dependentDialects = [
"fir::FIROpsDialect", "mlir::gpu::GPUDialect"
"fir::FIROpsDialect", "mlir::gpu::GPUDialect", "mlir::DLTIDialect"
];
}

Expand All @@ -451,14 +451,14 @@ def CUFDeviceGlobal :
def CUFAddConstructor : Pass<"cuf-add-constructor", "mlir::ModuleOp"> {
let summary = "Add constructor to register CUDA Fortran allocators";
let dependentDialects = [
"cuf::CUFDialect", "mlir::func::FuncDialect"
"cuf::CUFDialect", "mlir::func::FuncDialect", "mlir::DLTIDialect"
];
}

def CUFGPUToLLVMConversion : Pass<"cuf-gpu-convert-to-llvm", "mlir::ModuleOp"> {
let summary = "Convert some GPU operations lowered from CUF to runtime calls";
let dependentDialects = [
"mlir::LLVM::LLVMDialect"
"mlir::LLVM::LLVMDialect", "mlir::DLTIDialect"
];
}

Expand All @@ -472,7 +472,10 @@ def CUFComputeSharedMemoryOffsetsAndSize
the global and set it.
}];

let dependentDialects = ["cuf::CUFDialect", "fir::FIROpsDialect"];
let dependentDialects = [
"cuf::CUFDialect", "fir::FIROpsDialect", "mlir::gpu::GPUDialect",
"mlir::DLTIDialect"
];
}

def SetRuntimeCallAttributes
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "flang/Optimizer/Support/DataLayout.h"
#include "flang/Runtime/CUDA/registration.h"
#include "flang/Runtime/entry-names.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "flang/Optimizer/Support/DataLayout.h"
#include "flang/Runtime/CUDA/registration.h"
#include "flang/Runtime/entry-names.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/Value.h"
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "flang/Runtime/CUDA/common.h"
#include "flang/Support/Fortran.h"
#include "mlir/Conversion/LLVMCommon/Pattern.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
#include "mlir/Pass/Pass.h"
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Optimizer/Transforms/CUFOpConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "flang/Runtime/allocatable.h"
#include "flang/Support/Fortran.h"
#include "mlir/Conversion/LLVMCommon/Pattern.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Pass/Pass.h"
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Optimizer/Transforms/LoopVersioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "flang/Optimizer/Dialect/Support/KindMapping.h"
#include "flang/Optimizer/Support/DataLayout.h"
#include "flang/Optimizer/Transforms/Passes.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/Dominance.h"
#include "mlir/IR/Matchers.h"
Expand Down
21 changes: 21 additions & 0 deletions flang/test/Transforms/dlti-dependency.fir
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This test only makes sure that passes with a DLTI dialect dependency are able
// to obtain the dlti.dl_spec module attribute from an llvm.data_layout string.
//
// If dependencies for the pass are not properly set, this test causes a
// compiler error due to the DLTI dialect not being loaded.

// RUN: fir-opt --add-debug-info %s
// RUN: fir-opt --cuf-add-constructor %s
// RUN: fir-opt --cuf-compute-shared-memory %s
// RUN: fir-opt --cuf-gpu-convert-to-llvm %s
// RUN: fir-opt --cuf-convert %s
// RUN: fir-opt --loop-versioning %s

module attributes {llvm.data_layout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"} {
llvm.func @foo(%arg0 : i32) {
llvm.return
}
}

// CHECK: module attributes {
// CHECK-SAME: dlti.dl_spec = #dlti.dl_spec<