20#include "llvm/IR/IntrinsicsDirectX.h"
25#define DEBUG_TYPE "dxil-resource-implicit-binding"
32static void diagnoseImplicitBindingNotFound(
CallInst *ImplBindingCall) {
44 struct ImplicitBindingCall {
47 ImplicitBindingCall(
int OrderID,
CallInst *Call)
48 : OrderID(OrderID), Call(Call) {}
55 if (!
F.isDeclaration())
58 if (
F.getIntrinsicID() != Intrinsic::dx_resource_handlefromimplicitbinding)
61 for (
User *U :
F.users()) {
62 if (
CallInst *CI = dyn_cast<CallInst>(U)) {
63 int OrderID = cast<ConstantInt>(CI->getArgOperand(0))->getZExtValue();
72 Calls, [](
auto &
LHS,
auto &
RHS) {
return LHS.OrderID <
RHS.OrderID; });
79 bool AllBindingsAssigned =
true;
82 for (ImplicitBindingCall &IB : Calls) {
85 if (IB.OrderID != LastOrderID) {
86 LastOrderID = IB.OrderID;
87 HandleTy = cast<TargetExtType>(IB.Call->getType());
91 cast<ConstantInt>(IB.Call->getArgOperand(1))->getZExtValue();
93 cast<ConstantInt>(IB.Call->getArgOperand(2))->getZExtValue();
95 std::optional<uint32_t> RegSlot =
98 diagnoseImplicitBindingNotFound(IB.Call);
99 AllBindingsAssigned =
false;
102 RegSlotOp = ConstantInt::get(Builder.
getInt32Ty(), RegSlot.value());
109 HandleTy, Intrinsic::dx_resource_handlefrombinding,
110 {IB.Call->getOperand(1),
112 IB.Call->getOperand(2),
113 IB.Call->getOperand(3),
114 IB.Call->getOperand(4)});
115 IB.Call->replaceAllUsesWith(NewCall);
116 IB.Call->eraseFromParent();
120 for (
Function *
F : FunctionsToMaybeRemove) {
121 if (
F->user_empty()) {
122 F->eraseFromParent();
142 if (!assignBindings(M, DRBI, DRTM))
153class DXILResourceImplicitBindingLegacy :
public ModulePass {
157 bool runOnModule(
Module &M)
override {
159 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
161 getAnalysis<DXILResourceBindingWrapperPass>().getBindingInfo();
164 return assignBindings(M, DRBI, DRTM);
177char DXILResourceImplicitBindingLegacy::ID = 0;
181 "DXIL Resource Implicit Binding",
false,
false)
188 return new DXILResourceImplicitBindingLegacy();
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)
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
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 &)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
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)
ModulePass * createDXILResourceImplicitBindingLegacyPass()
Pass to assign register slots to resources without binding.