36#include "llvm/IR/IntrinsicsSPIRV.h"
41#define DEBUG_TYPE "spirv-cbuffer-access"
58 std::optional<hlsl::CBufferMetadata> CBufMD =
61 return TET->getName() ==
"spirv.Padding";
70 CBufferHandles.
insert(Mapping.Handle);
80 Mapping.Handle->getName());
88 const StructLayout *SL = M.getDataLayout().getStructLayout(LayoutTy);
99 Value *IndexVal = Builder.getInt32(IndexInStruct);
101 Value *GetPointerCall = Builder.CreateIntrinsic(
102 PtrType, Intrinsic::spv_resource_getpointer, {HandleDef, IndexVal});
111 return GV && CBufferHandles.
contains(GV);
114 HandleGV->removeDeadConstantUsers();
118 for (
const auto &Member : Mapping.Members) {
119 Member.GV->eraseFromParent();
123 for (
User *U : Mapping.Handle->
users()) {
129 I->eraseFromParent();
131 Mapping.Handle->eraseFromParent();
134 CBufMD->eraseFromModule();
147class SPIRVCBufferAccessLegacy :
public ModulePass {
150 StringRef getPassName()
const override {
return "SPIRV CBuffer Access"; }
151 SPIRVCBufferAccessLegacy() : ModulePass(
ID) {}
155char SPIRVCBufferAccessLegacy::ID = 0;
162 return new SPIRVCBufferAccessLegacy();
static bool replaceCBufferAccesses(Module &M)
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool replaceCBufferAccesses(Module &M)
static Instruction * findHandleDef(GlobalVariable *HandleVar)
This is an important base class in LLVM.
PointerType * getType() const
Global values are always pointers.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
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)
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.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
LLVM_ABI unsigned getElementContainingOffset(uint64_t FixedOffset) const
Given a valid byte offset into the structure, returns the structure index that contains it.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
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.
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.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI void removeFromUsedLists(Module &M, function_ref< bool(Constant *)> ShouldRemove)
Removes global values from the llvm.used and llvm.compiler.used arrays.
ModulePass * createSPIRVCBufferAccessLegacyPass()
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.