20#include "llvm/IR/IntrinsicsDirectX.h"
25#define DEBUG_TYPE "dxil-remove-unused-resources"
30 return ID == Intrinsic::dx_resource_handlefrombinding ||
31 ID == Intrinsic::dx_resource_handlefromimplicitbinding ||
32 ID == Intrinsic::dx_resource_handlefromheap;
42 .get<DirectXMCOptions>()
43 .remove_unused_resources)
53 if (
II->user_empty()) {
58 if (!
II->hasOneUser())
68 "expected value operand to be the resource handle");
76 "expected single user to be the store instruction");
85 if (DeadInstr.
empty())
88 for (
auto *Instr : DeadInstr) {
92 if (
II->getIntrinsicID() == Intrinsic::dx_resource_handlefromheap)
94 const unsigned ResourceNameOpIndex = 4;
96 II->getArgOperand(ResourceNameOpIndex));
98 DeadGlobals.
insert(ResourceName);
100 Instr->eraseFromParent();
103 for (
auto *GV : DeadGlobals)
105 GV->eraseFromParent();
117class DXILRemoveUnusedResourcesLegacy :
public FunctionPass {
121 return "DXIL Remove Unused Resources";
123 DXILRemoveUnusedResourcesLegacy() : FunctionPass(
ID) {}
126 void getAnalysisUsage(llvm::AnalysisUsage &AU)
const override {
130char DXILRemoveUnusedResourcesLegacy::ID = 0;
134 "DXIL Remove Unused Resources",
false,
false)
140 return new DXILRemoveUnusedResourcesLegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
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.