2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
9 * @author Matthias Braun, Sebastian Hack
10 * @brief Macros to instruct the compiler compiling libFirm.
13 #ifndef FIRM_COMPILER_H
14 #define FIRM_COMPILER_H
18 * Indicates to the compiler that the value of x is very likely 1
19 * @note Only use this in speed critical code and when you are sure x is often 1
21 #define LIKELY(x) __builtin_expect((x), 1)
24 * Indicates to the compiler that it's very likely that x is 0
25 * @note Only use this in speed critical code and when you are sure x is often 0
27 #define UNLIKELY(x) __builtin_expect((x), 0)
30 * Tell the compiler, that a function is pure, i.e. it only
31 * uses its parameters and never modifies the "state".
32 * Add this macro after the return type.
34 #define PURE __attribute__((const))
37 * Tell the compiler, that a function is unused, no warning needed.
39 #define UNUSED __attribute__((unused))
49 * Asserts that the constant expression x is not zero at compiletime. name has
50 * to be a unique identifier.
52 * @note This uses the fact, that double case labels are not allowed.
54 #define COMPILETIME_ASSERT(x, name) \
55 static UNUSED void compiletime_assert_##name (int h) { \
56 switch(h) { case 0: case (x): {} } \