[llvm] [RemoveDIs] C API: Add before-dbg-record versions of IRBuilder position funcs (PR #92417)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 01:04:40 PDT 2024
https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/92417
>From 4799699ec13bf9f63ee25c7bb3b7da3946511aaf Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Thu, 16 May 2024 10:12:56 +0100
Subject: [PATCH 01/10] Add BeforeDbgRecords option to C API insertion
functions
Inserting a PHI before an instruction with debug records attached results in
the following assert because the PHI needs to be inserted before its debug
records too.
llvm/lib/IR/Instruction.cpp:166: void llvm::Instruction::insertBefore(llvm::BasicBlock&, llvm::iplist_impl<llvm::simple_ilist<llvm::Instruction, llvm::ilist_iterator_bits<true> >, llvm::SymbolTableListTraits<llvm::Instruction, llvm::ilist_iterator_bits<true> > >::iterator): Assertion `!isa<PHINode>(this) && "Inserting PHI after debug-records!"' failed.
---
llvm/bindings/ocaml/llvm/llvm.ml | 16 ++++++------
llvm/bindings/ocaml/llvm/llvm.mli | 25 +++++++++++-------
llvm/bindings/ocaml/llvm/llvm_ocaml.c | 6 ++---
llvm/docs/ReleaseNotes.rst | 26 +++++++++++++++++++
llvm/docs/RemoveDIsDebugInfo.md | 10 +++++++
llvm/include/llvm-c/Core.h | 11 ++++++--
llvm/lib/IR/Core.cpp | 10 ++++---
llvm/test/Bindings/OCaml/core.ml | 4 +--
llvm/test/Bindings/OCaml/debuginfo.ml | 2 +-
llvm/test/Bindings/llvm-c/debug_info.ll | 3 +++
.../Bindings/llvm-c/debug_info_new_format.ll | 3 +++
llvm/tools/llvm-c-test/debuginfo.c | 19 +++++++++++++-
12 files changed, 106 insertions(+), 29 deletions(-)
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 7eeaae49e1059..9f5cafad09f8d 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -1133,22 +1133,22 @@ external delete_instruction : llvalue -> unit = "llvm_delete_instruction"
(*===-- Instruction builders ----------------------------------------------===*)
external builder : llcontext -> llbuilder = "llvm_builder"
-external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
- = "llvm_position_builder"
+external position_builder : (llbasicblock, llvalue) llpos -> bool -> llbuilder ->
+ unit = "llvm_position_builder"
external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
external insert_into_builder : llvalue -> string -> llbuilder -> unit
= "llvm_insert_into_builder"
-let builder_at context ip =
+let builder_at context ip before_dbg_records =
let b = builder context in
- position_builder ip b;
+ position_builder ip before_dbg_records b;
b
-let builder_before context i = builder_at context (Before i)
-let builder_at_end context bb = builder_at context (At_end bb)
+let builder_before context i before_dbg_records = builder_at context (Before i) before_dbg_records
+let builder_at_end context bb = builder_at context (At_end bb) false
-let position_before i = position_builder (Before i)
-let position_at_end bb = position_builder (At_end bb)
+let position_before i before_dbg_records = position_builder (Before i) before_dbg_records
+let position_at_end bb = position_builder (At_end bb) false
(*--... Metadata ...........................................................--*)
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index 36cc095dc66e3..9dcf446e032ff 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1857,26 +1857,33 @@ val incoming : llvalue -> (llvalue * llbasicblock) list
for [llvm::LLVMBuilder]. *)
val builder : llcontext -> llbuilder
-(** [builder_at ip] creates an instruction builder positioned at [ip].
+(** [builder_at ip before_dbg_records] creates an instruction builder
+ positioned at [ip]. [before_dbg_records] determines whether the insertion
+ point is before debug records attached to [ip].
See the constructor for [llvm::LLVMBuilder]. *)
-val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
+val builder_at : llcontext -> (llbasicblock, llvalue) llpos ->
+ bool -> llbuilder
-(** [builder_before ins] creates an instruction builder positioned before the
- instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
-val builder_before : llcontext -> llvalue -> llbuilder
+(** [builder_before ins before_dbg_records] creates an instruction builder
+ positioned before the instruction [isn]. [before_dbg_records] determines
+ whether the insertion point is before debug records attached to [isn].
+ See the constructor for [llvm::LLVMBuilder]. *)
+val builder_before : llcontext -> llvalue -> bool -> llbuilder
(** [builder_at_end bb] creates an instruction builder positioned at the end of
the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
val builder_at_end : llcontext -> llbasicblock -> llbuilder
-(** [position_builder ip bb] moves the instruction builder [bb] to the position
- [ip].
+(** [position_builder ip bb before_dbg_records] moves the instruction builder
+ [bb] to the position [ip]. [before_dbg_records] determines whether the
+ insertion point is before debug records attached to [ip].
See the constructor for [llvm::LLVMBuilder]. *)
-val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
+val position_builder : (llbasicblock, llvalue) llpos -> bool -> 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
+val position_before : llvalue -> bool -> 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]. *)
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 26a3ac21501d2..d0bf78f4c618d 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -2004,14 +2004,14 @@ value llvm_builder(value C) {
return alloc_builder(LLVMCreateBuilderInContext(Context_val(C)));
}
-/* (llbasicblock, llvalue) llpos -> llbuilder -> unit */
-value llvm_position_builder(value Pos, value B) {
+/* (llbasicblock, llvalue) llpos -> bool -> llbuilder -> unit */
+value llvm_position_builder(value Pos, value BeforeDbgRecords, 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));
- LLVMPositionBuilderBefore(Builder_val(B), I);
+ LLVMPositionBuilderBefore(Builder_val(B), I, Bool_val(BeforeDbgRecords));
}
return Val_unit;
}
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index e1e1652d1e0a1..05201038172ca 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -214,6 +214,32 @@ Changes to the C API
* ``LLVMConstICmp``
* ``LLVMConstFCmp``
+* Added the following functions for querying and setting the debug info format and for explicitly building either debug intrinsics (old format) or records (new format). These functions will be deprecated and removed in the future as we move towards removing support for the old debug format. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info.
+
+ * ``LLVMIsNewDbgInfoFormat``
+ * ``LLVMSetIsNewDbgInfoFormat``
+ * ``LLVMDIBuilderInsertDeclareIntrinsicBefore``
+ * ``LLVMDIBuilderInsertDeclareIntrinsicAtEnd``
+ * ``LLVMDIBuilderInsertDbgValueIntrinsicBefore``
+ * ``LLVMDIBuilderInsertDbgValueIntrinsicAtEnd``
+ * ``LLVMDIBuilderInsertDeclareRecordBefore``
+ * ``LLVMDIBuilderInsertDeclareRecordAtEnd``
+ * ``LLVMDIBuilderInsertDbgValueRecordBefore``
+ * ``LLVMDIBuilderInsertDbgValueRecordAtEnd``
+
+* Modified the following functions which now always insert debug records (new debug info format) rather than debug intrinsics (old debug info format). See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info.
+
+ * ``LLVMDIBuilderInsertDeclareBefore``
+ * ``LLVMDIBuilderInsertDeclareBefore``
+ * ``LLVMDIBuilderInsertDeclareAtEnd``
+ * ``LLVMDIBuilderInsertDbgValueBefore``
+ * ``LLVMDIBuilderInsertDbgValueAtEnd``
+
+* Modified the following functions, adding a new `BeforeDbgRecords` parameter which indicates whether or not the insertion position should also be before the debug records that precede the instruction. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info.
+
+ * ``LLVMPositionBuilder``
+ * ``LLVMPositionBuilderBefore``
+
Changes to the CodeGen infrastructure
-------------------------------------
diff --git a/llvm/docs/RemoveDIsDebugInfo.md b/llvm/docs/RemoveDIsDebugInfo.md
index 3cdf63c63b5a0..9ab54b5f0173b 100644
--- a/llvm/docs/RemoveDIsDebugInfo.md
+++ b/llvm/docs/RemoveDIsDebugInfo.md
@@ -60,8 +60,18 @@ LLVMDIBuilderInsertDeclareBefore # Insert a debug record (new debug info forma
LLVMDIBuilderInsertDeclareAtEnd # Same as above.
LLVMDIBuilderInsertDbgValueBefore # Same as above.
LLVMDIBuilderInsertDbgValueAtEnd # Same as above.
+
+Existing functions (new parameter)
+----------------------------------
+LLVMPositionBuilder # Added BeforeDbgRecords parameter. See info below.
+LLVMPositionBuilderBefore # Same as above.
```
+`LLVMPositionBuilder` and `LLVMPositionBuilderBefore` have gained a parameter `BeforeDbgRecords` which indicates whether or not the insertion position should also be before the debug records that precede the instruction. Note that this doesn't mean that debug intrinsics before the chosen instruction are skipped, only debug records (which unlike debug records are not themselves instructions).
+
+If you don't know whether it should be true or false then follow this rule:
+If you are trying to insert at the start of a block, or purposfully skip debug intrinsics to determine the insertion point for any other reason, then set it to true. Otherwise set it to false.
+
# The new "Debug Record" model
Below is a brief overview of the new representation that replaces debug intrinsics; for an instructive guide on updating old code, see [here](#how-to-update-existing-code).
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 7d6b8c7607974..253caa51ad847 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -3946,14 +3946,21 @@ const unsigned *LLVMGetIndices(LLVMValueRef Inst);
* An instruction builder represents a point within a basic block and is
* the exclusive means of building instructions using the C interface.
*
+ * Some insertion-position-setting methods have a "BeforeDbgRecords"
+ * parameter. Set to true if the insertion point should be in front of debug
+ * records, for example when inserting a phi. If you are trying to insert at the
+ * start of a block, or purposfully skip debug intrinsics to determine the
+ * insertion point for any other reason, then set it to true. Otherwise set it
+ * to false.
* @{
*/
LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
LLVMBuilderRef LLVMCreateBuilder(void);
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
- LLVMValueRef Instr);
-void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
+ LLVMValueRef Instr, LLVMBool BeforeDbgRecords);
+void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr,
+ LLVMBool BeforeDbgRecords);
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 4a508a022cf7e..3a4b9727225f0 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3138,15 +3138,19 @@ LLVMBuilderRef LLVMCreateBuilder(void) {
}
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
- LLVMValueRef Instr) {
+ LLVMValueRef Instr, LLVMBool BeforeDbgRecords) {
BasicBlock *BB = unwrap(Block);
auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->end();
+ I.setHeadBit(BeforeDbgRecords);
unwrap(Builder)->SetInsertPoint(BB, I);
}
-void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
+void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr,
+ LLVMBool BeforeDbgRecords) {
Instruction *I = unwrap<Instruction>(Instr);
- unwrap(Builder)->SetInsertPoint(I->getParent(), I->getIterator());
+ BasicBlock::iterator It = I->getIterator();
+ It.setHeadBit(BeforeDbgRecords);
+ unwrap(Builder)->SetInsertPoint(I->getParent(), It);
}
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
diff --git a/llvm/test/Bindings/OCaml/core.ml b/llvm/test/Bindings/OCaml/core.ml
index 36f4c468d99f4..d2265cf34d133 100644
--- a/llvm/test/Bindings/OCaml/core.ml
+++ b/llvm/test/Bindings/OCaml/core.ml
@@ -830,7 +830,7 @@ let test_instructions () =
let fty = function_type void_type [| i32_type; i32_type |] in
let f = define_function "f" fty m in
let bb = entry_block f in
- let b = builder_at context (At_end bb) in
+ let b = builder_at context (At_end bb) false in
insist (At_end bb = instr_begin bb);
insist (At_start bb = instr_end bb);
@@ -1150,7 +1150,7 @@ let test_builder () =
(* CHECK: ret{{.*}}P1
*)
let ret = build_ret p1 atentry in
- position_before ret atentry
+ position_before ret false atentry
end;
(* see test/Feature/exception.ll *)
diff --git a/llvm/test/Bindings/OCaml/debuginfo.ml b/llvm/test/Bindings/OCaml/debuginfo.ml
index f95800dfcb025..4f779743adaa0 100644
--- a/llvm/test/Bindings/OCaml/debuginfo.ml
+++ b/llvm/test/Bindings/OCaml/debuginfo.ml
@@ -273,7 +273,7 @@ let test_variables f dibuilder file_di fun_di =
stdout_metadata auto_var;
(* CHECK: [[LOCAL_VAR_PTR:<0x[0-9a-f]*>]] = !DILocalVariable(name: "my_local", scope: <{{0x[0-9a-f]*}}>, file: <{{0x[0-9a-f]*}}>, line: 10, type: [[INT64TY_PTR]])
*)
- let builder = Llvm.builder_before context entry_term in
+ let builder = Llvm.builder_before context entry_term false in
let all = Llvm.build_alloca (Llvm.i64_type context) "my_alloca" builder in
let scope =
Llvm_debuginfo.dibuild_create_lexical_block dibuilder ~scope:fun_di
diff --git a/llvm/test/Bindings/llvm-c/debug_info.ll b/llvm/test/Bindings/llvm-c/debug_info.ll
index 9358bac59bd21..71986fbb2348f 100644
--- a/llvm/test/Bindings/llvm-c/debug_info.ll
+++ b/llvm/test/Bindings/llvm-c/debug_info.ll
@@ -10,7 +10,10 @@
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !40, metadata !DIExpression()), !dbg !43
; CHECK-NEXT: br label %vars
; CHECK: vars:
+; CHECK-NEXT: %p1 = phi i64 [ 0, %entry ]
+; CHECK-NEXT: %p2 = phi i64 [ 0, %entry ]
; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !41, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !44
+; CHECK-NEXT: %a = add i64 %p1, %p2
; CHECK-NEXT: ret i64 0
; CHECK-NEXT: }
diff --git a/llvm/test/Bindings/llvm-c/debug_info_new_format.ll b/llvm/test/Bindings/llvm-c/debug_info_new_format.ll
index 05b6ef4de9adb..1b6f2c4ea403a 100644
--- a/llvm/test/Bindings/llvm-c/debug_info_new_format.ll
+++ b/llvm/test/Bindings/llvm-c/debug_info_new_format.ll
@@ -11,7 +11,10 @@
; CHECK-NEXT: #dbg_declare(i64 0, !40, !DIExpression(), !43)
; CHECK-NEXT: br label %vars
; CHECK: vars:
+; CHECK-NEXT: %p1 = phi i64 [ 0, %entry ]
+; CHECK-NEXT: %p2 = phi i64 [ 0, %entry ]
; CHECK-NEXT: #dbg_value(i64 0, !41, !DIExpression(DW_OP_constu, 0, DW_OP_stack_value), !44)
+; CHECK-NEXT: %a = add i64 %p1, %p2
; CHECK-NEXT: ret i64 0
; CHECK-NEXT: }
diff --git a/llvm/tools/llvm-c-test/debuginfo.c b/llvm/tools/llvm-c-test/debuginfo.c
index 35c65f885af32..ed1cb4e30223a 100644
--- a/llvm/tools/llvm-c-test/debuginfo.c
+++ b/llvm/tools/llvm-c-test/debuginfo.c
@@ -228,7 +228,24 @@ int llvm_test_dibuilder(bool NewDebugInfoFormat) {
LLVMPositionBuilderAtEnd(Builder, FooVarBlock);
LLVMTypeRef I64 = LLVMInt64TypeInContext(Ctx);
LLVMValueRef Zero = LLVMConstInt(I64, 0, false);
- LLVMBuildRet(Builder, Zero);
+ LLVMValueRef Ret = LLVMBuildRet(Builder, Zero);
+
+ // Insert a `phi` before the `ret`. In the new debug info mode we need to
+ // be careful to insert before debug records too, else the debug records
+ // will come before the `phi` (and be absorbed onto it) which is an invalid
+ // state.
+ LLVMValueRef InsertPos = LLVMGetFirstInstruction(FooVarBlock);
+ LLVMPositionBuilderBefore(Builder, InsertPos, true);
+ LLVMValueRef Phi1 = LLVMBuildPhi(Builder, I64, "p1");
+ LLVMAddIncoming(Phi1, &Zero, &FooEntryBlock, 1);
+ // Do the same again using the other position-setting function.
+ LLVMPositionBuilder(Builder, FooVarBlock, InsertPos, true);
+ LLVMValueRef Phi2 = LLVMBuildPhi(Builder, I64, "p2");
+ LLVMAddIncoming(Phi2, &Zero, &FooEntryBlock, 1);
+ // Insert a non-phi before the `ret` but not before the debug records to
+ // test that works as expected.
+ LLVMPositionBuilder(Builder, FooVarBlock, Ret, false);
+ LLVMBuildAdd(Builder, Phi1, Phi2, "a");
char *MStr = LLVMPrintModuleToString(M);
puts(MStr);
>From 94f1d14a8d9b2fd7f0d94310125599f183b520fc Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Thu, 16 May 2024 16:27:30 +0100
Subject: [PATCH 02/10] remove other docs updates
---
llvm/docs/ReleaseNotes.rst | 21 ---------------------
1 file changed, 21 deletions(-)
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 05201038172ca..40b4adc53c62e 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -214,27 +214,6 @@ Changes to the C API
* ``LLVMConstICmp``
* ``LLVMConstFCmp``
-* Added the following functions for querying and setting the debug info format and for explicitly building either debug intrinsics (old format) or records (new format). These functions will be deprecated and removed in the future as we move towards removing support for the old debug format. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info.
-
- * ``LLVMIsNewDbgInfoFormat``
- * ``LLVMSetIsNewDbgInfoFormat``
- * ``LLVMDIBuilderInsertDeclareIntrinsicBefore``
- * ``LLVMDIBuilderInsertDeclareIntrinsicAtEnd``
- * ``LLVMDIBuilderInsertDbgValueIntrinsicBefore``
- * ``LLVMDIBuilderInsertDbgValueIntrinsicAtEnd``
- * ``LLVMDIBuilderInsertDeclareRecordBefore``
- * ``LLVMDIBuilderInsertDeclareRecordAtEnd``
- * ``LLVMDIBuilderInsertDbgValueRecordBefore``
- * ``LLVMDIBuilderInsertDbgValueRecordAtEnd``
-
-* Modified the following functions which now always insert debug records (new debug info format) rather than debug intrinsics (old debug info format). See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info.
-
- * ``LLVMDIBuilderInsertDeclareBefore``
- * ``LLVMDIBuilderInsertDeclareBefore``
- * ``LLVMDIBuilderInsertDeclareAtEnd``
- * ``LLVMDIBuilderInsertDbgValueBefore``
- * ``LLVMDIBuilderInsertDbgValueAtEnd``
-
* Modified the following functions, adding a new `BeforeDbgRecords` parameter which indicates whether or not the insertion position should also be before the debug records that precede the instruction. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info.
* ``LLVMPositionBuilder``
>From bd478b765fd7d33c70093f9ffc476af817f4327b Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 20 May 2024 14:42:35 +0100
Subject: [PATCH 03/10] add new functions rather than update existing
---
llvm/docs/ReleaseNotes.rst | 5 +----
llvm/docs/RemoveDIsDebugInfo.md | 12 +++++++-----
llvm/include/llvm-c/Core.h | 16 +++++++++++-----
llvm/lib/IR/Core.cpp | 15 ++++++++++++---
4 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 40b4adc53c62e..1c79d9b5bc1cf 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -214,10 +214,7 @@ Changes to the C API
* ``LLVMConstICmp``
* ``LLVMConstFCmp``
-* Modified the following functions, adding a new `BeforeDbgRecords` parameter which indicates whether or not the insertion position should also be before the debug records that precede the instruction. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info.
-
- * ``LLVMPositionBuilder``
- * ``LLVMPositionBuilderBefore``
+* Added ``LLVMPositionBuilder2`` and ``LLVMPositionBuilderBefore2``. Same as ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore2`` with a new ``BeforeDbgRecords`` parameter which indicates whether or not the insertion position should also be before the debug records that precede the instruction. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info. ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore`` are unchanged. They insert before the indicated instruction but after any attached debug records (equivalent to calling the new variants with ``BeforeDbgRecords`` set to ``false``).
Changes to the CodeGen infrastructure
-------------------------------------
diff --git a/llvm/docs/RemoveDIsDebugInfo.md b/llvm/docs/RemoveDIsDebugInfo.md
index 9ab54b5f0173b..9893ba69f3711 100644
--- a/llvm/docs/RemoveDIsDebugInfo.md
+++ b/llvm/docs/RemoveDIsDebugInfo.md
@@ -36,7 +36,7 @@ For a more in-depth overview of how to update existing code to support debug rec
# C-API changes
-All the functions that have been added are temporary and will be deprecated in the future. The intention is that they'll help downstream projects adapt during the transition period.
+Some new functions that have been added are temporary and will be deprecated in the future. The intention is that they'll help downstream projects adapt during the transition period.
```
New functions (all to be deprecated)
@@ -61,17 +61,19 @@ LLVMDIBuilderInsertDeclareAtEnd # Same as above.
LLVMDIBuilderInsertDbgValueBefore # Same as above.
LLVMDIBuilderInsertDbgValueAtEnd # Same as above.
-Existing functions (new parameter)
+New functions (no plans to deprecate)
----------------------------------
-LLVMPositionBuilder # Added BeforeDbgRecords parameter. See info below.
-LLVMPositionBuilderBefore # Same as above.
+LLVMPositionBuilder2 # LLVMPositionBuilder but with BeforeDbgRecords parameter. See info below.
+LLVMPositionBuilderBefore2 # Same as above.
```
-`LLVMPositionBuilder` and `LLVMPositionBuilderBefore` have gained a parameter `BeforeDbgRecords` which indicates whether or not the insertion position should also be before the debug records that precede the instruction. Note that this doesn't mean that debug intrinsics before the chosen instruction are skipped, only debug records (which unlike debug records are not themselves instructions).
+`LLVMPositionBuilder2` and `LLVMPositionBuilderBefore2` have a parameter `BeforeDbgRecords` which indicates whether or not the insertion position should also be before the debug records that precede the instruction. Note that this doesn't mean that debug intrinsics before the chosen instruction are skipped, only debug records (which unlike debug records are not themselves instructions).
If you don't know whether it should be true or false then follow this rule:
If you are trying to insert at the start of a block, or purposfully skip debug intrinsics to determine the insertion point for any other reason, then set it to true. Otherwise set it to false.
+`LLVMPositionBuilder` and `LLVMPositionBuilderBefore` are unchanged. They insert before the indicated instruction but after any attached debug records (equivalent to calling the new variants with `BeforeDbgRecords` set to `false`).
+
# The new "Debug Record" model
Below is a brief overview of the new representation that replaces debug intrinsics; for an instructive guide on updating old code, see [here](#how-to-update-existing-code).
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 253caa51ad847..e2bdfeeb0b9f1 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -3946,21 +3946,27 @@ const unsigned *LLVMGetIndices(LLVMValueRef Inst);
* An instruction builder represents a point within a basic block and is
* the exclusive means of building instructions using the C interface.
*
- * Some insertion-position-setting methods have a "BeforeDbgRecords"
+ * Some insertion-position-setting functions have a "BeforeDbgRecords"
* parameter. Set to true if the insertion point should be in front of debug
* records, for example when inserting a phi. If you are trying to insert at the
* start of a block, or purposfully skip debug intrinsics to determine the
* insertion point for any other reason, then set it to true. Otherwise set it
- * to false.
+ * to false. Insertion-position-setting functions without the parameter always
+ * set the position after any attached debug records (i.e., as if
+ * "BeforeDbgRecords" is false).
+ *
* @{
*/
LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
LLVMBuilderRef LLVMCreateBuilder(void);
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
- LLVMValueRef Instr, LLVMBool BeforeDbgRecords);
-void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr,
- LLVMBool BeforeDbgRecords);
+ LLVMValueRef Instr);
+void LLVMPositionBuilder2(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
+ LLVMValueRef Instr, LLVMBool BeforeDbgRecords);
+void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
+void LLVMPositionBuilderBefore2(LLVMBuilderRef Builder, LLVMValueRef Instr,
+ LLVMBool BeforeDbgRecords);
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 3a4b9727225f0..1d61f93124407 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3138,15 +3138,24 @@ LLVMBuilderRef LLVMCreateBuilder(void) {
}
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
- LLVMValueRef Instr, LLVMBool BeforeDbgRecords) {
+ LLVMValueRef Instr) {
+ return LLVMPositionBuilder2(Builder, Block, Instr, false);
+}
+
+void LLVMPositionBuilder2(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
+ LLVMValueRef Instr, LLVMBool BeforeDbgRecords) {
BasicBlock *BB = unwrap(Block);
auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->end();
I.setHeadBit(BeforeDbgRecords);
unwrap(Builder)->SetInsertPoint(BB, I);
}
-void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr,
- LLVMBool BeforeDbgRecords) {
+void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
+ return LLVMPositionBuilderBefore2(Builder, Instr, false);
+}
+
+void LLVMPositionBuilderBefore2(LLVMBuilderRef Builder, LLVMValueRef Instr,
+ LLVMBool BeforeDbgRecords) {
Instruction *I = unwrap<Instruction>(Instr);
BasicBlock::iterator It = I->getIterator();
It.setHeadBit(BeforeDbgRecords);
>From c670cbf92a6581b212282ad374381af4cd621031 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 20 May 2024 14:57:15 +0100
Subject: [PATCH 04/10] update llvm-c-test/debuginfo.c
---
llvm/tools/llvm-c-test/debuginfo.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/tools/llvm-c-test/debuginfo.c b/llvm/tools/llvm-c-test/debuginfo.c
index ed1cb4e30223a..476168aedd19d 100644
--- a/llvm/tools/llvm-c-test/debuginfo.c
+++ b/llvm/tools/llvm-c-test/debuginfo.c
@@ -235,16 +235,16 @@ int llvm_test_dibuilder(bool NewDebugInfoFormat) {
// will come before the `phi` (and be absorbed onto it) which is an invalid
// state.
LLVMValueRef InsertPos = LLVMGetFirstInstruction(FooVarBlock);
- LLVMPositionBuilderBefore(Builder, InsertPos, true);
+ LLVMPositionBuilderBefore2(Builder, InsertPos, true);
LLVMValueRef Phi1 = LLVMBuildPhi(Builder, I64, "p1");
LLVMAddIncoming(Phi1, &Zero, &FooEntryBlock, 1);
// Do the same again using the other position-setting function.
- LLVMPositionBuilder(Builder, FooVarBlock, InsertPos, true);
+ LLVMPositionBuilder2(Builder, FooVarBlock, InsertPos, true);
LLVMValueRef Phi2 = LLVMBuildPhi(Builder, I64, "p2");
LLVMAddIncoming(Phi2, &Zero, &FooEntryBlock, 1);
// Insert a non-phi before the `ret` but not before the debug records to
// test that works as expected.
- LLVMPositionBuilder(Builder, FooVarBlock, Ret, false);
+ LLVMPositionBuilder2(Builder, FooVarBlock, Ret, false);
LLVMBuildAdd(Builder, Phi1, Phi2, "a");
char *MStr = LLVMPrintModuleToString(M);
>From 585b9d54c56b7d1b7939a86f2e345b9dec7eb840 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 20 May 2024 14:57:02 +0100
Subject: [PATCH 05/10] undo ocaml changes
---
llvm/bindings/ocaml/llvm/llvm.ml | 16 ++++++++--------
llvm/bindings/ocaml/llvm/llvm.mli | 25 +++++++++----------------
llvm/bindings/ocaml/llvm/llvm_ocaml.c | 6 +++---
llvm/test/Bindings/OCaml/core.ml | 4 ++--
llvm/test/Bindings/OCaml/debuginfo.ml | 2 +-
5 files changed, 23 insertions(+), 30 deletions(-)
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 9f5cafad09f8d..7eeaae49e1059 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -1133,22 +1133,22 @@ external delete_instruction : llvalue -> unit = "llvm_delete_instruction"
(*===-- Instruction builders ----------------------------------------------===*)
external builder : llcontext -> llbuilder = "llvm_builder"
-external position_builder : (llbasicblock, llvalue) llpos -> bool -> llbuilder ->
- unit = "llvm_position_builder"
+external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
+ = "llvm_position_builder"
external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
external insert_into_builder : llvalue -> string -> llbuilder -> unit
= "llvm_insert_into_builder"
-let builder_at context ip before_dbg_records =
+let builder_at context ip =
let b = builder context in
- position_builder ip before_dbg_records b;
+ position_builder ip b;
b
-let builder_before context i before_dbg_records = builder_at context (Before i) before_dbg_records
-let builder_at_end context bb = builder_at context (At_end bb) false
+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 before_dbg_records = position_builder (Before i) before_dbg_records
-let position_at_end bb = position_builder (At_end bb) false
+let position_before i = position_builder (Before i)
+let position_at_end bb = position_builder (At_end bb)
(*--... Metadata ...........................................................--*)
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index 9dcf446e032ff..36cc095dc66e3 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1857,33 +1857,26 @@ val incoming : llvalue -> (llvalue * llbasicblock) list
for [llvm::LLVMBuilder]. *)
val builder : llcontext -> llbuilder
-(** [builder_at ip before_dbg_records] creates an instruction builder
- positioned at [ip]. [before_dbg_records] determines whether the insertion
- point is before debug records attached to [ip].
+(** [builder_at ip] creates an instruction builder positioned at [ip].
See the constructor for [llvm::LLVMBuilder]. *)
-val builder_at : llcontext -> (llbasicblock, llvalue) llpos ->
- bool -> llbuilder
+val builder_at : llcontext -> (llbasicblock, llvalue) llpos -> llbuilder
-(** [builder_before ins before_dbg_records] creates an instruction builder
- positioned before the instruction [isn]. [before_dbg_records] determines
- whether the insertion point is before debug records attached to [isn].
- See the constructor for [llvm::LLVMBuilder]. *)
-val builder_before : llcontext -> llvalue -> bool -> llbuilder
+(** [builder_before ins] creates an instruction builder positioned before the
+ instruction [isn]. See the constructor for [llvm::LLVMBuilder]. *)
+val builder_before : llcontext -> llvalue -> llbuilder
(** [builder_at_end bb] creates an instruction builder positioned at the end of
the basic block [bb]. See the constructor for [llvm::LLVMBuilder]. *)
val builder_at_end : llcontext -> llbasicblock -> llbuilder
-(** [position_builder ip bb before_dbg_records] moves the instruction builder
- [bb] to the position [ip]. [before_dbg_records] determines whether the
- insertion point is before debug records attached to [ip].
+(** [position_builder ip bb] moves the instruction builder [bb] to the position
+ [ip].
See the constructor for [llvm::LLVMBuilder]. *)
-val position_builder : (llbasicblock, llvalue) llpos -> bool -> llbuilder ->
- unit
+val position_builder : (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 -> bool -> llbuilder -> unit
+val position_before : 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]. *)
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index d0bf78f4c618d..26a3ac21501d2 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -2004,14 +2004,14 @@ value llvm_builder(value C) {
return alloc_builder(LLVMCreateBuilderInContext(Context_val(C)));
}
-/* (llbasicblock, llvalue) llpos -> bool -> llbuilder -> unit */
-value llvm_position_builder(value Pos, value BeforeDbgRecords, value B) {
+/* (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));
LLVMPositionBuilderAtEnd(Builder_val(B), BB);
} else {
LLVMValueRef I = Value_val(Field(Pos, 0));
- LLVMPositionBuilderBefore(Builder_val(B), I, Bool_val(BeforeDbgRecords));
+ LLVMPositionBuilderBefore(Builder_val(B), I);
}
return Val_unit;
}
diff --git a/llvm/test/Bindings/OCaml/core.ml b/llvm/test/Bindings/OCaml/core.ml
index d2265cf34d133..36f4c468d99f4 100644
--- a/llvm/test/Bindings/OCaml/core.ml
+++ b/llvm/test/Bindings/OCaml/core.ml
@@ -830,7 +830,7 @@ let test_instructions () =
let fty = function_type void_type [| i32_type; i32_type |] in
let f = define_function "f" fty m in
let bb = entry_block f in
- let b = builder_at context (At_end bb) false in
+ let b = builder_at context (At_end bb) in
insist (At_end bb = instr_begin bb);
insist (At_start bb = instr_end bb);
@@ -1150,7 +1150,7 @@ let test_builder () =
(* CHECK: ret{{.*}}P1
*)
let ret = build_ret p1 atentry in
- position_before ret false atentry
+ position_before ret atentry
end;
(* see test/Feature/exception.ll *)
diff --git a/llvm/test/Bindings/OCaml/debuginfo.ml b/llvm/test/Bindings/OCaml/debuginfo.ml
index 4f779743adaa0..f95800dfcb025 100644
--- a/llvm/test/Bindings/OCaml/debuginfo.ml
+++ b/llvm/test/Bindings/OCaml/debuginfo.ml
@@ -273,7 +273,7 @@ let test_variables f dibuilder file_di fun_di =
stdout_metadata auto_var;
(* CHECK: [[LOCAL_VAR_PTR:<0x[0-9a-f]*>]] = !DILocalVariable(name: "my_local", scope: <{{0x[0-9a-f]*}}>, file: <{{0x[0-9a-f]*}}>, line: 10, type: [[INT64TY_PTR]])
*)
- let builder = Llvm.builder_before context entry_term false in
+ let builder = Llvm.builder_before context entry_term in
let all = Llvm.build_alloca (Llvm.i64_type context) "my_alloca" builder in
let scope =
Llvm_debuginfo.dibuild_create_lexical_block dibuilder ~scope:fun_di
>From 82adae1967006e4ea9eb778b84ffbee10a328987 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 20 May 2024 15:23:26 +0100
Subject: [PATCH 06/10] update ocaml bindings
---
llvm/bindings/ocaml/llvm/llvm.ml | 3 +++
llvm/bindings/ocaml/llvm/llvm.mli | 12 ++++++++++++
llvm/bindings/ocaml/llvm/llvm_ocaml.c | 16 +++++++++++++---
llvm/test/Bindings/OCaml/core.ml | 2 +-
4 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 7eeaae49e1059..5046749febcab 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -1135,6 +1135,8 @@ 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_builder2 : (llbasicblock, llvalue) llpos -> bool -> llbuilder ->
+ unit = "llvm_position_builder2"
external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
external insert_into_builder : llvalue -> string -> llbuilder -> unit
= "llvm_insert_into_builder"
@@ -1148,6 +1150,7 @@ 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_builder2 (Before i) true
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 36cc095dc66e3..1e0e414ee0eae 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_builder2 ip bb before_dbg_records] moves the instruction builder
+ [bb] to the position [ip]. [before_dbg_records] determines whether the
+ insertion point is before debug records attached to [ip].
+ See the constructor for [llvm::LLVMBuilder]. *)
+val position_builder2 : (llbasicblock, llvalue) llpos -> bool -> 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 : 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 26a3ac21501d2..1b5bc7e770fd8 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -2004,18 +2004,28 @@ value llvm_builder(value C) {
return alloc_builder(LLVMCreateBuilderInContext(Context_val(C)));
}
-/* (llbasicblock, llvalue) llpos -> llbuilder -> unit */
-value llvm_position_builder(value Pos, value B) {
+static value llvm_position_builder_impl(value Pos, value B,
+ LLVMBool BeforeDbgRecords) {
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));
- LLVMPositionBuilderBefore(Builder_val(B), I);
+ LLVMPositionBuilderBefore2(Builder_val(B), I, BeforeDbgRecords);
}
return Val_unit;
}
+/* (llbasicblock, llvalue) llpos -> bool -> llbuilder -> unit */
+value llvm_position_builder2(value Pos, value BeforeDbgRecords, value B) {
+ return llvm_position_builder_impl(Pos, B, Bool_val(BeforeDbgRecords));
+}
+
+/* (llbasicblock, llvalue) llpos -> llbuilder -> unit */
+value llvm_position_builder(value Pos, value B) {
+ return llvm_position_builder_impl(Pos, B, /*BeforeDbgRecords=*/0);
+}
+
/* llbuilder -> llbasicblock */
value llvm_insertion_block(value B) {
LLVMBasicBlockRef InsertBlock = LLVMGetInsertBlock(Builder_val(B));
diff --git a/llvm/test/Bindings/OCaml/core.ml b/llvm/test/Bindings/OCaml/core.ml
index 36f4c468d99f4..923a3541e239c 100644
--- a/llvm/test/Bindings/OCaml/core.ml
+++ b/llvm/test/Bindings/OCaml/core.ml
@@ -1150,7 +1150,7 @@ let test_builder () =
(* CHECK: ret{{.*}}P1
*)
let ret = build_ret p1 atentry in
- position_before ret atentry
+ position_before_dbg_records ret atentry
end;
(* see test/Feature/exception.ll *)
>From 5abb7aa7ba8b99da3ab93d700b2ed500c33a37f6 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 20 May 2024 15:38:54 +0100
Subject: [PATCH 07/10] typo
---
llvm/docs/ReleaseNotes.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 1c79d9b5bc1cf..694d557231977 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -214,7 +214,7 @@ Changes to the C API
* ``LLVMConstICmp``
* ``LLVMConstFCmp``
-* Added ``LLVMPositionBuilder2`` and ``LLVMPositionBuilderBefore2``. Same as ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore2`` with a new ``BeforeDbgRecords`` parameter which indicates whether or not the insertion position should also be before the debug records that precede the instruction. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info. ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore`` are unchanged. They insert before the indicated instruction but after any attached debug records (equivalent to calling the new variants with ``BeforeDbgRecords`` set to ``false``).
+* Added ``LLVMPositionBuilder2`` and ``LLVMPositionBuilderBefore2``. Same as ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore`` with a new ``BeforeDbgRecords`` parameter which indicates whether or not the insertion position should also be before the debug records that precede the instruction. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info. ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore`` are unchanged. They insert before the indicated instruction but after any attached debug records (equivalent to calling the new variants with ``BeforeDbgRecords`` set to ``false``).
Changes to the CodeGen infrastructure
-------------------------------------
>From 6fd51a152f39853f63c29c4683573566e1e2523a Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Thu, 6 Jun 2024 13:43:23 +0100
Subject: [PATCH 08/10] rework patch
* C: add new versions without bool param
* ocaml: position_before_dbg_records stays the same (equ. to LLVMPositionBuilderBeforeInstrAndDbgRecords)
* ocaml: position_builder2 -> position_builder_before_dbg_records (equ. to LLVMPositionBuilderBeforeDbgRecords)
---
llvm/bindings/ocaml/llvm/llvm.ml | 8 ++++---
llvm/bindings/ocaml/llvm/llvm.mli | 16 +++++++-------
llvm/bindings/ocaml/llvm/llvm_ocaml.c | 20 +++++++++--------
llvm/docs/ReleaseNotes.rst | 2 +-
llvm/docs/RemoveDIsDebugInfo.md | 12 +++++-----
llvm/include/llvm-c/Core.h | 9 ++++----
llvm/lib/IR/Core.cpp | 32 ++++++++++++++++-----------
llvm/tools/llvm-c-test/debuginfo.c | 6 ++---
8 files changed, 58 insertions(+), 47 deletions(-)
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 5046749febcab..7bfaf8656ab3f 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -1135,8 +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_builder2 : (llbasicblock, llvalue) llpos -> bool -> llbuilder ->
- unit = "llvm_position_builder2"
+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"
@@ -1150,7 +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_builder2 (Before i) true
+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 1e0e414ee0eae..89b894b35849d 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1874,21 +1874,21 @@ val builder_at_end : llcontext -> llbasicblock -> llbuilder
See the constructor for [llvm::LLVMBuilder]. *)
val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
-(** [position_builder2 ip bb before_dbg_records] moves the instruction builder
- [bb] to the position [ip]. [before_dbg_records] determines whether the
- insertion point is before debug records attached to [ip].
+(** [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_builder2 : (llbasicblock, llvalue) llpos -> bool -> llbuilder ->
- unit
+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.
+(** [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 : llvalue -> llbuilder -> unit
+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]. *)
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 1b5bc7e770fd8..3976a96a6da9b 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -2004,26 +2004,28 @@ value llvm_builder(value C) {
return alloc_builder(LLVMCreateBuilderInContext(Context_val(C)));
}
-static value llvm_position_builder_impl(value Pos, value B,
- LLVMBool BeforeDbgRecords) {
+/* (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));
- LLVMPositionBuilderBefore2(Builder_val(B), I, BeforeDbgRecords);
+ LLVMPositionBuilderBeforeInstrAndDbgRecords(Builder_val(B), I);
}
return Val_unit;
}
-/* (llbasicblock, llvalue) llpos -> bool -> llbuilder -> unit */
-value llvm_position_builder2(value Pos, value BeforeDbgRecords, value B) {
- return llvm_position_builder_impl(Pos, B, Bool_val(BeforeDbgRecords));
-}
-
/* (llbasicblock, llvalue) llpos -> llbuilder -> unit */
value llvm_position_builder(value Pos, value B) {
- return llvm_position_builder_impl(Pos, B, /*BeforeDbgRecords=*/0);
+ 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));
+ LLVMPositionBuilderBefore(Builder_val(B), I);
+ }
+ return Val_unit;
}
/* llbuilder -> llbasicblock */
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 694d557231977..f86f9430201f8 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -214,7 +214,7 @@ Changes to the C API
* ``LLVMConstICmp``
* ``LLVMConstFCmp``
-* Added ``LLVMPositionBuilder2`` and ``LLVMPositionBuilderBefore2``. Same as ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore`` with a new ``BeforeDbgRecords`` parameter which indicates whether or not the insertion position should also be before the debug records that precede the instruction. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info. ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore`` are unchanged. They insert before the indicated instruction but after any attached debug records (equivalent to calling the new variants with ``BeforeDbgRecords`` set to ``false``).
+* Added ``LLVMPositionBuilderBeforeDbgRecords`` and ``LLVMPositionBuilderBeforeInstrAndDbgRecords``. Same as ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore`` except the insertion position is set to before the debug records that precede the target instruction. See the `debug info migration guide <https://llvm.org/docs/RemoveDIsDebugInfo.html>`_ for more info. ``LLVMPositionBuilder`` and ``LLVMPositionBuilderBefore`` are unchanged; they insert before the indicated instruction but after any attached debug records.
Changes to the CodeGen infrastructure
-------------------------------------
diff --git a/llvm/docs/RemoveDIsDebugInfo.md b/llvm/docs/RemoveDIsDebugInfo.md
index 9893ba69f3711..8138462a32564 100644
--- a/llvm/docs/RemoveDIsDebugInfo.md
+++ b/llvm/docs/RemoveDIsDebugInfo.md
@@ -63,16 +63,16 @@ LLVMDIBuilderInsertDbgValueAtEnd # Same as above.
New functions (no plans to deprecate)
----------------------------------
-LLVMPositionBuilder2 # LLVMPositionBuilder but with BeforeDbgRecords parameter. See info below.
-LLVMPositionBuilderBefore2 # Same as above.
+LLVMPositionBuilderBeforeDbgRecords # See info below.
+LLVMPositionBuilderBeforeInstrAndDbgRecords # See info below.
```
-`LLVMPositionBuilder2` and `LLVMPositionBuilderBefore2` have a parameter `BeforeDbgRecords` which indicates whether or not the insertion position should also be before the debug records that precede the instruction. Note that this doesn't mean that debug intrinsics before the chosen instruction are skipped, only debug records (which unlike debug records are not themselves instructions).
+`LLVMPositionBuilderBeforeDbgRecords` and `LLVMPositionBuilderBeforeInstrAndDbgRecords` behave the same as `LLVMPositionBuilder` and `LLVMPositionBuilderBefore` except the insition position is set before the debug records that precede the target instruction. Note that this doesn't mean that debug intrinsics before the chosen instruction are skipped, only debug records (which unlike debug records are not themselves instructions).
-If you don't know whether it should be true or false then follow this rule:
-If you are trying to insert at the start of a block, or purposfully skip debug intrinsics to determine the insertion point for any other reason, then set it to true. Otherwise set it to false.
+If you don't know which function to call then follow this rule:
+If you are trying to insert at the start of a block, or purposfully skip debug intrinsics to determine the insertion point for any other reason, then call the new functions.
-`LLVMPositionBuilder` and `LLVMPositionBuilderBefore` are unchanged. They insert before the indicated instruction but after any attached debug records (equivalent to calling the new variants with `BeforeDbgRecords` set to `false`).
+`LLVMPositionBuilder` and `LLVMPositionBuilderBefore` are unchanged. They insert before the indicated instruction but after any attached debug records.
# The new "Debug Record" model
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index e2bdfeeb0b9f1..fa676f6007744 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -3962,11 +3962,12 @@ LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
LLVMBuilderRef LLVMCreateBuilder(void);
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
LLVMValueRef Instr);
-void LLVMPositionBuilder2(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
- LLVMValueRef Instr, LLVMBool BeforeDbgRecords);
+void LLVMPositionBuilderBeforeDbgRecords(LLVMBuilderRef Builder,
+ LLVMBasicBlockRef Block,
+ LLVMValueRef Inst);
void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
-void LLVMPositionBuilderBefore2(LLVMBuilderRef Builder, LLVMValueRef Instr,
- LLVMBool BeforeDbgRecords);
+void LLVMPositionBuilderBeforeInstrAndDbgRecords(LLVMBuilderRef Builder,
+ LLVMValueRef Instr);
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 1d61f93124407..3a91a4eb6e0d1 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3137,29 +3137,35 @@ LLVMBuilderRef LLVMCreateBuilder(void) {
return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
}
+static void LLVMPositionBuilderImpl(IRBuilder<> *Builder, BasicBlock *Block,
+ Instruction *Instr, bool BeforeDbgRecords) {
+ BasicBlock::iterator I = Instr ? Instr->getIterator() : Block->end();
+ I.setHeadBit(BeforeDbgRecords);
+ Builder->SetInsertPoint(Block, I);
+}
+
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
LLVMValueRef Instr) {
- return LLVMPositionBuilder2(Builder, Block, Instr, false);
+ return LLVMPositionBuilderImpl(unwrap(Builder), unwrap(Block),
+ unwrap<Instruction>(Instr), false);
}
-void LLVMPositionBuilder2(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
- LLVMValueRef Instr, LLVMBool BeforeDbgRecords) {
- BasicBlock *BB = unwrap(Block);
- auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->end();
- I.setHeadBit(BeforeDbgRecords);
- unwrap(Builder)->SetInsertPoint(BB, I);
+void LLVMPositionBuilderBeforeDbgRecords(LLVMBuilderRef Builder,
+ LLVMBasicBlockRef Block,
+ LLVMValueRef Instr) {
+ return LLVMPositionBuilderImpl(unwrap(Builder), unwrap(Block),
+ unwrap<Instruction>(Instr), true);
}
void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
- return LLVMPositionBuilderBefore2(Builder, Instr, false);
+ Instruction *I = unwrap<Instruction>(Instr);
+ return LLVMPositionBuilderImpl(unwrap(Builder), I->getParent(), I, false);
}
-void LLVMPositionBuilderBefore2(LLVMBuilderRef Builder, LLVMValueRef Instr,
- LLVMBool BeforeDbgRecords) {
+void LLVMPositionBuilderBeforeInstrAndDbgRecords(LLVMBuilderRef Builder,
+ LLVMValueRef Instr) {
Instruction *I = unwrap<Instruction>(Instr);
- BasicBlock::iterator It = I->getIterator();
- It.setHeadBit(BeforeDbgRecords);
- unwrap(Builder)->SetInsertPoint(I->getParent(), It);
+ return LLVMPositionBuilderImpl(unwrap(Builder), I->getParent(), I, true);
}
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
diff --git a/llvm/tools/llvm-c-test/debuginfo.c b/llvm/tools/llvm-c-test/debuginfo.c
index 476168aedd19d..032657203b5f2 100644
--- a/llvm/tools/llvm-c-test/debuginfo.c
+++ b/llvm/tools/llvm-c-test/debuginfo.c
@@ -235,16 +235,16 @@ int llvm_test_dibuilder(bool NewDebugInfoFormat) {
// will come before the `phi` (and be absorbed onto it) which is an invalid
// state.
LLVMValueRef InsertPos = LLVMGetFirstInstruction(FooVarBlock);
- LLVMPositionBuilderBefore2(Builder, InsertPos, true);
+ LLVMPositionBuilderBeforeInstrAndDbgRecords(Builder, InsertPos);
LLVMValueRef Phi1 = LLVMBuildPhi(Builder, I64, "p1");
LLVMAddIncoming(Phi1, &Zero, &FooEntryBlock, 1);
// Do the same again using the other position-setting function.
- LLVMPositionBuilder2(Builder, FooVarBlock, InsertPos, true);
+ LLVMPositionBuilderBeforeDbgRecords(Builder, FooVarBlock, InsertPos);
LLVMValueRef Phi2 = LLVMBuildPhi(Builder, I64, "p2");
LLVMAddIncoming(Phi2, &Zero, &FooEntryBlock, 1);
// Insert a non-phi before the `ret` but not before the debug records to
// test that works as expected.
- LLVMPositionBuilder2(Builder, FooVarBlock, Ret, false);
+ LLVMPositionBuilder(Builder, FooVarBlock, Ret);
LLVMBuildAdd(Builder, Phi1, Phi2, "a");
char *MStr = LLVMPrintModuleToString(M);
>From 18862b39296c6a8ac059aae1f5d6fe4f82b7a7a4 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Thu, 6 Jun 2024 16:53:11 +0100
Subject: [PATCH 09/10] update C API comments
---
llvm/include/llvm-c/Core.h | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index fa676f6007744..cd9d7e0f843d0 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -3946,26 +3946,31 @@ const unsigned *LLVMGetIndices(LLVMValueRef Inst);
* An instruction builder represents a point within a basic block and is
* the exclusive means of building instructions using the C interface.
*
- * Some insertion-position-setting functions have a "BeforeDbgRecords"
- * parameter. Set to true if the insertion point should be in front of debug
- * records, for example when inserting a phi. If you are trying to insert at the
- * start of a block, or purposfully skip debug intrinsics to determine the
- * insertion point for any other reason, then set it to true. Otherwise set it
- * to false. Insertion-position-setting functions without the parameter always
- * set the position after any attached debug records (i.e., as if
- * "BeforeDbgRecords" is false).
- *
* @{
*/
LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
LLVMBuilderRef LLVMCreateBuilder(void);
+/**
+ * Set the builder poisiton before Instr but after any attached debug records,
+ * or if Instr is null set the position to the end of Block.
+ */
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
LLVMValueRef Instr);
+/**
+ * Set the builder poisiton before Instr and any attached debug records,
+ * or if Instr is null set the position to the end of Block.
+ */
void LLVMPositionBuilderBeforeDbgRecords(LLVMBuilderRef Builder,
LLVMBasicBlockRef Block,
LLVMValueRef Inst);
+/**
+ * Set the builder poisiton before Instr but after any attached debug records.
+ */
void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
+/**
+ * Set the builder poisiton before Instr and any attached debug records.
+ */
void LLVMPositionBuilderBeforeInstrAndDbgRecords(LLVMBuilderRef Builder,
LLVMValueRef Instr);
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
>From 902f282a88ad158c215f31bbc416729b99d8f27b Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 10 Jun 2024 09:03:22 +0100
Subject: [PATCH 10/10] fix typo
---
llvm/docs/RemoveDIsDebugInfo.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/docs/RemoveDIsDebugInfo.md b/llvm/docs/RemoveDIsDebugInfo.md
index 8138462a32564..ef11c8ed8b433 100644
--- a/llvm/docs/RemoveDIsDebugInfo.md
+++ b/llvm/docs/RemoveDIsDebugInfo.md
@@ -67,7 +67,7 @@ LLVMPositionBuilderBeforeDbgRecords # See info below.
LLVMPositionBuilderBeforeInstrAndDbgRecords # See info below.
```
-`LLVMPositionBuilderBeforeDbgRecords` and `LLVMPositionBuilderBeforeInstrAndDbgRecords` behave the same as `LLVMPositionBuilder` and `LLVMPositionBuilderBefore` except the insition position is set before the debug records that precede the target instruction. Note that this doesn't mean that debug intrinsics before the chosen instruction are skipped, only debug records (which unlike debug records are not themselves instructions).
+`LLVMPositionBuilderBeforeDbgRecords` and `LLVMPositionBuilderBeforeInstrAndDbgRecords` behave the same as `LLVMPositionBuilder` and `LLVMPositionBuilderBefore` except the insertion position is set before the debug records that precede the target instruction. Note that this doesn't mean that debug intrinsics before the chosen instruction are skipped, only debug records (which unlike debug records are not themselves instructions).
If you don't know which function to call then follow this rule:
If you are trying to insert at the start of a block, or purposfully skip debug intrinsics to determine the insertion point for any other reason, then call the new functions.
More information about the llvm-commits
mailing list