2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * @author Matthias Braun, Sebastian Hack
24 * @brief Macros to instruct the compiler compiling libFirm.
27 #ifndef FIRM_COMPILER_H
28 #define FIRM_COMPILER_H
32 * Indicates to the compiler that the value of x is very likely 1
33 * @note Only use this in speed critical code and when you are sure x is often 1
35 #define LIKELY(x) __builtin_expect((x), 1)
38 * Indicates to the compiler that it's very likely that x is 0
39 * @note Only use this in speed critical code and when you are sure x is often 0
41 #define UNLIKELY(x) __builtin_expect((x), 0)
44 * Tell the compiler, that a function is pure, i.e. it only
45 * uses its parameters and never modifies the "state".
46 * Add this macro after the return type.
48 #define PURE __attribute__((const))
51 * Tell the compiler, that a function is unused, no warning needed.
53 #define UNUSED __attribute__((unused))
63 * Asserts that the constant expression x is not zero at compiletime. name has
64 * to be a unique identifier.
66 * @note This uses the fact, that double case labels are not allowed.
68 #define COMPILETIME_ASSERT(x, name) \
69 static UNUSED void compiletime_assert_##name (int h) { \
70 switch(h) { case 0: case (x): {} } \