https://github.com/hekota created https://github.com/llvm/llvm-project/pull/130323
`DXILResourceMDAnalysis` gathers information about resources from obsolete resource metadata annotations that are going to be removed in a follow-up PR. Part 1/2 of #114126 >From 80765757f067527816c4c8b9d728169568b04b7a Mon Sep 17 00:00:00 2001 From: Helena Kotas <heko...@microsoft.com> Date: Fri, 7 Mar 2025 10:40:20 -0800 Subject: [PATCH] [DirectX] Remove DXILResourceMDAnalysis Part 1/2 of #114126 --- llvm/lib/Target/DirectX/CMakeLists.txt | 2 - .../Target/DirectX/DXILDataScalarization.h | 1 - .../Target/DirectX/DXILIntrinsicExpansion.h | 1 - llvm/lib/Target/DirectX/DXILOpLowering.cpp | 2 - llvm/lib/Target/DirectX/DXILPrepare.cpp | 2 - llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp | 23 +- llvm/lib/Target/DirectX/DXILResource.cpp | 346 ------------------ llvm/lib/Target/DirectX/DXILResource.h | 133 ------- .../Target/DirectX/DXILResourceAnalysis.cpp | 41 --- .../lib/Target/DirectX/DXILResourceAnalysis.h | 55 --- .../Target/DirectX/DXILTranslateMetadata.cpp | 31 +- llvm/lib/Target/DirectX/DirectX.h | 3 - .../Target/DirectX/DirectXPassRegistry.def | 1 - .../Target/DirectX/DirectXTargetMachine.cpp | 2 - llvm/test/CodeGen/DirectX/llc-pipeline.ll | 1 - 15 files changed, 7 insertions(+), 637 deletions(-) delete mode 100644 llvm/lib/Target/DirectX/DXILResource.cpp delete mode 100644 llvm/lib/Target/DirectX/DXILResource.h delete mode 100644 llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp delete mode 100644 llvm/lib/Target/DirectX/DXILResourceAnalysis.h diff --git a/llvm/lib/Target/DirectX/CMakeLists.txt b/llvm/lib/Target/DirectX/CMakeLists.txt index 5a167535b0afa..6904a1c0f1e73 100644 --- a/llvm/lib/Target/DirectX/CMakeLists.txt +++ b/llvm/lib/Target/DirectX/CMakeLists.txt @@ -28,8 +28,6 @@ add_llvm_target(DirectXCodeGen DXILOpLowering.cpp DXILPrepare.cpp DXILPrettyPrinter.cpp - DXILResource.cpp - DXILResourceAnalysis.cpp DXILResourceAccess.cpp DXILShaderFlags.cpp DXILTranslateMetadata.cpp diff --git a/llvm/lib/Target/DirectX/DXILDataScalarization.h b/llvm/lib/Target/DirectX/DXILDataScalarization.h index 560e061db96d0..e8cd495729431 100644 --- a/llvm/lib/Target/DirectX/DXILDataScalarization.h +++ b/llvm/lib/Target/DirectX/DXILDataScalarization.h @@ -9,7 +9,6 @@ #ifndef LLVM_TARGET_DIRECTX_DXILDATASCALARIZATION_H #define LLVM_TARGET_DIRECTX_DXILDATASCALARIZATION_H -#include "DXILResource.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h index c283386c6e3df..43fc4d7735e1f 100644 --- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h +++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h @@ -8,7 +8,6 @@ #ifndef LLVM_TARGET_DIRECTX_DXILINTRINSICEXPANSION_H #define LLVM_TARGET_DIRECTX_DXILINTRINSICEXPANSION_H -#include "DXILResource.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" diff --git a/llvm/lib/Target/DirectX/DXILOpLowering.cpp b/llvm/lib/Target/DirectX/DXILOpLowering.cpp index 92b6787b9571e..1b02206464661 100644 --- a/llvm/lib/Target/DirectX/DXILOpLowering.cpp +++ b/llvm/lib/Target/DirectX/DXILOpLowering.cpp @@ -10,7 +10,6 @@ #include "DXILConstants.h" #include "DXILIntrinsicExpansion.h" #include "DXILOpBuilder.h" -#include "DXILResourceAnalysis.h" #include "DXILShaderFlags.h" #include "DirectX.h" #include "llvm/ADT/SmallVector.h" @@ -889,7 +888,6 @@ class DXILOpLoweringLegacy : public ModulePass { AU.addRequired<DXILResourceTypeWrapperPass>(); AU.addRequired<DXILResourceBindingWrapperPass>(); AU.addPreserved<DXILResourceBindingWrapperPass>(); - AU.addPreserved<DXILResourceMDWrapper>(); AU.addPreserved<DXILMetadataAnalysisWrapperPass>(); AU.addPreserved<ShaderFlagsAnalysisWrapper>(); } diff --git a/llvm/lib/Target/DirectX/DXILPrepare.cpp b/llvm/lib/Target/DirectX/DXILPrepare.cpp index 355c79ae0edc9..0014cc9e1f67c 100644 --- a/llvm/lib/Target/DirectX/DXILPrepare.cpp +++ b/llvm/lib/Target/DirectX/DXILPrepare.cpp @@ -11,7 +11,6 @@ /// Language (DXIL). //===----------------------------------------------------------------------===// -#include "DXILResourceAnalysis.h" #include "DXILShaderFlags.h" #include "DirectX.h" #include "DirectXIRPasses/PointerTypeAnalysis.h" @@ -248,7 +247,6 @@ class DXILPrepareModule : public ModulePass { void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<DXILMetadataAnalysisWrapperPass>(); AU.addPreserved<ShaderFlagsAnalysisWrapper>(); - AU.addPreserved<DXILResourceMDWrapper>(); AU.addPreserved<DXILMetadataAnalysisWrapperPass>(); AU.addPreserved<DXILResourceBindingWrapperPass>(); } diff --git a/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp b/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp index 7255a9be06d51..c1f2483044693 100644 --- a/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp +++ b/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "DXILPrettyPrinter.h" -#include "DXILResourceAnalysis.h" #include "DirectX.h" #include "llvm/ADT/StringRef.h" #include "llvm/Analysis/DXILResource.h" @@ -222,8 +221,7 @@ struct FormatBindingSize } // namespace static void prettyPrintResources(raw_ostream &OS, const DXILBindingMap &DBM, - DXILResourceTypeMap &DRTM, - const dxil::Resources &MDResources) { + DXILResourceTypeMap &DRTM) { // Column widths are arbitrary but match the widths DXC uses. OS << ";\n; Resource Bindings:\n;\n"; OS << formatv("; {0,-30} {1,10} {2,7} {3,11} {4,7} {5,14} {6,9}\n", "Name", @@ -237,11 +235,6 @@ static void prettyPrintResources(raw_ostream &OS, const DXILBindingMap &DBM, const dxil::ResourceTypeInfo &RTI = DRTM[RBI.getHandleTy()]; dxil::ResourceClass RC = RTI.getResourceClass(); - assert((RC != dxil::ResourceClass::CBuffer || !MDResources.hasCBuffers()) && - "Old and new cbuffer representations can't coexist"); - assert((RC != dxil::ResourceClass::UAV || !MDResources.hasUAVs()) && - "Old and new UAV representations can't coexist"); - StringRef Name(RBI.getName()); StringRef Type(getRCName(RC)); StringRef Format(getFormatName(RTI)); @@ -252,12 +245,6 @@ static void prettyPrintResources(raw_ostream &OS, const DXILBindingMap &DBM, OS << formatv("; {0,-30} {1,10} {2,7} {3,11} {4,7} {5,14} {6,9}\n", Name, Type, Format, Dim, ID, Bind, Count); } - - if (MDResources.hasCBuffers()) - MDResources.printCBuffers(OS); - if (MDResources.hasUAVs()) - MDResources.printUAVs(OS); - OS << ";\n"; } @@ -265,8 +252,7 @@ PreservedAnalyses DXILPrettyPrinterPass::run(Module &M, ModuleAnalysisManager &MAM) { const DXILBindingMap &DBM = MAM.getResult<DXILResourceBindingAnalysis>(M); DXILResourceTypeMap &DRTM = MAM.getResult<DXILResourceTypeAnalysis>(M); - const dxil::Resources &MDResources = MAM.getResult<DXILResourceMDAnalysis>(M); - prettyPrintResources(OS, DBM, DRTM, MDResources); + prettyPrintResources(OS, DBM, DRTM); return PreservedAnalyses::all(); } @@ -293,7 +279,6 @@ class DXILPrettyPrinterLegacy : public llvm::ModulePass { AU.setPreservesAll(); AU.addRequired<DXILResourceTypeWrapperPass>(); AU.addRequired<DXILResourceBindingWrapperPass>(); - AU.addRequired<DXILResourceMDWrapper>(); } }; } // namespace @@ -303,7 +288,6 @@ INITIALIZE_PASS_BEGIN(DXILPrettyPrinterLegacy, "dxil-pretty-printer", "DXIL Metadata Pretty Printer", true, true) INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass) INITIALIZE_PASS_DEPENDENCY(DXILResourceBindingWrapperPass) -INITIALIZE_PASS_DEPENDENCY(DXILResourceMDWrapper) INITIALIZE_PASS_END(DXILPrettyPrinterLegacy, "dxil-pretty-printer", "DXIL Metadata Pretty Printer", true, true) @@ -312,8 +296,7 @@ bool DXILPrettyPrinterLegacy::runOnModule(Module &M) { getAnalysis<DXILResourceBindingWrapperPass>().getBindingMap(); DXILResourceTypeMap &DRTM = getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap(); - dxil::Resources &Res = getAnalysis<DXILResourceMDWrapper>().getDXILResource(); - prettyPrintResources(OS, DBM, DRTM, Res); + prettyPrintResources(OS, DBM, DRTM); return false; } diff --git a/llvm/lib/Target/DirectX/DXILResource.cpp b/llvm/lib/Target/DirectX/DXILResource.cpp deleted file mode 100644 index f027283b70521..0000000000000 --- a/llvm/lib/Target/DirectX/DXILResource.cpp +++ /dev/null @@ -1,346 +0,0 @@ -//===- DXILResource.cpp - DXIL Resource helper objects --------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -/// -/// \file This file contains helper objects for working with DXIL Resources. -/// -//===----------------------------------------------------------------------===// - -#include "DXILResource.h" -#include "CBufferDataLayout.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/IR/IRBuilder.h" -#include "llvm/IR/Metadata.h" -#include "llvm/IR/Module.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/Format.h" - -using namespace llvm; -using namespace llvm::dxil; - -template <typename T> void ResourceTable<T>::collect(Module &M) { - NamedMDNode *Entry = M.getNamedMetadata(MDName); - if (!Entry || Entry->getNumOperands() == 0) - return; - - uint32_t Counter = 0; - for (auto *Res : Entry->operands()) { - Data.push_back(T(Counter++, hlsl::FrontendResource(cast<MDNode>(Res)))); - } -} - -template <> void ResourceTable<ConstantBuffer>::collect(Module &M) { - NamedMDNode *Entry = M.getNamedMetadata(MDName); - if (!Entry || Entry->getNumOperands() == 0) - return; - - uint32_t Counter = 0; - for (auto *Res : Entry->operands()) { - Data.push_back( - ConstantBuffer(Counter++, hlsl::FrontendResource(cast<MDNode>(Res)))); - } - // FIXME: share CBufferDataLayout with CBuffer load lowering. - // See https://github.com/llvm/llvm-project/issues/58381 - CBufferDataLayout CBDL(M.getDataLayout(), /*IsLegacy*/ true); - for (auto &CB : Data) - CB.setSize(CBDL); -} - -void Resources::collect(Module &M) { - UAVs.collect(M); - CBuffers.collect(M); -} - -ResourceBase::ResourceBase(uint32_t I, hlsl::FrontendResource R) - : ID(I), GV(R.getGlobalVariable()), Name(""), Space(R.getSpace()), - LowerBound(R.getResourceIndex()), RangeSize(1) { - if (auto *ArrTy = dyn_cast<ArrayType>(GV->getValueType())) - RangeSize = ArrTy->getNumElements(); -} - -StringRef ResourceBase::getElementTypeName(ElementType ElTy) { - switch (ElTy) { - case ElementType::Invalid: - return "invalid"; - case ElementType::I1: - return "i1"; - case ElementType::I16: - return "i16"; - case ElementType::U16: - return "u16"; - case ElementType::I32: - return "i32"; - case ElementType::U32: - return "u32"; - case ElementType::I64: - return "i64"; - case ElementType::U64: - return "u64"; - case ElementType::F16: - return "f16"; - case ElementType::F32: - return "f32"; - case ElementType::F64: - return "f64"; - case ElementType::SNormF16: - return "snorm_f16"; - case ElementType::UNormF16: - return "unorm_f16"; - case ElementType::SNormF32: - return "snorm_f32"; - case ElementType::UNormF32: - return "unorm_f32"; - case ElementType::SNormF64: - return "snorm_f64"; - case ElementType::UNormF64: - return "unorm_f64"; - case ElementType::PackedS8x32: - return "p32i8"; - case ElementType::PackedU8x32: - return "p32u8"; - } - llvm_unreachable("All ElementType enums are handled in switch"); -} - -void ResourceBase::printElementType(ResourceKind Kind, ElementType ElTy, - unsigned Alignment, raw_ostream &OS) { - switch (Kind) { - default: - // TODO: add vector size. - OS << right_justify(getElementTypeName(ElTy), Alignment); - break; - case ResourceKind::RawBuffer: - OS << right_justify("byte", Alignment); - break; - case ResourceKind::StructuredBuffer: - OS << right_justify("struct", Alignment); - break; - case ResourceKind::CBuffer: - case ResourceKind::Sampler: - OS << right_justify("NA", Alignment); - break; - case ResourceKind::Invalid: - case ResourceKind::NumEntries: - break; - } -} - -StringRef ResourceBase::getKindName(ResourceKind Kind) { - switch (Kind) { - case ResourceKind::NumEntries: - case ResourceKind::Invalid: - return "invalid"; - case ResourceKind::Texture1D: - return "1d"; - case ResourceKind::Texture2D: - return "2d"; - case ResourceKind::Texture2DMS: - return "2dMS"; - case ResourceKind::Texture3D: - return "3d"; - case ResourceKind::TextureCube: - return "cube"; - case ResourceKind::Texture1DArray: - return "1darray"; - case ResourceKind::Texture2DArray: - return "2darray"; - case ResourceKind::Texture2DMSArray: - return "2darrayMS"; - case ResourceKind::TextureCubeArray: - return "cubearray"; - case ResourceKind::TypedBuffer: - return "buf"; - case ResourceKind::RawBuffer: - return "rawbuf"; - case ResourceKind::StructuredBuffer: - return "structbuf"; - case ResourceKind::CBuffer: - return "cbuffer"; - case ResourceKind::Sampler: - return "sampler"; - case ResourceKind::TBuffer: - return "tbuffer"; - case ResourceKind::RTAccelerationStructure: - return "ras"; - case ResourceKind::FeedbackTexture2D: - return "fbtex2d"; - case ResourceKind::FeedbackTexture2DArray: - return "fbtex2darray"; - } - llvm_unreachable("All ResourceKind enums are handled in switch"); -} - -void ResourceBase::printKind(ResourceKind Kind, unsigned Alignment, - raw_ostream &OS, bool SRV, bool HasCounter, - uint32_t SampleCount) { - switch (Kind) { - default: - OS << right_justify(getKindName(Kind), Alignment); - break; - - case ResourceKind::RawBuffer: - case ResourceKind::StructuredBuffer: - if (SRV) - OS << right_justify("r/o", Alignment); - else { - if (!HasCounter) - OS << right_justify("r/w", Alignment); - else - OS << right_justify("r/w+cnt", Alignment); - } - break; - case ResourceKind::TypedBuffer: - OS << right_justify("buf", Alignment); - break; - case ResourceKind::Texture2DMS: - case ResourceKind::Texture2DMSArray: { - std::string DimName = getKindName(Kind).str(); - if (SampleCount) - DimName += std::to_string(SampleCount); - OS << right_justify(DimName, Alignment); - } break; - case ResourceKind::CBuffer: - case ResourceKind::Sampler: - OS << right_justify("NA", Alignment); - break; - case ResourceKind::Invalid: - case ResourceKind::NumEntries: - break; - } -} - -void ResourceBase::print(raw_ostream &OS, StringRef IDPrefix, - StringRef BindingPrefix) const { - std::string ResID = IDPrefix.str(); - ResID += std::to_string(ID); - OS << right_justify(ResID, 8); - - std::string Bind = BindingPrefix.str(); - Bind += std::to_string(LowerBound); - if (Space) - Bind += ",space" + std::to_string(Space); - - OS << right_justify(Bind, 15); - if (RangeSize != UINT_MAX) - OS << right_justify(std::to_string(RangeSize), 6) << "\n"; - else - OS << right_justify("unbounded", 6) << "\n"; -} - -void UAVResource::print(raw_ostream &OS) const { - OS << "; " << left_justify(Name, 31); - - OS << right_justify("UAV", 10); - - printElementType(Shape, ExtProps.ElementType.value_or(ElementType::Invalid), - 8, OS); - - // FIXME: support SampleCount. - // See https://github.com/llvm/llvm-project/issues/58175 - printKind(Shape, 12, OS, /*SRV*/ false, HasCounter); - // Print the binding part. - ResourceBase::print(OS, "U", "u"); -} - -ConstantBuffer::ConstantBuffer(uint32_t I, hlsl::FrontendResource R) - : ResourceBase(I, R) {} - -void ConstantBuffer::setSize(CBufferDataLayout &DL) { - CBufferSizeInBytes = DL.getTypeAllocSizeInBytes(GV->getValueType()); -} - -void ConstantBuffer::print(raw_ostream &OS) const { - OS << "; " << left_justify(Name, 31); - - OS << right_justify("cbuffer", 10); - - printElementType(ResourceKind::CBuffer, ElementType::Invalid, 8, OS); - - printKind(ResourceKind::CBuffer, 12, OS, /*SRV*/ false, /*HasCounter*/ false); - // Print the binding part. - ResourceBase::print(OS, "CB", "cb"); -} - -template <typename T> void ResourceTable<T>::print(raw_ostream &OS) const { - for (auto &Res : Data) - Res.print(OS); -} - -MDNode *ResourceBase::ExtendedProperties::write(LLVMContext &Ctx) const { - IRBuilder<> B(Ctx); - SmallVector<Metadata *> Entries; - if (ElementType) { - Entries.emplace_back( - ConstantAsMetadata::get(B.getInt32(TypedBufferElementType))); - Entries.emplace_back(ConstantAsMetadata::get( - B.getInt32(static_cast<uint32_t>(*ElementType)))); - } - if (Entries.empty()) - return nullptr; - return MDNode::get(Ctx, Entries); -} - -void ResourceBase::write(LLVMContext &Ctx, - MutableArrayRef<Metadata *> Entries) const { - IRBuilder<> B(Ctx); - Entries[0] = ConstantAsMetadata::get(B.getInt32(ID)); - Entries[1] = ConstantAsMetadata::get(GV); - Entries[2] = MDString::get(Ctx, Name); - Entries[3] = ConstantAsMetadata::get(B.getInt32(Space)); - Entries[4] = ConstantAsMetadata::get(B.getInt32(LowerBound)); - Entries[5] = ConstantAsMetadata::get(B.getInt32(RangeSize)); -} - -MDNode *UAVResource::write() const { - auto &Ctx = GV->getContext(); - IRBuilder<> B(Ctx); - Metadata *Entries[11]; - ResourceBase::write(Ctx, Entries); - Entries[6] = - ConstantAsMetadata::get(B.getInt32(static_cast<uint32_t>(Shape))); - Entries[7] = ConstantAsMetadata::get(B.getInt1(GloballyCoherent)); - Entries[8] = ConstantAsMetadata::get(B.getInt1(HasCounter)); - Entries[9] = ConstantAsMetadata::get(B.getInt1(IsROV)); - Entries[10] = ExtProps.write(Ctx); - return MDNode::get(Ctx, Entries); -} - -MDNode *ConstantBuffer::write() const { - auto &Ctx = GV->getContext(); - IRBuilder<> B(Ctx); - Metadata *Entries[7]; - ResourceBase::write(Ctx, Entries); - - Entries[6] = ConstantAsMetadata::get(B.getInt32(CBufferSizeInBytes)); - return MDNode::get(Ctx, Entries); -} - -template <typename T> MDNode *ResourceTable<T>::write(Module &M) const { - if (Data.empty()) - return nullptr; - SmallVector<Metadata *> MDs; - for (auto &Res : Data) - MDs.emplace_back(Res.write()); - - NamedMDNode *Entry = M.getNamedMetadata(MDName); - if (Entry) - Entry->eraseFromParent(); - - return MDNode::get(M.getContext(), MDs); -} - -Metadata *Resources::writeUAVs(Module &M) const { return UAVs.write(M); } -void Resources::printUAVs(raw_ostream &OS) const { UAVs.print(OS); } -Metadata *Resources::writeCBuffers(Module &M) const { - return CBuffers.write(M); -} -void Resources::printCBuffers(raw_ostream &OS) const { CBuffers.print(OS); } - -void Resources::dump() const { - printCBuffers(dbgs()); - printUAVs(dbgs()); -} diff --git a/llvm/lib/Target/DirectX/DXILResource.h b/llvm/lib/Target/DirectX/DXILResource.h deleted file mode 100644 index 812729bc4dc57..0000000000000 --- a/llvm/lib/Target/DirectX/DXILResource.h +++ /dev/null @@ -1,133 +0,0 @@ -//===- DXILResource.h - DXIL Resource helper objects ----------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -/// -/// \file This file contains helper objects for working with DXIL Resources. -/// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TARGET_DIRECTX_DXILRESOURCE_H -#define LLVM_TARGET_DIRECTX_DXILRESOURCE_H - -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Frontend/HLSL/HLSLResource.h" -#include "llvm/IR/Metadata.h" -#include "llvm/Support/Compiler.h" -#include "llvm/Support/DXILABI.h" -#include <cstdint> - -namespace llvm { -class Module; -class GlobalVariable; - -namespace dxil { -class CBufferDataLayout; - -class ResourceBase { -protected: - uint32_t ID; - GlobalVariable *GV; - StringRef Name; - uint32_t Space; - uint32_t LowerBound; - uint32_t RangeSize; - ResourceBase(uint32_t I, hlsl::FrontendResource R); - - void write(LLVMContext &Ctx, MutableArrayRef<Metadata *> Entries) const; - - void print(raw_ostream &O, StringRef IDPrefix, StringRef BindingPrefix) const; - static StringRef getKindName(dxil::ResourceKind Kind); - static void printKind(dxil::ResourceKind Kind, unsigned Alignment, - raw_ostream &OS, bool SRV = false, - bool HasCounter = false, uint32_t SampleCount = 0); - - static StringRef getElementTypeName(dxil::ElementType CompType); - static void printElementType(dxil::ResourceKind Kind, - dxil::ElementType CompType, unsigned Alignment, - raw_ostream &OS); - -public: - struct ExtendedProperties { - std::optional<dxil::ElementType> ElementType; - - // The value ordering of this enumeration is part of the DXIL ABI. Elements - // can only be added to the end, and not removed. - enum Tags : uint32_t { - TypedBufferElementType = 0, - StructuredBufferElementStride, - SamplerFeedbackKind, - Atomic64Use - }; - - MDNode *write(LLVMContext &Ctx) const; - }; -}; - -class UAVResource : public ResourceBase { - dxil::ResourceKind Shape; - bool GloballyCoherent; - bool HasCounter; - bool IsROV; - ResourceBase::ExtendedProperties ExtProps; - - void parseSourceType(StringRef S); - -public: - UAVResource(uint32_t I, hlsl::FrontendResource R) - : ResourceBase(I, R), Shape(R.getResourceKind()), GloballyCoherent(false), - HasCounter(false), IsROV(R.getIsROV()), ExtProps{R.getElementType()} {} - - MDNode *write() const; - void print(raw_ostream &O) const; -}; - -class ConstantBuffer : public ResourceBase { - uint32_t CBufferSizeInBytes = 0; // Cbuffer used size in bytes. -public: - ConstantBuffer(uint32_t I, hlsl::FrontendResource R); - void setSize(CBufferDataLayout &DL); - MDNode *write() const; - void print(raw_ostream &O) const; -}; - -template <typename T> class ResourceTable { - StringRef MDName; - - llvm::SmallVector<T> Data; - -public: - ResourceTable(StringRef Name) : MDName(Name) {} - void collect(Module &M); - bool empty() const { return Data.empty(); } - MDNode *write(Module &M) const; - void print(raw_ostream &O) const; -}; - -// FIXME: Fully computing the resource structures requires analyzing the IR -// because some flags are set based on what operations are performed on the -// resource. This partial patch handles some of the leg work, but not all of it. -// See issue https://github.com/llvm/llvm-project/issues/57936. -class Resources { - ResourceTable<UAVResource> UAVs = {"hlsl.uavs"}; - ResourceTable<ConstantBuffer> CBuffers = {"hlsl.cbufs"}; - -public: - void collect(Module &M); - bool hasUAVs() const { return !UAVs.empty(); } - Metadata *writeUAVs(Module &M) const; - void printUAVs(raw_ostream &OS) const; - bool hasCBuffers() const { return !CBuffers.empty(); } - Metadata *writeCBuffers(Module &M) const; - void printCBuffers(raw_ostream &OS) const; - LLVM_DUMP_METHOD void dump() const; -}; - -} // namespace dxil -} // namespace llvm - -#endif // LLVM_TARGET_DIRECTX_DXILRESOURCE_H diff --git a/llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp b/llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp deleted file mode 100644 index d423220bb902e..0000000000000 --- a/llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===- DXILResourceAnalysis.cpp - DXIL Resource analysis-------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -/// -/// \file This file contains Analysis for information about DXIL resources. -/// -//===----------------------------------------------------------------------===// - -#include "DXILResourceAnalysis.h" -#include "DirectX.h" -#include "llvm/IR/PassManager.h" - -using namespace llvm; - -#define DEBUG_TYPE "dxil-resource-analysis" - -dxil::Resources DXILResourceMDAnalysis::run(Module &M, - ModuleAnalysisManager &AM) { - dxil::Resources R; - R.collect(M); - return R; -} - -AnalysisKey DXILResourceMDAnalysis::Key; - -char DXILResourceMDWrapper::ID = 0; -INITIALIZE_PASS_BEGIN(DXILResourceMDWrapper, DEBUG_TYPE, - "DXIL resource Information", true, true) -INITIALIZE_PASS_END(DXILResourceMDWrapper, DEBUG_TYPE, - "DXIL resource Information", true, true) - -bool DXILResourceMDWrapper::runOnModule(Module &M) { - Resources.collect(M); - return false; -} - -DXILResourceMDWrapper::DXILResourceMDWrapper() : ModulePass(ID) {} diff --git a/llvm/lib/Target/DirectX/DXILResourceAnalysis.h b/llvm/lib/Target/DirectX/DXILResourceAnalysis.h deleted file mode 100644 index 0ad97dc1992f4..0000000000000 --- a/llvm/lib/Target/DirectX/DXILResourceAnalysis.h +++ /dev/null @@ -1,55 +0,0 @@ -//===- DXILResourceAnalysis.h - DXIL Resource analysis-------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -/// -/// \file This file contains Analysis for information about DXIL resources. -/// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TARGET_DIRECTX_DXILRESOURCEANALYSIS_H -#define LLVM_TARGET_DIRECTX_DXILRESOURCEANALYSIS_H - -#include "DXILResource.h" -#include "llvm/IR/PassManager.h" -#include "llvm/Pass.h" -#include <memory> - -namespace llvm { -/// Analysis pass that exposes the \c DXILResource for a module. -class DXILResourceMDAnalysis - : public AnalysisInfoMixin<DXILResourceMDAnalysis> { - friend AnalysisInfoMixin<DXILResourceMDAnalysis>; - static AnalysisKey Key; - -public: - typedef dxil::Resources Result; - dxil::Resources run(Module &M, ModuleAnalysisManager &AM); -}; - -/// The legacy pass manager's analysis pass to compute DXIL resource -/// information. -class DXILResourceMDWrapper : public ModulePass { - dxil::Resources Resources; - -public: - static char ID; // Pass identification, replacement for typeid - - DXILResourceMDWrapper(); - - dxil::Resources &getDXILResource() { return Resources; } - const dxil::Resources &getDXILResource() const { return Resources; } - - /// Calculate the DXILResource for the module. - bool runOnModule(Module &M) override; - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesAll(); - } -}; -} // namespace llvm - -#endif // LLVM_TARGET_DIRECTX_DXILRESOURCEANALYSIS_H diff --git a/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp b/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp index 5fd5c226eef89..6da5a355f8390 100644 --- a/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp +++ b/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp @@ -7,8 +7,6 @@ //===----------------------------------------------------------------------===// #include "DXILTranslateMetadata.h" -#include "DXILResource.h" -#include "DXILResourceAnalysis.h" #include "DXILShaderFlags.h" #include "DirectX.h" #include "llvm/ADT/SmallVector.h" @@ -75,8 +73,7 @@ enum class EntryPropsTag { } // namespace static NamedMDNode *emitResourceMetadata(Module &M, DXILBindingMap &DBM, - DXILResourceTypeMap &DRTM, - const dxil::Resources &MDResources) { + DXILResourceTypeMap &DRTM) { LLVMContext &Context = M.getContext(); for (ResourceBindingInfo &RI : DBM) @@ -99,18 +96,6 @@ static NamedMDNode *emitResourceMetadata(Module &M, DXILBindingMap &DBM, Metadata *SmpMD = Smps.empty() ? nullptr : MDNode::get(Context, Smps); bool HasResources = !DBM.empty(); - if (MDResources.hasUAVs()) { - assert(!UAVMD && "Old and new UAV representations can't coexist"); - UAVMD = MDResources.writeUAVs(M); - HasResources = true; - } - - if (MDResources.hasCBuffers()) { - assert(!CBufMD && "Old and new cbuffer representations can't coexist"); - CBufMD = MDResources.writeCBuffers(M); - HasResources = true; - } - if (!HasResources) return nullptr; @@ -336,7 +321,6 @@ static void translateBranchMetadata(Module &M) { static void translateMetadata(Module &M, DXILBindingMap &DBM, DXILResourceTypeMap &DRTM, - const Resources &MDResources, const ModuleShaderFlags &ShaderFlags, const ModuleMetadataInfo &MMDI) { LLVMContext &Ctx = M.getContext(); @@ -346,8 +330,7 @@ static void translateMetadata(Module &M, DXILBindingMap &DBM, emitValidatorVersionMD(M, MMDI); emitShaderModelVersionMD(M, MMDI); emitDXILVersionTupleMD(M, MMDI); - NamedMDNode *NamedResourceMD = - emitResourceMetadata(M, DBM, DRTM, MDResources); + NamedMDNode *NamedResourceMD = emitResourceMetadata(M, DBM, DRTM); auto *ResourceMD = (NamedResourceMD != nullptr) ? NamedResourceMD->getOperand(0) : nullptr; // FIXME: Add support to construct Signatures @@ -401,11 +384,10 @@ PreservedAnalyses DXILTranslateMetadata::run(Module &M, ModuleAnalysisManager &MAM) { DXILBindingMap &DBM = MAM.getResult<DXILResourceBindingAnalysis>(M); DXILResourceTypeMap &DRTM = MAM.getResult<DXILResourceTypeAnalysis>(M); - const dxil::Resources &MDResources = MAM.getResult<DXILResourceMDAnalysis>(M); const ModuleShaderFlags &ShaderFlags = MAM.getResult<ShaderFlagsAnalysis>(M); const dxil::ModuleMetadataInfo MMDI = MAM.getResult<DXILMetadataAnalysis>(M); - translateMetadata(M, DBM, DRTM, MDResources, ShaderFlags, MMDI); + translateMetadata(M, DBM, DRTM, ShaderFlags, MMDI); translateBranchMetadata(M); return PreservedAnalyses::all(); @@ -422,11 +404,9 @@ class DXILTranslateMetadataLegacy : public ModulePass { void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<DXILResourceTypeWrapperPass>(); AU.addRequired<DXILResourceBindingWrapperPass>(); - AU.addRequired<DXILResourceMDWrapper>(); AU.addRequired<ShaderFlagsAnalysisWrapper>(); AU.addRequired<DXILMetadataAnalysisWrapperPass>(); AU.addPreserved<DXILResourceBindingWrapperPass>(); - AU.addPreserved<DXILResourceMDWrapper>(); AU.addPreserved<DXILMetadataAnalysisWrapperPass>(); AU.addPreserved<ShaderFlagsAnalysisWrapper>(); } @@ -436,14 +416,12 @@ class DXILTranslateMetadataLegacy : public ModulePass { getAnalysis<DXILResourceBindingWrapperPass>().getBindingMap(); DXILResourceTypeMap &DRTM = getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap(); - const dxil::Resources &MDResources = - getAnalysis<DXILResourceMDWrapper>().getDXILResource(); const ModuleShaderFlags &ShaderFlags = getAnalysis<ShaderFlagsAnalysisWrapper>().getShaderFlags(); dxil::ModuleMetadataInfo MMDI = getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata(); - translateMetadata(M, DBM, DRTM, MDResources, ShaderFlags, MMDI); + translateMetadata(M, DBM, DRTM, ShaderFlags, MMDI); translateBranchMetadata(M); return true; } @@ -460,7 +438,6 @@ ModulePass *llvm::createDXILTranslateMetadataLegacyPass() { INITIALIZE_PASS_BEGIN(DXILTranslateMetadataLegacy, "dxil-translate-metadata", "DXIL Translate Metadata", false, false) INITIALIZE_PASS_DEPENDENCY(DXILResourceBindingWrapperPass) -INITIALIZE_PASS_DEPENDENCY(DXILResourceMDWrapper) INITIALIZE_PASS_DEPENDENCY(ShaderFlagsAnalysisWrapper) INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass) INITIALIZE_PASS_END(DXILTranslateMetadataLegacy, "dxil-translate-metadata", diff --git a/llvm/lib/Target/DirectX/DirectX.h b/llvm/lib/Target/DirectX/DirectX.h index 953ac3eb82098..42aa0da16e8aa 100644 --- a/llvm/lib/Target/DirectX/DirectX.h +++ b/llvm/lib/Target/DirectX/DirectX.h @@ -65,9 +65,6 @@ void initializeDXILTranslateMetadataLegacyPass(PassRegistry &); /// Pass to emit metadata for DXIL. ModulePass *createDXILTranslateMetadataLegacyPass(); -/// Initializer for DXILTranslateMetadata. -void initializeDXILResourceMDWrapperPass(PassRegistry &); - /// Pass to pretty print DXIL metadata. ModulePass *createDXILPrettyPrinterLegacyPass(raw_ostream &OS); diff --git a/llvm/lib/Target/DirectX/DirectXPassRegistry.def b/llvm/lib/Target/DirectX/DirectXPassRegistry.def index de5087ce1ae2f..aee0a4ff83d43 100644 --- a/llvm/lib/Target/DirectX/DirectXPassRegistry.def +++ b/llvm/lib/Target/DirectX/DirectXPassRegistry.def @@ -17,7 +17,6 @@ #define MODULE_ANALYSIS(NAME, CREATE_PASS) #endif MODULE_ANALYSIS("dx-shader-flags", dxil::ShaderFlagsAnalysis()) -MODULE_ANALYSIS("dxil-resource-md", DXILResourceMDAnalysis()) MODULE_ANALYSIS("dxil-root-signature-analysis", dxil::RootSignatureAnalysis()) #undef MODULE_ANALYSIS diff --git a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp index dda650b0f6e15..82dc1c6af562a 100644 --- a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp +++ b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp @@ -18,7 +18,6 @@ #include "DXILOpLowering.h" #include "DXILPrettyPrinter.h" #include "DXILResourceAccess.h" -#include "DXILResourceAnalysis.h" #include "DXILRootSignature.h" #include "DXILShaderFlags.h" #include "DXILTranslateMetadata.h" @@ -60,7 +59,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTarget() { initializeDXILOpLoweringLegacyPass(*PR); initializeDXILResourceAccessLegacyPass(*PR); initializeDXILTranslateMetadataLegacyPass(*PR); - initializeDXILResourceMDWrapperPass(*PR); initializeShaderFlagsAnalysisWrapperPass(*PR); initializeRootSignatureAnalysisWrapperPass(*PR); initializeDXILFinalizeLinkageLegacyPass(*PR); diff --git a/llvm/test/CodeGen/DirectX/llc-pipeline.ll b/llvm/test/CodeGen/DirectX/llc-pipeline.ll index afbf1ff72ec7e..3a9af4d744f98 100644 --- a/llvm/test/CodeGen/DirectX/llc-pipeline.ll +++ b/llvm/test/CodeGen/DirectX/llc-pipeline.ll @@ -22,7 +22,6 @@ ; CHECK-NEXT: Dominator Tree Construction ; CHECK-NEXT: Scalarize vector operations ; CHECK-NEXT: DXIL Resource Binding Analysis -; CHECK-NEXT: DXIL resource Information ; CHECK-NEXT: DXIL Module Metadata analysis ; CHECK-NEXT: DXIL Shader Flag Analysis ; CHECK-NEXT: DXIL Translate Metadata _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits