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 @@ -1357,7 +1357,12 @@ const ValueAsMetadata *MD, SmallVectorImpl &Record) { // Mimic an MDNode with a value as one operand. Value *V = MD->getValue(); - Record.push_back(getTypeID(V->getType())); + Type *Ty = V->getType(); + if (Function *F = dyn_cast(V)) + Ty = TypedPointerType::get(F->getFunctionType(), F->getAddressSpace()); + else if (GlobalVariable *GV = dyn_cast(V)) + Ty = TypedPointerType::get(GV->getValueType(), GV->getAddressSpace()); + Record.push_back(getTypeID(Ty)); Record.push_back(VE.getValueID(V)); Stream.EmitRecord(bitc::METADATA_VALUE, Record, 0); Record.clear(); diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp --- a/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp +++ b/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "DXILValueEnumerator.h" +#include "DXILPointerType.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/Argument.h" @@ -373,6 +374,8 @@ for (const Function &F : M) { EnumerateValue(&F); EnumerateType(F.getValueType()); + EnumerateType( + dxil::TypedPointerType::get(F.getFunctionType(), F.getAddressSpace())); EnumerateAttributes(F.getAttributes()); } @@ -392,6 +395,8 @@ for (const GlobalVariable &GV : M.globals()) { if (GV.hasInitializer()) EnumerateValue(GV.getInitializer()); + EnumerateType( + dxil::TypedPointerType::get(GV.getValueType(), GV.getAddressSpace())); if (GV.hasAttributes()) EnumerateAttributes(GV.getAttributesAsList(AttributeList::FunctionIndex)); } diff --git a/llvm/test/tools/dxil-dis/opaque-value_as_metadata.ll b/llvm/test/tools/dxil-dis/opaque-value_as_metadata.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/dxil-dis/opaque-value_as_metadata.ll @@ -0,0 +1,29 @@ +; RUN: llc --filetype=obj %s -o - 2>&1 | dxil-dis -o - | FileCheck %s +target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64" +target triple = "dxil-ms-dx" + +%"$Globals" = type { float } + +@CBV = external constant %"$Globals" + +define void @main() { + ret void +} + +!llvm.ident = !{!0} +!dx.version = !{!1} +!dx.valver = !{!2} +!dx.shaderModel = !{!3} +!dx.entryPoints = !{!8} + +!0 = !{!"clang version 15.0.0"} +!1 = !{i32 1, i32 0} +!2 = !{i32 1, i32 7} +!3 = !{!"ps", i32 6, i32 0} +!4 = !{null, null, !5, null} +!5 = !{!6} +; CHECK-DAG:!{{[0-9]}} = !{i32 0, %"$Globals"* @CBV +!6 = !{i32 0, ptr @CBV, !"", i32 0, i32 0, i32 1, i32 4, null} +!7 = !{[2 x i32] [i32 0, i32 1]} +; CHECK-DAG:!{{[0-9]}} = !{void ()* @main +!8 = !{ptr @main, !"main", null, !4, null}