View | Details | Raw Unified | Return to bug 218644
Collapse All | Expand All

(-)lang/beignet/Makefile (+8 lines)
Lines 47-53 Link Here
47
	@${REINPLACE_CMD} -e 's|llvm-dis|llvm-dis${LLVMVER}|g; \
47
	@${REINPLACE_CMD} -e 's|llvm-dis|llvm-dis${LLVMVER}|g; \
48
		s|clang |clang${LLVMVER} |g' \
48
		s|clang |clang${LLVMVER} |g' \
49
		${WRKSRC}/backend/kernels/compile.sh
49
		${WRKSRC}/backend/kernels/compile.sh
50
.if ${LLVMVER} >= 40
51
	${CAT} \
52
	  ${PATCHDIR}/extra-patch-remove_old_llvm_support \
53
	  ${PATCHDIR}/extra-patch-refine_llvm_version_check \
54
		${PATCHDIR}/extra-patch-add_llvm40_support | \
55
		${PATCH} -E -p1 -d ${WRKSRC}
56
.endif
50
57
58
51
# XXX bug 213732: compiler_fill_gl_image() [FAILED]
59
# XXX bug 213732: compiler_fill_gl_image() [FAILED]
52
do-test-TEST-on:
60
do-test-TEST-on:
53
	-@(cd ${TEST_WRKSRC}/utests; . ./setenv.sh; \
61
	-@(cd ${TEST_WRKSRC}/utests; . ./setenv.sh; \
(-)lang/beignet/files/extra-patch-add_llvm40_support (+690 lines)
Line 0 Link Here
1
From 919deced0cd796e30410d45fc71bcda37441e80c Mon Sep 17 00:00:00 2001
2
From: Pan Xiuli <xiuli.pan@intel.com>
3
Date: Tue, 11 Apr 2017 15:59:50 +0800
4
Subject: Backend: Add LLVM40 support
5
6
1.Refine APFloat fltSemantics.
7
2.Refine bitcode read/write header.
8
3.Refine clang invocation.
9
4.Refine return llvm::error handler.
10
5.Refine ilist_iterator usage.
11
6.Refine CFG Printer pass manager.
12
7.Refine GEP with pointer type changing.
13
8.Refine libocl 20 support
14
V2: Add missing ocl_sampler.ll and ocl_sampler_20.ll file
15
V3: Fix some build problem for llvm36
16
17
Signed-off-by: Pan Xiuli <xiuli.pan@intel.com>
18
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
19
20
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
21
index 998e340..c1827b1 100644
22
--- a/backend/src/backend/gen_program.cpp
23
+++ b/backend/src/backend/gen_program.cpp
24
@@ -29,7 +29,11 @@
25
 #include "llvm/IR/DataLayout.h"
26
 #include "llvm-c/Linker.h"
27
 #include "llvm/Transforms/Utils/Cloning.h"
28
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
29
+#include "llvm/Bitcode/BitcodeWriter.h"
30
+#else
31
 #include "llvm/Bitcode/ReaderWriter.h"
32
+#endif /* LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 */
33
 #include "llvm/Support/raw_ostream.h"
34
 #include "llvm/ADT/StringRef.h"
35
 #include "llvm/Support/MemoryBuffer.h"
36
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
37
index 6e8227a..724058c 100644
38
--- a/backend/src/backend/program.cpp
39
+++ b/backend/src/backend/program.cpp
40
@@ -62,7 +62,13 @@
41
 #include <clang/Basic/TargetOptions.h>
42
 #include <llvm/ADT/IntrusiveRefCntPtr.h>
43
 #include <llvm/IR/Module.h>
44
+
45
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
46
+#include <llvm/Bitcode/BitcodeWriter.h>
47
+#include <clang/Lex/PreprocessorOptions.h>
48
+#else
49
 #include <llvm/Bitcode/ReaderWriter.h>
50
+#endif
51
 #include <llvm/Support/raw_ostream.h>
52
 #endif
53
 
54
@@ -694,14 +700,15 @@ namespace gbe {
55
     llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(new clang::DiagnosticIDs());
56
     clang::DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
57
 
58
+    llvm::StringRef srcString(source);
59
     // Create the compiler invocation
60
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
61
+    auto CI = std::make_shared<clang::CompilerInvocation>();
62
+    CI->getPreprocessorOpts().addRemappedFile("stringInput.cl",
63
+#else
64
     std::unique_ptr<clang::CompilerInvocation> CI(new clang::CompilerInvocation);
65
-    clang::CompilerInvocation::CreateFromArgs(*CI,
66
-                                              &args[0],
67
-                                              &args[0] + args.size(),
68
-                                              Diags);
69
-    llvm::StringRef srcString(source);
70
     (*CI).getPreprocessorOpts().addRemappedFile("stringInput.cl",
71
+#endif
72
 #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
73
                 llvm::MemoryBuffer::getMemBuffer(srcString)
74
 #else
75
@@ -709,9 +716,17 @@ namespace gbe {
76
 #endif
77
                 );
78
 
79
+    clang::CompilerInvocation::CreateFromArgs(*CI,
80
+                                              &args[0],
81
+                                              &args[0] + args.size(),
82
+                                              Diags);
83
     // Create the compiler instance
84
     clang::CompilerInstance Clang;
85
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
86
+    Clang.setInvocation(std::move(CI));
87
+#else
88
     Clang.setInvocation(CI.release());
89
+#endif
90
     // Get ready to report problems
91
     Clang.createDiagnostics(DiagClient, false);
92
 
93
diff --git a/backend/src/ir/half.cpp b/backend/src/ir/half.cpp
94
index 1c0d7eb..0abc6cb 100644
95
--- a/backend/src/ir/half.cpp
96
+++ b/backend/src/ir/half.cpp
97
@@ -29,7 +29,11 @@ namespace ir {
98
   {
99
     uint64_t v64 = static_cast<uint64_t>(v);
100
     llvm::APInt apInt(16, v64, false);
101
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
102
+    return llvm::APFloat(llvm::APFloat::IEEEhalf(), apInt);
103
+#else
104
     return llvm::APFloat(llvm::APFloat::IEEEhalf, apInt);
105
+#endif
106
   }
107
 
108
   static uint16_t convAPFloatToU16(const llvm::APFloat& apf)
109
@@ -42,14 +46,22 @@ namespace ir {
110
   half::operator float(void) const {
111
     bool loseInfo;
112
     llvm::APFloat apf_self = convU16ToAPFloat(this->val);
113
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
114
+    apf_self.convert(llvm::APFloat::IEEEsingle(), llvm::APFloat::rmNearestTiesToEven, &loseInfo);
115
+#else
116
     apf_self.convert(llvm::APFloat::IEEEsingle, llvm::APFloat::rmNearestTiesToEven, &loseInfo);
117
+#endif
118
     return apf_self.convertToFloat();
119
   }
120
 
121
   half::operator double(void) const {
122
     bool loseInfo;
123
     llvm::APFloat apf_self = convU16ToAPFloat(this->val);
124
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
125
+    apf_self.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven, &loseInfo);
126
+#else
127
     apf_self.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, &loseInfo);
128
+#endif
129
     return apf_self.convertToDouble();
130
   }
131
 
132
@@ -70,7 +82,11 @@ namespace ir {
133
   }
134
 
135
   half half::convToHalf(uint16_t u16) {
136
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
137
+    llvm::APFloat res(llvm::APFloat::IEEEhalf(), llvm::APInt(16, 0, false));
138
+#else
139
     llvm::APFloat res(llvm::APFloat::IEEEhalf, llvm::APInt(16, 0, false));
140
+#endif
141
     uint64_t u64 = static_cast<uint64_t>(u16);
142
     llvm::APInt apInt(16, u64, false);
143
     res.convertFromAPInt(apInt, false, llvm::APFloat::rmNearestTiesToEven);
144
@@ -78,7 +94,11 @@ namespace ir {
145
   }
146
 
147
   half half::convToHalf(int16_t v16) {
148
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
149
+    llvm::APFloat res(llvm::APFloat::IEEEhalf(), llvm::APInt(16, 0, true));
150
+#else
151
     llvm::APFloat res(llvm::APFloat::IEEEhalf, llvm::APInt(16, 0, true));
152
+#endif
153
     uint64_t u64 = static_cast<uint64_t>(v16);
154
     llvm::APInt apInt(16, u64, true);
155
     res.convertFromAPInt(apInt, true, llvm::APFloat::rmNearestTiesToEven);
156
diff --git a/backend/src/libocl/CMakeLists.txt b/backend/src/libocl/CMakeLists.txt
157
index c68ecb0..2917e6d 100644
158
--- a/backend/src/libocl/CMakeLists.txt
159
+++ b/backend/src/libocl/CMakeLists.txt
160
@@ -211,7 +211,7 @@ MACRO(ADD_LL_TO_BC_TARGET M)
161
 	)
162
 ENDMACRO(ADD_LL_TO_BC_TARGET)
163
 
164
-SET (OCL_LL_MODULES_12 ocl_barrier ocl_clz ocl_ctz)
165
+SET (OCL_LL_MODULES_12 ocl_barrier ocl_clz ocl_ctz ocl_sampler)
166
 FOREACH(f ${OCL_LL_MODULES_12})
167
     COPY_THE_LL(${f})
168
     ADD_LL_TO_BC_TARGET(${f})
169
@@ -255,7 +255,7 @@ if (ENABLE_OPENCL_20)
170
     ADD_CL_TO_BC_TARGET(${f} ${bc_name} "${CLANG_OCL_FLAGS_20}")
171
   ENDFOREACH(f)
172
 
173
-  SET (OCL_LL_MODULES_20 ocl_barrier_20 ocl_clz_20 ocl_ctz_20 ocl_atomic_20)
174
+  SET (OCL_LL_MODULES_20 ocl_barrier_20 ocl_clz_20 ocl_ctz_20 ocl_atomic_20 ocl_sampler_20)
175
   FOREACH(f ${OCL_LL_MODULES_20})
176
     COPY_THE_LL(${f})
177
     ADD_LL_TO_BC_TARGET(${f})
178
diff --git a/backend/src/libocl/include/ocl_enqueue.h b/backend/src/libocl/include/ocl_enqueue.h
179
index 6479df7..7ccab59 100644
180
--- a/backend/src/libocl/include/ocl_enqueue.h
181
+++ b/backend/src/libocl/include/ocl_enqueue.h
182
@@ -38,7 +38,7 @@ struct Block_literal {
183
   void *isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
184
   int flags;
185
   int reserved;
186
-  __global void (*invoke)(void *, ...);
187
+  __global void* invoke;
188
   struct Block_descriptor_1 {
189
     unsigned long int reserved;         // NULL
190
     unsigned long int size;         // sizeof(struct Block_literal_1)
191
@@ -65,10 +65,6 @@ OVERLOADABLE int enqueue_kernel(queue_t q, int flag, ndrange_t ndrange, void (^b
192
 OVERLOADABLE int enqueue_kernel(queue_t q, int flag, ndrange_t ndrange,
193
                                 uint num_events_in_wait_list, const clk_event_t *event_wait_list,
194
                                 clk_event_t *event_ret, void (^block)(void));
195
-OVERLOADABLE int enqueue_kernel(queue_t q, int flag, ndrange_t ndrange, __private void *block, uint size0, ...);
196
-OVERLOADABLE int enqueue_kernel(queue_t q, int flag, ndrange_t ndrange,
197
-                                uint num_events_in_wait_list, const clk_event_t *event_wait_list,
198
-                                clk_event_t *event_ret,  __private void *block, uint size0, ...);
199
 
200
 queue_t get_default_queue(void);
201
 int __gen_enqueue_kernel(queue_t q, int flag, ndrange_t ndrange, void (^block)(void), int size);
202
diff --git a/backend/src/libocl/src/ocl_image.cl b/backend/src/libocl/src/ocl_image.cl
203
index 2febfda..e66aa15 100644
204
--- a/backend/src/libocl/src/ocl_image.cl
205
+++ b/backend/src/libocl/src/ocl_image.cl
206
@@ -295,17 +295,18 @@ GEN_VALIDATE_ARRAY_INDEX(int, read_write image1d_buffer_t)
207
 // The work around is to use a LD message instead of normal sample message.
208
 ///////////////////////////////////////////////////////////////////////////////
209
 
210
-bool __gen_ocl_sampler_need_fix(sampler_t);
211
-bool __gen_ocl_sampler_need_rounding_fix(sampler_t);
212
+bool __gen_ocl_sampler_need_fix(int);
213
+bool __gen_ocl_sampler_need_rounding_fix(int);
214
+int __gen_ocl_sampler_to_int(sampler_t);
215
 
216
 bool __gen_sampler_need_fix(const sampler_t sampler)
217
 {
218
-  return __gen_ocl_sampler_need_fix(sampler);
219
+  return __gen_ocl_sampler_need_fix(__gen_ocl_sampler_to_int(sampler));
220
 }
221
 
222
 bool __gen_sampler_need_rounding_fix(const sampler_t sampler)
223
 {
224
-  return __gen_ocl_sampler_need_rounding_fix(sampler);
225
+  return __gen_ocl_sampler_need_rounding_fix(__gen_ocl_sampler_to_int(sampler));
226
 }
227
 
228
 INLINE_OVERLOADABLE float __gen_fixup_float_coord(float tmpCoord)
229
diff --git a/backend/src/libocl/src/ocl_sampler.ll b/backend/src/libocl/src/ocl_sampler.ll
230
new file mode 100644
231
index 0000000..6d39fdb
232
--- /dev/null
233
+++ b/backend/src/libocl/src/ocl_sampler.ll
234
@@ -0,0 +1,10 @@
235
+target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
236
+target triple = "spir"
237
+%opencl.sampler_t = type opaque
238
+
239
+declare %opencl.sampler_t addrspace(2)*@__gen_ocl_int_to_sampler(i32)
240
+
241
+define %opencl.sampler_t addrspace(2)*@__translate_sampler_initializer(i32 %s) {
242
+  %call = call %opencl.sampler_t addrspace(2)*@__gen_ocl_int_to_sampler(i32 %s)
243
+  ret %opencl.sampler_t addrspace(2)* %call
244
+}
245
diff --git a/backend/src/libocl/src/ocl_sampler_20.ll b/backend/src/libocl/src/ocl_sampler_20.ll
246
new file mode 100644
247
index 0000000..bea6d75
248
--- /dev/null
249
+++ b/backend/src/libocl/src/ocl_sampler_20.ll
250
@@ -0,0 +1,10 @@
251
+target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
252
+target triple = "spir64"
253
+%opencl.sampler_t = type opaque
254
+
255
+declare %opencl.sampler_t addrspace(2)*@__gen_ocl_int_to_sampler(i32)
256
+
257
+define %opencl.sampler_t addrspace(2)*@__translate_sampler_initializer(i32 %s) {
258
+  %call = call %opencl.sampler_t addrspace(2)*@__gen_ocl_int_to_sampler(i32 %s)
259
+  ret %opencl.sampler_t addrspace(2)* %call
260
+}
261
diff --git a/backend/src/llvm/ExpandUtils.cpp b/backend/src/llvm/ExpandUtils.cpp
262
index a09d990..cb1736b 100644
263
--- a/backend/src/llvm/ExpandUtils.cpp
264
+++ b/backend/src/llvm/ExpandUtils.cpp
265
@@ -101,7 +101,11 @@ namespace llvm {
266
   Function *RecreateFunction(Function *Func, FunctionType *NewType) {
267
     Function *NewFunc = Function::Create(NewType, Func->getLinkage());
268
     NewFunc->copyAttributesFrom(Func);
269
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
270
+    Func->getParent()->getFunctionList().insert(Func->getIterator(), NewFunc);
271
+#else
272
     Func->getParent()->getFunctionList().insert(ilist_iterator<Function>(Func), NewFunc);
273
+#endif
274
     NewFunc->takeName(Func);
275
     NewFunc->getBasicBlockList().splice(NewFunc->begin(),
276
                                         Func->getBasicBlockList());
277
diff --git a/backend/src/llvm/llvm_barrier_nodup.cpp b/backend/src/llvm/llvm_barrier_nodup.cpp
278
index 727e6bd..a7d0d1a 100644
279
--- a/backend/src/llvm/llvm_barrier_nodup.cpp
280
+++ b/backend/src/llvm/llvm_barrier_nodup.cpp
281
@@ -48,7 +48,12 @@ namespace gbe {
282
 
283
       }
284
 
285
-      virtual const char *getPassName() const {
286
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
287
+      virtual StringRef getPassName() const
288
+#else
289
+      virtual const char *getPassName() const
290
+#endif
291
+      {
292
         return "SPIR backend: set barrier no duplicate attr";
293
       }
294
 
295
diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp
296
index 869db89..5c6585d 100644
297
--- a/backend/src/llvm/llvm_bitcode_link.cpp
298
+++ b/backend/src/llvm/llvm_bitcode_link.cpp
299
@@ -117,17 +117,28 @@ namespace gbe
300
 
301
         std::string ErrInfo;// = "Not Materializable";
302
         if (!fromSrc && newMF->isMaterializable()) {
303
-#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
304
-          if (newMF->Materialize(&ErrInfo)) {
305
-            printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
306
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
307
+          if (llvm::Error EC = newMF->materialize()) {
308
+            std::string Msg;
309
+            handleAllErrors(std::move(EC), [&](ErrorInfoBase &EIB) {
310
+              Msg = EIB.message();
311
+            });
312
+            printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), Msg.c_str());
313
             return false;
314
           }
315
-#else
316
+          Gvs.push_back((GlobalValue *)newMF);
317
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
318
           if (std::error_code EC = newMF->materialize()) {
319
             printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), EC.message().c_str());
320
             return false;
321
           }
322
           Gvs.push_back((GlobalValue *)newMF);
323
+#else
324
+         if (newMF->Materialize(&ErrInfo)) {
325
+            printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
326
+            return false;
327
+          }
328
+
329
 #endif
330
         }
331
         if (!materializedFuncCall(src, lib, *newMF, MFS, Gvs))
332
@@ -250,21 +261,30 @@ namespace gbe
333
       }
334
       std::string ErrInfo;// = "Not Materializable";
335
       if (newMF->isMaterializable()) {
336
-#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
337
-        if (newMF->Materialize(&ErrInfo)) {
338
-          printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
339
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
340
+        if (llvm::Error EC = newMF->materialize()) {
341
+          std::string Msg;
342
+          handleAllErrors(std::move(EC), [&](ErrorInfoBase &EIB) {
343
+            Msg = EIB.message();
344
+          });
345
+          printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), Msg.c_str());
346
           delete clonedLib;
347
           return NULL;
348
         }
349
-      }
350
-#else
351
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
352
         if (std::error_code EC = newMF->materialize()) {
353
           printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), EC.message().c_str());
354
           delete clonedLib;
355
           return NULL;
356
         }
357
-      }
358
+#else
359
+        if (newMF->Materialize(&ErrInfo)) {
360
+          printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
361
+          delete clonedLib;
362
+          return NULL;
363
+        }
364
 #endif
365
+      }
366
 
367
       if (!materializedFuncCall(*mod, *clonedLib, *newMF, materializedFuncs, Gvs)) {
368
         delete clonedLib;
369
@@ -292,7 +312,12 @@ namespace gbe
370
     Module::GlobalListType &GVlist = clonedLib->getGlobalList();
371
     for(Module::global_iterator GVitr = GVlist.begin();GVitr != GVlist.end();++GVitr) {
372
       GlobalValue * GV = &*GVitr;
373
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
374
+      ExitOnError ExitOnErr("Can not materialize the clonedLib: ");
375
+      ExitOnErr(clonedLib->materialize(GV));
376
+#else
377
       clonedLib->materialize(GV);
378
+#endif
379
       Gvs.push_back(GV);
380
     }
381
     llvm::legacy::PassManager Extract;
382
@@ -300,8 +325,13 @@ namespace gbe
383
     Extract.add(createGVExtractionPass(Gvs, false));
384
     Extract.run(*clonedLib);
385
     /* Mark the library module as materialized for later use. */
386
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
387
+    ExitOnError ExitOnErr("Can not materialize the clonedLib: ");
388
+    ExitOnErr(clonedLib->materializeAll());
389
+#else
390
     clonedLib->materializeAll();
391
 #endif
392
+#endif
393
 
394
     /* the SPIR binary datalayout maybe different with beignet's bitcode */
395
     if(clonedLib->getDataLayout() != mod->getDataLayout())
396
@@ -309,14 +339,14 @@ namespace gbe
397
 
398
     /* We use beignet's bitcode as dst because it will have a lot of
399
        lazy functions which will not be loaded. */
400
-    char* errorMsg;
401
 #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
402
     if(LLVMLinkModules2(wrap(clonedLib), wrap(mod))) {
403
 #else
404
+    char* errorMsg;
405
     if(LLVMLinkModules(wrap(clonedLib), wrap(mod), LLVMLinkerDestroySource, &errorMsg)) {
406
+      printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg);
407
 #endif
408
       delete clonedLib;
409
-      printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg);
410
       return NULL;
411
     }
412
 #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
413
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
414
index fa45a42..a106259 100644
415
--- a/backend/src/llvm/llvm_gen_backend.cpp
416
+++ b/backend/src/llvm/llvm_gen_backend.cpp
417
@@ -357,6 +357,15 @@ namespace gbe
418
       GBE_ASSERT(! (isa<Constant>(value) && !isa<GlobalValue>(value)));
419
       Type *type = value->getType();
420
       auto typeID = type->getTypeID();
421
+      if (typeID == Type::PointerTyID)
422
+      {
423
+        Type *eltTy = dyn_cast<PointerType>(type)->getElementType();
424
+        if (eltTy->isStructTy()) {
425
+          StructType *strTy = dyn_cast<StructType>(eltTy);
426
+          if (strTy->getName().data() && strstr(strTy->getName().data(), "sampler"))
427
+            type = Type::getInt32Ty(value->getContext());
428
+        }
429
+      }
430
       switch (typeID) {
431
         case Type::IntegerTyID:
432
         case Type::FloatTyID:
433
@@ -573,7 +582,11 @@ namespace gbe
434
       pass = PASS_EMIT_REGISTERS;
435
     }
436
 
437
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
438
+    virtual llvm::StringRef getPassName() const { return "Gen Back-End"; }
439
+#else
440
     virtual const char *getPassName() const { return "Gen Back-End"; }
441
+#endif
442
 
443
     void getAnalysisUsage(AnalysisUsage &AU) const {
444
 #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
445
@@ -2410,10 +2423,11 @@ namespace gbe
446
         }
447
 
448
         if (llvmInfo.isSamplerType()) {
449
-          ctx.input(argName, ir::FunctionArgument::SAMPLER, reg, llvmInfo, getTypeByteSize(unit, type), getAlignmentByte(unit, type), 0);
450
+          ctx.input(argName, ir::FunctionArgument::SAMPLER, reg, llvmInfo, 4, 4, 0);
451
           (void)ctx.getFunction().getSamplerSet()->append(reg, &ctx);
452
           continue;
453
         }
454
+
455
         if(llvmInfo.isPipeType()) {
456
           llvmInfo.typeSize = getTypeSize(F.getParent(),unit,llvmInfo.typeName);
457
           ctx.input(argName, ir::FunctionArgument::PIPE, reg, llvmInfo, getTypeByteSize(unit, type), getAlignmentByte(unit, type), BtiMap.find(&*I)->second);
458
@@ -4070,6 +4084,15 @@ namespace gbe
459
         regTranslator.newValueProxy(srcValue, dst);
460
         break;
461
       }
462
+      case GEN_OCL_INT_TO_SAMPLER:
463
+      case GEN_OCL_SAMPLER_TO_INT:
464
+      {
465
+        Value *srcValue = I.getOperand(0);
466
+        //srcValue->dump();
467
+        //dst->dump();
468
+        regTranslator.newValueProxy(srcValue, dst);
469
+        break;
470
+      }
471
       case GEN_OCL_ENQUEUE_GET_ENQUEUE_INFO_ADDR:
472
         regTranslator.newScalarProxy(ir::ocl::enqueuebufptr, dst);
473
         break;
474
@@ -4576,10 +4599,19 @@ namespace gbe
475
   /* append a new sampler. should be called before any reference to
476
    * a sampler_t value. */
477
   uint8_t GenWriter::appendSampler(CallSite::arg_iterator AI) {
478
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
479
+    CallInst *TC = dyn_cast<CallInst>(*AI);
480
+    Constant *CPV = TC ? dyn_cast<Constant>(TC->getOperand(0)) : NULL;
481
+#else
482
     Constant *CPV = dyn_cast<Constant>(*AI);
483
+#endif
484
     uint8_t index;
485
     if (CPV != NULL)
486
     {
487
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
488
+      // Check if the Callee is sampler convert function
489
+      GBE_ASSERT(TC->getCalledFunction()->getName().str() == "__gen_ocl_int_to_sampler");
490
+#endif
491
       // This is not a kernel argument sampler, we need to append it to sampler set,
492
       // and allocate a sampler slot for it.
493
       const ir::Immediate &x = processConstantImm(CPV);
494
@@ -5583,6 +5615,8 @@ namespace gbe
495
           case GEN_OCL_GET_PIPE:
496
           case GEN_OCL_MAKE_RID:
497
           case GEN_OCL_GET_RID:
498
+          case GEN_OCL_INT_TO_SAMPLER:
499
+          case GEN_OCL_SAMPLER_TO_INT:
500
           {
501
             break;
502
           }
503
diff --git a/backend/src/llvm/llvm_gen_ocl_function.hxx b/backend/src/llvm/llvm_gen_ocl_function.hxx
504
index 5682c45..b056642 100644
505
--- a/backend/src/llvm/llvm_gen_ocl_function.hxx
506
+++ b/backend/src/llvm/llvm_gen_ocl_function.hxx
507
@@ -279,3 +279,7 @@ DECL_LLVM_GEN_FUNCTION(MAKE_RID, __gen_ocl_make_rid)
508
 DECL_LLVM_GEN_FUNCTION(ENQUEUE_SET_NDRANGE_INFO, __gen_ocl_set_ndrange_info)
509
 DECL_LLVM_GEN_FUNCTION(ENQUEUE_GET_NDRANGE_INFO, __gen_ocl_get_ndrange_info)
510
 DECL_LLVM_GEN_FUNCTION(ENQUEUE_GET_ENQUEUE_INFO_ADDR, __gen_ocl_get_enqueue_info_addr)
511
+
512
+// sampler helper functions
513
+DECL_LLVM_GEN_FUNCTION(SAMPLER_TO_INT, __gen_ocl_sampler_to_int)
514
+DECL_LLVM_GEN_FUNCTION(INT_TO_SAMPLER, __gen_ocl_int_to_sampler)
515
diff --git a/backend/src/llvm/llvm_includes.hpp b/backend/src/llvm/llvm_includes.hpp
516
index a242fd3..184553a 100644
517
--- a/backend/src/llvm/llvm_includes.hpp
518
+++ b/backend/src/llvm/llvm_includes.hpp
519
@@ -24,6 +24,7 @@
520
 #ifndef __GBE_IR_LLVM_INCLUDES_HPP__
521
 #define __GBE_IR_LLVM_INCLUDES_HPP__
522
 
523
+#ifdef GBE_COMPILER_AVAILABLE
524
 #include "llvm/Config/llvm-config.h"
525
 
526
 #include "llvm/IR/BasicBlock.h"
527
@@ -75,7 +76,12 @@
528
 
529
 #include "llvm-c/Linker.h"
530
 #include "llvm/IRReader/IRReader.h"
531
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
532
+#include <llvm/Bitcode/BitcodeWriter.h>
533
+//#include <llvm/Bitcode/BitcodeReader.h>
534
+#else
535
 #include "llvm/Bitcode/ReaderWriter.h"
536
+#endif
537
 #include "llvm/Transforms/IPO.h"
538
 #include "llvm/Transforms/Utils/Cloning.h"
539
 
540
@@ -132,4 +138,10 @@
541
 #include "llvm/Transforms/Scalar/GVN.h"
542
 #endif
543
 
544
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
545
+#include "llvm/Support/Error.h"
546
+#endif
547
+
548
+#endif /*GBE_COMPILER_AVAILABLE */
549
+
550
 #endif /* __GBE_IR_LLVM_INCLUDES_HPP__ */
551
diff --git a/backend/src/llvm/llvm_intrinsic_lowering.cpp b/backend/src/llvm/llvm_intrinsic_lowering.cpp
552
index f01bb51..57c933f 100644
553
--- a/backend/src/llvm/llvm_intrinsic_lowering.cpp
554
+++ b/backend/src/llvm/llvm_intrinsic_lowering.cpp
555
@@ -40,7 +40,12 @@ namespace gbe {
556
 
557
       }
558
 
559
-      virtual const char *getPassName() const {
560
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
561
+      virtual StringRef getPassName() const
562
+#else
563
+      virtual const char *getPassName() const
564
+#endif
565
+      {
566
         return "SPIR backend: lowering instrinsics";
567
       }
568
       static char convertSpaceToName(Value *val) {
569
diff --git a/backend/src/llvm/llvm_loadstore_optimization.cpp b/backend/src/llvm/llvm_loadstore_optimization.cpp
570
index 4f4639c..5aa38be 100644
571
--- a/backend/src/llvm/llvm_loadstore_optimization.cpp
572
+++ b/backend/src/llvm/llvm_loadstore_optimization.cpp
573
@@ -75,8 +75,12 @@ namespace gbe {
574
                                   const BasicBlock::iterator &start,
575
                                   unsigned maxVecSize,
576
                                   bool isLoad);
577
-
578
-    virtual const char *getPassName() const {
579
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
580
+    virtual StringRef getPassName() const
581
+#else
582
+    virtual const char *getPassName() const
583
+#endif
584
+    {
585
       return "Merge compatible Load/stores for Gen";
586
     }
587
   };
588
diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp
589
index f414fbb..10752a3 100644
590
--- a/backend/src/llvm/llvm_passes.cpp
591
+++ b/backend/src/llvm/llvm_passes.cpp
592
@@ -232,7 +232,11 @@ namespace gbe
593
       AU.setPreservesCFG();
594
     }
595
 
596
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
597
+    virtual StringRef getPassName() const {
598
+#else
599
     virtual const char *getPassName() const {
600
+#endif
601
       return "SPIR backend: insert special spir instructions";
602
     }
603
 
604
diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp
605
index a1b1c2c..6bb7c52 100644
606
--- a/backend/src/llvm/llvm_printf_parser.cpp
607
+++ b/backend/src/llvm/llvm_printf_parser.cpp
608
@@ -309,7 +309,11 @@ error:
609
     bool parseOnePrintfInstruction(CallInst * call);
610
     bool generateOneParameterInst(PrintfSlot& slot, Value* arg, Value*& new_arg);
611
 
612
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
613
+    virtual StringRef getPassName() const
614
+#else
615
     virtual const char *getPassName() const
616
+#endif
617
     {
618
       return "Printf Parser";
619
     }
620
@@ -515,7 +519,11 @@ error:
621
       case Type::FloatTyID: {
622
         /* llvm 3.6 will give a undef value for NAN. */
623
         if (dyn_cast<llvm::UndefValue>(arg)) {
624
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
625
+          APFloat nan = APFloat::getNaN(APFloat::IEEEsingle(), false);
626
+#else
627
           APFloat nan = APFloat::getNaN(APFloat::IEEEsingle, false);
628
+#endif
629
           new_arg = ConstantFP::get(module->getContext(), nan);
630
         }
631
 
632
diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp
633
index bc16951..f7e4cc5 100644
634
--- a/backend/src/llvm/llvm_profiling.cpp
635
+++ b/backend/src/llvm/llvm_profiling.cpp
636
@@ -83,7 +83,11 @@ namespace gbe
637
     {
638
     }
639
 
640
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
641
+    virtual StringRef getPassName() const
642
+#else
643
     virtual const char *getPassName() const
644
+#endif
645
     {
646
       return "Timestamp Parser";
647
     }
648
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
649
index 9b3b1f4..37919ec 100644
650
--- a/backend/src/llvm/llvm_to_gen.cpp
651
+++ b/backend/src/llvm/llvm_to_gen.cpp
652
@@ -402,9 +402,17 @@ namespace gbe
653
     passes.add(createScalarizePass());             // Expand all vector ops
654
 
655
     if(OCL_OUTPUT_CFG)
656
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
657
+      passes.add(createCFGPrinterLegacyPassPass());
658
+#else
659
       passes.add(createCFGPrinterPass());
660
+#endif
661
     if(OCL_OUTPUT_CFG_ONLY)
662
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
663
+      passes.add(createCFGOnlyPrinterLegacyPassPass());
664
+#else
665
       passes.add(createCFGOnlyPrinterPass());
666
+#endif
667
     passes.add(createGenPass(unit));
668
     passes.run(mod);
669
     errors = dc.str();
670
diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp
671
index bfd3bbe..107d793 100644
672
--- a/backend/src/llvm/llvm_unroll.cpp
673
+++ b/backend/src/llvm/llvm_unroll.cpp
674
@@ -238,7 +238,12 @@ namespace gbe {
675
         return true;
676
       }
677
 
678
-      virtual const char *getPassName() const {
679
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
680
+      virtual StringRef getPassName() const
681
+#else
682
+      virtual const char *getPassName() const
683
+#endif
684
+      {
685
         return "SPIR backend: custom loop unrolling pass";
686
       }
687
 
688
-- 
689
cgit v0.10.2
690
(-)lang/beignet/files/extra-patch-refine_llvm_version_check (+921 lines)
Line 0 Link Here
1
From f40ed02f7de65296219a0a160118ae3234e765c5 Mon Sep 17 00:00:00 2001
2
From: Pan Xiuli <xiuli.pan@intel.com>
3
Date: Fri, 17 Mar 2017 14:16:01 +0800
4
Subject: Backend: Refine LLVM version check macro
5
6
LLVM 4.0 is coming, we should refine our version check to fit the
7
LLVM_MAJOR_VERSION bump to 4.
8
9
Signed-off-by: Pan Xiuli <xiuli.pan@intel.com>
10
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
11
12
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
13
index 376342b..998e340 100644
14
--- a/backend/src/backend/gen_program.cpp
15
+++ b/backend/src/backend/gen_program.cpp
16
@@ -329,13 +329,13 @@ namespace gbe {
17
     //the first byte stands for binary_type.
18
     binary_content.assign(binary+1, size-1);
19
     llvm::StringRef llvm_bin_str(binary_content);
20
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
21
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
22
     llvm::LLVMContext& c = GBEGetLLVMContext();
23
 #else
24
     llvm::LLVMContext& c = llvm::getGlobalContext();
25
 #endif
26
     llvm::SMDiagnostic Err;
27
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
28
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
29
     std::unique_ptr<llvm::MemoryBuffer> memory_buffer = llvm::MemoryBuffer::getMemBuffer(llvm_bin_str, "llvm_bin_str");
30
     acquireLLVMContextLock();
31
     llvm::Module* module = llvm::parseIR(memory_buffer->getMemBufferRef(), Err, c).release();
32
@@ -482,14 +482,14 @@ namespace gbe {
33
     using namespace gbe;
34
     char* errMsg;
35
     if(((GenProgram*)dst_program)->module == NULL){
36
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
37
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
38
       ((GenProgram*)dst_program)->module = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module).release();
39
 #else
40
       ((GenProgram*)dst_program)->module = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module);
41
 #endif
42
       errSize = 0;
43
     }else{
44
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
45
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
46
       // Src now will be removed automatically. So clone it.
47
       llvm::Module* src = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module).release();
48
 #else
49
@@ -497,9 +497,9 @@ namespace gbe {
50
 #endif
51
       llvm::Module* dst = (llvm::Module*)((GenProgram*)dst_program)->module;
52
 
53
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
54
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
55
       if (LLVMLinkModules2(wrap(dst), wrap(src))) {
56
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
57
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
58
       if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource_Removed, &errMsg)) {
59
 #else
60
       if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource, &errMsg)) {
61
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
62
index 6b5fce0..6e8227a 100644
63
--- a/backend/src/backend/program.cpp
64
+++ b/backend/src/backend/program.cpp
65
@@ -115,7 +115,7 @@ namespace gbe {
66
     llvm::Module * cloned_module = NULL;
67
     bool ret = false;
68
     if(module){
69
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
70
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
71
       cloned_module = llvm::CloneModule((llvm::Module*)module).release();
72
 #else
73
       cloned_module = llvm::CloneModule((llvm::Module*)module);
74
@@ -124,7 +124,7 @@ namespace gbe {
75
     bool strictMath = true;
76
     if (fast_relaxed_math || !OCL_STRICT_CONFORMANCE)
77
       strictMath = false;
78
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
79
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
80
     llvm::Module * linked_module = module ? llvm::CloneModule((llvm::Module*)module).release() : NULL;
81
     // Src now will be removed automatically. So clone it.
82
     if (llvmToGen(*unit, fileName, linked_module, optLevel, strictMath, OCL_PROFILING_LOG, error) == false) {
83
@@ -651,7 +651,7 @@ namespace gbe {
84
     // The ParseCommandLineOptions used for mllvm args can not be used with multithread
85
     // and GVN now have a 100 inst limit on block scan. Now only pass a bigger limit
86
     // for each context only once, this can also fix multithread bug.
87
-#if LLVM_VERSION_MINOR >= 8
88
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
89
     static bool ifsetllvm = false;
90
     if(!ifsetllvm) {
91
       args.push_back("-mllvm");
92
@@ -702,7 +702,7 @@ namespace gbe {
93
                                               Diags);
94
     llvm::StringRef srcString(source);
95
     (*CI).getPreprocessorOpts().addRemappedFile("stringInput.cl",
96
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
97
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
98
                 llvm::MemoryBuffer::getMemBuffer(srcString)
99
 #else
100
                 llvm::MemoryBuffer::getMemBuffer(srcString).release()
101
@@ -755,7 +755,7 @@ namespace gbe {
102
     if (!retVal)
103
       return false;
104
 
105
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
106
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
107
     llvm::Module *module = Act->takeModule();
108
 #else
109
     llvm::Module *module = Act->takeModule().release();
110
@@ -764,7 +764,7 @@ namespace gbe {
111
     *out_module = module;
112
 
113
 // Dump the LLVM if requested.
114
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 6)
115
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 36
116
     if (!dumpLLVMFileName.empty()) {
117
       std::string err;
118
       llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
119
@@ -1123,7 +1123,7 @@ EXTEND_QUOTE:
120
     //FIXME: if use new allocated context to link two modules there would be context mismatch
121
     //for some functions, so we use global context now, need switch to new context later.
122
     llvm::Module * out_module;
123
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
124
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
125
     llvm::LLVMContext* llvm_ctx = &GBEGetLLVMContext();
126
 #else
127
     llvm::LLVMContext* llvm_ctx = &llvm::getGlobalContext();
128
@@ -1599,7 +1599,7 @@ namespace gbe
129
     }
130
 
131
     ~CallBackInitializer() {
132
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR > 3)
133
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 34
134
       llvm::llvm_shutdown();
135
 #endif
136
     }
137
diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp
138
index 5fcb14a..64d9727 100644
139
--- a/backend/src/ir/function.hpp
140
+++ b/backend/src/ir/function.hpp
141
@@ -186,7 +186,7 @@ namespace ir {
142
 
143
 
144
       // only llvm-3.6 or later has kernel_arg_base_type in metadata.
145
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR <= 5)
146
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
147
       bool isImage1dT() const {
148
         return typeName.compare("image1d_t") == 0;
149
       }
150
diff --git a/backend/src/llvm/ExpandLargeIntegers.cpp b/backend/src/llvm/ExpandLargeIntegers.cpp
151
index 60740f5..8515dc1 100644
152
--- a/backend/src/llvm/ExpandLargeIntegers.cpp
153
+++ b/backend/src/llvm/ExpandLargeIntegers.cpp
154
@@ -93,7 +93,7 @@
155
 
156
 using namespace llvm;
157
 
158
-#if LLVM_VERSION_MINOR >= 5
159
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
160
 #define DEBUG_TYPE "nacl-expand-ints"
161
 #endif
162
 
163
@@ -766,7 +766,7 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
164
 bool ExpandLargeIntegers::runOnFunction(Function &F) {
165
   // Don't support changing the function arguments. Illegal function arguments
166
   // should not be generated by clang.
167
-#if LLVM_VERSION_MINOR >= 5
168
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
169
   for (const Argument &Arg : F.args())
170
 #else
171
   for (const Argument &Arg : F.getArgumentList())
172
@@ -789,7 +789,7 @@ bool ExpandLargeIntegers::runOnFunction(Function &F) {
173
       // Only attempt to convert an instruction if its result or any of its
174
       // operands are illegal.
175
       bool ShouldConvert = shouldConvert(&I);
176
-#if LLVM_VERSION_MINOR >= 5
177
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
178
       for (Value *Op : I.operands())
179
         ShouldConvert |= shouldConvert(Op);
180
 #else
181
diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp
182
index 89d5e7c..869db89 100644
183
--- a/backend/src/llvm/llvm_bitcode_link.cpp
184
+++ b/backend/src/llvm/llvm_bitcode_link.cpp
185
@@ -60,7 +60,7 @@ namespace gbe
186
       return NULL;
187
     }
188
 
189
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
190
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
191
     oclLib = getLazyIRFileModule(FilePath, Err, ctx);
192
 #else
193
     oclLib = getLazyIRFileModule(FilePath, Err, ctx).release();
194
@@ -117,7 +117,7 @@ namespace gbe
195
 
196
         std::string ErrInfo;// = "Not Materializable";
197
         if (!fromSrc && newMF->isMaterializable()) {
198
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
199
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
200
           if (newMF->Materialize(&ErrInfo)) {
201
             printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
202
             return false;
203
@@ -250,7 +250,7 @@ namespace gbe
204
       }
205
       std::string ErrInfo;// = "Not Materializable";
206
       if (newMF->isMaterializable()) {
207
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
208
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
209
         if (newMF->Materialize(&ErrInfo)) {
210
           printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
211
           delete clonedLib;
212
@@ -287,7 +287,7 @@ namespace gbe
213
    * pass to extract the functions and values in Gvs from the library module.
214
    * After extract what we need and remove what we do not need, we use 
215
    * materializeAll to mark the module as materialized. */
216
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=8
217
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
218
     /* Get all GlobalValue from module. */
219
     Module::GlobalListType &GVlist = clonedLib->getGlobalList();
220
     for(Module::global_iterator GVitr = GVlist.begin();GVitr != GVlist.end();++GVitr) {
221
@@ -310,7 +310,7 @@ namespace gbe
222
     /* We use beignet's bitcode as dst because it will have a lot of
223
        lazy functions which will not be loaded. */
224
     char* errorMsg;
225
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
226
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
227
     if(LLVMLinkModules2(wrap(clonedLib), wrap(mod))) {
228
 #else
229
     if(LLVMLinkModules(wrap(clonedLib), wrap(mod), LLVMLinkerDestroySource, &errorMsg)) {
230
@@ -319,13 +319,13 @@ namespace gbe
231
       printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg);
232
       return NULL;
233
     }
234
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
235
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
236
     llvm::legacy::PassManager passes;
237
 #else
238
     llvm::PassManager passes;
239
 #endif
240
 
241
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=9
242
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
243
     auto PreserveKernel = [=](const GlobalValue &GV) {
244
       for(size_t i = 0;i < kernels.size(); ++i)
245
         if(strcmp(GV.getName().data(), kernels[i]))
246
diff --git a/backend/src/llvm/llvm_device_enqueue.cpp b/backend/src/llvm/llvm_device_enqueue.cpp
247
index ee236de..9a0fb46 100644
248
--- a/backend/src/llvm/llvm_device_enqueue.cpp
249
+++ b/backend/src/llvm/llvm_device_enqueue.cpp
250
@@ -62,7 +62,7 @@ namespace gbe {
251
       for (Value::use_iterator iter = v->use_begin(); iter != v->use_end(); ++iter) {
252
         // After LLVM 3.5, use_iterator points to 'Use' instead of 'User',
253
         // which is more straightforward.
254
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
255
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
256
         User *theUser = *iter;
257
 #else
258
         User *theUser = iter->getUser();
259
@@ -84,7 +84,7 @@ namespace gbe {
260
 
261
   Function* setFunctionAsKernel(Module *mod, Function *Fn)
262
   {
263
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 9)
264
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
265
     LLVMContext &Context = mod->getContext();
266
     Type *intTy = IntegerType::get(mod->getContext(), 32);
267
     SmallVector<llvm::Metadata *, 5> kernelMDArgs;
268
@@ -210,7 +210,7 @@ namespace gbe {
269
           }
270
 
271
           for (Value::use_iterator iter = bt->use_begin(); iter != bt->use_end(); ++iter) {
272
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
273
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
274
             User *theUser = *iter;
275
 #else
276
             User *theUser = iter->getUser();
277
@@ -298,7 +298,7 @@ namespace gbe {
278
             if(AllocaInst *ai = dyn_cast<AllocaInst>(ld->getPointerOperand())) {
279
               Value *v = NULL;
280
               for (Value::use_iterator iter = ai->use_begin(); iter != ai->use_end(); ++iter) {
281
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
282
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
283
                 User *theUser = *iter;
284
 #else
285
                 User *theUser = iter->getUser();
286
@@ -347,7 +347,7 @@ namespace gbe {
287
             if(ld) {
288
               Value *block = ld->getPointerOperand();
289
               for (Value::use_iterator iter = block->use_begin(); iter != block->use_end(); ++iter) {
290
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
291
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
292
                 User *theUser = *iter;
293
 #else
294
                 User *theUser = iter->getUser();
295
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
296
index 742c947..4621f6d 100644
297
--- a/backend/src/llvm/llvm_gen_backend.cpp
298
+++ b/backend/src/llvm/llvm_gen_backend.cpp
299
@@ -95,9 +95,9 @@
300
 #define LLVM_VERSION_MINOR 0
301
 #endif /* !defined(LLVM_VERSION_MINOR) */
302
 
303
-#if (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR < 3)
304
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 33
305
 #error "Only LLVM 3.3 and newer are supported"
306
-#endif /* (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR > 4) */
307
+#endif
308
 
309
 using namespace llvm;
310
 
311
@@ -565,7 +565,7 @@ namespace gbe
312
         has_errors(false),
313
         legacyMode(true)
314
     {
315
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
316
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
317
       initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry());
318
 #else
319
       initializeLoopInfoPass(*PassRegistry::getPassRegistry());
320
@@ -576,7 +576,7 @@ namespace gbe
321
     virtual const char *getPassName() const { return "Gen Back-End"; }
322
 
323
     void getAnalysisUsage(AnalysisUsage &AU) const {
324
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
325
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
326
       AU.addRequired<LoopInfoWrapperPass>();
327
 #else
328
       AU.addRequired<LoopInfo>();
329
@@ -611,7 +611,7 @@ namespace gbe
330
       if (legacyMode)
331
         analyzePointerOrigin(F);
332
 
333
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
334
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
335
       LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
336
 #else
337
       LI = &getAnalysis<LoopInfo>();
338
@@ -835,7 +835,7 @@ namespace gbe
339
       for (Value::use_iterator iter = work->use_begin(); iter != work->use_end(); ++iter) {
340
       // After LLVM 3.5, use_iterator points to 'Use' instead of 'User',
341
       // which is more straightforward.
342
-  #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
343
+  #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
344
         User *theUser = *iter;
345
   #else
346
         User *theUser = iter->getUser();
347
@@ -1089,7 +1089,7 @@ namespace gbe
348
             if (predBB->getTerminator())
349
               Builder2.SetInsertPoint(predBB->getTerminator());
350
 
351
-#if (LLVM_VERSION_MAJOR== 3 && LLVM_VERSION_MINOR < 6)
352
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 36
353
   // llvm 3.5 and older version don't have CreateBitOrPointerCast() define
354
             Type *srcTy = base->getType();
355
             Type *dstTy = ptr->getType();
356
@@ -1248,7 +1248,7 @@ namespace gbe
357
      uint32_t ops = clKernels->getNumOperands();
358
       for(uint32_t x = 0; x < ops; x++) {
359
         MDNode* node = clKernels->getOperand(x);
360
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
361
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
362
         Value * op = node->getOperand(0);
363
 #else
364
         auto *V = cast<ValueAsMetadata>(node->getOperand(0));
365
@@ -1272,7 +1272,7 @@ namespace gbe
366
     MDNode *typeNameNode = NULL;
367
     MDNode *typeBaseNameNode = NULL;
368
     MDNode *typeQualNode = NULL;
369
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
370
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
371
     typeNameNode = F.getMetadata("kernel_arg_type");
372
     typeBaseNameNode = F.getMetadata("kernel_arg_base_type");
373
     typeQualNode = F.getMetadata("kernel_arg_type_qual");
374
@@ -1298,7 +1298,7 @@ namespace gbe
375
     ir::FunctionArgument::InfoFromLLVM llvmInfo;
376
     for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I, argID++) {
377
       unsigned opID = argID;
378
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9
379
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 39
380
       opID += 1;
381
 #endif
382
 
383
@@ -1340,7 +1340,7 @@ namespace gbe
384
       for (Value::use_iterator iter = work->use_begin(); iter != work->use_end(); ++iter) {
385
       // After LLVM 3.5, use_iterator points to 'Use' instead of 'User',
386
       // which is more straightforward.
387
-  #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
388
+  #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
389
         User *theUser = *iter;
390
   #else
391
         User *theUser = iter->getUser();
392
@@ -2120,7 +2120,7 @@ namespace gbe
393
 
394
     std::string functionAttributes;
395
 
396
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
397
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
398
     /* LLVM 3.9 change kernel arg info as function metadata */
399
     addrSpaceNode = F.getMetadata("kernel_arg_addr_space");
400
     accessQualNode = F.getMetadata("kernel_arg_access_qual");
401
@@ -2222,7 +2222,7 @@ namespace gbe
402
 
403
       if (attrName->getString() == "reqd_work_group_size") {
404
         GBE_ASSERT(attrNode->getNumOperands() == 4);
405
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
406
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
407
         ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1));
408
         ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2));
409
         ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3));
410
@@ -2264,13 +2264,13 @@ namespace gbe
411
       } else if (attrName->getString() == "vec_type_hint") {
412
         GBE_ASSERT(attrNode->getNumOperands() == 3);
413
         functionAttributes += attrName->getString();
414
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
415
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
416
         Value* V = attrNode->getOperand(1);
417
 #else
418
         auto *Op1 = cast<ValueAsMetadata>(attrNode->getOperand(1));
419
         Value *V = Op1 ? Op1->getValue() : NULL;
420
 #endif
421
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
422
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
423
         ConstantInt *sign = dyn_cast<ConstantInt>(attrNode->getOperand(2));
424
 #else
425
         ConstantInt *sign = mdconst::extract<ConstantInt>(attrNode->getOperand(2));
426
@@ -2299,7 +2299,7 @@ namespace gbe
427
         functionAttributes += " ";
428
       } else if (attrName->getString() == "work_group_size_hint") {
429
         GBE_ASSERT(attrNode->getNumOperands() == 4);
430
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
431
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
432
         ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1));
433
         ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2));
434
         ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3));
435
@@ -2341,13 +2341,13 @@ namespace gbe
436
       // Insert a new register for each function argument
437
       for (; I != E; ++I, ++argID) {
438
         uint32_t opID = argID;
439
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9
440
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 39
441
         opID += 1;
442
 #endif
443
         const std::string &argName = I->getName().str();
444
         Type *type = I->getType();
445
         if(addrSpaceNode) {
446
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
447
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
448
           llvmInfo.addrSpace = (cast<ConstantInt>(addrSpaceNode->getOperand(opID)))->getZExtValue();
449
 #else
450
           llvmInfo.addrSpace = (mdconst::extract<ConstantInt>(addrSpaceNode->getOperand(opID)))->getZExtValue();
451
@@ -2914,7 +2914,7 @@ namespace gbe
452
     const Instruction *insn = NULL;
453
     for(Value::const_use_iterator iter = v->use_begin(); iter != v->use_end(); ++iter) {
454
     // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', which is more straightforward.
455
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
456
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
457
       const User *theUser = *iter;
458
 #else
459
       const User *theUser = iter->getUser();
460
diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp
461
index f1c791e..2a322ac 100644
462
--- a/backend/src/llvm/llvm_gen_backend.hpp
463
+++ b/backend/src/llvm/llvm_gen_backend.hpp
464
@@ -149,7 +149,7 @@ namespace gbe
465
   /*! Insert the time stamp for profiling. */
466
   llvm::FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit &unit);
467
 
468
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
469
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
470
   /* customized loop unrolling pass. */
471
   llvm::LoopPass *createCustomLoopUnrollPass();
472
 #endif
473
diff --git a/backend/src/llvm/llvm_includes.hpp b/backend/src/llvm/llvm_includes.hpp
474
index 0b80979..a242fd3 100644
475
--- a/backend/src/llvm/llvm_includes.hpp
476
+++ b/backend/src/llvm/llvm_includes.hpp
477
@@ -91,7 +91,7 @@
478
 #include "llvm/MC/MCSubtargetInfo.h"
479
 #include "llvm/MC/MCSymbol.h"
480
 
481
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5
482
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
483
 #include "llvm/IR/Mangler.h"
484
 #include "llvm/IR/CallSite.h"
485
 #include "llvm/IR/CFG.h"
486
@@ -111,7 +111,7 @@
487
 #include "llvm/Target/Mangler.h"
488
 #endif
489
 
490
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
491
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
492
 #include "llvm/Analysis/TargetLibraryInfo.h"
493
 #include "llvm/IR/LegacyPassManager.h"
494
 #else
495
@@ -122,12 +122,12 @@
496
 
497
 #include <clang/CodeGen/CodeGenAction.h>
498
 
499
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=8
500
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
501
 #include "llvm/Analysis/BasicAliasAnalysis.h"
502
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
503
 #endif
504
 
505
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
506
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
507
 #include "llvm/Transforms/IPO/FunctionAttrs.h"
508
 #include "llvm/Transforms/Scalar/GVN.h"
509
 #endif
510
diff --git a/backend/src/llvm/llvm_loadstore_optimization.cpp b/backend/src/llvm/llvm_loadstore_optimization.cpp
511
index e797e98..4f4639c 100644
512
--- a/backend/src/llvm/llvm_loadstore_optimization.cpp
513
+++ b/backend/src/llvm/llvm_loadstore_optimization.cpp
514
@@ -35,7 +35,7 @@ namespace gbe {
515
     GenLoadStoreOptimization() : BasicBlockPass(ID) {}
516
 
517
     void getAnalysisUsage(AnalysisUsage &AU) const {
518
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
519
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
520
       AU.addRequired<ScalarEvolutionWrapperPass>();
521
       AU.addPreserved<ScalarEvolutionWrapperPass>();
522
 #else
523
@@ -46,12 +46,12 @@ namespace gbe {
524
     }
525
 
526
     virtual bool runOnBasicBlock(BasicBlock &BB) {
527
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
528
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
529
       SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
530
 #else
531
       SE = &getAnalysis<ScalarEvolution>();
532
 #endif
533
-      #if LLVM_VERSION_MINOR >= 7
534
+      #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
535
         TD = &BB.getModule()->getDataLayout();
536
       #elif LLVM_VERSION_MINOR >= 5
537
         DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
538
diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp
539
index 8f5bcc9..f414fbb 100644
540
--- a/backend/src/llvm/llvm_passes.cpp
541
+++ b/backend/src/llvm/llvm_passes.cpp
542
@@ -42,7 +42,7 @@ namespace gbe
543
 {
544
   bool isKernelFunction(const llvm::Function &F) {
545
     bool bKernel = false;
546
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
547
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
548
     bKernel = F.getMetadata("kernel_arg_name") != NULL;
549
 #else
550
     const Module *module = F.getParent();
551
@@ -53,7 +53,7 @@ namespace gbe
552
       uint32_t ops = md.getNumOperands();
553
       for(uint32_t x = 0; x < ops; x++) {
554
         MDNode* node = md.getOperand(x);
555
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
556
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
557
         Value * op = node->getOperand(0);
558
 #else
559
         Value * op = cast<ValueAsMetadata>(node->getOperand(0))->getValue();
560
@@ -74,7 +74,7 @@ namespace gbe
561
     if(ops > 0) {
562
       uint32_t major = 0, minor = 0;
563
       MDNode* node = version->getOperand(0);
564
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
565
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
566
       major = mdconst::extract<ConstantInt>(node->getOperand(0))->getZExtValue();
567
       minor = mdconst::extract<ConstantInt>(node->getOperand(1))->getZExtValue();
568
 #else
569
diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp
570
index 734c69d..bc16951 100644
571
--- a/backend/src/llvm/llvm_profiling.cpp
572
+++ b/backend/src/llvm/llvm_profiling.cpp
573
@@ -34,7 +34,7 @@
574
 #include "llvm/Pass.h"
575
 #include "llvm/IR/IRBuilder.h"
576
 
577
-#if LLVM_VERSION_MINOR >= 5
578
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
579
 #include "llvm/IR/CallSite.h"
580
 #include "llvm/IR/CFG.h"
581
 #else
582
diff --git a/backend/src/llvm/llvm_sampler_fix.cpp b/backend/src/llvm/llvm_sampler_fix.cpp
583
index de7ebdb..2e8bcf9 100644
584
--- a/backend/src/llvm/llvm_sampler_fix.cpp
585
+++ b/backend/src/llvm/llvm_sampler_fix.cpp
586
@@ -33,7 +33,7 @@ namespace gbe {
587
   class SamplerFix : public FunctionPass {
588
   public:
589
     SamplerFix() : FunctionPass(ID) {
590
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
591
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
592
       initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
593
 #else
594
       initializeDominatorTreePass(*PassRegistry::getPassRegistry());
595
diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp
596
index 329e3a9..be3d549 100644
597
--- a/backend/src/llvm/llvm_scalarize.cpp
598
+++ b/backend/src/llvm/llvm_scalarize.cpp
599
@@ -96,7 +96,7 @@ namespace gbe {
600
 
601
     Scalarize() : FunctionPass(ID)
602
     {
603
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
604
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
605
       initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
606
 #else
607
       initializeDominatorTreePass(*PassRegistry::getPassRegistry());
608
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
609
index bef4df1..9b3b1f4 100644
610
--- a/backend/src/llvm/llvm_to_gen.cpp
611
+++ b/backend/src/llvm/llvm_to_gen.cpp
612
@@ -46,14 +46,14 @@ namespace gbe
613
   BVAR(OCL_OUTPUT_CFG_GEN_IR, false);
614
   using namespace llvm;
615
 
616
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
617
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
618
   llvm::LLVMContext& GBEGetLLVMContext() {
619
     static llvm::LLVMContext GBEContext;
620
     return GBEContext;
621
   }
622
 #endif
623
 
624
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
625
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
626
   #define TARGETLIBRARY  TargetLibraryInfoImpl
627
 #else
628
   #define TARGETLIBRARY  TargetLibraryInfo
629
@@ -61,32 +61,32 @@ namespace gbe
630
 
631
   void runFuntionPass(Module &mod, TARGETLIBRARY *libraryInfo, const DataLayout &DL)
632
   {
633
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
634
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
635
     legacy::FunctionPassManager FPM(&mod);
636
 #else
637
     FunctionPassManager FPM(&mod);
638
 #endif
639
 
640
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
641
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
642
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
643
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
644
     FPM.add(new DataLayoutPass());
645
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
646
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35
647
     FPM.add(new DataLayoutPass(DL));
648
 #else
649
     FPM.add(new DataLayout(DL));
650
 #endif
651
 
652
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5
653
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
654
     FPM.add(createVerifierPass(true));
655
 #else
656
     FPM.add(createVerifierPass());
657
 #endif
658
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
659
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
660
     FPM.add(new TargetLibraryInfoWrapperPass(*libraryInfo));
661
 #else
662
     FPM.add(new TargetLibraryInfo(*libraryInfo));
663
 #endif
664
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
665
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
666
     FPM.add(createTypeBasedAAWrapperPass());
667
     FPM.add(createBasicAAWrapperPass());
668
 #else
669
@@ -108,27 +108,27 @@ namespace gbe
670
 
671
   void runModulePass(Module &mod, TARGETLIBRARY *libraryInfo, const DataLayout &DL, int optLevel, bool strictMath)
672
   {
673
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
674
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
675
     legacy::PassManager MPM;
676
 #else
677
     PassManager MPM;
678
 #endif
679
 
680
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
681
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
682
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
683
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
684
     MPM.add(new DataLayoutPass());
685
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
686
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35
687
     MPM.add(new DataLayoutPass(DL));
688
 #else
689
     MPM.add(new DataLayout(DL));
690
 #endif
691
 
692
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
693
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
694
     MPM.add(new TargetLibraryInfoWrapperPass(*libraryInfo));
695
 #else
696
     MPM.add(new TargetLibraryInfo(*libraryInfo));
697
 #endif
698
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
699
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
700
     MPM.add(createTypeBasedAAWrapperPass());
701
     MPM.add(createBasicAAWrapperPass());
702
 #else
703
@@ -149,9 +149,9 @@ namespace gbe
704
     MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
705
     MPM.add(createCFGSimplificationPass());   // Clean up after IPCP & DAE
706
     MPM.add(createPruneEHPass());             // Remove dead EH info
707
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
708
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
709
     MPM.add(createPostOrderFunctionAttrsLegacyPass());
710
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
711
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
712
     MPM.add(createPostOrderFunctionAttrsPass());       // Set readonly/readnone attrs
713
 #else
714
     MPM.add(createFunctionAttrsPass());       // Set readonly/readnone attrs
715
@@ -159,7 +159,7 @@ namespace gbe
716
 
717
     //MPM.add(createScalarReplAggregatesPass(64, true, -1, -1, 64))
718
     if(optLevel > 0)
719
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
720
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
721
       MPM.add(createSROAPass());
722
 #else
723
       MPM.add(createSROAPass(/*RequiresDomTree*/ false));
724
@@ -182,14 +182,14 @@ namespace gbe
725
     MPM.add(createLoopDeletionPass());          // Delete dead loops
726
     MPM.add(createLoopUnrollPass(640)); //1024, 32, 1024, 512)); //Unroll loops
727
     if(optLevel > 0) {
728
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
729
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
730
       MPM.add(createSROAPass());
731
 #else
732
       MPM.add(createSROAPass(/*RequiresDomTree*/ false));
733
 #endif
734
       MPM.add(createGVNPass());                 // Remove redundancies
735
     }
736
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
737
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
738
     // FIXME Workaround: we find that CustomLoopUnroll may increase register pressure greatly,
739
     // and it may even make som cl kernel cannot compile because of limited scratch memory for spill.
740
     // As we observe this under strict math. So we disable CustomLoopUnroll if strict math is enabled.
741
@@ -199,7 +199,7 @@ namespace gbe
742
 #endif
743
       MPM.add(createLoopUnrollPass()); //1024, 32, 1024, 512)); //Unroll loops
744
       if(optLevel > 0) {
745
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
746
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
747
         MPM.add(createSROAPass());
748
 #else
749
         MPM.add(createSROAPass(/*RequiresDomTree*/ false));
750
@@ -230,7 +230,7 @@ namespace gbe
751
   }
752
 
753
 
754
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
755
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
756
 #define OUTPUT_BITCODE(STAGE, MOD)  do {         \
757
   legacy::PassManager passes__;           \
758
    if (OCL_OUTPUT_LLVM_##STAGE) {                \
759
@@ -238,7 +238,7 @@ namespace gbe
760
      passes__.run(MOD);                          \
761
    }                                             \
762
  }while(0)
763
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
764
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
765
 #define OUTPUT_BITCODE(STAGE, MOD)  do {         \
766
    PassManager passes__;           \
767
    if (OCL_OUTPUT_LLVM_##STAGE) {                \
768
@@ -303,12 +303,12 @@ namespace gbe
769
     if (module) {
770
       cl_mod = reinterpret_cast<Module*>(const_cast<void*>(module));
771
     } else if (fileName){
772
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
773
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
774
       llvm::LLVMContext& c = GBEGetLLVMContext();
775
 #else
776
       llvm::LLVMContext& c = llvm::getGlobalContext();
777
 #endif
778
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
779
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
780
       cl_mod = parseIRFile(fileName, Err, c).release();
781
 #else
782
       cl_mod = ParseIRFile(fileName, Err, c);
783
@@ -318,7 +318,7 @@ namespace gbe
784
     if (!cl_mod) return false;
785
 
786
     OUTPUT_BITCODE(BEFORE_LINK, (*cl_mod));
787
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
788
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
789
     legacy::PassManager passes__;
790
 #else
791
     PassManager passes__;
792
@@ -346,7 +346,7 @@ namespace gbe
793
     gbeDiagnosticContext dc;
794
     mod.getContext().setDiagnosticHandler(&gbeDiagnosticHandler,&dc);
795
 
796
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
797
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
798
     mod.setDataLayout(DL);
799
 #endif
800
     Triple TargetTriple(mod.getTargetTriple());
801
@@ -357,15 +357,15 @@ namespace gbe
802
 
803
     runFuntionPass(mod, libraryInfo, DL);
804
     runModulePass(mod, libraryInfo, DL, optLevel, strictMath);
805
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
806
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
807
     legacy::PassManager passes;
808
 #else
809
     PassManager passes;
810
 #endif
811
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
812
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
813
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
814
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
815
     passes.add(new DataLayoutPass());
816
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
817
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35
818
     passes.add(new DataLayoutPass(DL));
819
 #else
820
     passes.add(new DataLayout(DL));
821
@@ -374,7 +374,7 @@ namespace gbe
822
     passes.add(createIntrinsicLoweringPass());
823
     passes.add(createStripAttributesPass());     // Strip unsupported attributes and calling conventions.
824
     passes.add(createFunctionInliningPass(20000));
825
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
826
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
827
     passes.add(createSROAPass());
828
 #else
829
     passes.add(createScalarReplAggregatesPass(64, true, -1, -1, 64));
830
diff --git a/backend/src/llvm/llvm_to_gen.hpp b/backend/src/llvm/llvm_to_gen.hpp
831
index d3928c6..9025852 100644
832
--- a/backend/src/llvm/llvm_to_gen.hpp
833
+++ b/backend/src/llvm/llvm_to_gen.hpp
834
@@ -23,7 +23,7 @@
835
  */
836
 #ifndef __GBE_IR_LLVM_TO_GEN_HPP__
837
 #define __GBE_IR_LLVM_TO_GEN_HPP__
838
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
839
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
840
 #include "llvm/IR/LLVMContext.h"
841
 #endif
842
 
843
@@ -37,7 +37,7 @@ namespace gbe {
844
 		  optLevel 0 equal to clang -O1 and 1 equal to clang -O2*/
845
   bool llvmToGen(ir::Unit &unit, const char *fileName, const void* module,
846
                  int optLevel, bool strictMath, int profiling, std::string &errors);
847
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
848
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
849
   extern llvm::LLVMContext& GBEGetLLVMContext();
850
 #endif
851
 
852
diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp
853
index e24dc4f..bfd3bbe 100644
854
--- a/backend/src/llvm/llvm_unroll.cpp
855
+++ b/backend/src/llvm/llvm_unroll.cpp
856
@@ -16,7 +16,7 @@
857
  */
858
 
859
 #include "llvm/Config/llvm-config.h"
860
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
861
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
862
 #include <set>
863
 
864
 #include "llvm_includes.hpp"
865
@@ -36,7 +36,7 @@ namespace gbe {
866
        LoopPass(ID) {}
867
 
868
       void getAnalysisUsage(AnalysisUsage &AU) const {
869
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 7)
870
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
871
         AU.addRequired<LoopInfoWrapperPass>();
872
         AU.addPreserved<LoopInfoWrapperPass>();
873
 #else
874
@@ -47,7 +47,7 @@ namespace gbe {
875
         AU.addPreservedID(LoopSimplifyID);
876
         AU.addRequiredID(LCSSAID);
877
         AU.addPreservedID(LCSSAID);
878
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
879
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
880
         AU.addRequired<ScalarEvolutionWrapperPass>();
881
         AU.addPreserved<ScalarEvolutionWrapperPass>();
882
 #else
883
@@ -91,7 +91,7 @@ namespace gbe {
884
           assert(MD->getNumOperands() == 2 &&
885
                  "Unroll count hint metadata should have two operands.");
886
           unsigned Count;
887
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
888
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
889
           Count = mdconst::extract<ConstantInt>(MD->getOperand(1))->getZExtValue();
890
 #else
891
           Count = cast<ConstantInt>(MD->getOperand(1))->getZExtValue();
892
@@ -105,7 +105,7 @@ namespace gbe {
893
       void setUnrollID(Loop *L, bool enable) {
894
         assert(enable);
895
         LLVMContext &Context = L->getHeader()->getContext();
896
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
897
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
898
         SmallVector<Metadata *, 2> forceUnroll;
899
         forceUnroll.push_back(MDString::get(Context, "llvm.loop.unroll.enable"));
900
         MDNode *forceUnrollNode = MDNode::get(Context, forceUnroll);
901
@@ -169,7 +169,7 @@ namespace gbe {
902
       // be unrolled.
903
       bool handleParentLoops(Loop *L, LPPassManager &LPM) {
904
         Loop *currL = L;
905
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
906
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
907
         ScalarEvolution *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
908
         LoopInfo &loopInfo = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
909
 #else
910
@@ -205,7 +205,7 @@ namespace gbe {
911
           if (parentTripCount != 0 && currTripCount * parentTripCount > 32) {
912
             //Don't change the unrollID if doesn't force unroll.
913
             //setUnrollID(parentL, false);
914
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
915
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
916
             loopInfo.markAsRemoved(parentL);
917
 #else
918
             LPM.deleteLoopFromQueue(parentL);
919
-- 
920
cgit v0.10.2
921
(-)lang/beignet/files/extra-patch-refine_llvm_version_check.orig (+921 lines)
Line 0 Link Here
1
From f40ed02f7de65296219a0a160118ae3234e765c5 Mon Sep 17 00:00:00 2001
2
From: Pan Xiuli <xiuli.pan@intel.com>
3
Date: Fri, 17 Mar 2017 14:16:01 +0800
4
Subject: Backend: Refine LLVM version check macro
5
6
LLVM 4.0 is coming, we should refine our version check to fit the
7
LLVM_MAJOR_VERSION bump to 4.
8
9
Signed-off-by: Pan Xiuli <xiuli.pan@intel.com>
10
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
11
12
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
13
index 376342b..998e340 100644
14
--- a/backend/src/backend/gen_program.cpp
15
+++ b/backend/src/backend/gen_program.cpp
16
@@ -329,13 +329,13 @@ namespace gbe {
17
     //the first byte stands for binary_type.
18
     binary_content.assign(binary+1, size-1);
19
     llvm::StringRef llvm_bin_str(binary_content);
20
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
21
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
22
     llvm::LLVMContext& c = GBEGetLLVMContext();
23
 #else
24
     llvm::LLVMContext& c = llvm::getGlobalContext();
25
 #endif
26
     llvm::SMDiagnostic Err;
27
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
28
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
29
     std::unique_ptr<llvm::MemoryBuffer> memory_buffer = llvm::MemoryBuffer::getMemBuffer(llvm_bin_str, "llvm_bin_str");
30
     acquireLLVMContextLock();
31
     llvm::Module* module = llvm::parseIR(memory_buffer->getMemBufferRef(), Err, c).release();
32
@@ -482,14 +482,14 @@ namespace gbe {
33
     using namespace gbe;
34
     char* errMsg;
35
     if(((GenProgram*)dst_program)->module == NULL){
36
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
37
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
38
       ((GenProgram*)dst_program)->module = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module).release();
39
 #else
40
       ((GenProgram*)dst_program)->module = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module);
41
 #endif
42
       errSize = 0;
43
     }else{
44
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
45
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
46
       // Src now will be removed automatically. So clone it.
47
       llvm::Module* src = llvm::CloneModule((llvm::Module*)((GenProgram*)src_program)->module).release();
48
 #else
49
@@ -497,9 +497,9 @@ namespace gbe {
50
 #endif
51
       llvm::Module* dst = (llvm::Module*)((GenProgram*)dst_program)->module;
52
 
53
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
54
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
55
       if (LLVMLinkModules2(wrap(dst), wrap(src))) {
56
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
57
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
58
       if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource_Removed, &errMsg)) {
59
 #else
60
       if (LLVMLinkModules(wrap(dst), wrap(src), LLVMLinkerPreserveSource, &errMsg)) {
61
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
62
index 6b5fce0..6e8227a 100644
63
--- a/backend/src/backend/program.cpp
64
+++ b/backend/src/backend/program.cpp
65
@@ -115,7 +115,7 @@ namespace gbe {
66
     llvm::Module * cloned_module = NULL;
67
     bool ret = false;
68
     if(module){
69
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
70
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
71
       cloned_module = llvm::CloneModule((llvm::Module*)module).release();
72
 #else
73
       cloned_module = llvm::CloneModule((llvm::Module*)module);
74
@@ -124,7 +124,7 @@ namespace gbe {
75
     bool strictMath = true;
76
     if (fast_relaxed_math || !OCL_STRICT_CONFORMANCE)
77
       strictMath = false;
78
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
79
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
80
     llvm::Module * linked_module = module ? llvm::CloneModule((llvm::Module*)module).release() : NULL;
81
     // Src now will be removed automatically. So clone it.
82
     if (llvmToGen(*unit, fileName, linked_module, optLevel, strictMath, OCL_PROFILING_LOG, error) == false) {
83
@@ -651,7 +651,7 @@ namespace gbe {
84
     // The ParseCommandLineOptions used for mllvm args can not be used with multithread
85
     // and GVN now have a 100 inst limit on block scan. Now only pass a bigger limit
86
     // for each context only once, this can also fix multithread bug.
87
-#if LLVM_VERSION_MINOR >= 8
88
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
89
     static bool ifsetllvm = false;
90
     if(!ifsetllvm) {
91
       args.push_back("-mllvm");
92
@@ -702,7 +702,7 @@ namespace gbe {
93
                                               Diags);
94
     llvm::StringRef srcString(source);
95
     (*CI).getPreprocessorOpts().addRemappedFile("stringInput.cl",
96
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
97
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
98
                 llvm::MemoryBuffer::getMemBuffer(srcString)
99
 #else
100
                 llvm::MemoryBuffer::getMemBuffer(srcString).release()
101
@@ -755,7 +755,7 @@ namespace gbe {
102
     if (!retVal)
103
       return false;
104
 
105
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
106
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
107
     llvm::Module *module = Act->takeModule();
108
 #else
109
     llvm::Module *module = Act->takeModule().release();
110
@@ -764,7 +764,7 @@ namespace gbe {
111
     *out_module = module;
112
 
113
 // Dump the LLVM if requested.
114
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 6)
115
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 36
116
     if (!dumpLLVMFileName.empty()) {
117
       std::string err;
118
       llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
119
@@ -1123,7 +1123,7 @@ EXTEND_QUOTE:
120
     //FIXME: if use new allocated context to link two modules there would be context mismatch
121
     //for some functions, so we use global context now, need switch to new context later.
122
     llvm::Module * out_module;
123
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
124
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
125
     llvm::LLVMContext* llvm_ctx = &GBEGetLLVMContext();
126
 #else
127
     llvm::LLVMContext* llvm_ctx = &llvm::getGlobalContext();
128
@@ -1599,7 +1599,7 @@ namespace gbe
129
     }
130
 
131
     ~CallBackInitializer() {
132
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR > 3)
133
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 34
134
       llvm::llvm_shutdown();
135
 #endif
136
     }
137
diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp
138
index 5fcb14a..64d9727 100644
139
--- a/backend/src/ir/function.hpp
140
+++ b/backend/src/ir/function.hpp
141
@@ -186,7 +186,7 @@ namespace ir {
142
 
143
 
144
       // only llvm-3.6 or later has kernel_arg_base_type in metadata.
145
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR <= 5)
146
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
147
       bool isImage1dT() const {
148
         return typeName.compare("image1d_t") == 0;
149
       }
150
diff --git a/backend/src/llvm/ExpandLargeIntegers.cpp b/backend/src/llvm/ExpandLargeIntegers.cpp
151
index 60740f5..8515dc1 100644
152
--- a/backend/src/llvm/ExpandLargeIntegers.cpp
153
+++ b/backend/src/llvm/ExpandLargeIntegers.cpp
154
@@ -93,7 +93,7 @@
155
 
156
 using namespace llvm;
157
 
158
-#if LLVM_VERSION_MINOR >= 5
159
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
160
 #define DEBUG_TYPE "nacl-expand-ints"
161
 #endif
162
 
163
@@ -766,7 +766,7 @@ static void convertInstruction(Instruction *Inst, ConversionState &State,
164
 bool ExpandLargeIntegers::runOnFunction(Function &F) {
165
   // Don't support changing the function arguments. Illegal function arguments
166
   // should not be generated by clang.
167
-#if LLVM_VERSION_MINOR >= 5
168
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
169
   for (const Argument &Arg : F.args())
170
 #else
171
   for (const Argument &Arg : F.getArgumentList())
172
@@ -789,7 +789,7 @@ bool ExpandLargeIntegers::runOnFunction(Function &F) {
173
       // Only attempt to convert an instruction if its result or any of its
174
       // operands are illegal.
175
       bool ShouldConvert = shouldConvert(&I);
176
-#if LLVM_VERSION_MINOR >= 5
177
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
178
       for (Value *Op : I.operands())
179
         ShouldConvert |= shouldConvert(Op);
180
 #else
181
diff --git a/backend/src/llvm/llvm_bitcode_link.cpp b/backend/src/llvm/llvm_bitcode_link.cpp
182
index 89d5e7c..869db89 100644
183
--- a/backend/src/llvm/llvm_bitcode_link.cpp
184
+++ b/backend/src/llvm/llvm_bitcode_link.cpp
185
@@ -60,7 +60,7 @@ namespace gbe
186
       return NULL;
187
     }
188
 
189
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
190
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
191
     oclLib = getLazyIRFileModule(FilePath, Err, ctx);
192
 #else
193
     oclLib = getLazyIRFileModule(FilePath, Err, ctx).release();
194
@@ -117,7 +117,7 @@ namespace gbe
195
 
196
         std::string ErrInfo;// = "Not Materializable";
197
         if (!fromSrc && newMF->isMaterializable()) {
198
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
199
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
200
           if (newMF->Materialize(&ErrInfo)) {
201
             printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
202
             return false;
203
@@ -250,7 +250,7 @@ namespace gbe
204
       }
205
       std::string ErrInfo;// = "Not Materializable";
206
       if (newMF->isMaterializable()) {
207
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
208
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
209
         if (newMF->Materialize(&ErrInfo)) {
210
           printf("Can not materialize the function: %s, because %s\n", fnName.c_str(), ErrInfo.c_str());
211
           delete clonedLib;
212
@@ -287,7 +287,7 @@ namespace gbe
213
    * pass to extract the functions and values in Gvs from the library module.
214
    * After extract what we need and remove what we do not need, we use 
215
    * materializeAll to mark the module as materialized. */
216
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=8
217
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
218
     /* Get all GlobalValue from module. */
219
     Module::GlobalListType &GVlist = clonedLib->getGlobalList();
220
     for(Module::global_iterator GVitr = GVlist.begin();GVitr != GVlist.end();++GVitr) {
221
@@ -310,7 +310,7 @@ namespace gbe
222
     /* We use beignet's bitcode as dst because it will have a lot of
223
        lazy functions which will not be loaded. */
224
     char* errorMsg;
225
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
226
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
227
     if(LLVMLinkModules2(wrap(clonedLib), wrap(mod))) {
228
 #else
229
     if(LLVMLinkModules(wrap(clonedLib), wrap(mod), LLVMLinkerDestroySource, &errorMsg)) {
230
@@ -319,13 +319,13 @@ namespace gbe
231
       printf("Fatal Error: link the bitcode error:\n%s\n", errorMsg);
232
       return NULL;
233
     }
234
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
235
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
236
     llvm::legacy::PassManager passes;
237
 #else
238
     llvm::PassManager passes;
239
 #endif
240
 
241
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=9
242
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
243
     auto PreserveKernel = [=](const GlobalValue &GV) {
244
       for(size_t i = 0;i < kernels.size(); ++i)
245
         if(strcmp(GV.getName().data(), kernels[i]))
246
diff --git a/backend/src/llvm/llvm_device_enqueue.cpp b/backend/src/llvm/llvm_device_enqueue.cpp
247
index ee236de..9a0fb46 100644
248
--- a/backend/src/llvm/llvm_device_enqueue.cpp
249
+++ b/backend/src/llvm/llvm_device_enqueue.cpp
250
@@ -62,7 +62,7 @@ namespace gbe {
251
       for (Value::use_iterator iter = v->use_begin(); iter != v->use_end(); ++iter) {
252
         // After LLVM 3.5, use_iterator points to 'Use' instead of 'User',
253
         // which is more straightforward.
254
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
255
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
256
         User *theUser = *iter;
257
 #else
258
         User *theUser = iter->getUser();
259
@@ -84,7 +84,7 @@ namespace gbe {
260
 
261
   Function* setFunctionAsKernel(Module *mod, Function *Fn)
262
   {
263
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 9)
264
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
265
     LLVMContext &Context = mod->getContext();
266
     Type *intTy = IntegerType::get(mod->getContext(), 32);
267
     SmallVector<llvm::Metadata *, 5> kernelMDArgs;
268
@@ -210,7 +210,7 @@ namespace gbe {
269
           }
270
 
271
           for (Value::use_iterator iter = bt->use_begin(); iter != bt->use_end(); ++iter) {
272
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
273
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
274
             User *theUser = *iter;
275
 #else
276
             User *theUser = iter->getUser();
277
@@ -298,7 +298,7 @@ namespace gbe {
278
             if(AllocaInst *ai = dyn_cast<AllocaInst>(ld->getPointerOperand())) {
279
               Value *v = NULL;
280
               for (Value::use_iterator iter = ai->use_begin(); iter != ai->use_end(); ++iter) {
281
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
282
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
283
                 User *theUser = *iter;
284
 #else
285
                 User *theUser = iter->getUser();
286
@@ -347,7 +347,7 @@ namespace gbe {
287
             if(ld) {
288
               Value *block = ld->getPointerOperand();
289
               for (Value::use_iterator iter = block->use_begin(); iter != block->use_end(); ++iter) {
290
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
291
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
292
                 User *theUser = *iter;
293
 #else
294
                 User *theUser = iter->getUser();
295
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
296
index 742c947..4621f6d 100644
297
--- a/backend/src/llvm/llvm_gen_backend.cpp
298
+++ b/backend/src/llvm/llvm_gen_backend.cpp
299
@@ -95,9 +95,9 @@
300
 #define LLVM_VERSION_MINOR 0
301
 #endif /* !defined(LLVM_VERSION_MINOR) */
302
 
303
-#if (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR < 3)
304
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 33
305
 #error "Only LLVM 3.3 and newer are supported"
306
-#endif /* (LLVM_VERSION_MAJOR != 3) || (LLVM_VERSION_MINOR > 4) */
307
+#endif
308
 
309
 using namespace llvm;
310
 
311
@@ -565,7 +565,7 @@ namespace gbe
312
         has_errors(false),
313
         legacyMode(true)
314
     {
315
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
316
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
317
       initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry());
318
 #else
319
       initializeLoopInfoPass(*PassRegistry::getPassRegistry());
320
@@ -576,7 +576,7 @@ namespace gbe
321
     virtual const char *getPassName() const { return "Gen Back-End"; }
322
 
323
     void getAnalysisUsage(AnalysisUsage &AU) const {
324
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
325
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
326
       AU.addRequired<LoopInfoWrapperPass>();
327
 #else
328
       AU.addRequired<LoopInfo>();
329
@@ -611,7 +611,7 @@ namespace gbe
330
       if (legacyMode)
331
         analyzePointerOrigin(F);
332
 
333
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
334
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
335
       LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
336
 #else
337
       LI = &getAnalysis<LoopInfo>();
338
@@ -835,7 +835,7 @@ namespace gbe
339
       for (Value::use_iterator iter = work->use_begin(); iter != work->use_end(); ++iter) {
340
       // After LLVM 3.5, use_iterator points to 'Use' instead of 'User',
341
       // which is more straightforward.
342
-  #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
343
+  #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
344
         User *theUser = *iter;
345
   #else
346
         User *theUser = iter->getUser();
347
@@ -1089,7 +1089,7 @@ namespace gbe
348
             if (predBB->getTerminator())
349
               Builder2.SetInsertPoint(predBB->getTerminator());
350
 
351
-#if (LLVM_VERSION_MAJOR== 3 && LLVM_VERSION_MINOR < 6)
352
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 36
353
   // llvm 3.5 and older version don't have CreateBitOrPointerCast() define
354
             Type *srcTy = base->getType();
355
             Type *dstTy = ptr->getType();
356
@@ -1248,7 +1248,7 @@ namespace gbe
357
      uint32_t ops = clKernels->getNumOperands();
358
       for(uint32_t x = 0; x < ops; x++) {
359
         MDNode* node = clKernels->getOperand(x);
360
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
361
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
362
         Value * op = node->getOperand(0);
363
 #else
364
         auto *V = cast<ValueAsMetadata>(node->getOperand(0));
365
@@ -1272,7 +1272,7 @@ namespace gbe
366
     MDNode *typeNameNode = NULL;
367
     MDNode *typeBaseNameNode = NULL;
368
     MDNode *typeQualNode = NULL;
369
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
370
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
371
     typeNameNode = F.getMetadata("kernel_arg_type");
372
     typeBaseNameNode = F.getMetadata("kernel_arg_base_type");
373
     typeQualNode = F.getMetadata("kernel_arg_type_qual");
374
@@ -1298,7 +1298,7 @@ namespace gbe
375
     ir::FunctionArgument::InfoFromLLVM llvmInfo;
376
     for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I, argID++) {
377
       unsigned opID = argID;
378
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9
379
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 39
380
       opID += 1;
381
 #endif
382
 
383
@@ -1340,7 +1340,7 @@ namespace gbe
384
       for (Value::use_iterator iter = work->use_begin(); iter != work->use_end(); ++iter) {
385
       // After LLVM 3.5, use_iterator points to 'Use' instead of 'User',
386
       // which is more straightforward.
387
-  #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
388
+  #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
389
         User *theUser = *iter;
390
   #else
391
         User *theUser = iter->getUser();
392
@@ -2120,7 +2120,7 @@ namespace gbe
393
 
394
     std::string functionAttributes;
395
 
396
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
397
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
398
     /* LLVM 3.9 change kernel arg info as function metadata */
399
     addrSpaceNode = F.getMetadata("kernel_arg_addr_space");
400
     accessQualNode = F.getMetadata("kernel_arg_access_qual");
401
@@ -2222,7 +2222,7 @@ namespace gbe
402
 
403
       if (attrName->getString() == "reqd_work_group_size") {
404
         GBE_ASSERT(attrNode->getNumOperands() == 4);
405
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
406
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
407
         ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1));
408
         ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2));
409
         ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3));
410
@@ -2264,13 +2264,13 @@ namespace gbe
411
       } else if (attrName->getString() == "vec_type_hint") {
412
         GBE_ASSERT(attrNode->getNumOperands() == 3);
413
         functionAttributes += attrName->getString();
414
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
415
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
416
         Value* V = attrNode->getOperand(1);
417
 #else
418
         auto *Op1 = cast<ValueAsMetadata>(attrNode->getOperand(1));
419
         Value *V = Op1 ? Op1->getValue() : NULL;
420
 #endif
421
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
422
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
423
         ConstantInt *sign = dyn_cast<ConstantInt>(attrNode->getOperand(2));
424
 #else
425
         ConstantInt *sign = mdconst::extract<ConstantInt>(attrNode->getOperand(2));
426
@@ -2299,7 +2299,7 @@ namespace gbe
427
         functionAttributes += " ";
428
       } else if (attrName->getString() == "work_group_size_hint") {
429
         GBE_ASSERT(attrNode->getNumOperands() == 4);
430
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
431
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
432
         ConstantInt *x = dyn_cast<ConstantInt>(attrNode->getOperand(1));
433
         ConstantInt *y = dyn_cast<ConstantInt>(attrNode->getOperand(2));
434
         ConstantInt *z = dyn_cast<ConstantInt>(attrNode->getOperand(3));
435
@@ -2341,13 +2341,13 @@ namespace gbe
436
       // Insert a new register for each function argument
437
       for (; I != E; ++I, ++argID) {
438
         uint32_t opID = argID;
439
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9
440
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 39
441
         opID += 1;
442
 #endif
443
         const std::string &argName = I->getName().str();
444
         Type *type = I->getType();
445
         if(addrSpaceNode) {
446
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
447
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
448
           llvmInfo.addrSpace = (cast<ConstantInt>(addrSpaceNode->getOperand(opID)))->getZExtValue();
449
 #else
450
           llvmInfo.addrSpace = (mdconst::extract<ConstantInt>(addrSpaceNode->getOperand(opID)))->getZExtValue();
451
@@ -2914,7 +2914,7 @@ namespace gbe
452
     const Instruction *insn = NULL;
453
     for(Value::const_use_iterator iter = v->use_begin(); iter != v->use_end(); ++iter) {
454
     // After LLVM 3.5, use_iterator points to 'Use' instead of 'User', which is more straightforward.
455
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR < 5)
456
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR < 35
457
       const User *theUser = *iter;
458
 #else
459
       const User *theUser = iter->getUser();
460
diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp
461
index f1c791e..2a322ac 100644
462
--- a/backend/src/llvm/llvm_gen_backend.hpp
463
+++ b/backend/src/llvm/llvm_gen_backend.hpp
464
@@ -149,7 +149,7 @@ namespace gbe
465
   /*! Insert the time stamp for profiling. */
466
   llvm::FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit &unit);
467
 
468
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
469
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
470
   /* customized loop unrolling pass. */
471
   llvm::LoopPass *createCustomLoopUnrollPass();
472
 #endif
473
diff --git a/backend/src/llvm/llvm_includes.hpp b/backend/src/llvm/llvm_includes.hpp
474
index 0b80979..a242fd3 100644
475
--- a/backend/src/llvm/llvm_includes.hpp
476
+++ b/backend/src/llvm/llvm_includes.hpp
477
@@ -91,7 +91,7 @@
478
 #include "llvm/MC/MCSubtargetInfo.h"
479
 #include "llvm/MC/MCSymbol.h"
480
 
481
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5
482
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
483
 #include "llvm/IR/Mangler.h"
484
 #include "llvm/IR/CallSite.h"
485
 #include "llvm/IR/CFG.h"
486
@@ -111,7 +111,7 @@
487
 #include "llvm/Target/Mangler.h"
488
 #endif
489
 
490
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=7
491
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
492
 #include "llvm/Analysis/TargetLibraryInfo.h"
493
 #include "llvm/IR/LegacyPassManager.h"
494
 #else
495
@@ -122,12 +122,12 @@
496
 
497
 #include <clang/CodeGen/CodeGenAction.h>
498
 
499
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=8
500
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
501
 #include "llvm/Analysis/BasicAliasAnalysis.h"
502
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
503
 #endif
504
 
505
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
506
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
507
 #include "llvm/Transforms/IPO/FunctionAttrs.h"
508
 #include "llvm/Transforms/Scalar/GVN.h"
509
 #endif
510
diff --git a/backend/src/llvm/llvm_loadstore_optimization.cpp b/backend/src/llvm/llvm_loadstore_optimization.cpp
511
index e797e98..4f4639c 100644
512
--- a/backend/src/llvm/llvm_loadstore_optimization.cpp
513
+++ b/backend/src/llvm/llvm_loadstore_optimization.cpp
514
@@ -35,7 +35,7 @@ namespace gbe {
515
     GenLoadStoreOptimization() : BasicBlockPass(ID) {}
516
 
517
     void getAnalysisUsage(AnalysisUsage &AU) const {
518
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
519
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
520
       AU.addRequired<ScalarEvolutionWrapperPass>();
521
       AU.addPreserved<ScalarEvolutionWrapperPass>();
522
 #else
523
@@ -46,12 +46,12 @@ namespace gbe {
524
     }
525
 
526
     virtual bool runOnBasicBlock(BasicBlock &BB) {
527
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
528
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
529
       SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
530
 #else
531
       SE = &getAnalysis<ScalarEvolution>();
532
 #endif
533
-      #if LLVM_VERSION_MINOR >= 7
534
+      #if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
535
         TD = &BB.getModule()->getDataLayout();
536
       #elif LLVM_VERSION_MINOR >= 5
537
         DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
538
diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp
539
index 8f5bcc9..f414fbb 100644
540
--- a/backend/src/llvm/llvm_passes.cpp
541
+++ b/backend/src/llvm/llvm_passes.cpp
542
@@ -42,7 +42,7 @@ namespace gbe
543
 {
544
   bool isKernelFunction(const llvm::Function &F) {
545
     bool bKernel = false;
546
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
547
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
548
     bKernel = F.getMetadata("kernel_arg_name") != NULL;
549
 #else
550
     const Module *module = F.getParent();
551
@@ -53,7 +53,7 @@ namespace gbe
552
       uint32_t ops = md.getNumOperands();
553
       for(uint32_t x = 0; x < ops; x++) {
554
         MDNode* node = md.getOperand(x);
555
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 5
556
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR <= 35
557
         Value * op = node->getOperand(0);
558
 #else
559
         Value * op = cast<ValueAsMetadata>(node->getOperand(0))->getValue();
560
@@ -74,7 +74,7 @@ namespace gbe
561
     if(ops > 0) {
562
       uint32_t major = 0, minor = 0;
563
       MDNode* node = version->getOperand(0);
564
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
565
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
566
       major = mdconst::extract<ConstantInt>(node->getOperand(0))->getZExtValue();
567
       minor = mdconst::extract<ConstantInt>(node->getOperand(1))->getZExtValue();
568
 #else
569
diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp
570
index 734c69d..bc16951 100644
571
--- a/backend/src/llvm/llvm_profiling.cpp
572
+++ b/backend/src/llvm/llvm_profiling.cpp
573
@@ -34,7 +34,7 @@
574
 #include "llvm/Pass.h"
575
 #include "llvm/IR/IRBuilder.h"
576
 
577
-#if LLVM_VERSION_MINOR >= 5
578
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
579
 #include "llvm/IR/CallSite.h"
580
 #include "llvm/IR/CFG.h"
581
 #else
582
diff --git a/backend/src/llvm/llvm_sampler_fix.cpp b/backend/src/llvm/llvm_sampler_fix.cpp
583
index de7ebdb..2e8bcf9 100644
584
--- a/backend/src/llvm/llvm_sampler_fix.cpp
585
+++ b/backend/src/llvm/llvm_sampler_fix.cpp
586
@@ -33,7 +33,7 @@ namespace gbe {
587
   class SamplerFix : public FunctionPass {
588
   public:
589
     SamplerFix() : FunctionPass(ID) {
590
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
591
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
592
       initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
593
 #else
594
       initializeDominatorTreePass(*PassRegistry::getPassRegistry());
595
diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp
596
index 329e3a9..be3d549 100644
597
--- a/backend/src/llvm/llvm_scalarize.cpp
598
+++ b/backend/src/llvm/llvm_scalarize.cpp
599
@@ -96,7 +96,7 @@ namespace gbe {
600
 
601
     Scalarize() : FunctionPass(ID)
602
     {
603
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
604
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
605
       initializeDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
606
 #else
607
       initializeDominatorTreePass(*PassRegistry::getPassRegistry());
608
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
609
index bef4df1..9b3b1f4 100644
610
--- a/backend/src/llvm/llvm_to_gen.cpp
611
+++ b/backend/src/llvm/llvm_to_gen.cpp
612
@@ -46,14 +46,14 @@ namespace gbe
613
   BVAR(OCL_OUTPUT_CFG_GEN_IR, false);
614
   using namespace llvm;
615
 
616
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
617
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
618
   llvm::LLVMContext& GBEGetLLVMContext() {
619
     static llvm::LLVMContext GBEContext;
620
     return GBEContext;
621
   }
622
 #endif
623
 
624
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
625
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
626
   #define TARGETLIBRARY  TargetLibraryInfoImpl
627
 #else
628
   #define TARGETLIBRARY  TargetLibraryInfo
629
@@ -61,32 +61,32 @@ namespace gbe
630
 
631
   void runFuntionPass(Module &mod, TARGETLIBRARY *libraryInfo, const DataLayout &DL)
632
   {
633
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
634
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
635
     legacy::FunctionPassManager FPM(&mod);
636
 #else
637
     FunctionPassManager FPM(&mod);
638
 #endif
639
 
640
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
641
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
642
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
643
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
644
     FPM.add(new DataLayoutPass());
645
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
646
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35
647
     FPM.add(new DataLayoutPass(DL));
648
 #else
649
     FPM.add(new DataLayout(DL));
650
 #endif
651
 
652
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >=5
653
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
654
     FPM.add(createVerifierPass(true));
655
 #else
656
     FPM.add(createVerifierPass());
657
 #endif
658
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
659
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
660
     FPM.add(new TargetLibraryInfoWrapperPass(*libraryInfo));
661
 #else
662
     FPM.add(new TargetLibraryInfo(*libraryInfo));
663
 #endif
664
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
665
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
666
     FPM.add(createTypeBasedAAWrapperPass());
667
     FPM.add(createBasicAAWrapperPass());
668
 #else
669
@@ -108,27 +108,27 @@ namespace gbe
670
 
671
   void runModulePass(Module &mod, TARGETLIBRARY *libraryInfo, const DataLayout &DL, int optLevel, bool strictMath)
672
   {
673
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
674
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
675
     legacy::PassManager MPM;
676
 #else
677
     PassManager MPM;
678
 #endif
679
 
680
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
681
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
682
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
683
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
684
     MPM.add(new DataLayoutPass());
685
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
686
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35
687
     MPM.add(new DataLayoutPass(DL));
688
 #else
689
     MPM.add(new DataLayout(DL));
690
 #endif
691
 
692
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
693
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
694
     MPM.add(new TargetLibraryInfoWrapperPass(*libraryInfo));
695
 #else
696
     MPM.add(new TargetLibraryInfo(*libraryInfo));
697
 #endif
698
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
699
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
700
     MPM.add(createTypeBasedAAWrapperPass());
701
     MPM.add(createBasicAAWrapperPass());
702
 #else
703
@@ -149,9 +149,9 @@ namespace gbe
704
     MPM.add(createInstructionCombiningPass());// Clean up after IPCP & DAE
705
     MPM.add(createCFGSimplificationPass());   // Clean up after IPCP & DAE
706
     MPM.add(createPruneEHPass());             // Remove dead EH info
707
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
708
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
709
     MPM.add(createPostOrderFunctionAttrsLegacyPass());
710
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
711
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
712
     MPM.add(createPostOrderFunctionAttrsPass());       // Set readonly/readnone attrs
713
 #else
714
     MPM.add(createFunctionAttrsPass());       // Set readonly/readnone attrs
715
@@ -159,7 +159,7 @@ namespace gbe
716
 
717
     //MPM.add(createScalarReplAggregatesPass(64, true, -1, -1, 64))
718
     if(optLevel > 0)
719
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
720
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
721
       MPM.add(createSROAPass());
722
 #else
723
       MPM.add(createSROAPass(/*RequiresDomTree*/ false));
724
@@ -182,14 +182,14 @@ namespace gbe
725
     MPM.add(createLoopDeletionPass());          // Delete dead loops
726
     MPM.add(createLoopUnrollPass(640)); //1024, 32, 1024, 512)); //Unroll loops
727
     if(optLevel > 0) {
728
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
729
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
730
       MPM.add(createSROAPass());
731
 #else
732
       MPM.add(createSROAPass(/*RequiresDomTree*/ false));
733
 #endif
734
       MPM.add(createGVNPass());                 // Remove redundancies
735
     }
736
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
737
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
738
     // FIXME Workaround: we find that CustomLoopUnroll may increase register pressure greatly,
739
     // and it may even make som cl kernel cannot compile because of limited scratch memory for spill.
740
     // As we observe this under strict math. So we disable CustomLoopUnroll if strict math is enabled.
741
@@ -199,7 +199,7 @@ namespace gbe
742
 #endif
743
       MPM.add(createLoopUnrollPass()); //1024, 32, 1024, 512)); //Unroll loops
744
       if(optLevel > 0) {
745
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
746
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
747
         MPM.add(createSROAPass());
748
 #else
749
         MPM.add(createSROAPass(/*RequiresDomTree*/ false));
750
@@ -230,7 +230,7 @@ namespace gbe
751
   }
752
 
753
 
754
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
755
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
756
 #define OUTPUT_BITCODE(STAGE, MOD)  do {         \
757
   legacy::PassManager passes__;           \
758
    if (OCL_OUTPUT_LLVM_##STAGE) {                \
759
@@ -238,7 +238,7 @@ namespace gbe
760
      passes__.run(MOD);                          \
761
    }                                             \
762
  }while(0)
763
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
764
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
765
 #define OUTPUT_BITCODE(STAGE, MOD)  do {         \
766
    PassManager passes__;           \
767
    if (OCL_OUTPUT_LLVM_##STAGE) {                \
768
@@ -303,12 +303,12 @@ namespace gbe
769
     if (module) {
770
       cl_mod = reinterpret_cast<Module*>(const_cast<void*>(module));
771
     } else if (fileName){
772
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
773
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
774
       llvm::LLVMContext& c = GBEGetLLVMContext();
775
 #else
776
       llvm::LLVMContext& c = llvm::getGlobalContext();
777
 #endif
778
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
779
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
780
       cl_mod = parseIRFile(fileName, Err, c).release();
781
 #else
782
       cl_mod = ParseIRFile(fileName, Err, c);
783
@@ -318,7 +318,7 @@ namespace gbe
784
     if (!cl_mod) return false;
785
 
786
     OUTPUT_BITCODE(BEFORE_LINK, (*cl_mod));
787
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
788
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
789
     legacy::PassManager passes__;
790
 #else
791
     PassManager passes__;
792
@@ -346,7 +346,7 @@ namespace gbe
793
     gbeDiagnosticContext dc;
794
     mod.getContext().setDiagnosticHandler(&gbeDiagnosticHandler,&dc);
795
 
796
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
797
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
798
     mod.setDataLayout(DL);
799
 #endif
800
     Triple TargetTriple(mod.getTargetTriple());
801
@@ -357,15 +357,15 @@ namespace gbe
802
 
803
     runFuntionPass(mod, libraryInfo, DL);
804
     runModulePass(mod, libraryInfo, DL, optLevel, strictMath);
805
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
806
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
807
     legacy::PassManager passes;
808
 #else
809
     PassManager passes;
810
 #endif
811
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
812
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
813
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
814
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
815
     passes.add(new DataLayoutPass());
816
-#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
817
+#elif LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR == 35
818
     passes.add(new DataLayoutPass(DL));
819
 #else
820
     passes.add(new DataLayout(DL));
821
@@ -374,7 +374,7 @@ namespace gbe
822
     passes.add(createIntrinsicLoweringPass());
823
     passes.add(createStripAttributesPass());     // Strip unsupported attributes and calling conventions.
824
     passes.add(createFunctionInliningPass(20000));
825
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
826
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
827
     passes.add(createSROAPass());
828
 #else
829
     passes.add(createScalarReplAggregatesPass(64, true, -1, -1, 64));
830
diff --git a/backend/src/llvm/llvm_to_gen.hpp b/backend/src/llvm/llvm_to_gen.hpp
831
index d3928c6..9025852 100644
832
--- a/backend/src/llvm/llvm_to_gen.hpp
833
+++ b/backend/src/llvm/llvm_to_gen.hpp
834
@@ -23,7 +23,7 @@
835
  */
836
 #ifndef __GBE_IR_LLVM_TO_GEN_HPP__
837
 #define __GBE_IR_LLVM_TO_GEN_HPP__
838
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
839
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
840
 #include "llvm/IR/LLVMContext.h"
841
 #endif
842
 
843
@@ -37,7 +37,7 @@ namespace gbe {
844
 		  optLevel 0 equal to clang -O1 and 1 equal to clang -O2*/
845
   bool llvmToGen(ir::Unit &unit, const char *fileName, const void* module,
846
                  int optLevel, bool strictMath, int profiling, std::string &errors);
847
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
848
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 39
849
   extern llvm::LLVMContext& GBEGetLLVMContext();
850
 #endif
851
 
852
diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp
853
index e24dc4f..bfd3bbe 100644
854
--- a/backend/src/llvm/llvm_unroll.cpp
855
+++ b/backend/src/llvm/llvm_unroll.cpp
856
@@ -16,7 +16,7 @@
857
  */
858
 
859
 #include "llvm/Config/llvm-config.h"
860
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
861
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 35
862
 #include <set>
863
 
864
 #include "llvm_includes.hpp"
865
@@ -36,7 +36,7 @@ namespace gbe {
866
        LoopPass(ID) {}
867
 
868
       void getAnalysisUsage(AnalysisUsage &AU) const {
869
-#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 7)
870
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 37
871
         AU.addRequired<LoopInfoWrapperPass>();
872
         AU.addPreserved<LoopInfoWrapperPass>();
873
 #else
874
@@ -47,7 +47,7 @@ namespace gbe {
875
         AU.addPreservedID(LoopSimplifyID);
876
         AU.addRequiredID(LCSSAID);
877
         AU.addPreservedID(LCSSAID);
878
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
879
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
880
         AU.addRequired<ScalarEvolutionWrapperPass>();
881
         AU.addPreserved<ScalarEvolutionWrapperPass>();
882
 #else
883
@@ -91,7 +91,7 @@ namespace gbe {
884
           assert(MD->getNumOperands() == 2 &&
885
                  "Unroll count hint metadata should have two operands.");
886
           unsigned Count;
887
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
888
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
889
           Count = mdconst::extract<ConstantInt>(MD->getOperand(1))->getZExtValue();
890
 #else
891
           Count = cast<ConstantInt>(MD->getOperand(1))->getZExtValue();
892
@@ -105,7 +105,7 @@ namespace gbe {
893
       void setUnrollID(Loop *L, bool enable) {
894
         assert(enable);
895
         LLVMContext &Context = L->getHeader()->getContext();
896
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6
897
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 36
898
         SmallVector<Metadata *, 2> forceUnroll;
899
         forceUnroll.push_back(MDString::get(Context, "llvm.loop.unroll.enable"));
900
         MDNode *forceUnrollNode = MDNode::get(Context, forceUnroll);
901
@@ -169,7 +169,7 @@ namespace gbe {
902
       // be unrolled.
903
       bool handleParentLoops(Loop *L, LPPassManager &LPM) {
904
         Loop *currL = L;
905
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
906
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
907
         ScalarEvolution *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
908
         LoopInfo &loopInfo = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
909
 #else
910
@@ -205,7 +205,7 @@ namespace gbe {
911
           if (parentTripCount != 0 && currTripCount * parentTripCount > 32) {
912
             //Don't change the unrollID if doesn't force unroll.
913
             //setUnrollID(parentL, false);
914
-#if LLVM_VERSION_MAJOR == 3 &&  LLVM_VERSION_MINOR >= 8
915
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 38
916
             loopInfo.markAsRemoved(parentL);
917
 #else
918
             LPM.deleteLoopFromQueue(parentL);
919
-- 
920
cgit v0.10.2
921
(-)lang/beignet/files/extra-patch-refine_llvm_version_check.rej (+12 lines)
Line 0 Link Here
1
@@ -29,7 +29,11 @@
2
 #include "llvm/IR/DataLayout.h"
3
 #include "llvm-c/Linker.h"
4
 #include "llvm/Transforms/Utils/Cloning.h"
5
+#if LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40
6
+#include "llvm/Bitcode/BitcodeWriter.h"
7
+#else
8
 #include "llvm/Bitcode/ReaderWriter.h"
9
+#endif /* LLVM_VERSION_MAJOR * 10 + LLVM_VERSION_MINOR >= 40 */
10
 #include "llvm/Support/raw_ostream.h"
11
 #include "llvm/ADT/StringRef.h"
12
 #include "llvm/Support/MemoryBuffer.h"
(-)lang/beignet/files/extra-patch-remove_old_llvm_support (+298 lines)
Line 0 Link Here
1
From c6497b19e7b32bcb0d1f4aceb1988488dfec639d Mon Sep 17 00:00:00 2001
2
From: Pan Xiuli <xiuli.pan@intel.com>
3
Date: Fri, 17 Mar 2017 14:15:58 +0800
4
Subject: Backend: Remove old llvm support code.
5
6
LLVM 3.3 or older is not supportted by Beignet now, and we need delete
7
these codes.
8
9
Signed-off-by: Pan Xiuli <xiuli.pan@intel.com>
10
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
11
12
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
13
index 073ede6..376342b 100644
14
--- a/backend/src/backend/gen_program.cpp
15
+++ b/backend/src/backend/gen_program.cpp
16
@@ -24,15 +24,9 @@
17
 
18
 #ifdef GBE_COMPILER_AVAILABLE
19
 #include "llvm/Config/llvm-config.h"
20
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
21
-#include "llvm/LLVMContext.h"
22
-#include "llvm/Module.h"
23
-#include "llvm/DataLayout.h"
24
-#else
25
 #include "llvm/IR/LLVMContext.h"
26
 #include "llvm/IR/Module.h"
27
 #include "llvm/IR/DataLayout.h"
28
-#endif  /* LLVM_VERSION_MINOR <= 2 */
29
 #include "llvm-c/Linker.h"
30
 #include "llvm/Transforms/Utils/Cloning.h"
31
 #include "llvm/Bitcode/ReaderWriter.h"
32
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
33
index 8b8abc4..6b5fce0 100644
34
--- a/backend/src/backend/program.cpp
35
+++ b/backend/src/backend/program.cpp
36
@@ -52,33 +52,16 @@
37
 #include <mutex>
38
 
39
 #ifdef GBE_COMPILER_AVAILABLE
40
-/* Not defined for LLVM 3.0 */
41
-#if !defined(LLVM_VERSION_MAJOR)
42
-#define LLVM_VERSION_MAJOR 3
43
-#endif /* !defined(LLVM_VERSION_MAJOR) */
44
-
45
-/* Not defined for LLVM 3.0 */
46
-#if !defined(LLVM_VERSION_MINOR)
47
-#define LLVM_VERSION_MINOR 0
48
-#endif /* !defined(LLVM_VERSION_MINOR) */
49
 
50
 #include <clang/CodeGen/CodeGenAction.h>
51
 #include <clang/Frontend/CompilerInstance.h>
52
 #include <clang/Frontend/CompilerInvocation.h>
53
-#if LLVM_VERSION_MINOR <= 1
54
-#include <clang/Frontend/DiagnosticOptions.h>
55
-#else
56
 #include <clang/Basic/DiagnosticOptions.h>
57
-#endif  /* LLVM_VERSION_MINOR <= 1 */
58
 #include <clang/Frontend/TextDiagnosticPrinter.h>
59
 #include <clang/Basic/TargetInfo.h>
60
 #include <clang/Basic/TargetOptions.h>
61
 #include <llvm/ADT/IntrusiveRefCntPtr.h>
62
-#if LLVM_VERSION_MINOR <= 2
63
-#include <llvm/Module.h>
64
-#else
65
 #include <llvm/IR/Module.h>
66
-#endif  /* LLVM_VERSION_MINOR <= 2 */
67
 #include <llvm/Bitcode/ReaderWriter.h>
68
 #include <llvm/Support/raw_ostream.h>
69
 #endif
70
@@ -686,10 +669,6 @@ namespace gbe {
71
     args.push_back("-disable-llvm-optzns");
72
     if(bFastMath)
73
       args.push_back("-D __FAST_RELAXED_MATH__=1");
74
-#if LLVM_VERSION_MINOR <= 2
75
-    args.push_back("-triple");
76
-    args.push_back("nvptx");
77
-#else
78
     args.push_back("-x");
79
     args.push_back("cl");
80
     args.push_back("-triple");
81
@@ -698,7 +677,6 @@ namespace gbe {
82
       args.push_back("-fblocks");
83
     } else
84
       args.push_back("spir");
85
-#endif /* LLVM_VERSION_MINOR <= 2 */
86
     args.push_back("stringInput.cl");
87
     args.push_back("-ffp-contract=on");
88
     if(OCL_DEBUGINFO) args.push_back("-g");
89
@@ -791,11 +769,7 @@ namespace gbe {
90
       std::string err;
91
       llvm::raw_fd_ostream ostream (dumpLLVMFileName.c_str(),
92
                                     err,
93
-      #if LLVM_VERSION_MINOR == 3
94
-                                    0
95
-      #else
96
                                     llvm::sys::fs::F_None
97
-      #endif
98
                                     );
99
 
100
       if (err.empty()) {
101
@@ -807,11 +781,7 @@ namespace gbe {
102
       std::string err;
103
       llvm::raw_fd_ostream ostream (dumpSPIRBinaryName.c_str(),
104
                                     err,
105
-      #if LLVM_VERSION_MINOR == 3
106
-                                    0
107
-      #else
108
                                     llvm::sys::fs::F_None
109
-      #endif
110
                                     );
111
       if (err.empty())
112
         llvm::WriteBitcodeToFile(*out_module, ostream);
113
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
114
index d7dabe3..6fa1ae0 100644
115
--- a/backend/src/llvm/llvm_gen_backend.cpp
116
+++ b/backend/src/llvm/llvm_gen_backend.cpp
117
@@ -746,9 +746,6 @@ namespace gbe
118
     void visitVAArgInst(VAArgInst &I) {NOT_SUPPORTED;}
119
     void visitSwitchInst(SwitchInst &I) {NOT_SUPPORTED;}
120
     void visitInvokeInst(InvokeInst &I) {NOT_SUPPORTED;}
121
-#if LLVM_VERSION_MINOR == 0
122
-    void visitUnwindInst(UnwindInst &I) {NOT_SUPPORTED;}
123
-#endif /* __LLVM_30__ */
124
     void visitResumeInst(ResumeInst &I) {NOT_SUPPORTED;}
125
     void visitInlineAsm(CallInst &I) {NOT_SUPPORTED;}
126
     void visitIndirectBrInst(IndirectBrInst &I) {NOT_SUPPORTED;}
127
@@ -1750,7 +1747,6 @@ namespace gbe
128
   {
129
     GBE_ASSERT(dyn_cast<ConstantExpr>(CPV) == NULL);
130
 
131
-#if LLVM_VERSION_MINOR > 0
132
     ConstantDataSequential *seq = dyn_cast<ConstantDataSequential>(CPV);
133
 
134
     if (seq) {
135
@@ -1773,7 +1769,6 @@ namespace gbe
136
         GBE_ASSERTM(0, "Const data array never be half float\n");
137
       }
138
     } else
139
-#endif /* LLVM_VERSION_MINOR > 0 */
140
 
141
     if (dyn_cast<ConstantAggregateZero>(CPV)) {
142
       Type* Ty = CPV->getType();
143
@@ -2344,9 +2339,6 @@ namespace gbe
144
       Function::arg_iterator I = F.arg_begin(), E = F.arg_end();
145
 
146
       // Insert a new register for each function argument
147
-#if LLVM_VERSION_MINOR <= 1
148
-      const AttrListPtr &PAL = F.getAttributes();
149
-#endif /* LLVM_VERSION_MINOR <= 1 */
150
       for (; I != E; ++I, ++argID) {
151
         uint32_t opID = argID;
152
 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 9
153
@@ -2436,11 +2428,7 @@ namespace gbe
154
             continue;
155
           Type *pointed = pointerType->getElementType();
156
           // By value structure
157
-#if LLVM_VERSION_MINOR <= 1
158
-          if (PAL.paramHasAttr(argID+1, Attribute::ByVal)) {
159
-#else
160
           if (I->hasByValAttr()) {
161
-#endif /* LLVM_VERSION_MINOR <= 1 */
162
             const size_t structSize = getTypeByteSize(unit, pointed);
163
             ctx.input(argName, ir::FunctionArgument::STRUCTURE, reg, llvmInfo, structSize, getAlignmentByte(unit, type), 0);
164
           }
165
@@ -3164,15 +3152,9 @@ namespace gbe
166
   void GenWriter::emitFunction(Function &F)
167
   {
168
     switch (F.getCallingConv()) {
169
-#if LLVM_VERSION_MINOR <= 2
170
-      case CallingConv::PTX_Device: // we do not emit device function
171
-        return;
172
-      case CallingConv::PTX_Kernel:
173
-#else
174
       case CallingConv::C:
175
       case CallingConv::Fast:
176
       case CallingConv::SPIR_KERNEL:
177
-#endif
178
         break;
179
       default:
180
         GBE_ASSERTM(false, "Unsupported calling convention");
181
@@ -3789,14 +3771,12 @@ namespace gbe
182
           break;
183
           case Intrinsic::stackrestore:
184
           break;
185
-#if LLVM_VERSION_MINOR >= 2
186
           case Intrinsic::lifetime_start:
187
           case Intrinsic::lifetime_end:
188
           break;
189
           case Intrinsic::fmuladd:
190
             this->newRegister(&I);
191
           break;
192
-#endif /* LLVM_VERSION_MINOR >= 2 */
193
           case Intrinsic::debugtrap:
194
           case Intrinsic::trap:
195
           case Intrinsic::dbg_value:
196
@@ -4644,11 +4624,9 @@ namespace gbe
197
             ctx.MOV(ir::getType(family), dst, src);
198
           }
199
           break;
200
-#if LLVM_VERSION_MINOR >= 2
201
           case Intrinsic::lifetime_start:
202
           case Intrinsic::lifetime_end:
203
           break;
204
-#endif /* LLVM_VERSION_MINOR >= 2 */
205
           case Intrinsic::debugtrap:
206
           case Intrinsic::trap:
207
           case Intrinsic::dbg_value:
208
diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp
209
index 800f343..d64fc60 100644
210
--- a/backend/src/llvm/llvm_printf_parser.cpp
211
+++ b/backend/src/llvm/llvm_printf_parser.cpp
212
@@ -389,15 +389,9 @@ error:
213
   {
214
     bool hasPrintf = false;
215
     switch (F.getCallingConv()) {
216
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
217
-      case CallingConv::PTX_Device:
218
-        return false;
219
-      case CallingConv::PTX_Kernel:
220
-#else
221
       case CallingConv::C:
222
       case CallingConv::Fast:
223
       case CallingConv::SPIR_KERNEL:
224
-#endif
225
         break;
226
       default:
227
         GBE_ASSERTM(false, "Unsupported calling convention");
228
diff --git a/backend/src/llvm/llvm_profiling.cpp b/backend/src/llvm/llvm_profiling.cpp
229
index 96c95ee..734c69d 100644
230
--- a/backend/src/llvm/llvm_profiling.cpp
231
+++ b/backend/src/llvm/llvm_profiling.cpp
232
@@ -26,27 +26,13 @@
233
 #include <stdlib.h>
234
 
235
 #include "llvm/Config/llvm-config.h"
236
-#if LLVM_VERSION_MINOR <= 2
237
-#include "llvm/Function.h"
238
-#include "llvm/InstrTypes.h"
239
-#include "llvm/Instructions.h"
240
-#include "llvm/IntrinsicInst.h"
241
-#include "llvm/Module.h"
242
-#else
243
 #include "llvm/IR/Function.h"
244
 #include "llvm/IR/InstrTypes.h"
245
 #include "llvm/IR/Instructions.h"
246
 #include "llvm/IR/IntrinsicInst.h"
247
 #include "llvm/IR/Module.h"
248
-#endif  /* LLVM_VERSION_MINOR <= 2 */
249
 #include "llvm/Pass.h"
250
-#if LLVM_VERSION_MINOR <= 1
251
-#include "llvm/Support/IRBuilder.h"
252
-#elif LLVM_VERSION_MINOR == 2
253
-#include "llvm/IRBuilder.h"
254
-#else
255
 #include "llvm/IR/IRBuilder.h"
256
-#endif /* LLVM_VERSION_MINOR <= 1 */
257
 
258
 #if LLVM_VERSION_MINOR >= 5
259
 #include "llvm/IR/CallSite.h"
260
@@ -111,15 +97,9 @@ namespace gbe
261
     int pointNum = 0;
262
 
263
     switch (F.getCallingConv()) {
264
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
265
-      case CallingConv::PTX_Device:
266
-        return false;
267
-      case CallingConv::PTX_Kernel:
268
-#else
269
       case CallingConv::C:
270
       case CallingConv::Fast:
271
       case CallingConv::SPIR_KERNEL:
272
-#endif
273
         break;
274
       default:
275
         GBE_ASSERTM(false, "Unsupported calling convention");
276
diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp
277
index 6f46c9d..329e3a9 100644
278
--- a/backend/src/llvm/llvm_scalarize.cpp
279
+++ b/backend/src/llvm/llvm_scalarize.cpp
280
@@ -884,15 +884,9 @@ namespace gbe {
281
   bool Scalarize::runOnFunction(Function& F)
282
   {
283
     switch (F.getCallingConv()) {
284
-#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 2
285
-    case CallingConv::PTX_Device:
286
-      return false;
287
-    case CallingConv::PTX_Kernel:
288
-#else
289
     case CallingConv::C:
290
     case CallingConv::Fast:
291
     case CallingConv::SPIR_KERNEL:
292
-#endif
293
       break;
294
     default:
295
       GBE_ASSERTM(false, "Unsupported calling convention");
296
-- 
297
cgit v0.10.2
298

Return to bug 218644