diff options
author | peter mckinna <peter.mckinna@gmail.com> | 2025-07-12 00:55:54 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-11 15:55:54 +0100 |
commit | 2c0d563a76fcda85d655f39a8fd287bbf0e547ca (patch) | |
tree | 6b023111c8895ce17a4a3c4cbb5ea26ab92c425b /llvm/lib/IR/DebugInfo.cpp | |
parent | b152611cbead7e1ee239b57624734b909cd4212b (diff) | |
download | llvm-2c0d563a76fcda85d655f39a8fd287bbf0e547ca.zip llvm-2c0d563a76fcda85d655f39a8fd287bbf0e547ca.tar.gz llvm-2c0d563a76fcda85d655f39a8fd287bbf0e547ca.tar.bz2 |
Add debuginfo C support for a SetType, Subrangetype, dynamic array type and replace arrays (#135607)
This change adds some support to the C DebugInfo capability to create set types,
subrange types, dynamic array types and the ability to replace arrays.
Diffstat (limited to 'llvm/lib/IR/DebugInfo.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 4e09f84..84a56058 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -1325,6 +1325,63 @@ return wrap(unwrap(Builder)->createEnumerationType( LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy))); } +LLVMMetadataRef LLVMDIBuilderCreateSetType( + LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, + uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef BaseTy) { + return wrap(unwrap(Builder)->createSetType( + unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), + LineNumber, SizeInBits, AlignInBits, unwrapDI<DIType>(BaseTy))); +} + +LLVMMetadataRef LLVMDIBuilderCreateSubrangeType( + LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t SizeInBits, + uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef BaseTy, + LLVMMetadataRef LowerBound, LLVMMetadataRef UpperBound, + LLVMMetadataRef Stride, LLVMMetadataRef Bias) { + return wrap(unwrap(Builder)->createSubrangeType( + {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, unwrapDI<DIScope>(Scope), + SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags), + unwrapDI<DIType>(BaseTy), unwrap(LowerBound), unwrap(UpperBound), + unwrap(Stride), unwrap(Bias))); +} + +/// MD may be nullptr, a DIExpression or DIVariable. +PointerUnion<DIExpression *, DIVariable *> unwrapExprVar(LLVMMetadataRef MD) { + if (!MD) + return nullptr; + MDNode *MDN = unwrapDI<MDNode>(MD); + if (auto *E = dyn_cast<DIExpression>(MDN)) + return E; + assert(isa<DIVariable>(MDN) && "Expected DIExpression or DIVariable"); + return cast<DIVariable>(MDN); +} + +LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType( + LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t Size, + uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, + unsigned NumSubscripts, LLVMMetadataRef DataLocation, + LLVMMetadataRef Associated, LLVMMetadataRef Allocated, LLVMMetadataRef Rank, + LLVMMetadataRef BitStride) { + auto Subs = + unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), NumSubscripts}); + return wrap(unwrap(Builder)->createArrayType( + unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, + Size, AlignInBits, unwrapDI<DIType>(Ty), Subs, + unwrapExprVar(DataLocation), unwrapExprVar(Associated), + unwrapExprVar(Allocated), unwrapExprVar(Rank), unwrap(BitStride))); +} + +void LLVMReplaceArrays(LLVMDIBuilderRef Builder, LLVMMetadataRef *T, + LLVMMetadataRef *Elements, unsigned NumElements) { + auto CT = unwrap<DICompositeType>(*T); + auto Elts = + unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements}); + unwrap(Builder)->replaceArrays(CT, Elts); +} + LLVMMetadataRef LLVMDIBuilderCreateUnionType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, |