@@ -995,12 +995,12 @@ void DXILResourceBindingInfo::populate(Module &M, DXILResourceTypeMap &DRTM) {
995995}
996996
997997// returns false if binding could not be found in given space
998- bool DXILResourceBindingInfo::findAvailableBinding (dxil::ResourceClass RC,
999- uint32_t Space, int32_t Size ,
1000- uint32_t *RegSlot ) {
998+ std::optional< uint32_t >
999+ DXILResourceBindingInfo::findAvailableBinding (dxil::ResourceClass RC ,
1000+ uint32_t Space, int32_t Size ) {
10011001 BindingSpaces &BS = getBindingSpaces (RC);
10021002 RegisterSpace &RS = BS.getOrInsertSpace (Space);
1003- return RS.findAvailableBinding (Size, RegSlot );
1003+ return RS.findAvailableBinding (Size);
10041004}
10051005
10061006DXILResourceBindingInfo::RegisterSpace &
@@ -1015,38 +1015,38 @@ DXILResourceBindingInfo::BindingSpaces::getOrInsertSpace(uint32_t Space) {
10151015 return Spaces.emplace_back (Space);
10161016}
10171017
1018- bool DXILResourceBindingInfo::RegisterSpace::findAvailableBinding (
1019- int32_t Size, uint32_t *RegSlot ) {
1018+ std::optional< uint32_t >
1019+ DXILResourceBindingInfo::RegisterSpace::findAvailableBinding ( int32_t Size) {
10201020 assert ((Size == -1 || Size > 0 ) && " invalid size" );
10211021
1022+ std::optional<uint32_t > RegSlot;
10221023 if (FreeRanges.empty ())
1023- return false ;
1024+ return RegSlot ;
10241025
10251026 // unbounded array
10261027 if (Size == -1 ) {
10271028 BindingRange &Last = FreeRanges.back ();
10281029 if (Last.UpperBound != UINT32_MAX)
10291030 // this space is already occupied by an unbounded array
10301031 return false ;
1031- * RegSlot = Last.LowerBound ;
1032+ RegSlot = Last.LowerBound ;
10321033 FreeRanges.pop_back ();
1033- return true ;
1034- }
1035-
1036- // single resource or fixed- size array
1037- for (BindingRange &R : FreeRanges) {
1038- // compare the size as uint64_t to prevent overflow for range (0,
1039- // UINT32_MAX)
1040- if (( uint64_t )R. UpperBound - R.LowerBound + 1 < ( uint64_t )Size)
1041- continue ;
1042- *RegSlot = R. LowerBound ;
1043- // This might create a range where (LowerBound == UpperBound + 1), but
1044- // that's ok.
1045- R. LowerBound += Size ;
1046- return true ;
1034+ } else {
1035+ // single resource or fixed-size array
1036+ for (BindingRange &R : FreeRanges) {
1037+ // compare the size as uint64_t to prevent overflow for range (0,
1038+ // UINT32_MAX)
1039+ if (( uint64_t )R. UpperBound - R. LowerBound + 1 < ( uint64_t )Size)
1040+ continue ;
1041+ RegSlot = R.LowerBound ;
1042+ // This might create a range where (LowerBound == UpperBound + 1). When
1043+ // that happens, the next time this function is called the range will
1044+ // skipped over by the check above (at this point Size is always > 0).
1045+ R. LowerBound += Size;
1046+ break ;
1047+ }
10471048 }
1048-
1049- return false ;
1049+ return RegSlot;
10501050}
10511051
10521052// ===----------------------------------------------------------------------===//
0 commit comments