|
80 | 80 | #define C_OPT_LEVEL 0x3 |
81 | 81 | #define C_OPT_INLINE (1<<2) |
82 | 82 | #define C_OPT_MEM2SSA (1<<3) |
| 83 | +#define C_OPT_TAILCALL (1<<4) |
83 | 84 |
|
84 | 85 | #define IR_UNKNOWN_SIZE 1 |
85 | 86 |
|
@@ -889,6 +890,9 @@ void rcc_ir_init(rcc_ctx *rcc, uint32_t flags) |
889 | 890 | if ((rcc->c_opt_flags & C_OPT_LEVEL) > 0) { |
890 | 891 | flags |= IR_OPT_FOLDING | IR_OPT_CFG | IR_OPT_CODEGEN; |
891 | 892 | } |
| 893 | + if (rcc->c_opt_flags & C_OPT_TAILCALL) { |
| 894 | + flags |= IR_OPT_TAILCALL; |
| 895 | + } |
892 | 896 | flags |= rcc->ir_flags; |
893 | 897 | ir_init(ctx, flags, 256, 1024); |
894 | 898 | ctx->mflags = rcc->ir_mflags; |
@@ -1827,6 +1831,7 @@ static void rcc_help(const char *cmd) |
1827 | 1831 | "Optimization Options:\n" |
1828 | 1832 | " -O[012] - optimization level (default: -O2)\n" |
1829 | 1833 | " -f[no-]inline - enable/disable function inlining (default: enabled at -O1)\n" |
| 1834 | + " -f[no-]tail-calls - enable/disable tail call optimization (default: enabled at -O1)\n" |
1830 | 1835 | " -fno-mem2ssa - disable MEM2SSA pass (default: enabled at -O1)\n" |
1831 | 1836 | "Code Generation Options:\n" |
1832 | 1837 | #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) |
@@ -1953,8 +1958,7 @@ static int rcc_parse_option(rcc_ctx *rcc, const char *opt, const char *arg, bool |
1953 | 1958 | { |
1954 | 1959 | if (opt[0] == '-' && opt[1] == 'O' && strlen(opt) == 3) { |
1955 | 1960 | if (opt[2] == '0') { |
1956 | | - rcc->c_opt_flags = (rcc->c_opt_flags & ~C_OPT_LEVEL) | 0; |
1957 | | - rcc->c_opt_flags &= ~C_OPT_INLINE; |
| 1961 | + rcc->c_opt_flags = 0; |
1958 | 1962 | } else if (opt[2] == '1') { |
1959 | 1963 | rcc->c_opt_flags = (rcc->c_opt_flags & ~C_OPT_LEVEL) | 1; |
1960 | 1964 | } else if (opt[2] == '2') { |
@@ -1988,6 +1992,10 @@ static int rcc_parse_option(rcc_ctx *rcc, const char *opt, const char *arg, bool |
1988 | 1992 | rcc->c_opt_flags &= ~C_OPT_INLINE; |
1989 | 1993 | } else if (strcmp(opt, "-finline") == 0) { |
1990 | 1994 | rcc->c_opt_flags |= C_OPT_INLINE; |
| 1995 | + } else if (strcmp(opt, "-fno-tail-calls") == 0) { |
| 1996 | + rcc->c_opt_flags &= ~C_OPT_TAILCALL; |
| 1997 | + } else if (strcmp(opt, "-ftail-calls") == 0) { |
| 1998 | + rcc->c_opt_flags |= C_OPT_TAILCALL; |
1991 | 1999 | } else if (strcmp(opt, "-fno-mem2ssa") == 0) { |
1992 | 2000 | rcc->c_opt_flags &= ~C_OPT_MEM2SSA; |
1993 | 2001 | } else if (strcmp(opt, "-P") == 0) { |
@@ -2234,7 +2242,7 @@ int main(int argc, const char **argv) |
2234 | 2242 | } |
2235 | 2243 |
|
2236 | 2244 | memset(rcc, 0, sizeof(rcc_ctx)); |
2237 | | - rcc->c_opt_flags = 2 | C_OPT_INLINE | C_OPT_MEM2SSA; |
| 2245 | + rcc->c_opt_flags = 2 | C_OPT_INLINE | C_OPT_MEM2SSA | C_OPT_TAILCALL; |
2238 | 2246 | rcc->e_errors = E_ERRORS_DEFAULT; |
2239 | 2247 | rcc->e_warnings = E_WARNINGS_DEFAULT; |
2240 | 2248 | rcc->ir_save_flags = IR_SAVE_SAFE_NAMES; |
|
0 commit comments