<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
David,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
It is done inside eliminateFrameIndex(). I'm trying to move the stack offset to a register by using my custom MOVRI_P pseudo instruction this way:<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
unsigned AR = MF.getRegInfo().createVirtualRegister(XXX::RegClass);</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span></span>BuildMI(MB,II,dl, TII.get(XXX::MOVRI_P), AR).addImm(Offset);</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
(When I print AR, I get 2147483648 = 0x80000000)<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Then, in expandPostRAPseudo(), I replace it with the real MOVRI instruction</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>MachineOperand op_0 = MI.getOperand(0);<br>
</span>
<div>MachineOperand op_1 = MI.getOperand(1);<br>
</div>
<div>BuildMI(MB,MBI,dl, get(XXX::MOVRI)).add(op_0).add(op_1);<br>
</div>
<span></span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
At this point op_1_0.getReg() is 2147483648 and op_1_1.getImm() is correct<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
When I execute the program it says: <span>Assertion `RegNo && RegNo < 37 && "Invalid register number!"' failed.<br>
</span><span></span><br>
<div>Thanks<br>
</div>
<span></span><br>
</div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> David Greene <dag@cray.com><br>
<b>Sent:</b> Monday, February 18, 2019 5:22 PM<br>
<b>To:</b> Josh Sharp<br>
<b>Cc:</b> via llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] New to LLVM. Need help getting available register</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">It would help if you can describe in more detail what you are trying to do.<br>
In which phase of the compiler is this being done?  What is your ultimate<br>
goal?<br>
<br>
I would not look to unit tests as good examples of how to do things.  They<br>
are specifically designed to pinpoint small bits of functionality and often<br>
rare corner cases.  It's possible the bit of code you're looking at is actually<br>
testing that the assertion triggers.<br>
<br>
                                     -David<br>
<br>
________________________________________<br>
From: Josh Sharp <mm92126@hotmail.com><br>
Sent: Saturday, February 16, 2019 8:38:53 PM<br>
To: David Greene<br>
Cc: via llvm-dev<br>
Subject: Re: [llvm-dev] New to LLVM. Need help getting available register<br>
<br>
Is it possible to get a virtual register and then use that to create a real register? I've seen it done in unittests/CodeGen/MachineInstrTest.cpp like this:<br>
<br>
unsigned VirtualDef1 = -42;<br>
  VD1VU->addOperand(*MF,<br>
                    MachineOperand::CreateReg(VirtualDef1, /*isDef*/ true));<br>
<br>
<br>
But when I do that in my code I get an assertion so I wasn't sure if it's legal or not.<br>
Thanks.<br>
<br>
________________________________<br>
From: David Greene <dag@cray.com><br>
Sent: Wednesday, January 2, 2019 9:23 AM<br>
To: m m<br>
Cc: via llvm-dev<br>
Subject: Re: [llvm-dev] New to LLVM. Need help getting available register<br>
<br>
m m via llvm-dev <llvm-dev@lists.llvm.org> writes:<br>
<br>
> I'm new to LLVM. I'd like to know if there is a method I can call<br>
> whenever I need any available CPU register.<br>
<br>
Take a look at RegisterScavenging.  Of course, this only works after<br>
register allocation.  Before register allocation you'd just create a new<br>
virtual register.<br>
<br>
                              -David<br>
</div>
</span></font></div>
</body>
</html>