Stream: t-compiler

Topic: Inline assembly in MIR


Amanieu (Feb 16 2020 at 09:56, on Zulip):

Could I get some opinions from a MIR expert for #69171? Specifically this question:

I'm not sure how best to represent inline assembly in MIR. I can think of several options:
- Represent it as a Statement, like the previous implementation. This effectively acts as a parallel Assign since it reads/writes to multiple places at once for outputs.
- Represent it as an RValue which takes its inputs as arguments and returns a tuple of outputs. The outputs are then moved to their destinations with Assign. This is closer to the LLVM representation, but it may be difficult to model the borrow checking behavior (we want to avoid multiple outputs to the same place).
- Represent it as a Terminator like a Call. This works well because the new asm! has a noreturn flag which indicates that it never returns.t-compiler/help

Matthew Jasper (Feb 16 2020 at 10:55, on Zulip):

Amanieu said:

  • Represent it as a Terminator like a Call. This works well because the new asm! has a noreturn flag which indicates that it never returns.t-compiler/help

I don't really know why asm isn't already a Terminator. If we're going to have two separate types for everything, then it may as well be done correctly.

Amanieu (Feb 16 2020 at 15:31, on Zulip):

@Matthew Jasper Indeed, I'm trying to do things correctly this time! Can you give me your opinion on these two ways of representing InlineAsm in MIR?

Amanieu (Feb 16 2020 at 15:31, on Zulip):
// Input
asm!("", in(reg) a, out(reg) b, inout(reg) c);

// Option 1
InlineAsm { operands: [in(a : rvalue), out(b : place), inout(c : place)] }

// Option 2
_0 = InlineAsm { inputs: [a: rvalue, c: rvalue] }
b = _0.0;
c = _0.1;
Amanieu (Feb 16 2020 at 15:33, on Zulip):

Both are functionally equivalent, since asm! only supports Copy arguments. My main concern is how it will integrate with the borrow checker, since we want to ban things like asm!("", out(reg) a, out(reg) a), or even asm!("", out(reg) *a, out(reg) a).

Matthew Jasper (Feb 16 2020 at 17:04, on Zulip):

I would probably try Option 1 first.

Last update: Jun 04 2020 at 18:40UTC