[llvm] [HLSL] Diagnose overlapping resource bindings (PR #140982)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Thu May 29 13:59:41 PDT 2025
================
@@ -50,15 +51,55 @@ static void reportInvalidDirection(Module &M, DXILResourceMap &DRM) {
}
}
-} // namespace
+static void reportOverlappingError(Module &M, ResourceInfo R1,
+ ResourceInfo R2) {
+ SmallString<64> Message;
+ raw_svector_ostream OS(Message);
+ OS << "resource " << R1.getName() << " at register "
+ << R1.getBinding().LowerBound << " overlaps with resource " << R2.getName()
+ << " at register " << R2.getBinding().LowerBound << ", space "
+ << R2.getBinding().Space;
+ M.getContext().diagnose(DiagnosticInfoGeneric(Message));
+}
-PreservedAnalyses
-DXILPostOptimizationValidation::run(Module &M, ModuleAnalysisManager &MAM) {
- DXILResourceMap &DRM = MAM.getResult<DXILResourceAnalysis>(M);
+static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM) {
+ if (DRM.empty())
+ return;
+ for (auto ResList :
+ {DRM.srvs(), DRM.uavs(), DRM.cbuffers(), DRM.samplers()}) {
+ if (ResList.empty())
+ continue;
+ const ResourceInfo *PrevRI = &*ResList.begin();
+ for (auto *I = ResList.begin() + 1; I != ResList.end(); ++I) {
+ const ResourceInfo *RI = &*I;
+ if (PrevRI->getBinding().overlapsWith(RI->getBinding())) {
+ reportOverlappingError(M, *PrevRI, *RI);
+ continue;
----------------
bogner wrote:
I'm not sure there's a "correct" answer here, but choosing to continue here makes one case better at the cost of another. Just to confirm the behaviour:
- If we have ranges 1-5, 2-3, and 2-5, we'll refer to the first range instead of the second in the error about the third. This seems fairly neutral / fine either way
- If we have ranges 1-5, 2-3, and 4-5, we'll report an error about the third range, where we wouldn't if we did this the other way
- If we have ranges 1-5, 2-7, and 6-8, we won't report an error about the third range, where we would if we did this the other way
Is this what we want? I suppose it's probably reasonable. Could you make sure there's a test that demonstrates this choice is intentional please?
https://github.com/llvm/llvm-project/pull/140982
More information about the llvm-commits
mailing list