[flang-commits] [flang] [Flang][MLIR] Extend DataLayout utilities to have basic GPU Module support (PR #123149)

Jan Leyonberg via flang-commits flang-commits at lists.llvm.org
Tue Jan 28 06:12:26 PST 2025


================
@@ -46,15 +49,53 @@ void fir::support::setMLIRDataLayoutFromAttributes(mlir::ModuleOp mlirModule,
   fir::support::setMLIRDataLayout(mlirModule, llvmDataLayout);
 }
 
-std::optional<mlir::DataLayout>
-fir::support::getOrSetDataLayout(mlir::ModuleOp mlirModule,
-                                 bool allowDefaultLayout) {
+template <typename ModOpTy>
+std::optional<mlir::DataLayout> getOrSetDataLayout(ModOpTy mlirModule,
+                                                   bool allowDefaultLayout) {
   if (!mlirModule.getDataLayoutSpec()) {
     fir::support::setMLIRDataLayoutFromAttributes(mlirModule,
                                                   allowDefaultLayout);
-    if (!mlirModule.getDataLayoutSpec()) {
+    // if it is a GPU module, we let it proceed, as it's contained within
+    // a module, its parent may have a DataLayout that can take its
+    // place.
+    if (!mlirModule.getDataLayoutSpec() &&
----------------
jsjodin wrote:

Maybe we can linearize this code instead of nesting so it is clear that the same value is checked and potentially modified.

https://github.com/llvm/llvm-project/pull/123149


More information about the flang-commits mailing list