| |
| |
| |
| #ifndef P2S_OPTIMIZE_H |
| #define P2S_OPTIMIZE_H |
|
|
| #include "ir.h" |
|
|
| |
| typedef enum { |
| OPT_O0 = 0, |
| OPT_O1 = 1, |
| OPT_O2 = 2, |
| OPT_O3 = 3, |
| } OptLevel; |
|
|
| |
| typedef enum { |
| SIMD_NONE = 0, |
| SIMD_SSE = 1, |
| SIMD_AVX = 2, |
| SIMD_AVX2 = 3, |
| SIMD_AVX512 = 4, |
| SIMD_NEON = 5, |
| } SIMDTarget; |
|
|
| |
| typedef struct { |
| OptLevel level; |
| SIMDTarget simd; |
| bool report; |
| int tile_size; |
| int unroll_factor; |
| Arena *arena; |
| } OptContext; |
|
|
| |
| typedef struct { |
| int start_inst; |
| int end_inst; |
| const char *iter_var; |
| int iter_reg; |
| int lo_reg; |
| int hi_reg; |
| int step_reg; |
| ReduceOp reduce_op; |
| int accum_reg; |
| bool is_reduce; |
| bool is_scan; |
| bool can_vectorize; |
| bool has_dependency; |
| int trip_count; |
| TypeKind elem_type; |
| } ParLoopInfo; |
|
|
| VEC_TYPEDEF(ParLoopInfo, ParLoopVec); |
|
|
| |
| typedef struct { |
| const char *pass_name; |
| const char *description; |
| SourceLoc loc; |
| bool applied; |
| } OptReport; |
|
|
| VEC_TYPEDEF(OptReport, OptReportVec); |
|
|
| |
| void optimize_module(IRModule *mod, OptContext *ctx); |
|
|
| |
| |
| ParLoopVec detect_parallel_patterns(IRBlock *bb); |
|
|
| |
| void opt_constant_fold(IRBlock *bb, Arena *arena); |
| void opt_dead_code_eliminate(IRBlock *bb); |
| void opt_strength_reduce(IRBlock *bb, Arena *arena); |
| void opt_cse(IRBlock *bb, Arena *arena); |
|
|
| |
| void opt_loop_tile(IRBlock *bb, ParLoopInfo *loop, int tile_size, Arena *arena); |
| void opt_loop_unroll(IRBlock *bb, ParLoopInfo *loop, int factor, Arena *arena); |
| void opt_loop_interchange(IRBlock *bb, Arena *arena); |
| void opt_loop_fuse(IRBlock *bb, Arena *arena); |
|
|
| |
| void opt_vectorize(IRBlock *bb, ParLoopInfo *loop, SIMDTarget target, Arena *arena); |
| void opt_vectorize_reduce(IRBlock *bb, ParLoopInfo *loop, SIMDTarget target, Arena *arena); |
|
|
| |
| void opt_insert_prefetch(IRBlock *bb, Arena *arena); |
| void opt_align_data(IRBlock *bb, Arena *arena); |
|
|
| |
| int simd_width(SIMDTarget target, TypeKind elem_type); |
| const char *simd_target_str(SIMDTarget t); |
|
|
| #endif |
|
|