Skip to content

Commit 7000351

Browse files
committed
code review feedback - use std::optional fixups
1 parent bc93994 commit 7000351

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/Support/FormatVariadic.h"
2424
#include <climits>
2525
#include <cstdint>
26+
#include <optional>
2627

2728
#define DEBUG_TYPE "dxil-resource"
2829

@@ -998,7 +999,7 @@ void DXILResourceBindingInfo::populate(Module &M, DXILResourceTypeMap &DRTM) {
998999
}
9991000
}
10001001

1001-
// returns false if binding could not be found in given space
1002+
// returns std::nulopt if binding could not be found in given space
10021003
std::optional<uint32_t>
10031004
DXILResourceBindingInfo::findAvailableBinding(dxil::ResourceClass RC,
10041005
uint32_t Space, int32_t Size) {
@@ -1023,34 +1024,35 @@ std::optional<uint32_t>
10231024
DXILResourceBindingInfo::RegisterSpace::findAvailableBinding(int32_t Size) {
10241025
assert((Size == -1 || Size > 0) && "invalid size");
10251026

1026-
std::optional<uint32_t> RegSlot;
10271027
if (FreeRanges.empty())
1028-
return RegSlot;
1028+
return std::nullopt;
10291029

10301030
// unbounded array
10311031
if (Size == -1) {
10321032
BindingRange &Last = FreeRanges.back();
10331033
if (Last.UpperBound != UINT32_MAX)
10341034
// this space is already occupied by an unbounded array
1035-
return false;
1036-
RegSlot = Last.LowerBound;
1035+
return std::nullopt;
1036+
uint32_t RegSlot = Last.LowerBound;
10371037
FreeRanges.pop_back();
1038-
} else {
1039-
// single resource or fixed-size array
1040-
for (BindingRange &R : FreeRanges) {
1041-
// compare the size as uint64_t to prevent overflow for range (0,
1042-
// UINT32_MAX)
1043-
if ((uint64_t)R.UpperBound - R.LowerBound + 1 < (uint64_t)Size)
1044-
continue;
1045-
RegSlot = R.LowerBound;
1046-
// This might create a range where (LowerBound == UpperBound + 1). When
1047-
// that happens, the next time this function is called the range will
1048-
// skipped over by the check above (at this point Size is always > 0).
1049-
R.LowerBound += Size;
1050-
break;
1051-
}
1038+
return RegSlot;
10521039
}
1053-
return RegSlot;
1040+
1041+
// single resource or fixed-size array
1042+
for (BindingRange &R : FreeRanges) {
1043+
// compare the size as uint64_t to prevent overflow for range (0,
1044+
// UINT32_MAX)
1045+
if ((uint64_t)R.UpperBound - R.LowerBound + 1 < (uint64_t)Size)
1046+
continue;
1047+
uint32_t RegSlot = R.LowerBound;
1048+
// This might create a range where (LowerBound == UpperBound + 1). When
1049+
// that happens, the next time this function is called the range will
1050+
// skipped over by the check above (at this point Size is always > 0).
1051+
R.LowerBound += Size;
1052+
return RegSlot;
1053+
}
1054+
1055+
return std::nullopt;
10541056
}
10551057

10561058
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)