[llvm] r358038 - [LLVM-C] Add Bindings to Access an Instruction's DebugLoc

Robert Widmann via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 15:27:51 PDT 2019


Author: codafi
Date: Tue Apr  9 15:27:51 2019
New Revision: 358038

URL: http://llvm.org/viewvc/llvm-project?rev=358038&view=rev
Log:
[LLVM-C] Add Bindings to Access an Instruction's DebugLoc

Summary: Provide direct accessors to supplement LLVMSetInstDebugLocation.  In addition, properly accept and return the NULL location.  The old accessors provided no way to do this, so the current debug location cannot currently be cleared.

Reviewers: whitequark, deadalnix

Reviewed By: whitequark

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D60481

Modified:
    llvm/trunk/include/llvm-c/DebugInfo.h
    llvm/trunk/lib/IR/DebugInfo.cpp

Modified: llvm/trunk/include/llvm-c/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/DebugInfo.h?rev=358038&r1=358037&r2=358038&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/DebugInfo.h (original)
+++ llvm/trunk/include/llvm-c/DebugInfo.h Tue Apr  9 15:27:51 2019
@@ -1193,6 +1193,22 @@ LLVMMetadataRef LLVMGetSubprogram(LLVMVa
 void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP);
 
 /**
+ * Get the debug location for the given instruction.
+ *
+ * @see llvm::Instruction::getDebugLoc()
+ */
+LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst);
+
+/**
+ * Set the debug location for the given instruction.
+ *
+ * To clear the location metadata of the given instruction, pass NULL to \p Loc.
+ *
+ * @see llvm::Instruction::setDebugLoc()
+ */
+void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc);
+
+/**
  * Obtain the enumerated type of a Metadata instance.
  *
  * @see llvm::Metadata::getMetadataID()

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=358038&r1=358037&r2=358038&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Tue Apr  9 15:27:51 2019
@@ -1355,6 +1355,17 @@ void LLVMSetSubprogram(LLVMValueRef Func
   unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
 }
 
+LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst) {
+  return wrap(unwrap<Instruction>(Inst)->getDebugLoc().getAsMDNode());
+}
+
+void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) {
+  if (Loc)
+    unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc(unwrap<MDNode>(Loc)));
+  else
+    unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
+}
+
 LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata) {
   switch(unwrap(Metadata)->getMetadataID()) {
 #define HANDLE_METADATA_LEAF(CLASS) \




More information about the llvm-commits mailing list