Advertisement
Guest User

Untitled

a guest
Aug 10th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. # The BUILDCONFIG file sets this config on targets by default, which means when
  2. # building with ThinLTO, no optimization is performed in the link step.
  3. config("thinlto_optimize_default") {
  4. if (!is_debug && use_thin_lto && is_a_target_toolchain) {
  5. lto_opt_level = 2
  6.  
  7. if (is_win) {
  8. ldflags = [ "/opt:lldlto=" + lto_opt_level ]
  9. } else {
  10. ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
  11. }
  12. }
  13. }
  14.  
  15. # Use this to enable optimization in the ThinLTO link step for select targets
  16. # when thin_lto_enable_optimizations is set by doing:
  17. #
  18. # configs -= [ "//build/config/compiler:thinlto_optimize_default" ]
  19. # configs += [ "//build/config/compiler:thinlto_optimize_max" ]
  20. #
  21. # Since it makes linking significantly slower and more resource intensive, only
  22. # use it on important targets such as the main browser executable or dll.
  23. config("thinlto_optimize_max") {
  24. if (!is_debug && use_thin_lto && is_a_target_toolchain) {
  25. if (thin_lto_enable_optimizations) {
  26. lto_opt_level = 2
  27. } else {
  28. lto_opt_level = 2
  29. }
  30.  
  31. if (is_win) {
  32. ldflags = [ "/opt:lldlto=" + lto_opt_level ]
  33. } else {
  34. ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
  35. }
  36. }
  37. }
  38.  
  39. ----------------
  40.  
  41. # Default "optimization on" config.
  42. config("optimize") {
  43. if (is_win) {
  44. if (chrome_pgo_phase != 2) {
  45. # Favor size over speed, /O1 must be before the common flags.
  46. # /O1 implies /Os and /GF.
  47. cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
  48. } else {
  49. # PGO requires all translation units to be compiled with /O2. The actual
  50. # optimization level will be decided based on the profiling data.
  51. cflags = [ "/O2" ] + common_optimize_on_cflags + [ "/Oi" ]
  52. }
  53. } else if (optimize_for_size) {
  54. # Favor size over speed.
  55. if (is_clang) {
  56. cflags = [ "-O2" ] + common_optimize_on_cflags
  57. } else {
  58. cflags = [ "-O2" ] + common_optimize_on_cflags
  59. }
  60. } else if (is_chromeos) {
  61. # TODO(gbiv): This is partially favoring size over speed. CrOS exclusively
  62. # uses clang, and -Os in clang is more of a size-conscious -O2 than "size at
  63. # any cost" (AKA -Oz). It'd be nice to:
  64. # - Make `optimize_for_size` apply to all platforms where we're optimizing
  65. # for size by default (so, also Windows)
  66. # - Investigate -Oz here, maybe just for ARM?
  67. cflags = [ "-Os" ] + common_optimize_on_cflags
  68. } else {
  69. cflags = [ "-O2" ] + common_optimize_on_cflags
  70. }
  71. if (optimize_for_size) {
  72. rustflags = [ "-Copt-level=2" ]
  73. } else {
  74. rustflags = [ "-Copt-level=3" ]
  75. }
  76. ldflags = common_optimize_on_ldflags
  77. }
  78.  
  79. # Turn off optimizations.
  80. config("no_optimize") {
  81. if (is_win) {
  82. cflags = [
  83. "/Od", # Disable optimization.
  84. "/Ob0", # Disable all inlining (on by default).
  85. "/GF", # Enable string pooling (off by default).
  86. ]
  87.  
  88. if (target_cpu == "arm64") {
  89. # Disable omitting frame pointers for no_optimize build because stack
  90. # traces on Windows ARM64 rely on it.
  91. cflags += [ "/Oy-" ]
  92. }
  93. } else if (is_android && !android_full_debug) {
  94. # On Android we kind of optimize some things that don't affect debugging
  95. # much even when optimization is disabled to get the binary size down.
  96. if (is_clang) {
  97. cflags = [ "-Oz" ] + common_optimize_on_cflags
  98. } else {
  99. cflags = [ "-Os" ] + common_optimize_on_cflags
  100. }
  101.  
  102. if (!is_component_build) {
  103. # Required for library partitions. Without this all symbols just end up
  104. # in the base partition.
  105. ldflags = [ "-Wl,--gc-sections" ]
  106. }
  107. } else if (is_fuchsia) {
  108. # On Fuchsia, we optimize for size here to reduce the size of debug build
  109. # packages so they can be run in a KVM. See crbug.com/910243 for details.
  110. cflags = [ "-Og" ]
  111. } else {
  112. cflags = [ "-O0" ]
  113. ldflags = []
  114. }
  115. }
  116.  
  117. # Turns up the optimization level. On Windows, this implies whole program
  118. # optimization and link-time code generation which is very expensive and should
  119. # be used sparingly.
  120. config("optimize_max") {
  121. if (is_nacl && is_nacl_irt) {
  122. # The NaCl IRT is a special case and always wants its own config.
  123. # Various components do:
  124. # if (!is_debug) {
  125. # configs -= [ "//build/config/compiler:default_optimization" ]
  126. # configs += [ "//build/config/compiler:optimize_max" ]
  127. # }
  128. # So this config has to have the selection logic just like
  129. # "default_optimization", below.
  130. configs = [ "//build/config/nacl:irt_optimize" ]
  131. } else {
  132. ldflags = common_optimize_on_ldflags
  133. if (is_win) {
  134. # Favor speed over size, /O2 must be before the common flags.
  135. # /O2 implies /Ot, /Oi, and /GF.
  136. cflags = [ "-Xclang", "-O3", ] + common_optimize_on_cflags
  137. } else if (optimize_for_fuzzing) {
  138. cflags = [ "-O1" ] + common_optimize_on_cflags
  139. } else {
  140. cflags = [ "-O3" ] + common_optimize_on_cflags
  141. }
  142. rustflags = [ "-Copt-level=3" ]
  143. }
  144. }
  145.  
  146. # This config can be used to override the default settings for per-component
  147. # and whole-program optimization, optimizing the particular target for speed
  148. # instead of code size. This config is exactly the same as "optimize_max"
  149. # except that we use -O3 instead of -O2 on non-win, non-IRT platforms.
  150. #
  151. # TODO(crbug.com/621335) - rework how all of these configs are related
  152. # so that we don't need this disclaimer.
  153. config("optimize_speed") {
  154. if (is_nacl && is_nacl_irt) {
  155. # The NaCl IRT is a special case and always wants its own config.
  156. # Various components do:
  157. # if (!is_debug) {
  158. # configs -= [ "//build/config/compiler:default_optimization" ]
  159. # configs += [ "//build/config/compiler:optimize_max" ]
  160. # }
  161. # So this config has to have the selection logic just like
  162. # "default_optimization", below.
  163. configs = [ "//build/config/nacl:irt_optimize" ]
  164. } else {
  165. ldflags = common_optimize_on_ldflags
  166. if (is_win) {
  167. # Favor speed over size, /O2 must be before the common flags.
  168. # /O2 implies /Ot, /Oi, and /GF.
  169. cflags = [ "-Xclang", "-O3", ] + common_optimize_on_cflags
  170. } else if (optimize_for_fuzzing) {
  171. cflags = [ "-O1" ] + common_optimize_on_cflags
  172. } else {
  173. cflags = [ "-O3" ] + common_optimize_on_cflags
  174. }
  175. rustflags = [ "-Copt-level=3" ]
  176. }
  177. }
  178.  
  179.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement