feat(llvm): Add optional latch→header connection in LoopForm
- Added NYASH_LOOPFORM_LATCH2HEADER environment variable - When enabled, latch block jumps back to header (completing the loop) - When disabled (default), latch remains unreachable (safe mode) - Preserves header predecessor count stability in default mode This allows gradual testing of full LoopForm loop structure.
This commit is contained in:
@ -134,9 +134,17 @@ pub fn lower_while_loopform<'ctx, 'b>(
|
||||
registry.insert(header_bid, (lf.dispatch, tag_phi, payload_phi, lf.latch));
|
||||
body_to_header.insert(body_bb, header_bid);
|
||||
|
||||
// Latch: keep unreachable for now (avoid adding a new predecessor to header)
|
||||
// Latch: optionally jump back to header (gated), otherwise keep unreachable to avoid header pred増
|
||||
codegen.builder.position_at_end(lf.latch);
|
||||
if std::env::var("NYASH_LOOPFORM_LATCH2HEADER").ok().as_deref() == Some("1") {
|
||||
codegen
|
||||
.builder
|
||||
.build_unconditional_branch(header_llbb)
|
||||
.map_err(|e| e.to_string())
|
||||
.unwrap();
|
||||
} else {
|
||||
let _ = codegen.builder.build_unreachable();
|
||||
}
|
||||
// Exit: to original after
|
||||
codegen.builder.position_at_end(lf.exit);
|
||||
codegen
|
||||
|
||||
@ -500,6 +500,9 @@ impl LLVMCompiler {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Note: LoopForm latch→header adds a new LLVM pred not represented in MIR.
|
||||
// Header PHI normalization for this extra pred will be implemented later
|
||||
// using a LoopForm-aware finalize that does not rely on MIR inputs.
|
||||
}
|
||||
}
|
||||
// Finalize function: ensure every basic block is closed with a terminator.
|
||||
|
||||
Reference in New Issue
Block a user