inkwell icon indicating copy to clipboard operation
inkwell copied to clipboard

Accept AnyValue in PhiValue::replace_all_uses_with

Open bjorn3 opened this issue 3 years ago • 3 comments

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

bjorn3 avatar Sep 27 '21 13:09 bjorn3

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?

TheDan64 avatar Jun 17 '22 02:06 TheDan64

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.

bjorn3 avatar Jun 17 '22 10:06 bjorn3

I'm not totally sure what the correct answer is for your situation, but something about it does seem odd 🤔

TheDan64 avatar Jun 18 '22 22:06 TheDan64