beifg: Factorise code to count interference components.
[libfirm] / ir / adt / compiler.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @date   04.06.2007
9  * @author Matthias Braun, Sebastian Hack
10  * @brief  Macros to instruct the compiler compiling libFirm.
11  */
12
13 #ifndef FIRM_COMPILER_H
14 #define FIRM_COMPILER_H
15
16 #ifdef __GNUC__
17 /**
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
20  */
21 #define LIKELY(x)   __builtin_expect((x), 1)
22
23 /**
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
26  */
27 #define UNLIKELY(x) __builtin_expect((x), 0)
28
29 /**
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.
33  */
34 #define PURE        __attribute__((const))
35
36 /**
37  * Tell the compiler, that a function is unused, no warning needed.
38  */
39 #define UNUSED      __attribute__((unused))
40
41 #else
42 #define LIKELY(x)   x
43 #define UNLIKELY(x) x
44 #define PURE
45 #define UNUSED
46 #endif
47
48 /**
49  * Asserts that the constant expression x is not zero at compiletime. name has
50  * to be a unique identifier.
51  *
52  * @note This uses the fact, that double case labels are not allowed.
53  */
54 #define COMPILETIME_ASSERT(x, name) \
55     static UNUSED void compiletime_assert_##name (int h) { \
56         switch(h) { case 0: case (x): {} } \
57     }
58
59 #endif