<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:Monospace;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In the context of MachineCode custom inserter, I’m trying to enforce the mapping of virtual register to a physical one.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">According to the documentation <a href="https://llvm.org/docs/CodeGenerator.html#mapping-virtual-registers-to-physical-registers">
https://llvm.org/docs/CodeGenerator.html#mapping-virtual-registers-to-physical-registers</a><o:p></o:p></p>
<p class="MsoNormal">There are two ways: the direct one and the indirect ones. The indirect ones refer
<span style="font-size:10.0pt;font-family:Consolas;color:black;background:white">
VirtRegMap class that I’ve never found. So I tried the direct one…<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Mapping virtual registers to physical registers<o:p></o:p></p>
<p class="MsoNormal">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">There are two ways to map virtual registers to physical registers (or to memory<o:p></o:p></p>
<p class="MsoNormal">slots). The first way, that we will call *direct mapping*, is based on the use<o:p></o:p></p>
<p class="MsoNormal">of methods of the classes ``TargetRegisterInfo``, and ``MachineOperand``. The<o:p></o:p></p>
<p class="MsoNormal">second way, that we will call *indirect mapping*, relies on the ``VirtRegMap``<o:p></o:p></p>
<p class="MsoNormal">class in order to insert loads and stores sending and getting values to and from<o:p></o:p></p>
<p class="MsoNormal">memory.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The direct mapping provides more flexibility to the developer of the register<o:p></o:p></p>
<p class="MsoNormal">allocator; however, it is more error prone, and demands more implementation<o:p></o:p></p>
<p class="MsoNormal">work.  Basically, the programmer will have to specify where load and store<o:p></o:p></p>
<p class="MsoNormal">instructions should be inserted in the target function being compiled in order<o:p></o:p></p>
<p class="MsoNormal">to get and store values in memory. To assign a physical register to a virtual<o:p></o:p></p>
<p class="MsoNormal">register present in a given operand, use ``MachineOperand::setReg(p_reg)``. To<o:p></o:p></p>
<p class="MsoNormal">insert a store instruction, use ``TargetInstrInfo::storeRegToStackSlot(...)``,<o:p></o:p></p>
<p class="MsoNormal">and to insert a load instruction, use ``TargetInstrInfo::loadRegFromStackSlot``.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">…<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I tried the direct mapping as following:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Monospace;color:black">            MachineOperand destination = MI->getOperand(0);</span><span style="font-size:10.0pt;font-family:Monospace"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Monospace;color:black">            MachineOperand offset = MI->getOperand(1);</span><span style="font-size:10.0pt;font-family:Monospace"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Monospace">                                    
<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Monospace;color:black">           
</span><b><span style="font-size:10.0pt;font-family:Monospace;color:#7F0055">unsigned</span></b><span style="font-size:10.0pt;font-family:Monospace;color:black"> destinationReg = destination.getReg();</span><span style="font-size:10.0pt;font-family:Monospace"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Monospace;color:black">            int64_t  FrameIndex = offset.getIndex();</span><span style="font-size:10.0pt;font-family:Monospace"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">                destination.setReg(CLP::FA_ROFF0+FrameIndex);<o:p></o:p></p>
<p class="MsoNormal">                destination.setIsDef(true);<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">                TII->loadRegFromStackSlot(*MBB,<o:p></o:p></p>
<p class="MsoNormal">                                                MI, destinationReg, FrameIndex,<o:p></o:p></p>
<p class="MsoNormal">                                                &CLP::FPUaOffsetClassRegClass, TRI);<o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><br>
</span><span style="font-size:10.0pt;font-family:Monospace;color:black">The code after customInserter seems valid but the compilation later hang-up in an infinite loop in procedure computeVirtRegs(); of pass LiveIntervals::runOnMachineFunction.<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Monospace;color:black">In other targets, I’ve seen an example with a setIsDef(true) for such physically mapped register. Is there something missing in my code (register
 other setting,…) ? <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><br>
<br>
<br>
<br>
<br>
<o:p></o:p></span></p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="536" style="width:402.0pt">
<tbody>
<tr>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><img border="0" width="536" height="49" id="_x0000_i1025" src="http://www.spacebel.be/wp-content/uploads/2018/02/image-sign-sbp30y-1.jpg" alt="http://www.spacebel.be/wp-content/uploads/2018/02/image-sign-sbp30y-1.jpg"></span><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><o:p></o:p></span></p>
</td>
</tr>
<tr>
<td style="border:solid silver 1.0pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="center" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:center">
<b><span style="font-size:10.0pt">Dominique Torette</span></b><span style="font-size:10.0pt">
<br>
System Architect<br>
Rue des Chasseurs Ardennais - Liège Science Park - B-4031 Angleur <br>
Tel: +32 (0) 4 </span><span lang="FR-BE" style="font-size:10.0pt">361 81 11 - Fax: +32 (0) 4 361 81 20
<br>
</span><span style="font-size:10.0pt"><a href="http://www.spacebel.be/"><span lang="FR-BE" style="color:blue">www.spacebel.be</span></a></span><span lang="FR-BE" style="font-size:12.0pt;font-family:"Times New Roman","serif""><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span lang="FR-BE"><o:p> </o:p></span></p>
</div>
<br clear="both">
 ------------------------------------------------------------------------------<BR>
<BR>
E-MAIL DISCLAIMER<BR>
<BR>
The present message may contain confidential and/or legally privileged information. If you are not the intended addressee and in case of a transmission error, please notify the sender immediately and destroy this E-mail. Disclosure, reproduction or distribution of this document and its possible attachments is strictly forbidden.<BR>
<BR>
SPACEBEL denies all liability for incomplete, improper, inaccurate, intercepted, (partly) destroyed, lost and/or belated transmission of the current information given that unencrypted electronic transmission cannot currently be guaranteed to be secure or error free.<BR>
Upon request or in conformity with formal, contractual agreements, an originally signed hard copy will be sent to you to confirm the information contained in this E-mail.<BR>
<BR>
SPACEBEL denies all liability where E-mail is used for private use.<BR>
<BR>
SPACEBEL cannot be held responsible for possible viruses that might corrupt this message and/or your computer system.<BR>
 -------------------------------------------------------------------------------<BR>
</body>
</html>