@@ -896,24 +896,46 @@ static LegalType createLegalUniformBufferType(
896
896
// Create a pointer type with a given legalized value type.
897
897
static LegalType createLegalPtrType (
898
898
TypeLegalizationContext* context,
899
- IROp op ,
899
+ IRInst* originalPtrType ,
900
900
LegalType legalValueType)
901
901
{
902
902
switch (legalValueType.flavor )
903
903
{
904
904
case LegalType::Flavor::none:
905
+ if (auto ptrType = as<IRPtrType>(originalPtrType))
906
+ {
907
+ switch (ptrType->getAddressSpace ())
908
+ {
909
+ case AddressSpace::UserPointer:
910
+ case AddressSpace::Global:
911
+ // If this is a physical pointer, we need to create an untyped pointer if
912
+ // the element type is nothing.
913
+ return LegalType::simple (
914
+ context->getBuilder ()->getPtrTypeWithAddressSpace (
915
+ context->getBuilder ()->getVoidType (),
916
+ ptrType));
917
+ }
918
+ }
905
919
return LegalType ();
906
920
907
921
case LegalType::Flavor::simple:
908
922
{
909
- // Easy case: we just have a simple element type,
910
- // so we want to create a uniform buffer that wraps it.
923
+ // Easy case: we just have a simple element type.
924
+ if (auto ptrTypeBase = as<IRPtrTypeBase>(originalPtrType))
925
+ {
926
+ if (ptrTypeBase->hasAddressSpace ())
927
+ {
928
+ return LegalType::simple (
929
+ context->getBuilder ()->getPtrTypeWithAddressSpace (
930
+ legalValueType.getSimple (),
931
+ ptrTypeBase));
932
+ }
933
+ }
911
934
return LegalType::simple (createBuiltinGenericType (
912
935
context,
913
- op ,
936
+ originalPtrType-> getOp () ,
914
937
legalValueType.getSimple ()));
915
938
}
916
- break ;
917
939
918
940
case LegalType::Flavor::implicitDeref:
919
941
{
@@ -936,7 +958,7 @@ static LegalType createLegalPtrType(
936
958
// will matter.
937
959
return LegalType::implicitDeref (createLegalPtrType (
938
960
context,
939
- op ,
961
+ originalPtrType ,
940
962
legalValueType.getImplicitDeref ()->valueType ));
941
963
}
942
964
break ;
@@ -948,11 +970,11 @@ static LegalType createLegalPtrType(
948
970
949
971
auto ordinaryType = createLegalPtrType (
950
972
context,
951
- op ,
973
+ originalPtrType ,
952
974
pairType->ordinaryType );
953
975
auto specialType = createLegalPtrType (
954
976
context,
955
- op ,
977
+ originalPtrType ,
956
978
pairType->specialType );
957
979
958
980
return LegalType::pair (ordinaryType, specialType, pairType->pairInfo );
@@ -974,7 +996,7 @@ static LegalType createLegalPtrType(
974
996
newElement.key = ee.key ;
975
997
newElement.type = createLegalPtrType (
976
998
context,
977
- op ,
999
+ originalPtrType ,
978
1000
ee.type );
979
1001
980
1002
ptrPseudoTupleType->elements .add (newElement);
@@ -1310,7 +1332,7 @@ LegalType legalizeTypeImpl(
1310
1332
if (legalValueType.flavor == LegalType::Flavor::simple &&
1311
1333
legalValueType.getSimple () == ptrType->getValueType ())
1312
1334
return LegalType::simple (ptrType);
1313
- return createLegalPtrType (context, ptrType-> getOp () , legalValueType);
1335
+ return createLegalPtrType (context, ptrType, legalValueType);
1314
1336
}
1315
1337
else if (auto structType = as<IRStructType>(type))
1316
1338
{
0 commit comments