19#include "llvm/IR/IntrinsicsDirectX.h"
24#define DEBUG_TYPE "dxil-remove-unused-resources"
29 "disable-dxil-remove-unused-resources",
36 return ID == Intrinsic::dx_resource_handlefrombinding ||
37 ID == Intrinsic::dx_resource_handlefromimplicitbinding ||
38 ID == Intrinsic::dx_resource_handlefromheap;
56 if (
II->user_empty()) {
61 if (!
II->hasOneUser())
71 "expected value operand to be the resource handle");
79 "expected single user to be the store instruction");
88 if (DeadInstr.
empty())
91 for (
auto *Instr : DeadInstr) {
95 if (
II->getIntrinsicID() == Intrinsic::dx_resource_handlefromheap)
97 const unsigned ResourceNameOpIndex = 4;
99 II->getArgOperand(ResourceNameOpIndex));
101 DeadGlobals.
insert(ResourceName);
103 Instr->eraseFromParent();
106 for (
auto *GV : DeadGlobals)
108 GV->eraseFromParent();
120class DXILRemoveUnusedResourcesLegacy :
public FunctionPass {
124 return "DXIL Remove Unused Resources";
126 DXILRemoveUnusedResourcesLegacy() : FunctionPass(
ID) {}
129 void getAnalysisUsage(llvm::AnalysisUsage &AU)
const override {
133char DXILRemoveUnusedResourcesLegacy::ID = 0;
137 "DXIL Remove Unused Resources",
false,
false)
143 return new DXILRemoveUnusedResourcesLegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static llvm::cl::opt< bool > DisableDXILRemoveUnusedResources("disable-dxil-remove-unused-resources", llvm::cl::desc("Disable dxil-remove-unused-resources pass"), llvm::cl::init(false), llvm::cl::Hidden)
static bool removeUnusedResources(Function &F)
static bool isResourceHandleCreation(Intrinsic::ID ID)
static bool runOnFunction(Function &F, bool PostInlining)
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file implements a set that has insertion order iteration characteristics.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM Basic Block Representation.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
FunctionPass class - This class is used to implement most global optimizations.
bool hasExternalLinkage() const
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
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.
Represent a constant reference to a string, i.e.
user_iterator user_begin()
LLVM_ABI bool hasOneUser() const
Return true if there is exactly one user of this value.
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...
auto dyn_cast_or_null(const Y &Val)
FunctionPass * createDXILRemoveUnusedResourcesLegacyPass()
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.