Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / profile / CMakeLists.txt
blob45e516489175158af77cb1e1aad0e7b47629caf3
2 CHECK_CXX_SOURCE_COMPILES("
3 #ifdef _WIN32
4 #include <intrin.h> /* Workaround for PR19898. */
5 #include <windows.h>
6 #endif
7 int main() {
8 #ifdef _WIN32
9         volatile LONG val = 1;
10         MemoryBarrier();
11         InterlockedCompareExchange(&val, 0, 1);
12         InterlockedIncrement(&val);
13         InterlockedDecrement(&val);
14 #else
15         volatile unsigned long val = 1;
16         __sync_synchronize();
17         __sync_val_compare_and_swap(&val, 1, 0);
18         __sync_add_and_fetch(&val, 1);
19         __sync_sub_and_fetch(&val, 1);
20 #endif
21         return 0;
22       }
23 " COMPILER_RT_TARGET_HAS_ATOMICS)
25 CHECK_CXX_SOURCE_COMPILES("
26 #if defined(__linux__)
27 #include <unistd.h>
28 #endif
29 #include <fcntl.h>
30 int fd;
31 int main() {
32  struct flock s_flock;
34  s_flock.l_type = F_WRLCK;
35  fcntl(fd, F_SETLKW, &s_flock);
36  return 0;
39 " COMPILER_RT_TARGET_HAS_FCNTL_LCK)
41 CHECK_CXX_SOURCE_COMPILES("
42 #include <sys/utsname.h>
43 int main() {
44  return 0;
47 " COMPILER_RT_TARGET_HAS_UNAME)
49 add_compiler_rt_component(profile)
51 set(PROFILE_SOURCES
52   GCDAProfiling.c
53   InstrProfiling.c
54   InstrProfilingInternal.c
55   InstrProfilingValue.c
56   InstrProfilingBuffer.c
57   InstrProfilingFile.c
58   InstrProfilingMerge.c
59   InstrProfilingMergeFile.c
60   InstrProfilingNameVar.c
61   InstrProfilingVersionVar.c
62   InstrProfilingWriter.c
63   InstrProfilingPlatformAIX.c
64   InstrProfilingPlatformDarwin.c
65   InstrProfilingPlatformFuchsia.c
66   InstrProfilingPlatformLinux.c
67   InstrProfilingPlatformOther.c
68   InstrProfilingPlatformWindows.c
69   InstrProfilingRuntime.cpp
70   InstrProfilingUtil.c
71   )
73 set(PROFILE_HEADERS
74   InstrProfiling.h
75   InstrProfilingInternal.h
76   InstrProfilingPort.h
77   InstrProfilingUtil.h
78   WindowsMMap.h
79   )
81 if(WIN32)
82   list(APPEND PROFILE_SOURCES
83     WindowsMMap.c
84   )
85 endif()
87 include_directories(..)
88 include_directories(../../include)
90 if(FUCHSIA OR UNIX)
91  set(EXTRA_FLAGS
92      -fPIC
93      -Wno-pedantic)
94 endif()
96 if(COMPILER_RT_TARGET_HAS_ATOMICS)
97  set(EXTRA_FLAGS
98      ${EXTRA_FLAGS}
99      -DCOMPILER_RT_HAS_ATOMICS=1)
100 endif()
102 if(COMPILER_RT_TARGET_HAS_FCNTL_LCK)
103  set(EXTRA_FLAGS
104      ${EXTRA_FLAGS}
105      -DCOMPILER_RT_HAS_FCNTL_LCK=1)
106 endif()
108 if(COMPILER_RT_TARGET_HAS_UNAME)
109  set(EXTRA_FLAGS
110      ${EXTRA_FLAGS}
111      -DCOMPILER_RT_HAS_UNAME=1)
112 endif()
114 # We don't use the C++ Standard Library here, so avoid including it by mistake.
115 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS)
116 # XRay uses C++ standard library headers.
117 string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
119 # This appears to be a C-only warning banning the use of locals in aggregate
120 # initializers. All other compilers accept this, though.
121 # nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable
122 append_list_if(COMPILER_RT_HAS_WD4221_FLAG /wd4221 EXTRA_FLAGS)
124 # Disable 'nonstandard extension used: translation unit is empty'.
125 append_list_if(COMPILER_RT_HAS_WD4206_FLAG /wd4206 EXTRA_FLAGS)
127 if(APPLE)
128   add_compiler_rt_runtime(clang_rt.profile
129     STATIC
130     OS ${PROFILE_SUPPORTED_OS}
131     ARCHS ${PROFILE_SUPPORTED_ARCH}
132     CFLAGS ${EXTRA_FLAGS}
133     SOURCES ${PROFILE_SOURCES}
134     ADDITIONAL_HEADERS ${PROFILE_HEADERS}
135     PARENT_TARGET profile)
136 else()
137   add_compiler_rt_runtime(clang_rt.profile
138     STATIC
139     ARCHS ${PROFILE_SUPPORTED_ARCH}
140     CFLAGS ${EXTRA_FLAGS}
141     SOURCES ${PROFILE_SOURCES}
142     ADDITIONAL_HEADERS ${PROFILE_HEADERS}
143     PARENT_TARGET profile)
144 endif()