-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[native_toolchain_c] Compile with
-Os
by default
- Loading branch information
Showing
12 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
pkgs/native_toolchain_c/lib/src/cbuilder/optimization_level.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// Optimization level for code compilation. | ||
/// | ||
/// For more information refer to compiler documentation: | ||
/// * https://clang.llvm.org/docs/CommandGuide/clang.html#code-generation-options | ||
/// * https://learn.microsoft.com/en-us/cpp/build/reference/o-options-optimize-code?view=msvc-170 | ||
final class OptimizationLevel { | ||
/// The optimization level. | ||
final String _level; | ||
|
||
const OptimizationLevel._(this._level); | ||
|
||
/// No optimization; prioritize fast compilation. | ||
static const OptimizationLevel o0 = OptimizationLevel._('O0'); | ||
|
||
/// Basic optimizations; balance compilation speed and code size. | ||
static const OptimizationLevel o1 = OptimizationLevel._('O1'); | ||
|
||
/// More aggressive optimizations; prioritize code size reduction. | ||
static const OptimizationLevel o2 = OptimizationLevel._('O2'); | ||
|
||
/// The most aggressive optimizations; prioritize runtime performance. | ||
/// | ||
/// Not supported in MSVC, defaults to [o2] for MSVC. | ||
static const OptimizationLevel o3 = OptimizationLevel._('O3'); | ||
|
||
/// Optimize for code size, even if it impacts runtime performance. | ||
static const OptimizationLevel oS = OptimizationLevel._('Os'); | ||
|
||
/// Optimize aggressively for code size, potentially at the cost of | ||
/// compilation time and debugging capabilities. | ||
/// | ||
/// Not supported in MSVC, defaults to [oS] for MSVC. | ||
static const OptimizationLevel oZ = OptimizationLevel._('Oz'); | ||
|
||
/// Unspecified optimization level; the default or compiler-chosen level. | ||
static const OptimizationLevel unspecified = | ||
OptimizationLevel._('unspecified'); | ||
|
||
/// Returns the string representation of the optimization level. | ||
@override | ||
String toString() => _level; | ||
|
||
String clangFlag() => '-$_level'; | ||
|
||
String msvcFlag() => switch (this) { | ||
// TODO: Handle this case. | ||
o3 => o2.msvcFlag(), | ||
oZ => oS.msvcFlag(), | ||
_ => '/$_level', | ||
}; | ||
|
||
static const List<OptimizationLevel> values = [ | ||
o0, | ||
o1, | ||
o2, | ||
o3, | ||
oS, | ||
oZ, | ||
unspecified, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters