|
14 | 14 | #define CLANG_CIR_DIALECT_IR_CIRATTRS_TD |
15 | 15 |
|
16 | 16 | include "mlir/IR/BuiltinAttributeInterfaces.td" |
| 17 | +include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td" |
17 | 18 | include "clang/CIR/Dialect/IR/CIREnumAttr.td" |
18 | 19 |
|
19 | 20 | include "clang/CIR/Dialect/IR/CIRDialect.td" |
@@ -963,43 +964,76 @@ def CIR_DynamicCastInfoAttr : CIR_Attr<"DynamicCastInfo", "dyn_cast_info"> { |
963 | 964 | // AddressSpaceAttr |
964 | 965 | //===----------------------------------------------------------------------===// |
965 | 966 |
|
966 | | -def CIR_AddressSpaceAttr : CIR_EnumAttr<CIR_AddressSpace, "address_space"> { |
| 967 | +def CIR_LangAddressSpaceAttr : |
| 968 | + CIR_EnumAttr<CIR_LangAddressSpace, "lang_address_space", [ |
| 969 | + DeclareAttrInterfaceMethods<MemorySpaceAttrInterface> |
| 970 | + ]> { |
| 971 | + |
| 972 | + let summary = "Represents a language address space"; |
| 973 | + let description = [{ |
| 974 | + Encodes the semantic address spaces defined by the front-end language |
| 975 | + (e.g. `__shared__`, `__constant__`, `__local__`). Values are stored using the |
| 976 | + `cir::LangAddressSpace` enum, keeping the representation compact while and |
| 977 | + preserves the qualifier until it is mapped onto target/LLVM address-space numbers. |
| 978 | + |
| 979 | + Example: |
| 980 | + ``` mlir |
| 981 | + !cir.ptr<!s32i, lang_address_space(offload_local)> |
| 982 | + cir.global constant external lang_address_space(offload_constant) |
| 983 | + |
| 984 | + ``` |
| 985 | + }]; |
| 986 | + |
967 | 987 | let builders = [ |
968 | 988 | AttrBuilder<(ins "clang::LangAS":$langAS), [{ |
969 | | - return $_get($_ctxt, cir::toCIRAddressSpace(langAS)); |
| 989 | + return $_get($_ctxt, cir::toCIRLangAddressSpace(langAS)); |
970 | 990 | }]> |
971 | 991 | ]; |
972 | 992 |
|
973 | 993 | let assemblyFormat = [{ |
974 | 994 | `(` custom<AddressSpaceValue>($value) `)` |
975 | 995 | }]; |
976 | 996 |
|
977 | | - let defaultValue = "cir::AddressSpace::Default"; |
| 997 | + let defaultValue = "cir::LangAddressSpace::Default"; |
978 | 998 |
|
979 | 999 | let extraClassDeclaration = [{ |
980 | | - bool isLang() const; |
981 | | - bool isTarget() const; |
982 | | - unsigned getTargetValue() const; |
983 | 1000 | unsigned getAsUnsignedValue() const; |
984 | 1001 | }]; |
985 | 1002 |
|
986 | 1003 | let extraClassDefinition = [{ |
987 | 1004 | unsigned $cppClass::getAsUnsignedValue() const { |
988 | 1005 | return static_cast<unsigned>(getValue()); |
989 | 1006 | } |
| 1007 | + }]; |
| 1008 | +} |
990 | 1009 |
|
991 | | - bool $cppClass::isLang() const { |
992 | | - return cir::isLangAddressSpace(getValue()); |
993 | | - } |
| 1010 | +//===----------------------------------------------------------------------===// |
| 1011 | +// TargetAddressSpaceAttr |
| 1012 | +//===----------------------------------------------------------------------===// |
994 | 1013 |
|
995 | | - bool $cppClass::isTarget() const { |
996 | | - return cir::isTargetAddressSpace(getValue()); |
997 | | - } |
| 1014 | +def CIR_TargetAddressSpaceAttr : CIR_Attr< "TargetAddressSpace", |
| 1015 | + "target_address_space", [ |
| 1016 | + DeclareAttrInterfaceMethods<MemorySpaceAttrInterface> |
| 1017 | + ]> { |
| 1018 | + let summary = "Represents a target-specific numeric address space"; |
| 1019 | + let description = [{ |
| 1020 | + The TargetAddressSpaceAttr represents a target-specific numeric address space, |
| 1021 | + corresponding to the LLVM IR `addressspace` qualifier and the clang |
| 1022 | + `address_space` attribute. |
| 1023 | + |
| 1024 | + A value of zero represents the default address space. The semantics of non-zero |
| 1025 | + address spaces are target-specific. |
998 | 1026 |
|
999 | | - unsigned $cppClass::getTargetValue() const { |
1000 | | - return cir::getTargetAddressSpaceValue(getValue()); |
1001 | | - } |
| 1027 | + Example: |
| 1028 | + ```mlir |
| 1029 | + // Target-specific numeric address spaces |
| 1030 | + !cir.ptr<!s32i, target_address_space(1)> |
| 1031 | + !cir.ptr<!s32i, target_address_space(1)> |
| 1032 | + ``` |
1002 | 1033 | }]; |
| 1034 | + |
| 1035 | + let parameters = (ins "unsigned":$value); |
| 1036 | + let assemblyFormat = "`<` `target` `<` $value `>` `>`"; |
1003 | 1037 | } |
1004 | 1038 |
|
1005 | 1039 | //===----------------------------------------------------------------------===// |
|
0 commit comments