LLVM: lib/Target/DirectX/DXILResourceImplicitBinding.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
20#include "llvm/IR/IntrinsicsDirectX.h"
23#include
24
25#define DEBUG_TYPE "dxil-resource-implicit-binding"
26
27using namespace llvm;
29
30namespace {
31
32static void diagnoseImplicitBindingNotFound(CallInst *ImplBindingCall) {
34 LLVMContext &Context = F->getParent()->getContext();
35
36
37 Context.diagnose(
40}
41
44 struct ImplicitBindingCall {
45 int OrderID;
47 ImplicitBindingCall(int OrderID, CallInst *Call)
48 : OrderID(OrderID), Call(Call) {}
49 };
52
53
54 for (Function &F : M.functions()) {
55 if (.isDeclaration())
56 continue;
57
58 if (F.getIntrinsicID() != Intrinsic::dx_resource_handlefromimplicitbinding)
59 continue;
60
61 for (User *U : F.users()) {
63 int OrderID = cast(CI->getArgOperand(0))->getZExtValue();
65 }
66 }
68 }
69
70
72 Calls, [](auto &LHS, auto &RHS) { return LHS.OrderID < RHS.OrderID; });
73
74
75
76 int LastOrderID = -1;
79 bool AllBindingsAssigned = true;
81
82 for (ImplicitBindingCall &IB : Calls) {
84
85 if (IB.OrderID != LastOrderID) {
86 LastOrderID = IB.OrderID;
89
92 int32_t Size =
94
95 std::optional<uint32_t> RegSlot =
97 if (!RegSlot) {
98 diagnoseImplicitBindingNotFound(IB.Call);
99 AllBindingsAssigned = false;
100 continue;
101 }
102 RegSlotOp = ConstantInt::get(Builder.getInt32Ty(), RegSlot.value());
103 }
104
105 if (!RegSlotOp)
106 continue;
107
108 auto *NewCall = Builder.CreateIntrinsic(
109 HandleTy, Intrinsic::dx_resource_handlefrombinding,
110 {IB.Call->getOperand(1),
111 RegSlotOp,
112 IB.Call->getOperand(2),
113 IB.Call->getOperand(3),
114 IB.Call->getOperand(4)});
115 IB.Call->replaceAllUsesWith(NewCall);
116 IB.Call->eraseFromParent();
118 }
119
120 for (Function *F : FunctionsToMaybeRemove) {
121 if (F->user_empty()) {
122 F->eraseFromParent();
124 }
125 }
126
129}
130
131}
132
135
138
141
142 if (!assignBindings(M, DRBI, DRTM))
144
148 return PA;
149}
150
151namespace {
152
153class DXILResourceImplicitBindingLegacy : public ModulePass {
154public:
155 DXILResourceImplicitBindingLegacy() : ModulePass(ID) {}
156
157 bool runOnModule(Module &M) override {
159 getAnalysis().getResourceTypeMap();
161 getAnalysis().getBindingInfo();
162
164 return assignBindings(M, DRBI, DRTM);
165 return false;
166 }
167
168 static char ID;
169 void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
170 AU.addRequired();
171 AU.addRequired();
172 AU.addPreserved();
173 AU.addPreserved();
174 }
175};
176
177char DXILResourceImplicitBindingLegacy::ID = 0;
178}
179
181 "DXIL Resource Implicit Binding", false, false)
186
188 return new DXILResourceImplicitBindingLegacy();
189}
This file implements a class to represent arbitrary precision integral constant values and operations...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
This class represents a function call, abstracting a target machine's calling convention.
This is the shared class of boolean and integer constants.
bool hasImplicitBinding() const
void setHasImplicitBinding(bool Value)
std::optional< uint32_t > findAvailableBinding(dxil::ResourceClass RC, uint32_t Space, int32_t Size)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Definition DXILResourceImplicitBinding.cpp:133
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
This is an important class for using LLVM in a threaded context.
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.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
dxil::ResourceClass getResourceClass() const
Pass manager infrastructure for declaring and invalidating analyses.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
ModulePass * createDXILResourceImplicitBindingLegacyPass()
Pass to assign register slots to resources without binding.
Definition DXILResourceImplicitBinding.cpp:187
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.