Skip to contentSkip to conversation

Split CONFIG_CC_OPTIMIZE_FOR_SIZE into two configs

PATCH In review Sean Anderson 3 participants 8 messages Feb 22, 2022 – Mar 26, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Split CONFIG_CC_OPTIMIZE_FOR_SIZE into two configs

This adds a separate CONFIG_CC_OPTIMIZE_FOR_SPEED option in a choice, in preparation for adding another optimization option. Also convert SH's makefile to use this new option.

---

 Kconfig              | 17 ++++++++++++++---
 Makefile             |  4 +++-
 arch/sh/lib/Makefile |  2 +-
 3 files changed, 18 insertions(+), 5 deletions(-)
Kconfig +14 -3
index 9dd9ec7f6d..8159c596c0 100644
@@ -72,15 +72,26 @@ config CLANG_VERSION
 	int
 	default $(shell,$(srctree)/scripts/clang-version.sh $(CC))
 
+choice
+	prompt "Optimization level"
+	default CC_OPTIMIZE_FOR_SIZE
+
 config CC_OPTIMIZE_FOR_SIZE
 	bool "Optimize for size"
-	default y
 	help
-	  Enabling this option will pass "-Os" instead of "-O2" to gcc
-	  resulting in a smaller U-Boot image.
+	  Enabling this option will pass "-Os" to gcc, resulting in a smaller
+	  U-Boot image.
 
 	  This option is enabled by default for U-Boot.
 
+config CC_OPTIMIZE_FOR_SPEED
+	bool "Optimize for speed"
+	help
+	  Enabling this option will pass "-O2" to gcc, resulting in a faster
+	  U-Boot image.
+
+endchoice
+
 config OPTIMIZE_INLINING
 	bool "Allow compiler to uninline functions marked 'inline' in full U-Boot"
 	help
Makefile +3 -1
index 4b152249ca..1d3331c69f 100644
@@ -682,7 +682,9 @@ endif
 
 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
 KBUILD_CFLAGS	+= -Os
-else
+endif
+
+ifdef CONFIG_CC_OPTIMIZE_FOR_SPEED
 KBUILD_CFLAGS	+= -O2
 endif
 
arch/sh/lib/Makefile +1 -1
index 9618da1cb3..e7520a328d 100644
@@ -12,7 +12,7 @@ obj-$(CONFIG_CMD_SH_ZIMAGEBOOT) += zimageboot.o
 
 udivsi3-y			:= udivsi3_i4i-Os.o
 
-ifneq ($(CONFIG_CC_OPTIMIZE_FOR_SIZE),y)
+ifeq ($(CONFIG_CC_OPTIMIZE_FOR_SPEED),y)
 udivsi3-$(CONFIG_CPU_SH4)	:= udivsi3_i4i.o
 endif
 udivsi3-y			+= udivsi3.o
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 Add option to use -Og

This adds support for using -Og when building U-Boot. According to the gcc man page:

Quoted 3 lines

-Og should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

This optimization level is roughly -O1 minus a few additional optimizations. It provides a noticably better debugging experience, with many fewer variables <optimized out>.

---

 Kconfig  | 6 ++++++
 Makefile | 4 ++++
 2 files changed, 10 insertions(+)
Kconfig +6 -0
index 8159c596c0..112745440b 100644
@@ -90,6 +90,12 @@ config CC_OPTIMIZE_FOR_SPEED
 	  Enabling this option will pass "-O2" to gcc, resulting in a faster
 	  U-Boot image.
 
+config CC_OPTIMIZE_FOR_DEBUG
+	bool "Optimize for debugging"
+	help
+	  Enabling this option will pass "-Og" to gcc, enabling optimizations
+	  which don't interfere with debugging.
+
 endchoice
 
 config OPTIMIZE_INLINING
Makefile +4 -0
index 1d3331c69f..7242eafc1e 100644
@@ -688,6 +688,10 @@ ifdef CONFIG_CC_OPTIMIZE_FOR_SPEED
 KBUILD_CFLAGS	+= -O2
 endif
 
+ifdef CONFIG_CC_OPTIMIZE_FOR_DEBUG
+KBUILD_CFLAGS	+= -Og
+endif
+
 LTO_CFLAGS :=
 LTO_FINAL_LDFLAGS :=
 export LTO_CFLAGS LTO_FINAL_LDFLAGS
Signature · 1 line
2.25.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] Add option to use -Og

Quoted 12 lines · Sean Anderson

This adds support for using -Og when building U-Boot. According to the gcc man page:

Quoted 3 lines

-Og should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

This optimization level is roughly -O1 minus a few additional optimizations. It provides a noticably better debugging experience, with many fewer variables <optimized out>.

Quoted 6 lines

---

 Kconfig  | 6 ++++++
 Makefile | 4 ++++
 2 files changed, 10 insertions(+)

But how about an update in doc/ ?

Regards,
Simon

#3 lore raw

Re: [PATCH 2/2] Add option to use -Og

Quoted 16 lines · Simon Glass
Quoted 15 lines · Sean Anderson

This adds support for using -Og when building U-Boot. According to the gcc man page:

Quoted 3 lines

-Og should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

This optimization level is roughly -O1 minus a few additional optimizations. It provides a noticably better debugging experience, with many fewer variables <optimized out>.

---

Quoted 7 lines
Quoted 3 lines
 Kconfig  | 6 ++++++
 Makefile | 4 ++++
 2 files changed, 10 insertions(+)

But how about an update in doc/ ?

What should be updated? As far as I can tell, optimization level is not otherwise documented. IMO the Kconfig does a reasonable job of documentation.

--Sean

#4 lore raw

Re: [PATCH 2/2] Add option to use -Og

Quoted 23 lines · Sean Anderson
Quoted 20 lines · Simon Glass
Quoted 18 lines · Sean Anderson

This adds support for using -Og when building U-Boot. According to the gcc man page:

Quoted 3 lines

-Og should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

This optimization level is roughly -O1 minus a few additional optimizations. It provides a noticably better debugging experience, with many fewer variables <optimized out>.

---

 Kconfig  | 6 ++++++
 Makefile | 4 ++++
 2 files changed, 10 insertions(+)
Quoted 7 lines
Quoted 3 lines

But how about an update in doc/ ?

What should be updated? As far as I can tell, optimization level is not otherwise documented. IMO the Kconfig does a reasonable job of documentation.

A follow-up to note somewhere under doc/ about this would be good. I'll pick up the series for next soon.

Signature · 1 line
Tom
#5 lore raw

Re: [PATCH 2/2] Add option to use -Og

In reply to Sean Anderson
Quoted 7 lines · Sean Anderson

This adds support for using -Og when building U-Boot. According to the gcc man page:

Quoted 3 lines

-Og should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

Quoted 6 lines

This optimization level is roughly -O1 minus a few additional optimizations. It provides a noticably better debugging experience, with many fewer variables <optimized out>.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
Reviewed-by on v1 1/2
#6 lore raw
In reply to Sean Anderson
Quoted 5 lines · Sean Anderson

This adds a separate CONFIG_CC_OPTIMIZE_FOR_SPEED option in a choice, in preparation for adding another optimization option. Also convert SH's makefile to use this new option.

Quoted 7 lines

---

 Kconfig              | 17 ++++++++++++++---
 Makefile             |  4 +++-
 arch/sh/lib/Makefile |  2 +-
 3 files changed, 18 insertions(+), 5 deletions(-)