[llvm] [C API] Add accessors for function prefix and prologue data (PR #82193)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 18 15:52:57 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Benji Smith (Benjins)
<details>
<summary>Changes</summary>
A test is added to echo.ll, and the echo.cpp part of llvm-c-test is updated to clone a function's prefix and prologue
---
Full diff: https://github.com/llvm/llvm-project/pull/82193.diff
5 Files Affected:
- (modified) llvm/docs/ReleaseNotes.rst (+12)
- (modified) llvm/include/llvm-c/Core.h (+38)
- (modified) llvm/lib/IR/Core.cpp (+32)
- (modified) llvm/test/Bindings/llvm-c/echo.ll (+14)
- (modified) llvm/tools/llvm-c-test/echo.cpp (+8)
``````````diff
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 5be00d9d5a5899..67df9a5e0ef1f6 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -125,6 +125,18 @@ Changes to the C API
* Added ``LLVMGetBlockAddressFunction`` and ``LLVMGetBlockAddressBasicBlock``
functions for accessing the values in a blockaddress constant.
+* Added the following functions for accessing a function's prefix data:
+
+ * ``LLVMHasPrefixData``
+ * ``LLVMGetPrefixData``
+ * ``LLVMSetPrefixData``
+
+* Added the following functions for accessing a function's prologue data:
+
+ * ``LLVMHasPrologueData``
+ * ``LLVMGetPrologueData``
+ * ``LLVMSetPrologueData``
+
Changes to the CodeGen infrastructure
-------------------------------------
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 09746bdaf0c94e..25560101c311ec 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2719,6 +2719,44 @@ const char *LLVMGetGC(LLVMValueRef Fn);
*/
void LLVMSetGC(LLVMValueRef Fn, const char *Name);
+/**
+ * Gets the prefix data associated with a function. Only valid on functions, and
+ * only if LLVMHasPrefixData returns true.
+ * See https://llvm.org/docs/LangRef.html#prefix-data
+ */
+LLVMValueRef LLVMGetPrefixData(LLVMValueRef Fn);
+
+/**
+ * Check if a given function has prefix data. Only valid on functions.
+ * See https://llvm.org/docs/LangRef.html#prefix-data
+ */
+LLVMBool LLVMHasPrefixData(LLVMValueRef Fn);
+
+/**
+ * Sets the prefix data for the function. Only valid on functions.
+ * See https://llvm.org/docs/LangRef.html#prefix-data
+ */
+void LLVMSetPrefixData(LLVMValueRef Fn, LLVMValueRef prefixData);
+
+/**
+ * Gets the prologue data associated with a function. Only valid on functions,
+ * and only if LLVMHasPrologueData returns true.
+ * See https://llvm.org/docs/LangRef.html#prologue-data
+ */
+LLVMValueRef LLVMGetPrologueData(LLVMValueRef Fn);
+
+/**
+ * Check if a given function has prologue data. Only valid on functions.
+ * See https://llvm.org/docs/LangRef.html#prologue-data
+ */
+LLVMBool LLVMHasPrologueData(LLVMValueRef Fn);
+
+/**
+ * Sets the prologue data for the function. Only valid on functions.
+ * See https://llvm.org/docs/LangRef.html#prologue-data
+ */
+void LLVMSetPrologueData(LLVMValueRef Fn, LLVMValueRef prologueData);
+
/**
* Add an attribute to a function.
*
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index d6d159ab8b9e83..9ff7dc296de8cf 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -2405,6 +2405,38 @@ void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
F->clearGC();
}
+LLVMValueRef LLVMGetPrefixData(LLVMValueRef Fn) {
+ Function *F = unwrap<Function>(Fn);
+ return wrap(F->getPrefixData());
+}
+
+LLVMBool LLVMHasPrefixData(LLVMValueRef Fn) {
+ Function *F = unwrap<Function>(Fn);
+ return F->hasPrefixData();
+}
+
+void LLVMSetPrefixData(LLVMValueRef Fn, LLVMValueRef prefixData) {
+ Function *F = unwrap<Function>(Fn);
+ Constant *prefix = unwrap<Constant>(prefixData);
+ F->setPrefixData(prefix);
+}
+
+LLVMValueRef LLVMGetPrologueData(LLVMValueRef Fn) {
+ Function *F = unwrap<Function>(Fn);
+ return wrap(F->getPrologueData());
+}
+
+LLVMBool LLVMHasPrologueData(LLVMValueRef Fn) {
+ Function *F = unwrap<Function>(Fn);
+ return F->hasPrologueData();
+}
+
+void LLVMSetPrologueData(LLVMValueRef Fn, LLVMValueRef prologueData) {
+ Function *F = unwrap<Function>(Fn);
+ Constant *prologue = unwrap<Constant>(prologueData);
+ F->setPrologueData(prologue);
+}
+
void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
LLVMAttributeRef A) {
unwrap<Function>(F)->addAttributeAtIndex(Idx, unwrap(A));
diff --git a/llvm/test/Bindings/llvm-c/echo.ll b/llvm/test/Bindings/llvm-c/echo.ll
index be0207599478b8..953a16b7e624e1 100644
--- a/llvm/test/Bindings/llvm-c/echo.ll
+++ b/llvm/test/Bindings/llvm-c/echo.ll
@@ -334,6 +334,20 @@ define void @test_fast_math_flags_call_outer(float %a) {
ret void
}
+define void @test_func_prefix_data_01() prefix i32 123 {
+ ret void
+}
+
+define void @test_func_prefix_data_02() prefix i64 2000 {
+ ret void
+}
+
+%func_prolog_struct = type <{ i8, i8, ptr }>
+
+define void @test_func_prologue_data_01() prologue %func_prolog_struct <{ i8 235, i8 8, ptr zeroinitializer}> {
+ ret void
+}
+
!llvm.dbg.cu = !{!0, !2}
!llvm.module.flags = !{!3}
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index bc708e2d472edd..d129fce3e8875c 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -1397,6 +1397,14 @@ static void clone_symbols(LLVMModuleRef Src, LLVMModuleRef M) {
}
LLVMDisposeValueMetadataEntries(AllMetadata);
+ // Copy any prefix data that may be on the function
+ if (LLVMHasPrefixData(Cur))
+ LLVMSetPrefixData(Fun, LLVMGetPrefixData(Cur));
+
+ // Copy any prologue data that may be on the function
+ if (LLVMHasPrologueData(Cur))
+ LLVMSetPrologueData(Fun, LLVMGetPrologueData(Cur));
+
FunCloner FC(Cur, Fun);
FC.CloneBBs(Cur);
``````````
</details>
https://github.com/llvm/llvm-project/pull/82193
More information about the llvm-commits
mailing list