@@ -282,17 +282,9 @@ bool Program::build(const char *options, list<Header> headers)
282
282
}
283
283
args.push_back (cl_ext.c_str ());
284
284
285
- // Disable Clang's optimizations.
286
- // We will manually run optimization passes and legalize the IR later.
287
- args.push_back (" -O0" );
288
-
289
- bool optimize = true ;
285
+ bool defaultOptimization = true ;
290
286
const char *clstd = NULL ;
291
287
292
- // Disable optimizations by default if in interactive mode
293
- if (checkEnv (" OCLGRIND_INTERACTIVE" ))
294
- optimize = false ;
295
-
296
288
// Add OpenCL build options
297
289
const char *mainOptions = options;
298
290
const char *extraOptions = getenv (" OCLGRIND_BUILD_OPTIONS" );
@@ -320,15 +312,9 @@ bool Program::build(const char *options, list<Header> headers)
320
312
strcmp (opt, " -cl-unsafe-math-optimizations" ) != 0 )
321
313
{
322
314
// Check for optimization flags
323
- if (strcmp (opt, " -O0 " ) == 0 || strcmp (opt, " -cl-opt-disable" ) == 0 )
315
+ if (strncmp (opt, " -O " , 2 ) == 0 || strcmp (opt, " -cl-opt-disable" ) == 0 )
324
316
{
325
- optimize = false ;
326
- continue ;
327
- }
328
- else if (strncmp (opt, " -O" , 2 ) == 0 )
329
- {
330
- optimize = true ;
331
- continue ;
317
+ defaultOptimization = false ;
332
318
}
333
319
334
320
// Clang no longer supports -cl-no-signed-zeros
@@ -346,6 +332,16 @@ bool Program::build(const char *options, list<Header> headers)
346
332
}
347
333
}
348
334
335
+ if (defaultOptimization)
336
+ {
337
+ // Disable optimizations by default if in interactive mode
338
+ if (checkEnv (" OCLGRIND_INTERACTIVE" ))
339
+ args.push_back (" -O0" );
340
+ // Otherwise, default to optimizing for size
341
+ else
342
+ args.push_back (" -Oz" );
343
+ }
344
+
349
345
if (!clstd)
350
346
{
351
347
clstd = " -cl-std=CL1.2" ;
@@ -495,29 +491,6 @@ bool Program::build(const char *options, list<Header> headers)
495
491
stripDebugIntrinsics ();
496
492
}
497
493
498
- // Run optimizations on module
499
- if (optimize)
500
- {
501
- // Initialize pass managers
502
- llvm::legacy::PassManager modulePasses;
503
- llvm::legacy::FunctionPassManager functionPasses (m_module.get ());
504
-
505
- // Populate pass managers with -Oz
506
- llvm::PassManagerBuilder builder;
507
- builder.OptLevel = 2 ;
508
- builder.SizeLevel = 2 ;
509
- builder.populateModulePassManager (modulePasses);
510
- builder.populateFunctionPassManager (functionPasses);
511
-
512
- // Run passes
513
- functionPasses.doInitialization ();
514
- llvm::Module::iterator fItr ;
515
- for (fItr = m_module->begin (); fItr != m_module->end (); fItr ++)
516
- functionPasses.run (*fItr );
517
- functionPasses.doFinalization ();
518
- modulePasses.run (*m_module);
519
- }
520
-
521
494
removeLValueLoads ();
522
495
523
496
allocateProgramScopeVars ();
0 commit comments