From fd31863a5dc64dcb3e02ddc468ab29a2ac771876 Mon Sep 17 00:00:00 2001 From: Alexandru Geana 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 42c0ad976089f..ba2d6260dac79 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 7d2e7c9552076..6c45af41631e7 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 dcad76ee8491d..fc5c6222fc788 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()); }