Stream: cranelift

Topic: Exact behaviour of block arguments


view this post on Zulip Ivan Chinenov (Mar 29 2024 at 10:48):

Here's a question. Does passing a slice of values as block args make those values valid to use withing said block, or does it emit new Values referencing the same SSA value?

view this post on Zulip bjorn3 (Mar 30 2024 at 10:46):

If you pass a slice of values as block args, you need to call append_block_param an equivalent amount of times on the target block. The arguments you pass will then be used as values of the Value returned by append_block_param. You only need to use block arguments when there are multiple sources of a value though. If you have v42 defined in block5 you can use it in block27 just fine for as long as all execution paths to block27 pass through block5. For example:

function u0:0(i8, i32, i32) -> i32 system_v {

block0(v0: i8, v1: i32, v2: i32):
  br_if v0, block1(v1), block1(v2)

block1(v3: i32):
  ; v3 is v1 if v0 was non-zero (true) and v2 otherwise
  v4 = iadd v3, v2 ; fine to reference v2 here as all execution paths to this block go through the defining block of v2 (block0)
  return v4
}

Last updated: Nov 22 2024 at 16:03 UTC