Skip to content

Commit 6fd51a1

Browse files
committed
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)
1 parent 5abb7aa commit 6fd51a1

File tree

8 files changed

+58
-47
lines changed

8 files changed

+58
-47
lines changed

llvm/bindings/ocaml/llvm/llvm.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,9 @@ external delete_instruction : llvalue -> unit = "llvm_delete_instruction"
11351135
external builder : llcontext -> llbuilder = "llvm_builder"
11361136
external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
11371137
= "llvm_position_builder"
1138-
external position_builder2 : (llbasicblock, llvalue) llpos -> bool -> llbuilder ->
1139-
unit = "llvm_position_builder2"
1138+
external position_builder_before_dbg_records : (llbasicblock, llvalue) llpos ->
1139+
llbuilder -> unit
1140+
= "llvm_position_builder_before_dbg_records"
11401141
external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block"
11411142
external insert_into_builder : llvalue -> string -> llbuilder -> unit
11421143
= "llvm_insert_into_builder"
@@ -1150,7 +1151,8 @@ let builder_before context i = builder_at context (Before i)
11501151
let builder_at_end context bb = builder_at context (At_end bb)
11511152

11521153
let position_before i = position_builder (Before i)
1153-
let position_before_dbg_records i = position_builder2 (Before i) true
1154+
let position_before_dbg_records i =
1155+
position_builder_before_dbg_records (Before i)
11541156
let position_at_end bb = position_builder (At_end bb)
11551157

11561158

llvm/bindings/ocaml/llvm/llvm.mli

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,21 +1874,21 @@ val builder_at_end : llcontext -> llbasicblock -> llbuilder
18741874
See the constructor for [llvm::LLVMBuilder]. *)
18751875
val position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit
18761876

1877-
(** [position_builder2 ip bb before_dbg_records] moves the instruction builder
1878-
[bb] to the position [ip]. [before_dbg_records] determines whether the
1879-
insertion point is before debug records attached to [ip].
1877+
(** [position_builder_before_dbg_records ip bb before_dbg_records] moves the
1878+
instruction builder [bb] to the position [ip], before any debug records
1879+
there.
18801880
See the constructor for [llvm::LLVMBuilder]. *)
1881-
val position_builder2 : (llbasicblock, llvalue) llpos -> bool -> llbuilder ->
1882-
unit
1881+
val position_builder_before_dbg_records : (llbasicblock, llvalue) llpos ->
1882+
llbuilder -> unit
18831883

18841884
(** [position_before ins b] moves the instruction builder [b] to before the
18851885
instruction [isn]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
18861886
val position_before : llvalue -> llbuilder -> unit
18871887

1888-
(** [position_before_dbg_records ins b] moves the instruction builder [b] to
1889-
before the instruction [isn] and any debug records attached to it.
1888+
(** [position_before_dbg_records ins b] moves the instruction builder [b]
1889+
to before the instruction [isn] and any debug records attached to it.
18901890
See the method [llvm::LLVMBuilder::SetInsertPoint]. *)
1891-
val position_before : llvalue -> llbuilder -> unit
1891+
val position_before_dbg_records : llvalue -> llbuilder -> unit
18921892

18931893
(** [position_at_end bb b] moves the instruction builder [b] to the end of the
18941894
basic block [bb]. See the method [llvm::LLVMBuilder::SetInsertPoint]. *)

llvm/bindings/ocaml/llvm/llvm_ocaml.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,26 +2004,28 @@ value llvm_builder(value C) {
20042004
return alloc_builder(LLVMCreateBuilderInContext(Context_val(C)));
20052005
}
20062006

2007-
static value llvm_position_builder_impl(value Pos, value B,
2008-
LLVMBool BeforeDbgRecords) {
2007+
/* (llbasicblock, llvalue) llpos -> llbuilder -> unit */
2008+
value llvm_position_builder_before_dbg_records(value Pos, value B) {
20092009
if (Tag_val(Pos) == 0) {
20102010
LLVMBasicBlockRef BB = BasicBlock_val(Field(Pos, 0));
20112011
LLVMPositionBuilderAtEnd(Builder_val(B), BB);
20122012
} else {
20132013
LLVMValueRef I = Value_val(Field(Pos, 0));
2014-
LLVMPositionBuilderBefore2(Builder_val(B), I, BeforeDbgRecords);
2014+
LLVMPositionBuilderBeforeInstrAndDbgRecords(Builder_val(B), I);
20152015
}
20162016
return Val_unit;
20172017
}
20182018

2019-
/* (llbasicblock, llvalue) llpos -> bool -> llbuilder -> unit */
2020-
value llvm_position_builder2(value Pos, value BeforeDbgRecords, value B) {
2021-
return llvm_position_builder_impl(Pos, B, Bool_val(BeforeDbgRecords));
2022-
}
2023-
20242019
/* (llbasicblock, llvalue) llpos -> llbuilder -> unit */
20252020
value llvm_position_builder(value Pos, value B) {
2026-
return llvm_position_builder_impl(Pos, B, /*BeforeDbgRecords=*/0);
2021+
if (Tag_val(Pos) == 0) {
2022+
LLVMBasicBlockRef BB = BasicBlock_val(Field(Pos, 0));
2023+
LLVMPositionBuilderAtEnd(Builder_val(B), BB);
2024+
} else {
2025+
LLVMValueRef I = Value_val(Field(Pos, 0));
2026+
LLVMPositionBuilderBefore(Builder_val(B), I);
2027+
}
2028+
return Val_unit;
20272029
}
20282030

20292031
/* llbuilder -> llbasicblock */

llvm/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Changes to the C API
214214
* ``LLVMConstICmp``
215215
* ``LLVMConstFCmp``
216216

217-
* 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``).
217+
* 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.
218218

219219
Changes to the CodeGen infrastructure
220220
-------------------------------------

llvm/docs/RemoveDIsDebugInfo.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ LLVMDIBuilderInsertDbgValueAtEnd # Same as above.
6363
6464
New functions (no plans to deprecate)
6565
----------------------------------
66-
LLVMPositionBuilder2 # LLVMPositionBuilder but with BeforeDbgRecords parameter. See info below.
67-
LLVMPositionBuilderBefore2 # Same as above.
66+
LLVMPositionBuilderBeforeDbgRecords # See info below.
67+
LLVMPositionBuilderBeforeInstrAndDbgRecords # See info below.
6868
```
6969

70-
`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).
70+
`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).
7171

72-
If you don't know whether it should be true or false then follow this rule:
73-
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.
72+
If you don't know which function to call then follow this rule:
73+
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.
7474

75-
`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`).
75+
`LLVMPositionBuilder` and `LLVMPositionBuilderBefore` are unchanged. They insert before the indicated instruction but after any attached debug records.
7676

7777
# The new "Debug Record" model
7878

llvm/include/llvm-c/Core.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3962,11 +3962,12 @@ LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
39623962
LLVMBuilderRef LLVMCreateBuilder(void);
39633963
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
39643964
LLVMValueRef Instr);
3965-
void LLVMPositionBuilder2(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
3966-
LLVMValueRef Instr, LLVMBool BeforeDbgRecords);
3965+
void LLVMPositionBuilderBeforeDbgRecords(LLVMBuilderRef Builder,
3966+
LLVMBasicBlockRef Block,
3967+
LLVMValueRef Inst);
39673968
void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
3968-
void LLVMPositionBuilderBefore2(LLVMBuilderRef Builder, LLVMValueRef Instr,
3969-
LLVMBool BeforeDbgRecords);
3969+
void LLVMPositionBuilderBeforeInstrAndDbgRecords(LLVMBuilderRef Builder,
3970+
LLVMValueRef Instr);
39703971
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
39713972
LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
39723973
void LLVMClearInsertionPosition(LLVMBuilderRef Builder);

llvm/lib/IR/Core.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,29 +3137,35 @@ LLVMBuilderRef LLVMCreateBuilder(void) {
31373137
return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
31383138
}
31393139

3140+
static void LLVMPositionBuilderImpl(IRBuilder<> *Builder, BasicBlock *Block,
3141+
Instruction *Instr, bool BeforeDbgRecords) {
3142+
BasicBlock::iterator I = Instr ? Instr->getIterator() : Block->end();
3143+
I.setHeadBit(BeforeDbgRecords);
3144+
Builder->SetInsertPoint(Block, I);
3145+
}
3146+
31403147
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
31413148
LLVMValueRef Instr) {
3142-
return LLVMPositionBuilder2(Builder, Block, Instr, false);
3149+
return LLVMPositionBuilderImpl(unwrap(Builder), unwrap(Block),
3150+
unwrap<Instruction>(Instr), false);
31433151
}
31443152

3145-
void LLVMPositionBuilder2(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
3146-
LLVMValueRef Instr, LLVMBool BeforeDbgRecords) {
3147-
BasicBlock *BB = unwrap(Block);
3148-
auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->end();
3149-
I.setHeadBit(BeforeDbgRecords);
3150-
unwrap(Builder)->SetInsertPoint(BB, I);
3153+
void LLVMPositionBuilderBeforeDbgRecords(LLVMBuilderRef Builder,
3154+
LLVMBasicBlockRef Block,
3155+
LLVMValueRef Instr) {
3156+
return LLVMPositionBuilderImpl(unwrap(Builder), unwrap(Block),
3157+
unwrap<Instruction>(Instr), true);
31513158
}
31523159

31533160
void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
3154-
return LLVMPositionBuilderBefore2(Builder, Instr, false);
3161+
Instruction *I = unwrap<Instruction>(Instr);
3162+
return LLVMPositionBuilderImpl(unwrap(Builder), I->getParent(), I, false);
31553163
}
31563164

3157-
void LLVMPositionBuilderBefore2(LLVMBuilderRef Builder, LLVMValueRef Instr,
3158-
LLVMBool BeforeDbgRecords) {
3165+
void LLVMPositionBuilderBeforeInstrAndDbgRecords(LLVMBuilderRef Builder,
3166+
LLVMValueRef Instr) {
31593167
Instruction *I = unwrap<Instruction>(Instr);
3160-
BasicBlock::iterator It = I->getIterator();
3161-
It.setHeadBit(BeforeDbgRecords);
3162-
unwrap(Builder)->SetInsertPoint(I->getParent(), It);
3168+
return LLVMPositionBuilderImpl(unwrap(Builder), I->getParent(), I, true);
31633169
}
31643170

31653171
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {

llvm/tools/llvm-c-test/debuginfo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,16 @@ int llvm_test_dibuilder(bool NewDebugInfoFormat) {
235235
// will come before the `phi` (and be absorbed onto it) which is an invalid
236236
// state.
237237
LLVMValueRef InsertPos = LLVMGetFirstInstruction(FooVarBlock);
238-
LLVMPositionBuilderBefore2(Builder, InsertPos, true);
238+
LLVMPositionBuilderBeforeInstrAndDbgRecords(Builder, InsertPos);
239239
LLVMValueRef Phi1 = LLVMBuildPhi(Builder, I64, "p1");
240240
LLVMAddIncoming(Phi1, &Zero, &FooEntryBlock, 1);
241241
// Do the same again using the other position-setting function.
242-
LLVMPositionBuilder2(Builder, FooVarBlock, InsertPos, true);
242+
LLVMPositionBuilderBeforeDbgRecords(Builder, FooVarBlock, InsertPos);
243243
LLVMValueRef Phi2 = LLVMBuildPhi(Builder, I64, "p2");
244244
LLVMAddIncoming(Phi2, &Zero, &FooEntryBlock, 1);
245245
// Insert a non-phi before the `ret` but not before the debug records to
246246
// test that works as expected.
247-
LLVMPositionBuilder2(Builder, FooVarBlock, Ret, false);
247+
LLVMPositionBuilder(Builder, FooVarBlock, Ret);
248248
LLVMBuildAdd(Builder, Phi1, Phi2, "a");
249249

250250
char *MStr = LLVMPrintModuleToString(M);

0 commit comments

Comments
 (0)