20#include "llvm/IR/IntrinsicsDirectX.h"
25#define DEBUG_TYPE "dxil-remove-unused-resources"
30 "disable-dxil-remove-unused-resources",
49 if (
II->getIntrinsicID() != Intrinsic::dx_resource_handlefrombinding &&
50 II->getIntrinsicID() !=
51 Intrinsic::dx_resource_handlefromimplicitbinding)
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) {
90 assert(
II->getIntrinsicID() == Intrinsic::dx_resource_handlefrombinding ||
91 II->getIntrinsicID() ==
92 Intrinsic::dx_resource_handlefromimplicitbinding);
93 const unsigned ResourceNameOpIndex = 4;
95 II->getArgOperand(ResourceNameOpIndex));
97 DeadGlobals.
insert(ResourceName);
99 Instr->eraseFromParent();
102 for (
auto *GV : DeadGlobals)
104 GV->eraseFromParent();
116class DXILRemoveUnusedResourcesLegacy :
public FunctionPass {
120 return "DXIL Remove Unused Resources";
122 DXILRemoveUnusedResourcesLegacy() : FunctionPass(
ID) {}
125 void getAnalysisUsage(llvm::AnalysisUsage &AU)
const override {
129char DXILRemoveUnusedResourcesLegacy::ID = 0;
133 "DXIL Remove Unused Resources",
false,
false)
139 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 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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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()
Pass to update remove unsused resources.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.