aboutsummaryrefslogtreecommitdiff
path: root/llvm/bindings
diff options
context:
space:
mode:
authorOrlando Cazalet-Hyams <orlando.hyams@sony.com>2024-06-10 09:21:40 +0100
committerGitHub <noreply@github.com>2024-06-10 09:21:40 +0100
commitd732a3298a70d83e5571c594de9be63df85668a7 (patch)
tree5b75158a1f1654d9ecfbc45425d2888094fb1d21 /llvm/bindings
parent26224ca2de193dcfd21ede7a846c28ea892b77e3 (diff)
downloadllvm-d732a3298a70d83e5571c594de9be63df85668a7.zip
llvm-d732a3298a70d83e5571c594de9be63df85668a7.tar.gz
llvm-d732a3298a70d83e5571c594de9be63df85668a7.tar.bz2
[RemoveDIs] C API: Add before-dbg-record versions of IRBuilder position funcs (#92417)
Add `LLVMPositionBuilderBeforeDbgRecords` and `LLVMPositionBuilderBeforeInstrAndDbgRecords` to `llvm/include/llvm-c/Core.h` which behave the same as `LLVMPositionBuilder` and `LVMPositionBuilderBefore` except that the position is set before debug records attached to the target instruction (the existing functions set the insertion point to after any attached debug records). More info on debug records and the migration towards using them can be found here: https://llvm.org/docs/RemoveDIsDebugInfo.html The distinction is important in some situations. An important example is when inserting a phi before another instruction which has debug records attached to it (these come "before" the instruction). Inserting before the instruction but after the debug records would result in having debug records before a phi, which is illegal. That results in an assertion failure: `llvm/lib/IR/Instruction.cpp:166: Assertion '!isa<PHINode>(this) && "Inserting PHI after debug-records!"' failed.` In llvm (C++) we've added bit to instruction iterators that carries around the extra information. Adding dedicated functions seemed like the least invasive and least suprising way to update the C API. Update llvm/tools/llvm-c-test/debuginfo.c to test this functionality. Update the OCaml bindings, the migration docs and release notes.
Diffstat (limited to 'llvm/bindings')
-rw-r--r--llvm/bindings/ocaml/llvm/llvm.ml5
-rw-r--r--llvm/bindings/ocaml/llvm/llvm.mli12
-rw-r--r--llvm/bindings/ocaml/llvm/llvm_ocaml.c12
3 files changed, 29 insertions, 0 deletions
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 7eeaae4..7bfaf86 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -1135,6 +1135,9 @@ external delete_instruction : llvalue -> unit = "llvm_delete_instruction"
external builder : llcontext -> llbuilder = "llvm_builder"
external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
= "llvm_position_builder"
+external position_builder_before_dbg_records : (llbasicblock, llvalue) llpos ->
+ llbuilder -> unit
+ = "llvm_position_builder_before_dbg_records"
external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
external insert_into_builder : llvalue -> string -> llbuilder -> unit
= "llvm_insert_into_builder"
@@ -1148,6 +1151,8 @@ let builder_before context i = builder_at context (Before i)
let builder_at_end context bb = builder_at context (At_end bb)
let position_before i = position_builder (Before i)
+let position_before_dbg_records i =
+ position_builder_before_dbg_records (Before i)
let position_at_end bb = position_builder (At_end bb)
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index 36cc095..89b894b 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1874,10 +1874,22 @@ val builder_at_end : llcontext -> llbasicblock -> llbuilder
See the constructor for [llvm::LLVMBuilder]. *)
val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
+(** [position_builder_before_dbg_records ip bb before_dbg_records] moves the
+ instruction builder [bb] to the position [ip], before any debug records
+ there.
+ See the constructor for [llvm::LLVMBuilder]. *)
+val position_builder_before_dbg_records : (llbasicblock, llvalue) llpos ->
+ llbuilder -> unit
+
(** [position_before ins b] moves the instruction builder [b] to before the
instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
val position_before : llvalue -> llbuilder -> unit
+(** [position_before_dbg_records ins b] moves the instruction builder [b]
+ to before the instruction [isn] and any debug records attached to it.
+ See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
+val position_before_dbg_records : llvalue -> llbuilder -> unit
+
(** [position_at_end bb b] moves the instruction builder [b] to the end of the
basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
val position_at_end : llbasicblock -> llbuilder -> unit
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 26a3ac2..3976a96 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -2005,6 +2005,18 @@ value llvm_builder(value C) {
}
/* (llbasicblock, llvalue) llpos -> llbuilder -> unit */
+value llvm_position_builder_before_dbg_records(value Pos, value B) {
+ if (Tag_val(Pos) == 0) {
+ LLVMBasicBlockRef BB = BasicBlock_val(Field(Pos, 0));
+ LLVMPositionBuilderAtEnd(Builder_val(B), BB);
+ } else {
+ LLVMValueRef I = Value_val(Field(Pos, 0));
+ LLVMPositionBuilderBeforeInstrAndDbgRecords(Builder_val(B), I);
+ }
+ return Val_unit;
+}
+
+/* (llbasicblock, llvalue) llpos -> llbuilder -> unit */
value llvm_position_builder(value Pos, value B) {
if (Tag_val(Pos) == 0) {
LLVMBasicBlockRef BB = BasicBlock_val(Field(Pos, 0));