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_mdname:
49 case Intrinsic::spv_resource_handlefromimplicitbinding_mdname:
52 case Intrinsic::spv_resource_counterhandlefrombinding:
53 case Intrinsic::spv_resource_counterhandlefromimplicitbinding:
66 if (!
SI ||
SI->isVolatile() ||
SI->getValueOperand() != Handle)
69 if (!GV || !GV->hasLocalLinkage() || !GV->hasOneUser())
71 SI->eraseFromParent();
76 if (Handle->use_empty()) {
77 Handle->eraseFromParent();
84 for (
auto *Counter : CounterHandles)
86 for (
auto *Handle : Handles)
89 for (
auto *GV : DeadGlobals) {
90 if (GV->user_empty()) {
91 GV->eraseFromParent();
106class SPIRVRemoveUnusedResourcesLegacy :
public ModulePass {
108 SPIRVRemoveUnusedResourcesLegacy() :
ModulePass(ID) {}
112 StringRef getPassName()
const override {
113 return "SPIRV Remove Unused Resources";
118char SPIRVRemoveUnusedResourcesLegacy::ID = 0;
122 "SPIRV Remove Unused Resources",
false,
false)
125 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.
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.
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.