summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ast-type.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-07-25 15:00:14 -0700
committerGitHub <noreply@github.com>2024-07-25 15:00:14 -0700
commitc9d89a40775a055873adf82cfb0ee1cb6bdcb93c (patch)
tree2438f353e87b30febe966ca23976793637c018d2 /source/slang/slang-ast-type.cpp
parent1343ab79fcd0ff9e5ffebbcf95414e51ab19e9cd (diff)
Overhaul IR lowering of pointer types. (#4710)
* Overhaul IR lowering of pointer types. * Propagate address space in IRBuilder. * Fixup. * Fix. * Fix. * Change how Ptr type is printed to text. * Fix.
Diffstat (limited to 'source/slang/slang-ast-type.cpp')
-rw-r--r--source/slang/slang-ast-type.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp
index 47cd68b9e..44585ee30 100644
--- a/source/slang/slang-ast-type.cpp
+++ b/source/slang/slang-ast-type.cpp
@@ -352,6 +352,66 @@ Type* NativeRefType::getValueType()
return as<Type>(_getGenericTypeArg(this, 0));
}
+Val* PtrTypeBase::getAddressSpace()
+{
+ return _getGenericTypeArg(this, 1);
+}
+
+AddressSpace tryGetAddressSpaceValue(Val* addrSpaceVal)
+{
+ AddressSpace addrSpace = AddressSpace::Generic;
+
+ if (auto cintVal = as<ConstantIntVal>(addrSpaceVal))
+ {
+ addrSpace = (AddressSpace)(cintVal->getValue());
+ }
+ return addrSpace;
+}
+
+void maybePrintAddrSpaceOperand(StringBuilder& out, AddressSpace addrSpace)
+{
+ switch (addrSpace)
+ {
+ case AddressSpace::Generic:
+ case AddressSpace::UserPointer:
+ break;
+ case AddressSpace::GroupShared:
+ out << toSlice(", groupshared");
+ break;
+ case AddressSpace::Global:
+ out << toSlice(", global");
+ break;
+ case AddressSpace::ThreadLocal:
+ out << toSlice(", threadlocal");
+ break;
+ case AddressSpace::Uniform:
+ out << toSlice(", uniform");
+ break;
+ default:
+ break;
+ }
+}
+
+void PtrType::_toTextOverride(StringBuilder& out)
+{
+ auto addrSpace = tryGetAddressSpaceValue(getAddressSpace());
+ if (addrSpace == AddressSpace::Generic)
+ out << toSlice("Addr<") << getValueType();
+ else
+ out << toSlice("Ptr<") << getValueType();
+ maybePrintAddrSpaceOperand(out, addrSpace);
+ out << toSlice(">");
+}
+
+void RefType::_toTextOverride(StringBuilder& out)
+{
+ out << toSlice("Ref<") << getValueType();
+ auto addressSpaceVal = getAddressSpace();
+ maybePrintAddrSpaceOperand(out, tryGetAddressSpaceValue(addressSpaceVal));
+ out << toSlice(">");
+}
+
+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NamedExpressionType !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void NamedExpressionType::_toTextOverride(StringBuilder& out)