Skip to content

2024编译系统实现赛RISC-V赛道一等奖作品(A compiler of SysY (subset of C) )

License

Notifications You must be signed in to change notification settings

yuhuifishash/SysY

Repository files navigation

2024编译系统实现赛(Risc-V赛道决赛性能分第二名)

SysY Compiler

SysY -> RISC-V 64bits GC_Zba_Zbb

Bugs

  1. QueryAlias in AliasAnalysis after LoopParallel may make mistakes, because LoopParallel may generate new pointers, but AliasAnalysis only consider array.

OverView

Introduction to SysY (subset of C, but something different with C)

supports int and float

supports array of any dimensions

supports while, for, if, else, break, continue

A[f()] += B[f()] is same as A[f()] = A[f()] + B[f()]
//this expression below is valid
const int a = 5,b = 13
int Arr[a][b] = {} 
//not support ++ operator
++i is same as +(+i) 
//keyword of for loop is @for
//because SysY2022 does not have keyword "for", and we can define a variable named "for"
@for(int i=1;i<=10;i=i+1){}

you can see more details in lexer/SysY_lexer.l and parser/SysY_parser.y

IO

see lib/sylib.c and lib/sylib.h

Architecture of Compilers

you can see more details in documents/*

Prerequisites

Clang 15.0+

riscv64-unknown-linux-gnu-gcc 12.2+

qemu-riscv64 7.0+

flex 2.6+

bison 3.8+

Build Steps

mkdir obj
mkdir bin
make -j

if you update parser(*.y), use the command below

make parser
make -j

if you update lexer(*.l), use the command below

make lexer
make -j

Tests

To test functional testcases without optimization

## see SysY_test.sh for more details
./SysY_test.sh S 00 rv64gc

To test functional testcases with optimization

## see SysY_test.sh for more details
./SysY_test.sh S 01 rv64gc

To test performance testcases with optimization

## see SysY_performance.sh for more details
./SysY_test_performance.sh S rv64gc

To generate asm of single file(*.sy) with optimization

## first put your inputfile in testcase/example
## then run the command below, outputfile is in test_output/example
## you can see SysY_test_single.sh for more details
./SysY_test_single.sh [filename] S O1  

Mid-End Optimization

Analysis Pass

-ControlFlowGraph

-DomTree

-AliasAnalysis

-MemoryDependencyAnalysis

-LoopBasicInformation

-ScalarEvolution

-LoopCarriedDependencyAnalysis

TransForm Pass

-TailRecursiveElimination

-Mem2reg

-FunctionInline

-SparseConditionalConstantPropagation

-SimplifyCFG

-InstSimplify

-InstCombine

-AggressiveDeadCodeElimination

-Reassociate

-CommonSubexpressionElimination

-DeadStoreElimination

-RedundantBranchElimination

-LoopSimplify

-LCSSA

-LoopInvariantCodeMotion

-LoopFullUnroll

-LoopIdomRecognize

-LoopFusion

-LoopParallel

-LoopStrengthReduce

-LoopUnroll

Back-End Optimization

-MachinePeephole

-MachineCSE

-MachineLICM

-MachineInstructionSchedule

-RegisterCoalesce

-LinearScan

-PrologueEpilogueOpt

-ShortForwardBranchOpt

Reference

https://github.com/llvm/llvm-project/blob/main/llvm/lib

testcase reference

https://github.com/pku-minic/awesome-sysy

https://github.com/sally-compiler/SallyCompiler

tutorials of some problems in OJ https://www.luogu.com.cn/

About

2024编译系统实现赛RISC-V赛道一等奖作品(A compiler of SysY (subset of C) )

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •