1

I'm writing some performance critical Swift code that I'm sure is safe to be optimized with -Ounchecked. I'd like the rest of the code to be compiled with a less aggressive optimization.

I can set compiler settings per file as per the answer here: Specific compiler flags for specific files in Xcode

How can I use that knowledge to set a specific file in my project to one of Swift's various optimization levels? (i.e. what compiler settings are available to me and how can I use them)

Community
  • 1
  • 1
ephemer
  • 1,239
  • 8
  • 21
  • Possible duplicate of [Specific compiler flags for specific files in Xcode](http://stackoverflow.com/questions/2764735/specific-compiler-flags-for-specific-files-in-xcode) – Kurt Revis Apr 18 '16 at 06:54
  • @KurtRevis thanks for the link! That question may well prove to have the same answer (I assume it will.. I'm going to try it tomorrow) but I'd argue that this not a duplicate question. I've actually used that trick before for something else but it didn't come to mind when I was thinking of optimization level. – ephemer Apr 19 '16 at 01:05
  • I can't think of any other way to set the optimization level, per-file, than to use a per-file compiler flag. – Kurt Revis Apr 19 '16 at 03:26
  • I agree, but when I googled setting optimization level per file nothing came up. So the question is helpful to anyone in the community looking for the same thing – ephemer Apr 19 '16 at 12:42

1 Answers1

1

I am not sure whether this is an answer to your question or just a side note but you can disable/enable optimization on specific function, not just per file, using optimize() compiler directive

void* __attribute__((optimize("O0"))) myfuncn(void* pointer) {
    // unmodifiable compiler code
}

This will ensure your myfuncn() function will not be optimized

DanielHsH
  • 4,287
  • 3
  • 30
  • 36