Intel SPMD Program Compiler  1.10.0
builtins.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010-2018, 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_double",
355  "__aos_to_soa3_double1",
356  "__aos_to_soa3_double16",
357  "__aos_to_soa3_double4",
358  "__aos_to_soa3_double8",
359  "__aos_to_soa3_int64",
360  "__aos_to_soa3_float",
361 //#ifdef ISPC_NVPTX_ENABLED
362  "__aos_to_soa3_float1",
363 //#endif /* ISPC_NVPTX_ENABLED */
364  "__aos_to_soa3_float16",
365  "__aos_to_soa3_float4",
366  "__aos_to_soa3_float8",
367  "__aos_to_soa3_int32",
368  "__aos_to_soa4_double",
369  "__aos_to_soa4_double1",
370  "__aos_to_soa4_double16",
371  "__aos_to_soa4_double4",
372  "__aos_to_soa4_double8",
373  "__aos_to_soa4_int64",
374  "__aos_to_soa4_float",
375 //#ifdef ISPC_NVPTX_ENABLED
376  "__aos_to_soa4_float1",
377 //#endif /* ISPC_NVPTX_ENABLED */
378  "__aos_to_soa4_float16",
379  "__aos_to_soa4_float4",
380  "__aos_to_soa4_float8",
381  "__aos_to_soa4_int32",
382  "__atomic_add_int32_global",
383  "__atomic_add_int64_global",
384  "__atomic_add_uniform_int32_global",
385  "__atomic_add_uniform_int64_global",
386  "__atomic_and_int32_global",
387  "__atomic_and_int64_global",
388  "__atomic_and_uniform_int32_global",
389  "__atomic_and_uniform_int64_global",
390  "__atomic_compare_exchange_double_global",
391  "__atomic_compare_exchange_float_global",
392  "__atomic_compare_exchange_int32_global",
393  "__atomic_compare_exchange_int64_global",
394  "__atomic_compare_exchange_uniform_double_global",
395  "__atomic_compare_exchange_uniform_float_global",
396  "__atomic_compare_exchange_uniform_int32_global",
397  "__atomic_compare_exchange_uniform_int64_global",
398  "__atomic_max_uniform_int32_global",
399  "__atomic_max_uniform_int64_global",
400  "__atomic_min_uniform_int32_global",
401  "__atomic_min_uniform_int64_global",
402  "__atomic_or_int32_global",
403  "__atomic_or_int64_global",
404  "__atomic_or_uniform_int32_global",
405  "__atomic_or_uniform_int64_global",
406  "__atomic_sub_int32_global",
407  "__atomic_sub_int64_global",
408  "__atomic_sub_uniform_int32_global",
409  "__atomic_sub_uniform_int64_global",
410  "__atomic_swap_double_global",
411  "__atomic_swap_float_global",
412  "__atomic_swap_int32_global",
413  "__atomic_swap_int64_global",
414  "__atomic_swap_uniform_double_global",
415  "__atomic_swap_uniform_float_global",
416  "__atomic_swap_uniform_int32_global",
417  "__atomic_swap_uniform_int64_global",
418  "__atomic_umax_uniform_uint32_global",
419  "__atomic_umax_uniform_uint64_global",
420  "__atomic_umin_uniform_uint32_global",
421  "__atomic_umin_uniform_uint64_global",
422  "__atomic_xor_int32_global",
423  "__atomic_xor_int64_global",
424  "__atomic_xor_uniform_int32_global",
425  "__atomic_xor_uniform_int64_global",
426 //#ifdef ISPC_NVPTX_ENABLED
427  "__atomic_add_varying_int32_global",
428  "__atomic_add_varying_int64_global",
429  "__atomic_and_varying_int32_global",
430  "__atomic_and_varying_int64_global",
431  "__atomic_compare_exchange_varying_double_global",
432  "__atomic_compare_exchange_varying_float_global",
433  "__atomic_compare_exchange_varying_int32_global",
434  "__atomic_compare_exchange_varying_int64_global",
435  "__atomic_max_varying_int32_global",
436  "__atomic_max_varying_int64_global",
437  "__atomic_min_varying_int32_global",
438  "__atomic_min_varying_int64_global",
439  "__atomic_or_varying_int32_global",
440  "__atomic_or_varying_int64_global",
441  "__atomic_sub_varying_int32_global",
442  "__atomic_sub_varying_int64_global",
443  "__atomic_swap_varying_double_global",
444  "__atomic_swap_varying_float_global",
445  "__atomic_swap_varying_int32_global",
446  "__atomic_swap_varying_int64_global",
447  "__atomic_umax_varying_uint32_global",
448  "__atomic_umax_varying_uint64_global",
449  "__atomic_umin_varying_uint32_global",
450  "__atomic_umin_varying_uint64_global",
451  "__atomic_xor_uniform_int32_global",
452  "__atomic_xor_uniform_int64_global",
453  "__atomic_xor_varying_int32_global",
454  "__atomic_xor_varying_int64_global",
455  "__atomic_xor_varying_int32_global",
456  "__atomic_xor_varying_int64_global",
457 //#endif /* ISPC_NVPTX_ENABLED */
458  "__broadcast_double",
459  "__broadcast_float",
460  "__broadcast_i16",
461  "__broadcast_i32",
462  "__broadcast_i64",
463  "__broadcast_i8",
464  "__cast_mask_to_i1",
465  "__cast_mask_to_i16",
466  "__ceil_uniform_double",
467  "__ceil_uniform_float",
468  "__ceil_varying_double",
469  "__ceil_varying_float",
470  "__clock",
471  "__count_trailing_zeros_i32",
472  "__count_trailing_zeros_i64",
473  "__count_leading_zeros_i32",
474  "__count_leading_zeros_i64",
475  "__delete_uniform_32rt",
476  "__delete_uniform_64rt",
477  "__delete_varying_32rt",
478  "__delete_varying_64rt",
479  "__do_assert_uniform",
480  "__do_assert_varying",
481  "__do_print",
482 //#ifdef ISPC_NVPTX_ENABLED
483  "__do_print_nvptx",
484 //#endif /* ISPC_NVPTX_ENABLED */
485  "__doublebits_uniform_int64",
486  "__doublebits_varying_int64",
487  "__exclusive_scan_add_double",
488  "__exclusive_scan_add_float",
489  "__exclusive_scan_add_i32",
490  "__exclusive_scan_add_i64",
491  "__exclusive_scan_and_i32",
492  "__exclusive_scan_and_i64",
493  "__exclusive_scan_or_i32",
494  "__exclusive_scan_or_i64",
495  "__extract_int16",
496  "__extract_int32",
497  "__extract_int64",
498  "__extract_int8",
499 //#ifdef ISPC_NVPTX_ENABLED
500  "__extract_float",
501  "__extract_double",
502 //#endif /* ISPC_NVPTX_ENABLED */
503  "__extract_mask_low",
504  "__extract_mask_hi",
505  "__fastmath",
506  "__float_to_half_uniform",
507  "__float_to_half_varying",
508  "__floatbits_uniform_int32",
509  "__floatbits_varying_int32",
510  "__floor_uniform_double",
511  "__floor_uniform_float",
512  "__floor_varying_double",
513  "__floor_varying_float",
514  "__get_system_isa",
515  "__half_to_float_uniform",
516  "__half_to_float_varying",
517  "__insert_int16",
518  "__insert_int32",
519  "__insert_int64",
520  "__insert_int8",
521 //#ifdef ISPC_NVPTX_ENABLED
522  "__insert_float",
523  "__insert_double",
524 //#endif /* ISPC_NVPTX_ENABLED */
525  "__intbits_uniform_double",
526  "__intbits_uniform_float",
527  "__intbits_varying_double",
528  "__intbits_varying_float",
529  "__max_uniform_double",
530  "__max_uniform_float",
531  "__max_uniform_int32",
532  "__max_uniform_int64",
533  "__max_uniform_uint32",
534  "__max_uniform_uint64",
535  "__max_varying_double",
536  "__max_varying_float",
537  "__max_varying_int32",
538  "__max_varying_int64",
539  "__max_varying_uint32",
540  "__max_varying_uint64",
541  "__memory_barrier",
542  "__memcpy32",
543  "__memcpy64",
544  "__memmove32",
545  "__memmove64",
546  "__memset32",
547  "__memset64",
548  "__min_uniform_double",
549  "__min_uniform_float",
550  "__min_uniform_int32",
551  "__min_uniform_int64",
552  "__min_uniform_uint32",
553  "__min_uniform_uint64",
554  "__min_varying_double",
555  "__min_varying_float",
556  "__min_varying_int32",
557  "__min_varying_int64",
558  "__min_varying_uint32",
559  "__min_varying_uint64",
560  "__movmsk",
561 //#ifdef ISPC_NVPTX_ENABLED
562  "__movmsk_ptx",
563 //#endif /* ISPC_NVPTX_ENABLED */
564  "__new_uniform_32rt",
565  "__new_uniform_64rt",
566  "__new_varying32_32rt",
567  "__new_varying32_64rt",
568  "__new_varying64_64rt",
569  "__none",
570  "__num_cores",
571  "__packed_load_active",
572  "__packed_store_active",
573  "__packed_store_active2",
574  "__padds_vi8",
575  "__padds_vi16",
576  "__paddus_vi8",
577  "__paddus_vi16",
578  "__popcnt_int32",
579  "__popcnt_int64",
580  "__prefetch_read_uniform_1",
581  "__prefetch_read_uniform_2",
582  "__prefetch_read_uniform_3",
583  "__prefetch_read_uniform_nt",
584  "__pseudo_prefetch_read_varying_1",
585  "__pseudo_prefetch_read_varying_2",
586  "__pseudo_prefetch_read_varying_3",
587  "__pseudo_prefetch_read_varying_nt",
588  "__psubs_vi8",
589  "__psubs_vi16",
590  "__psubus_vi8",
591  "__psubus_vi16",
592  "__rcp_uniform_float",
593  "__rcp_varying_float",
594  "__rcp_uniform_double",
595  "__rcp_varying_double",
596  "__rdrand_i16",
597  "__rdrand_i32",
598  "__rdrand_i64",
599  "__reduce_add_double",
600  "__reduce_add_float",
601  "__reduce_add_int8",
602  "__reduce_add_int16",
603  "__reduce_add_int32",
604  "__reduce_add_int64",
605  "__reduce_equal_double",
606  "__reduce_equal_float",
607  "__reduce_equal_int32",
608  "__reduce_equal_int64",
609  "__reduce_max_double",
610  "__reduce_max_float",
611  "__reduce_max_int32",
612  "__reduce_max_int64",
613  "__reduce_max_uint32",
614  "__reduce_max_uint64",
615  "__reduce_min_double",
616  "__reduce_min_float",
617  "__reduce_min_int32",
618  "__reduce_min_int64",
619  "__reduce_min_uint32",
620  "__reduce_min_uint64",
621  "__rotate_double",
622  "__rotate_float",
623  "__rotate_i16",
624  "__rotate_i32",
625  "__rotate_i64",
626  "__rotate_i8",
627  "__round_uniform_double",
628  "__round_uniform_float",
629  "__round_varying_double",
630  "__round_varying_float",
631  "__rsqrt_uniform_float",
632  "__rsqrt_varying_float",
633  "__rsqrt_uniform_double",
634  "__rsqrt_varying_double",
635  "__set_system_isa",
636  "__sext_uniform_bool",
637  "__sext_varying_bool",
638  "__shift_double",
639  "__shift_float",
640  "__shift_i16",
641  "__shift_i32",
642  "__shift_i64",
643  "__shift_i8",
644  "__shuffle2_double",
645  "__shuffle2_float",
646  "__shuffle2_i16",
647  "__shuffle2_i32",
648  "__shuffle2_i64",
649  "__shuffle2_i8",
650  "__shuffle_double",
651  "__shuffle_float",
652  "__shuffle_i16",
653  "__shuffle_i32",
654  "__shuffle_i64",
655  "__shuffle_i8",
656  "__soa_to_aos3_double",
657  "__soa_to_aos3_double16",
658  "__soa_to_aos3_double4",
659  "__soa_to_aos3_double8",
660  "__soa_to_aos3_int64",
661  "__soa_to_aos3_float",
662  "__soa_to_aos3_float16",
663  "__soa_to_aos3_float4",
664  "__soa_to_aos3_float8",
665  "__soa_to_aos3_int32",
666  "__soa_to_aos4_float",
667 //#ifdef ISPC_NVPTX_ENABLED
668  "__soa_to_aos3_double1",
669  "__soa_to_aos3_float1",
670  "__soa_to_aos4_float1",
671  "__soa_to_aos4_double1",
672 //#endif /* ISPC_NVPTX_ENABLED */
673  "__soa_to_aos4_double16",
674  "__soa_to_aos4_double4",
675  "__soa_to_aos4_double8",
676  "__soa_to_aos4_double",
677  "__soa_to_aos4_int64",
678  "__soa_to_aos4_float16",
679  "__soa_to_aos4_float4",
680  "__soa_to_aos4_float8",
681  "__soa_to_aos4_int32",
682  "__sqrt_uniform_double",
683  "__sqrt_uniform_float",
684  "__sqrt_varying_double",
685  "__sqrt_varying_float",
686  "__stdlib_acosf",
687  "__stdlib_asinf",
688  "__stdlib_atan",
689  "__stdlib_atan2",
690  "__stdlib_atan2f",
691  "__stdlib_atanf",
692  "__stdlib_cos",
693  "__stdlib_cosf",
694  "__stdlib_exp",
695  "__stdlib_expf",
696  "__stdlib_log",
697  "__stdlib_logf",
698  "__stdlib_pow",
699  "__stdlib_powf",
700  "__stdlib_sin",
701  "__stdlib_asin",
702  "__stdlib_sincos",
703  "__stdlib_sincosf",
704  "__stdlib_sinf",
705  "__stdlib_tan",
706  "__stdlib_tanf",
707  "__streaming_load_uniform_double",
708  "__streaming_load_uniform_float",
709  "__streaming_load_uniform_i8",
710  "__streaming_load_uniform_i16",
711  "__streaming_load_uniform_i32",
712  "__streaming_load_uniform_i64",
713  "__streaming_load_varying_double",
714  "__streaming_load_varying_float",
715  "__streaming_load_varying_i8",
716  "__streaming_load_varying_i16",
717  "__streaming_load_varying_i32",
718  "__streaming_load_varying_i64",
719  "__streaming_store_uniform_double",
720  "__streaming_store_uniform_float",
721  "__streaming_store_uniform_i8",
722  "__streaming_store_uniform_i16",
723  "__streaming_store_uniform_i32",
724  "__streaming_store_uniform_i64",
725  "__streaming_store_varying_double",
726  "__streaming_store_varying_float",
727  "__streaming_store_varying_i8",
728  "__streaming_store_varying_i16",
729  "__streaming_store_varying_i32",
730  "__streaming_store_varying_i64",
731  "__svml_sind",
732  "__svml_asind",
733  "__svml_cosd",
734  "__svml_acosd",
735  "__svml_sincosd",
736  "__svml_tand",
737  "__svml_atand",
738  "__svml_atan2d",
739  "__svml_expd",
740  "__svml_logd",
741  "__svml_powd",
742  "__svml_sinf",
743  "__svml_asinf",
744  "__svml_cosf",
745  "__svml_acosf",
746  "__svml_sincosf",
747  "__svml_tanf",
748  "__svml_atanf",
749  "__svml_atan2f",
750  "__svml_expf",
751  "__svml_logf",
752  "__svml_powf",
753  "__log_uniform_float",
754  "__log_varying_float",
755  "__exp_uniform_float",
756  "__exp_varying_float",
757  "__pow_uniform_float",
758  "__pow_varying_float",
759  "__log_uniform_double",
760  "__log_varying_double",
761  "__exp_uniform_double",
762  "__exp_varying_double",
763  "__pow_uniform_double",
764  "__pow_varying_double",
765  "__sin_varying_float",
766  "__asin_varying_float",
767  "__cos_varying_float",
768  "__acos_varying_float",
769  "__sincos_varying_float",
770  "__tan_varying_float",
771  "__atan_varying_float",
772  "__atan2_varying_float",
773  "__sin_uniform_float",
774  "__asin_uniform_float",
775  "__cos_uniform_float",
776  "__acos_uniform_float",
777  "__sincos_uniform_float",
778  "__tan_uniform_float",
779  "__atan_uniform_float",
780  "__atan2_uniform_float",
781  "__sin_varying_double",
782  "__asin_varying_double",
783  "__cos_varying_double",
784  "__acos_varying_double",
785  "__sincos_varying_double",
786  "__tan_varying_double",
787  "__atan_varying_double",
788  "__atan2_varying_double",
789  "__sin_uniform_double",
790  "__asin_uniform_double",
791  "__cos_uniform_double",
792  "__acos_uniform_double",
793  "__sincos_uniform_double",
794  "__tan_uniform_double",
795  "__atan_uniform_double",
796  "__atan2_uniform_double",
797  "__undef_uniform",
798  "__undef_varying",
799  "__vec4_add_float",
800  "__vec4_add_int32",
801  "__vselect_float",
802 //#ifdef ISPC_NVPTX_ENABLED
803  "__program_index",
804  "__program_count",
805  "__warp_index",
806  "__task_index0",
807  "__task_index1",
808  "__task_index2",
809  "__task_index",
810  "__task_count0",
811  "__task_count1",
812  "__task_count2",
813  "__task_count",
814  "__cvt_loc2gen",
815  "__cvt_loc2gen_var",
816  "__cvt_const2gen",
817  "__puts_nvptx",
818  "ISPCAlloc",
819  "ISPCLaunch",
820  "ISPCSync",
821 //#endif /* ISPC_NVPTX_ENABLED */
822  "__vselect_i32"
823  };
824 
825  int count = sizeof(names) / sizeof(names[0]);
826  for (int i = 0; i < count; ++i) {
827  llvm::Function *f = module->getFunction(names[i]);
828  if (f != NULL && f->empty() == false) {
829  f->setLinkage(llvm::GlobalValue::InternalLinkage);
831  }
832  }
833 }
834 
835 
836 /** This utility function takes serialized binary LLVM bitcode and adds its
837  definitions to the given module. Functions in the bitcode that can be
838  mapped to ispc functions are also added to the symbol table.
839 
840  @param bitcode Binary LLVM bitcode (e.g. the contents of a *.bc file)
841  @param length Length of the bitcode buffer
842  @param module Module to link the bitcode into
843  @param symbolTable Symbol table to add definitions to
844  */
845 void
846 AddBitcodeToModule(const unsigned char *bitcode, int length,
847  llvm::Module *module, SymbolTable *symbolTable, bool warn) {
848  llvm::StringRef sb = llvm::StringRef((char *)bitcode, length);
849 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_5
850  llvm::MemoryBuffer *bcBuf = llvm::MemoryBuffer::getMemBuffer(sb);
851 #else // LLVM 3.6+
852  llvm::MemoryBufferRef bcBuf = llvm::MemoryBuffer::getMemBuffer(sb)->getMemBufferRef();
853 #endif
854 
855 #if ISPC_LLVM_VERSION >= ISPC_LLVM_4_0 // LLVM 4.0+
856  llvm::Expected<std::unique_ptr<llvm::Module>> ModuleOrErr = llvm::parseBitcodeFile(bcBuf, *g->ctx);
857  if (!ModuleOrErr) {
858  Error(SourcePos(), "Error parsing stdlib bitcode: %s", toString(ModuleOrErr.takeError()).c_str());
859  } else {
860  llvm::Module *bcModule = ModuleOrErr.get().release();
861 #elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+
862  llvm::ErrorOr<std::unique_ptr<llvm::Module>> ModuleOrErr = llvm::parseBitcodeFile(bcBuf, *g->ctx);
863  if (std::error_code EC = ModuleOrErr.getError())
864  Error(SourcePos(), "Error parsing stdlib bitcode: %s", EC.message().c_str());
865  else {
866  llvm::Module *bcModule = ModuleOrErr.get().release();
867 #elif ISPC_LLVM_VERSION == ISPC_LLVM_3_5 || ISPC_LLVM_VERSION == ISPC_LLVM_3_6
868  llvm::ErrorOr<llvm::Module *> ModuleOrErr = llvm::parseBitcodeFile(bcBuf, *g->ctx);
869  if (std::error_code EC = ModuleOrErr.getError())
870  Error(SourcePos(), "Error parsing stdlib bitcode: %s", EC.message().c_str());
871  else {
872  llvm::Module *bcModule = ModuleOrErr.get();
873 #else // LLVM 3.2 - 3.4
874  std::string bcErr;
875  llvm::Module *bcModule = llvm::ParseBitcodeFile(bcBuf, *g->ctx, &bcErr);
876  if (!bcModule)
877  Error(SourcePos(), "Error parsing stdlib bitcode: %s", bcErr.c_str());
878  else {
879 #endif
880  // FIXME: this feels like a bad idea, but the issue is that when we
881  // set the llvm::Module's target triple in the ispc Module::Module
882  // constructor, we start by calling llvm::sys::getHostTriple() (and
883  // then change the arch if needed). Somehow that ends up giving us
884  // strings like 'x86_64-apple-darwin11.0.0', while the stuff we
885  // compile to bitcode with clang has module triples like
886  // 'i386-apple-macosx10.7.0'. And then LLVM issues a warning about
887  // linking together modules with incompatible target triples..
888  llvm::Triple mTriple(m->module->getTargetTriple());
889  llvm::Triple bcTriple(bcModule->getTargetTriple());
890  Debug(SourcePos(), "module triple: %s\nbitcode triple: %s\n",
891  mTriple.str().c_str(), bcTriple.str().c_str());
892 #if defined(ISPC_ARM_ENABLED) && !defined(__arm__)
893  // FIXME: More ugly and dangerous stuff. We really haven't set up
894  // proper build and runtime infrastructure for ispc to do
895  // cross-compilation, yet it's at minimum useful to be able to emit
896  // ARM code from x86 for ispc development. One side-effect is that
897  // when the build process turns builtins/builtins.c to LLVM bitcode
898  // for us to link in at runtime, that bitcode has been compiled for
899  // an IA target, which in turn causes the checks in the following
900  // code to (appropraitely) fail.
901  //
902  // In order to be able to have some ability to generate ARM code on
903  // IA, we'll just skip those tests in that case and allow the
904  // setTargetTriple() and setDataLayout() calls below to shove in
905  // the values for an ARM target. This maybe won't cause problems
906  // in the generated code, since bulitins.c doesn't do anything too
907  // complex w.r.t. struct layouts, etc.
908  if (g->target->getISA() != Target::NEON32 &&
909  g->target->getISA() != Target::NEON16 &&
910  g->target->getISA() != Target::NEON8)
911 #endif // !__arm__
912 #ifdef ISPC_NVPTX_ENABLED
913  if (g->target->getISA() != Target::NVPTX)
914 #endif /* ISPC_NVPTX_ENABLED */
915  {
916  Assert(bcTriple.getArch() == llvm::Triple::UnknownArch ||
917  mTriple.getArch() == bcTriple.getArch());
918  Assert(bcTriple.getVendor() == llvm::Triple::UnknownVendor ||
919  mTriple.getVendor() == bcTriple.getVendor());
920 
921  // We unconditionally set module DataLayout to library, but we must
922  // ensure that library and module DataLayouts are compatible.
923  // If they are not, we should recompile the library for problematic
924  // architecture and investigate what happened.
925  // Generally we allow library DataLayout to be subset of module
926  // DataLayout or library DataLayout to be empty.
927 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5
928  if (!VerifyDataLayoutCompatibility(module->getDataLayoutStr(),
929  bcModule->getDataLayoutStr())
930  && warn) {
931  Warning(SourcePos(), "Module DataLayout is incompatible with "
932  "library DataLayout:\n"
933  "Module DL: %s\n"
934  "Library DL: %s\n",
935  module->getDataLayoutStr().c_str(),
936  bcModule->getDataLayoutStr().c_str());
937  }
938 #else
939  if (!VerifyDataLayoutCompatibility(module->getDataLayout(),
940  bcModule->getDataLayout())
941  && warn) {
942  Warning(SourcePos(), "Module DataLayout is incompatible with "
943  "library DataLayout:\n"
944  "Module DL: %s\n"
945  "Library DL: %s\n",
946  module->getDataLayout().c_str(),
947  bcModule->getDataLayout().c_str());
948  }
949 #endif
950  }
951 
952  bcModule->setTargetTriple(mTriple.str());
953  bcModule->setDataLayout(module->getDataLayout());
954 
955 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_5 // 3.2-3.5
956  std::string(linkError);
957 
958  if (llvm::Linker::LinkModules(module, bcModule,
959  llvm::Linker::DestroySource,
960  &linkError))
961  Error(SourcePos(), "Error linking stdlib bitcode: %s", linkError.c_str());
962 #elif ISPC_LLVM_VERSION <= ISPC_LLVM_3_7 // 3.6-3.7
963  llvm::Linker::LinkModules(module, bcModule);
964 #else // LLVM 3.8+
965  // A hack to move over declaration, which have no definition.
966  // New linker is kind of smart and think it knows better what to do, so
967  // it removes unused declarations without definitions.
968  // This trick should be legal, as both modules use the same LLVMContext.
969  for (llvm::Function& f : *bcModule) {
970  if (f.isDeclaration()) {
971  // Declarations with uses will be moved by Linker.
972  if (f.getNumUses() > 0)
973  continue;
974  module->getOrInsertFunction(f.getName(), f.getFunctionType(),
975  f.getAttributes());
976  }
977  }
978 
979  std::unique_ptr<llvm::Module> M(bcModule);
980  if (llvm::Linker::linkModules(*module, std::move(M))) {
981  Error(SourcePos(), "Error linking stdlib bitcode.");
982  }
983 #endif
984 
985  lSetInternalFunctions(module);
986  if (symbolTable != NULL)
987  lAddModuleSymbols(module, symbolTable);
988  lCheckModuleIntrinsics(module);
989  }
990 }
991 
992 
993 /** Utility routine that defines a constant int32 with given value, adding
994  the symbol to both the ispc symbol table and the given LLVM module.
995  */
996 static void
997 lDefineConstantInt(const char *name, int val, llvm::Module *module,
998  SymbolTable *symbolTable, std::vector<llvm::Constant*> &dbg_sym) {
999  Symbol *sym =
1000  new Symbol(name, SourcePos(), AtomicType::UniformInt32->GetAsConstType(),
1001  SC_STATIC);
1002  sym->constValue = new ConstExpr(sym->type, val, SourcePos());
1003  llvm::Type *ltype = LLVMTypes::Int32Type;
1004  llvm::Constant *linit = LLVMInt32(val);
1005 #if ISPC_LLVM_VERSION < ISPC_LLVM_3_6
1006  // Use WeakODRLinkage rather than InternalLinkage so that a definition
1007  // survives even if it's not used in the module, so that the symbol is
1008  // there in the debugger.
1009  llvm::GlobalValue::LinkageTypes linkage = g->generateDebuggingSymbols ?
1010  llvm::GlobalValue::WeakODRLinkage : llvm::GlobalValue::InternalLinkage;
1011  sym->storagePtr = new llvm::GlobalVariable(*module, ltype, true, linkage,
1012  linit, name);
1013 #else // LLVM 3.6+
1014  auto GV = new llvm::GlobalVariable(*module, ltype, true,
1015  llvm::GlobalValue::InternalLinkage,
1016  linit, name);
1017  dbg_sym.push_back(GV);
1018  sym->storagePtr = GV;
1019 #endif
1020  symbolTable->AddVariable(sym);
1021 
1022  if (m->diBuilder != NULL) {
1023 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
1024  llvm::DIFile file;
1025  llvm::DIType diType = sym->type->GetDIType(file);
1026  Assert(diType.Verify());
1027 #else // LLVM 3.7+
1028  llvm::DIFile *file = m->diCompileUnit->getFile();
1029  llvm::DICompileUnit *cu = m->diCompileUnit;
1030  llvm::DIType *diType = sym->type->GetDIType(file);
1031 #endif
1032  // FIXME? DWARF says that this (and programIndex below) should
1033  // have the DW_AT_artifical attribute. It's not clear if this
1034  // matters for anything though.
1035 
1036 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_5
1037  llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable(
1038  name,
1039  file,
1040  0 /* line */,
1041  diType,
1042  true /* static */,
1043  sym->storagePtr);
1044 #elif ISPC_LLVM_VERSION == ISPC_LLVM_3_6 // LLVM 3.6
1045  llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
1046  Assert(sym_const_storagePtr);
1047  llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable(
1048  file,
1049  name,
1050  name,
1051  file,
1052  0 /* line */,
1053  diType,
1054  true /* static */,
1055  sym_const_storagePtr);
1056 #elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 && ISPC_LLVM_VERSION <= ISPC_LLVM_3_9 // LLVM 3.7 - 3.9
1057  llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
1058  Assert(sym_const_storagePtr);
1059  m->diBuilder->createGlobalVariable(
1060  cu,
1061  name,
1062  name,
1063  file,
1064  0 /* line */,
1065  diType,
1066  true /* static */,
1067  sym_const_storagePtr);
1068 #else // LLVM 4.0+
1069  llvm::GlobalVariable *sym_GV_storagePtr = llvm::dyn_cast<llvm::GlobalVariable>(sym->storagePtr);
1070  llvm::DIGlobalVariableExpression *var = m->diBuilder->createGlobalVariableExpression(
1071  cu,
1072  name,
1073  name,
1074  file,
1075  0 /* line */,
1076  diType,
1077  true /* static */);
1078  sym_GV_storagePtr->addDebugInfo(var);
1079 #endif
1080 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
1081  Assert(var.Verify());
1082 #else // LLVM 3.7+
1083  //coming soon
1084 #endif
1085  }
1086 }
1087 
1088 
1089 
1090 static void
1091 lDefineConstantIntFunc(const char *name, int val, llvm::Module *module,
1092  SymbolTable *symbolTable, std::vector<llvm::Constant*> &dbg_sym) {
1093  llvm::SmallVector<const Type *, 8> args;
1095  Symbol *sym = new Symbol(name, SourcePos(), ft, SC_STATIC);
1096 
1097  llvm::Function *func = module->getFunction(name);
1098  dbg_sym.push_back(func);
1099  Assert(func != NULL); // it should be declared already...
1100 #if ISPC_LLVM_VERSION == ISPC_LLVM_3_2
1101  func->addFnAttr(llvm::Attributes::AlwaysInline);
1102 #else // LLVM 3.3+
1103  func->addFnAttr(llvm::Attribute::AlwaysInline);
1104 #endif
1105  llvm::BasicBlock *bblock = llvm::BasicBlock::Create(*g->ctx, "entry", func, 0);
1106  llvm::ReturnInst::Create(*g->ctx, LLVMInt32(val), bblock);
1107 
1108  sym->function = func;
1109  symbolTable->AddVariable(sym);
1110 }
1111 
1112 
1113 
1114 static void
1115 lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable, std::vector<llvm::Constant*> &dbg_sym) {
1116  Symbol *sym =
1117  new Symbol("programIndex", SourcePos(),
1118  AtomicType::VaryingInt32->GetAsConstType(), SC_STATIC);
1119 
1120  int pi[ISPC_MAX_NVEC];
1121  for (int i = 0; i < g->target->getVectorWidth(); ++i)
1122  pi[i] = i;
1123  sym->constValue = new ConstExpr(sym->type, pi, SourcePos());
1124 
1125  llvm::Type *ltype = LLVMTypes::Int32VectorType;
1126  llvm::Constant *linit = LLVMInt32Vector(pi);
1127 #if ISPC_LLVM_VERSION < ISPC_LLVM_3_6
1128  // See comment in lDefineConstantInt() for why WeakODRLinkage is used here
1129  llvm::GlobalValue::LinkageTypes linkage = g->generateDebuggingSymbols ?
1130  llvm::GlobalValue::WeakODRLinkage : llvm::GlobalValue::InternalLinkage;
1131  sym->storagePtr = new llvm::GlobalVariable(*module, ltype, true, linkage,
1132  linit, sym->name.c_str());
1133 #else // LLVM 3.6+
1134  auto GV = new llvm::GlobalVariable(*module, ltype, true,
1135  llvm::GlobalValue::InternalLinkage,
1136  linit, sym->name.c_str());
1137  dbg_sym.push_back(GV);
1138  sym->storagePtr = GV;
1139 #endif
1140  symbolTable->AddVariable(sym);
1141 
1142  if (m->diBuilder != NULL) {
1143 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
1144  llvm::DIFile file;
1145  llvm::DIType diType = sym->type->GetDIType(file);
1146  Assert(diType.Verify());
1147 #else // LLVM 3.7+
1148  llvm::DIFile *file = m->diCompileUnit->getFile();
1149  llvm::DICompileUnit *cu = m->diCompileUnit;
1150  llvm::DIType *diType = sym->type->GetDIType(file);
1151 #endif
1152 #if ISPC_LLVM_VERSION == ISPC_LLVM_3_6 // LLVM 3.6
1153  llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
1154  Assert(sym_const_storagePtr);
1155  llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable(
1156  file,
1157  sym->name.c_str(),
1158  sym->name.c_str(),
1159  file,
1160  0 /* line */,
1161  diType,
1162  false /* static */,
1163  sym_const_storagePtr);
1164 #elif ISPC_LLVM_VERSION <= ISPC_LLVM_3_5
1165  llvm::DIGlobalVariable var = m->diBuilder->createGlobalVariable(
1166  sym->name.c_str(),
1167  file,
1168  0 /* line */,
1169  diType,
1170  false /* static */,
1171  sym->storagePtr);
1172 #elif ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 && ISPC_LLVM_VERSION <= ISPC_LLVM_3_9 // LLVM 3.7 - 3.9
1173  llvm::Constant *sym_const_storagePtr = llvm::dyn_cast<llvm::Constant>(sym->storagePtr);
1174  Assert(sym_const_storagePtr);
1175  m->diBuilder->createGlobalVariable(
1176  cu,
1177  sym->name.c_str(),
1178  sym->name.c_str(),
1179  file,
1180  0 /* line */,
1181  diType,
1182  false /* static */,
1183  sym_const_storagePtr);
1184 #else // LLVM 4.0+
1185  llvm::GlobalVariable *sym_GV_storagePtr = llvm::dyn_cast<llvm::GlobalVariable>(sym->storagePtr);
1186  llvm::DIGlobalVariableExpression *var = m->diBuilder->createGlobalVariableExpression(
1187  cu,
1188  sym->name.c_str(),
1189  sym->name.c_str(),
1190  file,
1191  0 /* line */,
1192  diType,
1193  false /* static */);
1194  sym_GV_storagePtr->addDebugInfo(var);
1195 #endif
1196 #if ISPC_LLVM_VERSION <= ISPC_LLVM_3_6
1197  Assert(var.Verify());
1198 #else // LLVM 3.7+
1199  //coming soon
1200 #endif
1201  }
1202 }
1203 
1204 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 // LLVM 3.6+
1205 static void emitLLVMUsed(llvm::Module& module, std::vector<llvm::Constant*> &list) {
1206  // Convert list to what ConstantArray needs.
1207  llvm::SmallVector<llvm::Constant*, 8> UsedArray;
1208  UsedArray.reserve(list.size());
1209  for (auto c : list) {
1210  UsedArray.push_back(
1211  llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
1212  llvm::cast<llvm::Constant>(c), LLVMTypes::Int8PointerType));
1213  }
1214 
1215  llvm::ArrayType *ATy = llvm::ArrayType::get(LLVMTypes::Int8PointerType, UsedArray.size());
1216 
1217  auto *GV = new llvm::GlobalVariable(module, ATy, false, llvm::GlobalValue::AppendingLinkage,
1218  llvm::ConstantArray::get(ATy, UsedArray), "llvm.used");
1219 
1220  GV->setSection("llvm.metadata");
1221 }
1222 #endif
1223 
1224 void
1225 DefineStdlib(SymbolTable *symbolTable, llvm::LLVMContext *ctx, llvm::Module *module,
1226  bool includeStdlibISPC) {
1227  // debug_symbols are symbols that supposed to be preserved in debug information.
1228  // They will be referenced in llvm.used intrinsic to prevent they removal from
1229  // the object file.
1230  std::vector<llvm::Constant*> debug_symbols;
1231  bool runtime32 = g->target->is32Bit();
1232  bool warn = g->target->getISA() != Target::GENERIC;
1233 
1234 #define EXPORT_MODULE_COND_WARN(export_module, warnings) \
1235  extern unsigned char export_module[]; \
1236  extern int export_module##_length; \
1237  AddBitcodeToModule(export_module, export_module##_length, \
1238  module, symbolTable, warnings);
1239 
1240 #define EXPORT_MODULE(export_module) \
1241  extern unsigned char export_module[]; \
1242  extern int export_module##_length; \
1243  AddBitcodeToModule(export_module, export_module##_length, \
1244  module, symbolTable, true);
1245 
1246  // Add the definitions from the compiled builtins.c file.
1247  // When compiling for "generic" target family, data layout warnings for
1248  // "builtins_bitcode_c" have to be switched off: its DL is incompatible
1249  // with the DL of "generic". Anyway, AddBitcodeToModule() corrects this
1250  // automatically if DLs differ (by copying module`s DL to export`s DL).
1251  if (runtime32) {
1252  EXPORT_MODULE_COND_WARN(builtins_bitcode_c_32, warn);
1253  }
1254  else {
1255  EXPORT_MODULE_COND_WARN(builtins_bitcode_c_64, warn);
1256  }
1257 
1258  // Next, add the target's custom implementations of the various needed
1259  // builtin functions (e.g. __masked_store_32(), etc).
1260  switch (g->target->getISA()) {
1261 #ifdef ISPC_NVPTX_ENABLED
1262  case Target::NVPTX:
1263  {
1264  if (runtime32) {
1265  fprintf(stderr, "Unfortunatly 32bit targets are not supported at the moment .. \n");
1266  assert(0);
1267  }
1268  else {
1269  EXPORT_MODULE(builtins_bitcode_nvptx_64bit);
1270  }
1271  break;
1272  };
1273 #endif /* ISPC_NVPTX_ENABLED */
1274 
1275 #ifdef ISPC_ARM_ENABLED
1276  case Target::NEON8: {
1277  if (runtime32) {
1278  EXPORT_MODULE(builtins_bitcode_neon_8_32bit);
1279  }
1280  else {
1281  EXPORT_MODULE(builtins_bitcode_neon_8_64bit);
1282  }
1283  break;
1284  }
1285  case Target::NEON16: {
1286  if (runtime32) {
1287  EXPORT_MODULE(builtins_bitcode_neon_16_32bit);
1288  }
1289  else {
1290  EXPORT_MODULE(builtins_bitcode_neon_16_64bit);
1291  }
1292  break;
1293  }
1294  case Target::NEON32: {
1295  if (runtime32) {
1296  EXPORT_MODULE(builtins_bitcode_neon_32_32bit);
1297  }
1298  else {
1299  EXPORT_MODULE(builtins_bitcode_neon_32_64bit);
1300  }
1301  break;
1302  }
1303 #endif
1304  case Target::SSE2: {
1305  switch (g->target->getVectorWidth()) {
1306  case 4:
1307  if (runtime32) {
1308  EXPORT_MODULE(builtins_bitcode_sse2_32bit);
1309  }
1310  else {
1311  EXPORT_MODULE(builtins_bitcode_sse2_64bit);
1312  }
1313  break;
1314  case 8:
1315  if (runtime32) {
1316  EXPORT_MODULE(builtins_bitcode_sse2_x2_32bit);
1317  }
1318  else {
1319  EXPORT_MODULE(builtins_bitcode_sse2_x2_64bit);
1320  }
1321  break;
1322  default:
1323  FATAL("logic error in DefineStdlib");
1324  }
1325  break;
1326  }
1327  case Target::SSE4: {
1328  switch (g->target->getVectorWidth()) {
1329  case 4:
1330  if (runtime32) {
1331  EXPORT_MODULE(builtins_bitcode_sse4_32bit);
1332  }
1333  else {
1334  EXPORT_MODULE(builtins_bitcode_sse4_64bit);
1335  }
1336  break;
1337  case 8:
1338  if (runtime32) {
1339  if (g->target->getMaskBitCount() == 16) {
1340  EXPORT_MODULE(builtins_bitcode_sse4_16_32bit);
1341  }
1342  else {
1343  Assert(g->target->getMaskBitCount() == 32);
1344  EXPORT_MODULE(builtins_bitcode_sse4_x2_32bit);
1345  }
1346  }
1347  else {
1348  if (g->target->getMaskBitCount() == 16) {
1349  EXPORT_MODULE(builtins_bitcode_sse4_16_64bit);
1350  }
1351  else {
1352  Assert(g->target->getMaskBitCount() == 32);
1353  EXPORT_MODULE(builtins_bitcode_sse4_x2_64bit);
1354  }
1355  }
1356  break;
1357  case 16:
1358  Assert(g->target->getMaskBitCount() == 8);
1359  if (runtime32) {
1360  EXPORT_MODULE(builtins_bitcode_sse4_8_32bit);
1361  }
1362  else {
1363  EXPORT_MODULE(builtins_bitcode_sse4_8_64bit);
1364  }
1365  break;
1366  default:
1367  FATAL("logic error in DefineStdlib");
1368  }
1369  break;
1370  }
1371  case Target::AVX: {
1372  switch (g->target->getVectorWidth()) {
1373  case 4:
1374  if (g->target->getDataTypeWidth() == 32) {
1375  // Note here that for avx1-i32x4 we are using bitcode file for
1376  // sse4-i32x4. This is intentional and good enough.
1377  // AVX target implies appropriate target-feature attrbute,
1378  // which forces LLVM to generate AVX code, even for SSE4
1379  // intrinsics. Except that the only "missing" feature in sse4
1380  // target is implemenation of __masked_[store|load]_[i32|i64]
1381  // using maskmov instruction. But it's not very popular
1382  // intrinsics, so we assume the implementation to be good
1383  // enough at the moment.
1384  if (runtime32) {
1385  EXPORT_MODULE(builtins_bitcode_sse4_32bit);
1386  }
1387  else {
1388  EXPORT_MODULE(builtins_bitcode_sse4_64bit);
1389  }
1390  } else if (g->target->getDataTypeWidth() == 64) {
1391  if (runtime32) {
1392  EXPORT_MODULE(builtins_bitcode_avx1_i64x4_32bit);
1393  }
1394  else {
1395  EXPORT_MODULE(builtins_bitcode_avx1_i64x4_64bit);
1396  }
1397  } else {
1398  FATAL("logic error in DefineStdlib");
1399  }
1400  break;
1401  case 8:
1402  if (runtime32) {
1403  EXPORT_MODULE(builtins_bitcode_avx1_32bit);
1404  }
1405  else {
1406  EXPORT_MODULE(builtins_bitcode_avx1_64bit);
1407  }
1408  break;
1409  case 16:
1410  if (runtime32) {
1411  EXPORT_MODULE(builtins_bitcode_avx1_x2_32bit);
1412  }
1413  else {
1414  EXPORT_MODULE(builtins_bitcode_avx1_x2_64bit);
1415  }
1416  break;
1417  default:
1418  FATAL("logic error in DefineStdlib");
1419  }
1420  break;
1421  }
1422  case Target::AVX11: {
1423  switch (g->target->getVectorWidth()) {
1424  case 4:
1425  if (runtime32) {
1426  EXPORT_MODULE(builtins_bitcode_avx11_i64x4_32bit);
1427  }
1428  else {
1429  EXPORT_MODULE(builtins_bitcode_avx11_i64x4_64bit);
1430  }
1431  break;
1432  case 8:
1433  if (runtime32) {
1434  EXPORT_MODULE(builtins_bitcode_avx11_32bit);
1435  }
1436  else {
1437  EXPORT_MODULE(builtins_bitcode_avx11_64bit);
1438  }
1439  break;
1440  case 16:
1441  if (runtime32) {
1442  EXPORT_MODULE(builtins_bitcode_avx11_x2_32bit);
1443  }
1444  else {
1445  EXPORT_MODULE(builtins_bitcode_avx11_x2_64bit);
1446  }
1447  break;
1448  default:
1449  FATAL("logic error in DefineStdlib");
1450  }
1451  break;
1452  }
1453  case Target::AVX2: {
1454  switch (g->target->getVectorWidth()) {
1455  case 4:
1456  if (runtime32) {
1457  EXPORT_MODULE(builtins_bitcode_avx2_i64x4_32bit);
1458  }
1459  else {
1460  EXPORT_MODULE(builtins_bitcode_avx2_i64x4_64bit);
1461  }
1462  break;
1463  case 8:
1464  if (runtime32) {
1465  EXPORT_MODULE(builtins_bitcode_avx2_32bit);
1466  }
1467  else {
1468  EXPORT_MODULE(builtins_bitcode_avx2_64bit);
1469  }
1470  break;
1471  case 16:
1472  if (runtime32) {
1473  EXPORT_MODULE(builtins_bitcode_avx2_x2_32bit);
1474  }
1475  else {
1476  EXPORT_MODULE(builtins_bitcode_avx2_x2_64bit);
1477  }
1478  break;
1479  default:
1480  FATAL("logic error in DefineStdlib");
1481  }
1482  break;
1483  }
1484 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_7 // LLVM 3.7+
1485  case Target::KNL_AVX512: {
1486  switch (g->target->getVectorWidth()) {
1487  case 16:
1488  if (runtime32) {
1489  EXPORT_MODULE(builtins_bitcode_knl_32bit);
1490  }
1491  else {
1492  EXPORT_MODULE(builtins_bitcode_knl_64bit);
1493  }
1494  break;
1495  default:
1496  FATAL("logic error in DefineStdlib");
1497  }
1498  break;
1499  }
1500 #endif
1501 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_8 // LLVM 3.8+
1502  case Target::SKX_AVX512: {
1503  switch (g->target->getVectorWidth()) {
1504  case 16:
1505  if (runtime32) {
1506  EXPORT_MODULE(builtins_bitcode_skx_32bit);
1507  }
1508  else {
1509  EXPORT_MODULE(builtins_bitcode_skx_64bit);
1510  }
1511  break;
1512  default:
1513  FATAL("logic error in DefineStdlib");
1514  }
1515  break;
1516  }
1517 #endif
1518  case Target::GENERIC: {
1519  switch (g->target->getVectorWidth()) {
1520  case 4:
1521  if (runtime32) {
1522  EXPORT_MODULE(builtins_bitcode_generic_4_32bit);
1523  }
1524  else {
1525  EXPORT_MODULE(builtins_bitcode_generic_4_64bit);
1526  }
1527  break;
1528  case 8:
1529  if (runtime32) {
1530  EXPORT_MODULE(builtins_bitcode_generic_8_32bit);
1531  }
1532  else {
1533  EXPORT_MODULE(builtins_bitcode_generic_8_64bit);
1534  }
1535  break;
1536  case 16:
1537  if (runtime32) {
1538  EXPORT_MODULE(builtins_bitcode_generic_16_32bit);
1539  }
1540  else {
1541  EXPORT_MODULE(builtins_bitcode_generic_16_64bit);
1542  }
1543  break;
1544  case 32:
1545  if (runtime32) {
1546  EXPORT_MODULE(builtins_bitcode_generic_32_32bit);
1547  }
1548  else {
1549  EXPORT_MODULE(builtins_bitcode_generic_32_64bit);
1550  }
1551  break;
1552  case 64:
1553  if (runtime32) {
1554  EXPORT_MODULE(builtins_bitcode_generic_64_32bit);
1555  }
1556  else {
1557  EXPORT_MODULE(builtins_bitcode_generic_64_64bit);
1558  }
1559  break;
1560  case 1:
1561  if (runtime32) {
1562  EXPORT_MODULE(builtins_bitcode_generic_1_32bit);
1563  }
1564  else {
1565  EXPORT_MODULE(builtins_bitcode_generic_1_64bit);
1566  }
1567  break;
1568  default:
1569  FATAL("logic error in DefineStdlib");
1570  }
1571  break;
1572  }
1573  default:
1574  FATAL("logic error");
1575  }
1576 
1577  // define the 'programCount' builtin variable
1578 #ifdef ISPC_NVPTX_ENABLED
1579  if (g->target->getISA() == Target::NVPTX)
1580  {
1581  lDefineConstantInt("programCount", 32, module, symbolTable, debug_symbols);
1582  }
1583  else
1584  {
1585 #endif /* ISPC_NVPTX_ENABLED */
1586  lDefineConstantInt("programCount", g->target->getVectorWidth(), module, symbolTable, debug_symbols);
1587 #ifdef ISPC_NVPTX_ENABLED
1588  }
1589 #endif /* ISPC_NVPTX_ENABLED */
1590 
1591  // define the 'programIndex' builtin
1592  lDefineProgramIndex(module, symbolTable, debug_symbols);
1593 
1594  // Define __math_lib stuff. This is used by stdlib.ispc, for example, to
1595  // figure out which math routines to end up calling...
1596  lDefineConstantInt("__math_lib", (int)g->mathLib, module, symbolTable, debug_symbols);
1597  lDefineConstantInt("__math_lib_ispc", (int)Globals::Math_ISPC, module,
1598  symbolTable, debug_symbols);
1599  lDefineConstantInt("__math_lib_ispc_fast", (int)Globals::Math_ISPCFast,
1600  module, symbolTable, debug_symbols);
1601  lDefineConstantInt("__math_lib_svml", (int)Globals::Math_SVML, module,
1602  symbolTable, debug_symbols);
1603  lDefineConstantInt("__math_lib_system", (int)Globals::Math_System, module,
1604  symbolTable, debug_symbols);
1605  lDefineConstantIntFunc("__fast_masked_vload", (int)g->opt.fastMaskedVload,
1606  module, symbolTable, debug_symbols);
1607 
1608  lDefineConstantInt("__have_native_half", g->target->hasHalf(), module,
1609  symbolTable, debug_symbols);
1610  lDefineConstantInt("__have_native_rand", g->target->hasRand(), module,
1611  symbolTable, debug_symbols);
1612  lDefineConstantInt("__have_native_transcendentals", g->target->hasTranscendentals(),
1613  module, symbolTable, debug_symbols);
1614  lDefineConstantInt("__have_native_trigonometry", g->target->hasTrigonometry(),
1615  module, symbolTable, debug_symbols);
1616  lDefineConstantInt("__have_native_rsqrtd", g->target->hasRsqrtd(),
1617  module, symbolTable, debug_symbols);
1618  lDefineConstantInt("__have_native_rcpd", g->target->hasRcpd(),
1619  module, symbolTable, debug_symbols);
1620 
1621 #ifdef ISPC_NVPTX_ENABLED
1622  lDefineConstantInt("__is_nvptx_target", (int)(g->target->getISA() == Target::NVPTX),
1623  module, symbolTable, debug_symbols);
1624 #else
1625  lDefineConstantInt("__is_nvptx_target", (int)0, module, symbolTable, debug_symbols);
1626 #endif /* ISPC_NVPTX_ENABLED */
1627 
1628  if (g->forceAlignment != -1) {
1629  llvm::GlobalVariable *alignment = module->getGlobalVariable("memory_alignment", true);
1630  alignment->setInitializer(LLVMInt32(g->forceAlignment));
1631  }
1632 
1633  // LLVM 3.6 is only because it was not tested with earlier versions.
1634 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_6 // LLVM 3.6+
1635  if (g->generateDebuggingSymbols) {
1636  emitLLVMUsed(*module, debug_symbols);
1637  }
1638 #endif
1639 
1640  if (includeStdlibISPC) {
1641  // If the user wants the standard library to be included, parse the
1642  // serialized version of the stdlib.ispc file to get its
1643  // definitions added.
1644  extern char stdlib_mask1_code[], stdlib_mask8_code[];
1645  extern char stdlib_mask16_code[], stdlib_mask32_code[], stdlib_mask64_code[];
1646  if (g->target->getISA() == Target::GENERIC &&
1647  g->target->getVectorWidth() == 1) { // 1 wide uses 32 stdlib
1648  yy_scan_string(stdlib_mask32_code);
1649  }
1650  else {
1651  switch (g->target->getMaskBitCount()) {
1652  case 1:
1653  yy_scan_string(stdlib_mask1_code);
1654  break;
1655  case 8:
1656  yy_scan_string(stdlib_mask8_code);
1657  break;
1658  case 16:
1659  yy_scan_string(stdlib_mask16_code);
1660  break;
1661  case 32:
1662  yy_scan_string(stdlib_mask32_code);
1663  break;
1664  case 64:
1665  yy_scan_string(stdlib_mask64_code);
1666  break;
1667  default:
1668  FATAL("Unhandled mask bit size for stdlib.ispc");
1669  }
1670  }
1671  yyparse();
1672  }
1673 }
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:846
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:1225
std::string GetString() const
Definition: type.cpp:3144
Opt opt
Definition: ispc.h:548
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:286
Module * m
Definition: ispc.cpp:101
static void lCheckModuleIntrinsics(llvm::Module *module)
Definition: builtins.cpp:303
Target * target
Definition: ispc.h:550
bool hasRsqrtd() const
Definition: ispc.h:306
bool AddVariable(Symbol *symbol)
Definition: sym.cpp:98
static const AtomicType * VaryingDouble
Definition: type.h:356
int getDataTypeWidth() const
Definition: ispc.h:284
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:173
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:1016
ConstExpr * constValue
Definition: sym.h:87
bool hasRand() const
Definition: ispc.h:296
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:166
static llvm::Type * Int8VectorPointerType
Definition: llvmutil.h:101
Globals * g
Definition: ispc.cpp:100
static const AtomicType * UniformUInt64
Definition: type.h:355
int getMaskBitCount() const
Definition: ispc.h:292
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:294
bool VerifyDataLayoutCompatibility(const std::string &module_dl, const std::string &lib_dl)
Definition: util.cpp:621
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:270
static llvm::Type * Int64PointerType
Definition: llvmutil.h:86
bool hasRcpd() const
Definition: ispc.h:308
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:137
static llvm::Type * Int16PointerType
Definition: llvmutil.h:84
bool generateDebuggingSymbols
Definition: ispc.h:614
static const AtomicType * VaryingBool
Definition: type.h:346
bool fastMaskedVload
Definition: ispc.h:448
const char * name
Definition: ispc.h:141
void markFuncWithTargetAttr(llvm::Function *func)
Definition: ispc.cpp:1502
static void lDefineConstantInt(const char *name, int val, llvm::Module *module, SymbolTable *symbolTable, std::vector< llvm::Constant * > &dbg_sym)
Definition: builtins.cpp:997
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:1115
#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:555
static llvm::Type * DoublePointerType
Definition: llvmutil.h:88
bool hasTrigonometry() const
Definition: ispc.h:304
#define ISPC_MAX_NVEC
Definition: ispc.h:69
static bool Equal(const Type *a, const Type *b)
Definition: type.cpp:3752
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:885
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:655
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:639
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:1091
const Type * type
Definition: sym.h:84
llvm::DIBuilder * diBuilder
Definition: module.h:169
void Debug(SourcePos p, const char *format,...) PRINTF_FUNC
Definition: util.cpp:398
bool is32Bit() const
Definition: ispc.h:276
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:302