@@ -898,12 +898,33 @@ void DXILResourceCounterDirectionMap::populate(Module &M, DXILBindingMap &DBM) {
898
898
899
899
// If any duplicate entries still exist at this point then it must be a
900
900
// resource that was both incremented and decremented which is not allowed.
901
- const auto DuplicateEntry =
902
- std::adjacent_find (DiagCounterDirs.begin (), DiagCounterDirs.end (),
903
- [](const auto &LHS, const auto &RHS) {
904
- return std::get<dxil::ResourceBindingInfo>(LHS) ==
905
- std::get<dxil::ResourceBindingInfo>(RHS);
906
- });
901
+ // Mark all those entries as invalid.
902
+ {
903
+ auto DupFirst = DiagCounterDirs.begin ();
904
+ auto DupNext = DupFirst + 1 ;
905
+ auto DupLast = DiagCounterDirs.end ();
906
+ for (; DupFirst < DupLast && DupNext < DupLast; ++DupFirst, ++DupNext) {
907
+ if (std::get<dxil::ResourceBindingInfo>(*DupFirst) == std::get<dxil::ResourceBindingInfo>(*DupNext)) {
908
+ std::get<ResourceCounterDirection>(*DupFirst) = ResourceCounterDirection::MyInvalid;
909
+ std::get<ResourceCounterDirection>(*DupNext) = ResourceCounterDirection::MyInvalid;
910
+ }
911
+ }
912
+ }
913
+
914
+ // Raise an error for every invalid entry
915
+ for (const auto Entry : DiagCounterDirs) {
916
+ ResourceCounterDirection Dir = std::get<ResourceCounterDirection>(Entry);
917
+ const Function *F = std::get<const Function *>(Entry);
918
+ const CallInst *CI = std::get<const CallInst *>(Entry);
919
+
920
+ if (Dir != ResourceCounterDirection::MyInvalid)
921
+ continue ;
922
+
923
+ StringRef Message = " RWStructuredBuffers may increment or decrement their "
924
+ " counters, but not both." ;
925
+ M.getContext ().diagnose (
926
+ DiagnosticInfoGenericWithLoc (Message, *F, CI->getDebugLoc ()));
927
+ }
907
928
908
929
// Copy the results into the final vec
909
930
CounterDirections.clear ();
@@ -913,16 +934,6 @@ void DXILResourceCounterDirectionMap::populate(Module &M, DXILBindingMap &DBM) {
913
934
return std::pair{std::get<dxil::ResourceBindingInfo>(Item),
914
935
std::get<ResourceCounterDirection>(Item)};
915
936
});
916
-
917
- if (DuplicateEntry == DiagCounterDirs.end ())
918
- return ;
919
-
920
- const Function *F = std::get<const Function *>(*DuplicateEntry);
921
- const CallInst *CI = std::get<const CallInst *>(*DuplicateEntry);
922
- StringRef Message = " RWStructuredBuffers may increment or decrement their "
923
- " counters, but not both." ;
924
- M.getContext ().diagnose (
925
- DiagnosticInfoGenericWithLoc (Message, *F, CI->getDebugLoc ()));
926
937
}
927
938
928
939
void DXILResourceCounterDirectionWrapperPass::getAnalysisUsage (
0 commit comments