This is an archive of the discontinued LLVM Phabricator instance.

[SPARC] Simplify instruction decoder.
ClosedPublic

Authored by jyknight on Nov 9 2022, 11:25 AM.

Details

Summary

After https://reviews.llvm.org/D137653 named sub-operands can be used
in the auto-generated instruction decoders. This allows the
auto-generated decoders to work properly, so all the hand-coded
decoders in the sparc target can be removed.

In some instances, a manually-written decoder had not been implemented
for an instruction, and thus that instruction was not decoded
properly. These have been fixed (and tests added).

Diff Detail

Event Timeline

jyknight created this revision.Nov 9 2022, 11:25 AM
jyknight requested review of this revision.Nov 9 2022, 11:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2022, 11:25 AM
MaskRay accepted this revision.Nov 19 2022, 11:22 AM
MaskRay added a subscriber: brad.

I think Sparc backend has many untested things and many(?) parts are somewhat broken. Perhaps @brad, @koakuma can do some verification

This revision is now accepted and ready to land.Nov 19 2022, 11:22 AM
brad added a comment.Nov 19 2022, 11:46 PM

I think Sparc backend has many untested things and many(?) parts are somewhat broken. Perhaps @brad, @koakuma can do some verification

It is definitely not of the same level of maturity as the other major CPU archs. It is inching towards being in a usable state.

koakuma requested changes to this revision.Nov 20 2022, 1:25 AM

The patch doesn't apply cleanly as-is on my test system (seems like there are some of the proposed changes that's already in main?).
Once I got the patch to apply, though, it seems to be hitting some assertion failures:

******************** TEST 'LLVM :: MC/Disassembler/Sparc/sparc-mem.txt' FAILED ********************                                    
Script:                                                                                                                                
--                                                                                                                                     
: 'RUN: at line 1';   /home/k/llvm-debug/src/llvm-project/out/bin/llvm-mc --disassemble /home/k/llvm-debug/src/llvm-project/llvm/test/M
C/Disassembler/Sparc/sparc-mem.txt -triple=sparcv9-unknown-linux | /home/k/llvm-debug/src/llvm-project/out/bin/FileCheck /home/k/llvm-debug/src/llvm-project/llvm/test/MC/Disassembler/Sparc/sparc-mem.txt                                                                    --                                                                                                                                     Exit Code: 2                                                                                                                                                                                                                                                                  
Command Output (stderr):                                                                                                               
--                                                                                                                                     
llvm-mc: /home/k/llvm-debug/src/llvm-project/llvm/include/llvm/ADT/SmallVector.h:298: const T& llvm::SmallVectorTemplateCommon<T, <temp
late-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) const [with T = llvm::MCOpe
rand; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::const_reference = const llvm::MCOperand&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' failed
.                                                                                                                                      
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.                            
Stack dump:                                                                                                                            
0.      Program arguments: /home/k/llvm-debug/src/llvm-project/out/bin/llvm-mc --disassemble /home/k/llvm-debug/src/llvm-project/llvm/t
est/MC/Disassembler/Sparc/sparc-mem.txt -triple=sparcv9-unknown-linux                                                                  
#0 0xfff80001013a3afc PrintStackTraceSignalHandler(void*) Signals.cpp:0:0                                                              
FileCheck error: '<stdin>' is empty.                                                                                                   
FileCheck command line:  /home/k/llvm-debug/src/llvm-project/out/bin/FileCheck /home/k/llvm-debug/src/llvm-project/llvm/test/MC/Disasse
mbler/Sparc/sparc-mem.txt                                                                                                              
                                                                                                                                       
--                                                                                                                                     
                                                                                                                                       
******************** TEST 'LLVM :: MC/Disassembler/Sparc/sparc-coproc.txt' FAILED ********************                                 
Script:                                                                                                                                
--                                                                                                                                     
: 'RUN: at line 1';   /home/k/llvm-debug/src/llvm-project/out/bin/llvm-mc --disassemble /home/k/llvm-debug/src/llvm-project/llvm/test/M
C/Disassembler/Sparc/sparc-coproc.txt -triple=sparcv9-unknown-linux | /home/k/llvm-debug/src/llvm-project/out/bin/FileCheck /home/k/llv
m-debug/src/llvm-project/llvm/test/MC/Disassembler/Sparc/sparc-coproc.txt                                                              
--                                                                                                                                     
Exit Code: 2                                                                                                                           
                                                                                                                                       
Command Output (stderr):                                                                                                               
--                                                                                                                                     
llvm-mc: /home/k/llvm-debug/src/llvm-project/llvm/include/llvm/ADT/SmallVector.h:298: const T& llvm::SmallVectorTemplateCommon<T, <temp
late-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) const [with T = llvm::MCOpe
rand; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::const_reference = const llvm::MCO
perand&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' failed
.                                                                                                                                      
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.                            
Stack dump:                                                                                                                            
0.      Program arguments: /home/k/llvm-debug/src/llvm-project/out/bin/llvm-mc --disassemble /home/k/llvm-debug/src/llvm-project/llvm/t
est/MC/Disassembler/Sparc/sparc-coproc.txt -triple=sparcv9-unknown-linux                                                               
#0 0xfff80001014a3afc PrintStackTraceSignalHandler(void*) Signals.cpp:0:0                                                              
FileCheck error: '<stdin>' is empty.                                                                                                   
FileCheck command line:  /home/k/llvm-debug/src/llvm-project/out/bin/FileCheck /home/k/llvm-debug/src/llvm-project/llvm/test/MC/Disasse
mbler/Sparc/sparc-coproc.txt                                                                                                           
                                                                                                                                       
--
llvm/test/MC/Disassembler/Sparc/sparc-coproc.txt
2

Coprocessor instructions are only available in v8.
v9 reassigned the encoding to other instructions (see §A.23 and §A.53 of the v9 ISA spec, for example), so I think the decoder should differentiate between the two meanings, if possible.

This revision now requires changes to proceed.Nov 20 2022, 1:25 AM

The patch doesn't apply cleanly as-is on my test system (seems like there are some of the proposed changes that's already in main?).

It depends on https://reviews.llvm.org/D137653 which is not yet committed.

llvm/test/MC/Disassembler/Sparc/sparc-coproc.txt
2

I will switch the test to test v8, but changing the instruction definition to be v8-only is out of scope for this patch.

jyknight updated this revision to Diff 476786.Nov 20 2022, 6:48 PM

Update coproc test to use v8 instead of v9.

koakuma accepted this revision.Nov 22 2022, 5:41 AM

Looks okay here too, thanks.

This revision is now accepted and ready to land.Nov 22 2022, 5:41 AM
This revision was landed with ongoing or failed builds.Dec 7 2022, 11:37 AM
This revision was automatically updated to reflect the committed changes.