Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transforms: (convert-snrt-to-riscv) Convert to arith where possible #2783

Merged
merged 4 commits into from
Jun 26, 2024

Conversation

AntonLydike
Copy link
Collaborator

Replace some arithmetic RISCV operations with arith dialect operations. This is in preperation for another PR.

This shouldn't change the usability of this pass, but makes it much easier to re-use this pass without targeting our own RISC-V backend.

@AntonLydike AntonLydike added the transformations Changes or adds a transformatio label Jun 26, 2024
@AntonLydike AntonLydike self-assigned this Jun 26, 2024
Copy link

codecov bot commented Jun 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.80%. Comparing base (9d9bbdd) to head (ac209a4).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2783   +/-   ##
=======================================
  Coverage   89.80%   89.80%           
=======================================
  Files         381      381           
  Lines       48226    48227    +1     
  Branches     7377     7378    +1     
=======================================
+ Hits        43308    43311    +3     
+ Misses       3765     3764    -1     
+ Partials     1153     1152    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@superlopuh
Copy link
Member

I don't understand, the pass is to riscv, why would it be to arith instead?

@AntonLydike
Copy link
Collaborator Author

I don't understand, the pass is to riscv, why would it be to arith instead?

Some things can only be represented as RISC-V dialect (eg. csr reads/writes), but others are just arithmetic operations. Instead of hand-lowering the arithmetic as well, I think it makes sense to leave that up to the default lowerings that are already in place (also makes CSE and such easier as arith is 100% pure and has more pattern coverage).

Additionally, this allows us to re-use this lowering when going to e.g. llvm dialect, as we only need to convert some select few RISC-V ops to inline assembly, which is the plan in snax mlir.

@AntonLydike AntonLydike force-pushed the anton/snrt-to-riscv-arith branch from e76c384 to 56288d3 Compare June 26, 2024 14:43
@superlopuh
Copy link
Member

Surely that's a different pass, that converts snrt to arith instead? This doesn't typecheck for me

@jorendumoulin
Copy link
Collaborator

I too, am a bit confused. As I very much welcome this change, this pass does not seem to be the correct place for this?
From the snax perspective, we don't want snrt being lowerd directly to risc-v as this dialect is unfortunately not yet usable for us, so a middle step in arith is necessary, but this seems like it mixes the path from snrt -> arith -> llvm and snrt -> riscv in one pass?

What is wrong with original plan from #2468?:

              snrt                                                   
              │                                                      
              │ lower-snrt                                           
              │                                                      
              │                                                      
              ▼                                                      
              arith + snrt primitives                                
                              │                                      
              │               │                                      
              │               │                                      
   ┌──────────┘               └───────┐                              
   │  convert-snrt-to-riscv           │  convert-snrt-to-llvm        
   │  convert-arith-to-riscv          │  convert-arith-to-llvm (MLIR)
   ▼                                  ▼                              
riscv                          llvm + llvm inline asm                

@AntonLydike
Copy link
Collaborator Author

@jorendumoulin I think this pass fits relatively nicely into the picture of yours, where the snrt primitives are just riscv.csr* and riscv_snrt ops

@AntonLydike
Copy link
Collaborator Author

I have renamed the pass to inline-snrt as it better reflects it's purpose now.

Copy link
Collaborator

@jorendumoulin jorendumoulin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allright, however, using the riscv_snrt dialect as primitives still results in some silly i32->riscv-reg->i32 conversions. It does avoid having almost duplicate ops in two different dialects. I'm not sure whats best.

@AntonLydike
Copy link
Collaborator Author

Allright, however, using the riscv_snrt dialect as primitives still results in some silly i32->riscv-reg->i32 conversions. It does avoid having almost duplicate ops in two different dialects. I'm not sure whats best.

Yes, but these will be cleaned up automagically by xdsl when we reconclile casts, this shouldn't be a problem imo

@AntonLydike AntonLydike merged commit cc8241d into main Jun 26, 2024
10 checks passed
@AntonLydike AntonLydike deleted the anton/snrt-to-riscv-arith branch June 26, 2024 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
transformations Changes or adds a transformatio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants