Skip to content

[DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers #100699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
64 changes: 59 additions & 5 deletions llvm/include/llvm/Analysis/DXILResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@
#ifndef LLVM_ANALYSIS_DXILRESOURCE_H
#define LLVM_ANALYSIS_DXILRESOURCE_H

#include "llvm/ADT/MapVector.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.h"
#include "llvm/Support/DXILABI.h"

namespace llvm {
class CallInst;
class MDTuple;
class TargetExtType;

namespace dxil {

class ResourceInfo {
struct ResourceBinding {
uint32_t UniqueID;
uint32_t RecordID;
uint32_t Space;
uint32_t LowerBound;
uint32_t Size;

bool operator==(const ResourceBinding &RHS) const {
return std::tie(UniqueID, Space, LowerBound, Size) ==
std::tie(RHS.UniqueID, RHS.Space, RHS.LowerBound, RHS.Size);
return std::tie(RecordID, Space, LowerBound, Size) ==
std::tie(RHS.RecordID, RHS.Space, RHS.LowerBound, RHS.Size);
}
bool operator!=(const ResourceBinding &RHS) const {
return !(*this == RHS);
Expand Down Expand Up @@ -124,9 +129,9 @@ class ResourceInfo {
bool isFeedback() const;
bool isMultiSample() const;

void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
void bind(uint32_t RecordID, uint32_t Space, uint32_t LowerBound,
uint32_t Size) {
Binding.UniqueID = UniqueID;
Binding.RecordID = RecordID;
Binding.Space = Space;
Binding.LowerBound = LowerBound;
Binding.Size = Size;
Expand Down Expand Up @@ -211,9 +216,58 @@ class ResourceInfo {

ResourceBinding getBinding() const { return Binding; }
std::pair<uint32_t, uint32_t> getAnnotateProps() const;

void print(raw_ostream &OS) const;
};

} // namespace dxil

using DXILResourceMap = MapVector<CallInst *, dxil::ResourceInfo>;

class DXILResourceAnalysis : public AnalysisInfoMixin<DXILResourceAnalysis> {
friend AnalysisInfoMixin<DXILResourceAnalysis>;

static AnalysisKey Key;

public:
using Result = DXILResourceMap;

/// Gather resource info for the module \c M.
DXILResourceMap run(Module &M, ModuleAnalysisManager &AM);
};

/// Printer pass for the \c DXILResourceAnalysis results.
class DXILResourcePrinterPass : public PassInfoMixin<DXILResourcePrinterPass> {
raw_ostream &OS;

public:
explicit DXILResourcePrinterPass(raw_ostream &OS) : OS(OS) {}

PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);

static bool isRequired() { return true; }
};

class DXILResourceWrapperPass : public ModulePass {
std::unique_ptr<DXILResourceMap> ResourceMap;

public:
static char ID; // Class identification, replacement for typeinfo

DXILResourceWrapperPass();
~DXILResourceWrapperPass() override;

const DXILResourceMap &getResourceMap() const { return *ResourceMap; }
DXILResourceMap &getResourceMap() { return *ResourceMap; }

void getAnalysisUsage(AnalysisUsage &AU) const override;
bool runOnModule(Module &M) override;
void releaseMemory() override;

void print(raw_ostream &OS, const Module *M) const override;
void dump() const;
};

} // namespace llvm

#endif // LLVM_ANALYSIS_DXILRESOURCE_H
10 changes: 10 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsDirectX.td
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ def int_dx_flattened_thread_id_in_group : Intrinsic<[llvm_i32_ty], [], [IntrNoMe
def int_dx_create_handle : ClangBuiltin<"__builtin_hlsl_create_handle">,
Intrinsic<[ llvm_ptr_ty ], [llvm_i8_ty], [IntrWillReturn]>;

// Create resource handle given binding information. Returns a `target("dx.")`
// type appropriate for the kind of resource given a register space ID, lower
// bound and range size of the binding, as well as an index and an indicator
// whether that index may be non-uniform.
def int_dx_handle_fromBinding
: DefaultAttrsIntrinsic<
[llvm_any_ty],
[llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty],
[IntrNoMem]>;

def int_dx_all : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty]>;
def int_dx_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty]>;
def int_dx_clamp : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>]>;
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void initializeCycleInfoWrapperPassPass(PassRegistry &);
void initializeDAEPass(PassRegistry&);
void initializeDAHPass(PassRegistry&);
void initializeDCELegacyPassPass(PassRegistry&);
void initializeDXILResourceWrapperPassPass(PassRegistry &);
void initializeDeadMachineInstructionElimPass(PassRegistry&);
void initializeDebugifyMachineModulePass(PassRegistry &);
void initializeDependenceAnalysisWrapperPassPass(PassRegistry&);
Expand Down
Loading
Loading