Use gcc "-fwhole-program" optimization.

Use "whole program" and "link time optimization" features of gcc.  The
whole-program optimization enables the compiler to evaluate the entire
firmware for optimization instead of just one code file at a time.
This leads to better overall optimizations.
2.0.x
Kevin O'Connor 12 years ago
parent 16fbb455ef
commit 0908458381

@ -227,6 +227,22 @@ OPT = s
DEFINES ?= DEFINES ?=
# Program settings
CC = $(AVR_TOOLS_PATH)avr-gcc
CXX = $(AVR_TOOLS_PATH)avr-g++
OBJCOPY = $(AVR_TOOLS_PATH)avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)avr-objdump
AR = $(AVR_TOOLS_PATH)avr-ar
SIZE = $(AVR_TOOLS_PATH)avr-size
NM = $(AVR_TOOLS_PATH)avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
MV = mv -f
# Tool for testing compiler flags
cc-option=$(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`" \
; then echo "$(2)"; else echo "$(3)"; fi ;)
# Place -D or -U options here # Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU) ${addprefix -D , $(DEFINES)} CDEFS = -DF_CPU=$(F_CPU) ${addprefix -D , $(DEFINES)}
CXXDEFS = -DF_CPU=$(F_CPU) ${addprefix -D , $(DEFINES)} CXXDEFS = -DF_CPU=$(F_CPU) ${addprefix -D , $(DEFINES)}
@ -251,8 +267,10 @@ CTUNING += -DMOTHERBOARD=${HARDWARE_MOTHERBOARD}
endif endif
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING) CFLAGS := $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CEXTRA) $(CTUNING) \
CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) -Wall $(CEXTRA) $(CTUNING) $(call cc-option,$(CC),-flto -fwhole-program,)
CXXFLAGS := $(CDEFS) $(CINCS) -O$(OPT) -Wall $(CEXTRA) $(CTUNING) \
$(call cc-option,$(CC),-flto -fwhole-program,)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -lm -Wl,--relax LDFLAGS = -lm -Wl,--relax
@ -264,18 +282,6 @@ AVRDUDE_FLAGS = -D -C $(ARDUINO_INSTALL_DIR)/hardware/tools/avrdude.conf \
-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
-b $(UPLOAD_RATE) -b $(UPLOAD_RATE)
# Program settings
CC = $(AVR_TOOLS_PATH)avr-gcc
CXX = $(AVR_TOOLS_PATH)avr-g++
OBJCOPY = $(AVR_TOOLS_PATH)avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)avr-objdump
AR = $(AVR_TOOLS_PATH)avr-ar
SIZE = $(AVR_TOOLS_PATH)avr-size
NM = $(AVR_TOOLS_PATH)avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
MV = mv -f
# Define all object files. # Define all object files.
OBJ = ${patsubst %.c, $(BUILD_DIR)/%.o, ${SRC}} OBJ = ${patsubst %.c, $(BUILD_DIR)/%.o, ${SRC}}
OBJ += ${patsubst %.cpp, $(BUILD_DIR)/%.o, ${CXXSRC}} OBJ += ${patsubst %.cpp, $(BUILD_DIR)/%.o, ${CXXSRC}}
@ -372,9 +378,13 @@ extcoff: $(TARGET).elf
$(NM) -n $< > $@ $(NM) -n $< > $@
# Link: create ELF output file from library. # Link: create ELF output file from library.
$(BUILD_DIR)/$(TARGET).elf: $(OBJ) Configuration.h $(BUILD_DIR)/$(TARGET).elf: $(BUILD_DIR)/$(TARGET).o
$(Pecho) " CXX $@"
$P $(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ -L. $^ $(LDFLAGS)
$(BUILD_DIR)/$(TARGET).o: $(OBJ) Configuration.h
$(Pecho) " CXX $@" $(Pecho) " CXX $@"
$P $(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ -L. $(OBJ) $(LDFLAGS) $P $(CC) $(ALL_CXXFLAGS) -nostdlib -Wl,-r -o $@ $(OBJ)
$(BUILD_DIR)/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE) $(BUILD_DIR)/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE)
$(Pecho) " CC $<" $(Pecho) " CC $<"

Loading…
Cancel
Save