Modify:
Add a global variable 'CurForbiddenSlotAttr' to save current instruction`s forbidden slot and whether set reorder.
This is the judgment condition for whether to add nop.
We would add a couple of '.set noreorder' and '.set reorder' to wrap the current instruction and the next instruction.
Then we can get previous instruction`s forbidden slot attribute and whether set reorder by 'CurForbiddenSlotAttr'.
If previous instruction has forbidden slot and .set reorder is active and current instruction is CTI. Then emit a NOP
after it.
Fix scenarios:
1.When inline asm ends with branch instruction:
1.1)then compiler
generate another CTI immediately, CTI lie in forbidden slot.
test: Use function foo1 in new file llvm/test/CodeGen/Mips/llvm-ir/forbidden-slot-ir.ll.
1.2)and next IR line was also inline asm, need insert nop between them.
test: Use function foo2 in new file llvm/test/CodeGen/Mips/llvm-ir/forbidden-slot-ir.ll.
2.When inline asm includes CTI following branch instruction, need
insert nop between them.
test: Use function foo3 in new file llvm/test/CodeGen/Mips/llvm-ir/forbidden-slot-ir.ll.
3.Also add test for scenario that have been realized in pass, when
CTI follow branch instruction.
test: Use function foo0 in new file llvm/test/CodeGen/Mips/llvm-ir/forbidden-slot-ir.ll.
4.When .set reorder is set in handwritten assembly file, nop need
insert between branch instruction and CTI.
test: in new file llvm/test/MC/Mips/forbidden-slot.s
Test result:
$ sudo ./build/bin/llvm-lit -v llvm/test/CodeGen/Mips/llvm-ir/forbidden-slot-ir.ll llvm/test/MC/Mips/forbidden-slot.s llvm/test/MC/Mips/mips32r6/relocations.s llvm/test/MC/Mips/mips64r6/relocations.s llvm/test/MC/Mips/relocation.s
[sudo] password for huangyin:
- Testing: 5 tests, 5 workers --
PASS: LLVM :: MC/Mips/mips32r6/relocations.s (1 of 5)
PASS: LLVM :: MC/Mips/mips64r6/relocations.s (2 of 5)
PASS: LLVM :: MC/Mips/forbidden-slot.s (3 of 5)
PASS: LLVM :: CodeGen/Mips/llvm-ir/forbidden-slot-ir.ll (4 of 5)
PASS: LLVM :: MC/Mips/relocation.s (5 of 5)
Testing Time: 0.25s
Total Discovered Tests: 5
Passed: 5 (100.00%)
Don't repeat the variable/function name in new code.