https://github.com/hvdijk updated https://github.com/llvm/llvm-project/pull/201336
>From 67f62403427919d636fd0f17d5752955a3bfe26e Mon Sep 17 00:00:00 2001 From: Harald van Dijk <[email protected]> Date: Wed, 3 Jun 2026 00:57:34 +0100 Subject: [PATCH] [DirectX][NFC] Delay converting to old-style debug info This is NFC at the moment, but upcoming work relies on debug info still using new-style debug records after DXILPrepare. --- llvm/lib/Target/DirectX/DXILPrepare.cpp | 121 ++++++++++-------- llvm/lib/Target/DirectX/DirectX.h | 4 + .../DirectX/DirectXIRPasses/DXILDebugInfo.cpp | 10 ++ 3 files changed, 79 insertions(+), 56 deletions(-) diff --git a/llvm/lib/Target/DirectX/DXILPrepare.cpp b/llvm/lib/Target/DirectX/DXILPrepare.cpp index 81f4d3da48362..7aafc926a5c5a 100644 --- a/llvm/lib/Target/DirectX/DXILPrepare.cpp +++ b/llvm/lib/Target/DirectX/DXILPrepare.cpp @@ -33,55 +33,71 @@ using namespace llvm; using namespace llvm::dxil; -namespace { - -constexpr bool isValidForDXIL(Attribute::AttrKind Attr) { - return is_contained({Attribute::Alignment, - Attribute::AlwaysInline, - Attribute::Builtin, - Attribute::ByVal, - Attribute::InAlloca, - Attribute::Cold, - Attribute::Convergent, - Attribute::InlineHint, - Attribute::InReg, - Attribute::JumpTable, - Attribute::MinSize, - Attribute::Naked, - Attribute::Nest, - Attribute::NoAlias, - Attribute::NoBuiltin, - Attribute::NoDuplicate, - Attribute::NoImplicitFloat, - Attribute::NoInline, - Attribute::NonLazyBind, - Attribute::NonNull, - Attribute::Dereferenceable, - Attribute::DereferenceableOrNull, - Attribute::Memory, - Attribute::NoRedZone, - Attribute::NoReturn, - Attribute::NoUnwind, - Attribute::OptimizeForSize, - Attribute::OptimizeNone, - Attribute::ReadNone, - Attribute::ReadOnly, - Attribute::Returned, - Attribute::ReturnsTwice, - Attribute::SExt, - Attribute::StackAlignment, - Attribute::StackProtect, - Attribute::StackProtectReq, - Attribute::StackProtectStrong, - Attribute::SafeStack, - Attribute::StructRet, - Attribute::SanitizeAddress, - Attribute::SanitizeThread, - Attribute::SanitizeMemory, - Attribute::UWTable, - Attribute::ZExt}, - Attr); +namespace llvm { +namespace dxil { +const AttributeMask &getNonDXILAttributeMask() { + static const AttributeMask Result = [] { + AttributeMask DXILAttributeMask; + for (Attribute::AttrKind Kind : {Attribute::Alignment, + Attribute::AlwaysInline, + Attribute::Builtin, + Attribute::ByVal, + Attribute::InAlloca, + Attribute::Cold, + Attribute::Convergent, + Attribute::InlineHint, + Attribute::InReg, + Attribute::JumpTable, + Attribute::MinSize, + Attribute::Naked, + Attribute::Nest, + Attribute::NoAlias, + Attribute::NoBuiltin, + Attribute::NoDuplicate, + Attribute::NoImplicitFloat, + Attribute::NoInline, + Attribute::NonLazyBind, + Attribute::NonNull, + Attribute::Dereferenceable, + Attribute::DereferenceableOrNull, + Attribute::Memory, + Attribute::NoRedZone, + Attribute::NoReturn, + Attribute::NoUnwind, + Attribute::OptimizeForSize, + Attribute::OptimizeNone, + Attribute::ReadNone, + Attribute::ReadOnly, + Attribute::Returned, + Attribute::ReturnsTwice, + Attribute::SExt, + Attribute::StackAlignment, + Attribute::StackProtect, + Attribute::StackProtectReq, + Attribute::StackProtectStrong, + Attribute::SafeStack, + Attribute::StructRet, + Attribute::SanitizeAddress, + Attribute::SanitizeThread, + Attribute::SanitizeMemory, + Attribute::UWTable, + Attribute::ZExt}) + DXILAttributeMask.addAttribute(Kind); + AttributeMask Result; + for (Attribute::AttrKind Kind = Attribute::None; + Kind != Attribute::EndAttrKinds; + Kind = Attribute::AttrKind(Kind + 1)) { + if (!DXILAttributeMask.contains(Kind)) + Result.addAttribute(Kind); + } + return Result; + }(); + return Result; } +} // namespace dxil +} // namespace llvm + +namespace { static void collectDeadStringAttrs(AttributeMask &DeadAttrs, AttributeSet &&AS, const StringSet<> &LiveKeys, @@ -177,15 +193,8 @@ class DXILPrepareModule : public ModulePass { public: bool runOnModule(Module &M) override { - M.convertFromNewDbgValues(); - PointerTypeMap PointerTypes = PointerTypeAnalysis::run(M); - AttributeMask AttrMask; - for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; - I = Attribute::AttrKind(I + 1)) { - if (!isValidForDXIL(I)) - AttrMask.addAttribute(I); - } + const AttributeMask &AttrMask = getNonDXILAttributeMask(); const dxil::ModuleMetadataInfo MetadataInfo = getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata(); diff --git a/llvm/lib/Target/DirectX/DirectX.h b/llvm/lib/Target/DirectX/DirectX.h index dfeb1ab12665d..3aa91ca75dd4b 100644 --- a/llvm/lib/Target/DirectX/DirectX.h +++ b/llvm/lib/Target/DirectX/DirectX.h @@ -12,6 +12,7 @@ #define LLVM_LIB_TARGET_DIRECTX_DIRECTX_H namespace llvm { +class AttributeMask; class FunctionPass; class ModulePass; class PassRegistry; @@ -126,6 +127,9 @@ void initializeDXILFinalizeLinkageLegacyPass(PassRegistry &); /// Pass to finalize linkage of functions. ModulePass *createDXILFinalizeLinkageLegacyPass(); +namespace dxil { +const AttributeMask &getNonDXILAttributeMask(); +} // namespace dxil } // namespace llvm #endif // LLVM_LIB_TARGET_DIRECTX_DIRECTX_H diff --git a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp index 0fa81186000f9..7ccf46ab9239e 100644 --- a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp +++ b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp @@ -7,7 +7,9 @@ //===----------------------------------------------------------------------===// #include "DXILDebugInfo.h" +#include "DirectX.h" #include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicsDirectX.h" @@ -64,11 +66,19 @@ static void replaceDbgValue(Module &M, DXILDebugInfoMap &Res) { } DXILDebugInfoMap DXILDebugInfoPass::run(Module &M) { + M.convertFromNewDbgValues(); + DXILDebugInfoMap Res; DebugInfoFinder DIF; DIF.processModule(M); + const AttributeMask &AttrMask = getNonDXILAttributeMask(); for (auto &F : M) { + F.removeFnAttrs(AttrMask); + F.removeRetAttrs(AttrMask); + for (unsigned ArgNo = 0; ArgNo != F.arg_size(); ++ArgNo) + F.removeParamAttrs(ArgNo, AttrMask); + for (auto &BB : F) { for (auto &I : make_early_inc_range(reverse(BB))) { if (auto *DL = dyn_cast<DbgLabelInst>(&I)) { _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
