[llvm] [llvm-c] Add getters for LLVMContextRef for various types (PR #99087)
Bogdan-Alexandru Geană via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 17 09:50:02 PDT 2024
https://github.com/abgeana updated https://github.com/llvm/llvm-project/pull/99087
>From fd31863a5dc64dcb3e02ddc468ab29a2ac771876 Mon Sep 17 00:00:00 2001
From: Alexandru Geana <ab at geana.io>
Date: Tue, 16 Jul 2024 21:27:20 +0200
Subject: [PATCH] [llvm-c] Add getters for LLVMContextRef for various types
---
llvm/docs/ReleaseNotes.rst | 6 ++++++
llvm/include/llvm-c/Core.h | 14 ++++++++++++++
llvm/lib/IR/Core.cpp | 8 ++++++++
3 files changed, 28 insertions(+)
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 42c0ad976089f7..ba2d6260dac79f 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -156,6 +156,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``
+
Changes to the CodeGen infrastructure
-------------------------------------
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