Skip to content

Commit 2c8b999

Browse files
committed
clean up 1
1 parent 4f7856f commit 2c8b999

File tree

3 files changed

+81
-107
lines changed

3 files changed

+81
-107
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,14 +1144,15 @@ struct PerVisibilityBindingChecker {
11441144
bool HadOverlap = false;
11451145

11461146
using llvm::hlsl::BindingInfoBuilder;
1147-
auto ReportOverlap = [this,
1148-
&HadOverlap](const BindingInfoBuilder &Builder,
1149-
const llvm::hlsl::Binding &Reported) {
1147+
auto ReportOverlap = [this, &HadOverlap](
1148+
const BindingInfoBuilder &Builder,
1149+
const llvm::hlsl::Binding &Reported) {
11501150
HadOverlap = true;
11511151

11521152
const auto *Elem =
11531153
static_cast<const hlsl::RootSignatureElement *>(Reported.Cookie);
1154-
const llvm::hlsl::Binding &Previous = Builder.findOverlapping(Reported);
1154+
const llvm::hlsl::Binding &Previous =
1155+
Builder.findOverlapping(Reported);
11551156
const auto *PrevElem =
11561157
static_cast<const hlsl::RootSignatureElement *>(Previous.Cookie);
11571158

llvm/include/llvm/Frontend/HLSL/HLSLBinding.h

Lines changed: 76 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class BindingInfo {
5959
}
6060
// Size == -1 means unbounded array
6161
LLVM_ABI std::optional<uint32_t> findAvailableBinding(int32_t Size);
62-
LLVM_ABI bool isBound(const BindingRange &Range) const;
6362

6463
bool operator==(const RegisterSpace &Other) const {
6564
return Space == Other.Space;
@@ -103,94 +102,90 @@ class BindingInfo {
103102
// Size == -1 means unbounded array
104103
LLVM_ABI std::optional<uint32_t>
105104
findAvailableBinding(dxil::ResourceClass RC, uint32_t Space, int32_t Size);
106-
107-
LLVM_ABI bool isBound(dxil::ResourceClass RC, uint32_t Space,
108-
const BindingRange &Range) const;
109-
110105
friend class BindingInfoBuilder;
111106
};
112-
struct Binding {
113-
dxil::ResourceClass RC;
114-
uint32_t Space;
115-
uint32_t LowerBound;
116-
uint32_t UpperBound;
117-
const void *Cookie;
118-
119-
Binding(dxil::ResourceClass RC, uint32_t Space, uint32_t LowerBound,
120-
uint32_t UpperBound, const void *Cookie)
121-
: RC(RC), Space(Space), LowerBound(LowerBound), UpperBound(UpperBound),
122-
Cookie(Cookie) {}
107+
struct Binding {
108+
dxil::ResourceClass RC;
109+
uint32_t Space;
110+
uint32_t LowerBound;
111+
uint32_t UpperBound;
112+
const void *Cookie;
113+
114+
Binding(dxil::ResourceClass RC, uint32_t Space, uint32_t LowerBound,
115+
uint32_t UpperBound, const void *Cookie)
116+
: RC(RC), Space(Space), LowerBound(LowerBound), UpperBound(UpperBound),
117+
Cookie(Cookie) {}
118+
119+
bool isUnbounded() const { return UpperBound == ~0U; }
120+
121+
bool operator==(const Binding &RHS) const {
122+
return std::tie(RC, Space, LowerBound, UpperBound, Cookie) ==
123+
std::tie(RHS.RC, RHS.Space, RHS.LowerBound, RHS.UpperBound,
124+
RHS.Cookie);
125+
}
126+
bool operator!=(const Binding &RHS) const { return !(*this == RHS); }
123127

124-
bool isUnbounded() const { return UpperBound == ~0U; }
128+
bool operator<(const Binding &RHS) const {
129+
return std::tie(RC, Space, LowerBound) <
130+
std::tie(RHS.RC, RHS.Space, RHS.LowerBound);
131+
}
132+
};
133+
class BoundRegs {
134+
SmallVector<Binding> Bindings;
125135

126-
bool operator==(const Binding &RHS) const {
127-
return std::tie(RC, Space, LowerBound, UpperBound, Cookie) ==
128-
std::tie(RHS.RC, RHS.Space, RHS.LowerBound, RHS.UpperBound,
129-
RHS.Cookie);
130-
}
131-
bool operator!=(const Binding &RHS) const { return !(*this == RHS); }
136+
public:
137+
BoundRegs(SmallVector<Binding> &&Bindings)
138+
: Bindings(std::move(Bindings)) {}
139+
140+
bool isBound(dxil::ResourceClass RC, uint32_t Space, uint32_t LowerBound,
141+
uint32_t UpperBound) const {
142+
const Binding *It = llvm::upper_bound(
143+
Bindings, Binding{RC, Space, LowerBound, 0, nullptr});
144+
if (It == Bindings.begin())
145+
return false;
146+
--It;
147+
return It->RC == RC && It->Space == Space &&
148+
It->LowerBound <= LowerBound && It->UpperBound >= UpperBound;
149+
}
150+
};
132151

133-
bool operator<(const Binding &RHS) const {
134-
return std::tie(RC, Space, LowerBound) <
135-
std::tie(RHS.RC, RHS.Space, RHS.LowerBound);
136-
}
137-
};
138-
class BoundRegs {
139-
SmallVector<Binding> Bindings;
140-
141-
public:
142-
BoundRegs(SmallVector<Binding> &&Bindings)
143-
: Bindings(std::move(Bindings)) {}
144-
145-
bool isBound(dxil::ResourceClass RC, uint32_t Space, uint32_t LowerBound,
146-
uint32_t UpperBound) const {
147-
const Binding *It = llvm::upper_bound(
148-
Bindings, Binding{RC, Space, LowerBound, 0, nullptr});
149-
if (It == Bindings.begin())
150-
return false;
151-
--It;
152-
return It->RC == RC && It->Space == Space &&
153-
It->LowerBound <= LowerBound && It->UpperBound >= UpperBound;
154-
}
155-
};
152+
/// Builder class for creating a /c BindingInfo.
153+
class BindingInfoBuilder {
154+
public:
155+
private:
156+
SmallVector<Binding> Bindings;
156157

157-
/// Builder class for creating a /c BindingInfo.
158-
class BindingInfoBuilder {
159-
public:
160-
private:
161-
SmallVector<Binding> Bindings;
162-
163-
public:
164-
void trackBinding(dxil::ResourceClass RC, uint32_t Space,
165-
uint32_t LowerBound, uint32_t UpperBound,
166-
const void *Cookie) {
167-
Bindings.emplace_back(RC, Space, LowerBound, UpperBound, Cookie);
168-
}
169-
/// Calculate the binding info - \c ReportOverlap will be called once for
170-
/// each overlapping binding.
171-
LLVM_ABI BindingInfo calculateBindingInfo(
172-
llvm::function_ref<void(const BindingInfoBuilder &Builder,
173-
const Binding &Overlapping)>
174-
ReportOverlap);
175-
176-
/// Calculate the binding info - \c HasOverlap will be set to indicate
177-
/// whether there are any overlapping bindings.
178-
BindingInfo calculateBindingInfo(bool &HasOverlap) {
179-
HasOverlap = false;
180-
return calculateBindingInfo(
181-
[&HasOverlap](auto, auto) { HasOverlap = true; });
182-
}
158+
public:
159+
void trackBinding(dxil::ResourceClass RC, uint32_t Space,
160+
uint32_t LowerBound, uint32_t UpperBound,
161+
const void *Cookie) {
162+
Bindings.emplace_back(RC, Space, LowerBound, UpperBound, Cookie);
163+
}
164+
/// Calculate the binding info - \c ReportOverlap will be called once for
165+
/// each overlapping binding.
166+
LLVM_ABI BindingInfo calculateBindingInfo(
167+
llvm::function_ref<void(const BindingInfoBuilder &Builder,
168+
const Binding &Overlapping)>
169+
ReportOverlap);
170+
171+
/// Calculate the binding info - \c HasOverlap will be set to indicate
172+
/// whether there are any overlapping bindings.
173+
BindingInfo calculateBindingInfo(bool &HasOverlap) {
174+
HasOverlap = false;
175+
return calculateBindingInfo(
176+
[&HasOverlap](auto, auto) { HasOverlap = true; });
177+
}
183178

184-
BoundRegs calculateBoundRegs(
185-
llvm::function_ref<void(const BindingInfoBuilder &Builder,
186-
const Binding &Overlapping)>
187-
ReportOverlap);
179+
BoundRegs calculateBoundRegs(
180+
llvm::function_ref<void(const BindingInfoBuilder &Builder,
181+
const Binding &Overlapping)>
182+
ReportOverlap);
188183

189-
/// For use in the \c ReportOverlap callback of \c calculateBindingInfo -
190-
/// finds a binding that the \c ReportedBinding overlaps with.
191-
LLVM_ABI const Binding &
192-
findOverlapping(const Binding &ReportedBinding) const;
193-
};
184+
/// For use in the \c ReportOverlap callback of \c calculateBindingInfo -
185+
/// finds a binding that the \c ReportedBinding overlaps with.
186+
LLVM_ABI const Binding &
187+
findOverlapping(const Binding &ReportedBinding) const;
188+
};
194189

195190
} // namespace hlsl
196191
} // namespace llvm

llvm/lib/Frontend/HLSL/HLSLBinding.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,6 @@ BindingInfo::RegisterSpace::findAvailableBinding(int32_t Size) {
7676
return std::nullopt;
7777
}
7878

79-
bool BindingInfo::RegisterSpace::isBound(const BindingRange &Range) const {
80-
const BindingRange *It = llvm::lower_bound(
81-
FreeRanges, Range.LowerBound,
82-
[](const BindingRange &R, uint32_t Val) { return R.UpperBound <= Val; });
83-
84-
if (It == FreeRanges.end())
85-
return true;
86-
return ((Range.LowerBound < It->LowerBound) &&
87-
(Range.UpperBound < It->LowerBound)) ||
88-
((Range.LowerBound > It->UpperBound) &&
89-
(Range.UpperBound > It->UpperBound));
90-
}
91-
92-
bool BindingInfo::isBound(dxil::ResourceClass RC, uint32_t Space,
93-
const BindingRange &Range) const {
94-
const BindingSpaces &BS = getBindingSpaces(RC);
95-
std::optional<const BindingInfo::RegisterSpace *> RS = BS.contains(Space);
96-
if (!RS)
97-
return false;
98-
return RS.value()->isBound(Range);
99-
}
100-
10179
BindingInfo BindingInfoBuilder::calculateBindingInfo(
10280
llvm::function_ref<void(const BindingInfoBuilder &Builder,
10381
const Binding &Overlapping)>

0 commit comments

Comments
 (0)