[flang-commits] [flang] [Flang][MLIR] Add basic initial support for alloca and program address space handling in FIR->LLVMIR codegen (PR #77518)
via flang-commits
flang-commits at lists.llvm.org
Wed Jan 10 05:45:49 PST 2024
================
@@ -67,8 +68,41 @@ static constexpr unsigned defaultAlign = 8;
static constexpr unsigned kAttrPointer = CFI_attribute_pointer;
static constexpr unsigned kAttrAllocatable = CFI_attribute_allocatable;
-static inline mlir::Type getLlvmPtrType(mlir::MLIRContext *context) {
- return mlir::LLVM::LLVMPointerType::get(context);
+static inline unsigned getAllocaAddressSpace(mlir::ModuleOp module) {
+ if (mlir::Attribute addrSpace =
+ mlir::DataLayout(module).getAllocaMemorySpace())
+ return addrSpace.cast<mlir::IntegerAttr>().getUInt();
+
+ return 0u;
+}
+
+static inline unsigned getProgramAddressSpace(mlir::ModuleOp module) {
+ if (mlir::Attribute addrSpace =
+ mlir::DataLayout(module).getProgramMemorySpace())
+ return addrSpace.cast<mlir::IntegerAttr>().getUInt();
+
+ return 0u;
+}
+
+static inline unsigned
+getAllocaAddressSpace(mlir::ConversionPatternRewriter &rewriter) {
+ mlir::Operation *parentOp = rewriter.getInsertionBlock()->getParentOp();
+ return parentOp ? ::getAllocaAddressSpace(
+ parentOp->getParentOfType<mlir::ModuleOp>())
+ : 0u;
+}
+
+static inline unsigned
+getProgramAddressSpace(mlir::ConversionPatternRewriter &rewriter) {
+ mlir::Operation *parentOp = rewriter.getInsertionBlock()->getParentOp();
+ return parentOp ? ::getProgramAddressSpace(
+ parentOp->getParentOfType<mlir::ModuleOp>())
+ : 0u;
+}
+
+static inline mlir::Type getLlvmPtrType(mlir::MLIRContext *context,
+ unsigned addressSpace = 0) {
+ return mlir::LLVM::LLVMPointerType::get(context, addressSpace);
----------------
agozillon wrote:
I think that could be left to another PR if someone wishes to do it, it'd touch on a bit more than this PR covers!
https://github.com/llvm/llvm-project/pull/77518
More information about the flang-commits
mailing list