Hi All,
I faced some problems while using the BuildMI().
Currently, i am trying to replace specific MI with a series of new MI.
I wrote a routine under the processFunctionAfterISel() to detect the targeted MI and replace it accordingly.
After using BuildMI() to perform my replacement, i realize there are unnecessary spilling and reloading of registers in the assembly generated.
By checking the llc debug output, i am suspecting that the virtual register states have been completely messed up.
This is because the spilling and reloading codes are only inserted at the register allocation phase, especially during the state of "Spilling live registers at the end of block".
These spilling and reloading codes are messing up the assembly generated, and the behavior of the code generated is undetermined.
I would like to know is there anything i can do to fix the virtual register use-def relationship?
Or is there any standard procedure i should follow to handle the MachineOperands while using BuildMI()?
Any opinions or suggestion are welcomed.
Regards,
JC
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Hi Matthias,
Sorry for the late reply.
Yes, you are correct, I do have optnone attribute on my function.
I did pass -O0 to the tools.
For your information, my invocations are as below:
clang --target=mips-unknown-linux -mips32 test.c -emit-llvm -S
llc -O0 -march=mips -mcpu=mips32 test.ll -o test.s
Based on the generated .ll file, there is optnone attribute on the function, i am guessing this is due to the default optimization -O0 by clang if not specified.
As for the llc, i tried to invoke it with -O1,-O2,-O3. All of them resulted in failure during the phase "PROCESS IMPLICIT DEFS"
This message showed up:
I am assuming that i messed up the virtual register allocation when i am using BuildMI().
Also, i cannot invoke the clang as -O1 and so on as it will optimize my code and the generated .ll file will contain nothing other than the prologue and epilogue code.
Is there any information i can provide you so that we can discuss the issue further?
Chuan.
On Sep 10, 2017, at 7:01 PM, jin chuan see <jinch...@hotmail.com> wrote:Sorry about the previous messageThis message showed up:llc: /home/jc/Desktop/Project/For_Testing/llvm/lib/CodeGen/MachineRegisterInfo.cpp:366: llvm::MachineInstr* llvm::MachineRegisterInfo::getVRegDef(unsigned int) const: Assertion `(I.atEnd() || std::next(I) == def_instr_end()) && "getVRegDef assumes a single definition or no definition"' failed.
Running llc with ‘-verify-machineinstrs’ may tell you which instruction break the SSA form.
Ruiling
On Sep 13, 2017, at 9:03 PM, jin chuan see via llvm-dev <llvm...@lists.llvm.org> wrote:
Hi All,
2.*** Bad machine code: Explicit definition marked as use ***
- function: main
- basic block: BB#1 entry (0x546e600)
- instruction: SLL
- operand 0: %vreg2
3.*** Bad machine code: Non-terminator instruction after the first terminator ***
- function: main
- basic block: BB#1 entry (0x4911600)
- instruction: SUB
First terminator was: BEQ %vreg3, %ZERO, <BB#2>, %AT<imp-def>; GPR32:%vreg3
4.*** Bad machine code: Non-terminator instruction after the first terminator ***
- function: main
- basic block: BB#1 entry (0x4632600)
- instruction: SLL
First terminator was: BEQ %vreg3, %ZERO, <BB#2>, %AT<imp-def>; GPR32:%vreg3
From: qcol...@apple.com [mailto:qcol...@apple.com]
Sent: Friday, September 15, 2017 1:32 AM
To: jin chuan see <jinch...@hotmail.com>
Cc: Song, Ruiling <ruilin...@intel.com>; Matthias Braun <mbr...@apple.com>; llvm...@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...@lists.llvm.org> wrote:
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
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,1
sll $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,1
j #BB_1
sll $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.
I found few ways that could solve my problem:
1.I found the -disable-mips-delay-filler from the llc hidden options. This option will not reorder my instructions below the branch delay slots but fills it with nop's
2.If i were to partition the jump instruction into another basic block as below, it will not reorder my instruction into the delay slot too.
#BB_2: sub $vreg3,$vreg3,1
sll $vreg2,$vreg2,1
#BB_3: j #BB_1
The 1st method seems to be viable, but it will generate nop's which increases the code size. Plus, i have to invoke it manually with llc everytime, else it won't work.
The 2nd method seems to be more automated compared to 1st method, but its more like a quick hack, rather than a formal way to solve the reordering issue.
Is there any other way to disable the reordering? Maybe through the coding instead of the invocation options of llc?
Chuan.