-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL] Analyze updateCounter usage #135669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -697,8 +697,12 @@ bool DXILResourceTypeMap::invalidate(Module &M, const PreservedAnalyses &PA, | |
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
static bool isUpdateCounterIntrinsic(Function &F) { | ||
return F.getIntrinsicID() == Intrinsic::dx_resource_updatecounter; | ||
} | ||
|
||
void DXILResourceMap::populate(Module &M, DXILResourceTypeMap &DRTM) { | ||
void DXILResourceMap::populateResourceInfos(Module &M, | ||
DXILResourceTypeMap &DRTM) { | ||
SmallVector<std::tuple<CallInst *, ResourceInfo, ResourceTypeInfo>> CIToInfos; | ||
|
||
for (Function &F : M.functions()) { | ||
|
@@ -777,6 +781,48 @@ void DXILResourceMap::populate(Module &M, DXILResourceTypeMap &DRTM) { | |
} | ||
} | ||
|
||
void DXILResourceMap::populateCounterDirections(Module &M) { | ||
for (Function &F : M.functions()) { | ||
if (!isUpdateCounterIntrinsic(F)) | ||
continue; | ||
|
||
LLVM_DEBUG(dbgs() << "Update Counter Function: " << F.getName() << "\n"); | ||
|
||
for (const User *U : F.users()) { | ||
const CallInst *CI = dyn_cast<CallInst>(U); | ||
assert(CI && "Users of dx_resource_updateCounter must be call instrs"); | ||
|
||
// Determine if the use is an increment or decrement | ||
Value *CountArg = CI->getArgOperand(1); | ||
ConstantInt *CountValue = cast<ConstantInt>(CountArg); | ||
int64_t CountLiteral = CountValue->getSExtValue(); | ||
|
||
// 0 is an unknown direction and shouldn't result in an insert | ||
if (CountLiteral == 0) | ||
continue; | ||
|
||
ResourceCounterDirection Direction = ResourceCounterDirection::Decrement; | ||
if (CountLiteral > 0) | ||
Direction = ResourceCounterDirection::Increment; | ||
|
||
// Collect all potential creation points for the handle arg | ||
Value *HandleArg = CI->getArgOperand(0); | ||
SmallVector<ResourceInfo *> RBInfos = findByUse(HandleArg); | ||
for (ResourceInfo *RBInfo : RBInfos) { | ||
if (RBInfo->CounterDirection == ResourceCounterDirection::Unknown) | ||
RBInfo->CounterDirection = Direction; | ||
else if (RBInfo->CounterDirection != Direction) | ||
RBInfo->CounterDirection = ResourceCounterDirection::Invalid; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this case mean? The CounterDirection was previously set and was wrong? Or there is conflicting information? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conflicting information! If CounterDirection is detected as both Increment and Decrement that is considered invalid (because only one direction is allowed) |
||
} | ||
} | ||
} | ||
} | ||
|
||
void DXILResourceMap::populate(Module &M, DXILResourceTypeMap &DRTM) { | ||
populateResourceInfos(M, DRTM); | ||
populateCounterDirections(M); | ||
} | ||
|
||
void DXILResourceMap::print(raw_ostream &OS, DXILResourceTypeMap &DRTM, | ||
const DataLayout &DL) const { | ||
for (unsigned I = 0, E = Infos.size(); I != E; ++I) { | ||
|
@@ -793,10 +839,9 @@ void DXILResourceMap::print(raw_ostream &OS, DXILResourceTypeMap &DRTM, | |
} | ||
} | ||
|
||
SmallVector<dxil::ResourceInfo> | ||
DXILResourceMap::findByUse(const Value *Key) const { | ||
SmallVector<dxil::ResourceInfo *> DXILResourceMap::findByUse(const Value *Key) { | ||
if (const PHINode *Phi = dyn_cast<PHINode>(Key)) { | ||
SmallVector<dxil::ResourceInfo> Children; | ||
SmallVector<dxil::ResourceInfo *> Children; | ||
for (const Value *V : Phi->operands()) { | ||
Children.append(findByUse(V)); | ||
} | ||
|
@@ -810,9 +855,9 @@ DXILResourceMap::findByUse(const Value *Key) const { | |
switch (CI->getIntrinsicID()) { | ||
// Found the create, return the binding | ||
case Intrinsic::dx_resource_handlefrombinding: { | ||
const auto *It = find(CI); | ||
hekota marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(It != Infos.end() && "HandleFromBinding must be in resource map"); | ||
return {*It}; | ||
auto Pos = CallMap.find(CI); | ||
V-FEXrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(Pos != CallMap.end() && "HandleFromBinding must be in resource map"); | ||
return {&Infos[Pos->second]}; | ||
} | ||
default: | ||
break; | ||
|
@@ -821,7 +866,7 @@ DXILResourceMap::findByUse(const Value *Key) const { | |
// Check if any of the parameters are the resource we are following. If so | ||
// keep searching. If none of them are return an empty list | ||
const Type *UseType = CI->getType(); | ||
SmallVector<dxil::ResourceInfo> Children; | ||
SmallVector<dxil::ResourceInfo *> Children; | ||
for (const Value *V : CI->args()) { | ||
if (V->getType() != UseType) | ||
continue; | ||
|
Uh oh!
There was an error while loading. Please reload this page.