Skip to content

Commit 2342302

Browse files
clementvalkcloudy0717
authored andcommitted
[flang][cuda][NFC] Split allocation related operation conversion from other cuf operations (llvm#169740)
Split AllocOp, FreeOp, AllocateOp and DeallocateOp from other conversion. Patterns are currently added to the base CUFOpConversion when the option is enabled. This split is a pre-requisite to be more flexible where we do the allocation related operations conversion in the pipeline.
1 parent ea1a38d commit 2342302

File tree

5 files changed

+524
-375
lines changed

5 files changed

+524
-375
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===------- CUFAllocationConversion.h --------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_CUDA_CUFALLOCATIONCONVERSION_H_
10+
#define FORTRAN_OPTIMIZER_TRANSFORMS_CUDA_CUFALLOCATIONCONVERSION_H_
11+
12+
#include "mlir/Pass/Pass.h"
13+
#include "mlir/Pass/PassRegistry.h"
14+
15+
namespace fir {
16+
class LLVMTypeConverter;
17+
}
18+
19+
namespace mlir {
20+
class DataLayout;
21+
class SymbolTable;
22+
} // namespace mlir
23+
24+
namespace cuf {
25+
26+
/// Patterns that convert CUF operations to runtime calls.
27+
void populateCUFAllocationConversionPatterns(
28+
const fir::LLVMTypeConverter &converter, mlir::DataLayout &dl,
29+
const mlir::SymbolTable &symtab, mlir::RewritePatternSet &patterns);
30+
31+
} // namespace cuf
32+
33+
#endif // FORTRAN_OPTIMIZER_TRANSFORMS_CUDA_CUFALLOCATIONCONVERSION_H_

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,19 @@ def AssumedRankOpConversion : Pass<"fir-assumed-rank-op", "mlir::ModuleOp"> {
470470
];
471471
}
472472

473+
def CUFAllocationConversion : Pass<"cuf-allocation-convert", "mlir::ModuleOp"> {
474+
let summary = "Convert allocation related CUF operations to runtime calls";
475+
let dependentDialects = ["fir::FIROpsDialect"];
476+
}
477+
473478
def CUFOpConversion : Pass<"cuf-convert", "mlir::ModuleOp"> {
474479
let summary = "Convert some CUF operations to runtime calls";
475480
let dependentDialects = [
476481
"fir::FIROpsDialect", "mlir::gpu::GPUDialect", "mlir::DLTIDialect"
477482
];
483+
let options = [Option<"allocationConversion", "allocation-conversion", "bool",
484+
/*default=*/"true",
485+
"Convert allocation related operation with this pass">];
478486
}
479487

480488
def CUFDeviceGlobal :

flang/lib/Optimizer/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_flang_library(FIRTransforms
99
CompilerGeneratedNames.cpp
1010
ConstantArgumentGlobalisation.cpp
1111
ControlFlowConverter.cpp
12+
CUDA/CUFAllocationConversion.cpp
1213
CUFAddConstructor.cpp
1314
CUFDeviceGlobal.cpp
1415
CUFOpConversion.cpp

0 commit comments

Comments
 (0)