~mcf/cproc

3cc28c8428306a66350ef3722d45ed8c49bc6f15 — Michael Forney 1 year, 4 months ago d875bf7
Implement no-op __builtin_expect
5 files changed, 21 insertions(+), 0 deletions(-)

M cc.h
M expr.c
M scope.c
A test/builtin-expect.c
A test/builtin-expect.qbe
M cc.h => cc.h +1 -0
@@ 236,6 236,7 @@ enum linkage {
enum builtinkind {
	BUILTINALLOCA,
	BUILTINCONSTANTP,
	BUILTINEXPECT,
	BUILTININFF,
	BUILTINNANF,
	BUILTINOFFSETOF,

M expr.c => expr.c +7 -0
@@ 565,6 565,13 @@ builtinfunc(struct scope *s, enum builtinkind kind)
	case BUILTINCONSTANTP:
		e = mkconstexpr(&typeint, eval(condexpr(s), EVALARITH)->kind == EXPRCONST);
		break;
	case BUILTINEXPECT:
		/* just a no-op for now */
		/* TODO: check that the expression and the expected value have type 'long' */
		e = assignexpr(s);
		expect(TCOMMA, "after expression");
		delexpr(assignexpr(s));
		break;
	case BUILTININFF:
		e = mkexpr(EXPRCONST, &typefloat);
		/* TODO: use INFINITY here when we can handle musl's math.h */

M scope.c => scope.c +1 -0
@@ 16,6 16,7 @@ scopeinit(void)
	} builtins[] = {
		{"__builtin_alloca",     {.kind = DECLBUILTIN, .builtin = BUILTINALLOCA}},
		{"__builtin_constant_p", {.kind = DECLBUILTIN, .builtin = BUILTINCONSTANTP}},
		{"__builtin_expect",     {.kind = DECLBUILTIN, .builtin = BUILTINEXPECT}},
		{"__builtin_inff",       {.kind = DECLBUILTIN, .builtin = BUILTININFF}},
		{"__builtin_nanf",       {.kind = DECLBUILTIN, .builtin = BUILTINNANF}},
		{"__builtin_offsetof",   {.kind = DECLBUILTIN, .builtin = BUILTINOFFSETOF}},

A test/builtin-expect.c => test/builtin-expect.c +4 -0
@@ 0,0 1,4 @@
int x;
int main(void) {
	return __builtin_expect(x, 0);
}

A test/builtin-expect.qbe => test/builtin-expect.qbe +8 -0
@@ 0,0 1,8 @@
export
function w $main() {
@start.1
@body.2
	%.1 =w loadsw $x
	ret %.1
}
export data $x = align 4 { z 4 }