@@ -148,9 +148,11 @@ name: ; the returned block, with the rest of the orig
148148
149149Returns the new block. The PHI nodes in the successors of the original block are updated
150150to refer to the new block. The block must have a terminator, and the split point must not be
151- at the end of the block, before a PHI node or before an exception-handling pad. Debug
152- records at the split point move along when the insertion point is at their head (e.g.,
153- `LLVM.after(prev)`), and stay in the original block otherwise (e.g., `LLVM.before(inst)`).
151+ at the end of the block or before an exception-handling pad. It can be before a PHI node, as
152+ in LLVM, but the PHI nodes that move to the new block are not updated: their only
153+ predecessor is the original block now, so the caller has to fix them. Debug records at the
154+ split point move along when the insertion point is at their head (e.g., `LLVM.after(prev)`),
155+ and stay in the original block otherwise (e.g., `LLVM.before(inst)`).
154156
155157Analyses, like the dominator tree, are not updated.
156158
@@ -162,9 +164,9 @@ function split_block!(pos::InsertionPoint{Instruction}, name::AbstractString="")
162164 throw (ArgumentError (" Cannot split a basic block without a terminator" ))
163165 pos. anchor == C_NULL &&
164166 throw (ArgumentError (" Cannot split a basic block at its end" ))
165- Instruction (pos. anchor) isa Union{PHIInst, LandingPadInst,CatchPadInst,CleanupPadInst,
167+ Instruction (pos. anchor) isa Union{LandingPadInst,CatchPadInst,CleanupPadInst,
166168 CatchSwitchInst} &&
167- throw (ArgumentError (" Cannot split a basic block before a PHI node or an exception-handling pad" ))
169+ throw (ArgumentError (" Cannot split a basic block before an exception-handling pad" ))
168170 BasicBlock (API. LLVMExtraSplitBasicBlock (bb, pos. anchor, pos. head, name))
169171end
170172split_block! (inst:: Instruction , name:: AbstractString = " " ) = split_block! (before (inst), name)
@@ -187,8 +189,10 @@ tail: ; `at` and the rest of the original block
187189```
188190
189191Returns the terminator of the new block, before which instructions can be inserted. The
190- instruction `at` must not be a PHI node or an exception-handling pad. The new branches get
191- the debug location of `at`.
192+ instruction `at` must not be an exception-handling pad. It can be a PHI node, as in LLVM,
193+ but the PHI nodes in the tail are not updated for its new predecessors, so the caller has
194+ to fix them (e.g., by creating a PHI node first, to split before it and add its incoming
195+ values afterwards). The new branches get the debug location of `at`.
192196
193197The `weights` of the conditional branch, a pair of integers for when `cond` is true and
194198when it is false (e.g., `(1, 9)` when the new block is rarely executed), are attached to it
@@ -264,8 +268,8 @@ function check_conditional_split(cond::Value, at::Instruction)
264268 bb === nothing && throw (ArgumentError (" Instruction is not part of a basic block" ))
265269 terminator (bb) === nothing &&
266270 throw (ArgumentError (" Cannot split a basic block without a terminator" ))
267- at isa Union{PHIInst, LandingPadInst,CatchPadInst,CleanupPadInst,CatchSwitchInst} &&
268- throw (ArgumentError (" Cannot split a basic block before a PHI node or an exception-handling pad" ))
271+ at isa Union{LandingPadInst,CatchPadInst,CleanupPadInst,CatchSwitchInst} &&
272+ throw (ArgumentError (" Cannot split a basic block before an exception-handling pad" ))
269273 return
270274end
271275
0 commit comments