Be a bit more efficient when processing the active and inactive
[oota-llvm.git] / include / Config / pagesize.h
1 /* 
2  *                     The LLVM Compiler Infrastructure
3  *
4  * This file was developed by the LLVM research group and is distributed under
5  * the University of Illinois Open Source License. See LICENSE.TXT for details.
6  * 
7  ******************************************************************************
8  *
9  * This header file provides a platform-independent way of quering page size.
10  */
11
12 #ifndef PAGESIZE_H
13 #define PAGESIZE_H
14
15 #include "Config/unistd.h"
16 #include <sys/param.h>
17
18 namespace llvm {
19
20 /* Compatibility chart:
21  *
22  * Linux/x86:        _SC_PAGESIZE, _SC_PAGE_SIZE
23  * MacOS X/PowerPC:  v. 10.2: NBPG, 
24  *                   v. 10.3: _SC_PAGESIZE
25  * Solaris/Sparc:    _SC_PAGESIZE, _SC_PAGE_SIZE
26  */
27
28 /**
29  * GetPageSize - wrapper to return page size in bytes for various 
30  *  architecture/OS combinations
31  */ 
32 unsigned GetPageSize() {
33 #ifdef _SC_PAGESIZE
34   return sysconf(_SC_PAGESIZE);
35 #elif defined(_SC_PAGE_SIZE)
36   return sysconf(_SC_PAGE_SIZE);
37 #elif defined(NBPG)
38 #ifndef CLSIZE
39 #define CLSIZE 1
40 #endif
41   return NBPG * CLSIZE;
42 #else
43   return 4096; /* allocate 4KB as a fall-back */
44 #endif
45 }
46
47 }
48
49 #endif