diff --git a/llvm/lib/Target/DirectX/DXILPrepare.cpp b/llvm/lib/Target/DirectX/DXILPrepare.cpp --- a/llvm/lib/Target/DirectX/DXILPrepare.cpp +++ b/llvm/lib/Target/DirectX/DXILPrepare.cpp @@ -54,6 +54,7 @@ Attribute::NonNull, Attribute::Dereferenceable, Attribute::DereferenceableOrNull, + Attribute::Memory, Attribute::NoRedZone, Attribute::NoReturn, Attribute::NoUnwind, @@ -61,7 +62,6 @@ Attribute::OptimizeNone, Attribute::ReadNone, Attribute::ReadOnly, - Attribute::ArgMemOnly, Attribute::Returned, Attribute::ReturnsTwice, Attribute::SExt, diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp --- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp +++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp @@ -40,6 +40,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Metadata.h" +#include "llvm/IR/ModRef.h" #include "llvm/IR/Module.h" #include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/IR/Operator.h" @@ -276,6 +277,13 @@ unsigned Abbrev) { llvm_unreachable("DXIL cannot contain DIArgList Nodes"); } + void writeDIAssignID(const DIAssignID *N, SmallVectorImpl &Record, + unsigned Abbrev) { + // DIAssignID is experimental feature to track variable location in IR.. + // FIXME: translate DIAssignID to debug info DXIL supports. + // See https://github.com/llvm/llvm-project/issues/58989 + llvm_unreachable("DXIL cannot contain DIAssignID Nodes"); + } void writeDIModule(const DIModule *N, SmallVectorImpl &Record, unsigned Abbrev); void writeDITemplateTypeParameter(const DITemplateTypeParameter *N, @@ -661,8 +669,6 @@ return bitc::ATTR_KIND_ALIGNMENT; case Attribute::AlwaysInline: return bitc::ATTR_KIND_ALWAYS_INLINE; - case Attribute::ArgMemOnly: - return bitc::ATTR_KIND_ARGMEMONLY; case Attribute::Builtin: return bitc::ATTR_KIND_BUILTIN; case Attribute::ByVal: @@ -929,12 +935,29 @@ Record.push_back(0); Record.push_back(Val); } else if (Attr.isIntAttribute()) { - uint64_t Val = getAttrKindEncoding(Attr.getKindAsEnum()); - assert(Val <= bitc::ATTR_KIND_ARGMEMONLY && - "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY"); - Record.push_back(1); - Record.push_back(Val); - Record.push_back(Attr.getValueAsInt()); + if (Attr.getKindAsEnum() == Attribute::AttrKind::Memory) { + MemoryEffects ME = Attr.getMemoryEffects(); + if (ME.doesNotAccessMemory()) { + Record.push_back(0); + Record.push_back(bitc::ATTR_KIND_READ_NONE); + } else { + if (ME.onlyReadsMemory()) { + Record.push_back(0); + Record.push_back(bitc::ATTR_KIND_READ_ONLY); + } + if (ME.onlyAccessesArgPointees()) { + Record.push_back(0); + Record.push_back(bitc::ATTR_KIND_ARGMEMONLY); + } + } + } else { + uint64_t Val = getAttrKindEncoding(Attr.getKindAsEnum()); + assert(Val <= bitc::ATTR_KIND_ARGMEMONLY && + "DXIL does not support attributes above ATTR_KIND_ARGMEMONLY"); + Record.push_back(1); + Record.push_back(Val); + Record.push_back(Attr.getValueAsInt()); + } } else { StringRef Kind = Attr.getKindAsString(); StringRef Val = Attr.getValueAsString(); diff --git a/llvm/test/CodeGen/DirectX/strip-fn-attrs.ll b/llvm/test/CodeGen/DirectX/strip-fn-attrs.ll --- a/llvm/test/CodeGen/DirectX/strip-fn-attrs.ll +++ b/llvm/test/CodeGen/DirectX/strip-fn-attrs.ll @@ -1,7 +1,7 @@ ; RUN: llc %s --filetype=asm -o - | FileCheck %s target triple = "dxil-unknown-shadermodel6.7-library" -; CHECK: Function Attrs: nounwind readnone +; CHECK: Function Attrs: nounwind memory(none) ; Function Attrs: norecurse nounwind readnone willreturn define dso_local float @fma(float %0, float %1, float %2) local_unnamed_addr #0 { %4 = fmul float %0, %1 @@ -9,11 +9,11 @@ ret float %5 } -; CHECK: Function Attrs: nounwind readnone +; CHECK: Function Attrs: nounwind memory(none) ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn declare void @llvm.dbg.value(metadata, metadata, metadata) #1 -; CHECK: attributes #0 = { nounwind readnone } +; CHECK: attributes #0 = { nounwind memory(none) } ; CHECK-NOT attributes # attributes #0 = { norecurse nounwind readnone willreturn } diff --git a/llvm/test/tools/dxil-dis/attribute-filter.ll b/llvm/test/tools/dxil-dis/attribute-filter.ll --- a/llvm/test/tools/dxil-dis/attribute-filter.ll +++ b/llvm/test/tools/dxil-dis/attribute-filter.ll @@ -11,5 +11,16 @@ ret float %5 } +; CHECK: Function Attrs: readnone +; Function Attrs: norecurse readnone willreturn +define float @fma2(float %0, float %1, float %2) #1 { + %4 = fmul float %0, %1 + %5 = fadd float %4, %2 + ret float %5 +} + ; CHECK: attributes #0 = { nounwind readnone "disable-tail-calls"="false" } attributes #0 = { norecurse nounwind readnone willreturn "disable-tail-calls"="false" } + +; CHECK: attributes #1 = { readnone "disable-tail-calls"="false" } +attributes #1 = { norecurse memory(none) willreturn "disable-tail-calls"="false" }