Skip to content

Commit 73ebb05

Browse files
committed
[DirectX] Support opaque ptr for ValueAsMetadata in DXILBitcodeWriter
When writeValueAsMetadata for GlobalVariable and Function, write TypedPointerType for ValueType and FunctionType. Reviewed By: bogner Differential Revision: https://reviews.llvm.org/D127705
1 parent 3fa62ef commit 73ebb05

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,12 @@ void DXILBitcodeWriter::writeValueAsMetadata(
13571357
const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &Record) {
13581358
// Mimic an MDNode with a value as one operand.
13591359
Value *V = MD->getValue();
1360-
Record.push_back(getTypeID(V->getType()));
1360+
Type *Ty = V->getType();
1361+
if (Function *F = dyn_cast<Function>(V))
1362+
Ty = TypedPointerType::get(F->getFunctionType(), F->getAddressSpace());
1363+
else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
1364+
Ty = TypedPointerType::get(GV->getValueType(), GV->getAddressSpace());
1365+
Record.push_back(getTypeID(Ty));
13611366
Record.push_back(VE.getValueID(V));
13621367
Stream.EmitRecord(bitc::METADATA_VALUE, Record, 0);
13631368
Record.clear();

llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "DXILValueEnumerator.h"
15+
#include "DXILPointerType.h"
1516
#include "llvm/ADT/SmallVector.h"
1617
#include "llvm/Config/llvm-config.h"
1718
#include "llvm/IR/Argument.h"
@@ -373,6 +374,8 @@ ValueEnumerator::ValueEnumerator(const Module &M, Type *PrefixType) {
373374
for (const Function &F : M) {
374375
EnumerateValue(&F);
375376
EnumerateType(F.getValueType());
377+
EnumerateType(
378+
dxil::TypedPointerType::get(F.getFunctionType(), F.getAddressSpace()));
376379
EnumerateAttributes(F.getAttributes());
377380
}
378381

@@ -392,6 +395,8 @@ ValueEnumerator::ValueEnumerator(const Module &M, Type *PrefixType) {
392395
for (const GlobalVariable &GV : M.globals()) {
393396
if (GV.hasInitializer())
394397
EnumerateValue(GV.getInitializer());
398+
EnumerateType(
399+
dxil::TypedPointerType::get(GV.getValueType(), GV.getAddressSpace()));
395400
if (GV.hasAttributes())
396401
EnumerateAttributes(GV.getAttributesAsList(AttributeList::FunctionIndex));
397402
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: llc --filetype=obj %s -o - 2>&1 | dxil-dis -o - | FileCheck %s
2+
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"
3+
target triple = "dxil-ms-dx"
4+
5+
%"$Globals" = type { float }
6+
7+
@CBV = external constant %"$Globals"
8+
9+
define void @main() {
10+
ret void
11+
}
12+
13+
!llvm.ident = !{!0}
14+
!dx.version = !{!1}
15+
!dx.valver = !{!2}
16+
!dx.shaderModel = !{!3}
17+
!dx.entryPoints = !{!8}
18+
19+
!0 = !{!"clang version 15.0.0"}
20+
!1 = !{i32 1, i32 0}
21+
!2 = !{i32 1, i32 7}
22+
!3 = !{!"ps", i32 6, i32 0}
23+
!4 = !{null, null, !5, null}
24+
!5 = !{!6}
25+
; CHECK-DAG:!{{[0-9]+}} = !{i32 0, %"$Globals"* @CBV
26+
!6 = !{i32 0, ptr @CBV, !"", i32 0, i32 0, i32 1, i32 4, null}
27+
!7 = !{[2 x i32] [i32 0, i32 1]}
28+
; CHECK-DAG:!{{[0-9]+}} = !{void ()* @main
29+
!8 = !{ptr @main, !"main", null, !4, null}

0 commit comments

Comments
 (0)