inkwell
inkwell copied to clipboard
Accept AnyValue in PhiValue::replace_all_uses_with
Description
Allow replacing a PhiValue
with any value kind, not just another PhiValue
. This is necessary to be able to use a PhiValue
as placeholder until the value is actually defined when translating from another SSA form ir like Cranelift ir.
Related Issue
Fixes https://github.com/TheDan64/inkwell/issues/272
How This Has Been Tested
Option<Breaking Changes>
I don't think this breaks anything as PhiValue
implements AnyValue
.
Checklist
- [x] I have read the Contributing Guide
Hi @bjorn3 sorry that this is taken so long to get merged. Could you please 1) rebase this PR and 2) explain how this is valid? If the IR expects a phi value, wouldn't replacing it with another type potentially break the code?
sorry that this is taken so long to get merged.
No worries.
If the IR expects a phi value, wouldn't replacing it with another type potentially break the code?
In my case other code doesn't expect a phi value. It expects any kind of value. It is just the case that I need a dummy value as placeholder (https://github.com/bjorn3/wasmtime/blob/0bb1639f68ba46d20919e2a8c4e83f8d20d19917/cranelift/llvm/src/function.rs#L205) until it gets replaced with the actual value (https://github.com/bjorn3/wasmtime/blob/0bb1639f68ba46d20919e2a8c4e83f8d20d19917/cranelift/llvm/src/function.rs#L221) once the defining block gets lowered. Phi instructions are the only instructions I could find that are suitable as placeholder for any type of value. If you have a suggestion for a better alternative, please tell me.
I'm not totally sure what the correct answer is for your situation, but something about it does seem odd 🤔