[llvm] 7cfc9a3 - [llvm-c] Add getters for LLVMContextRef for various types (#99087)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 05:10:16 PDT 2024


Author: Bogdan-Alexandru Geană
Date: 2024-08-20T14:10:12+02:00
New Revision: 7cfc9a3a3d87e39611438e4bd178358329573294

URL: https://github.com/llvm/llvm-project/commit/7cfc9a3a3d87e39611438e4bd178358329573294
DIFF: https://github.com/llvm/llvm-project/commit/7cfc9a3a3d87e39611438e4bd178358329573294.diff

LOG: [llvm-c] Add getters for LLVMContextRef for various types (#99087)

Small PR to add additional getters for LLVMContextRef in the C API.

Added: 
    

Modified: 
    llvm/docs/ReleaseNotes.rst
    llvm/include/llvm-c/Core.h
    llvm/lib/IR/Core.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index d40bb2682f9ad8..7405023f9f27ed 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -157,6 +157,12 @@ Changes to the C API
   * ``LLVMGetNamedFunctionWithLength``
   * ``LLVMGetNamedGlobalWithLength``
 
+* The following functions are added to access the ``LLVMContextRef`` associated
+   with ``LLVMValueRef`` and ``LLVMBuilderRef`` objects:
+
+  * ``LLVMGetValueContext``
+  * ``LLVMGetBuilderContext``
+
 * The new pass manager can now be invoked with a custom alias analysis pipeline, using
   the ``LLVMPassBuilderOptionsSetAAPipeline`` function.
 

diff  --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 7d2e7c95520761..6c45af41631e7e 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -1973,6 +1973,13 @@ void LLVMDumpValue(LLVMValueRef Val);
  */
 char *LLVMPrintValueToString(LLVMValueRef Val);
 
+/**
+ * Obtain the context to which this value is associated.
+ *
+ * @see llvm::Value::getContext()
+ */
+LLVMContextRef LLVMGetValueContext(LLVMValueRef Val);
+
 /**
  * Return a string representation of the DbgRecord. Use
  * LLVMDisposeMessage to free the string.
@@ -4160,6 +4167,13 @@ LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder);
 void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
                                     LLVMMetadataRef FPMathTag);
 
+/**
+ * Obtain the context to which this builder is associated.
+ *
+ * @see llvm::IRBuilder::getContext()
+ */
+LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef Builder);
+
 /**
  * Deprecated: Passing the NULL location will crash.
  * Use LLVMGetCurrentDebugLocation2 instead.

diff  --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index dcad76ee8491dd..fc5c6222fc7880 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -1044,6 +1044,10 @@ char* LLVMPrintValueToString(LLVMValueRef Val) {
   return strdup(buf.c_str());
 }
 
+LLVMContextRef LLVMGetValueContext(LLVMValueRef Val) {
+  return wrap(&unwrap(Val)->getContext());
+}
+
 char *LLVMPrintDbgRecordToString(LLVMDbgRecordRef Record) {
   std::string buf;
   raw_string_ostream os(buf);
@@ -3329,6 +3333,10 @@ void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
                                        : nullptr);
 }
 
+LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef Builder) {
+  return wrap(&unwrap(Builder)->getContext());
+}
+
 LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder) {
   return wrap(unwrap(Builder)->getDefaultFPMathTag());
 }


        


More information about the llvm-commits mailing list