[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
This commit is contained in:
parent
3fa62efdbb
commit
73ebb05e44
|
@ -1357,7 +1357,12 @@ void DXILBitcodeWriter::writeValueAsMetadata(
|
|||
const ValueAsMetadata *MD, SmallVectorImpl<uint64_t> &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<Function>(V))
|
||||
Ty = TypedPointerType::get(F->getFunctionType(), F->getAddressSpace());
|
||||
else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(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();
|
||||
|
|
|
@ -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 @@ ValueEnumerator::ValueEnumerator(const Module &M, Type *PrefixType) {
|
|||
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 @@ ValueEnumerator::ValueEnumerator(const Module &M, Type *PrefixType) {
|
|||
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));
|
||||
}
|
||||
|
|
|
@ -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}
|
Loading…
Reference in New Issue