Home | History | Annotate | Download | only in profile
      1 
      2 CHECK_CXX_SOURCE_COMPILES("
      3 #ifdef _MSC_VER
      4 #include <Intrin.h> /* Workaround for PR19898. */
      5 #include <windows.h>
      6 #endif
      7 int main() {
      8 #ifdef _MSC_VER
      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)
     24 
     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;
     33 
     34  s_flock.l_type = F_WRLCK;
     35  fcntl(fd, F_SETLKW, &s_flock);
     36  return 0;
     37 }
     38 
     39 " COMPILER_RT_TARGET_HAS_FCNTL_LCK)
     40 
     41 add_custom_target(profile)
     42 set_target_properties(profile PROPERTIES FOLDER "Compiler-RT Misc")
     43 
     44 set(PROFILE_SOURCES
     45   GCDAProfiling.c
     46   InstrProfiling.c
     47   InstrProfilingValue.c
     48   InstrProfilingBuffer.c
     49   InstrProfilingFile.c
     50   InstrProfilingMerge.c
     51   InstrProfilingMergeFile.c
     52   InstrProfilingWriter.c
     53   InstrProfilingPlatformDarwin.c
     54   InstrProfilingPlatformLinux.c
     55   InstrProfilingPlatformOther.c
     56   InstrProfilingRuntime.cc
     57   InstrProfilingUtil.c)
     58 
     59 if(WIN32)
     60     list(APPEND PROFILE_SOURCES WindowsMMap.c)
     61 endif()
     62 
     63 if(UNIX)
     64  set(EXTRA_FLAGS
     65      -fPIC
     66      -Wno-pedantic)
     67 endif()
     68 
     69 if(COMPILER_RT_TARGET_HAS_ATOMICS)
     70  set(EXTRA_FLAGS
     71      ${EXTRA_FLAGS}
     72      -DCOMPILER_RT_HAS_ATOMICS=1)
     73 endif() 
     74 
     75 if(COMPILER_RT_TARGET_HAS_FCNTL_LCK)
     76  set(EXTRA_FLAGS
     77      ${EXTRA_FLAGS}
     78      -DCOMPILER_RT_HAS_FCNTL_LCK=1)
     79 endif()
     80 
     81 # This appears to be a C-only warning banning the use of locals in aggregate
     82 # initializers. All other compilers accept this, though.
     83 # nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable
     84 append_list_if(COMPILER_RT_HAS_WD4221_FLAG /wd4221 EXTRA_FLAGS)
     85 
     86 if(APPLE)
     87   add_compiler_rt_runtime(clang_rt.profile
     88     STATIC
     89     OS ${PROFILE_SUPPORTED_OS}
     90     ARCHS ${PROFILE_SUPPORTED_ARCH}
     91     CFLAGS ${EXTRA_FLAGS}
     92     SOURCES ${PROFILE_SOURCES}
     93     PARENT_TARGET profile)
     94 else()
     95   add_compiler_rt_runtime(clang_rt.profile
     96     STATIC
     97     ARCHS ${PROFILE_SUPPORTED_ARCH}
     98     CFLAGS ${EXTRA_FLAGS}
     99     SOURCES ${PROFILE_SOURCES}
    100     PARENT_TARGET profile)
    101 endif()
    102 
    103 add_dependencies(compiler-rt profile)
    104