2015-07-10 01:21:52 +08:00
|
|
|
/*===- InstrProfilingUtil.c - Support library for PGO instrumentation -----===*\
|
|
|
|
|*
|
|
|
|
|* The LLVM Compiler Infrastructure
|
|
|
|
|*
|
|
|
|
|* This file is distributed under the University of Illinois Open Source
|
|
|
|
|* License. See LICENSE.TXT for details.
|
|
|
|
|*
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#include "InstrProfilingUtil.h"
|
2015-11-23 12:38:17 +08:00
|
|
|
#include "InstrProfiling.h"
|
2015-07-10 01:21:52 +08:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <direct.h>
|
|
|
|
#else
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
2016-03-06 12:52:45 +08:00
|
|
|
#ifdef COMPILER_RT_HAS_UNAME
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
COMPILER_RT_VISIBILITY
|
2015-07-10 01:21:52 +08:00
|
|
|
void __llvm_profile_recursive_mkdir(char *path) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; path[i] != '\0'; ++i) {
|
2016-03-29 05:32:46 +08:00
|
|
|
char save = path[i];
|
|
|
|
if (!(path[i] == '/' || path[i] == '\\'))
|
|
|
|
continue;
|
2015-07-10 01:21:52 +08:00
|
|
|
path[i] = '\0';
|
|
|
|
#ifdef _WIN32
|
|
|
|
_mkdir(path);
|
|
|
|
#else
|
|
|
|
mkdir(path, 0755); /* Some of these will fail, ignore it. */
|
|
|
|
#endif
|
2016-03-29 05:32:46 +08:00
|
|
|
path[i] = save;
|
2015-07-10 01:21:52 +08:00
|
|
|
}
|
|
|
|
}
|
2016-03-06 08:55:20 +08:00
|
|
|
|
|
|
|
#if COMPILER_RT_HAS_ATOMICS != 1
|
|
|
|
COMPILER_RT_VISIBILITY
|
2016-03-06 12:18:13 +08:00
|
|
|
uint32_t lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV) {
|
2016-03-06 08:55:20 +08:00
|
|
|
void *R = *Ptr;
|
|
|
|
if (R == OldV) {
|
|
|
|
*Ptr = NewV;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-06 12:52:45 +08:00
|
|
|
#ifdef COMPILER_RT_HAS_UNAME
|
|
|
|
int lprofGetHostName(char *Name, int Len) {
|
|
|
|
struct utsname N;
|
|
|
|
int R;
|
|
|
|
if (!(R = uname(&N)))
|
|
|
|
strncpy(Name, N.nodename, Len);
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|