blob: ed755b08ca55f3fef108b62495aea1428e5d0e00 [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001#ifndef __LINUX_COMPILER_H
2#define __LINUX_COMPILER_H
3
4#ifndef __ASSEMBLY__
5
6#ifdef __CHECKER__
7# define __user __attribute__((noderef, address_space(1)))
8# define __kernel __attribute__((address_space(0)))
9# define __safe __attribute__((safe))
10# define __force __attribute__((force))
11# define __nocast __attribute__((nocast))
12# define __iomem __attribute__((noderef, address_space(2)))
13# define __acquires(x) __attribute__((context(x,0,1)))
14# define __releases(x) __attribute__((context(x,1,0)))
15# define __acquire(x) __context__(x,1)
16# define __release(x) __context__(x,-1)
17# define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
18# define __percpu __attribute__((noderef, address_space(3)))
19#ifdef CONFIG_SPARSE_RCU_POINTER
20# define __rcu __attribute__((noderef, address_space(4)))
21#else
22# define __rcu
23#endif
24extern void __chk_user_ptr(const volatile void __user *);
25extern void __chk_io_ptr(const volatile void __iomem *);
26#else
27# define __user
28# define __kernel
29# define __safe
30# define __force
31# define __nocast
32# define __iomem
33# define __chk_user_ptr(x) (void)0
34# define __chk_io_ptr(x) (void)0
35# define __builtin_warning(x, y...) (1)
36# define __acquires(x)
37# define __releases(x)
38# define __acquire(x) (void)0
39# define __release(x) (void)0
40# define __cond_lock(x,c) (c)
41# define __percpu
42# define __rcu
43#endif
44
45#ifdef __KERNEL__
46
47#ifdef __GNUC__
48#include <linux/compiler-gcc.h>
49#endif
50
51#define notrace __attribute__((no_instrument_function))
52
53#ifdef __INTEL_COMPILER
54# include <linux/compiler-intel.h>
55#endif
56
57
58struct ftrace_branch_data {
59 const char *func;
60 const char *file;
61 unsigned line;
62 union {
63 struct {
64 unsigned long correct;
65 unsigned long incorrect;
66 };
67 struct {
68 unsigned long miss;
69 unsigned long hit;
70 };
71 unsigned long miss_hit[2];
72 };
73};
74
75#if defined(CONFIG_TRACE_BRANCH_PROFILING) \
76 && !defined(DISABLE_BRANCH_PROFILING) && !defined(__CHECKER__)
77void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78
79#define likely_notrace(x) __builtin_expect(!!(x), 1)
80#define unlikely_notrace(x) __builtin_expect(!!(x), 0)
81
82#define __branch_check__(x, expect) ({ \
83 int ______r; \
84 static struct ftrace_branch_data \
85 __attribute__((__aligned__(4))) \
86 __attribute__((section("_ftrace_annotated_branch"))) \
87 ______f = { \
88 .func = __func__, \
89 .file = __FILE__, \
90 .line = __LINE__, \
91 }; \
92 ______r = likely_notrace(x); \
93 ftrace_likely_update(&______f, ______r, expect); \
94 ______r; \
95 })
96
97/*
98 * Using __builtin_constant_p(x) to ignore cases where the return
99 * value is always the same. This idea is taken from a similar patch
100 * written by Daniel Walker.
101 */
102# ifndef likely
103# define likely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 1))
104# endif
105# ifndef unlikely
106# define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
107# endif
108
109#ifdef CONFIG_PROFILE_ALL_BRANCHES
110#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
111#define __trace_if(cond) \
112 if (__builtin_constant_p((cond)) ? !!(cond) : \
113 ({ \
114 int ______r; \
115 static struct ftrace_branch_data \
116 __attribute__((__aligned__(4))) \
117 __attribute__((section("_ftrace_branch"))) \
118 ______f = { \
119 .func = __func__, \
120 .file = __FILE__, \
121 .line = __LINE__, \
122 }; \
123 ______r = !!(cond); \
124 ______f.miss_hit[______r]++; \
125 ______r; \
126 }))
127#endif
128
129#else
130# define likely(x) __builtin_expect(!!(x), 1)
131# define unlikely(x) __builtin_expect(!!(x), 0)
132#endif
133
134#ifndef barrier
135# define barrier() __memory_barrier()
136#endif
137
138#ifndef unreachable
139# define unreachable() do { } while (1)
140#endif
141
142#ifndef RELOC_HIDE
143# define RELOC_HIDE(ptr, off) \
144 ({ unsigned long __ptr; \
145 __ptr = (unsigned long) (ptr); \
146 (typeof(ptr)) (__ptr + (off)); })
147#endif
148
149#endif
150
151#endif
152
153#ifdef __KERNEL__
154#ifndef __deprecated
155# define __deprecated
156#endif
157
158#ifdef MODULE
159#define __deprecated_for_modules __deprecated
160#else
161#define __deprecated_for_modules
162#endif
163
164#ifndef __must_check
165#define __must_check
166#endif
167
168#ifndef CONFIG_ENABLE_MUST_CHECK
169#undef __must_check
170#define __must_check
171#endif
172#ifndef CONFIG_ENABLE_WARN_DEPRECATED
173#undef __deprecated
174#undef __deprecated_for_modules
175#define __deprecated
176#define __deprecated_for_modules
177#endif
178
179#ifndef __used
180# define __used
181#endif
182
183#ifndef __maybe_unused
184# define __maybe_unused
185#endif
186
187#ifndef __always_unused
188# define __always_unused
189#endif
190
191#ifndef noinline
192#define noinline
193#endif
194
195#define noinline_for_stack noinline
196
197#ifndef __always_inline
198#define __always_inline inline
199#endif
200
201#endif
202
203#ifndef __attribute_const__
204# define __attribute_const__
205#endif
206
207
208#ifndef __cold
209#define __cold
210#endif
211
212#ifndef __section
213# define __section(S) __attribute__ ((__section__(#S)))
214#endif
215
216#ifndef __same_type
217# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
218#endif
219
220#ifndef __compiletime_object_size
221# define __compiletime_object_size(obj) -1
222#endif
223#ifndef __compiletime_warning
224# define __compiletime_warning(message)
225#endif
226#ifndef __compiletime_error
227# define __compiletime_error(message)
228#endif
229#ifndef __linktime_error
230# define __linktime_error(message)
231#endif
232#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
233
234#endif