From e010b1396bebc7e3ccace4247114f92f544082d6 Mon Sep 17 00:00:00 2001 From: seyko Date: Sat, 16 Apr 2016 12:41:53 +0300 Subject: [PATCH] __builtin_expect no-op Taken from David Mertens tcc branch on github https://github.com/run4flat/tinycc.git --- tccgen.c | 37 +++++++++++++++++++++++++++++++++++++ tcctok.h | 1 + 2 files changed, 38 insertions(+) diff --git a/tccgen.c b/tccgen.c index 4b2893a..8bf7007 100644 --- a/tccgen.c +++ b/tccgen.c @@ -84,6 +84,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_re static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope); static int decl0(int l, int is_for_loop_init); static void expr_eq(void); +static void expr_lor_const(void); static void unary_type(CType *type); static void vla_runtime_type_size(CType *type, int *a); static void vla_sp_restore(void); @@ -3938,6 +3939,22 @@ ST_FUNC void unary(void) vtop->type.t |= VT_UNSIGNED; break; + case TOK_builtin_expect: + { + /* __builtin_expect is a no-op for now */ + int saved_nocode_wanted; + next(); + skip('('); + expr_eq(); + skip(','); + saved_nocode_wanted = nocode_wanted; + nocode_wanted = 1; + expr_lor_const(); + vpop(); + nocode_wanted = saved_nocode_wanted; + skip(')'); + } + break; case TOK_builtin_types_compatible_p: { CType type1, type2; @@ -4466,6 +4483,26 @@ static void expr_or(void) } } +/* XXX: fix this mess */ +static void expr_land_const(void) +{ + expr_or(); + while (tok == TOK_LAND) { + next(); + expr_or(); + gen_op(TOK_LAND); + } +} +static void expr_lor_const(void) +{ + expr_land_const(); + while (tok == TOK_LOR) { + next(); + expr_land_const(); + gen_op(TOK_LOR); + } +} + static void expr_land(void) { expr_or(); diff --git a/tcctok.h b/tcctok.h index b2fbebf..2cb310b 100644 --- a/tcctok.h +++ b/tcctok.h @@ -131,6 +131,7 @@ DEF(TOK_builtin_constant_p, "__builtin_constant_p") DEF(TOK_builtin_frame_address, "__builtin_frame_address") DEF(TOK_builtin_return_address, "__builtin_return_address") + DEF(TOK_builtin_expect, "__builtin_expect") #ifdef TCC_TARGET_X86_64 #ifdef TCC_TARGET_PE DEF(TOK_builtin_va_start, "__builtin_va_start")