16#include "llvm/IR/IntrinsicsDirectX.h"
24#define DEBUG_TYPE "dxil-cbuffer-access"
32 assert(UseInst &&
"Non-instruction use of cbuffer");
37 Value *Ptr = Builder.CreateIntrinsic(
38 Global->getType(), Intrinsic::dx_resource_getpointer,
40 ConstantInt::get(Builder.getInt32Ty(), Offset)});
44 Global->removeFromParent();
56 CBufferHandles.
insert(Mapping.Handle);
69 return GV && CBufferHandles.
contains(GV);
72 HandleGV->removeDeadConstantUsers();
74 CBufMD->eraseFromModule();
88class DXILCBufferAccessLegacy :
public ModulePass {
91 StringRef getPassName()
const override {
return "DXIL CBuffer Access"; }
92 DXILCBufferAccessLegacy() : ModulePass(
ID) {}
96char DXILCBufferAccessLegacy::ID = 0;
103 return new DXILCBufferAccessLegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool replaceCBufferAccesses(Module &M)
static void replaceUsersOfGlobal(GlobalVariable *Global, GlobalVariable *HandleGV, size_t Offset)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
This is an important base class in LLVM.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Type * getValueType() const
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
An instruction for reading from memory.
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 all()
Construct a special preserved set that preserves all passes.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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.
The instances of the Type class are immutable: once they are created, they are never changed.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
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 * createDXILCBufferAccessLegacyPass()
Pass to translate loads in the cbuffer address space to intrinsics.
LLVM_ABI bool convertUsersOfConstantsToInstructions(ArrayRef< Constant * > Consts, Function *RestrictToFunc=nullptr, bool RemoveDeadConstants=true, bool IncludeSelf=false)
Replace constant expressions users of the given constants with instructions.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI void removeFromUsedLists(Module &M, function_ref< bool(Constant *)> ShouldRemove)
Removes global values from the llvm.used and llvm.compiler.used arrays.
@ Global
Append to llvm.global_dtors.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.