Skip to content

Commit 9a0ff45

Browse files
[mlir][IR] Add SingleBlock trait to ModuleOp/GPUModuleOp
The region is already declared as `SizedRegion<1>`, but this will add an additional `getBlock()` convenience function to `ModuleOp`.
1 parent 82e594a commit 9a0ff45

File tree

5 files changed

+13
-20
lines changed

5 files changed

+13
-20
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
478478
return existingPrivatizer;
479479

480480
mlir::OpBuilder::InsertionGuard guard(firOpBuilder);
481-
firOpBuilder.setInsertionPoint(&moduleOp.getBodyRegion().front(),
482-
moduleOp.getBodyRegion().front().begin());
481+
firOpBuilder.setInsertionPointToStart(moduleOp.getBody());
483482
auto result = firOpBuilder.create<mlir::omp::PrivateClauseOp>(
484483
symLoc, uniquePrivatizerName, symType,
485484
isFirstPrivate ? mlir::omp::DataSharingClauseType::FirstPrivate

mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ struct BufferizationToMemRefPass
134134

135135
bufferization::DeallocHelperMap deallocHelperFuncMap;
136136
if (auto module = dyn_cast<ModuleOp>(getOperation())) {
137-
OpBuilder builder =
138-
OpBuilder::atBlockBegin(&module.getBodyRegion().front());
137+
OpBuilder builder = OpBuilder::atBlockBegin(module.getBody());
139138

140139
// Build dealloc helper function if there are deallocs.
141140
getOperation()->walk([&](bufferization::DeallocOp deallocOp) {

mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,10 @@ static IntegerAttr wrapNumericMemorySpace(MLIRContext *ctx, unsigned space) {
642642

643643
/// Generates a symbol with 0-sized array type for dynamic shared memory usage,
644644
/// or uses existing symbol.
645-
LLVM::GlobalOp
646-
getDynamicSharedMemorySymbol(ConversionPatternRewriter &rewriter,
647-
Operation *moduleOp, gpu::DynamicSharedMemoryOp op,
648-
const LLVMTypeConverter *typeConverter,
649-
MemRefType memrefType, unsigned alignmentBit) {
645+
LLVM::GlobalOp getDynamicSharedMemorySymbol(
646+
ConversionPatternRewriter &rewriter, gpu::GPUModuleOp moduleOp,
647+
gpu::DynamicSharedMemoryOp op, const LLVMTypeConverter *typeConverter,
648+
MemRefType memrefType, unsigned alignmentBit) {
650649
uint64_t alignmentByte = alignmentBit / memrefType.getElementTypeBitWidth();
651650

652651
FailureOr<unsigned> addressSpace =
@@ -661,8 +660,7 @@ getDynamicSharedMemorySymbol(ConversionPatternRewriter &rewriter,
661660
// Step 1. Collect symbol names of LLVM::GlobalOp Ops. Also if any of
662661
// LLVM::GlobalOp is suitable for shared memory, return it.
663662
llvm::StringSet<> existingGlobalNames;
664-
for (auto globalOp :
665-
moduleOp->getRegion(0).front().getOps<LLVM::GlobalOp>()) {
663+
for (auto globalOp : moduleOp.getBody()->getOps<LLVM::GlobalOp>()) {
666664
existingGlobalNames.insert(globalOp.getSymName());
667665
if (auto arrayType = dyn_cast<LLVM::LLVMArrayType>(globalOp.getType())) {
668666
if (globalOp.getAddrSpace() == addressSpace.value() &&
@@ -684,7 +682,7 @@ getDynamicSharedMemorySymbol(ConversionPatternRewriter &rewriter,
684682

685683
// Step 3. Generate a global op
686684
OpBuilder::InsertionGuard guard(rewriter);
687-
rewriter.setInsertionPoint(&moduleOp->getRegion(0).front().front());
685+
rewriter.setInsertionPointToStart(moduleOp.getBody());
688686

689687
auto zeroSizedArrayType = LLVM::LLVMArrayType::get(
690688
typeConverter->convertType(memrefType.getElementType()), 0);
@@ -709,10 +707,8 @@ LogicalResult GPUDynamicSharedMemoryOpLowering::matchAndRewrite(
709707

710708
// Step 2: Generate a global symbol or existing for the dynamic shared
711709
// memory with memref<0xi8> type
712-
LLVM::LLVMFuncOp funcOp = op->getParentOfType<LLVM::LLVMFuncOp>();
713-
LLVM::GlobalOp shmemOp = {};
714-
Operation *moduleOp = funcOp->getParentWithTrait<OpTrait::SymbolTable>();
715-
shmemOp = getDynamicSharedMemorySymbol(
710+
auto moduleOp = op->getParentOfType<gpu::GPUModuleOp>();
711+
LLVM::GlobalOp shmemOp = getDynamicSharedMemorySymbol(
716712
rewriter, moduleOp, op, getTypeConverter(), memrefType0sz, alignmentBit);
717713

718714
// Step 3. Get address of the global symbol

mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ struct LowerDeallocationsPass
391391

392392
bufferization::DeallocHelperMap deallocHelperFuncMap;
393393
if (auto module = dyn_cast<ModuleOp>(getOperation())) {
394-
OpBuilder builder =
395-
OpBuilder::atBlockBegin(&module.getBodyRegion().front());
394+
OpBuilder builder = OpBuilder::atBlockBegin(module.getBody());
396395

397396
// Build dealloc helper function if there are deallocs.
398397
getOperation()->walk([&](bufferization::DeallocOp deallocOp) {

mlir/lib/Dialect/SparseTensor/Transforms/SparseGPUCodegen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static gpu::GPUModuleOp genGPUModule(OpBuilder &builder, ModuleOp topModule) {
5858
for (auto op : topModule.getBodyRegion().getOps<gpu::GPUModuleOp>())
5959
return op; // existing
6060
markAsGPUContainer(topModule);
61-
builder.setInsertionPointToStart(&topModule.getBodyRegion().front());
61+
builder.setInsertionPointToStart(topModule.getBody());
6262
return builder.create<gpu::GPUModuleOp>(topModule->getLoc(),
6363
"sparse_kernels");
6464
}
@@ -75,7 +75,7 @@ static gpu::GPUFuncOp genGPUFunc(OpBuilder &builder, gpu::GPUModuleOp gpuModule,
7575
("kernel" + Twine(kernelNumber++)).toStringRef(kernelName);
7676
} while (gpuModule.lookupSymbol(kernelName));
7777
// Then we insert a new kernel with given arguments into the module.
78-
builder.setInsertionPointToStart(&gpuModule.getBodyRegion().front());
78+
builder.setInsertionPointToStart(gpuModule.getBody());
7979
SmallVector<Type> argsTp;
8080
for (auto arg : args)
8181
argsTp.push_back(arg.getType());

0 commit comments

Comments
 (0)