[llvm-dev] Live Register Spilling (original) (raw)
jin chuan see via llvm-dev llvm-dev at lists.llvm.org
Sun Sep 17 07:06:48 PDT 2017
- Previous message: [llvm-dev] Live Register Spilling
- Next message: [llvm-dev] Live Register Spilling
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi All,
Thank you all for your advices. (Especially Ruiling, your phi nodes hints solves pretty much all of my problems!) Currently,i am facing issue with the optimization.
One of my redefined basic block is as below:
#BB_2: sub vreg3,vreg3,vreg3,vreg3,1 sll vreg2,vreg2,vreg2,vreg2,1 j #BB_1
The implementation works fine for O0 invocation. But for O1,O2,O3, the instruction is reordered. The j instruction is reordered to execute before sll:
#BB_2: sub vreg3,vreg3,vreg3,vreg3,1 j #BB_1 sll vreg2,vreg2,vreg2,vreg2,1
I am guessing the optimization reordered sll in the jump delay slot, and the instruction in jump delay slot is assumed to be executed everytime? Is there a way to force the j and sll to be in-order as shown in my previous basic block even with the optimization? Or llc accepts parameters to turn off mips jump delay slot?
Chuan.
From: Song, Ruiling <ruiling.song at intel.com> Sent: Friday, September 15, 2017 9:25 AM To: qcolombet at apple.com; jin chuan see Cc: Matthias Braun; llvm-dev at lists.llvm.org Subject: RE: [llvm-dev] Live Register Spilling
From: qcolombet at apple.com [mailto:qcolombet at apple.com] Sent: Friday, September 15, 2017 1:32 AM To: jin chuan see <jinchuansee at hotmail.com> Cc: Song, Ruiling <ruiling.song at intel.com>; Matthias Braun <mbraun at apple.com>; llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] Live Register Spilling
On Sep 13, 2017, at 9:03 PM, jin chuan see via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
Hi All,
Thanks for the reply. I managed to identify and fixed a few errors in my implementation.
However, there are a few errors that i am not sure what is it indicating. For starters, i think i should explain what i am trying to achieve.
I am actually working on MIPS backend to generate smaller set of MIPS Instructions compared to its existing supported instructions. Currently, i am working on shifting instructions.
Take an example: A typical mips sllv syntax goes in this manner:
sllv <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mi>e</mi><mi>g</mi><mn>1</mn><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">reg1,</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8389em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord">1</span><span class="mpunct">,</span></span></span></span>reg2,$reg3The $reg3 contains the shifting amount. Only the LSB 5 bit will be used. The $reg2 contains the data to be shifted. The $reg1 contains the data after shifting is performed.
What i want to achieve is to expand sllv instruction to the following routine:
andi <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mi>e</mi><mi>g</mi><mn>3</mn><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">reg3,</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8389em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord">3</span><span class="mpunct">,</span></span></span></span>reg3,0x1f //To mask the 5 bit LSB shifting amount#BB_1: beq reg3,reg3,reg3,zero,#BB_2 //Branch out from basic block if shifting amount is zero sub reg3,reg3,reg3,reg3,1 //To subtract 1 from the shifting amount sll reg2,reg2,reg2,reg2,1 //Shift by 1 bit j #BB_1 //Branch back to the begining of the routine #BB_2: addu reg1,reg1,reg1,reg2,$zero //Transfer the completed shift data to the original destination register
Since you guys mentioned that the MI are represented in MachineSSA form, i imagined my routine represented by virtual registers would look something like this:
andi <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>v</mi><mi>r</mi><mi>e</mi><mi>g</mi><mn>3</mn><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">vreg3,</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8389em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord">3</span><span class="mpunct">,</span></span></span></span>vreg3,0x1f#BB_1: beq vreg3,vreg3,vreg3,zero,#BB_2 sub vreg3,vreg3,vreg3,vreg3,1 sll vreg2,vreg2,vreg2,vreg2,1 j #BB_1 #BB_2: addu vreg1,vreg1,vreg1,vreg2,$zero
Hi Chuan,
In your example, you should not try to define $vreg3 many times. In SSA form, each value should be defined only once.
You need to create some new virtual registers and make sure each virtual register will be defined only once.
In your example you may need PHI node. Which is an important concept in SSA. You may need to google it to teach yourself on this.
And you should not insert normal arithmetic instructions between two branch/jump instructions. In your example, there are sub/sll between beq/j. which is invalid.
A ‘basic block’ should only terminate(br/jump) at the last one or two instructions.
llc has many useful options besides verify instructions. It also support printing machine IR before/after each pass which is also very useful. Try ‘llc --help’
Ruiling -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170917/1bdfbb5c/attachment.html>
- Previous message: [llvm-dev] Live Register Spilling
- Next message: [llvm-dev] Live Register Spilling
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]