Skip to content

Commit 28e7369

Browse files
committed
format
1 parent ee05b44 commit 28e7369

File tree

3 files changed

+80
-66
lines changed

3 files changed

+80
-66
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,18 +418,21 @@ enum ResourceCounterDirection {
418418
};
419419

420420
class DXILResourceCounterDirectionMap {
421-
std::vector<std::pair<dxil::ResourceBindingInfo, ResourceCounterDirection>> CounterDirections;
421+
std::vector<std::pair<dxil::ResourceBindingInfo, ResourceCounterDirection>>
422+
CounterDirections;
422423

423424
public:
424425
bool invalidate(Module &M, const PreservedAnalyses &PA,
425426
ModuleAnalysisManager::Invalidator &Inv);
426427

427-
void populate(Module &M, ModuleAnalysisManager &AM);
428+
void populate(Module &M, ModuleAnalysisManager &AM);
428429

429-
ResourceCounterDirection operator[](const dxil::ResourceBindingInfo &Info) const {
430-
auto Lower = std::lower_bound(CounterDirections.begin(), CounterDirections.end(), std::pair{Info, ResourceCounterDirection::Unknown}, [](auto lhs, auto rhs){
431-
return lhs.first < rhs.first;
432-
});
430+
ResourceCounterDirection
431+
operator[](const dxil::ResourceBindingInfo &Info) const {
432+
auto Lower = std::lower_bound(
433+
CounterDirections.begin(), CounterDirections.end(),
434+
std::pair{Info, ResourceCounterDirection::Unknown},
435+
[](auto lhs, auto rhs) { return lhs.first < rhs.first; });
433436

434437
if (Lower == CounterDirections.end()) {
435438
return ResourceCounterDirection::Unknown;
@@ -440,7 +443,7 @@ class DXILResourceCounterDirectionMap {
440443
}
441444

442445
return Lower->second;
443-
}
446+
}
444447
};
445448

446449
class DXILResourceCounterDirectionAnalysis
@@ -468,8 +471,13 @@ class DXILResourceCounterDirectionWrapperPass : public ImmutablePass {
468471
static char ID;
469472
DXILResourceCounterDirectionWrapperPass();
470473

471-
DXILResourceCounterDirectionMap &getResourceCounterDirectionMap() { return DRCDM; }
472-
const DXILResourceCounterDirectionMap &getResourceCounterDirectionMap() const { return DRCDM; }
474+
DXILResourceCounterDirectionMap &getResourceCounterDirectionMap() {
475+
return DRCDM;
476+
}
477+
const DXILResourceCounterDirectionMap &
478+
getResourceCounterDirectionMap() const {
479+
return DRCDM;
480+
}
473481
};
474482

475483
ModulePass *createDXILResourceCounterDirectionWrapperPassPass();

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -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

llvm/unittests/Target/DirectX/UniqueResourceFromUseTests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ declare void @a.func(target("dx.RawBuffer", float, 1, 0) %handle)
307307
ASSERT_TRUE(M) << "Bad assembly?";
308308

309309
const DXILBindingMap &DBM = MAM->getResult<DXILResourceBindingAnalysis>(*M);
310-
const DXILResourceCounterDirectionMap &DCDM = MAM->getResult<DXILResourceCounterDirectionAnalysis>(*M);
310+
const DXILResourceCounterDirectionMap &DCDM =
311+
MAM->getResult<DXILResourceCounterDirectionAnalysis>(*M);
311312

312313
for (const Function &F : M->functions()) {
313314
if (F.getName() != "a.func") {

0 commit comments

Comments
 (0)