1 //===-- Optimizer/Support/DataLayout.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 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef FORTRAN_OPTIMIZER_SUPPORT_DATALAYOUT_H 14 #define FORTRAN_OPTIMIZER_SUPPORT_DATALAYOUT_H 15 16 #include "mlir/Interfaces/DataLayoutInterfaces.h" 17 #include <optional> 18 19 namespace mlir { 20 class ModuleOp; 21 } 22 namespace llvm { 23 class DataLayout; 24 } 25 26 namespace fir::support { 27 /// Create an mlir::DataLayoutSpecInterface attribute from an llvm::DataLayout 28 /// and set it on the provided mlir::ModuleOp. 29 /// Also set the llvm.data_layout attribute with the string representation of 30 /// the llvm::DataLayout on the module. 31 /// These attributes are replaced if they were already set. 32 void setMLIRDataLayout(mlir::ModuleOp mlirModule, const llvm::DataLayout &dl); 33 34 /// Create an mlir::DataLayoutSpecInterface from the llvm.data_layout attribute 35 /// if one is provided. If such attribute is not available, create a default 36 /// target independent layout when allowDefaultLayout is true. Otherwise do 37 /// nothing. 38 void setMLIRDataLayoutFromAttributes(mlir::ModuleOp mlirModule, 39 bool allowDefaultLayout); 40 41 /// Create mlir::DataLayout from the data layout information on the 42 /// mlir::Module. Creates the data layout information attributes with 43 /// setMLIRDataLayoutFromAttributes if the DLTI attribute is not yet set. If no 44 /// information is present at all and \p allowDefaultLayout is false, returns 45 /// std::nullopt. 46 std::optional<mlir::DataLayout> 47 getOrSetDataLayout(mlir::ModuleOp mlirModule, bool allowDefaultLayout = false); 48 } // namespace fir::support 49 50 #endif // FORTRAN_OPTIMIZER_SUPPORT_DATALAYOUT_H 51