Remapping memory spaces is a function often needed in type conversions, most often when going to LLVM or to/from SPIR-V (a future commit), and it is possible that such remappings may become more common in the future as dialects take advantage of the more generic memory space infrastructure. Currently, memory space remappings are handled by running a special-purpose conversion pass before the main conversion that changes the address space attributes. In this commit, this approach is replaced by adding a notion of type attribute conversions TypeConverter, which is then used to convert memory space attributes. Then, we use this infrastructure throughout the *ToLLVM conversions. This has the advantage of loosing the requirements on the inputs to those passes from "all address spaces must be integers" to "all memory spaces must be convertible to integer spaces", a looser requirement that reduces the coupling between portions of MLIR. ON top of that, this change leads to the removal of most of the calls to getMemorySpaceAsInt(), bringing us closer to removing it. (A rework of the SPIR-V conversions to use this new system will be in a folowup commit.) As a note, one long-term motivation for this change is that I would eventually like to add an allocaMemorySpace key to MLIR data layouts and then call getMemRefAddressSpace(allocaMemorySpace) in the relevant *ToLLVM in order to ensure all alloca()s, whether incoming or produces during the LLVM lowering, have the correct address space for a given target. I expect that the type attribute conversion system may be useful in other contexts. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D142159
15 lines
545 B
MLIR
15 lines
545 B
MLIR
// RUN: mlir-opt %s -finalize-memref-to-llvm -split-input-file 2>&1 | FileCheck %s
|
|
// Since the error is at an unknown location, we use FileCheck instead of
|
|
// -veri-y-diagnostics here
|
|
|
|
// CHECK: conversion of memref memory space "foo" to integer address space failed. Consider adding memory space conversions.
|
|
// CHECK-LABEL: @bad_address_space
|
|
func.func @bad_address_space(%a: memref<2xindex, "foo">) {
|
|
%c0 = arith.constant 0 : index
|
|
// CHECK: memref.store
|
|
memref.store %c0, %a[%c0] : memref<2xindex, "foo">
|
|
return
|
|
}
|
|
|
|
// -----
|