[flang-commits] [flang] [mlir] [flang] Introduce omp.target_allocmem and omp.target_freemem omp dialect ops. (PR #145464)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Wed Jul 16 04:27:23 PDT 2025


================
@@ -224,6 +226,67 @@ std::optional<llvm::ArrayRef<int64_t>> getComponentLowerBoundsIfNonDefault(
     fir::RecordType recordType, llvm::StringRef component,
     mlir::ModuleOp module, const mlir::SymbolTable *symbolTable = nullptr);
 
+// Convert FIR type to LLVM without turning fir.box<T> into memory
+// reference.
+mlir::Type convertObjectType(const fir::LLVMTypeConverter &converter,
+                             mlir::Type firType);
+
+/// Generate a LLVM constant value of type `ity`, using the provided offset.
+mlir::LLVM::ConstantOp
+genConstantIndex(mlir::Location loc, mlir::Type ity,
+                 mlir::ConversionPatternRewriter &rewriter,
+                 std::int64_t offset);
+
+/// Helper function for generating the LLVM IR that computes the distance
+/// in bytes between adjacent elements pointed to by a pointer
+/// of type \p ptrTy. The result is returned as a value of \p idxTy integer
+/// type.
+mlir::Value computeElementDistance(mlir::Location loc,
+                                   mlir::Type llvmObjectType, mlir::Type idxTy,
+                                   mlir::ConversionPatternRewriter &rewriter,
+                                   const mlir::DataLayout &dataLayout);
+
+// Compute the alloc scale size (constant factors encoded in the array type).
+// We do this for arrays without a constant interior or arrays of character with
+// dynamic length arrays, since those are the only ones that get decayed to a
+// pointer to the element type.
+template <typename OP>
+inline mlir::Value
+genAllocationScaleSize(OP op, mlir::Type ity,
----------------
ergawy wrote:

Can you please de-templetize this and move the definiton to the `.cpp` file? >From `op`, we only need `InType` and `Loc`; both of which can be easily passed to the function on call sites.

Adding templates in headers files (specially the ones who are used in a lot places like `Uilts` files) can slow down compilation times.

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


More information about the flang-commits mailing list