llvm.org GIT mirror llvm / 4240051
[LLVM-C] Move DIBuilder Bindings For Temporary MDNodes Summary: Move LLVMTemporaryMDNode and LLVMMetadataReplaceAllUsesWith to the C bindings and add LLVMDeleteTemporaryMDNode for deleting non-RAUW'ed temporary nodes. Reviewers: whitequark, harlanhaskins, deadalnix Reviewed By: whitequark Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D46632 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332010 91177308-0d34-0410-b5e6-96231b3b80d8 Robert Widmann 1 year, 4 months ago
7 changed file(s) with 70 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
3535 MDNode::get(*unwrap(C), ArrayRef(unwrap(MDs), Count)));
3636 }
3737
38 LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
39 unsigned Count) {
40 return wrap(MDTuple::getTemporary(*unwrap(C),
41 ArrayRef(unwrap(MDs), Count))
42 .release());
43 }
44
4538 void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
4639 LLVMMetadataRef Val) {
4740 NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
5548 void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD) {
5649 MDNode *N = MD ? unwrap(MD) : nullptr;
5750 unwrap(Inst)->setMetadata(KindID, N);
58 }
59
60 void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) {
61 auto *Node = unwrap(MD);
62 Node->replaceAllUsesWith(unwrap(New));
63 MDNode::deleteTemporary(Node);
6451 }
6552
6653 void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
3737 LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen);
3838 LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs,
3939 unsigned Count);
40 LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
41 unsigned Count);
4240
4341 void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
4442 LLVMMetadataRef Val);
4543 void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD);
46
47 void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New);
4844
4945 void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
5046 unsigned Col, LLVMMetadataRef Scope,
584584 }
585585 return 0
586586 }
587
588 //-------------------------------------------------------------------------
589 // llvm.Metadata
590 //-------------------------------------------------------------------------
591
592 func (c Context) TemporaryMDNode(mds []Metadata) (md Metadata) {
593 ptr, nvals := llvmMetadataRefs(mds)
594 md.C = C.LLVMTemporaryMDNode(c.C, ptr, C.size_t(nvals))
595 return
596 }
597
598 func (md Metadata) ReplaceAllUsesWith(new Metadata) {
599 C.LLVMMetadataReplaceAllUsesWith(md.C, new.C)
600 }
783783 md.C = C.LLVMMDNode2(c.C, ptr, nvals)
784784 return
785785 }
786 func (c Context) TemporaryMDNode(mds []Metadata) (md Metadata) {
787 ptr, nvals := llvmMetadataRefs(mds)
788 md.C = C.LLVMTemporaryMDNode(c.C, ptr, nvals)
789 return
790 }
791786 func (v Value) ConstantAsMetadata() (md Metadata) {
792787 md.C = C.LLVMConstantAsMetadata(v.C)
793788 return
19151910 // the module provider.
19161911 // See llvm::PassManagerBase::~PassManagerBase.
19171912 func (pm PassManager) Dispose() { C.LLVMDisposePassManager(pm.C) }
1918
1919 //-------------------------------------------------------------------------
1920 // llvm.Metadata
1921 //-------------------------------------------------------------------------
1922
1923 func (md Metadata) ReplaceAllUsesWith(new Metadata) {
1924 C.LLVMMetadataReplaceAllUsesWith(md.C, new.C)
1925 }
829829 LLVMMetadataRef Expr,
830830 LLVMMetadataRef Decl,
831831 uint32_t AlignInBits);
832 /**
833 * Create a new temporary \c MDNode. Suitable for use in constructing cyclic
834 * \c MDNode structures. A temporary \c MDNode is not uniqued, may be RAUW'd,
835 * and must be manually deleted with \c LLVMDisposeTemporaryMDNode.
836 * \param Ctx The context in which to construct the temporary node.
837 * \param Data The metadata elements.
838 * \param NumElements Number of metadata elements.
839 */
840 LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data,
841 size_t NumElements);
842
843 /**
844 * Deallocate a temporary node.
845 *
846 * Calls \c replaceAllUsesWith(nullptr) before deleting, so any remaining
847 * references will be reset.
848 * \param TempNode The temporary metadata node.
849 */
850 void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode);
851
852 /**
853 * Replace all uses of temporary metadata.
854 * \param TempTargetMetadata The temporary metadata node.
855 * \param Replacement The replacement metadata node.
856 */
857 void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TempTargetMetadata,
858 LLVMMetadataRef Replacement);
832859
833860 /**
834861 * Create a new descriptor for the specified global variable that is temporary
11511151 unwrapDI(Decl), AlignInBits));
11521152 }
11531153
1154 LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data,
1155 size_t Count) {
1156 return wrap(
1157 MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release());
1158 }
1159
1160 void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode) {
1161 MDNode::deleteTemporary(unwrapDI(TempNode));
1162 }
1163
1164 void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TargetMetadata,
1165 LLVMMetadataRef Replacement) {
1166 auto *Node = unwrapDI(TargetMetadata);
1167 Node->replaceAllUsesWith(unwrap(Replacement));
1168 MDNode::deleteTemporary(Node);
1169 }
1170
11541171 LLVMMetadataRef
11551172 LLVMDIBuilderCreateTempGlobalVariableFwdDecl(LLVMDIBuilderRef Builder,
11561173 LLVMMetadataRef Scope,
9292 LLVMMetadataRef ParamTypes[] = {Int64Ty, Int64Ty, VectorTy};
9393 LLVMMetadataRef FunctionTy =
9494 LLVMDIBuilderCreateSubroutineType(DIB, File, ParamTypes, 3, 0);
95
96 LLVMMetadataRef ReplaceableFunctionMetadata =
97 LLVMDIBuilderCreateReplaceableCompositeType(DIB, 0x15, "foo", 3,
98 File, File, 42,
99 0, 0, 0,
100 LLVMDIFlagFwdDecl,
101 "", 0);
102
103 LLVMMetadataRef FooParamLocation =
104 LLVMDIBuilderCreateDebugLocation(LLVMGetGlobalContext(), 42, 0,
105 ReplaceableFunctionMetadata, NULL);
95106 LLVMMetadataRef FunctionMetadata =
96107 LLVMDIBuilderCreateFunction(DIB, File, "foo", 3, "foo", 3,
97108 File, 42, FunctionTy, true, true,
98109 42, 0, false);
110 LLVMMetadataReplaceAllUsesWith(ReplaceableFunctionMetadata, FunctionMetadata);
99111
100 LLVMMetadataRef FooParamLocation =
101 LLVMDIBuilderCreateDebugLocation(LLVMGetGlobalContext(), 42, 0,
102 FunctionMetadata, NULL);
103112 LLVMMetadataRef FooParamExpression =
104113 LLVMDIBuilderCreateExpression(DIB, NULL, 0);
105114 LLVMMetadataRef FooParamVar1 =