<div dir="auto">Thanks! That's exactly the explanation I was looking for!</div><div class="gmail_extra"><br><div class="gmail_quote">On Dec 29, 2017 8:34 AM, "Krzysztof Parzyszek via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 12/28/2017 8:02 PM, Sean Silva via llvm-dev wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
One thing I've been curious about is how immediates interact with register classes. Could we use ordinary immediate MachineOperand's (of the appropriate bit width) and just print the immediate MO's of this register class as the corresponding hardwired register? Does MIR have any constraints on using an immediate MO instead of a register?<br>
</blockquote>
<br>
You can construct an instruction that has an immediate operand in place of a register, but that won't work well.  For one, the MachineVerifier will complain about having an invalid operand, plus any code that tries to use operand information for that instruction may end up "surprised" to see an immediate where a register was expected.<br>
<br>
There is an assumption in MIR that physical registers should not be used as explicit operands before RA, except in COPY instructions, so the most "canonical" way of having it in MIR is something like<br>
  %vreg2 = COPY %PHYSICAL_ZERO<br>
  ... = %vreg2<br>
<br>
If using these special registers is the only way to put an immediate in a register of that class, then that suggests that immediates are generally not "legal" for that register class (except for the special cases). It means that after legalization, the selection DAG should not contain immediates of the type associated with that register class except for the values that are explicitly allowed.  You could then simply write a custom selection code for ISD::Constant, and turn it into "CopyFromReg".<br>
<br>
-Krzysztof<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>