Skip to content

Commit 030cdcb

Browse files
committed
fixes for LLVM on Windows
1 parent bba7589 commit 030cdcb

File tree

4 files changed

+157
-44
lines changed

4 files changed

+157
-44
lines changed

CMakeLists.txt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,37 @@ if (ENABLE_LLVM_BACKEND)
105105
message(STATUS "LLVM_DEFINITIONS =" ${LLVM_DEFINITIONS})
106106
add_definitions(${LLVM_DEFINITIONS})
107107

108-
execute_process(
109-
COMMAND ${LLVM_CONFIG_EXECUTABLE} --includedir
110-
OUTPUT_VARIABLE LLVM_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
108+
if (NOT LLVM_CONFIG_EXECUTABLE STREQUAL "LLVM_CONFIG_EXECUTABLE-NOTFOUND")
109+
execute_process(
110+
COMMAND ${LLVM_CONFIG_EXECUTABLE} --includedir
111+
OUTPUT_VARIABLE LLVM_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
112+
else ()
113+
set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
114+
endif ()
111115
message(STATUS "LLVM_INCLUDE_DIR =" ${LLVM_INCLUDE_DIR})
112116
include_directories(${LLVM_INCLUDE_DIR})
113117

114-
execute_process(
115-
COMMAND ${LLVM_CONFIG_EXECUTABLE} --libdir
116-
OUTPUT_VARIABLE LLVM_LIBRARY_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
118+
if (NOT LLVM_CONFIG_EXECUTABLE STREQUAL "LLVM_CONFIG_EXECUTABLE-NOTFOUND")
119+
execute_process(
120+
COMMAND ${LLVM_CONFIG_EXECUTABLE} --libdir
121+
OUTPUT_VARIABLE LLVM_LIBRARY_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
122+
else ()
123+
set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_DIRS})
124+
endif ()
117125
message(STATUS "LLVM_LIBRARY_DIR =" ${LLVM_LIBRARY_DIR})
118126
link_directories(${LLVM_LIBRARY_DIR})
119127

120128
#todo infinite loop in this?
121129
#llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native)
122130

123131
# construct library name
124-
execute_process(
125-
COMMAND ${LLVM_CONFIG_EXECUTABLE} --version
126-
OUTPUT_VARIABLE LLVM_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
132+
if (NOT LLVM_CONFIG_EXECUTABLE STREQUAL "LLVM_CONFIG_EXECUTABLE-NOTFOUND")
133+
execute_process(
134+
COMMAND ${LLVM_CONFIG_EXECUTABLE} --version
135+
OUTPUT_VARIABLE LLVM_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
136+
else ()
137+
set(LLVM_VERSION ${LLVM_PACKAGE_VERSION})
138+
endif ()
127139
message(STATUS "LLVM_VERSION = ${LLVM_VERSION}")
128140

129141
set(LLVM_LIB LLVM)

src/SeExpr/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,9 @@ configure_file(seexpr2.pc.in seexpr2.pc @ONLY)
102102
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/seexpr2.pc DESTINATION share/pkgconfig)
103103

104104
if (ENABLE_LLVM_BACKEND)
105-
target_link_libraries(SeExpr2 ${LLVM_LIB} "dl" "pthread")
105+
if (NOT WIN32)
106+
target_link_libraries(SeExpr2 ${LLVM_LIB} "dl" "pthread")
107+
else ()
108+
target_link_libraries(SeExpr2 ${LLVM_LIB})
109+
endif ()
106110
endif()

src/SeExpr/Platform.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Copyright Disney Enterprises, Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License
6+
and the following modification to it: Section 6 Trademarks.
7+
deleted and replaced with:
8+
9+
6. Trademarks. This License does not grant permission to use the
10+
trade names, trademarks, service marks, or product names of the
11+
Licensor and its affiliates, except as required for reproducing
12+
the content of the NOTICE file.
13+
14+
You may obtain a copy of the License at
15+
http://www.apache.org/licenses/LICENSE-2.0
16+
*/
17+
18+
/** @file Platform.cpp
19+
@brief Platform-specific classes, functions, and includes' implementations.
20+
*/
21+
22+
#include "Platform.h"
23+
24+
#if defined(WINDOWS)
25+
26+
#define _CRT_NONSTDC_NO_DEPRECATE 1
27+
#define _CRT_SECURE_NO_DEPRECATE 1
28+
#define NOMINMAX 1
29+
30+
// windows - defined for both Win32 and Win64
31+
#define WIN32_LEAN_AND_MEAN
32+
#define VC_EXTRALEAN
33+
#include <Windows.h>
34+
35+
namespace SeExpr2 {
36+
37+
__int64 Timer::time() {
38+
LARGE_INTEGER perfCounter;
39+
QueryPerformanceCounter(&perfCounter);
40+
return perfCounter.QuadPart;
41+
}
42+
43+
Timer::Timer() : started(false) {
44+
// get the timer frequency
45+
LARGE_INTEGER frequency;
46+
QueryPerformanceFrequency(&frequency);
47+
ticksPerSeconds = frequency.QuadPart;
48+
}
49+
50+
void Timer::start() {
51+
started = true;
52+
startTime = this->time();
53+
}
54+
55+
long Timer::elapsedTime() {
56+
stopTime = this->time();
57+
return static_cast<long>(((stopTime - startTime) * 1000000) / ticksPerSeconds);
58+
}
59+
60+
}
61+
62+
namespace SeExprInternal2 {
63+
64+
/*
65+
* Mutex/SpinLock classes
66+
*/
67+
68+
_Mutex::_Mutex() {
69+
_mutex = CreateMutex(NULL, FALSE, NULL);
70+
}
71+
72+
_Mutex::~_Mutex() {
73+
CloseHandle(_mutex);
74+
}
75+
76+
void _Mutex::lock() {
77+
WaitForSingleObject(_mutex, INFINITE);
78+
}
79+
80+
void _Mutex::unlock() {
81+
ReleaseMutex(_mutex);
82+
}
83+
84+
_SpinLock::_SpinLock() {
85+
_spinlock = new CRITICAL_SECTION;
86+
InitializeCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
87+
}
88+
89+
_SpinLock::~_SpinLock() {
90+
DeleteCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
91+
delete _spinlock;
92+
_spinlock = nullptr;
93+
}
94+
95+
void _SpinLock::lock() {
96+
EnterCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
97+
}
98+
99+
void _SpinLock::unlock() {
100+
LeaveCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(_spinlock));
101+
}
102+
103+
}
104+
105+
#endif // defined(WINDOWS)

src/SeExpr/Platform.h

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@
3434
#endif
3535
#define _CRT_NONSTDC_NO_DEPRECATE 1
3636
#define _CRT_SECURE_NO_DEPRECATE 1
37+
#if !defined(NOMINMAX)
3738
#define NOMINMAX 1
39+
#endif
40+
41+
// note: because there are some conflicts preventing the use of
42+
// windows.h and COFF.h (one of LLVM include files) in the same
43+
// compilation unit (https://groups.google.com/forum/#!topic/llvm-dev/6n5Q0pFdaSA)
44+
// do NOT include windows.h here. The Windows implementation is
45+
// done on the Platform.cpp file, using opaque types.
3846

39-
// windows - defined for both Win32 and Win64
40-
#include <Windows.h>
4147
#include <malloc.h>
4248
#include <io.h>
4349
#include <tchar.h>
@@ -77,8 +83,12 @@ inline double log2(double x) { return log(x) * 1.4426950408889634; }
7783
typedef unsigned int uint32_t;
7884
#define M_E (2.7182818284590452354)
7985
#define M_PI (3.141592653589793238)
86+
#if !defined(UINT32_MAX)
8087
#define UINT32_MAX (0xffffffff)
88+
#endif
89+
#if !defined(UINT32_MAX)
8190
#define UINT32_MIN (0)
91+
#endif
8292
#else
8393
typedef off_t FilePos;
8494
#endif
@@ -125,33 +135,15 @@ class Timer {
125135
};
126136
#else // Windows
127137
class Timer {
138+
__int64 time();
128139
__int64 ticksPerSeconds;
129140
__int64 startTime, stopTime;
130141
bool started;
131142

132-
__int64 time() {
133-
LARGE_INTEGER perfCounter;
134-
QueryPerformanceCounter(&perfCounter);
135-
return perfCounter.QuadPart;
136-
}
137-
138143
public:
139-
Timer() : started(false) {
140-
// get the timer frequency
141-
LARGE_INTEGER frequency;
142-
QueryPerformanceFrequency(&frequency);
143-
ticksPerSeconds = frequency.QuadPart;
144-
}
145-
146-
void start() {
147-
started = true;
148-
startTime = this->time();
149-
}
150-
151-
long elapsedTime() {
152-
stopTime = this->time();
153-
return static_cast<long>(((stopTime - startTime) * 1000000) / ticksPerSeconds);
154-
}
144+
Timer();
145+
void start();
146+
long elapsedTime();
155147
};
156148
#endif
157149

@@ -178,24 +170,24 @@ namespace SeExprInternal2 {
178170

179171
class _Mutex {
180172
public:
181-
_Mutex() { _mutex = CreateMutex(NULL, FALSE, NULL); }
182-
~_Mutex() { CloseHandle(_mutex); }
183-
void lock() { WaitForSingleObject(_mutex, INFINITE); }
184-
void unlock() { ReleaseMutex(_mutex); }
173+
_Mutex();
174+
~_Mutex();
175+
void lock();
176+
void unlock();
185177

186178
private:
187-
HANDLE _mutex;
179+
void* _mutex;
188180
};
189181

190182
class _SpinLock {
191183
public:
192-
_SpinLock() { InitializeCriticalSection(&_spinlock); }
193-
~_SpinLock() { DeleteCriticalSection(&_spinlock); }
194-
void lock() { EnterCriticalSection(&_spinlock); }
195-
void unlock() { LeaveCriticalSection(&_spinlock); }
184+
_SpinLock();
185+
~_SpinLock();
186+
void lock();
187+
void unlock();
196188

197189
private:
198-
CRITICAL_SECTION _spinlock;
190+
void* _spinlock;
199191
};
200192

201193
#else

0 commit comments

Comments
 (0)