22#include "llvm/IR/IntrinsicsSPIRV.h"
27#define DEBUG_TYPE "spirv-remove-unused-resources"
32 "disable-spirv-remove-unused-resources",
47 switch (
II->getIntrinsicID()) {
50 case Intrinsic::spv_resource_handlefrombinding:
51 case Intrinsic::spv_resource_handlefromimplicitbinding:
54 case Intrinsic::spv_resource_counterhandlefrombinding:
55 case Intrinsic::spv_resource_counterhandlefromimplicitbinding:
65 auto VisitHandle = [&](
Instruction *Handle,
bool IsCounter) {
68 if (!
SI ||
SI->isVolatile() ||
SI->getValueOperand() != Handle)
71 if (!GV || !GV->hasLocalLinkage() || !GV->hasOneUser())
73 SI->eraseFromParent();
78 const unsigned ResourceNameOpIndex = 4;
92 for (
auto *Counter : CounterHandles)
93 VisitHandle(Counter,
true);
94 for (
auto *Handle : Handles)
95 VisitHandle(Handle,
false);
97 for (
auto *GV : DeadGlobals) {
98 if (GV->user_empty()) {
99 GV->eraseFromParent();
114class SPIRVRemoveUnusedResourcesLegacy :
public ModulePass {
116 SPIRVRemoveUnusedResourcesLegacy() :
ModulePass(ID) {}
120 StringRef getPassName()
const override {
121 return "SPIRV Remove Unused Resources";
126char SPIRVRemoveUnusedResourcesLegacy::ID = 0;
130 "SPIRV Remove Unused Resources",
false,
false)
133 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)
static cl::opt< bool > DisableSPIRVRemoveUnusedResources("disable-spirv-remove-unused-resources", cl::desc("Disable spirv-remove-unused-resources pass"), cl::init(false), cl::Hidden)
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
initializer< Ty > init(const Ty &Val)
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.