LLVM: lib/Target/SPIRV/SPIRVCBufferAccess.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
36#include "llvm/IR/IntrinsicsSPIRV.h"
39
40#define DEBUG_TYPE "spirv-cbuffer-access"
41using namespace llvm;
42
43
44
46 for (User *U : HandleVar->users()) {
49 return I;
50 }
51 }
52 }
53 return nullptr;
54}
55
57 std::optionalhlsl::CBufferMetadata CBufMD =
60 return TET->getName() == "spirv.Padding";
61 return false;
62 });
63 if (!CBufMD)
64 return false;
65
69 CBufferGlobals.push_back(Member.GV);
71
74 if (!HandleDef) {
76 Mapping.Handle->getName());
77 }
78
79
80
83 auto *LayoutTy = cast(HandleTy->getTypeParameter(0));
84 const StructLayout *SL = M.getDataLayout().getStructLayout(LayoutTy);
85
89 continue;
90 }
91
93
94
95 Value *IndexVal = Builder.getInt32(IndexInStruct);
97 Value *GetPointerCall = Builder.CreateIntrinsic(
98 PtrType, Intrinsic::spv_resource_getpointer, {HandleDef, IndexVal});
99
101 }
102 }
103
104
106 for (const auto &Member : Mapping.Members) {
107 Member.GV->eraseFromParent();
108 }
109
111 for (User *U : Mapping.Handle->users()) {
114 }
115 }
117 I->eraseFromParent();
118 }
119 Mapping.Handle->eraseFromParent();
120 }
121
122 CBufMD->eraseFromModule();
123 return true;
124}
125
133
134namespace {
135class SPIRVCBufferAccessLegacy : public ModulePass {
136public:
138 StringRef getPassName() const override { return "SPIRV CBuffer Access"; }
139 SPIRVCBufferAccessLegacy() : ModulePass(ID) {}
140
141 static char ID;
142};
143char SPIRVCBufferAccessLegacy::ID = 0;
144}
145
147 false, false)
148
150 return new SPIRVCBufferAccessLegacy();
151}
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)
Definition SPIRVCBufferAccess.cpp:56
static Instruction * findHandleDef(GlobalVariable *HandleVar)
Definition SPIRVCBufferAccess.cpp:45
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)
Definition SPIRVCBufferAccess.cpp:126
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - 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.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - 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)
ModulePass * createSPIRVCBufferAccessLegacyPass()
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.