@@ -823,71 +823,73 @@ static bool isUpdateCounterIntrinsic(Function &F) {
823823 return F.getIntrinsicID () == Intrinsic::dx_resource_updatecounter;
824824}
825825
826- void DXILResourceCounterDirectionMap::populate (Module &M, ModuleAnalysisManager &AM) {
827- DXILBindingMap &DBM = AM.getResult <DXILResourceBindingAnalysis>(M);
828- CounterDirections.clear ();
829-
830- for (Function &F : M.functions ()) {
831- if (!isUpdateCounterIntrinsic (F))
832- continue ;
833-
834- for (const User *U : F.users ()) {
835- const CallInst *CI = dyn_cast<CallInst>(U);
836- assert (CI && " Users of dx_resource_updateCounter must be call instrs" );
837-
838- // Determine if the use is an increment or decrement
839- Value *CountArg = CI->getArgOperand (1 );
840- ConstantInt *CountValue = dyn_cast<ConstantInt>(CountArg);
841- int64_t CountLiteral = CountValue->getSExtValue ();
842-
843- ResourceCounterDirection Direction = ResourceCounterDirection::Unknown;
844- if (CountLiteral > 0 ) {
845- Direction = ResourceCounterDirection::Increment;
846- }
847- if (CountLiteral < 0 ) {
848- Direction = ResourceCounterDirection::Decrement;
849- }
826+ void DXILResourceCounterDirectionMap::populate (Module &M,
827+ ModuleAnalysisManager &AM) {
828+ DXILBindingMap &DBM = AM.getResult <DXILResourceBindingAnalysis>(M);
829+ CounterDirections.clear ();
850830
831+ for (Function &F : M.functions ()) {
832+ if (!isUpdateCounterIntrinsic (F))
833+ continue ;
851834
852- // Collect all potential creation points for the handle arg
853- Value *HandleArg = CI->getArgOperand (0 );
854- SmallVector<dxil::ResourceBindingInfo> RBInfos = DBM.findByUse (HandleArg);
855- for (const dxil::ResourceBindingInfo RBInfo : RBInfos) {
856- CounterDirections.emplace_back (RBInfo, Direction);
857- }
835+ for (const User *U : F.users ()) {
836+ const CallInst *CI = dyn_cast<CallInst>(U);
837+ assert (CI && " Users of dx_resource_updateCounter must be call instrs" );
838+
839+ // Determine if the use is an increment or decrement
840+ Value *CountArg = CI->getArgOperand (1 );
841+ ConstantInt *CountValue = dyn_cast<ConstantInt>(CountArg);
842+ int64_t CountLiteral = CountValue->getSExtValue ();
843+
844+ ResourceCounterDirection Direction = ResourceCounterDirection::Unknown;
845+ if (CountLiteral > 0 ) {
846+ Direction = ResourceCounterDirection::Increment;
847+ }
848+ if (CountLiteral < 0 ) {
849+ Direction = ResourceCounterDirection::Decrement;
850+ }
851+
852+ // Collect all potential creation points for the handle arg
853+ Value *HandleArg = CI->getArgOperand (0 );
854+ SmallVector<dxil::ResourceBindingInfo> RBInfos = DBM.findByUse (HandleArg);
855+ for (const dxil::ResourceBindingInfo RBInfo : RBInfos) {
856+ CounterDirections.emplace_back (RBInfo, Direction);
858857 }
859858 }
859+ }
860860
861- // An entry that is not in the map is considered unknown so its wasted
862- // overhead and increased complexity to keep it so it should be removed.
863- const auto RemoveEnd = std::remove_if (CounterDirections.begin (), CounterDirections.end (), [](const auto & Item) {
864- return Item.second == ResourceCounterDirection::Unknown;
865- });
861+ // An entry that is not in the map is considered unknown so its wasted
862+ // overhead and increased complexity to keep it so it should be removed.
863+ const auto RemoveEnd = std::remove_if (
864+ CounterDirections.begin (), CounterDirections.end (), [](const auto &Item) {
865+ return Item.second == ResourceCounterDirection::Unknown;
866+ });
866867
867- // Order for fast lookup
868- std::sort (CounterDirections.begin (), RemoveEnd);
868+ // Order for fast lookup
869+ std::sort (CounterDirections.begin (), RemoveEnd);
869870
870- // Remove the duplicate entries. Since direction is considered for equality
871- // a unique resource with more than one direction will not be deduped.
872- const auto UniqueEnd = std::unique (CounterDirections.begin (), RemoveEnd);
871+ // Remove the duplicate entries. Since direction is considered for equality
872+ // a unique resource with more than one direction will not be deduped.
873+ const auto UniqueEnd = std::unique (CounterDirections.begin (), RemoveEnd);
873874
874- // Actually erase the items invalidated by remove_if + unique
875- CounterDirections.erase (UniqueEnd, CounterDirections.end ());
875+ // Actually erase the items invalidated by remove_if + unique
876+ CounterDirections.erase (UniqueEnd, CounterDirections.end ());
876877
877- // If any duplicate entries still exist at this point then it must be a
878- // resource that was both incremented and decremented which is not allowed.
879- const auto DuplicateEntry = std::adjacent_find (CounterDirections. begin (), CounterDirections. end (), []( const auto & LHS, const auto & RHS){
880- return LHS. first == RHS. first ;
881- });
882- if (DuplicateEntry == CounterDirections.end ())
883- return ;
878+ // If any duplicate entries still exist at this point then it must be a
879+ // resource that was both incremented and decremented which is not allowed.
880+ const auto DuplicateEntry = std::adjacent_find (
881+ CounterDirections. begin (), CounterDirections. end (),
882+ []( const auto &LHS, const auto &RHS) { return LHS. first == RHS. first ; });
883+ if (DuplicateEntry == CounterDirections.end ())
884+ return ;
884885
885- // TODO: Emit an error message
886- assert (CounterDirections.size () == 1 && " dups found" );
886+ // TODO: Emit an error message
887+ assert (CounterDirections.size () == 1 && " dups found" );
887888}
888889
889- bool DXILResourceCounterDirectionMap::invalidate (Module &M, const PreservedAnalyses &PA,
890- ModuleAnalysisManager::Invalidator &Inv) {
890+ bool DXILResourceCounterDirectionMap::invalidate (
891+ Module &M, const PreservedAnalyses &PA,
892+ ModuleAnalysisManager::Invalidator &Inv) {
891893 // Passes that introduce resource types must explicitly invalidate this pass.
892894 // auto PAC = PA.getChecker<DXILResourceTypeAnalysis>();
893895 // return !PAC.preservedWhenStateless();
@@ -919,10 +921,13 @@ DXILResourceBindingPrinterPass::run(Module &M, ModuleAnalysisManager &AM) {
919921 return PreservedAnalyses::all ();
920922}
921923
922- INITIALIZE_PASS (DXILResourceCounterDirectionWrapperPass, " dxil-resource-counter" ,
923- " DXIL Resource Counter Analysis" , false , true )
924+ INITIALIZE_PASS (DXILResourceCounterDirectionWrapperPass,
925+ " dxil-resource-counter" , " DXIL Resource Counter Analysis" ,
926+ false , true )
924927
925- DXILResourceCounterDirectionWrapperPass::DXILResourceCounterDirectionWrapperPass() : ImmutablePass(ID) {
928+ DXILResourceCounterDirectionWrapperPass::
929+ DXILResourceCounterDirectionWrapperPass()
930+ : ImmutablePass(ID) {
926931 initializeDXILResourceTypeWrapperPassPass (*PassRegistry::getPassRegistry ());
927932}
928933
0 commit comments