23#include "llvm/IR/IntrinsicsSPIRV.h"
27#define DEBUG_TYPE "spirv-remove-unused-resources"
35 .enable_remove_unused_resources)
45 switch (
II->getIntrinsicID()) {
48 case Intrinsic::spv_resource_handlefrombinding:
49 case Intrinsic::spv_resource_handlefromimplicitbinding:
52 case Intrinsic::spv_resource_counterhandlefrombinding:
53 case Intrinsic::spv_resource_counterhandlefromimplicitbinding:
63 auto VisitHandle = [&](
Instruction *Handle,
bool IsCounter) {
66 if (!
SI ||
SI->isVolatile() ||
SI->getValueOperand() != Handle)
69 if (!GV || !GV->hasLocalLinkage() || !GV->hasOneUser())
71 SI->eraseFromParent();
76 const unsigned ResourceNameOpIndex = 4;
90 for (
auto *Counter : CounterHandles)
91 VisitHandle(Counter,
true);
92 for (
auto *Handle : Handles)
93 VisitHandle(Handle,
false);
95 for (
auto *GV : DeadGlobals) {
96 if (GV->user_empty()) {
97 GV->eraseFromParent();
112class SPIRVRemoveUnusedResourcesLegacy :
public ModulePass {
114 SPIRVRemoveUnusedResourcesLegacy() :
ModulePass(ID) {}
118 StringRef getPassName()
const override {
119 return "SPIRV Remove Unused Resources";
124char SPIRVRemoveUnusedResourcesLegacy::ID = 0;
128 "SPIRV Remove Unused Resources",
false,
false)
131 return new SPIRVRemoveUnusedResourcesLegacy();
Expand Atomic instructions
static bool removeUnusedResources(Function &F)
Module.h This file contains the declarations for the Module class.
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool removeUnusedResources(Module &M)
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
iterator_range< user_iterator > users()
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Value * getOperand(unsigned i) const
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
ModulePass * createSPIRVRemoveUnusedResourcesLegacyPass()
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.