-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[C API] Add accessors for function prefix and prologue data #82193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-ir Author: Benji Smith (Benjins) ChangesA 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:
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);
|
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
1cc19d8
to
b6c6cc2
Compare
bumping this: merged from latest main and resolved conflict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
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