Skip to content

Commit 7e8b3fe

Browse files
authored
[Flang] Add missing dependent dialects to MLIR passes (#139260)
This patch updates several passes to include the DLTI dialect, since their use of the `fir::support::getOrSetMLIRDataLayout()` utility function could, in some cases, require this dialect to be loaded in advance. Also, the `CUFComputeSharedMemoryOffsetsAndSize` pass has been updated with a dependency to the GPU dialect, as its invocation to `cuf::getOrCreateGPUModule()` would result in the same kind of error if no other operations or attributes from that dialect were present in the input MLIR module.
1 parent bbb7f01 commit 7e8b3fe

File tree

7 files changed

+34
-5
lines changed

7 files changed

+34
-5
lines changed

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def LoopVersioning : Pass<"loop-versioning", "mlir::func::FuncOp"> {
356356
an array has element sized stride. The element sizes stride allows some
357357
loops to be vectorized as well as other loop optimizations.
358358
}];
359-
let dependentDialects = [ "fir::FIROpsDialect" ];
359+
let dependentDialects = [ "fir::FIROpsDialect", "mlir::DLTIDialect" ];
360360
}
361361

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

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

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

@@ -472,7 +472,10 @@ def CUFComputeSharedMemoryOffsetsAndSize
472472
the global and set it.
473473
}];
474474

475-
let dependentDialects = ["cuf::CUFDialect", "fir::FIROpsDialect"];
475+
let dependentDialects = [
476+
"cuf::CUFDialect", "fir::FIROpsDialect", "mlir::gpu::GPUDialect",
477+
"mlir::DLTIDialect"
478+
];
476479
}
477480

478481
def SetRuntimeCallAttributes

flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "flang/Optimizer/Support/DataLayout.h"
2323
#include "flang/Runtime/CUDA/registration.h"
2424
#include "flang/Runtime/entry-names.h"
25+
#include "mlir/Dialect/DLTI/DLTI.h"
2526
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
2627
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
2728
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"

flang/lib/Optimizer/Transforms/CUFComputeSharedMemoryOffsetsAndSize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "flang/Optimizer/Support/DataLayout.h"
2323
#include "flang/Runtime/CUDA/registration.h"
2424
#include "flang/Runtime/entry-names.h"
25+
#include "mlir/Dialect/DLTI/DLTI.h"
2526
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
2627
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
2728
#include "mlir/IR/Value.h"

flang/lib/Optimizer/Transforms/CUFGPUToLLVMConversion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "flang/Runtime/CUDA/common.h"
1515
#include "flang/Support/Fortran.h"
1616
#include "mlir/Conversion/LLVMCommon/Pattern.h"
17+
#include "mlir/Dialect/DLTI/DLTI.h"
1718
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
1819
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
1920
#include "mlir/Pass/Pass.h"

flang/lib/Optimizer/Transforms/CUFOpConversion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "flang/Runtime/allocatable.h"
2525
#include "flang/Support/Fortran.h"
2626
#include "mlir/Conversion/LLVMCommon/Pattern.h"
27+
#include "mlir/Dialect/DLTI/DLTI.h"
2728
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
2829
#include "mlir/IR/Matchers.h"
2930
#include "mlir/Pass/Pass.h"

flang/lib/Optimizer/Transforms/LoopVersioning.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "flang/Optimizer/Dialect/Support/KindMapping.h"
5252
#include "flang/Optimizer/Support/DataLayout.h"
5353
#include "flang/Optimizer/Transforms/Passes.h"
54+
#include "mlir/Dialect/DLTI/DLTI.h"
5455
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
5556
#include "mlir/IR/Dominance.h"
5657
#include "mlir/IR/Matchers.h"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This test only makes sure that passes with a DLTI dialect dependency are able
2+
// to obtain the dlti.dl_spec module attribute from an llvm.data_layout string.
3+
//
4+
// If dependencies for the pass are not properly set, this test causes a
5+
// compiler error due to the DLTI dialect not being loaded.
6+
7+
// RUN: fir-opt --add-debug-info %s
8+
// RUN: fir-opt --cuf-add-constructor %s
9+
// RUN: fir-opt --cuf-compute-shared-memory %s
10+
// RUN: fir-opt --cuf-gpu-convert-to-llvm %s
11+
// RUN: fir-opt --cuf-convert %s
12+
// RUN: fir-opt --loop-versioning %s
13+
14+
module attributes {llvm.data_layout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"} {
15+
llvm.func @foo(%arg0 : i32) {
16+
llvm.return
17+
}
18+
}
19+
20+
// CHECK: module attributes {
21+
// CHECK-SAME: dlti.dl_spec = #dlti.dl_spec<

0 commit comments

Comments
 (0)