Intel SPMD Program Compiler  1.9.2
builtins.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010-2015, Intel Corporation
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11 
12  * Redistributions in binary form must reproduce the above copyright
13  notice, this list of conditions and the following disclaimer in the
14  documentation and/or other materials provided with the distribution.
15 
16  * Neither the name of Intel Corporation nor the names of its
17  contributors may be used to endorse or promote products derived from
18  this software without specific prior written permission.
19 
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 /** @file builtins.cpp
35  @brief Definitions of functions related to setting up the standard library
36  and other builtins.
37 */
38 
39 #include "builtins.h"
40 #include "type.h"
41 #include "util.h"
42 #include "sym.h"
43 #include "expr.h"
44 #include "llvmutil.h"
45 #include "module.h"
46 #include "ctx.h"
47 
48 #include <math.h>
49 #include <stdlib.h>
50 #if ISPC_LLVM_VERSION == ISPC_LLVM_3_2
51  #include <llvm/Attributes.h>
52  #include <llvm/LLVMContext.h>
53  #include <llvm/Module.h>
54  #include <llvm/Type.h>
55  #include <llvm/Instructions.h>
56  #include <llvm/Intrinsics.h>
57  #include <llvm/DerivedTypes.h>
58 #else
59  #include <llvm/IR/Attributes.h>
60  #include <llvm/IR/LLVMContext.h>
61  #include <llvm/IR/Module.h>
62  #include <llvm/IR/Type.h>
63  #include <llvm/IR/Instructions.h>
64  #include <llvm/IR/Intrinsics.h>
65  #include <llvm/IR/DerivedTypes.h>
66 #endif
67 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5
68  #include <llvm/Linker/Linker.h>
69 #else
70  #include <llvm/Linker.h>
71 #endif
72 #include <llvm/Target/TargetMachine.h>
73 #include <llvm/ADT/Triple.h>
74 #include <llvm/Support/MemoryBuffer.h>
75 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_9
76  #include <llvm/Bitcode/ReaderWriter.h>
77 #else
78  #include <llvm/Bitcode/BitcodeReader.h>
79 #endif
80 
81 extern int yyparse();
82 struct yy_buffer_state;
83 extern yy_buffer_state *yy_scan_string(const char *);
84 
85 
86 /** Given an LLVM type, try to find the equivalent ispc type. Note that
87  this is an under-constrained problem due to LLVM's type representations
88  carrying less information than ispc's. (For example, LLVM doesn't
89  distinguish between signed and unsigned integers in its types.)
90 
91  Because this function is only used for generating ispc declarations of
92  functions defined in LLVM bitcode in the builtins-*.ll files, in practice
93  we can get enough of what we need for the relevant cases to make things
94  work, partially with the help of the intAsUnsigned parameter, which
95  indicates whether LLVM integer types should be treated as being signed
96  or unsigned.
97 
98  */
99 static const Type *
100 lLLVMTypeToISPCType(const llvm::Type *t, bool intAsUnsigned) {
101  if (t == LLVMTypes::VoidType)
102  return AtomicType::Void;
103 
104  // uniform
105  else if (t == LLVMTypes::BoolType)
107  else if (t == LLVMTypes::Int8Type)
108  return intAsUnsigned ? AtomicType::UniformUInt8 : AtomicType::UniformInt8;
109  else if (t == LLVMTypes::Int16Type)
110  return intAsUnsigned ? AtomicType::UniformUInt16 : AtomicType::UniformInt16;
111  else if (t == LLVMTypes::Int32Type)
112  return intAsUnsigned ? AtomicType::UniformUInt32 : AtomicType::UniformInt32;
113  else if (t == LLVMTypes::FloatType)
115  else if (t == LLVMTypes::DoubleType)
117  else if (t == LLVMTypes::Int64Type)
118  return intAsUnsigned ? AtomicType::UniformUInt64 : AtomicType::UniformInt64;
119 
120  // varying
121  if (t == LLVMTypes::Int8VectorType)
122  return intAsUnsigned ? AtomicType::VaryingUInt8 : AtomicType::VaryingInt8;
123  else if (t == LLVMTypes::Int16VectorType)
124  return intAsUnsigned ? AtomicType::VaryingUInt16 : AtomicType::VaryingInt16;
125  else if (t == LLVMTypes::Int32VectorType)
126  return intAsUnsigned ? AtomicType::VaryingUInt32 : AtomicType::VaryingInt32;
127  else if (t == LLVMTypes::FloatVectorType)
129  else if (t == LLVMTypes::DoubleVectorType)
131  else if (t == LLVMTypes::Int64VectorType)
132  return intAsUnsigned ? AtomicType::VaryingUInt64 : AtomicType::VaryingInt64;
133  else if (t == LLVMTypes::MaskType)
135 
136  // pointers to uniform
137  else if (t == LLVMTypes::Int8PointerType)
138  return PointerType::GetUniform(intAsUnsigned ? AtomicType::UniformUInt8 :
140  else if (t == LLVMTypes::Int16PointerType)
141  return PointerType::GetUniform(intAsUnsigned ? AtomicType::UniformUInt16 :
143  else if (t == LLVMTypes::Int32PointerType)
144  return PointerType::GetUniform(intAsUnsigned ? AtomicType::UniformUInt32 :
146  else if (t == LLVMTypes::Int64PointerType)
147  return PointerType::GetUniform(intAsUnsigned ? AtomicType::UniformUInt64 :
149  else if (t == LLVMTypes::FloatPointerType)
151  else if (t == LLVMTypes::DoublePointerType)
153 
154  // pointers to varying
155  else if (t == LLVMTypes::Int8VectorPointerType)
156  return PointerType::GetUniform(intAsUnsigned ? AtomicType::VaryingUInt8 :
158  else if (t == LLVMTypes::Int16VectorPointerType)
159  return PointerType::GetUniform(intAsUnsigned ? AtomicType::VaryingUInt16 :
161  else if (t == LLVMTypes::Int32VectorPointerType)
162  return PointerType::GetUniform(intAsUnsigned ? AtomicType::VaryingUInt32 :
164  else if (t == LLVMTypes::Int64VectorPointerType)
165  return PointerType::GetUniform(intAsUnsigned ? AtomicType::VaryingUInt64 :
167  else if (t == LLVMTypes::FloatVectorPointerType)
171 
172  return NULL;
173 }
174 
175 
176 static void
177 lCreateSymbol(const std::string &name, const Type *returnType,
178  llvm::SmallVector<const Type *, 8> &argTypes,
179  const llvm::FunctionType *ftype, llvm::Function *func,
180  SymbolTable *symbolTable) {
181  SourcePos noPos;
182  noPos.name = "__stdlib";
183 
184  FunctionType *funcType = new FunctionType(returnType, argTypes, noPos);
185 
186  Debug(noPos, "Created builtin symbol \"%s\" [%s]\n", name.c_str(),
187  funcType->GetString().c_str());
188 
189  Symbol *sym = new Symbol(name, noPos, funcType);
190  sym->function = func;
191  symbolTable->AddFunction(sym);
192 }
193 
194 
195 /** Given an LLVM function declaration, synthesize the equivalent ispc
196  symbol for the function (if possible). Returns true on success, false
197  on failure.
198  */
199 static bool
200 lCreateISPCSymbol(llvm::Function *func, SymbolTable *symbolTable) {
201  SourcePos noPos;
202  noPos.name = "__stdlib";
203 
204  const llvm::FunctionType *ftype = func->getFunctionType();
205  std::string name = func->getName();
206 
207  if (name.size() < 3 || name[0] != '_' || name[1] != '_')
208  return false;
209 
210  Debug(SourcePos(), "Attempting to create ispc symbol for function \"%s\".",
211  name.c_str());
212 
213  // An unfortunate hack: we want this builtin function to have the
214  // signature "int __sext_varying_bool(bool)", but the ispc function
215  // symbol creation code below assumes that any LLVM vector of i32s is a
216  // varying int32. Here, we need that to be interpreted as a varying
217  // bool, so just have a one-off override for that one...
218  if (g->target->getMaskBitCount() != 1 && name == "__sext_varying_bool") {
219  const Type *returnType = AtomicType::VaryingInt32;
220  llvm::SmallVector<const Type *, 8> argTypes;
221  argTypes.push_back(AtomicType::VaryingBool);
222 
223  FunctionType *funcType = new FunctionType(returnType, argTypes, noPos);
224 
225  Symbol *sym = new Symbol(name, noPos, funcType);
226  sym->function = func;
227  symbolTable->AddFunction(sym);
228  return true;
229  }
230 
231  // If the function has any parameters with integer types, we'll make
232  // two Symbols for two overloaded versions of the function, one with
233  // all of the integer types treated as signed integers and one with all
234  // of them treated as unsigned.
235  for (int i = 0; i < 2; ++i) {
236  bool intAsUnsigned = (i == 1);
237 
238  const Type *returnType = lLLVMTypeToISPCType(ftype->getReturnType(),
239  intAsUnsigned);
240  if (returnType == NULL) {
241  Debug(SourcePos(), "Failed: return type not representable for "
242  "builtin %s.", name.c_str());
243  // return type not representable in ispc -> not callable from ispc
244  return false;
245  }
246 
247  // Iterate over the arguments and try to find their equivalent ispc
248  // types. Track if any of the arguments has an integer type.
249  bool anyIntArgs = false;
250  llvm::SmallVector<const Type *, 8> argTypes;
251  for (unsigned int j = 0; j < ftype->getNumParams(); ++j) {
252  const llvm::Type *llvmArgType = ftype->getParamType(j);
253  const Type *type = lLLVMTypeToISPCType(llvmArgType, intAsUnsigned);
254  if (type == NULL) {
255  Debug(SourcePos(), "Failed: type of parameter %d not "
256  "representable for builtin %s", j, name.c_str());
257  return false;
258  }
259  anyIntArgs |=
260  (Type::Equal(type, lLLVMTypeToISPCType(llvmArgType, !intAsUnsigned)) == false);
261  argTypes.push_back(type);
262  }
263 
264  // Always create the symbol the first time through, in particular
265  // so that we get symbols for things with no integer types!
266  if (i == 0 || anyIntArgs == true)
267  lCreateSymbol(name, returnType, argTypes, ftype, func, symbolTable);
268  }
269 
270  return true;
271 }
272 
273 
274 /** Given an LLVM module, create ispc symbols for the functions in the
275  module.
276  */
277 static void
278 lAddModuleSymbols(llvm::Module *module, SymbolTable *symbolTable) {
279 #if 0
280  // FIXME: handle globals?
281  Assert(module->global_empty());
282 #endif
283 
284  llvm::Module::iterator iter;
285  for (iter = module->begin(); iter != module->end(); ++iter) {
286 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6, 3.7 */
287  llvm::Function *func = iter;
288 #else /* LLVM 3.8+ */
289  llvm::Function *func = &*iter;
290 #endif
291  lCreateISPCSymbol(func, symbolTable);
292  }
293 }
294 
295 
296 /** In many of the builtins-*.ll files, we have declarations of various LLVM
297  intrinsics that are then used in the implementation of various target-
298  specific functions. This function loops over all of the intrinsic
299  declarations and makes sure that the signature we have in our .ll file
300  matches the signature of the actual intrinsic.
301 */
302 static void
303 lCheckModuleIntrinsics(llvm::Module *module) {
304  llvm::Module::iterator iter;
305  for (iter = module->begin(); iter != module->end(); ++iter) {
306 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_7 /* 3.2, 3.3, 3.4, 3.5, 3.6, 3.7 */
307  llvm::Function *func = iter;
308 #else /* LLVM 3.8+ */
309  llvm::Function *func = &*iter;
310 #endif
311  if (!func->isIntrinsic())
312  continue;
313 
314  const std::string funcName = func->getName().str();
315  // Work around http://llvm.org/bugs/show_bug.cgi?id=10438; only
316  // check the llvm.x86.* intrinsics for now...
317  if (!strncmp(funcName.c_str(), "llvm.x86.", 9)) {
318  llvm::Intrinsic::ID id = (llvm::Intrinsic::ID)func->getIntrinsicID();
319  if (id == 0) fprintf(stderr, "FATAL: intrinsic is not found: %s \n", funcName.c_str());
320  Assert(id != 0);
321  llvm::Type *intrinsicType =
322  llvm::Intrinsic::getType(*g->ctx, id);
323  intrinsicType = llvm::PointerType::get(intrinsicType, 0);
324  Assert(func->getType() == intrinsicType);
325  }
326  }
327 }
328 
329 
330 /** We'd like to have all of these functions declared as 'internal' in
331  their respective bitcode files so that if they aren't needed by the
332  user's program they are elimiated from the final output. However, if
333  we do so, then they aren't brought in by the LinkModules() call below
334  since they aren't yet used by anything in the module they're being
335  linked with (in LLVM 3.1, at least).
336 
337  Therefore, we don't declare them as internal when we first define them,
338  but instead mark them as internal after they've been linked in. This
339  is admittedly a kludge.
340  */
341 static void
342 lSetInternalFunctions(llvm::Module *module) {
343  const char *names[] = {
344  "__add_float",
345  "__add_int32",
346  "__add_uniform_double",
347  "__add_uniform_int32",
348  "__add_uniform_int64",
349  "__add_varying_double",
350  "__add_varying_int32",
351  "__add_varying_int64",
352  "__all",
353  "__any",
354  "__aos_to_soa3_float",
355 //#ifdef ISPC_NVPTX_ENABLED
356  "__aos_to_soa3_float1",
357 //#endif /* ISPC_NVPTX_ENABLED */
358  "__aos_to_soa3_float16",
359  "__aos_to_soa3_float4",
360  "__aos_to_soa3_float8",
361  "__aos_to_soa3_int32",
362  "__aos_to_soa4_float",
363 //#ifdef ISPC_NVPTX_ENABLED
364  "__aos_to_soa4_float1",
365 //#endif /* ISPC_NVPTX_ENABLED */
366  "__aos_to_soa4_float16",
367  "__aos_to_soa4_float4",
368  "__aos_to_soa4_float8",
369  "__aos_to_soa4_int32",
370  "__atomic_add_int32_global",
371  "__atomic_add_int64_global",
372  "__atomic_add_uniform_int32_global",
373  "__atomic_add_uniform_int64_global",
374  "__atomic_and_int32_global",
375  "__atomic_and_int64_global",
376  "__atomic_and_uniform_int32_global",
377  "__atomic_and_uniform_int64_global",
378  "__atomic_compare_exchange_double_global",
379  "__atomic_compare_exchange_float_global",
380  "__atomic_compare_exchange_int32_global",
381  "__atomic_compare_exchange_int64_global",
382  "__atomic_compare_exchange_uniform_double_global",
383  "__atomic_compare_exchange_uniform_float_global",
384  "__atomic_compare_exchange_uniform_int32_global",
385  "__atomic_compare_exchange_uniform_int64_global",
386  "__atomic_max_uniform_int32_global",
387  "__atomic_max_uniform_int64_global",
388  "__atomic_min_uniform_int32_global",
389  "__atomic_min_uniform_int64_global",
390  "__atomic_or_int32_global",
391  "__atomic_or_int64_global",
392  "__atomic_or_uniform_int32_global",
393  "__atomic_or_uniform_int64_global",
394  "__atomic_sub_int32_global",
395  "__atomic_sub_int64_global",
396  "__atomic_sub_uniform_int32_global",
397  "__atomic_sub_uniform_int64_global",
398  "__atomic_swap_double_global",
399  "__atomic_swap_float_global",
400  "__atomic_swap_int32_global",
401  "__atomic_swap_int64_global",
402  "__atomic_swap_uniform_double_global",
403  "__atomic_swap_uniform_float_global",
404  "__atomic_swap_uniform_int32_global",
405  "__atomic_swap_uniform_int64_global",
406  "__atomic_umax_uniform_uint32_global",
407  "__atomic_umax_uniform_uint64_global",
408  "__atomic_umin_uniform_uint32_global",
409  "__atomic_umin_uniform_uint64_global",
410  "__atomic_xor_int32_global",
411  "__atomic_xor_int64_global",
412  "__atomic_xor_uniform_int32_global",
413  "__atomic_xor_uniform_int64_global",
414 //#ifdef ISPC_NVPTX_ENABLED
415  "__atomic_add_varying_int32_global",
416  "__atomic_add_varying_int64_global",
417  "__atomic_and_varying_int32_global",
418  "__atomic_and_varying_int64_global",
419  "__atomic_compare_exchange_varying_double_global",
420  "__atomic_compare_exchange_varying_float_global",
421  "__atomic_compare_exchange_varying_int32_global",
422  "__atomic_compare_exchange_varying_int64_global",
423  "__atomic_max_varying_int32_global",
424  "__atomic_max_varying_int64_global",
425  "__atomic_min_varying_int32_global",
426  "__atomic_min_varying_int64_global",
427  "__atomic_or_varying_int32_global",
428  "__atomic_or_varying_int64_global",
429  "__atomic_sub_varying_int32_global",
430  "__atomic_sub_varying_int64_global",
431  "__atomic_swap_varying_double_global",
432  "__atomic_swap_varying_float_global",
433  "__atomic_swap_varying_int32_global",
434  "__atomic_swap_varying_int64_global",
435  "__atomic_umax_varying_uint32_global",
436  "__atomic_umax_varying_uint64_global",
437  "__atomic_umin_varying_uint32_global",
438  "__atomic_umin_varying_uint64_global",
439  "__atomic_xor_uniform_int32_global",
440  "__atomic_xor_uniform_int64_global",
441  "__atomic_xor_varying_int32_global",
442  "__atomic_xor_varying_int64_global",
443  "__atomic_xor_varying_int32_global",
444  "__atomic_xor_varying_int64_global",
445 //#endif /* ISPC_NVPTX_ENABLED */
446  "__broadcast_double",
447  "__broadcast_float",
448  "__broadcast_i16",
449  "__broadcast_i32",
450  "__broadcast_i64",
451  "__broadcast_i8",
452  "__cast_mask_to_i1",
453  "__cast_mask_to_i16",
454  "__ceil_uniform_double",
455  "__ceil_uniform_float",
456  "__ceil_varying_double",
457  "__ceil_varying_float",
458  "__clock",
459  "__count_trailing_zeros_i32",
460  "__count_trailing_zeros_i64",
461  "__count_leading_zeros_i32",
462  "__count_leading_zeros_i64",
463  "__delete_uniform_32rt",
464  "__delete_uniform_64rt",
465  "__delete_varying_32rt",
466  "__delete_varying_64rt",
467  "__do_assert_uniform",
468  "__do_assert_varying",
469  "__do_print",
470 //#ifdef ISPC_NVPTX_ENABLED
471  "__do_print_nvptx",
472 //#endif /* ISPC_NVPTX_ENABLED */
473  "__doublebits_uniform_int64",
474  "__doublebits_varying_int64",
475  "__exclusive_scan_add_double",
476  "__exclusive_scan_add_float",
477  "__exclusive_scan_add_i32",
478  "__exclusive_scan_add_i64",
479  "__exclusive_scan_and_i32",
480  "__exclusive_scan_and_i64",
481  "__exclusive_scan_or_i32",
482  "__exclusive_scan_or_i64",
483  "__extract_int16",
484  "__extract_int32",
485  "__extract_int64",
486  "__extract_int8",
487 //#ifdef ISPC_NVPTX_ENABLED
488  "__extract_float",
489  "__extract_double",
490 //#endif /* ISPC_NVPTX_ENABLED */
491  "__extract_mask_low",
492  "__extract_mask_hi",
493  "__fastmath",
494  "__float_to_half_uniform",
495  "__float_to_half_varying",
496  "__floatbits_uniform_int32",
497  "__floatbits_varying_int32",
498  "__floor_uniform_double",
499  "__floor_uniform_float",
500  "__floor_varying_double",
501  "__floor_varying_float",
502  "__get_system_isa",
503  "__half_to_float_uniform",
504  "__half_to_float_varying",
505  "__insert_int16",
506  "__insert_int32",
507  "__insert_int64",
508  "__insert_int8",
509 //#ifdef ISPC_NVPTX_ENABLED
510  "__insert_float",
511  "__insert_double",
512 //#endif /* ISPC_NVPTX_ENABLED */
513  "__intbits_uniform_double",
514  "__intbits_uniform_float",
515  "__intbits_varying_double",
516  "__intbits_varying_float",
517  "__max_uniform_double",
518  "__max_uniform_float",
519  "__max_uniform_int32",
520  "__max_uniform_int64",
521  "__max_uniform_uint32",
522  "__max_uniform_uint64",
523  "__max_varying_double",
524  "__max_varying_float",
525  "__max_varying_int32",
526  "__max_varying_int64",
527  "__max_varying_uint32",
528  "__max_varying_uint64",
529  "__memory_barrier",
530  "__memcpy32",
531  "__memcpy64",
532  "__memmove32",
533  "__memmove64",
534  "__memset32",
535  "__memset64",
536  "__min_uniform_double",
537  "__min_uniform_float",
538  "__min_uniform_int32",
539  "__min_uniform_int64",
540  "__min_uniform_uint32",
541  "__min_uniform_uint64",
542  "__min_varying_double",
543  "__min_varying_float",
544  "__min_varying_int32",
545  "__min_varying_int64",
546  "__min_varying_uint32",
547  "__min_varying_uint64",
548  "__movmsk",
549 //#ifdef ISPC_NVPTX_ENABLED
550  "__movmsk_ptx",
551 //#endif /* ISPC_NVPTX_ENABLED */
552  "__new_uniform_32rt",
553  "__new_uniform_64rt",
554  "__new_varying32_32rt",
555  "__new_varying32_64rt",
556  "__new_varying64_64rt",
557  "__none",
558  "__num_cores",
559  "__packed_load_active",
560  "__packed_store_active",
561  "__packed_store_active2",
562  "__padds_vi8",
563  "__padds_vi16",
564  "__paddus_vi8",
565  "__paddus_vi16",
566  "__popcnt_int32",
567  "__popcnt_int64",
568  "__prefetch_read_uniform_1",
569  "__prefetch_read_uniform_2",
570  "__prefetch_read_uniform_3",
571  "__prefetch_read_uniform_nt",
572  "__pseudo_prefetch_read_varying_1",
573  "__pseudo_prefetch_read_varying_2",
574  "__pseudo_prefetch_read_varying_3",
575  "__pseudo_prefetch_read_varying_nt",
576  "__psubs_vi8",
577  "__psubs_vi16",
578  "__psubus_vi8",
579  "__psubus_vi16",
580  "__rcp_uniform_float",
581  "__rcp_varying_float",
582  "__rcp_uniform_double",
583  "__rcp_varying_double",
584  "__rdrand_i16",
585  "__rdrand_i32",
586  "__rdrand_i64",
587  "__reduce_add_double",
588  "__reduce_add_float",
589  "__reduce_add_int8",
590  "__reduce_add_int16",
591  "__reduce_add_int32",
592  "__reduce_add_int64",
593  "__reduce_equal_double",
594  "__reduce_equal_float",
595  "__reduce_equal_int32",
596  "__reduce_equal_int64",
597  "__reduce_max_double",
598  "__reduce_max_float",
599  "__reduce_max_int32",
600  "__reduce_max_int64",
601  "__reduce_max_uint32",
602  "__reduce_max_uint64",
603  "__reduce_min_double",
604  "__reduce_min_float",
605  "__reduce_min_int32",
606  "__reduce_min_int64",
607  "__reduce_min_uint32",
608  "__reduce_min_uint64",
609  "__rotate_double",
610  "__rotate_float",
611  "__rotate_i16",
612  "__rotate_i32",
613  "__rotate_i64",
614  "__rotate_i8",
615  "__round_uniform_double",
616  "__round_uniform_float",
617  "__round_varying_double",
618  "__round_varying_float",
619  "__rsqrt_uniform_float",
620  "__rsqrt_varying_float",
621  "__rsqrt_uniform_double",
622  "__rsqrt_varying_double",
623  "__set_system_isa",
624  "__sext_uniform_bool",
625  "__sext_varying_bool",
626  "__shift_double",
627  "__shift_float",
628  "__shift_i16",
629  "__shift_i32",
630  "__shift_i64",
631  "__shift_i8",
632  "__shuffle2_double",
633  "__shuffle2_float",
634  "__shuffle2_i16",
635  "__shuffle2_i32",
636  "__shuffle2_i64",
637  "__shuffle2_i8",
638  "__shuffle_double",
639  "__shuffle_float",
640  "__shuffle_i16",
641  "__shuffle_i32",
642  "__shuffle_i64",
643  "__shuffle_i8",
644  "__soa_to_aos3_float",
645  "__soa_to_aos3_float16",
646  "__soa_to_aos3_float4",
647  "__soa_to_aos3_float8",
648  "__soa_to_aos3_int32",
649  "__soa_to_aos4_float",
650 //#ifdef ISPC_NVPTX_ENABLED
651  "__soa_to_aos3_float1",
652  "__soa_to_aos4_float1",
653 //#endif /* ISPC_NVPTX_ENABLED */
654  "__soa_to_aos4_float16",
655  "__soa_to_aos4_float4",
656  "__soa_to_aos4_float8",
657  "__soa_to_aos4_int32",
658  "__sqrt_uniform_double",
659  "__sqrt_uniform_float",
660  "__sqrt_varying_double",
661  "__sqrt_varying_float",
662  "__stdlib_acosf",
663  "__stdlib_asinf",
664  "__stdlib_atan",
665  "__stdlib_atan2",
666  "__stdlib_atan2f",
667  "__stdlib_atanf",
668  "__stdlib_cos",
669  "__stdlib_cosf",
670  "__stdlib_exp",
671  "__stdlib_expf",
672  "__stdlib_log",
673  "__stdlib_logf",
674  "__stdlib_pow",
675  "__stdlib_powf",
676  "__stdlib_sin",
677  "__stdlib_asin",
678  "__stdlib_sincos",
679  "__stdlib_sincosf",
680  "__stdlib_sinf",
681  "__stdlib_tan",
682  "__stdlib_tanf",
683  "__svml_sind",
684  "__svml_asind",
685  "__svml_cosd",
686  "__svml_acosd",
687  "__svml_sincosd",
688  "__svml_tand",
689  "__svml_atand",
690  "__svml_atan2d",
691  "__svml_expd",
692  "__svml_logd",
693  "__svml_powd",
694  "__svml_sinf",
695  "__svml_asinf",
696  "__svml_cosf",
697  "__svml_acosf",
698  "__svml_sincosf",
699  "__svml_tanf",
700  "__svml_atanf",
701  "__svml_atan2f",
702  "__svml_expf",
703  "__svml_logf",
704  "__svml_powf",
705  "__log_uniform_float",
706  "__log_varying_float",
707  "__exp_uniform_float",
708  "__exp_varying_float",
709  "__pow_uniform_float",
710  "__pow_varying_float",
711  "__log_uniform_double",
712  "__log_varying_double",
713  "__exp_uniform_double",
714  "__exp_varying_double",
715  "__pow_uniform_double",
716  "__pow_varying_double",
717  "__sin_varying_float",
718  "__asin_varying_float",
719  "__cos_varying_float",
720  "__acos_varying_float",
721  "__sincos_varying_float",
722  "__tan_varying_float",
723  "__atan_varying_float",
724  "__atan2_varying_float",
725  "__sin_uniform_float",
726  "__asin_uniform_float",
727  "__cos_uniform_float",
728  "__acos_uniform_float",
729  "__sincos_uniform_float",
730  "__tan_uniform_float",
731  "__atan_uniform_float",
732  "__atan2_uniform_float",
733  "__sin_varying_double",
734  "__asin_varying_double",
735  "__cos_varying_double",
736  "__acos_varying_double",
737  "__sincos_varying_double",
738  "__tan_varying_double",
739  "__atan_varying_double",
740  "__atan2_varying_double",
741  "__sin_uniform_double",
742  "__asin_uniform_double",
743  "__cos_uniform_double",
744  "__acos_uniform_double",
745  "__sincos_uniform_double",
746  "__tan_uniform_double",
747  "__atan_uniform_double",
748  "__atan2_uniform_double",
749  "__undef_uniform",
750  "__undef_varying",
751  "__vec4_add_float",
752  "__vec4_add_int32",
753  "__vselect_float",
754 //#ifdef ISPC_NVPTX_ENABLED
755  "__program_index",
756  "__program_count",
757  "__warp_index",
758  "__task_index0",
759  "__task_index1",
760  "__task_index2",
761  "__task_index",
762  "__task_count0",
763  "__task_count1",
764  "__task_count2",
765  "__task_count",
766  "__cvt_loc2gen",
767  "__cvt_loc2gen_var",
768  "__cvt_const2gen",
769  "__puts_nvptx",
770  "ISPCAlloc",
771  "ISPCLaunch",
772  "ISPCSync",
773 //#endif /* ISPC_NVPTX_ENABLED */
774  "__vselect_i32"
775  };
776 
777  int count = sizeof(names) / sizeof(names[0]);
778  for (int i = 0; i < count; ++i) {
779  llvm::Function *f = module->getFunction(names[i]);
780  if (f != NULL && f->empty() == false) {
781  f->setLinkage(llvm::GlobalValue::InternalLinkage);
783  }
784  }
785 }
786 
787 
788 /** This utility function takes serialized binary LLVM bitcode and adds its
789  definitions to the given module. Functions in the bitcode that can be
790  mapped to ispc functions are also added to the symbol table.
791 
792  @param bitcode Binary LLVM bitcode (e.g. the contents of a *.bc file)
793  @param length Length of the bitcode buffer
794  @param module Module to link the bitcode into
795  @param symbolTable Symbol table to add definitions to
796  */
797 void
798 AddBitcodeToModule(const unsigned char *bitcode, int length,
799  llvm::Module *module, SymbolTable *symbolTable, bool warn) {
800  llvm::StringRef sb = llvm::StringRef((char *)bitcode, length);
801 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_5
802  llvm::MemoryBuffer *bcBuf = llvm::MemoryBuffer::getMemBuffer(sb);
803 #else // LLVM 3.6+
804  llvm::MemoryBufferRef bcBuf = llvm::MemoryBuffer::getMemBuffer(sb)->getMemBufferRef();
805 #endif
806 
807 #if ISPC_LLVM_VERSION >= ISPC_LLVM_4_0 // LLVM 4.0+
808  llvm::Expected<std::unique_ptr<llvm::Module>> ModuleOrErr = llvm::parseBitcodeFile(bcBuf, *g->ctx);
809  if (!ModuleOrErr) {
810  Error(SourcePos(), "Error parsing stdlib bitcode: %s", toString(ModuleOrErr.takeError()).c_str());
811  } else {
812  llvm::Module *bcModule = ModuleOrErr.get().release();
813 #elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+
814  llvm::ErrorOr<std::unique_ptr<llvm::Module>> ModuleOrErr = llvm::parseBitcodeFile(bcBuf, *g->ctx);
815  if (std::error_code EC = ModuleOrErr.getError())
816  Error(SourcePos(), "Error parsing stdlib bitcode: %s", EC.message().c_str());
817  else {
818  llvm::Module *bcModule = ModuleOrErr.get().release();
819 #elif ISPC_LLVM_VERSION == ISPC_LLVM_3_5 || ISPC_LLVM_VERSION == ISPC_LLVM_3_6
820  llvm::ErrorOr<llvm::Module *> ModuleOrErr = llvm::parseBitcodeFile(bcBuf, *g->ctx);
821  if (std::error_code EC = ModuleOrErr.getError())
822  Error(SourcePos(), "Error parsing stdlib bitcode: %s", EC.message().c_str());
823  else {
824  llvm::Module *bcModule = ModuleOrErr.get();
825 #else // LLVM 3.2 - 3.4
826  std::string bcErr;
827  llvm::Module *bcModule = llvm::ParseBitcodeFile(bcBuf, *g->ctx, &bcErr);
828  if (!bcModule)
829  Error(SourcePos(), "Error parsing stdlib bitcode: %s", bcErr.c_str());
830  else {
831 #endif
832  // FIXME: this feels like a bad idea, but the issue is that when we
833  // set the llvm::Module's target triple in the ispc Module::Module
834  // constructor, we start by calling llvm::sys::getHostTriple() (and
835  // then change the arch if needed). Somehow that ends up giving us
836  // strings like 'x86_64-apple-darwin11.0.0', while the stuff we
837  // compile to bitcode with clang has module triples like
838  // 'i386-apple-macosx10.7.0'. And then LLVM issues a warning about
839  // linking together modules with incompatible target triples..
840  llvm::Triple mTriple(m->module->getTargetTriple());
841  llvm::Triple bcTriple(bcModule->getTargetTriple());
842  Debug(SourcePos(), "module triple: %s\nbitcode triple: %s\n",
843  mTriple.str().c_str(), bcTriple.str().c_str());
844 #if defined(ISPC_ARM_ENABLED) && !defined(__arm__)
845  // FIXME: More ugly and dangerous stuff. We really haven't set up
846  // proper build and runtime infrastructure for ispc to do
847  // cross-compilation, yet it's at minimum useful to be able to emit
848  // ARM code from x86 for ispc development. One side-effect is that
849  // when the build process turns builtins/builtins.c to LLVM bitcode
850  // for us to link in at runtime, that bitcode has been compiled for
851  // an IA target, which in turn causes the checks in the following
852  // code to (appropraitely) fail.
853  //
854  // In order to be able to have some ability to generate ARM code on
855  // IA, we'll just skip those tests in that case and allow the
856  // setTargetTriple() and setDataLayout() calls below to shove in
857  // the values for an ARM target. This maybe won't cause problems
858  // in the generated code, since bulitins.c doesn't do anything too
859  // complex w.r.t. struct layouts, etc.
860  if (g->target->getISA() != Target::NEON32 &&
861  g->target->getISA() != Target::NEON16 &&
862  g->target->getISA() != Target::NEON8)
863 #endif // !__arm__
864 #ifdef ISPC_NVPTX_ENABLED
865  if (g->target->getISA() != Target::NVPTX)
866 #endif /* ISPC_NVPTX_ENABLED */
867  {
868  Assert(bcTriple.getArch() == llvm::Triple::UnknownArch ||
869  mTriple.getArch() == bcTriple.getArch());
870  Assert(bcTriple.getVendor() == llvm::Triple::UnknownVendor ||
871  mTriple.getVendor() == bcTriple.getVendor());
872 
873  // We unconditionally set module DataLayout to library, but we must
874  // ensure that library and module DataLayouts are compatible.
875  // If they are not, we should recompile the library for problematic
876  // architecture and investigate what happened.
877  // Generally we allow library DataLayout to be subset of module
878  // DataLayout or library DataLayout to be empty.
879 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5
880  if (!VerifyDataLayoutCompatibility(module->getDataLayoutStr(),
881  bcModule->getDataLayoutStr())
882  && warn) {
883  Warning(SourcePos(), "Module DataLayout is incompatible with "
884  "library DataLayout:\n"
885  "Module DL: %s\n"
886  "Library DL: %s\n",
887  module->getDataLayoutStr().c_str(),
888  bcModule->getDataLayoutStr().c_str());
889  }
890 #else
891  if (!VerifyDataLayoutCompatibility(module->getDataLayout(),
892  bcModule->getDataLayout())
893  && warn) {
894  Warning(SourcePos(), "Module DataLayout is incompatible with "
895  "library DataLayout:\n"
896  "Module DL: %s\n"
897  "Library DL: %s\n",
898  module->getDataLayout().c_str(),
899  bcModule->getDataLayout().c_str());
900  }
901 #endif
902  }
903 
904  bcModule->setTargetTriple(mTriple.str());
905  bcModule->setDataLayout(module->getDataLayout());
906 
907 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_5 // 3.2-3.5
908  std::string(linkError);
909 
910  if (llvm::Linker::LinkModules(module, bcModule,
911  llvm::Linker::DestroySource,
912  &linkError))
913  Error(SourcePos(), "Error linking stdlib bitcode: %s", linkError.c_str());
914 #elif ISPC_LLVM_VERSION <= ISPC_LLVM_3_7 // 3.6-3.7
915  llvm::Linker::LinkModules(module, bcModule);
916 #else // LLVM 3.8+
917  // A hack to move over declaration, which have no definition.
918  // New linker is kind of smart and think it knows better what to do, so
919  // it removes unused declarations without definitions.
920  // This trick should be legal, as both modules use the same LLVMContext.
921  for (llvm::Function& f : *bcModule) {
922  if (f.isDeclaration()) {
923  // Declarations with uses will be moved by Linker.
924  if (f.getNumUses() > 0)
925  continue;
926  module->getOrInsertFunction(f.getName(), f.getFunctionType(),
927  f.getAttributes());
928  }
929  }
930 
931  std::unique_ptr<llvm::Module> M(bcModule);
932  if (llvm::Linker::linkModules(*module, std::move(M))) {
933  Error(SourcePos(), "Error linking stdlib bitcode.");
934  }
935 #endif
936 
937  lSetInternalFunctions(module);
938  if (symbolTable != NULL)
939  lAddModuleSymbols(module, symbolTable);
940  lCheckModuleIntrinsics(module);
941  }
942 }
943 
944 
945 /** Utility routine that defines a constant int32 with given value, adding
946  the symbol to both the ispc symbol table and the given LLVM module.
947  */
948 static void
949 lDefineConstantInt(const char *name, int val, llvm::Module *module,
950  SymbolTable *symbolTable, std::vector<llvm::Constant*> &dbg_sym) {
951  Symbol *sym =
952  new Symbol(name, SourcePos(), AtomicType::UniformInt32->GetAsConstType(),
953  SC_STATIC);
954  sym->constValue = new ConstExpr(sym->type, val, SourcePos());
955  llvm::Type *ltype = LLVMTypes::Int32Type;
956  llvm::Constant *linit = LLVMInt32(val);
957 #if ISPC_LLVM_VERSION < ISPC_LLVM_3_6
958  // Use WeakODRLinkage rather than InternalLinkage so that a definition
959  // survives even if it's not used in the module, so that the symbol is
960  // there in the debugger.
961  llvm::GlobalValue::LinkageTypes linkage = g->generateDebuggingSymbols ?
962  llvm::GlobalValue::WeakODRLinkage : llvm::GlobalValue::InternalLinkage;
963  sym->storagePtr = new llvm::GlobalVariable(*module, ltype, true, linkage,
964  linit, name);
965 #else // LLVM 3.6+
966  auto GV = new llvm::GlobalVariable(*module, ltype, true,
967  llvm::GlobalValue::InternalLinkage,
968  linit, name);
969  dbg_sym.push_back(GV);
970  sym->storagePtr = GV;
971 #endif
972  symbolTable->AddVariable(sym);
973 
974  if (m->diBuilder != NULL) {
975 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
976  llvm::DIFile file;
977  llvm::DIType diType = sym->type->GetDIType(file);
978  Assert(diType.Verify());
979 #else // LLVM 3.7+
980  llvm::DIFile *file = m->diCompileUnit->getFile();
981  llvm::DICompileUnit *cu = m->diCompileUnit;
982  llvm::DIType *diType = sym->type->GetDIType(file);
983 #endif
984  // FIXME? DWARF says that this (and programIndex below) should
985  // have the DW_AT_artifical attribute. It's not clear if this
986  // matters for anything though.
987 
988 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_5
989  llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable(
990  name,
991  file,
992  0 /* line */,
993  diType,
994  true /* static */,
995  sym->storagePtr);
996 #elif ISPC_LLVM_VERSION == ISPC_LLVM_3_6 // LLVM 3.6
997  llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
998  Assert(sym_const_storagePtr);
999  llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable(
1000  file,
1001  name,
1002  name,
1003  file,
1004  0 /* line */,
1005  diType,
1006  true /* static */,
1007  sym_const_storagePtr);
1008 #elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 && ISPC_LLVM_VERSION <= ISPC_LLVM_3_9 // LLVM 3.7 - 3.9
1009  llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
1010  Assert(sym_const_storagePtr);
1011  m->diBuilder->createGlobalVariable(
1012  cu,
1013  name,
1014  name,
1015  file,
1016  0 /* line */,
1017  diType,
1018  true /* static */,
1019  sym_const_storagePtr);
1020 #else // LLVM 4.0+
1021  llvm::GlobalVariable *sym_GV_storagePtr = llvm::dyn_cast<llvm::GlobalVariable>(sym->storagePtr);
1022  llvm::DIGlobalVariableExpression *var = m->diBuilder->createGlobalVariableExpression(
1023  cu,
1024  name,
1025  name,
1026  file,
1027  0 /* line */,
1028  diType,
1029  true /* static */);
1030  sym_GV_storagePtr->addDebugInfo(var);
1031 #endif
1032 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
1033  Assert(var.Verify());
1034 #else // LLVM 3.7+
1035  //coming soon
1036 #endif
1037  }
1038 }
1039 
1040 
1041 
1042 static void
1043 lDefineConstantIntFunc(const char *name, int val, llvm::Module *module,
1044  SymbolTable *symbolTable, std::vector<llvm::Constant*> &dbg_sym) {
1045  llvm::SmallVector<const Type *, 8> args;
1047  Symbol *sym = new Symbol(name, SourcePos(), ft, SC_STATIC);
1048 
1049  llvm::Function *func = module->getFunction(name);
1050  dbg_sym.push_back(func);
1051  Assert(func != NULL); // it should be declared already...
1052 #if ISPC_LLVM_VERSION == ISPC_LLVM_3_2
1053  func->addFnAttr(llvm::Attributes::AlwaysInline);
1054 #else // LLVM 3.3+
1055  func->addFnAttr(llvm::Attribute::AlwaysInline);
1056 #endif
1057  llvm::BasicBlock *bblock = llvm::BasicBlock::Create(*g->ctx, "entry", func, 0);
1058  llvm::ReturnInst::Create(*g->ctx, LLVMInt32(val), bblock);
1059 
1060  sym->function = func;
1061  symbolTable->AddVariable(sym);
1062 }
1063 
1064 
1065 
1066 static void
1067 lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable, std::vector<llvm::Constant*> &dbg_sym) {
1068  Symbol *sym =
1069  new Symbol("programIndex", SourcePos(),
1070  AtomicType::VaryingInt32->GetAsConstType(), SC_STATIC);
1071 
1072  int pi[ISPC_MAX_NVEC];
1073  for (int i = 0; i < g->target->getVectorWidth(); ++i)
1074  pi[i] = i;
1075  sym->constValue = new ConstExpr(sym->type, pi, SourcePos());
1076 
1077  llvm::Type *ltype = LLVMTypes::Int32VectorType;
1078  llvm::Constant *linit = LLVMInt32Vector(pi);
1079 #if ISPC_LLVM_VERSION < ISPC_LLVM_3_6
1080  // See comment in lDefineConstantInt() for why WeakODRLinkage is used here
1081  llvm::GlobalValue::LinkageTypes linkage = g->generateDebuggingSymbols ?
1082  llvm::GlobalValue::WeakODRLinkage : llvm::GlobalValue::InternalLinkage;
1083  sym->storagePtr = new llvm::GlobalVariable(*module, ltype, true, linkage,
1084  linit, sym->name.c_str());
1085 #else // LLVM 3.6+
1086  auto GV = new llvm::GlobalVariable(*module, ltype, true,
1087  llvm::GlobalValue::InternalLinkage,
1088  linit, sym->name.c_str());
1089  dbg_sym.push_back(GV);
1090  sym->storagePtr = GV;
1091 #endif
1092  symbolTable->AddVariable(sym);
1093 
1094  if (m->diBuilder != NULL) {
1095 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
1096  llvm::DIFile file;
1097  llvm::DIType diType = sym->type->GetDIType(file);
1098  Assert(diType.Verify());
1099 #else // LLVM 3.7+
1100  llvm::DIFile *file = m->diCompileUnit->getFile();
1101  llvm::DICompileUnit *cu = m->diCompileUnit;
1102  llvm::DIType *diType = sym->type->GetDIType(file);
1103 #endif
1104 #if ISPC_LLVM_VERSION == ISPC_LLVM_3_6 // LLVM 3.6
1105  llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
1106  Assert(sym_const_storagePtr);
1107  llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable(
1108  file,
1109  sym->name.c_str(),
1110  sym->name.c_str(),
1111  file,
1112  0 /* line */,
1113  diType,
1114  false /* static */,
1115  sym_const_storagePtr);
1116 #elif ISPC_LLVM_VERSION <= ISPC_LLVM_3_5
1117  llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable(
1118  sym->name.c_str(),
1119  file,
1120  0 /* line */,
1121  diType,
1122  false /* static */,
1123  sym->storagePtr);
1124 #elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 && ISPC_LLVM_VERSION <= ISPC_LLVM_3_9 // LLVM 3.7 - 3.9
1125  llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
1126  Assert(sym_const_storagePtr);
1127  m->diBuilder->createGlobalVariable(
1128  cu,
1129  sym->name.c_str(),
1130  sym->name.c_str(),
1131  file,
1132  0 /* line */,
1133  diType,
1134  false /* static */,
1135  sym_const_storagePtr);
1136 #else // LLVM 4.0+
1137  llvm::GlobalVariable *sym_GV_storagePtr = llvm::dyn_cast<llvm::GlobalVariable>(sym->storagePtr);
1138  llvm::DIGlobalVariableExpression *var = m->diBuilder->createGlobalVariableExpression(
1139  cu,
1140  sym->name.c_str(),
1141  sym->name.c_str(),
1142  file,
1143  0 /* line */,
1144  diType,
1145  false /* static */);
1146  sym_GV_storagePtr->addDebugInfo(var);
1147 #endif
1148 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
1149  Assert(var.Verify());
1150 #else // LLVM 3.7+
1151  //coming soon
1152 #endif
1153  }
1154 }
1155 
1156 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 // LLVM 3.6+
1157 static void emitLLVMUsed(llvm::Module& module, std::vector<llvm::Constant*> &list) {
1158  // Convert list to what ConstantArray needs.
1159  llvm::SmallVector<llvm::Constant*, 8> UsedArray;
1160  UsedArray.reserve(list.size());
1161  for (auto c : list) {
1162  UsedArray.push_back(
1163  llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
1164  llvm::cast<llvm::Constant>(c), LLVMTypes::Int8PointerType));
1165  }
1166 
1167  llvm::ArrayType *ATy = llvm::ArrayType::get(LLVMTypes::Int8PointerType, UsedArray.size());
1168 
1169  auto *GV = new llvm::GlobalVariable(module, ATy, false, llvm::GlobalValue::AppendingLinkage,
1170  llvm::ConstantArray::get(ATy, UsedArray), "llvm.used");
1171 
1172  GV->setSection("llvm.metadata");
1173 }
1174 #endif
1175 
1176 void
1177 DefineStdlib(SymbolTable *symbolTable, llvm::LLVMContext *ctx, llvm::Module *module,
1178  bool includeStdlibISPC) {
1179  // debug_symbols are symbols that supposed to be preserved in debug information.
1180  // They will be referenced in llvm.used intrinsic to prevent they removal from
1181  // the object file.
1182  std::vector<llvm::Constant*> debug_symbols;
1183  bool runtime32 = g->target->is32Bit();
1184  bool warn = g->target->getISA() != Target::GENERIC;
1185 
1186 #define EXPORT_MODULE_COND_WARN(export_module, warnings) \
1187  extern unsigned char export_module[]; \
1188  extern int export_module##_length; \
1189  AddBitcodeToModule(export_module, export_module##_length, \
1190  module, symbolTable, warnings);
1191 
1192 #define EXPORT_MODULE(export_module) \
1193  extern unsigned char export_module[]; \
1194  extern int export_module##_length; \
1195  AddBitcodeToModule(export_module, export_module##_length, \
1196  module, symbolTable, true);
1197 
1198  // Add the definitions from the compiled builtins.c file.
1199  // When compiling for "generic" target family, data layout warnings for
1200  // "builtins_bitcode_c" have to be switched off: its DL is incompatible
1201  // with the DL of "generic". Anyway, AddBitcodeToModule() corrects this
1202  // automatically if DLs differ (by copying module`s DL to export`s DL).
1203  if (runtime32) {
1204  EXPORT_MODULE_COND_WARN(builtins_bitcode_c_32, warn);
1205  }
1206  else {
1207  EXPORT_MODULE_COND_WARN(builtins_bitcode_c_64, warn);
1208  }
1209 
1210  // Next, add the target's custom implementations of the various needed
1211  // builtin functions (e.g. __masked_store_32(), etc).
1212  switch (g->target->getISA()) {
1213 #ifdef ISPC_NVPTX_ENABLED
1214  case Target::NVPTX:
1215  {
1216  if (runtime32) {
1217  fprintf(stderr, "Unfortunatly 32bit targets are not supported at the moment .. \n");
1218  assert(0);
1219  }
1220  else {
1221  EXPORT_MODULE(builtins_bitcode_nvptx_64bit);
1222  }
1223  break;
1224  };
1225 #endif /* ISPC_NVPTX_ENABLED */
1226 
1227 #ifdef ISPC_ARM_ENABLED
1228  case Target::NEON8: {
1229  if (runtime32) {
1230  EXPORT_MODULE(builtins_bitcode_neon_8_32bit);
1231  }
1232  else {
1233  EXPORT_MODULE(builtins_bitcode_neon_8_64bit);
1234  }
1235  break;
1236  }
1237  case Target::NEON16: {
1238  if (runtime32) {
1239  EXPORT_MODULE(builtins_bitcode_neon_16_32bit);
1240  }
1241  else {
1242  EXPORT_MODULE(builtins_bitcode_neon_16_64bit);
1243  }
1244  break;
1245  }
1246  case Target::NEON32: {
1247  if (runtime32) {
1248  EXPORT_MODULE(builtins_bitcode_neon_32_32bit);
1249  }
1250  else {
1251  EXPORT_MODULE(builtins_bitcode_neon_32_64bit);
1252  }
1253  break;
1254  }
1255 #endif
1256  case Target::SSE2: {
1257  switch (g->target->getVectorWidth()) {
1258  case 4:
1259  if (runtime32) {
1260  EXPORT_MODULE(builtins_bitcode_sse2_32bit);
1261  }
1262  else {
1263  EXPORT_MODULE(builtins_bitcode_sse2_64bit);
1264  }
1265  break;
1266  case 8:
1267  if (runtime32) {
1268  EXPORT_MODULE(builtins_bitcode_sse2_x2_32bit);
1269  }
1270  else {
1271  EXPORT_MODULE(builtins_bitcode_sse2_x2_64bit);
1272  }
1273  break;
1274  default:
1275  FATAL("logic error in DefineStdlib");
1276  }
1277  break;
1278  }
1279  case Target::SSE4: {
1280  switch (g->target->getVectorWidth()) {
1281  case 4:
1282  if (runtime32) {
1283  EXPORT_MODULE(builtins_bitcode_sse4_32bit);
1284  }
1285  else {
1286  EXPORT_MODULE(builtins_bitcode_sse4_64bit);
1287  }
1288  break;
1289  case 8:
1290  if (runtime32) {
1291  if (g->target->getMaskBitCount() == 16) {
1292  EXPORT_MODULE(builtins_bitcode_sse4_16_32bit);
1293  }
1294  else {
1295  Assert(g->target->getMaskBitCount() == 32);
1296  EXPORT_MODULE(builtins_bitcode_sse4_x2_32bit);
1297  }
1298  }
1299  else {
1300  if (g->target->getMaskBitCount() == 16) {
1301  EXPORT_MODULE(builtins_bitcode_sse4_16_64bit);
1302  }
1303  else {
1304  Assert(g->target->getMaskBitCount() == 32);
1305  EXPORT_MODULE(builtins_bitcode_sse4_x2_64bit);
1306  }
1307  }
1308  break;
1309  case 16:
1310  Assert(g->target->getMaskBitCount() == 8);
1311  if (runtime32) {
1312  EXPORT_MODULE(builtins_bitcode_sse4_8_32bit);
1313  }
1314  else {
1315  EXPORT_MODULE(builtins_bitcode_sse4_8_64bit);
1316  }
1317  break;
1318  default:
1319  FATAL("logic error in DefineStdlib");
1320  }
1321  break;
1322  }
1323  case Target::AVX: {
1324  switch (g->target->getVectorWidth()) {
1325  case 4:
1326  if (g->target->getDataTypeWidth() == 32) {
1327  // Note here that for avx1-i32x4 we are using bitcode file for
1328  // sse4-i32x4. This is intentional and good enough.
1329  // AVX target implies appropriate target-feature attrbute,
1330  // which forces LLVM to generate AVX code, even for SSE4
1331  // intrinsics. Except that the only "missing" feature in sse4
1332  // target is implemenation of __masked_[store|load]_[i32|i64]
1333  // using maskmov instruction. But it's not very popular
1334  // intrinsics, so we assume the implementation to be good
1335  // enough at the moment.
1336  if (runtime32) {
1337  EXPORT_MODULE(builtins_bitcode_sse4_32bit);
1338  }
1339  else {
1340  EXPORT_MODULE(builtins_bitcode_sse4_64bit);
1341  }
1342  } else if (g->target->getDataTypeWidth() == 64) {
1343  if (runtime32) {
1344  EXPORT_MODULE(builtins_bitcode_avx1_i64x4_32bit);
1345  }
1346  else {
1347  EXPORT_MODULE(builtins_bitcode_avx1_i64x4_64bit);
1348  }
1349  } else {
1350  FATAL("logic error in DefineStdlib");
1351  }
1352  break;
1353  case 8:
1354  if (runtime32) {
1355  EXPORT_MODULE(builtins_bitcode_avx1_32bit);
1356  }
1357  else {
1358  EXPORT_MODULE(builtins_bitcode_avx1_64bit);
1359  }
1360  break;
1361  case 16:
1362  if (runtime32) {
1363  EXPORT_MODULE(builtins_bitcode_avx1_x2_32bit);
1364  }
1365  else {
1366  EXPORT_MODULE(builtins_bitcode_avx1_x2_64bit);
1367  }
1368  break;
1369  default:
1370  FATAL("logic error in DefineStdlib");
1371  }
1372  break;
1373  }
1374  case Target::AVX11: {
1375  switch (g->target->getVectorWidth()) {
1376  case 4:
1377  if (runtime32) {
1378  EXPORT_MODULE(builtins_bitcode_avx11_i64x4_32bit);
1379  }
1380  else {
1381  EXPORT_MODULE(builtins_bitcode_avx11_i64x4_64bit);
1382  }
1383  break;
1384  case 8:
1385  if (runtime32) {
1386  EXPORT_MODULE(builtins_bitcode_avx11_32bit);
1387  }
1388  else {
1389  EXPORT_MODULE(builtins_bitcode_avx11_64bit);
1390  }
1391  break;
1392  case 16:
1393  if (runtime32) {
1394  EXPORT_MODULE(builtins_bitcode_avx11_x2_32bit);
1395  }
1396  else {
1397  EXPORT_MODULE(builtins_bitcode_avx11_x2_64bit);
1398  }
1399  break;
1400  default:
1401  FATAL("logic error in DefineStdlib");
1402  }
1403  break;
1404  }
1405  case Target::AVX2: {
1406  switch (g->target->getVectorWidth()) {
1407  case 4:
1408  if (runtime32) {
1409  EXPORT_MODULE(builtins_bitcode_avx2_i64x4_32bit);
1410  }
1411  else {
1412  EXPORT_MODULE(builtins_bitcode_avx2_i64x4_64bit);
1413  }
1414  break;
1415  case 8:
1416  if (runtime32) {
1417  EXPORT_MODULE(builtins_bitcode_avx2_32bit);
1418  }
1419  else {
1420  EXPORT_MODULE(builtins_bitcode_avx2_64bit);
1421  }
1422  break;
1423  case 16:
1424  if (runtime32) {
1425  EXPORT_MODULE(builtins_bitcode_avx2_x2_32bit);
1426  }
1427  else {
1428  EXPORT_MODULE(builtins_bitcode_avx2_x2_64bit);
1429  }
1430  break;
1431  default:
1432  FATAL("logic error in DefineStdlib");
1433  }
1434  break;
1435  }
1436 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+
1437  case Target::KNL_AVX512: {
1438  switch (g->target->getVectorWidth()) {
1439  case 16:
1440  if (runtime32) {
1441  EXPORT_MODULE(builtins_bitcode_knl_32bit);
1442  }
1443  else {
1444  EXPORT_MODULE(builtins_bitcode_knl_64bit);
1445  }
1446  break;
1447  default:
1448  FATAL("logic error in DefineStdlib");
1449  }
1450  break;
1451  }
1452 #endif
1453 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_8 // LLVM 3.8+
1454  case Target::SKX_AVX512: {
1455  switch (g->target->getVectorWidth()) {
1456  case 16:
1457  if (runtime32) {
1458  EXPORT_MODULE(builtins_bitcode_skx_32bit);
1459  }
1460  else {
1461  EXPORT_MODULE(builtins_bitcode_skx_64bit);
1462  }
1463  break;
1464  default:
1465  FATAL("logic error in DefineStdlib");
1466  }
1467  break;
1468  }
1469 #endif
1470  case Target::GENERIC: {
1471  switch (g->target->getVectorWidth()) {
1472  case 4:
1473  if (runtime32) {
1474  EXPORT_MODULE(builtins_bitcode_generic_4_32bit);
1475  }
1476  else {
1477  EXPORT_MODULE(builtins_bitcode_generic_4_64bit);
1478  }
1479  break;
1480  case 8:
1481  if (runtime32) {
1482  EXPORT_MODULE(builtins_bitcode_generic_8_32bit);
1483  }
1484  else {
1485  EXPORT_MODULE(builtins_bitcode_generic_8_64bit);
1486  }
1487  break;
1488  case 16:
1489  if (runtime32) {
1490  EXPORT_MODULE(builtins_bitcode_generic_16_32bit);
1491  }
1492  else {
1493  EXPORT_MODULE(builtins_bitcode_generic_16_64bit);
1494  }
1495  break;
1496  case 32:
1497  if (runtime32) {
1498  EXPORT_MODULE(builtins_bitcode_generic_32_32bit);
1499  }
1500  else {
1501  EXPORT_MODULE(builtins_bitcode_generic_32_64bit);
1502  }
1503  break;
1504  case 64:
1505  if (runtime32) {
1506  EXPORT_MODULE(builtins_bitcode_generic_64_32bit);
1507  }
1508  else {
1509  EXPORT_MODULE(builtins_bitcode_generic_64_64bit);
1510  }
1511  break;
1512  case 1:
1513  if (runtime32) {
1514  EXPORT_MODULE(builtins_bitcode_generic_1_32bit);
1515  }
1516  else {
1517  EXPORT_MODULE(builtins_bitcode_generic_1_64bit);
1518  }
1519  break;
1520  default:
1521  FATAL("logic error in DefineStdlib");
1522  }
1523  break;
1524  }
1525  default:
1526  FATAL("logic error");
1527  }
1528 
1529  // define the 'programCount' builtin variable
1530 #ifdef ISPC_NVPTX_ENABLED
1531  if (g->target->getISA() == Target::NVPTX)
1532  {
1533  lDefineConstantInt("programCount", 32, module, symbolTable, debug_symbols);
1534  }
1535  else
1536  {
1537 #endif /* ISPC_NVPTX_ENABLED */
1538  lDefineConstantInt("programCount", g->target->getVectorWidth(), module, symbolTable, debug_symbols);
1539 #ifdef ISPC_NVPTX_ENABLED
1540  }
1541 #endif /* ISPC_NVPTX_ENABLED */
1542 
1543  // define the 'programIndex' builtin
1544  lDefineProgramIndex(module, symbolTable, debug_symbols);
1545 
1546  // Define __math_lib stuff. This is used by stdlib.ispc, for example, to
1547  // figure out which math routines to end up calling...
1548  lDefineConstantInt("__math_lib", (int)g->mathLib, module, symbolTable, debug_symbols);
1549  lDefineConstantInt("__math_lib_ispc", (int)Globals::Math_ISPC, module,
1550  symbolTable, debug_symbols);
1551  lDefineConstantInt("__math_lib_ispc_fast", (int)Globals::Math_ISPCFast,
1552  module, symbolTable, debug_symbols);
1553  lDefineConstantInt("__math_lib_svml", (int)Globals::Math_SVML, module,
1554  symbolTable, debug_symbols);
1555  lDefineConstantInt("__math_lib_system", (int)Globals::Math_System, module,
1556  symbolTable, debug_symbols);
1557  lDefineConstantIntFunc("__fast_masked_vload", (int)g->opt.fastMaskedVload,
1558  module, symbolTable, debug_symbols);
1559 
1560  lDefineConstantInt("__have_native_half", g->target->hasHalf(), module,
1561  symbolTable, debug_symbols);
1562  lDefineConstantInt("__have_native_rand", g->target->hasRand(), module,
1563  symbolTable, debug_symbols);
1564  lDefineConstantInt("__have_native_transcendentals", g->target->hasTranscendentals(),
1565  module, symbolTable, debug_symbols);
1566  lDefineConstantInt("__have_native_trigonometry", g->target->hasTrigonometry(),
1567  module, symbolTable, debug_symbols);
1568  lDefineConstantInt("__have_native_rsqrtd", g->target->hasRsqrtd(),
1569  module, symbolTable, debug_symbols);
1570  lDefineConstantInt("__have_native_rcpd", g->target->hasRcpd(),
1571  module, symbolTable, debug_symbols);
1572 
1573 #ifdef ISPC_NVPTX_ENABLED
1574  lDefineConstantInt("__is_nvptx_target", (int)(g->target->getISA() == Target::NVPTX),
1575  module, symbolTable, debug_symbols);
1576 #else
1577  lDefineConstantInt("__is_nvptx_target", (int)0, module, symbolTable, debug_symbols);
1578 #endif /* ISPC_NVPTX_ENABLED */
1579 
1580  if (g->forceAlignment != -1) {
1581  llvm::GlobalVariable *alignment = module->getGlobalVariable("memory_alignment", true);
1582  alignment->setInitializer(LLVMInt32(g->forceAlignment));
1583  }
1584 
1585  // LLVM 3.6 is only because it was not tested with earlier versions.
1586 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 // LLVM 3.6+
1587  if (g->generateDebuggingSymbols) {
1588  emitLLVMUsed(*module, debug_symbols);
1589  }
1590 #endif
1591 
1592  if (includeStdlibISPC) {
1593  // If the user wants the standard library to be included, parse the
1594  // serialized version of the stdlib.ispc file to get its
1595  // definitions added.
1596  extern char stdlib_mask1_code[], stdlib_mask8_code[];
1597  extern char stdlib_mask16_code[], stdlib_mask32_code[], stdlib_mask64_code[];
1598  if (g->target->getISA() == Target::GENERIC &&
1599  g->target->getVectorWidth() == 1) { // 1 wide uses 32 stdlib
1600  yy_scan_string(stdlib_mask32_code);
1601  }
1602  else {
1603  switch (g->target->getMaskBitCount()) {
1604  case 1:
1605  yy_scan_string(stdlib_mask1_code);
1606  break;
1607  case 8:
1608  yy_scan_string(stdlib_mask8_code);
1609  break;
1610  case 16:
1611  yy_scan_string(stdlib_mask16_code);
1612  break;
1613  case 32:
1614  yy_scan_string(stdlib_mask32_code);
1615  break;
1616  case 64:
1617  yy_scan_string(stdlib_mask64_code);
1618  break;
1619  default:
1620  FATAL("Unhandled mask bit size for stdlib.ispc");
1621  }
1622  }
1623  yyparse();
1624  }
1625 }
llvm::Value * storagePtr
Definition: sym.h:72
static const AtomicType * VaryingInt32
Definition: type.h:349
static llvm::Type * FloatType
Definition: llvmutil.h:80
static bool lCreateISPCSymbol(llvm::Function *func, SymbolTable *symbolTable)
Definition: builtins.cpp:200
void AddBitcodeToModule(const unsigned char *bitcode, int length, llvm::Module *module, SymbolTable *symbolTable, bool warn)
Definition: builtins.cpp:798
static const AtomicType * VaryingInt16
Definition: type.h:348
llvm::Function * function
Definition: sym.h:76
static llvm::Type * Int32VectorPointerType
Definition: llvmutil.h:103
void DefineStdlib(SymbolTable *symbolTable, llvm::LLVMContext *ctx, llvm::Module *module, bool includeStdlibISPC)
Definition: builtins.cpp:1177
std::string GetString() const
Definition: type.cpp:3127
Opt opt
Definition: ispc.h:547
Declaration of the FunctionEmitContext class
bool AddFunction(Symbol *symbol)
Definition: sym.cpp:147
static const AtomicType * VaryingUInt64
Definition: type.h:355
static llvm::Type * DoubleType
Definition: llvmutil.h:81
#define EXPORT_MODULE_COND_WARN(export_module, warnings)
int getVectorWidth() const
Definition: ispc.h:285
Module * m
Definition: ispc.cpp:93
static void lCheckModuleIntrinsics(llvm::Module *module)
Definition: builtins.cpp:303
Target * target
Definition: ispc.h:549
bool hasRsqrtd() const
Definition: ispc.h:305
bool AddVariable(Symbol *symbol)
Definition: sym.cpp:98
static const AtomicType * VaryingDouble
Definition: type.h:356
int getDataTypeWidth() const
Definition: ispc.h:283
Expression representing a compile-time constant value.
Definition: expr.h:390
static llvm::Type * BoolType
Definition: llvmutil.h:74
#define Assert(expr)
Definition: ispc.h:172
Symbol table that holds all known symbols during parsing and compilation.
Definition: sym.h:119
llvm::Constant * LLVMInt32Vector(int32_t i)
Definition: llvmutil.cpp:379
static llvm::VectorType * Int32VectorType
Definition: llvmutil.h:96
static const AtomicType * UniformUInt32
Definition: type.h:352
static llvm::Type * FloatVectorPointerType
Definition: llvmutil.h:105
Declarations of functions related to builtins and the standard library.
static llvm::Type * Int8PointerType
Definition: llvmutil.h:83
static llvm::Type * Int32PointerType
Definition: llvmutil.h:85
std::string name
Definition: sym.h:71
static llvm::Type * Int16VectorPointerType
Definition: llvmutil.h:102
static llvm::Type * Int16Type
Definition: llvmutil.h:77
static llvm::Type * DoubleVectorPointerType
Definition: llvmutil.h:106
#define EXPORT_MODULE(export_module)
static const AtomicType * UniformUInt16
Definition: type.h:351
static void lSetInternalFunctions(llvm::Module *module)
Definition: builtins.cpp:342
static PointerType * GetUniform(const Type *t, bool isSlice=false)
Definition: type.cpp:1015
ConstExpr * constValue
Definition: sym.h:87
bool hasRand() const
Definition: ispc.h:295
header file with declarations for symbol and symbol table classes.
static const AtomicType * UniformBool
Definition: type.h:346
static llvm::Type * VoidType
Definition: llvmutil.h:71
llvm::ConstantInt * LLVMInt32(int32_t i)
Definition: llvmutil.cpp:263
llvm::Module * module
Definition: module.h:158
static llvm::Type * Int8VectorPointerType
Definition: llvmutil.h:101
Globals * g
Definition: ispc.cpp:92
static const AtomicType * UniformUInt64
Definition: type.h:355
int getMaskBitCount() const
Definition: ispc.h:291
static llvm::VectorType * Int8VectorType
Definition: llvmutil.h:94
void Error(SourcePos p, const char *format,...) PRINTF_FUNC
Definition: util.cpp:385
bool hasHalf() const
Definition: ispc.h:293
bool VerifyDataLayoutCompatibility(const std::string &module_dl, const std::string &lib_dl)
Definition: util.cpp:603
static llvm::VectorType * FloatVectorType
Definition: llvmutil.h:98
static llvm::Type * Int64Type
Definition: llvmutil.h:79
static llvm::Type * Int8Type
Definition: llvmutil.h:76
virtual llvm::DIType GetDIType(llvm::DIDescriptor scope) const =0
static llvm::VectorType * Int64VectorType
Definition: llvmutil.h:97
Header file with declarations for various LLVM utility stuff.
ISA getISA() const
Definition: ispc.h:269
static llvm::Type * Int64PointerType
Definition: llvmutil.h:86
bool hasRcpd() const
Definition: ispc.h:307
static llvm::Type * FloatPointerType
Definition: llvmutil.h:87
static void lAddModuleSymbols(llvm::Module *module, SymbolTable *symbolTable)
Definition: builtins.cpp:278
Representation of a range of positions in a source file.
Definition: ispc.h:136
static llvm::Type * Int16PointerType
Definition: llvmutil.h:84
bool generateDebuggingSymbols
Definition: ispc.h:613
static const AtomicType * VaryingBool
Definition: type.h:346
bool fastMaskedVload
Definition: ispc.h:447
const char * name
Definition: ispc.h:140
void markFuncWithTargetAttr(llvm::Function *func)
Definition: ispc.cpp:1485
static void lDefineConstantInt(const char *name, int val, llvm::Module *module, SymbolTable *symbolTable, std::vector< llvm::Constant * > &dbg_sym)
Definition: builtins.cpp:949
void Warning(SourcePos p, const char *format,...) PRINTF_FUNC
Definition: util.cpp:410
static const AtomicType * VaryingInt64
Definition: type.h:354
static void lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable, std::vector< llvm::Constant * > &dbg_sym)
Definition: builtins.cpp:1067
#define FATAL(message)
Definition: util.h:113
int yyparse()
static const AtomicType * UniformUInt8
Definition: type.h:350
static llvm::Type * Int64VectorPointerType
Definition: llvmutil.h:104
static llvm::Type * Int32Type
Definition: llvmutil.h:78
MathLib mathLib
Definition: ispc.h:554
static llvm::Type * DoublePointerType
Definition: llvmutil.h:88
bool hasTrigonometry() const
Definition: ispc.h:303
#define ISPC_MAX_NVEC
Definition: ispc.h:68
static bool Equal(const Type *a, const Type *b)
Definition: type.cpp:3735
static const AtomicType * VaryingUInt16
Definition: type.h:351
static const AtomicType * VaryingInt8
Definition: type.h:347
static const AtomicType * UniformFloat
Definition: type.h:353
static const AtomicType * UniformInt32
Definition: type.h:349
Type representing a function (return type + argument types)
Definition: type.h:884
Representation of a program symbol.
Definition: sym.h:63
Interface class that defines the type abstraction.
Definition: type.h:101
static const AtomicType * UniformDouble
Definition: type.h:356
Expr abstract base class and expression implementations.
static const AtomicType * Void
Definition: type.h:357
static llvm::VectorType * MaskType
Definition: llvmutil.h:90
int forceAlignment
Definition: ispc.h:654
yy_buffer_state * yy_scan_string(const char *)
static llvm::VectorType * DoubleVectorType
Definition: llvmutil.h:99
static llvm::VectorType * Int16VectorType
Definition: llvmutil.h:95
static const AtomicType * VaryingUInt8
Definition: type.h:350
Declaration of the Module class, which is the ispc-side representation of the results of compiling a ...
static const AtomicType * UniformInt64
Definition: type.h:354
llvm::LLVMContext * ctx
Definition: ispc.h:638
static const AtomicType * UniformInt16
Definition: type.h:348
static void lDefineConstantIntFunc(const char *name, int val, llvm::Module *module, SymbolTable *symbolTable, std::vector< llvm::Constant * > &dbg_sym)
Definition: builtins.cpp:1043
const Type * type
Definition: sym.h:84
llvm::DIBuilder * diBuilder
Definition: module.h:161
void Debug(SourcePos p, const char *format,...) PRINTF_FUNC
Definition: util.cpp:398
bool is32Bit() const
Definition: ispc.h:275
static const Type * lLLVMTypeToISPCType(const llvm::Type *t, bool intAsUnsigned)
Definition: builtins.cpp:100
static const AtomicType * VaryingUInt32
Definition: type.h:352
static const AtomicType * VaryingFloat
Definition: type.h:353
static void lCreateSymbol(const std::string &name, const Type *returnType, llvm::SmallVector< const Type *, 8 > &argTypes, const llvm::FunctionType *ftype, llvm::Function *func, SymbolTable *symbolTable)
Definition: builtins.cpp:177
static const AtomicType * UniformInt8
Definition: type.h:347
File with declarations for classes related to type representation.
bool hasTranscendentals() const
Definition: ispc.h:301