-
Notifications
You must be signed in to change notification settings - Fork 38
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
RISC-V basic isel #156
RISC-V basic isel #156
Conversation
Hels15
commented
Feb 8, 2025
- Added basic risc0-v instruction selection.
- Address modes are not complete and are mostly just copied from x86-64 to get a fast complete version.
- Added float calling conv for both systemV and win64
- Immediate bitwise ops for both riscv and x86-64.
- Many minor cleanups
Major CodeGen cleanup; most static globals move into the CodeGen object.
Only "return 0;", no registers, no encoding, but yah gotta start somewhere
Parser bug fref in args Some new test cases.
Add calling convention basics to X86; con+ret RegMasks. GCM computes CFG for all users. Drop unused MultiUse. Pick up reg-pressure aware ListScheduler. Re-layout CodeGen file to get code & data chunks nearer each other. minor Ary extension
InstSel handles folding 2+ ideal ops into 1 machine op
Bool,If,CProj,Region,Phi Handle 2-op expansions Shuffle instSel graph walk back again.
mul-by-small constant opt. Some utilities.
Change inst sel walk again to pre-order, to set an early visit bit to stop cycles. CFGNode copies dom/loop info. Cmp not-immediate form. Ret/Fun lazy updates
* left shift codegen basic * sar codegen basic * merge * some basic ops * addf * divf, subf, mulf * rsp allowed in bitwise input, not output * formatting * left shift codegen basic * sar codegen basic * merge * some basic ops * addf * divf, subf, mulf * rsp allowed in bitwise input, not output * formatting * Remove non-exsting FP+imm ops * Handle first loop Change inst sel walk again to pre-order, to set an early visit bit to stop cycles. CFGNode copies dom/loop info. Cmp not-immediate form. Ret/Fun lazy updates * float ops without imm values * merge * merge * inst select for new struct allocation * left shift codegen basic * sar codegen basic * merge * some basic ops * addf * divf, subf, mulf * rsp allowed in bitwise input, not output * formatting * Remove non-exsting FP+imm ops * left shift codegen basic * sar codegen basic * merge * some basic ops * addf * divf, subf, mulf * rsp allowed in bitwise input, not output * formatting * float ops without imm values * merge * merge * Rebased on ch 19 * Update tests --------- Co-authored-by: Cliff Click <[email protected]>
alpha-sort helper fcns implicit test vs zero/null
asm print works on ideal nodes for all tests
Drop New taking inits; just follow with initializing stores. Simplifies inst selelection which otherwise needs to undo this optimization and emit following init stores. Basic load/store for now, op-to-mem comes later add same becomes Shl by 1. Drop DivF-immiedate
* merge2 * merge3
ld/st get size (but not signed/unsigned) Add unsigned LT for later range checks.
Common addressing mode print LEA can skip a base
A bunch of mem op patterns are missing, hopefully they are just cut-n-paste from the existing patterns.
Minor README updates
narrowing stores can bypass an AndMask Array length loads do not need control Some missing print info
at least for MemAdd
load-after-store zero/sign-extends if the store is truncating
No base+scaled+offset addressing modes in risc5. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a way to ld/st FP regs.
Ld & St need to extend MemOp.
Remove dead Lea.
Everything else is mostly cosmetic
// Using ABI names instead of register names | ||
public static int ZERO = 0, RA = 1, SP = 2, GP = 3, TP = 4, T0 = 5, T1 = 6, T2 = 7; | ||
public static int s0 = 8, s1 = 9, A0 = 10, A1 = 11, A2 = 12, A3 = 13, A4 = 14, A5 = 15; | ||
public static int A6 = 16, A7 = 17, S2 = 18, S3 = 19, S4 = 20, S5 = 21, s6 = 22, S7 = 23; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalization of s0, s1, s7
import com.seaofnodes.simple.type.TypeInteger; | ||
import java.io.ByteArrayOutputStream; | ||
|
||
public class LoadRISC extends MachConcreteNode implements MachNode{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must extend MemOpNode; e.g. GCM uses this to insert anti-deps.
return riscv.RMASK; | ||
} | ||
// Register mask allowed as a result. 0 for no register. | ||
@Override public RegMask outregmap() { return riscv.RMASK; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we load into a float/FMask ?
2 different kinds of loads (one GPR, on FRegs?) or the same load but encoded differently (needs another encoding bit to tell 32 GPRs from 32 FPRs) ?
|
||
|
||
// sw rs2,offset(rs1) | ||
public class StoreRISC extends MachConcreteNode implements MachNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same-same Load; need to extend MemOpNode to pick up e.g. anti-deps.
Need a way to store FPRs.
private Node add(AddNode add) { | ||
Node rhs = add.in(2); | ||
if( rhs instanceof ConstantNode off && off._con instanceof TypeInteger toff ) { | ||
if( toff.value()==0 ) return add; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never see a 0 here, cleaned out by peeps earlier
} | ||
|
||
private Node and(AndNode and) { | ||
if( and.in(2) instanceof ConstantNode con && con._con instanceof TypeInteger ti ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lower priority comment. Since add,and,or,xor,sub,mul,div, etc all look very similar, would like to see them boilerplated the same (or a some kind of helper fcn). Currently e.g. add
has a rhs = add.in(2); if( rhs...
whereas and
just uses if( and.in(2)...
.
import com.seaofnodes.simple.node.*; | ||
import java.io.ByteArrayOutputStream; | ||
|
||
public class LeaRISC extends MachConcreteNode implements MachNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used, delete ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good