@@ -652,19 +652,27 @@ def DynamicCastInfoAttr
652
652
// AddressSpaceAttr
653
653
//===----------------------------------------------------------------------===//
654
654
655
- // TODO: other CIR AS cases
656
- def AS_Target : I32EnumAttrCase<"target", 21>;
655
+ def AS_OffloadPrivate : I32EnumAttrCase<"offload_private", 1>;
656
+ def AS_OffloadLocal : I32EnumAttrCase<"offload_local", 2>;
657
+ def AS_OffloadGlobal : I32EnumAttrCase<"offload_global", 3>;
658
+ def AS_OffloadConstant : I32EnumAttrCase<"offload_constant", 4>;
659
+ def AS_OffloadGeneric : I32EnumAttrCase<"offload_generic", 5>;
660
+ def AS_Target : I32EnumAttrCase<"target", 6>;
657
661
658
662
def AddressSpaceAttr : CIR_Attr<"AddressSpace", "addrspace"> {
659
663
660
664
let summary = "Address space attribute for pointer types";
661
665
let description = [{
662
- The address space attribute models `clang::LangAS` rather than the LLVM
663
- address space, which means it's not yet converted by the address space map
664
- to carry target-specific semantics .
666
+ The address space attribute is used in pointer types. It essentially
667
+ provides a unified model on top of `clang::LangAS`, rather than LLVM address
668
+ spaces .
665
669
666
- The representation is one-to-one except for `LangAS::Default`, which
667
- corresponds to a null attribute instead.
670
+ The representation is further simplified: `LangAS::Default` is encoded as
671
+ a null attribute; many address spaces from different offloading languages
672
+ are unified as `offload_*`; etc.
673
+
674
+ The meaning of `value` parameter is defined as an extensible enum `Kind`,
675
+ which encodes target AS as offset to the last language AS.
668
676
}];
669
677
670
678
let parameters = (ins "int32_t":$value);
@@ -690,7 +698,8 @@ def AddressSpaceAttr : CIR_Attr<"AddressSpace", "addrspace"> {
690
698
// simplified assembly format `custom<PointerAddrSpace>`.
691
699
692
700
list<I32EnumAttrCase> langASCases = [
693
- // TODO: includes all non-target CIR AS cases here
701
+ AS_OffloadPrivate, AS_OffloadLocal, AS_OffloadGlobal, AS_OffloadConstant,
702
+ AS_OffloadGeneric
694
703
];
695
704
696
705
I32EnumAttrCase targetASCase = AS_Target;
@@ -703,9 +712,23 @@ def AddressSpaceAttr : CIR_Attr<"AddressSpace", "addrspace"> {
703
712
bool isTarget() const;
704
713
unsigned getTargetValue() const;
705
714
706
- static std::optional<int32_t> parseValueFromString(llvm::StringRef s);
715
+ /// Convert a clang LangAS to its corresponding CIR AS storage value. This
716
+ /// helper does not perform any language-specific mappings (e.g. determining
717
+ /// the default AS for offloading languages), so these must be handled in
718
+ /// the caller.
707
719
static std::optional<int32_t> getValueFromLangAS(clang::LangAS v);
720
+
721
+ /// Helper methods for the assembly format `custom<PointerAddrSpace>`.
722
+ static std::optional<int32_t> parseValueFromString(llvm::StringRef s);
708
723
static std::optional<llvm::StringRef> stringifyValue(int32_t v);
724
+
725
+ struct Kind {
726
+ }]#!interleave(
727
+ !foreach(case, langASCases,
728
+ "static constexpr int32_t "#case.symbol#" = "#case.value#";"
729
+ ), "\n"
730
+ )#[{
731
+ };
709
732
}];
710
733
711
734
let extraClassDefinition = [{
@@ -757,31 +780,6 @@ def AddressSpaceAttr : CIR_Attr<"AddressSpace", "addrspace"> {
757
780
return std::nullopt;
758
781
}
759
782
}
760
-
761
- std::optional<int32_t>
762
- $cppClass::getValueFromLangAS(clang::LangAS langAS) {
763
- assert((langAS == clang::LangAS::Default ||
764
- clang::isTargetAddressSpace(langAS)) &&
765
- "Language-specific address spaces are not supported");
766
- switch (langAS) {
767
- }]
768
- #
769
- !interleave(
770
- !foreach(case, langASCases,
771
- "case clang::LangAS::"#case.symbol
772
- # [{: llvm_unreachable("Not Yet Supported");}] ),
773
- "\n"
774
- )
775
- #
776
- [{
777
- case clang::LangAS::Default:
778
- // Default address space should be encoded as a null attribute.
779
- return std::nullopt;
780
- default:
781
- // Target address space offset arithmetics
782
- return clang::toTargetAddressSpace(langAS) + kFirstTargetASValue;
783
- }
784
- }
785
783
}];
786
784
}
787
785
0 commit comments