Skip to content

[mlir][NFC] Minor cleanup around ModuleOp usage #110498

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
Sep 30, 2024
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
3 changes: 1 addition & 2 deletions flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
return existingPrivatizer;

mlir::OpBuilder::InsertionGuard guard(firOpBuilder);
firOpBuilder.setInsertionPoint(&moduleOp.getBodyRegion().front(),
moduleOp.getBodyRegion().front().begin());
firOpBuilder.setInsertionPointToStart(moduleOp.getBody());
auto result = firOpBuilder.create<mlir::omp::PrivateClauseOp>(
symLoc, uniquePrivatizerName, symType,
isFirstPrivate ? mlir::omp::DataSharingClauseType::FirstPrivate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ struct BufferizationToMemRefPass

bufferization::DeallocHelperMap deallocHelperFuncMap;
if (auto module = dyn_cast<ModuleOp>(getOperation())) {
OpBuilder builder =
OpBuilder::atBlockBegin(&module.getBodyRegion().front());
OpBuilder builder = OpBuilder::atBlockBegin(module.getBody());

// Build dealloc helper function if there are deallocs.
getOperation()->walk([&](bufferization::DeallocOp deallocOp) {
Expand Down
20 changes: 8 additions & 12 deletions mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,10 @@ static IntegerAttr wrapNumericMemorySpace(MLIRContext *ctx, unsigned space) {

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

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

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

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

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

// Step 3. Get address of the global symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ struct LowerDeallocationsPass

bufferization::DeallocHelperMap deallocHelperFuncMap;
if (auto module = dyn_cast<ModuleOp>(getOperation())) {
OpBuilder builder =
OpBuilder::atBlockBegin(&module.getBodyRegion().front());
OpBuilder builder = OpBuilder::atBlockBegin(module.getBody());

// Build dealloc helper function if there are deallocs.
getOperation()->walk([&](bufferization::DeallocOp deallocOp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static gpu::GPUModuleOp genGPUModule(OpBuilder &builder, ModuleOp topModule) {
for (auto op : topModule.getBodyRegion().getOps<gpu::GPUModuleOp>())
return op; // existing
markAsGPUContainer(topModule);
builder.setInsertionPointToStart(&topModule.getBodyRegion().front());
builder.setInsertionPointToStart(topModule.getBody());
return builder.create<gpu::GPUModuleOp>(topModule->getLoc(),
"sparse_kernels");
}
Expand All @@ -75,7 +75,7 @@ static gpu::GPUFuncOp genGPUFunc(OpBuilder &builder, gpu::GPUModuleOp gpuModule,
("kernel" + Twine(kernelNumber++)).toStringRef(kernelName);
} while (gpuModule.lookupSymbol(kernelName));
// Then we insert a new kernel with given arguments into the module.
builder.setInsertionPointToStart(&gpuModule.getBodyRegion().front());
builder.setInsertionPointToStart(gpuModule.getBody());
SmallVector<Type> argsTp;
for (auto arg : args)
argsTp.push_back(arg.getType());
Expand Down
Loading