diff --git a/core/binary.mk b/core/binary.mk index 9fa968dbe..92b08faca 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -213,10 +213,15 @@ endif ## Please note that we will do option filtering during FDO build. ## i.e. Os->O2, remove -fno-early-inline and -finline-limit. ################################################################## -ifeq ($(strip $(LOCAL_FDO_SUPPORT)), true) - ifeq ($(strip $(LOCAL_IS_HOST_MODULE)),) - my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_CFLAGS) - my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_LDFLAGS) +my_fdo_build := +ifneq ($(filter true always, $(LOCAL_FDO_SUPPORT)),) + ifeq ($(BUILD_FDO_INSTRUMENT),true) + my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_CFLAGS) + my_ldflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_INSTRUMENT_LDFLAGS) + my_fdo_build := true + else ifneq ($(filter true,$(BUILD_FDO_OPTIMIZE))$(filter always,$(LOCAL_FDO_SUPPORT)),) + my_cflags += $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_OPTIMIZE_CFLAGS) + my_fdo_build := true endif endif @@ -1045,19 +1050,10 @@ my_asflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flag my_ldflags := $(call $(LOCAL_2ND_ARCH_VAR_PREFIX)convert-to-$(my_host)clang-flags,$(my_ldflags)) endif -ifeq ($(LOCAL_FDO_SUPPORT), true) - build_with_fdo := false - ifeq ($(BUILD_FDO_INSTRUMENT), true) - build_with_fdo := true - endif - ifeq ($(BUILD_FDO_OPTIMIZE), true) - build_with_fdo := true - endif - ifeq ($(build_with_fdo), true) - my_cflags := $(patsubst -Os,-O2,$(my_cflags)) - fdo_incompatible_flags=-fno-early-inlining -finline-limit=% - my_cflags := $(filter-out $(fdo_incompatible_flags),$(my_cflags)) - endif +ifeq ($(my_fdo_build), true) + my_cflags := $(patsubst -Os,-O2,$(my_cflags)) + fdo_incompatible_flags := -fno-early-inlining -finline-limit=% + my_cflags := $(filter-out $(fdo_incompatible_flags),$(my_cflags)) endif $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS) diff --git a/core/combo/fdo.mk b/core/combo/fdo.mk index 9e331b6fa..8fb8fd3a5 100644 --- a/core/combo/fdo.mk +++ b/core/combo/fdo.mk @@ -18,22 +18,16 @@ $(combo_2nd_arch_prefix)TARGET_FDO_CFLAGS:= -ifeq ($(strip $(BUILD_FDO_INSTRUMENT)), true) - # Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation. - # The profile will be generated on /sdcard/fdo_profile on the device. - $(combo_2nd_arch_prefix)TARGET_FDO_CFLAGS := -fprofile-generate=/sdcard/fdo_profile -DANDROID_FDO - $(combo_2nd_arch_prefix)TARGET_FDO_LDFLAGS := -lgcov -lgcc -else - ifeq ($(strip $(BUILD_FDO_OPTIMIZE)), true) - # Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build. - ifeq ($(strip $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH)),) - $(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH := vendor/google_data/fdo_profile - endif +# Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation. +# The profile will be generated on /sdcard/fdo_profile on the device. +$(combo_2nd_arch_prefix)TARGET_FDO_INSTRUMENT_CFLAGS := -fprofile-generate=/sdcard/fdo_profile -DANDROID_FDO +$(combo_2nd_arch_prefix)TARGET_FDO_INSTRUMENT_LDFLAGS := -lgcov -lgcc - ifneq ($(strip $(wildcard $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH)/$(PRODUCT_OUT))),) - $(combo_2nd_arch_prefix)TARGET_FDO_CFLAGS := -fprofile-use=$($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH) -DANDROID_FDO -fprofile-correction -Wcoverage-mismatch -Wno-error - else - $(warning Profile directory $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH)/$(PRODUCT_OUT) does not exist. Turn off FDO.) - endif - endif +# Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build. +ifeq ($(strip $($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH)),) + $(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH := vendor/google_data/fdo_profile endif + +$(combo_2nd_arch_prefix)TARGET_FDO_OPTIMIZE_CFLAGS := \ + -fprofile-use=$($(combo_2nd_arch_prefix)TARGET_FDO_PROFILE_PATH) \ + -DANDROID_FDO -fprofile-correction -Wcoverage-mismatch -Wno-error