Intel SPMD Program Compiler  1.9.1
main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010-2016, 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 main.cpp
35  @brief main() entrypoint implementation for ispc
36 */
37 
38 #include "ispc.h"
39 #include "module.h"
40 #include "util.h"
41 #include "type.h"
42 #include <stdio.h>
43 #include <stdlib.h>
44 #ifdef ISPC_IS_WINDOWS
45  #include <time.h>
46 #else
47  #include <unistd.h>
48 #endif // ISPC_IS_WINDOWS
49 #include <llvm/Support/Signals.h>
50 #include <llvm/Support/TargetRegistry.h>
51 #include <llvm/Support/TargetSelect.h>
52 
53 #ifdef ISPC_IS_WINDOWS
54 #define strcasecmp stricmp
55 #ifndef BUILD_DATE
56 #define BUILD_DATE __DATE__
57 #endif
58 #define BUILD_VERSION ""
59 #if _MSC_VER >= 1900
60 #define ISPC_VS_VERSION "Visual Studio 2015 and later"
61 #else
62 #define ISPC_VS_VERSION "Visual Studio 2013 and earlier"
63 #endif
64 #endif // ISPC_IS_WINDOWS
65 
66 static void
68 #ifdef ISPC_IS_WINDOWS
69  printf("Intel(r) SPMD Program Compiler (ispc), %s (build date %s, LLVM %s)\n"
70  "Supported Visual Studio versions: %s.\n",
71  ISPC_VERSION, BUILD_DATE,
72  ISPC_LLVM_VERSION_STRING,
73  ISPC_VS_VERSION
74  );
75 #else
76  printf("Intel(r) SPMD Program Compiler (ispc), %s (build %s @ %s, LLVM %s)\n",
77  ISPC_VERSION, BUILD_VERSION, BUILD_DATE,
78  ISPC_LLVM_VERSION_STRING
79  );
80 #endif
81 }
82 
83 
84 static void
85 usage(int ret) {
86  lPrintVersion();
87  printf("\nusage: ispc\n");
88  printf(" [--addressing={32,64}]\t\tSelect 32- or 64-bit addressing. (Note that 32-bit\n");
89  printf(" \t\taddressing calculations are done by default, even\n");
90  printf(" \t\ton 64-bit target architectures.)\n");
91  printf(" [--arch={%s}]\t\tSelect target architecture\n",
93  printf(" [--c++-include-file=<name>]\t\tSpecify name of file to emit in #include statement in generated C++ code.\n");
94 #ifndef ISPC_IS_WINDOWS
95  printf(" [--colored-output]\t\tAlways use terminal colors in error/warning messages.\n");
96 #endif
97  printf(" ");
98  char cpuHelp[2048];
99  sprintf(cpuHelp, "[--cpu=<cpu>]\t\t\tSelect target CPU type\n<cpu>={%s}\n",
100  Target::SupportedCPUs().c_str());
101  PrintWithWordBreaks(cpuHelp, 16, TerminalWidth(), stdout);
102  printf(" [-D<foo>]\t\t\t\t#define given value when running preprocessor\n");
103  printf(" [--dev-stub <filename>]\t\tEmit device-side offload stub functions to file\n");
104 #ifdef ISPC_IS_WINDOWS
105  printf(" [--dllexport]\t\t\tMake non-static functions DLL exported. Windows only.\n");
106 #endif
107 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5
108  printf(" [--dwarf-version={2,3,4}]\t\tGenerate source-level debug information with given DWARF version (triggers -g)\n");
109 #endif
110  printf(" [--emit-asm]\t\t\tGenerate assembly language file as output\n");
111  printf(" [--emit-c++]\t\t\tEmit a C++ source file as output\n");
112  printf(" [--emit-llvm]\t\t\tEmit LLVM bitode file as output\n");
113  printf(" [--emit-obj]\t\t\tGenerate object file file as output (default)\n");
114  printf(" [--force-alignment=<value>]\t\tForce alignment in memory allocations routine to be <value>\n");
115  printf(" [-g]\t\t\t\tGenerate source-level debug information\n");
116  printf(" [--help]\t\t\t\tPrint help\n");
117  printf(" [--help-dev]\t\t\tPrint help for developer options\n");
118  printf(" [--host-stub <filename>]\t\tEmit host-side offload stub functions to file\n");
119  printf(" [-h <name>/--header-outfile=<name>]\tOutput filename for header\n");
120  printf(" [-I <path>]\t\t\t\tAdd <path> to #include file search path\n");
121  printf(" [--instrument]\t\t\tEmit instrumentation to gather performance data\n");
122  printf(" [--math-lib=<option>]\t\tSelect math library\n");
123  printf(" default\t\t\t\tUse ispc's built-in math functions\n");
124  printf(" fast\t\t\t\tUse high-performance but lower-accuracy math functions\n");
125  printf(" svml\t\t\t\tUse the Intel(r) SVML math libraries\n");
126  printf(" system\t\t\t\tUse the system's math library (*may be quite slow*)\n");
127  printf(" [-MMM <filename>\t\t\tWrite #include dependencies to given file.\n");
128  printf(" [--no-omit-frame-pointer]\t\tDisable frame pointer omission. It may be useful for profiling\n");
129  printf(" [--nostdlib]\t\t\tDon't make the ispc standard library available\n");
130  printf(" [--nocpp]\t\t\t\tDon't run the C preprocessor\n");
131  printf(" [-o <name>/--outfile=<name>]\tOutput filename (may be \"-\" for standard output)\n");
132  printf(" [-O0/-O(1/2/3)]\t\t\tSet optimization level (off or on). Optimizations are on by default.\n");
133  printf(" [--opt=<option>]\t\t\tSet optimization option\n");
134  printf(" disable-assertions\t\tRemove assertion statements from final code.\n");
135  printf(" disable-fma\t\t\tDisable 'fused multiply-add' instructions (on targets that support them)\n");
136  printf(" disable-loop-unroll\t\tDisable loop unrolling.\n");
137  printf(" fast-masked-vload\t\tFaster masked vector loads on SSE (may go past end of array)\n");
138  printf(" fast-math\t\t\tPerform non-IEEE-compliant optimizations of numeric expressions\n");
139  printf(" force-aligned-memory\t\tAlways issue \"aligned\" vector load and store instructions\n");
140 #ifndef ISPC_IS_WINDOWS
141  printf(" [--pic]\t\t\t\tGenerate position-independent code\n");
142 #endif // !ISPC_IS_WINDOWS
143  printf(" [--quiet]\t\t\t\tSuppress all output\n");
144  printf(" ");
145  char targetHelp[2048];
146  sprintf(targetHelp, "[--target=<t>]\t\t\tSelect target ISA and width.\n"
147  "<t>={%s}", Target::SupportedTargets());
148  PrintWithWordBreaks(targetHelp, 24, TerminalWidth(), stdout);
149  printf(" [--version]\t\t\t\tPrint ispc version\n");
150  printf(" [--werror]\t\t\t\tTreat warnings as errors\n");
151  printf(" [--woff]\t\t\t\tDisable warnings\n");
152  printf(" [--wno-perf]\t\t\tDon't issue warnings related to performance-related issues\n");
153  printf(" <file to compile or \"-\" for stdin>\n");
154  exit(ret);
155 }
156 
157 
158 static void
159 devUsage(int ret) {
160  lPrintVersion();
161  printf("\nusage (developer options): ispc\n");
162  printf(" [--debug]\t\t\t\tPrint information useful for debugging ispc\n");
163  printf(" [--print-target]\t\t\tPrint target's information\n");
164  printf(" [--fuzz-test]\t\t\tRandomly perturb program input to test error conditions\n");
165  printf(" [--fuzz-seed=<value>]\t\tSeed value for RNG for fuzz testing\n");
166  printf(" [--opt=<option>]\t\t\tSet optimization option\n");
167  printf(" disable-all-on-optimizations\t\tDisable optimizations that take advantage of \"all on\" mask\n");
168  printf(" disable-blended-masked-stores\t\tScalarize masked stores on SSE (vs. using vblendps)\n");
169  printf(" disable-blending-removal\t\tDisable eliminating blend at same scope\n");
170  printf(" disable-coalescing\t\t\tDisable gather coalescing\n");
171  printf(" disable-coherent-control-flow\t\tDisable coherent control flow optimizations\n");
172  printf(" disable-gather-scatter-flattening\tDisable flattening when all lanes are on\n");
173  printf(" disable-gather-scatter-optimizations\tDisable improvements to gather/scatter\n");
174  printf(" disable-handle-pseudo-memory-ops\tLeave __pseudo_* calls for gather/scatter/etc. in final IR\n");
175  printf(" disable-uniform-control-flow\t\tDisable uniform control flow optimizations\n");
176  printf(" disable-uniform-memory-optimizations\tDisable uniform-based coherent memory access\n");
177  printf(" [--yydebug]\t\t\t\tPrint debugging information during parsing\n");
178  printf(" [--debug-phase=<value>]\t\tSet optimization phases to dump. --debug-phase=first,210:220,300,305,310:last\n");
179 #if ISPC_LLVM_VERSION == ISPC_LLVM_3_4 || ISPC_LLVM_VERSION == ISPC_LLVM_3_5 // 3.4, 3.5
180  printf(" [--debug-ir=<value>]\t\tSet optimization phase to generate debugIR after it\n");
181 #endif
182  printf(" [--off-phase=<value>]\t\tSwitch off optimization phases. --off-phase=first,210:220,300,305,310:last\n");
183  exit(ret);
184 }
185 
186 
187 /** We take arguments from both the command line as well as from the
188  ISPC_ARGS environment variable. This function returns a new set of
189  arguments representing the ones from those two sources merged together.
190 */
191 static void lGetAllArgs(int Argc, char *Argv[], int &argc, char *argv[128]) {
192  // Copy over the command line arguments (passed in)
193  for (int i = 0; i < Argc; ++i)
194  argv[i] = Argv[i];
195  argc = Argc;
196 
197  // See if we have any set via the environment variable
198  const char *env = getenv("ISPC_ARGS");
199  if (!env)
200  return;
201  while (true) {
202  // Look for the next space in the string, which delimits the end of
203  // the current argument
204  const char *end = strchr(env, ' ');
205  if (end == NULL)
206  end = env + strlen(env);
207  int len = end - env;
208 
209  // Copy the argument into a newly allocated memory (so we can
210  // NUL-terminate it).
211  char *ptr = new char[len+1];
212  strncpy(ptr, env, len);
213  ptr[len] = '\0';
214 
215  // Add it to the args array and get out of here
216  argv[argc++] = ptr;
217  if (*end == '\0')
218  break;
219 
220  // Advance the starting pointer of the string to the next non-space
221  // character
222  env = end+1;
223  while (*env == ' ')
224  ++env;
225 
226  // Hit the end of the string; get out of here
227  if (*env == '\0')
228  break;
229  }
230 }
231 
232 
233 static void
234 lSignal(void *) {
235  FATAL("Unhandled signal sent to process; terminating.");
236 }
237 
238 
239 static int ParsingPhaseName(char * stage) {
240  if (strncmp(stage, "first", 5) == 0) {
241  return 0;
242  }
243  else if (strncmp(stage, "last", 4) == 0) {
244  return LAST_OPT_NUMBER;
245  }
246  else {
247  int t = atoi(stage);
248  if (t < 0 || t > LAST_OPT_NUMBER) {
249  fprintf(stderr, "Phases must be from 0 to %d. %s is incorrect.\n", LAST_OPT_NUMBER, stage);
250  exit(0);
251  }
252  else {
253  return t;
254  }
255  }
256 }
257 
258 
259 static std::set<int> ParsingPhases(char * stages) {
260  std::set<int> phases;
261  int begin = ParsingPhaseName(stages);
262  int end = begin;
263 
264  for (unsigned i = 0; i < strlen(stages); i++) {
265  if ((stages[i] == ',') || (i == strlen(stages) - 1)) {
266  for (int j = begin; j < end + 1; j++) {
267  phases.insert(j);
268  }
269  begin = ParsingPhaseName(stages + i + 1);
270  end = begin;
271  }
272  else if (stages[i] == ':') {
273  end = ParsingPhaseName(stages + i + 1);
274  }
275  }
276  return phases;
277 }
278 
279 
280 static void
281 lParseInclude(const char *path) {
282 #ifdef ISPC_IS_WINDOWS
283  char delim = ';';
284 #else
285  char delim = ':';
286 #endif
287  size_t pos = 0, pos_end;
288  std::string str_path(path);
289  do {
290  pos_end = str_path.find(delim, pos);
291  size_t len = (pos_end == std::string::npos) ?
292  // Not found, copy till end of the string.
293  std::string::npos :
294  // Copy [pos, pos_end).
295  (pos_end - pos);
296  std::string s = str_path.substr(pos, len);
297  g->includePath.push_back(s);
298  pos = pos_end+1;
299  } while (pos_end != std::string::npos);
300 }
301 
302 
303 int main(int Argc, char *Argv[]) {
304  int argc;
305  char *argv[128];
306  lGetAllArgs(Argc, Argv, argc, argv);
307 
308  llvm::sys::AddSignalHandler(lSignal, NULL);
309 
310  // initialize available LLVM targets
311 #ifndef __arm__
312  // FIXME: LLVM build on ARM doesn't build the x86 targets by default.
313  // It's not clear that anyone's going to want to generate x86 from an
314  // ARM host, though...
315  LLVMInitializeX86TargetInfo();
316  LLVMInitializeX86Target();
317  LLVMInitializeX86AsmPrinter();
318  LLVMInitializeX86AsmParser();
319  LLVMInitializeX86Disassembler();
320  LLVMInitializeX86TargetMC();
321 #endif // !__ARM__
322 
323 #ifdef ISPC_ARM_ENABLED
324  // Generating ARM from x86 is more likely to be useful, though.
325  LLVMInitializeARMTargetInfo();
326  LLVMInitializeARMTarget();
327  LLVMInitializeARMAsmPrinter();
328  LLVMInitializeARMAsmParser();
329  LLVMInitializeARMDisassembler();
330  LLVMInitializeARMTargetMC();
331 #endif
332 
333 #ifdef ISPC_NVPTX_ENABLED
334  LLVMInitializeNVPTXTargetInfo();
335  LLVMInitializeNVPTXTarget();
336  LLVMInitializeNVPTXAsmPrinter();
337  LLVMInitializeNVPTXTargetMC();
338 #endif /* ISPC_NVPTX_ENABLED */
339 
340  char *file = NULL;
341  const char *headerFileName = NULL;
342  const char *outFileName = NULL;
343  const char *includeFileName = NULL;
344  const char *depsFileName = NULL;
345  const char *hostStubFileName = NULL;
346  const char *devStubFileName = NULL;
347  // Initiailize globals early so that we can set various option values
348  // as we're parsing below
349  g = new Globals;
350 
352  bool generatePIC = false;
353  const char *arch = NULL, *cpu = NULL, *target = NULL;
354 
355  for (int i = 1; i < argc; ++i) {
356  if (!strcmp(argv[i], "--help"))
357  usage(0);
358  if (!strcmp(argv[i], "--help-dev"))
359  devUsage(0);
360  else if (!strncmp(argv[i], "-D", 2))
361  g->cppArgs.push_back(argv[i]);
362  else if (!strncmp(argv[i], "--addressing=", 13)) {
363  if (atoi(argv[i] + 13) == 64)
364  // FIXME: this doesn't make sense on 32 bit platform.
365  g->opt.force32BitAddressing = false;
366  else if (atoi(argv[i] + 13) == 32)
367  g->opt.force32BitAddressing = true;
368  else {
369  fprintf(stderr, "Addressing width \"%s\" invalid--only 32 and "
370  "64 are allowed.\n", argv[i]+13);
371  usage(1);
372  }
373  }
374  else if (!strncmp(argv[i], "--arch=", 7))
375  arch = argv[i] + 7;
376  else if (!strncmp(argv[i], "--cpu=", 6))
377  cpu = argv[i] + 6;
378  else if (!strcmp(argv[i], "--fast-math")) {
379  fprintf(stderr, "--fast-math option has been renamed to --opt=fast-math!\n");
380  usage(1);
381  }
382  else if (!strcmp(argv[i], "--fast-masked-vload")) {
383  fprintf(stderr, "--fast-masked-vload option has been renamed to "
384  "--opt=fast-masked-vload!\n");
385  usage(1);
386  }
387  else if (!strcmp(argv[i], "--debug"))
388  g->debugPrint = true;
389 #ifdef ISPC_IS_WINDOWS
390  else if (!strcmp(argv[i], "--dllexport"))
391  g->dllExport = true;
392 #endif
393 #if ISPC_LLVM_VERSION >= ISPC_LLVM_3_5
394  else if (!strncmp(argv[i], "--dwarf-version=", 16)) {
395  int val = atoi(argv[i] + 16);
396  if (2 <= val && val <=4) {
397  g->generateDebuggingSymbols = true;
398  g->generateDWARFVersion=val;
399  } else {
400  fprintf(stderr, "Invalid value for DWARF version: \"%s\" -- "
401  "only 2, 3 and 4 are allowed.\n", argv[i]+16);
402  usage(1);
403  }
404  }
405 #endif
406  else if (!strcmp(argv[i], "--print-target"))
407  g->printTarget = true;
408  else if (!strcmp(argv[i], "--no-omit-frame-pointer"))
409  g->NoOmitFramePointer = true;
410  else if (!strcmp(argv[i], "--instrument"))
411  g->emitInstrumentation = true;
412  else if (!strcmp(argv[i], "-g")) {
413  g->generateDebuggingSymbols = true;
414  }
415  else if (!strcmp(argv[i], "--emit-asm"))
416  ot = Module::Asm;
417  else if (!strcmp(argv[i], "--emit-c++"))
418  ot = Module::CXX;
419  else if (!strcmp(argv[i], "--emit-llvm"))
420  ot = Module::Bitcode;
421  else if (!strcmp(argv[i], "--emit-obj"))
422  ot = Module::Object;
423  else if (!strcmp(argv[i], "-I")) {
424  if (++i == argc) {
425  fprintf(stderr, "No path specified after -I option.\n");
426  usage(1);
427  }
428  lParseInclude(argv[i]);
429  }
430  else if (!strncmp(argv[i], "-I", 2))
431  lParseInclude(argv[i]+2);
432  else if (!strcmp(argv[i], "--fuzz-test"))
433  g->enableFuzzTest = true;
434  else if (!strncmp(argv[i], "--fuzz-seed=", 12))
435  g->fuzzTestSeed = atoi(argv[i] + 12);
436  else if (!strcmp(argv[i], "--target")) {
437  // FIXME: should remove this way of specifying the target...
438  if (++i == argc) {
439  fprintf(stderr, "No target specified after --target option.\n");
440  usage(1);
441  }
442  target = argv[i];
443  }
444  else if (!strncmp(argv[i], "--target=", 9))
445  target = argv[i] + 9;
446  else if (!strncmp(argv[i], "--math-lib=", 11)) {
447  const char *lib = argv[i] + 11;
448  if (!strcmp(lib, "default"))
450  else if (!strcmp(lib, "fast"))
452  else if (!strcmp(lib, "svml"))
454  else if (!strcmp(lib, "system"))
456  else {
457  fprintf(stderr, "Unknown --math-lib= option \"%s\".\n", lib);
458  usage(1);
459  }
460  }
461  else if (!strncmp(argv[i], "--opt=", 6)) {
462  const char *opt = argv[i] + 6;
463  if (!strcmp(opt, "fast-math"))
464  g->opt.fastMath = true;
465  else if (!strcmp(opt, "fast-masked-vload"))
466  g->opt.fastMaskedVload = true;
467  else if (!strcmp(opt, "disable-assertions"))
468  g->opt.disableAsserts = true;
469  else if (!strcmp(opt, "disable-loop-unroll"))
470  g->opt.unrollLoops = false;
471  else if (!strcmp(opt, "disable-fma"))
472  g->opt.disableFMA = true;
473  else if (!strcmp(opt, "force-aligned-memory"))
474  g->opt.forceAlignedMemory = true;
475 
476  // These are only used for performance tests of specific
477  // optimizations
478  else if (!strcmp(opt, "disable-all-on-optimizations"))
480  else if (!strcmp(opt, "disable-coalescing"))
481  g->opt.disableCoalescing = true;
482  else if (!strcmp(opt, "disable-handle-pseudo-memory-ops"))
484  else if (!strcmp(opt, "disable-blended-masked-stores"))
486  else if (!strcmp(opt, "disable-coherent-control-flow"))
488  else if (!strcmp(opt, "disable-uniform-control-flow"))
490  else if (!strcmp(opt, "disable-gather-scatter-optimizations"))
492  else if (!strcmp(opt, "disable-blending-removal"))
494  else if (!strcmp(opt, "disable-gather-scatter-flattening"))
496  else if (!strcmp(opt, "disable-uniform-memory-optimizations"))
498  else {
499  fprintf(stderr, "Unknown --opt= option \"%s\".\n", opt);
500  usage(1);
501  }
502  }
503  else if (!strncmp(argv[i], "--force-alignment=", 18)) {
504  g->forceAlignment = atoi(argv[i] + 18);
505  }
506  else if (!strcmp(argv[i], "--woff") || !strcmp(argv[i], "-woff")) {
507  g->disableWarnings = true;
508  g->emitPerfWarnings = false;
509  }
510  else if (!strcmp(argv[i], "--werror"))
511  g->warningsAsErrors = true;
512  else if (!strcmp(argv[i], "--nowrap"))
513  g->disableLineWrap = true;
514  else if (!strcmp(argv[i], "--wno-perf") || !strcmp(argv[i], "-wno-perf"))
515  g->emitPerfWarnings = false;
516  else if (!strcmp(argv[i], "-o")) {
517  if (++i == argc) {
518  fprintf(stderr, "No output file specified after -o option.\n");
519  usage(1);
520  }
521  outFileName = argv[i];
522  }
523  else if (!strncmp(argv[i], "--outfile=", 10))
524  outFileName = argv[i] + strlen("--outfile=");
525  else if (!strcmp(argv[i], "-h")) {
526  if (++i == argc) {
527  fprintf(stderr, "No header file name specified after -h option.\n");
528  usage(1);
529  }
530  headerFileName = argv[i];
531  }
532  else if (!strncmp(argv[i], "--header-outfile=", 17)) {
533  headerFileName = argv[i] + strlen("--header-outfile=");
534  }
535  else if (!strncmp(argv[i], "--c++-include-file=", 19)) {
536  includeFileName = argv[i] + strlen("--c++-include-file=");
537  }
538  else if (!strcmp(argv[i], "-O0")) {
539  g->opt.level = 0;
540  }
541  else if (!strcmp(argv[i], "-O") || !strcmp(argv[i], "-O1") ||
542  !strcmp(argv[i], "-O2") || !strcmp(argv[i], "-O3")) {
543  g->opt.level = 1;
544  }
545  else if (!strcmp(argv[i], "-"))
546  ;
547  else if (!strcmp(argv[i], "--nostdlib"))
548  g->includeStdlib = false;
549  else if (!strcmp(argv[i], "--nocpp"))
550  g->runCPP = false;
551 #ifndef ISPC_IS_WINDOWS
552  else if (!strcmp(argv[i], "--pic"))
553  generatePIC = true;
554  else if (!strcmp(argv[i], "--colored-output"))
555  g->forceColoredOutput = true;
556 #endif // !ISPC_IS_WINDOWS
557  else if (!strcmp(argv[i], "--quiet"))
558  g->quiet = true;
559  else if (!strcmp(argv[i], "--yydebug")) {
560  extern int yydebug;
561  yydebug = 1;
562  }
563  else if (!strcmp(argv[i], "-MMM")) {
564  if (++i == argc) {
565  fprintf(stderr, "No output file name specified after -MMM option.\n");
566  usage(1);
567  }
568  depsFileName = argv[i];
569  }
570  else if (!strcmp(argv[i], "--dev-stub")) {
571  if (++i == argc) {
572  fprintf(stderr, "No output file name specified after --dev-stub option.\n");
573  usage(1);
574  }
575  devStubFileName = argv[i];
576  }
577  else if (!strcmp(argv[i], "--host-stub")) {
578  if (++i == argc) {
579  fprintf(stderr, "No output file name specified after --host-stub option.\n");
580  usage(1);
581  }
582  hostStubFileName = argv[i];
583  }
584  else if (strncmp(argv[i], "--debug-phase=", 14) == 0) {
585  fprintf(stderr, "WARNING: Adding debug phases may change the way PassManager"
586  "handles the phases and it may possibly make some bugs go"
587  "away or introduce the new ones.\n");
588  g->debug_stages = ParsingPhases(argv[i] + strlen("--debug-phase="));
589  }
590 
591 #if ISPC_LLVM_VERSION == ISPC_LLVM_3_4 || ISPC_LLVM_VERSION == ISPC_LLVM_3_5 // 3.4, 3.5
592  else if (strncmp(argv[i], "--debug-ir=", 11) == 0) {
593  g->debugIR = ParsingPhaseName(argv[i] + strlen("--debug-ir="));
594  }
595 #endif
596  else if (strncmp(argv[i], "--off-phase=", 12) == 0) {
597  g->off_stages = ParsingPhases(argv[i] + strlen("--off-phase="));
598  }
599  else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
600  lPrintVersion();
601  return 0;
602  }
603  else if (argv[i][0] == '-') {
604  fprintf(stderr, "Unknown option \"%s\".\n", argv[i]);
605  usage(1);
606  }
607  else {
608  if (file != NULL) {
609  fprintf(stderr, "Multiple input files specified on command "
610  "line: \"%s\" and \"%s\".\n", file, argv[i]);
611  usage(1);
612  }
613  else
614  file = argv[i];
615  }
616  }
617 
618  if (g->enableFuzzTest) {
619  if (g->fuzzTestSeed == -1) {
620 #ifdef ISPC_IS_WINDOWS
621  int seed = (unsigned)time(NULL);
622 #else
623  int seed = getpid();
624 #endif
625  g->fuzzTestSeed = seed;
626  Warning(SourcePos(), "Using seed %d for fuzz testing",
627  g->fuzzTestSeed);
628  }
629 #ifdef ISPC_IS_WINDOWS
630  srand(g->fuzzTestSeed);
631 #else
632  srand48(g->fuzzTestSeed);
633 #endif
634  }
635 
636  if (outFileName == NULL &&
637  headerFileName == NULL &&
638  depsFileName == NULL &&
639  hostStubFileName == NULL &&
640  devStubFileName == NULL)
641  Warning(SourcePos(), "No output file or header file name specified. "
642  "Program will be compiled and warnings/errors will "
643  "be issued, but no output will be generated.");
644 
645  return Module::CompileAndOutput(file, arch, cpu, target, generatePIC,
646  ot,
647  outFileName,
648  headerFileName,
649  includeFileName,
650  depsFileName,
651  hostStubFileName,
652  devStubFileName);
653 }
bool disableFMA
Definition: ispc.h:459
static void lGetAllArgs(int Argc, char *Argv[], int &argc, char *argv[128])
Definition: main.cpp:191
Opt opt
Definition: ispc.h:541
bool disableWarnings
Definition: ispc.h:579
This structure collects together a number of global variables.
Definition: ispc.h:537
bool disableBlendedMaskedStores
Definition: ispc.h:486
static void lSignal(void *)
Definition: main.cpp:234
bool forceColoredOutput
Definition: ispc.h:597
std::vector< std::string > includePath
Definition: ispc.h:644
bool emitPerfWarnings
Definition: ispc.h:590
bool warningsAsErrors
Definition: ispc.h:582
bool NoOmitFramePointer
Definition: ispc.h:566
bool forceAlignedMemory
Definition: ispc.h:465
int fuzzTestSeed
Definition: ispc.h:629
static const char * SupportedArchs()
Definition: ispc.cpp:1192
OutputType
Definition: module.h:97
static void devUsage(int ret)
Definition: main.cpp:159
bool disableLineWrap
Definition: ispc.h:586
bool disableCoalescing
Definition: ispc.h:526
bool includeStdlib
Definition: ispc.h:552
std::set< int > debug_stages
Definition: ispc.h:569
bool disableMaskAllOnOptimizations
Definition: ispc.h:470
int level
Definition: ispc.h:431
static std::string SupportedCPUs()
Definition: ispc.cpp:1185
Globals * g
Definition: ispc.cpp:88
bool disableGatherScatterOptimizations
Definition: ispc.h:504
bool debugPrint
Definition: ispc.h:560
bool disableCoherentControlFlow
Definition: ispc.h:492
static void lPrintVersion()
Definition: main.cpp:67
bool enableFuzzTest
Definition: ispc.h:626
bool printTarget
Definition: ispc.h:563
void PrintWithWordBreaks(const char *buf, int indent, int columnWidth, FILE *out)
Definition: util.cpp:230
int TerminalWidth()
Definition: util.cpp:81
bool runCPP
Definition: ispc.h:556
bool emitInstrumentation
Definition: ispc.h:603
bool unrollLoops
Definition: ispc.h:445
Representation of a range of positions in a source file.
Definition: ispc.h:134
bool disableUniformMemoryOptimizations
Definition: ispc.h:522
bool generateDebuggingSymbols
Definition: ispc.h:607
bool fastMath
Definition: ispc.h:435
static void lParseInclude(const char *path)
Definition: main.cpp:281
bool fastMaskedVload
Definition: ispc.h:441
bool disableHandlePseudoMemoryOps
Definition: ispc.h:476
bool force32BitAddressing
Definition: ispc.h:451
bool dllExport
Definition: ispc.h:651
void Warning(SourcePos p, const char *format,...) PRINTF_FUNC
Definition: util.cpp:410
int main(int Argc, char *Argv[])
Definition: main.cpp:303
#define FATAL(message)
Definition: util.h:113
MathLib mathLib
Definition: ispc.h:548
bool disableUniformControlFlow
Definition: ispc.h:498
bool disableMaskedStoreToStore
Definition: ispc.h:510
int forceAlignment
Definition: ispc.h:648
static int ParsingPhaseName(char *stage)
Definition: main.cpp:239
bool quiet
Definition: ispc.h:593
std::set< int > off_stages
Definition: ispc.h:576
std::vector< std::string > cppArgs
Definition: ispc.h:640
static std::set< int > ParsingPhases(char *stages)
Definition: main.cpp:259
Declaration of the Module class, which is the ispc-side representation of the results of compiling a ...
static const char * SupportedTargets()
Definition: ispc.cpp:1202
#define LAST_OPT_NUMBER
Definition: ispc.h:71
Main ispc.header file. Defines Target, Globals and Opt classes.
static void usage(int ret)
Definition: main.cpp:85
bool disableAsserts
Definition: ispc.h:455
static int CompileAndOutput(const char *srcFile, const char *arch, const char *cpu, const char *targets, bool generatePIC, OutputType outputType, const char *outFileName, const char *headerFileName, const char *includeFileName, const char *depsFileName, const char *hostStubFileName, const char *devStubFileName)
Definition: module.cpp:3046
File with declarations for classes related to type representation.
bool disableGatherScatterFlattening
Definition: ispc.h:516
int debugIR
Definition: ispc.h:573