[llvm] [InlineAsm] Steal a bit to denote a register is spillable (PR #70738)

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 1 09:41:25 PDT 2023


================
@@ -1792,6 +1792,12 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST,
       if (F.isUseOperandTiedToDef(TiedTo))
         OS << " tiedto:$" << TiedTo;
 
+      if ((F.isRegDefKind() || F.isRegDefEarlyClobberKind() ||
+           F.isRegUseKind()) &&
+          F.getRegMayBeFolded()) {
+        OS << " foldable";
----------------
nickdesaulniers wrote:

Here's a part of MIR I kind of curious about.  Maybe you can double check my understanding?

(For the entire complete series I have locally) When I use `llc -stop-before` or `-stop-after` to generate the starting point of a new MIR test, `foldable` is printed as a comment, using my change to `TargetInstrInfo::createMIROperandComment` below. Example:
```
INLINEASM &"", 0 /* attdialect */, 1076101130 /* regdef:GR32 spillable */, def %0
```

But if I use `llc -print-after-all` (or `-print-after=finalize-isel`), it's printed via this method.
```
INLINEASM &"" [attdialect], $0:[regdef:GR32 spillable], %0:gr32
```

(Note that the MachineOperand is a 32b immediate encoding an INLINEASM::Flag, hence the value `1076101130` which we pretty print as `$0:[regdef:GR32 spillable]` to be somewhat more understandable).

So for the purposes of testing _parsing_ MIR, I _think_ the answer to the question of "does this need a parser test" is "_no_" because `foldable` is only ever printed inside a comment, which is what we'd need to be able to parse for MIR tests.  IIUC, it seems the parser consumes the result of `TargetInstrInfo::createMIROperandComment` and not `MachineInstr::print` as far as this is concerned (and that result is a comment).

For the purposes of testing _printing_ MIR, nothing will be setting this bit until the instruction selection frameworks later in the series.  For those, I will add MIR tests that they use the above `MachineInstr::print` method to print, but IIUC it seems that you need to use `-print-after` with a pass that sets this bit in order to observe the result of the above method.

So can the printing test wait until then? Or is there some other way to provide code coverage of `MachineInstr::print` before then that I'm not thinking of?  I could write a unittest if this is really necessary, but there doesn't seem to be much unittests for MIR.

https://github.com/llvm/llvm-project/pull/70738


More information about the llvm-commits mailing list